// 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 Key_Down_seo_1()
{ 
  document.form.page.value="-1";
　document.form.action="index_second.php";
    document.form.submit();
}

function Key_Down_seo_2()
{
	document.form.page.value="-1";
　　if (event.keyCode == 13)
　　{
　　　　event.returnValue=false;
　　　　event.cancel = true;
    document.form.action="index_second.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 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();
	}
	
//图片旋转
 var Car_Image_Width=160;   // 
 var Car_Image_Height=100;
 var Car_Border=true;  // true or false
 var Car_Border_Color="#000";
 var Car_Speed=2;
 var Car_Direction=true;  // true or false
 var Car_NoOfSides=12;  // must be 4, 6, 8 or 12
/* array to specify images and optional links. 
 For 4 sided carousel specify at least 2 images
 For 6 sided carousel specify at least 3
 For 8 sided carousel specify at least 4
 For 12 sided carousel specify at least 6
 If Link is not needed keep it ""
*/
 Car_Image_Sources=new Array(
  "images/img_1.png","#",
  "images/img_2.png","#",
  "images/img_3.png","#",
  "images/img_4.png","#",
  "images/img_5.png","#",
  "images/img_6.png","#",
  "images/img_7.png","#"
  );
/***************** DO NOT EDIT BELOW **********************************/
 CW_I=new Array(Car_NoOfSides/2+1);C_ClcW=new Array(Car_NoOfSides/2);
 C_Coef=new Array(
  3*Math.PI/2,0,3*Math.PI/2,11*Math.PI/6,Math.PI/6,3*Math.PI/2,7*Math.PI/4, 0,
  Math.PI/4,3*Math.PI/2,5*Math.PI/3,11*Math.PI/6,0,Math.PI/6,Math.PI/3);
 var C_CoefOf=Car_NoOfSides==4?0:Car_NoOfSides==6?2:Car_NoOfSides==8?5:9;
 C_Pre_Img=new Array(Car_Image_Sources.length);
 var C_Angle=Car_Direction?Math.PI/(Car_NoOfSides/2):0,C_CrImg=Car_NoOfSides,C_MaxW,C_TotalW,
 C_Stppd=false,i,C_LeftOffset,C_HalfNo=Car_NoOfSides/2;
 function Carousel(){
  if(document.getElementById){
   for(i=0;i<Car_Image_Sources.length;i+=2){
    C_Pre_Img[i]=new Image();C_Pre_Img[i].src=Car_Image_Sources[i]}
   C_MaxW=Car_Image_Width/Math.sin(Math.PI/Car_NoOfSides)+C_HalfNo+1;
   Car_Div=document.getElementById("Carousel");
   for(i=0;i<C_HalfNo;i++){
    CW_I[i]=document.createElement("img");Car_Div.appendChild(CW_I[i]); 
    CW_I[i].style.position="absolute";
    CW_I[i].style.top=0+"px";
    CW_I[i].style.height=Car_Image_Height+"px";
    if(Car_Border){
     CW_I[i].style.border="solid";
     CW_I[i].style.borderWidth=1+"px";
     CW_I[i].style.borderColor=Car_Border_Color}
    CW_I[i].src=Car_Image_Sources[2*i];
    CW_I[i].lnk=Car_Image_Sources[2*i+1];
    CW_I[i].onclick=C_LdLnk;
    CW_I[i].onmouseover=C_Stp;
    CW_I[i].onmouseout=C_Rstrt}
   CarImages()}}
 function CarImages(){
  if(!C_Stppd){
   C_TotalW=0;
   for(i=0;i<C_HalfNo;i++){
    C_ClcW[i]=Math.round(Math.cos(Math.abs(C_Coef[C_CoefOf+i]+C_Angle))*Car_Image_Width);
    C_TotalW+=C_ClcW[i]}
   C_LeftOffset=(C_MaxW-C_TotalW)/2;
   for(i=0;i<C_HalfNo;i++){
    CW_I[i].style.left=C_LeftOffset+"px";
    CW_I[i].style.width=C_ClcW[i]+"px";
    C_LeftOffset+=C_ClcW[i]}
   C_Angle+=Car_Speed/720*Math.PI*(Car_Direction?-1:1);
   if((Car_Direction&&C_Angle<=0)||(!Car_Direction&&C_Angle>=Math.PI/C_HalfNo)){
    if(C_CrImg==Car_Image_Sources.length)C_CrImg=0;
    if(Car_Direction){
     CW_I[C_HalfNo]=CW_I[0];
     for(i=0;i<C_HalfNo;i++)CW_I[i]=CW_I[i+1];
     CW_I[C_HalfNo-1].src=Car_Image_Sources[C_CrImg];
     CW_I[C_HalfNo-1].lnk=Car_Image_Sources[C_CrImg+1]}
    else{ for(i=C_HalfNo;i>0;i--)CW_I[i]=CW_I[i-1];
     CW_I[0]=CW_I[C_HalfNo];
     CW_I[0].src=Car_Image_Sources[C_CrImg];
     CW_I[0].lnk=Car_Image_Sources[C_CrImg+1]}
    C_Angle=Car_Direction?Math.PI/C_HalfNo:0;C_CrImg+=2}}
  setTimeout("CarImages()",50)}
 function C_LdLnk(){if(this.lnk)window.location.href=this.lnk}
 function C_Stp(){this.style.cursor=this.lnk?"pointer":"default";C_Stppd=true;}
 function C_Rstrt(){C_Stppd=false}
 
 //图片旋转
 
 //客服悬浮
var tips;
var theTop = 230;
var old = theTop;    
   
function initFloatTips() {    
   
tips = document.getElementById('floatTips');    
   
tips.style.left= window.screen.width-150 + "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;
                  }
      }
}

