function GE(a){return document.getElementById(a);}	

function createXMLHttps()		
{
  var ret = null;				
  try {
    ret = new ActiveXObject('Msxml2.XMLHTTP');
  }
  catch (e) {
    try {
       ret = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (ee) {
       ret = null;
    }
  }
  if (!ret && typeof XMLHttpRequest != 'undefined')
     ret = new XMLHttpRequest();
    return ret;
}


function putingwc(spid){
 var SendData; 
   if(spid=="") spid="*";
   var X = createXMLHttps();
   if(X){
     X.onreadystatechange=function(){
     if(X.readyState==4){
       if(X.status==200){					
	   	 if(X.responseText=="1"){
			alert("Product "+sp_z_id(spid)+" has been added in your cart");
			GE("sp"+spid).innerHTML="<img src=../images/gou.gif>";
		 }else{
			alert("Add faild");	 
		}
       }
     }
    };
    X.open('POST','../order/cart_add.asp',true);				
    X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
    SendData = 'spid='+escape(spid);
    X.send(SendData);
   }
  }


function tofavorite() {
if (window.sidebar) {
	window.sidebar.addPanel("Bjbead.com-Discount jewelry,cheap jewelry,handmade jewelry center in China","http://www.bjbead.com/","");
} else if( document.all ) {
	window.external.addFavorite("http://www.bjbead.com/","Bjbead.com-Discount jewelry,cheap jewelry,handmade jewelry center in China");
} else if( window.opera && window.print ) {
return true;
}
}



function picClick(pid){
	GE("smallpic").src=GE(pid).src;
	try{
	GE("bigpic").src=GE(pid).src;
	}catch(e){}
	GE(pid).className="current";
	for(i=1;i<5;i++){
		if(pid!="bspic"+i){
			GE("bspic"+i).className="";
		}
	}
}

	function onsearch(obj){
		if(obj.value=="keywords or ID"){
			obj.value="";
			obj.className="search-col";
		}
	}
/*第一种形式 第二种形式 更换显示样式*/
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
}

function trim(str){   
 return str.replace(/(^\s*)|(\s*$)/g, "");    
}    
function ltrim(str){ 
 return str.replace(/(^\s*)/g,"");    
}    
function rtrim(str){ 
 return str.replace(/(\s*$)/g,"");    
}    

function checkSearch(obj){
	if(trim(obj.keyword.value)=="" || obj.keyword.value.toLowerCase()=="use id or keyword")	{
		alert("Please input the ID or keyword to search!");
		obj.keyword.focus();
		return false;
	}
}

//function isingwc(){
// var SendData,spstr,i; 
//   if(spid=="") spid="*";
//   var X = createXMLHttps();
//   if(X){
//     X.onreadystatechange=function(){
//     if(X.readyState==4){
//       if(X.status==200){	
//	   	 spstr=X.responseText.split(",");
//	   	 if(spstr[0]=="1"){
//			try{ 
//			  for(i=1;i<spstr.length;i++){
//				GE("sp"+spstr[i]).innerHTML="<img src=../images/gou.gif>";
//			  }
//			}catch(e){}
//		 }
//       }
//     }
//    };
//    X.open('POST','../order/isInCart.asp',true);				
//    X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
//    SendData = '';
//    X.send(SendData);
//   }
//  }

function sp_z_id(id){
	var id_zhuan_num_z="";
	if(id>=1 && id<=5000){
		id_zhuan_num_z=id;
	}else if(id>=5001 && id<=10000){
		id_zhuan_num_z=id;	
	}else if(id>=10001 && id<=15000){
		id_zhuan_num_z="A"+(id-10000);
	}else if(id>=15001 && id<=20000){
		id_zhuan_num_z="B"+(id-15000);
	}
	return id_zhuan_num_z
}

function logincheck(){							//User Login
   if (document.userlogin.Form_username.value == '')	{
	 alert("Please fill in the username！");
  	 document.userlogin.Form_username.focus();
	 return false;
	}
    if (document.userlogin.Form_password.value == '')	{
	 alert("Please fill in the password！");
  	 document.userlogin.Form_password.focus();
	 return false;
	}
	 return true;
}

function info_back(spid){
	if(readcookie("spid").indexOf(spid)!=-1){
		history.go(-1);
		window.location.reload();
	}else{
		history.go(-1);
	}
}

function getpwd(){
  window.open("../password.html","getpwd","height=396, width=610,top=200, left=350, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no")
}

function getpwdCheck(obj){
	 if(obj.email.value.length<2){
	   alert("Please input your Email.\n");
	   obj.email.focus();
	   return false;
	 }else{
		if (obj.email.value.charAt(0)=="." ||        
			 obj.email.value.charAt(0)=="@"||       
			 obj.email.value.indexOf('@', 0) == -1 || 
			 obj.email.value.indexOf('.', 0) == -1 || 
			 obj.email.value.lastIndexOf("@")==obj.email.value.length-1 || 
			 obj.email.value.lastIndexOf(".")==obj.email.value.length-1)
		 {
		  alert("Please fill in the correct mail address!\n");
		  obj.email.focus();	  
		  return false;
		  }
	 }
}


function Confirmer()                //del all product
{
if (confirm("Are you sure to delete all products in your cart?")){
window.location.href='consigner.asp?action=del';
}
}
function Confirmwish()                //del all product
{
if (confirm("Are you sure to delete all products in your wishlist?")){
window.location.href='wishlist.asp?action=del';
}
}

var navigatorName = "Microsoft Internet Explorer";   
var isIE = false;   
if(navigator.appName==navigatorName) isIE = true; 

function OpenMWin(url,w,h)
{
    var theDes = "status:no;center:yes;help:no;minimize:no;maximize:no;dialogWidth:"+w+"px;scroll:no;dialogHeight:"+h+"px;border:think";
    return self.showModalDialog(url,null,theDes);
}

function openwin(url){
  if(isIE==true){
	OpenMWin("../"+url,625,580);
  }else{
  	window.open("../"+url,'larger picture','status=no,scrollbars=auto,top=200,left=310,width=625,height=580');
  }
}

function addsp(spid,money){						//click "+" start  
	var spmoney=GE("zongji"+spid).value;
	GE("geshu"+spid).value=Number(GE("geshu"+spid).value)+1;
	GE("zongji"+spid).value="$"+Math.round((eval(GE('geshu'+spid).value)*eval(money))*100)/100;
}													//click "+"  end 

function jiansp(spid,money){						//click "-" start  
	var spmoney=GE("zongji"+spid).value;
	GE("geshu"+spid).value=Number(GE("geshu"+spid).value)-1;
	if(eval(GE('geshu'+spid).value)>0){
		GE("zongji"+spid).value="$"+Math.round((eval(GE('geshu'+spid).value)*eval(money))*100)/100;
	}else{
		GE("geshu"+spid).value=0;
		GE("zongji"+spid).value=0;
	}
}													//click "-"  end 

function gwayspshu(spid,money){						//input in textbox   start
  if(isNaN(GE('geshu'+spid).value)){
	 alert("请输入数字");
	 GE('geshu'+spid).value=0;
  }else{
	if(eval(GE('geshu'+spid).value)>0){
		GE("zongji"+spid).value="$"+Math.round((eval(GE('geshu'+spid).value)*eval(money))*100)/100;
	}else{
		GE("geshu"+spid).value=0;
		GE("zongji"+spid).value=0;
	}
  }
}													//input in textbox    end 

function openKFWin(){
  var url="http://www1.53kf.com/webCompany.php?arg=ayjewelry&style=5&language=en&lytype=0&charset=gbk&kflist=off&kf=007&zdkf_type=1&tpl=crystal_blue";
  	window.open(url,'LiveCheat','status=no,scrollbars=auto,resizable=no,top=200,left=310,width=700,height=472');
//  if(isIE==true){
//	OpenMWin(url,700,472);
//  }else{
//  	window.open(url,'Live Cheat','status=no,scrollbars=auto,top=200,left=310,width=700,height=472');
//  }
}



function rate(obj,oEvent){ 
var imgSrc = 'http://www.bjbead.com/images/star0.gif'; 
var imgSrc_2 = 'http://www.bjbead.com/images/star1.gif'; 
//--------------------------------------------------------------------------- 
if(obj.rateFlag) return; 
var e = oEvent || window.event; 
var target = e.target || e.srcElement;  
var imgArray = obj.getElementsByTagName("img"); 
for(var i=0;i<imgArray.length;i++){ 
   imgArray[i]._num = i; 
   imgArray[i].onclick=function(){ 
    if(obj.rateFlag) return; 
    obj.rateFlag=true; 
	GE("star").value=this._num+1;
   }; 
} 
if(target.tagName=="IMG"){ 
   for(var j=0;j<imgArray.length;j++){ 
    if(j<=target._num){ 
     imgArray[j].src=imgSrc_2; 
	 GE("star").value=target._num+1;
    } else { 
     imgArray[j].src=imgSrc; 
	 GE("star").value=target._num+1;
    } 
   } 
} else { 
   for(var k=0;k<imgArray.length;k++){ 
    imgArray[k].src=imgSrc; 
   } 
} 
} 

function checkReview(obj){
	if(obj.nickname.value==""){
		alert("Please input your nickname");	
		obj.nickname.focus();
		return false;
	}
	if(obj.title.value==""){
		alert("Please input the title");	
		obj.title.focus();
		return false;
	}
	if(obj.content.value==""){
		alert("Please input the review");	
		obj.content.focus();
		return false;
	}else{
		if(obj.content.value.length>500){
		alert("The review should less than 500 letters");	
		obj.content.focus();
		return false;
		}
	}
	if(!obj.agreeCon.checked){
		alert("You must agree to our Terms of conditions Terms and Conditions.");	
		obj.agreeCon.focus();
		return false;
	}
}



