function checkSearchForm()
{
	if(document.quick_find_header.keyWord.value=="")
	{
	
		document.quick_find_header.searchType.value=100;
		document.quick_find_header.keyWord.value='All Products';

	
	}
	
	return true;

}


function hideElement(name)
{

	var divs = document.getElementsByName(name); 
	
	for (var i=0; i<divs.length; i++) 
	{
		divs[i].style.display = "none"; 

	}
	
	//window.alert("hide all");
	
}


	
	function mouseUp(self)
	{

		self.style.background="#efefef";

	}
	
	function mouseOut(self)
	{
		self.style.background="#FFFFFF";
	
	}

	
	
	function selectFilterOption(self,p1,value)
	{
		var input=document.getElementById(p1);
		
		input.value = self.innerHTML;
		
		document.searchForm.searchType.value=value;
		
	}
	
	
	function selectSortOption(self,p1,value)
	{
	
		var input=document.getElementById(p1);
		
		input.value = self.innerHTML;
		
		document.searchForm.orderBy.value=value;
			
	}
	



function CoLeeSelect(thisObj)
{
 var thisinput = thisObj.getElementsByTagName("input");
 var thisul = thisObj.getElementsByTagName("ul");
 var thisli = thisul[0].getElementsByTagName("li");
 
 if(thisObj.id != "CoLeeSelect")
 {
	  thisObj.id = "CoLeeSelect";
	  thisObj.focus();
	  thisul[0].style.display = "";
	  
  }
  else
  {
  
   	ObjBlur();
   	
  }
  
  thisObj.onblur = ObjBlur;
  
  
  function ObjBlur()
  {
	   thisObj.id =  "";
	   thisul[0].style.display = "none";
	   
  }
 }
	



function  changeStyle(item,style)
{
			
	item.className=style;	
}


function  changesrc(item,img)
{
			
	//item.className=style;	

	item.src="images/"+img;
}


	function selectImage(img)
	{
		var dImage=document.getElementById("dImage");
		
		if(dImage!=null)
		{
			dImage.src=img.src;
		}
		
	}


function checkEnquiryForm()
{
	if(document.enquiryForm.name.value=="")
	{
		window.alert("name is empty!");
		document.enquiryForm.name.focus();
		
		return false;
		
	}
	
	if(document.enquiryForm.email.value=="")
	{
		window.alert("emailis empty!");
		document.enquiryForm.email.focus();
		
		return false;
		
	}
	
	
	if(document.enquiryForm.phone.value=="")
	{
		window.alert("phoneis empty!");
		document.enquiryForm.phone.focus();
		
		return false;
		
	}
	
	if(document.enquiryForm.enquiry.value=="")
	{
		window.alert("enquiryis empty!");
		document.enquiryForm.enquiry.focus();
		
		return false;
		
	}
}


	function expandItem(id)
	{
		var div=document.getElementById("child"+id);
		
		var div1=document.getElementById("div"+id);

		
		var jt=document.getElementById("jt"+id);
		
		if(div!=null)
		{
			var className=div.className;
			

			if(className=="hideDiv")
			{
				div.className="showDiv";
				div.style.display="block";
				
				jt.className="jt1";
								
				div1.className="leftitemArticleTitle2";
				
				
				

			}
			else
			{
				
				div.style.display="none";

				div.className="hideDiv";
							
				jt.className="jt";
		
				
				div1.className="leftitemArticleTitle";
	
			}
		
		}
		
	}
	
	
function loadImg(url,img,d)
	{
	
		
        var day="";
        
        var mydate=new Date(); 
        
        d = d.replace(/-/g, "/");
        
		var newdate=new Date(d);  
      
        
        var times= mydate.getTime() - newdate.getTime(); 
        
		var day = parseInt(times/ (1000 * 60 * 60 * 24));

        
        if(day<=5)
        {
        
        		img.src=url+"images/is_new.gif";
        }
        
        else
        {
        		img.src=url+"images/blank.gif";

        
        }

	
	}
	
	
	
	
	
	function addEmail(email)
	{
	
		var emailTag=document.getElementById(email);
		var emailValue=emailTag.value;
		
		if(emailValue!="" && emailValue!="Your Email Address")
		{
	
			var oBao;
										
										try { 
												oBao= new ActiveXObject("Msxml2.XMLHTTP");
												} 
												catch(ex) { 
												try { 
												oBao= new ActiveXObject("Microsoft.XMLHTTP"); 
												} 
												catch(except) { 
												oBao= false; 
												} 
												} 
												
												// thank goodness!! they at least aren't using that...let's check for real support. 
												if(!oBao&& typeof XMLHttpRequest != 'undefined') { 
												oBao= new XMLHttpRequest( ); 
												} 
									
									
	
			oBao.open("POST","addMail.action",false);
	
			oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	    	oBao.send("email="+emailValue);
	    		
	    	var resultStr=unescape(oBao.responseText);
	    
	 
			window.alert(resultStr);
	

		}
		else
		{
		
			window.alert("Email Address is required.");
			
			emailTag.focus();
		}
		
	
	}

/*	
	function addEmail(email)
	{
	
		var emailValue=document.getElementById(email).value;

		if(emailValue!="" && emailValue!="Your Email Address")
		{
		
			if
	
			var oBao;
										
										try { 
												oBao= new ActiveXObject("Msxml2.XMLHTTP");
												} 
												catch(ex) { 
												try { 
												oBao= new ActiveXObject("Microsoft.XMLHTTP"); 
												} 
												catch(except) { 
												oBao= false; 
												} 
												} 
												
												// thank goodness!! they at least aren't using that...let's check for real support. 
												if(!oBao&& typeof XMLHttpRequest != 'undefined') { 
												oBao= new XMLHttpRequest( ); 
												} 
									
									
	
			oBao.open("POST","addMail.action",false);
	
			oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	    	oBao.send("email="+emailValue);
	    		
	    	var resultStr=unescape(oBao.responseText);
	    
		}
		else
		{
		
			window.alert("Email Address is required.");
			
			document.mailSubscription.mailAddress.focus();
		}
		
	
	}
	*/
	
	function addFavorites(pName,pid,path,fileName)
	{
	
		
		if(pName!="" && pid!="")
		{
	
			var oBao;
										
										try { 
												oBao= new ActiveXObject("Msxml2.XMLHTTP");
												} 
												catch(ex) { 
												try { 
												oBao= new ActiveXObject("Microsoft.XMLHTTP"); 
												} 
												catch(except) { 
												oBao= false; 
												} 
												} 
												
												// thank goodness!! they at least aren't using that...let's check for real support. 
												if(!oBao&& typeof XMLHttpRequest != 'undefined') { 
												oBao= new XMLHttpRequest( ); 
												} 
									
									

	
			oBao.open("POST","addFavorites.action",false);
	
			oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	    	oBao.send("pName="+pName+"&pid="+pid);
	    		
	    	var resultStr=unescape(oBao.responseText);
	    
	    	
	    	
			
			if(resultStr=="sessiontimeout")
			{
				window.alert("thanks your interesting.please sign in.");
			
				window.location.href=path+"/login.jsp?rpage=../products/"+fileName;
			
			}
			else
			{
				var status=document.getElementById("statusP");
		
				var thankP=document.getElementById("thankP");
				
				//var nameP=document.getElementById("nameP");
				
				
				var img=document.getElementById("statusIMG");
		
				img.src="images/favorite.jpg";
				
				thankP.innerHTML="Thank you interesting!";
				
				//nameP.innerHTML=pName;

				status.innerHTML=resultStr;
				
				showDiv("addResult");
			
			}
			
			
			
		

		

	

		}
		else
		{
		
			window.alert("Parameters  is required.");
			
			

		}
		
	
	}
	
	
	function addInquiry(pid)
	{
		var nameInput=document.getElementById("inquireName");
		
		var emailInput=document.getElementById("inquireEmail");
		
		var contentInput=document.getElementById("inquireContent");
	
		var vcodeInput=document.getElementById("vcode");
		
		var name=nameInput.value;
		var email=emailInput.value;
		var content=contentInput.value;
		var vcode=vcodeInput.value;
		
		if(name!="" && email!="" && content!="" && pid!=""  && vcode!="")
		{
		
			
			
			var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
	 		var flag = pattern.test(email); 
	 		if(!flag)
	 		{ 
	 			window.alert("Email Address is wrong.");

				emailInput.focus();
				
	  			return false; 
	 		} 

	
			var oBao;
										
										try { 
												oBao= new ActiveXObject("Msxml2.XMLHTTP");
												} 
												catch(ex) { 
												try { 
												oBao= new ActiveXObject("Microsoft.XMLHTTP"); 
												} 
												catch(except) { 
												oBao= false; 
												} 
												} 
												
												// thank goodness!! they at least aren't using that...let's check for real support. 
												if(!oBao&& typeof XMLHttpRequest != 'undefined') { 
												oBao= new XMLHttpRequest( ); 
												} 
									
									

	
			oBao.open("POST","addInquire.action",false);
	
			oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	    	oBao.send("inquire.name="+name+"&inquire.email="+email+"&inquire.content="+content+"&pid="+pid+"&type=2&inquireCode="+vcode);
	    		
	    	var resultStr=unescape(oBao.responseText);
	    
			
			if(resultStr.indexOf("success")==-1)
			{
				window.alert(resultStr);
				vcodeInput.value="";
		
			}
			else
			{
				nameInput.value="";
				emailInput.value="";
				contentInput.value="";
				vcodeInput.value="";
				
				var status=document.getElementById("statusP");
		
				var thankP=document.getElementById("thankP");
				
				
				var img=document.getElementById("statusIMG");
		
				img.src="images/inquiry.jpg";
				
				thankP.innerHTML="Thank for you inquiry!";
				

				status.innerHTML="We will contact you soon.";
				
				showDiv("addResult");
			
			}
			
		}
		else
		{

		
			if(name=="")
			{
				window.alert("Your Name is required.");
				
				nameInput.focus();
			}
			else if(email=="")
			{
				window.alert("Your Email is required.");
				
				emailInput.focus();

			}
			else if(content=="")
			{
				window.alert("Content is required.");
				
				contentInput.focus();

			}
			else if(pid=="")
			{
				window.alert("ProductName is required.");

			}
			else if(vcode=="")
			{
				window.alert("Verification code is required.");
				
				vcodeInput.focus();

			}

	

		}
		
	
	}




function countExpressFee(weight,rate)
{

	if(weight<=0)
	{		
			return 0.0;
			
	}
	
	var total=0.00;

	var a=0;
	
	a=parseInt((weight-0.5)/0.5);
		
	if((weight-0.5)%0.5>0)
	{	
	
		a++;
	}
		
	var b=a*50;
		
	total=parseFloat(200+b+120);
			
	return total.toFixed(1)/rate;

	
}


function countHKPostFee(weight,rate)
{

	

	if(weight<=0)
	{		
			return 0.0;
			
	}
	
	
	var total=0.00;

	
	var hk=0;
	
	hk=parseFloat(weight);
		
	total=parseFloat(130*hk+20);
	
	return total.toFixed(1)/rate;


}





function countFreightFee(weight,rate)
{

	

	if(weight<=0)
	{		
			return 0.0;
			
	}
	
	
	var total=0.00;
	
	if(weight<=2)
	{
		//hongkong post
	
		var hk=0;
		hk=parseFloat(weight);
		
		total=parseFloat((130*hk+20)/6.3);


	}
	else
	{
		//DHL
	
		var a=0;
		a=parseInt((weight-0.5)/0.5);
		
		if((weight-0.5)%0.5>0)
		{
			
	
			a++;
		}
		
		var b=a*50;
		
		total=parseFloat((200+b+120)/6.3);
		
		
	}
	
	return total.toFixed(1)/rate;

	

}



	function addToCart(item_no,item_name,item_weight,rate,priceString,eType,moqValue)
	{
		
		var quan=document.getElementById("quantityTextBox");
		
		var priceInput=document.getElementById("priceInput");

		var item_price=priceInput.value;
		
		

		var result;
			
		if(quan!=null)
		{
			var qValue=quan.value;
			
			var pattern  = /^[0-9]*[1-9][0-9]*$/;
		
	 		var flag = pattern.test(qValue); 
	 		
	 	
	 		if(!flag)
	 		{ 
	 			window.alert("Quantity must be figure!");
  			
  				quan.value="";
  				
  				return;
	 		}
	 		else
	 		{
	 		
	 							
				if(qValue<moqValue)
				{
				
					window.alert("Quantity  must be greater than or equal to the minimum order quantity !");
					
					quan.value=moqValue;
					
					return;
		
				}
				else
				{
					
				
					result=SetOrderForm(item_no,item_name,quan.value,item_price,item_weight,priceString,eType,moqValue);
				}
			}
		}
		else
		{
			
			result=SetOrderForm(item_no,item_name,'1',item_price,item_weight,priceString,eType,moqValue);

		}
		
		
		var status=document.getElementById("statusP");
		
		var thankP=document.getElementById("thankP");
		
		var nameP=document.getElementById("nameP");
		
		
		var img=document.getElementById("statusIMG");

		img.src="images/cart.jpg";
		
		thankP.innerHTML="Thank you for your purchase!";
		
		nameP.innerHTML=item_name;

		if(result=="success")
		{
			
			status.innerHTML="has added to your cart!";
				
		}
		else if(result=="exists")
		{
			
			status.innerHTML="is existing in your cart already!";

		}

		showDiv("addResult");
	
	}
	

	//eType:1:DHL,2:hkPOST,3:Free Shipping
	function changQuantity(eType,value,price,weight,rate,moq)
	{
		
		
		var quan=document.getElementById("quantityTextBox");

		
		var pattern  = /^[0-9]*[1-9][0-9]*$/;
		
 		var flag = pattern.test(value); 
 		
 		if(!flag)
 		{ 
  			window.alert("Quantity must be figure!");
  			
  			quan.value="";
  			
 		} 
		else
		{
		
					var totalWeight=value*weight;
					
					/*if(eType=="2" && totalWeight>2)
					{
					
						window.alert("If the produce over 2 kg, We can not ship it by hongkong post office");
						
						var select=document.getElementById("Delivery");

						curDelivery="1";
						select.options[0].selected = true;  
					}*/
							
				   	if(value<moq)
					{
				
						window.alert("Quantity  must be greater than or equal to the minimum order quantity !");
					
						value=moq;
					
						quan.value=value;
					
					
					}

						
					var tempArray=price.split('##');
				
					var curPrice;
				
					if (price.indexOf("**") >0) 
					{
						
						for(var i=0;i<tempArray.length;i++)
						{
							
							var tempString=tempArray[i];
							var tempArray1=tempString.split('**');
							
							if(value>=parseInt(tempArray1[0]) && value<=parseInt(tempArray1[1]))
							{
								curPrice=parseFloat(tempArray1[2]);
								
								
								break;
							}
							
							
				
							if(i==tempArray.length-1)
							{
							
								if(value>parseInt(tempArray1[1]))
								{
									
									curPrice=parseFloat(tempArray1[2]);
																
								}
							}
							
				
						}
					}
					else
					{
						
						curPrice=price;
					
					}
		
				
					var total=document.getElementById("total");
					
					var tempShipping=document.getElementById("shipping");
		
					var priceInput=document.getElementById("priceInput");
			
					if(total!=null)
					{
							curPrice=parseFloat(curPrice);
										
							priceInput.value=curPrice;
												
							var shipping=0.00;
							
							
							if(eType=="3")
							{
								shipping=0.00;
							
								tempShipping.innerHTML="Free Shipping";

							}
							else
							{
							
								if(totalWeight<=2)
								{
								
									if(eType=="2")
									{
										
										shipping=countHKPostFee(totalWeight,rate);
									}
									else if(eType=="1")
									{
										
										shipping=countExpressFee(totalWeight,rate);
			
									}
								
								}
								else
								{
									
									shipping=countExpressFee(totalWeight,rate);
		
								}
								
								tempShipping.innerHTML=shipping.toFixed(2);

							}
	
														
							var tt=value*(parseFloat(curPrice))+parseFloat(shipping);
		
							total.innerHTML=tt.toFixed(2);
		
					}
					
				}
	
	
	}




	function checkReviewForm()
	{

	
		if(document.reviewAdd.rating.value=="")
		{
			window.alert("Please select rating stars. ");
			
			return false;
		}
		
		if(document.reviewAdd.name.value=="")
		{
			window.alert("Please type Your Name.");
			document.reviewAdd.name.focus();
			return false;
		}

		if(document.reviewAdd.email.value=="")
		{
			window.alert("Please type Your Email Address.");
			document.reviewAdd.email.focus();
			return false;
		}
		else
		{
		
			var email=document.reviewAdd.email.value;
			
			var pattern = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
	 		flag = pattern.test(email); 
	 		if(!flag)
	 		{ 
	 			window.alert("Email Address is wrong.");

				document.reviewAdd.email.focus();
				
	  			return false; 
	 		} 
	 		
		}


		if(document.reviewAdd.content.value=="")
		{
			window.alert("Please type review content.");
			document.reviewAdd.content.focus();

			return false;
		}
		
		if(document.reviewAdd.reviewCode.value=="")
		{
			window.alert("Please type verification code.");
			document.reviewAdd.reviewCode.focus();
			return false;
		}


		
			var oBao;
										
										try { 
												oBao= new ActiveXObject("Msxml2.XMLHTTP");
												} 
												catch(ex) { 
												try { 
												oBao= new ActiveXObject("Microsoft.XMLHTTP"); 
												} 
												catch(except) { 
												oBao= false; 
												} 
												} 
												
												// thank goodness!! they at least aren't using that...let's check for real support. 
												if(!oBao&& typeof XMLHttpRequest != 'undefined') { 
												oBao= new XMLHttpRequest( ); 
												} 
									
									

	
			oBao.open("POST","returnReviewCode.jsp",false);
	
			oBao.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	
	    	oBao.send("");
	    		
	    	var resultStr=unescape(oBao.responseText);
	    
			
			
			if(resultStr.indexOf(document.reviewAdd.reviewCode.value)==-1)
			{
				window.alert("Verification code error.");
				
				document.reviewAdd.reviewCode.value="";
				document.reviewAdd.reviewCode.focus();
				return false;
						
			}
	
	
	}
	
	


	function selectStar(num)
	{
	
		document.reviewAdd.rating.value=num;

	}


	function unSelectStar()
	{
	
		var i=1;
		
		var j=5;
		
		var temp=document.reviewAdd.rating.value;


		if(temp!="")
		{
			for(i=1;i<=temp;i++)
			{
			
				//window.alert(i);
				
				var tempStar=document.getElementById("star"+i);
				
				if(tempStar!=null)
				{
				
					tempStar.src="images/st.gif";
					
				
				}
	
			}
			
			
			for(j=5;j>temp;j--)
			{
			
				var tempStar=document.getElementById("star"+j);
				
				if(tempStar!=null)
				{
				
					tempStar.src="images/ust.gif";
					
				
				}
	
			
			}
		}

	}
	
	
	
	function changeStar(num)
	{
		var i=1;
		
		var j=5;
		
		for(i=1;i<=num;i++)
		{
		
			//window.alert(i);
			
			var tempStar=document.getElementById("star"+i);
			
			if(tempStar!=null)
			{
			
				tempStar.src="images/st.gif";
				
			
			}

		}
		
		for(j=5;j>num;j--)
		{
		
			var tempStar=document.getElementById("star"+j);
			
			if(tempStar!=null)
			{
			
				tempStar.src="images/ust.gif";
				
			
			}

		
		}
	
	}
	
	
	
function showDiv(id)
{
	
		var div=document.getElementById(id);
		
		var buttom=document.getElementById("closeButtom");


		if(div!=null)
		{

			div.style.display="block";
			
			var d1=document.body, d2=document.documentElement;


			div.style.top=(Math.max(d1.scrollTop,d2.scrollTop)+200)+"px";
			
			buttom.focus();
			
			
			

		}  

}

function hideDiv(id)
{

	var div=document.getElementById(id);
		if(div!=null)
		{

			div.style.display="none";
	
		}  

}

