function ReSetCart(url,poststr,r_id)
{
	var xmlHttp;
	   if(window.XMLHttpRequest){ 
		  xmlHttp = new XMLHttpRequest();
		  if(xmlHttp.overrideMimeType){ 
			xmlHttp.overrideMimeType("text/xml");
		  }
	   }else if(window.ActiveXObject){  
		   try{
			 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		   }catch(e){
			 try{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			 }catch(e){}
		   }
	   }
	   if(!xmlHttp){
		alert("Can't create an XMLHTTP instance'");
	   }
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function(){
	if(xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			Refresh("/shopping/refreshcart.asp","act=get_discount","discount");
			Refresh("/shopping/refreshcart.asp","act=get_totals","totals");
			Refresh("/shopping/refreshcart.asp","act=get_shipping","shipping");
			
			if (r_id!=null) 
			{
			  document.getElementById(r_id).innerHTML=xmlHttp.responseText;
			}
		}
	}
};
	xmlHttp.send(poststr);
}
function Refresh(url,poststr,id)
{
	var xmlHttpnum;
	   if(window.XMLHttpRequest){ 
		  xmlHttpnum = new XMLHttpRequest();
		  if(xmlHttpnum.overrideMimeType){ 
			xmlHttpnum.overrideMimeType("text/xml");
		  }
	   }else if(window.ActiveXObject){  
		   try{
			 xmlHttpnum = new ActiveXObject("Msxml2.XMLHTTP");
		   }catch(e){
			 try{
				xmlHttpnum = new ActiveXObject("Microsoft.XMLHTTP");
			 }catch(e){}
		   }
	   }
	   if(!xmlHttpnum){
		alert("Can't create an XMLHTTP instance'");
	   }
	xmlHttpnum.open("POST",url,true);
	xmlHttpnum.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlHttpnum.onreadystatechange = function(){
	if(xmlHttpnum.readyState == 4)
	{
		if (xmlHttpnum.status == 200)
		{
			document.getElementById(id).innerHTML=xmlHttpnum.responseText;
		}
	}
};
	xmlHttpnum.send(poststr);
}

function show_other_country(){
	var SelectedCountry = document.getElementById("country").value;
	if (SelectedCountry=="other")
	{
	document.getElementById('input_counrty').style.display=''
	}
	else
	{
	document.getElementById('input_counrty').style.display='none'
	}
}

function check_input()
{
  var   o   
  var   i;  
  var can_checkout;
  
 i=0;
 can_checkout=true;
 
 o= document.getElementsByName("usa_size");  
 if (o==null||o.length==0)
 {
	alert('Your shopping cart is empty!');
	return false; 
 }
 
 o=document.getElementsByName("OrderQty");
 for(i=0;i<o.length;i++)
 {
	var k;
	k=o[i].value;
	if ((k=="") || (k=="0") || (isNaN(k)))
	{
	  can_checkout=false;
	  alert('The "Qty" least need put "1"');
	  return false; 
	}
 }
 
 o= document.getElementsByName("usa_size");
 //check usa_size
 for(i=0;i<o.length;i++)
 {  
  if (o[i].value=="-")
  {
    can_checkout=false;
	alert('Please select product size !')
    return false;
   }
 }
 
 //check payment
// o= document.getElementsByName("R1");  
 //for(i=0;i<o.length;i++){  
 //if (o[i].type=="radio")
 //{
  //if (o[i].checked==true)  
  //{
   // can_checkout=true;
    // break;
   //}
 // }
 //}
  //if (can_checkout==false)
  //{
   // can_checkout=false;
	//alert('Choose your payment, Please!');
    //return false;
 // }
  
  //check country
  o= document.getElementById("country"); 
  if (o.value=="-")
  {
	can_checkout=false;
	alert('Choose your country, Please!');
    return false;
  }
  if (o.value=="other")
  {
	  if (trim(document.getElementById("input_counrty").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your country, Please!');
          return false;
	  }
   }
   
 //ok checkout
 if (can_checkout==true)
 {
	 window.location="/shopping/sendinfo.asp";
 }
	
}

function check_placeOrder()
{
  var   o;    
  var can_checkout;
  
  can_checkout=false;
  
  //first name
  if (trim(document.getElementById("FN").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your First Name, Please!');
          return false;
	  }
  //Last name
  if (trim(document.getElementById("LN").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your Last Name, Please!');
          return false;
	  }	  
   //Email
  if (trim(document.getElementById("Msn").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your Email Address, Please!');
          return false;
	  }
  else
     {
		 if (is_email(trim(document.getElementById("Msn").value))==false)
	        {
		      can_checkout=false;
		      alert('Is your email address correct?, Please try again!');
              return false;
	        }
	 }
  //Country
  if (trim(document.getElementById("Country").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your country, Please!');
          return false;
	  }	  
   //Address
  if (trim(document.getElementById("Address").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your shipping address, Please!');
          return false;
	  }	  
   //Zip code
  if (trim(document.getElementById("Pcode").value)=="")
	  {
		  can_checkout=false;
		  alert('Input your postalcode, Please!');
          return false;
	  }	  	  

   return true;
  
}

function is_email( str ){
    p = /^([\w\.-]+)@([a-zA-Z0-9-]+)(\.[a-zA-Z\.]+)$/;
    if(str.search(p) == -1){
        return false;
    }else{
        return true;
    }
}

function trim(str)
{ 
  return str.replace(/(^\s*)|(\s*$)/g, "");
}
