// JavaScript Document

function Check_Login(){ 
theform=document.form;
if (Trim(theform.login_name.value)=="") 
{
$sMsg = "请输入用户名!";
alert($sMsg) ;
theform.login_name.focus(); 
return false; 
}
if (Trim(theform.login_pwd.value) == "") 
{ 
$sMsg = "请输入密码!";
alert($sMsg) ;
theform.login_pwd.focus(); 
return false; 
} 
	
document.form.action="check_login.php";
document.form.submit();

} 


function AddFavorite(sURL, sTitle)
{
	alert(sTitle);

   try
   {
       window.external.addFavorite(sURL, sTitle);
   }
   catch (e)
   {
       try
       {
         window.sidebar.addPanel(sTitle, sURL, "");
		
       }
       catch (e)
       {
           alert("加入收藏失败，请使用Ctrl+D进行添加");
       }
   }
}


function Key_Down(object)
{
　　if (event.keyCode == 13)
　　{
　　　　event.returnValue=false;
　　　　event.cancel = true;
    　document.getElementById(object).focus();
　　}
}



function Get_Radio(radioName){
	var str=""
   var obj=document.getElementsByName(radioName);
 for(var i=0;i<obj.length;i++){
  if(obj[i].checked){
   str=obj[i].value;
   break;
  }
 }
return str
}

function change_lan(model_lan){
var url="change_lan.php?model_lan="+model_lan;
AJAX(url);
document.form.action='index.php';	
document.form.submit();	
	}

function Is_Valid(object) 
{ 
re= /select|insert|update|delete|exec|count|'|"|=|;|>|<|%/i; 
$sMsg = "请您不要在参数中输入特殊字符和SQL关键字！";
if ( re.test(document.getElementById(object).value) ) 
{ 
alert( $sMsg ); 
document.getElementById(object).value =''; 
document.getElementById(object).focus(); 
return false; 
} 
} 

function Is_Digit(object){
	var pattern=/^(\-?)(\d+)$/;
    if  (!pattern.test(document.getElementById(object).value)){
	$sMsg = "只能是数字！";
alert( $sMsg ); 
//document.getElementById(object).value ='';
return false;
		}

}


function calc(){
	Is_Digit("product_number");
	product_number=parseInt(document.getElementById("product_number").value);
	purchase_price=parseInt(document.getElementById("purchase_price").value);
	document.getElementById("total_price_display").innerHTML=product_number*purchase_price+"元";
	document.getElementById("total_price").value=product_number*purchase_price;
}


 
  function   open_pop(){  
  calc();
 document.form.purchase_detail.value=document.getElementById("product").innerHTML; 
  close_pop(); 
  document.form.action="index_order_save.php";
  document.form.submit();
  }
  
  function   close_pop(){   

  closeBox('win') ; 
  }
 
 
 
function order_1() 
{ 
if (document.form.user_id.value==""){
	alert("您需要登陆后才能订购！");
	return false;}
popBox('win');
} 



function $(id){return document.getElementById(id)}
//打开弹出层
function popBox(_div){
    $(_div).style.display ="block";
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
    var bgObj = document.createElement("div");
    bgObj.id = "bg_obj";
    bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=50);opacity:0.5;background-color:#000000;z-index:101;";
    document.body.appendChild(bgObj);
	}

//关闭弹出层
function closeBox(_div){
    $(_div).style.display = "none";
    bgObj = $("bg_obj");
    document.body.removeChild(bgObj);
}


function Trim(inputString) {

   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length - 1, retValue.length);
	
   while (ch == " ") { 
      retValue = retValue.substring(0, retValue.length - 1);
      ch = retValue.substring(retValue.length - 1, retValue.length);
   }
	

   while (retValue.indexOf("  ") != -1) {
	
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
   }
   
   retValue =retValue.replace(/\&nbsp;/gi,'');
   
   return retValue; 
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function service(){
void(window.open('service/chat_guest.php','','width=608,height=400,location=no,resizable=0,scrollbars=0,status=no,toolbar=no,menubar=no,top=100,left=200,depended=no'));
}


function AddFavorite(sURL, sTitle)
{
   try
   {
       window.external.addFavorite(sURL, sTitle);
   }
   catch (e)
   {
       try
       {
           window.sidebar.addPanel(sTitle, sURL, "");
       }
       catch (e)
       {
           alert("加入收藏失败，请使用Ctrl+D进行添加");
       }
   }
}


function checkuser()   
{
	
	
	flag=true;
 var pattern=/^\w+$/; 
var flag=pattern.test(document.form.s1.value);   
   if (!flag){
	   document.getElementById("t1").innerHTML="含有非法字符!";
	   document.getElementById("p1").innerHTML='<img src=images/tanhao.gif />';
	   document.form.s1.focus();
	   document.form.s1.value="";
	    hf=false;
	   return false;
   }
document.getElementById("p1").innerHTML="<img src=images/loading.gif />"; 
document.getElementById("t1").innerHTML="正在查询,请稍候..."; 
var url="check_user.php?login_name="+document.form.s1.value;
 var zf =AJAX(url);
  if (zf==0)
{
	 document.getElementById("t1").innerHTML="恭喜,您可以使用这个名字!";
	 document.getElementById("p1").innerHTML='<img src=images/dagou.gif />';
	 document.form.s2.focus();
	 hf=true;
	}
	 if (zf==1){
	document.getElementById("t1").innerHTML="用户名已存在！";
	 document.getElementById("p1").innerHTML='<img src=images/tanhao.gif />';
	   document.form.s1.value="";
	    document.form.s1.focus();
		 hf=false;
	   return false;
		}
}

function checkpwd()   
{
	flag=true;
 var pattern=/^\w+$/; 
var flag=pattern.test(document.form.s2.value);   
var flag1=document.form.s2.value.length;
   if ((!flag)||(flag1<6)||(flag1>12)){
	   document.getElementById("t2").innerHTML="6-12个英文或数字";
	   document.getElementById("p2").innerHTML='<img src=images/tanhao.gif />';
	   document.form.s2.value="";
	    document.form.s2.focus();
		 hf=false;
	   return false;
   }
   document.getElementById("p2").innerHTML='<img src=images/dagou.gif />';
   document.getElementById("t2").innerHTML="密码验证通过！";
   hf=true;
}

function checkpwd1()   
{
 
   if ((document.form.s2.value!=document.form.s3.value)&&(!checkspace(document.form.s2.value))){
	   document.getElementById("t3").innerHTML="密码不一致!";
	   document.getElementById("p3").innerHTML='<img src=images/tanhao.gif />';
	   document.form.s3.value="";
	     document.form.s3.focus();
		  hf=false;
	   return false;
   }
   if ((document.form.s2.value=document.form.s3.value)&&(!checkspace(document.form.s2.value))){
   document.getElementById("p3").innerHTML='<img src=images/dagou.gif />';
    document.getElementById("t3").innerHTML="密码验证通过！";
  document.form.s4.focus();
   hf=true;}
}

function checkemail()   
{
	
      para=document.form.s4.value;
	
      var  pattern1=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
      flag1=pattern1.test(para);  

 
   if (!flag1){
    
	document.getElementById("t4").innerHTML="email验证未通过!";
	   document.getElementById("p4").innerHTML='<img src=images/tanhao.gif />';
	  document.form.s4.focus();
	   hf=false;
	   return false;
 
   }
 
 document.getElementById("p4").innerHTML='<img src=images/dagou.gif />';
    document.getElementById("t4").innerHTML="email信息验证通过！";
    hf=true;  
	 }


function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}

function checkform() { 

checkemail();	

if (!hf){
	alert('信息输入有错误！请检查！');
	return false;}
	
if (!document.form.s5.checked){
	alert('您没有同意注册协议！');
	return false;}
    document.form.action='user_save.php';
	document.form.submit();
	
}

  function   quit()   
  {   

  if  
   (confirm("你确定要退出登陆状态吗？") ) 
  {   
window.location.href='login_out.php';
  }   
  }  
  
  function go_page(i)
{document.getElementById("page").value=i;
document.form.submit();}



function save_q(){
	if(checkspace(document.form.content.value)){alert('您没有任何留言!');return false;}
	if(checkspace(document.form.email.value)){alert('您没有任何留下Email!');return false;}
	document.form.action='index_7_save.php';
	document.form.submit();
	}
