//内页用切换
function procase(val){
	var overColor = "";
	var outColor = "";
	var overtxt = "#000000"
	var outtxt = "#000000"
	
	var i=1
	var len=3


	for(i;i<=len;i++)
	{
		if(i!=val)
		{
			document.getElementById("pbox"+i).style.display='none';			
			document.getElementById("ptn"+i).className = "normal";
		}
		else
		{
			document.getElementById("pbox"+val).style.display='block';	
			document.getElementById("ptn"+val).className = "current";		
		}
	}
}

function secBoard(elementID,listName,n) {
 var elem = document.getElementById(elementID);
 var elemlist = elem.getElementsByTagName("li");
 for (var i=0; i<elemlist.length; i++) {
  elemlist[i].className = "normal";
  var m = i+1;
  document.getElementById(listName+"_"+m).style.display = "none";
 }
  elemlist[n-1].className = "current";
  document.getElementById(listName+"_"+n).style.display = "block";
}


//首页用Banner切换
function banner(val){
	var overColor = "url(images/bannerBtn.jpg)";
	var outColor = "url(images/bannerBtn.jpg)";
	var overtxt = "#fff"
	var outtxt = "#666"
	
	var i=1
	var len=3

	for(i;i<=len;i++)
	{
		if(i!=val)
		{
			document.getElementById("banner"+i).style.display='none';
			//document.getElementById("pic"+i).style.backgroundImage =outColor;
			document.getElementById("pic"+i).style.color = outtxt;
		}
		else
		{
			document.getElementById("banner"+val).style.display='';	
			//document.getElementById("pic"+val).style.backgroundImage =overColor;
			document.getElementById("pic"+val).style.color = overtxt;	
		}
	}
	

}





function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
//左边小图焦点切换右边大图js代码 code by 轻羽 QQ:17208008 time:2010-6-17
var pubdex=0;
var oTimer = null;
function mousesetcls(dex,maxdex)//鼠标移动切换小图和大图
{
  window.clearInterval(oTimer);
  document.getElementById("isauto").value=0;
  setcls(dex,maxdex);
}
function setcls(dex,maxdex) //切换小图和大图
{
  pubdex=dex;
  for (var i=1;i<=maxdex;i++)
  {
    if (i==dex)
	{
	  //document.getElementById("isauto").value=0;
	  document.getElementById("smallBox_"+i).className="smallBox_current";
	}
	else
	{
	  document.getElementById("smallBox_"+i).className="smallBox_normal";
	}
  }
  
}
//自动切换小图和大图
function autosetcls()
{
  if (document.getElementById("isauto").value==0) return;
  var thisdex=pubdex+1;
  if (thisdex>4)
  {
    thisdex =1;
  }
  setcls(thisdex,4)
}
function doautosetcls()
{
  if (!document.getElementById("indexBanner")) return;
  document.getElementById("isauto").value=1;
  oTimer=setInterval('autosetcls()',3000);
}
function mouseout()
{
   window.clearInterval(oTimer);
   //setTimeout('doautosetcls()',3000)
  
   doautosetcls();
}
addLoadEvent(doautosetcls)

function $(obj)
{
  return document.getElementById(obj);	
}
//创建xmlhttp对象
var xmlhttp;
function createXMLHttpRequest()
{
  if(window.ActiveXObject){
    //MS IE
    try{
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
    }catch(e){
        try{
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }catch(e){ }
    } 
}else if(window.XMLHttpRequest){
    //NOT MS IE
    xmlhttp=new XMLHttpRequest();
    }
if(!xmlhttp){
    xmlhttp=false;
    alert("无法建立 Ajax 请求对象,你的浏览器版本太低，建议升级你的浏览器.");
    //window.location.href="ajaxError.htm";
    }
return xmlhttp;
 }
 
var pubdiv=""
function showpager(cid,p)
{
  var divid="pager_"+cid;
  $(divid).innerHTML="<img src='/images/loading.gif' /> "
  var url="/ajax.asp?act=showpager&c_id="+cid+"&curpage="+p;
  AjaxPager(url,divid);
}
function AjaxPager(url,divid)
{
	createXMLHttpRequest();
	xmlhttp.onreadystatechange=ResultAjaxPager;
	pubdiv=divid;
	xmlhttp.open("post",url,true);
    xmlhttp.send(null)
}
function ResultAjaxPager()
{
    if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		$(pubdiv).innerHTML=xmlhttp.responseText;
	  }		
	}
}
function LoadregForm()
{
  var url="reg.asp"
  AjaxPager(url,"regform")
}
function LoadLoginForm()
{
  var LocString=String(window.document.location.href);   
  function getQueryStr(str){   
        var rs = new RegExp("(^|)"+str+"=([^\&]*)(\&|$)","gi").exec(LocString),tmp;   
       
        if(tmp=rs){   
            return tmp[2];   
        }   
       
        // parameter cannot be found   
        return "";   
    }   
  var backurl=getQueryStr("url");
  var act=getQueryStr("act");
  var url="login.asp?brkurl=http://www.chinaalarm.com"+backurl+"&act="+act;
  AjaxPager(url,"regform")
}
//用户注册
function checkform_user()
{
  if ($("user_name").value=="")
  {
    $("span_user_name").innerHTML="<img src='/images/error.gif' />请输入用户名!";
	$("temp_ok").value=0; 
  }
  else
  {
    if ($("user_name").value.length<2)
	{
	  $("temp_ok").value=0; 
	  $("span_user_name").innerHTML="<img src='/images/error.gif' />用户名不能少于2个字符!"
	}
	else
	{
		if ($("user_name").value.length>16)
		{
		  $("temp_ok").value=0; 
		  $("span_user_name").innerHTML="<img src='/images/error.gif' />用户名不能大于16个字符!"
		}
		else
		{
			checkuser($("user_name").value);
		}
	}
	
  }
}
function checkform_email()
{
  if ($("user_mail").value=="")
  {
    $("temp_ok").value=0; 
	$("span_user_mail").innerHTML="<img src='/images/error.gif' />请输入邮箱!"
  }
  else
  {
     if (!isEmail($("user_mail").value))
	 {
	   $("temp_ok").value=0; 
	   $("span_user_mail").innerHTML="<img src='/images/error.gif' />邮箱格式不正确!"
	 }
	 else
	 {
	    checkuseremail($("user_mail").value);
	 }
  }
}
function checkform_pwd()
{
   if ($("user_pwd").value=="")
   {
    $("temp_ok").value=0; 
	$("span_user_pwd").innerHTML="<img src='/images/error.gif' />请输入密码!"
   }
   else
   {
		if ($("user_pwd").value.length<2)
		{
		  $("temp_ok").value=0; 
		  $("span_user_pwd").innerHTML="<img src='/images/error.gif' />密码不能少于2个字符!"
		}
		else
		{ 
		  if ($("user_pwd").value.length>16)
		  {
			  $("temp_ok").value=0; 
			  $("span_user_pwd").innerHTML="<img src='/images/error.gif' />密码不能大于16个字符!"
		  }
		  else
		  {
		    $("temp_ok").value=1; 
			 $("span_user_pwd").innerHTML="<img src='/images/ok.gif' />正确!"
		  }
		}
   }
}
function checkform_chkpwd()
{
  if ($("user_pwd_check").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_user_pwd_check").innerHTML="<img src='/images/error.gif' />请输入确认密码!"
  }
  else
  {
      if ($("user_pwd").value!=$("user_pwd_check").value)
	  {
		$("temp_ok").value=0; 
		$("span_user_pwd_check").innerHTML="<img src='/images/error.gif' />确认密码和密码不一致!"
	  }
	  else
	  {
		$("temp_ok").value=1; 
		$("span_user_pwd_check").innerHTML="<img src='/images/ok.gif' />正确!"
	  }
  }
}
function checkform_RealName()
{
  if ($("RealName").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_RealName_check").innerHTML="<img src='/images/error.gif' />请输入真实姓名!"
  }
  else
  {
	 $("temp_ok").value=1; 
     $("span_RealName_check").innerHTML="<img src='/images/ok.gif' />正确"
  }
}
function checkform_utype()
{
  if ($("utype").value=="" && $("utype2").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_utype_check").innerHTML="<img src='/images/error.gif' />请选择或输入用户类型!"
  }
  else  
  {
	if ($("utype").value=="产品用户" || $("utype2").value=="产品用户")
	{
		checkform_product();
	    checkform_productsn();
	}
	else
	{
		$("span_product_check").innerHTML="";
		$("span_productsn_check").innerHTML="";
		if ($("utype").value=="其它")
		{
			if ($("utype2").value=="")
			{
			  $("temp_ok").value=0; 
              $("span_utype_check").innerHTML="<img src='/images/error.gif' />请输入用户类型!"
			}
			else
			{
			  $("span_utype_check").innerHTML="<img src='/images/ok.gif' />正确!"
		     $("temp_ok").value=1; 	
			}
		}
	    else
		{
			 $("span_utype_check").innerHTML="<img src='/images/ok.gif' />正确!"
		     $("temp_ok").value=1; 	
		}
	}
  }

}
function checkform_company()
{
  if ($("company").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_company_check").innerHTML="<img src='/images/error.gif' />请输入单位名称!"
  }
  else
  {
	 $("temp_ok").value=1; 
     $("span_company_check").innerHTML="<img src='/images/ok.gif' />正确!"
  }

}
function checkform_address()
{
  if ($("address").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_address_check").innerHTML="<img src='/images/error.gif' />请输入单位地址!"
  }
  else
  {
	 $("temp_ok").value=1; 
     $("span_address_check").innerHTML="<img src='/images/ok.gif' />正确!"
  }

}
function checkform_ctype()
{
  if ($("ctype").value=="" && $("ctype2").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_ctype_check").innerHTML="<img src='/images/error.gif' />请选择或输入单位类型!"
  }
  else
  {
	  if ($("ctype2").value=="其它")
	  {
		  if ($("ctype").value=="")
		  {
			  $("temp_ok").value=0; 
			  $("span_ctype_check").innerHTML="<img src='/images/error.gif' />请输入其它单位类型!"
			  $("ctype2").focus();
		  }
		  else
	      {
		    $("temp_ok").value=1; 
            $("span_ctype_check").innerHTML="<img src='/images/ok.gif' />正确!"
	      }
	   }
	   else
	   {
		    $("temp_ok").value=1; 
            $("span_ctype_check").innerHTML="<img src='/images/ok.gif' />正确!"
	   }
  }

}
function checkform_ctelphone()
{
  if ($("ctelphone").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_ctelphone_check").innerHTML="<img src='/images/error.gif' />请选择或输入单位类型!"
  }
  else
  {
	  $("temp_ok").value=1; 
     $("span_ctelphone_check").innerHTML="<img src='/images/ok.gif' />正确!"
  }

}
function checkform_product()
{
  if ($("utype").value=="产品用户")
  {
	  if ($("product").value=="")
	  {
		 $("temp_ok").value=0; 
		 $("span_product_check").innerHTML="<img src='/images/error.gif' />您是产品用,请输入产品名称!"
	   }
	   else
	   {
		 $("temp_ok").value=1; 
		 $("span_product_check").innerHTML="<img src='/images/ok.gif' />正确!"
	   }
  }
}
function checkform_productsn()
{
   if ($("utype").value=="产品用户")
   {
	   if ($("productsn").value=="")
	   {
		  $("temp_ok").value=0; 
		  $("span_productsn_check").innerHTML="<img src='/images/error.gif' />您是产品用,请输入产品编号!"
		}
		else
		{
		  $("temp_ok").value=1; 
		  $("span_productsn_check").innerHTML="<img src='/images/ok.gif' />正确!"
		}
   }
}
	   
function checkform_reg()
{
  checkform_user();
  checkform_email();
  checkform_pwd();
  checkform_chkpwd();
  checkform_RealName();
  checkform_utype();
  checkform_company();
  checkform_address();
  checkform_ctype();
  checkform_ctelphone()
  if ($("temp_ok").value=="0")
  {
   return false;
  }
  return true;
}
function isEmail(strEmail) {
  if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
  return true;
else
  return false;
}

function checkuser(userstr)
{
	createXMLHttpRequest();
	$("span_user_name").innerHTML="<img src='/images/loading.gif' /> "
	xmlhttp.onreadystatechange=Resultcheckuser;
	xmlhttp.open("post","/ajax.asp?act=chkuser&username="+userstr,true);
    xmlhttp.send(null);
	
}
function Resultcheckuser()
{
  if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		 if (xmlhttp.responseText=="0")
		 {
		   $("span_user_name").innerHTML="<img src='/images/OK.gif' />恭喜您,此用户名可以注册! "
		   $("temp_ok").value=1; 
		 }
		 else
		 {
		   $("span_user_name").innerHTML="<img src='/images/error.gif' />此用户名不能注册! "
		   $("temp_ok").value=0; 
		 }
	  }		
	}
}
//会员登录
function checkform_user_login()
{
  if ($("user_name").value=="")
  {
    $("span_user_name").innerHTML="<img src='/images/error.gif' />请输入用户名!";
	$("temp_ok").value=0; 
  }
  else
  {
	$("span_user_name").innerHTML=""
	$("temp_ok").value=1;
  }
}

function checkform_pwd_login()
{
   if ($("user_pwd").value=="")
   {
    $("temp_ok").value=0; 
	$("span_user_pwd").innerHTML="<img src='/images/error.gif' />请输入密码!"
   }
   else
   {
	 $("temp_ok").value=1;
	 $("span_user_pwd").innerHTML="";
   }
}
function checkform_login()
{
	
	checkform_user_login();
	checkform_pwd_login();
	if ($("temp_ok").value=="0")
	{
	  return false;
	}
	$("txtbackurl2").value=$("txtbackurl").value;
	//alert($("txtbackurl2").value);
	return true;
}
//验证邮件
function checkuseremail(str)
{
    createXMLHttpRequest();
	$("span_user_mail").innerHTML="<img src='/images/loading.gif' /> "
	xmlhttp.onreadystatechange=Resultcheck;
	xmlhttp.open("post","/ajax.asp?act=checkemal&email="+str,true);
    xmlhttp.send(null)
}
function Resultcheck()
{
	 if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		 if (xmlhttp.responseText=="0")
		 {
		   $("span_user_mail").innerHTML="<img src='/images/OK.gif' />正确! "
		   $("temp_ok").value=1; 
		 }
		 else
		 {
		   $("span_user_mail").innerHTML="<img src='/images/error.gif' />此邮箱已有人使用,不能注册! "
		   $("temp_ok").value=0; 
		 }
	  }		
	}
}

function checkdown(id)
{
	createXMLHttpRequest();
	xmlhttp.onreadystatechange=Resultcheckdown;
	xmlhttp.open("post","/ajax.asp?act=checkdown&fileid="+id,true);
    xmlhttp.send(null)
}

function Resultcheckdown()
{
	
	 if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		  //alert(xmlhttp.responseText);
		  var rtuarr=xmlhttp.responseText.split("|");
		  var is_user_down=rtuarr[0];
		  var is_login=rtuarr[1];
		  var file_path=rtuarr[2]
		  if (is_user_down==1&&is_login==0)
		  { 
		    window.location.href="login.html?url="+file_path;
		  }
		  else
		  {
			 if (file_path=="")
			 {
				 alert("没有相关的下载文件!");
			 }
			 else
			 {
			   window.location.href=file_path;
			 }
		  }
	  }		
	}
}

function LoadUCenterForm()
{
  var LocString=String(window.document.location.href);   
  function getQueryStr(str){   
        var rs = new RegExp("(^|)"+str+"=([^\&]*)(\&|$)","gi").exec(LocString),tmp;   
       
        if(tmp=rs){   
            return tmp[2];   
        }   
       
        // parameter cannot be found   
        return "";   
    }   
  var pannel=getQueryStr("col");  
  var url="/user.asp?pannel="+pannel;
  AjaxPager(url,"regform")
}

//修改密码
function checkform_pwd_editpass()
{
   if ($("txtoldpassword").value=="")
   {
    $("temp_ok").value=0; 
	$("span_user_oldpwd").innerHTML="<img src='/images/error.gif' />请输入原密码!"
   }
   else
   {
	  checkoldpass($("txtaccount").value,$("txtoldpassword").value);
   }
}
function checkform_newpwd_editpass()
{
	if ($("txtnewpass").value=="")
   {
    $("temp_ok").value=0; 
	$("span_user_newpwd").innerHTML="<img src='/images/error.gif' />请输入新密码!"
   }
   else
   {
		if ($("txtnewpass").value.length<2)
		{
		  $("temp_ok").value=0; 
		  $("span_user_newpwd").innerHTML="<img src='/images/error.gif' />密码不能少于2个字符!"
		}
		else
		{ 
		  if ($("txtnewpass").value.length>16)
		  {
			  $("temp_ok").value=0; 
			  $("span_user_newpwd").innerHTML="<img src='/images/error.gif' />密码不能大于16个字符!"
		  }
		  else
		  {
		    $("temp_ok").value=1; 
			 $("span_user_newpwd").innerHTML=""
		  }
		}
   }
}
function checkform_newpwd2_editpass()
{
	if ($("txtnewpass2").value=="")
  {
	 $("temp_ok").value=0; 
     $("span_user_newpwd2").innerHTML="<img src='/images/error.gif' />请输入确认密码!"
  }
  else
  {
      if ($("txtnewpass2").value!=$("txtnewpass").value)
	  {
		$("temp_ok").value=0; 
		$("span_user_newpwd2").innerHTML="<img src='/images/error.gif' />确认密码和密码不一致!"
	  }
	  else
	  {
		$("span_user_newpwd2").innerHTML="";
	  }
  }
}
function checkoldpass(user,pass)
{
	createXMLHttpRequest();
	$("span_user_oldpwd").innerHTML="<img src='/images/loading.gif' /> "
	xmlhttp.onreadystatechange=Resultcheckoldpass;
	var url="/ajax.asp?act=chkoldpass&username="+user+"&pass="+pass;
	xmlhttp.open("post","/ajax.asp?act=chkoldpass&username="+user+"&pass="+pass,true);
    xmlhttp.send(null)
}
function Resultcheckoldpass()
{
  if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		if (xmlhttp.responseText=="0")
		 {
		    $("span_user_oldpwd").innerHTML="<img src='/images/error.gif' />原密码输入错误! "
		    $("temp_ok").value=0; 
		  
		 }
		 else
		 {
		    $("span_user_oldpwd").innerHTML="<img src='/images/OK.gif' />原密码输入正确! "
		    $("temp_ok").value=1; 
		 }
	  }		
	}
}
function checkform_editpass()
{
	checkform_pwd_editpass();
	checkform_newpwd_editpass();
	checkform_newpwd2_editpass();
	if ($("temp_ok").value==0)
	{
	  return false;
	}
	if ($("txtoldpassword").value==$("txtnewpass").value)
	{
		$("trshowerror").style.display="";
		$("showerror").innerHTML="<font color='red'>您输入的新密码和原密码一致!</font>";
		return false;
	}
	doeditpass();
}

function doeditpass()
{
   createXMLHttpRequest();
   xmlhttp.onreadystatechange=Resultdoeditpass;
   var url="/ajax.asp?act=editpass&user="+$("txtaccount").value+"&pass="+$("txtnewpass").value;
   xmlhttp.open("post",url,true);
   xmlhttp.send(null);
}

function Resultdoeditpass()
{
	 if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		 $("trshowerror").style.display="";
		 $("showerror").innerHTML=xmlhttp.responseText;
		 $("txtoldpassword").value="";
		 $("txtnewpass").value="";
		 $("span_user_oldpwd").innerHTML="";
		 $("txtnewpass2").value="";
	  }		
	}
}

function chkclassdown(cid,fid)
{
	createXMLHttpRequest();
	xmlhttp.onreadystatechange=Resultchkclassdown;
	xmlhttp.open("post","/ajax.asp?act=checkclsdown&clsid="+cid+"&fileid="+fid,true);
    xmlhttp.send(null)
	
}
function Resultchkclassdown()
{
	 if (xmlhttp.readyState==4)
	{
	  if (xmlhttp.status==200)
	  {
		  var rtuarr=xmlhttp.responseText.split("|");
		  var is_user_down=rtuarr[0];
		  var is_login=rtuarr[1];
		  var file_path=rtuarr[2]
		  if (is_user_down==1&&is_login==0)
		  { 
		    window.location.href="login.html?url="+file_path;
		  }
		  else
		  {
			 if (file_path=="")
			 { 
			   alert("没有相关的下载文件!");
			 }
			 else
			 {
			   window.location.href=file_path;
			 }
		  }
	  }		
	}
}
