// JavaScript Document
function find_city(){
	var   city_id=document.form.city_id; 
	for(var i = city_id.options.length; i > 0; i--) {
    city_id.remove(city_id.options[i]);}
	city_id.options[0]= new Option("请选择城市","");
 var url="super/check_city.php?province_id="+document.form.province_id.value;
 var zf =AJAX(url);
   k=zf.indexOf("$") ;
   h=zf.substring(0,k);
   zf=zf.substring(k+1);
   
   for(j=1;j<=h;j++){
   m=zf.indexOf("^") ;
   p=zf.substring(0,m);
   zf=zf.substring(m+1);
   r=zf.indexOf("#") ;
   s=zf.substring(0,r);
   zf=zf.substring(r+1);
   city_id.options[j]= new Option(s,p);
		}

}


function find_area(){
	var   area_id=document.form.area_id; 
			for(var i = area_id.options.length; i > 0; i--) {
    area_id.remove(area_id.options[i]);}
	area_id.options[0]= new Option("请选择区县","");
 var url="super/check_area.php?city_id="+document.form.city_id.value;
var zf =AJAX(url);
   k=zf.indexOf("$") ;
   h=zf.substring(0,k);
   zf=zf.substring(k+1);
   
   for(j=1;j<=h;j++){
   m=zf.indexOf("^") ;
   p=zf.substring(0,m);
   zf=zf.substring(m+1);
   r=zf.indexOf("#") ;
   s=zf.substring(0,r);
   zf=zf.substring(r+1);
   area_id.options[j]= new Option(s,p);
		}
}

function Key_submit(url)
{
　　if (event.keyCode == 13)
　　{
　　　　event.returnValue=false;
　　　　event.cancel = true;
    Check_Login(url);
　　}
}

// JavaScript Document
function find_city_1(){
	var   city_id=document.form.city_id_1; 
	for(var i = city_id.options.length; i > 0; i--) {
    city_id.remove(city_id.options[i]);}
	city_id.options[0]= new Option("请选择城市","");
 var url="super/check_city.php?province_id="+document.form.province_id_1.value;
 var zf =AJAX(url);
   k=zf.indexOf("$") ;
   h=zf.substring(0,k);
   zf=zf.substring(k+1);
   
   for(j=1;j<=h;j++){
   m=zf.indexOf("^") ;
   p=zf.substring(0,m);
   zf=zf.substring(m+1);
   r=zf.indexOf("#") ;
   s=zf.substring(0,r);
   zf=zf.substring(r+1);
   city_id.options[j]= new Option(s,p);
		}

}


function find_area_1(){
	var   area_id=document.form.area_id_1; 
			for(var i = area_id.options.length; i > 0; i--) {
    area_id.remove(area_id.options[i]);}
	area_id.options[0]= new Option("请选择区县","");
 var url="super/check_area.php?city_id="+document.form.city_id_1.value;
var zf =AJAX(url);
   k=zf.indexOf("$") ;
   h=zf.substring(0,k);
   zf=zf.substring(k+1);
   
   for(j=1;j<=h;j++){
   m=zf.indexOf("^") ;
   p=zf.substring(0,m);
   zf=zf.substring(m+1);
   r=zf.indexOf("#") ;
   s=zf.substring(0,r);
   zf=zf.substring(r+1);
   area_id.options[j]= new Option(s,p);
		}
}

function Check_Login(reg_url){ 
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?reg_url="+reg_url;
document.form.submit();

} 


function Key_Down(object)
{
　　if (event.keyCode == 13)
　　{
　　　　event.returnValue=false;
　　　　event.cancel = true;
    if (object=="enter"){document.form.submit();}
	else{document.getElementById(object).focus();}
　　}
}


function Key_Down_seo(object)
{
　　if (event.keyCode == 13)
　　{
　　　　event.returnValue=false;
　　　　event.cancel = true;
   document.form.action='index_search.php';
      document.form.submit();
	
　　}
}





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 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;
if (i=="-1"){document.form.action="index_search.php";}
document.form.submit();}



function vote(){
      what_vote=""; vote_no=0;
	 var n= document.getElementsByTagName('input');
		 for (i=0;i<n.length;i++)
		 {
		if (document.form.elements[i].checked){
			vote_id=document.form.elements[i].id;
			vote_value=Get_Radio(vote_id);
			vote_id=vote_id.replace("what_vote_","");
			what_vote+=vote_id+"|"+vote_value+",";
			vote_no=vote_no+1;
			 }
		 }
		 if (vote_no<document.form.vote_no.value){alert("请选择所有的调查问题!谢谢！"); return false;}
			document.form.what_vote.value=what_vote;
			document.form.action="index_vote_save.php";
			document.form.submit();
	
	}
	
function find_point(){
	document.form.action='index_point.php';
	document.form.submit();}

function save_q(){
	if(checkspace(document.form.user_id.value)){alert('您必须登陆后才能留言!');return false;}
	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();
	}
//客服悬浮
var tips;
var theTop = 230;
var old = theTop;    
   
function initFloatTips() {    
   
tips = document.getElementById('floatTips');    
   
tips.style.left= window.screen.width-320 + "px";    
   
moveTips();    
   
}

function moveTips() {    
   
var tt=50;    
   
if (window.innerHeight) {    
   
pos = window.pageYOffset    
   
}    
   
else if (document.documentElement && document.documentElement.scrollTop) {    
   
pos = document.documentElement.scrollTop    
   
}    
   
else if (document.body) {    
   
pos = document.body.scrollTop;    
   
}    
   
pos=pos-tips.offsetTop+theTop;    
   
pos=tips.offsetTop+pos/10;    
   
if (pos < theTop) pos = theTop;    
   
if (pos != old) {    
   
tips.style.top = pos+"px";    
   
tt=10;    
   
}    
   
old = pos;    
   
setTimeout(moveTips,tt);    
   
}  


 //客服悬浮
 


var proMaxHeight = 550;
var proMaxWidth = 690;
function adjustIMG(ImgD){
      var image=new Image();
      image.src=ImgD.src;
      if(image.width>0 && image.height>0){
      var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
    if(rate <= 1){   
     ImgD.width = image.width*rate;
     ImgD.height =image.height*rate;
    }
    else {
                          ImgD.width = image.width;
                          ImgD.height =image.height;
                  }
      }
}



