function turntopage(page)
{
document.myform.page.value=page;
document.myform.submit();
}
function show(i){
 for(var t=1;t<4;t++){
	var rhq    = "rhq"+t;
	var lvfen  = "xujing"+t;
	if (t==i){
	  document.getElementById(rhq).className = "rhq1";
	  document.getElementById(lvfen).style.display = "block";
	}
	else{
	  document.getElementById(rhq).className = "rhq2";
	  document.getElementById(lvfen).style.display = "none";	
	}
 }
}
function check_customer(){
	 var MailPattern = /^[a-z]([a-z0-9\.]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/;
	 var Title = document.myform.title.value;
	 var Content = document.myform.content.value;
	 var tel = document.myform.tel.value;
	 var txtName = document.myform.name.value;
	 var Email    = document.myform.email.value;
     if (txtName.length==0){
	    alert("请输入您姓名!");
		document.myform.name.focus();
		return false;
	 } 
     if (Email.length==0){
	    alert("请输入您的邮箱地址!");
		document.myform.email.focus();
		return false;
	 }
	 if(!MailPattern.test(Email)){
	    alert("请输入您的正确邮箱地址!");
	    document.myform.email.focus();
		return false;	 
	 } 
     if (tel.length==0){
	    alert("请留下您的联系方式!");
		document.myform.tel.focus();
		return false;
	 }		 
	 if (Title.length==0){
	    alert("请输入投诉主题!");
		document.myform.title.focus();
		return false;
	 }
     if (Content.length==0){
	    alert("请输入投诉内容!");
		document.myform.content.focus();
		return false;
	 }	  	 	 
}
function check_feedbak(){
	 var MailPattern = /^[a-z]([a-z0-9\.]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/;
	 var Title = document.myform.title.value;
	 var Content = document.myform.content.value;
	 var tel = document.myform.tel.value;
	 var txtName = document.myform.name.value;
	 var Email    = document.myform.email.value;
     if (txtName.length==0){
	    alert("请输入您姓名!");
		document.myform.name.focus();
		return false;
	 } 
     if (Email.length==0){
	    alert("请输入您的邮箱地址!");
		document.myform.email.focus();
		return false;
	 }
	 if(!MailPattern.test(Email)){
	    alert("请输入您的正确邮箱地址!");
	    document.myform.email.focus();
		return false;	 
	 } 
     if (tel.length==0){
	    alert("请留下您的电话!");
		document.myform.tel.focus();
		return false;
	 }		 
	 if (Title.length==0){
	    alert("请输入主题!");
		document.myform.title.focus();
		return false;
	 }
     if (Content.length==0){
	    alert("请输入留言内容!");
		document.myform.content.focus();
		return false;
	 }	  	 	 
}
//用户注册判断
function check_username(){
	 var username = document.myform.username.value;
     if (username.length < 3){
	    document.getElementById("username_c_1").style.display ="block";
	    document.getElementById("username_c").innerHTML = "用户名不能小于3个字符";
		return false;
	 }
	 else if (username.length > 15){
	    document.getElementById("username_c_1").style.display ="block";
	    document.getElementById("username_c").innerHTML = "用户名不能大于15个字符";
		return false;
	 }
	 else{
	    //hava_username(username);
	    document.getElementById("username_c_1").style.display ="none";
		return true;
	 }
}
function check_password(){
	 var password = document.myform.password.value;
     if (password.length < 6){
	    document.getElementById("password_c_1").style.display ="block";
	    document.getElementById("password_c").innerHTML = "密码长度不能小于6个字符";
		return false;
	 }
	 else if (password.length > 16){
	    document.getElementById("password_c_1").style.display ="block";
	    document.getElementById("password_c").innerHTML = "密码长度不能大于16个字符";
		return false;
	 }
	 else{
	    document.getElementById("password_c_1").style.display ="none";
		return true;
	 }
}
function check_city(){
	 var password = document.myform.province.value;
     if (password.length < 6){
	    document.getElementById("citys").innerHTML = "请选择您所在的城市";
		return false;
	 }
	 else{
		return true;
	 }
}
function check_opassword(){
	 var password = document.myform.opassword.value;
     if (password.length == 0){
	    document.getElementById("opassword_c_1").style.display ="block";
	    document.getElementById("opassword_c").innerHTML = "请输入旧密码";
		return false;
	 }
	 else{
	    document.getElementById("opassword_c_1").style.display ="none";
		return true;
	 }
}
function check_rpassword(){
	if (document.myform.rpassword.value != document.myform.password.value){
	  document.getElementById("rpassword_c_1").style.display ="block";
	  document.getElementById("rpassword_c").innerHTML = "两次密码输入的不一致"; 
	  return false;
	}
	else{
	  document.getElementById("rpassword_c_1").style.display ="none";
	  return true;
	}
}

function check_email(){
   var MailPattern = /^[a-z]([a-z0-9\.]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/;
   var email = document.myform.email.value;
   if (email ==  ""){
	  document.getElementById("email_c_1").style.display ="block";
	  document.getElementById("email_c").innerHTML = "请输入您的E-mail地址"; 
	  return false;
   }
   else{
      if(!MailPattern.test(email)){
	  document.getElementById("email_c_1").style.display ="block";
	  document.getElementById("email_c").innerHTML = "请输入合法的E-mail地址";
	  return false;
	  }
	  else{
	  document.getElementById("email_c_1").style.display ="none";
      return true;
	  }
  }
}
function check_realname(){
   var realname = document.myform.realname.value;
   if (realname ==  ""){
	  document.getElementById("realname_c_1").style.display ="block";
	  document.getElementById("realname_c").innerHTML = "请输入您的真实姓名"; 
	  return false;
   }
   else{
	  document.getElementById("realname_c_1").style.display ="none";
      return true;
   }
}
function check_address(){
   var address = document.myform.address.value;
   if (address ==  ""){
	  document.getElementById("address_c_1").style.display ="block";
	  document.getElementById("address_c").innerHTML = "请输入您的收货地址"; 
	  return false;
   }
   else{
	  document.getElementById("address_c_1").style.display ="none";
      return true;
   }
}
function check_code(){
   var code = document.myform.code.value;
   if (code ==  ""){
	  document.getElementById("code_c_1").style.display ="block";
	  document.getElementById("code_c").innerHTML = "请输入您的邮编"; 
	  return false;
   }
   else{
	  document.getElementById("code_c_1").style.display ="none";
      return true;
   }
}
function check_tel(){
   var tel = document.myform.tel.value;
   if (tel ==  ""){
	  document.getElementById("tel_c_1").style.display ="block";
	  document.getElementById("tel_c").innerHTML = "请输入您的联系电话"; 
	  return false;
   }
   else{
	  document.getElementById("tel_c_1").style.display ="none";
      return true;
   }
}
function  check_form(){
 if (check_username()== false || check_password()==false || check_rpassword()==false || check_email() ==false || check_realname() ==false ||  check_address() ==false || check_code() ==false || check_tel() ==false){
 alert("请确保您的填写是正确的 ");
 return false;
}
}
function  check_add(){
myform.action='methods.php';
 if (check_realname() ==false || check_address() ==false || check_code() ==false || check_tel() ==false){
 alert("请确保您的填写是正确的 ");
 return false;
}
}
function check_edit(){
 if (check_opassword()== false || check_password()==false || check_rpassword()==false || check_email() ==false || check_realname() ==false || check_address() ==false || check_code() ==false || check_tel() ==false){
 alert("请确保您的填写是正确的 ");
 return false;
}	
}
function createXMLHttp() {
	if (window.XMLHttpRequest) {
		var objXMLHttp = new XMLHttpRequest();
		if (objXMLHttp.readyState == null) {
			objXMLHttp.readyState = 0;
			objXMLHttp.addEventListener(
			"load",
			function () {
				objXMLHttp.readyState = 4;
				if (typeof(objXMLHttp.onreadystatechange) == "function") {
					objXMLHttp.onreadystatechange();
				}
			},
			false
			);
		}
		return objXMLHttp;
	} else if (s_XMLHttpNameCache != null) {
		return new ActiveXObject(s_XMLHttpNameCache);
	} else {
		var MSXML = [
			'MSXML2.XMLHTTP.6.0',
			'MSXML2.XMLHTTP.5.0',
			'MSXML2.XMLHTTP.4.0',
			'MSXML2.XMLHTTP.3.0',
			'MsXML2.XMLHTTP.2.6',
			'MSXML2.XMLHTTP',
			'Microsoft.XMLHTTP.1.0',
			'Microsoft.XMLHTTP.1',
			'Microsoft.XMLHTTP'
		];
		var n = MSXML.length;
		for (var i = 0; i < n; i++) {
			try {
				objXMLHttp = new ActiveXObject(MSXML[i]);
				s_XMLHttpNameCache = MSXML[i];
				return objXMLHttp;
			}
			catch(e) {}
		}
		return null;
	}
}

var http_request = null;
var s_XMLHttpNameCache = null;
function send_request(url,sh){
    http_request = createXMLHttp();
	if (typeof(http_request) == 'undefined') {
		window.alert("Can't creat XMLHttpRequest Object.");
		return false;
	}
	if (typeof(data) == 'undefined') {
		http_request.open('GET',url,true);
		http_request.send(null);
	} else {
		var request = data;
		http_request.open('POST',url,true);
		http_request.setRequestHeader('Content-Length', request.length);
		http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		http_request.send(request);
	}
	if (typeof(callback) == 'function') {
		http_request.onreadystatechange = function () {
			if (http_request.readyState == 4) {
				if (http_request.status == 200 || http_request.status == 304) {
					callback(http_request,sh);//调用显示函数//////
				} else {
					alert("Error loading page\n" + http_request.status + ':' + http_request.statusText);
				}
			}
		}
	}
}

function basket(id,sh){
 url= "into_basket.php?act=insert&id="+id;
 send_request(url,sh);
}
function del_basket(id,sh){
 url= "into_basket.php?act=del&id="+id;
 send_request(url,sh);
 alert(http_request.responseText);
}
function update_basket(number,id,sh){
  if (isNaN(number)){
	   alert('请确认输入的是整数');
  }
  else{
     url= "into_basket.php?act=update&id="+id+"&number="+number;
	 send_request(url,sh); 
  }
}

function del_basket(id,sh){
 url= "into_basket.php?act=del&id="+id;
 send_request(url,sh);
}


function callback(http_request,sh){
	if (http_request.responseText=='hava'){
	   if (confirm('对不起,您的购物车中已经有了该产品\n进购物车查看?')){
	      window.location.href='basket.php';
	   }
	   else{
	     return false;
	   }
	}
	else if (http_request.responseText=='nologin'){
	      alert("对不起，请先登陆");
		  window.location.href="log.php";
	     return false;
	}	
	else if (sh=="basket"){
	   if (confirm('成功放入购物车\n进购物车查看?')){
	      window.location.href='basket.php';
	   }
	   else{
	     return false;
	   }
	}
	else if (sh=="del_goods" ){
	    document.getElementById("basketball").innerHTML=http_request.responseText;
	}
	else if (sh=="update_number" ){
        document.getElementById("basketball").innerHTML=http_request.responseText;
	}	
}
function check_list(){
	     var aa=document.getElementsByName("address_id");
        var length = aa.length;
			if (document.getElementById("prices").value==""||document.getElementById("prices").value==0)
			{
				alert("你还没有选购任何产品");
				return false;
		    }		
		if (length == 0){
	       alert("请先添加一个收货地址!");
		   return false;
		}
		else{
	        for (var j=0;j<length;j++){
			    if (aa[j].checked){
				  var pp=1;
				}
			}
			if (pp!=1){
	          alert("请先选择一个收货地址!");
			  return false;
			}
		}
		
		var bbt=document.getElementsByName("method_name");
        var lengthst = bbt.length;
		if (lengthst == 0){
	       alert("请选择送货方式!");
		   return false;
		}
		else{
	        for (var it=0;it<lengthst;it++){
			    if (bbt[it].checked){
				  var ttt=1;
				}
			}
			if (ttt!=1){
	          alert("请选择送货方式!");
			  return false;
			}
		}
		
	    var bb=document.getElementsByName("pay_id");
        var lengths = bb.length;
		if (lengths == 0){
	       alert("请选择付款方式!");
		   return false;
		}
		else{
	        for (var i=0;i<lengths;i++){
			    if (bb[i].checked){
				  var tt=1;
				}
			}
			if (tt!=1){
	          alert("请选择付款方式!");
			  return false;
			}
		}
	  if (document.getElementById("is_fp").checked){
			if (document.getElementById("fp").value=="")
			{
				alert("请填写发票抬头");
				return false;
		    }
	  }
	  
		
}
