//AJAX START
var xmlHttp

function setAjax(url,str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
url=url+"?"+str
url=url+"&rid="+Math.random()
xmlHttp.onreadystatechange=stateChangeds
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChangeds() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
var   response   =   xmlHttp.responseText;  
var   ss   =   response.split( '|'); 
//alert(ss);
   if(xmlHttp.status == 200) {
      document.getElementById("hits").innerHTML=ss;
   }else{
       alert("Error!" + "\nStatus code is: " + xmlHttp.status + "\nStatus text is: " + xmlHttp.statusText);
   }
} 
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

//AJAX END


function showHintEmail(str,hintID,msg)
{
    var strP=/^\w+@[0-9a-zA-Z]+\.[a-zA-Z]+$/; 
    if(!strP.test(str)){
        document.getElementById(hintID).innerHTML=msg
    }else{
	 document.getElementById(hintID).innerHTML=""  
    }
} 

function showHintField(str,hintID,msg)
{
if (str.length==0 || str.length>250)
  { 
  document.getElementById(hintID).innerHTML=msg
  }else{
	 document.getElementById(hintID).innerHTML=""  
  }
}

 //验证只能输入数字.
function check_validate1(value){
    //定义正则表达式部分
    var strP = /^\d+$/;
    if(strP.test(value)){
        return true;
	}else{
        return false;	
	}
}
//验证只能输入字母.数字和下划线. 
function check_validate2(value){
    var strP = /^\w+$/;
    if(strP.test(value)){
        return true;
	}else{
        return false;	
	}

}
//验证固定电话：只能是数字.并且有相应的格式//028-67519441 或者 0839-8777222或者 028-6545124
function check_validate(value){
    var strP = /^(\d{3,4})-(\d{7,8})/;
    if(strP.test(value)){
        return true;
	}else{
        return false;	
	}
} 

//验证邮箱
function check_email(value){
    var strP=/^\w+@[0-9a-zA-Z]+\.[a-zA-Z]+$/; 
    if(strP.test(value)){
        return true;
	}else{
        return false;	
	}
} 


 function chkorder(){
     if (document.orderform.proname.value.length<1 || document.orderform.proname.value.length>255 ){
	    alert("你要订购的产品未填写！");
		document.orderform.proname.focus();
		return false; 
	 }
	 if (document.orderform.linkman.value.length<1 || document.orderform.linkman.value.length>4 ){
	    alert("姓名未填写或填写错误！");
		document.orderform.linkman.focus();
		return false; 
	 }
	 if (document.orderform.phone.value.length<7 || document.orderform.phone.value.length>50 ){
	    alert("联系方式未填写或填写不正确,请填写联系电话或手机号码！");
		document.orderform.phone.focus();
		return false; 
	 }
	 if (document.orderform.qq.value.length>0){
		if (document.orderform.qq.value.length<5 || document.orderform.qq.value.length>10 ){
	        alert("QQ号码位数不对，请输入5-10位以内QQ号码！");
		    document.orderform.qq.focus();
		    return false; 
		}
		if(!check_validate1(document.orderform.qq.value)){
			alert("QQ号码只能输入数字！");
		    document.orderform.qq.focus();
		    return false;
		}
	 }
      if(document.orderform.email.value.length>0){
         if(!check_email(document.orderform.email.value)){
             alert("您的邮箱填写不正确，请检查！");
             document.orderform.email.focus();
             return false; 
         }
      }
	  if(document.orderform.content.value.length>0){
          if (document.orderform.content.value.length>300 ){
			  alert("备注填写不能超过300个字！");
             document.orderform.content.focus();
             return false; 
		  }
	  }
//	  if(confirm("请确认您填写的信息正确无误，您真的要提交么？")){
//		return true;
//	  }else{
//		return false;
//	  }
 }


function chkgbook(){
	 if (document.gbookform.guestname.value.length<2 || document.gbookform.guestname.value.length>10 ){
	    alert("用户名称请输入2-10位以内！");
		document.gbookform.guestname.focus();
		return false; 
	 }
	 if (document.gbookform.phone.value.length>0){
	     if (document.gbookform.phone.value.length<7 || document.gbookform.phone.value.length>50 ){
	        alert("联系方式未填写或填写不正确,请填写联系电话或手机号码！");
		    document.gbookform.phone.focus();
		    return false; 
	     }
	 }
	 if (document.gbookform.qq.value.length>0){
		if (document.gbookform.qq.value.length<5 || document.gbookform.qq.value.length>10 ){
	        alert("QQ号码位数不对，请输入5-10位以内QQ号码！");
		    document.gbookform.qq.focus();
		    return false; 
		}
		if(!check_validate1(document.gbookform.qq.value)){
			alert("QQ号码只能输入数字！");
		    document.gbookform.qq.focus();
		    return false;
		}
	 }
	 if (document.gbookform.fax.value.length>0){
	     if (document.gbookform.fax.value.length<7 || document.gbookform.fax.value.length>30 ){
	        alert("联系传真未填写或填写不正确,请填写传真！");
		    document.gbookform.fax.focus();
		    return false; 
	     }
	 }
      if(document.gbookform.email.value.length>0){
         if(!check_email(document.gbookform.email.value)){
             alert("您的邮箱填写不正确，请检查！");
             document.gbookform.email.focus();
             return false; 
         }
      }
	  if (document.gbookform.content.value.length<2 || document.gbookform.content.value.length>300 ){
	     alert("请发表留言主题字数在2-300字之间");
		 document.gbookform.content.focus();
		 return false; 
	 }
}

function show(num) {
   for(i=1;i<2;i++){
	   ID=document.getElementById("channel_"+i);
	   if (i==num){
		   ID.style.visibility="visible";
	   }else{
		   ID.style.visibility="hidden"; 
	   }
   }
}

function hide(num) {
    setTimeout('ihide('+num+')',5000)
}

function ihide(num){
   for(i=1;i<2;i++){
	   ID=document.getElementById("channel_"+i);
	   if (i==num){
		   	ID.style.visibility="hidden";
	   }
   }
}


function loadimage(){
    document.getElementById("vcimage").src = "../VerifyCode.php?";
  }
  
function showHintfield(str,hintID)
{
if (str.length==0 || str.length>50)
  { 
  document.getElementById(hintID).innerHTML="<font color=red>×</font>"
  }else{
  document.getElementById(hintID).innerHTML="<font color=green>√</font>"  
  }
}
function showHintEmail(str,hintID)
{
var strP=/^\w+@[0-9a-zA-Z]+\.[a-zA-Z]+$/; 
if(!strP.test(str)){
  document.getElementById(hintID).innerHTML="<font color=red>×</font>"
  }else{
  document.getElementById(hintID).innerHTML="<font color=green>√</font>"  
  }
} 
function showHintpwd(str)
{
if (str.length==0 || str.length < 6  || str.length > 20)
  { 
  document.getElementById("chkpassword").innerHTML="<font color=red>×</font>"
  }else{
  document.getElementById("chkpassword").innerHTML="<font color=green>√</font>"  
  }
} 
function showHintpwd2(str)
{
if (str != document.regform.password1.value)
  { 
  document.getElementById("chkpassword2").innerHTML="<font color=red>×</font>"
  }else{
  document.getElementById("chkpassword2").innerHTML="<font color=green>√</font>"  
  }
} 
var xmlHttp

function showHint(str)
{
if (str.length==0 || str.length<2 ||  str.length>16){ 
  document.getElementById("chkusername").innerHTML="<font color=red>×</font>"
  return
  }
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
var url="gethint.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("chkusername").innerHTML=xmlHttp.responseText 
} 
} 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

function reg() { 
    var strPs=/^\w+@[0-9a-zA-Z]+\.[a-zA-Z]+$/;  
	if (document.regform.username.value.length<2 || document.regform.username.value.length>16 ) 
    {
    alert("用户名必须填写,有效长度为2-16位字符！");
    document.regform.username.focus();
    return false; 
    }
    if (document.regform.password1.value.length<6 || document.regform.password1.value.length>20) 
    {
    alert("密码必须填写,有效长度为6-20位字符!");
    document.regform.password1.focus();
    return false; 
    }
    if (document.regform.password2.value != document.regform.password1.value) 
    {
    alert("两次填写的密码不一致，请重新填写！");
    document.regform.password2.focus();
    return false; 
    }
//    if (document.regform.question.value =="")
//    {
//    alert("请填写您的密码问题！");
//    document.regform.question.focus();    
//    return false;  
//    }
//    if (document.regform.answer.value =="")
//    {
//    alert("请填写您的问题答案！");
//    document.regform.answer.focus();  
//    return false;
//    }
	if (document.regform.email.value =="")
    {
    alert("请填写您的Email！");
    document.regform.email.focus();
    return false;
    }
	if(!strPs.test(document.regform.email.value)){
    alert("您的注册邮箱填写不正确，请检查！");
    document.regform.email.focus();
    return false; 
    }
    if (document.regform.VerifyCode.value=='')
    {alert('请输入验证码！');
    document.regform.VerifyCode.focus();
    return false
    }
	if(document.regform.licence.checked == false) {
     alert('请点击确定已经认真阅读并接受本站服务条款！');
     document.regform.licence.focus();
     return false;
   }
}//检测注册框

function login() { 
    if (document.loginform.username.value =="")
    {
    alert("请填写您的用户名！");
    document.loginform.username.focus();
    return false;
    }
    if (document.loginform.password.value =="") 
    {
    alert("请填写您的密码！");
    document.loginform.password.focus();
    return false; 
    }
}//检测登录框

function clearForm(){
	document.loginform.username.value='';
	document.loginform.password.value='';
	document.loginform.username.select();
}

function chkemail() { 
    var strPs=/^\w+@[0-9a-zA-Z]+\.[a-zA-Z]+$/; 
	if (document.sendmailform.username.value =="") 
    {
    alert("请填写您的用户名！");
    document.sendmailform.username.focus();
    return false; 
    }
	if (document.sendmailform.email.value =="") 
    {
    alert("请填写您的注册邮箱！");
    document.sendmailform.email.focus();
    return false; 
    }
    if(!strPs.test(document.sendmailform.email.value)){
    alert("您的注册邮箱填写不正确，请检查！");
    document.sendmailform.email.focus();
    return false; 
    }
}

function copyText(obj)
{
obj.select(); 
js=obj.createTextRange(); 
js.execCommand("Copy") 
alert("复制成功,赶紧与您的朋友分享吧!");
}

function chkanswer(){
    var theCheckboxInputs=document.getElementsByName('chooseoption'); 
    for(var i=0;i<theCheckboxInputs.length;i++)   
    {   
        if(theCheckboxInputs[i].checked)
        return true;
    } 
    alert('您还没有选中其中的一项!'); 
    return false;
}

function openwindows(url,windowsname,width,height,thisurl)
{
	if(!url){var url="about:blank"}
	if(!width){var width=600}
	if(!height){var height=500}
window.open(url,windowsname,"width="+width+",height="+height+",toolbar=no,location=no,menubar=no,scrollbars=no,marginheight=0 marginwdith=0,directories=no,title=no,status=no,resizable=yes,top="+(screen.availHeight-height)/2+",left="+(screen.availWidth-width)/2+"");
window.opener=null;
window.open('','_self');//关键的一步
if(thisurl){
location.href=thisurl;
}else{
window.close();
}
}
