// JScript File
function showMsg(x){
	alert(x);
}

function ajaxFunction(){

 var xmlHttp;
  try
    {    // Firefox, Opera 8.0+, Safari 
 	xmlHttp=new XMLHttpRequest();  
  }
  catch (e)
    {    // Internet Explorer 
  try
      {   
 	 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
      }
    catch (e)
      {   
  	try
        	{   
     		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
      	}
     	 catch (e)
        	{     
 		alert("Your browser does not support AJAX!");    
    		return false;
	}

      }  
 }	

	return xmlHttp;
	
}
function show()
{  
    if(document.getElementById("ddCountry").value!="0")
    {
       /* if(document.getElementById("ddCountry").value=="220")
	    {
	        document.getElementById("chooseshipping").innerHTML="<p style='margin-top:-10px'></p>";
	        document.getElementById("chooseinsurance").innerHTML="<p style='margin-top:-10px'></p>";
	        document.getElementById("shippingoption").innerHTML="<p style='margin-top:-10px'></p>";
	        document.getElementById("insuranceoption").innerHTML="<p style='margin-top:-10px'></p>";	        
            document.getElementById("span2").innerHTML="<p style='margin-top:-10px'></p>";	        
            document.getElementById("span3").innerHTML="<p style='margin-top:-10px'></p>";
            document.getElementById("sub").innerHTML="$" + document.getElementById("txtval").value;
            document.getElementById("hiddenCountry").value = document.getElementById("ddCountry").value;
	        document.getElementById("ImageButton1").style.visibility="visible";
	        return null;
	    }
	    else
	    {*/
        xmlHttp=ajaxFunction();
        xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState==1)
					{
					//alert("Anij");
					   document.getElementById("shippingoption").innerHTML="<img src='checkout/images/a1.gif'/><img src='checkout/images/loading.gif'/>";
                       document.getElementById("spanshippingMethod").innerHTML="<p style='margin-top:-10px'></p>";
			           document.getElementById("spanShippingOption").innerHTML= "<p style='margin-top:-10px'></p>";
				       document.getElementById("spnfedexrate").innerHTML = "<p style='margin-top:-10px'></p>";
			           document.getElementById("span2").innerHTML="<p style='margin-top:-10px'></p>";
                       document.getElementById("span3").innerHTML="<p style='margin-top:-10px'></p>";
                       document.getElementById("chooseinsurance").innerHTML="<p style='margin-top:-10px'></p>";
                       document.getElementById("insuranceoption").innerHTML="<p style='margin-top:-10px'></p>";
                       document.getElementById("spanInsurance1").innerHTML="<p style='margin-top:-10px'></p>";
                       document.getElementById("spanInsurance2").innerHTML="<p style='margin-top:-10px'></p>";
                       document.getElementById("spanInsurance3").innerHTML="<p style='margin-top:-10px'></p>";
					}
					if(xmlHttp.readyState==4)
					{
					    var r=xmlHttp.responseText
					   
					    
					   if(document.getElementById("ddCountry").value!="UNITED STATES")
					   {
					    //alert("r value" + r);
					       //document.getElementById("sub").innerHTML="$ " + document.getElementById("txtval").value;
					       document.getElementById("chooseshipping").innerHTML="Select Shipping :";
					       document.getElementById("shippingoption").innerHTML=r.split("eee",1);
					       document.getElementById("chooseinsurance").innerHTML="Select Insurance :";
					       document.getElementById("insuranceoption").innerHTML="<select id=ddlinsurance onchange=showinsurnce();><option value=0>-----Select-----</option><option value=2.00>$100</option><option value=4.00>$200</option><option value=6.00>$300</option><option value=8.00>$400</option><option value=10.00>$500</option><option value=12.00>$600</option><option value=14.00>$700</option><option value=16.00>$800</option><option value=18.00>$900</option><option value=20.00>$1000</option></select>";
					       document.getElementById("spanshippingMethod").innerHTML="";
					       document.getElementById("spanShippingOption").innerHTML= "";
    					   document.getElementById("spnfedexrate").innerHTML = "";
					       document.getElementById("span2").innerHTML="";
                           document.getElementById("span3").innerHTML="";
                           //document.getElementById("hiddenCountry").value = document.getElementById("ddCountry").value;
                            /*if(document.getElementById("hiddenShipping").value!="")
                            {                        
                                document.getElementById("ddlshipping").selectedIndex = getSelectedIndex(document.getElementById("ddlshipping"),document.getElementById("hiddenShipping").value,"txt");                                
                                //alert( document.getElementById("ddlshipping").selectedIndex); 
                                showshipping();
                            }
                            if(document.getElementById("hiddenInsurance").value!="")
                            {
                                document.getElementById("ddlinsurance").selectedIndex = getSelectedIndex(document.getElementById("ddlinsurance"),document.getElementById("hiddenInsurance").value,"");
                                showinsurnce();
                            }*/
                        }
                        else
                        {
                            var ab=r.split("eee",1);      
                            //alert(ab);                     
                           document.getElementById("chooseshipping").innerHTML="Select ShipTo State :";
					       document.getElementById("shippingoption").innerHTML=ab;					      
					       document.getElementById("chooseinsurance").innerHTML="";
					       document.getElementById("insuranceoption").innerHTML="";						       
					       /*if(document.getElementById("hiddenState").value!="")
                            {         
                                document.getElementById("ddlState").selectedIndex = getSelectedIndex(document.getElementById("ddlState"),document.getElementById("hiddenState").value,"txt");                                
                                
                               showZip();
                            }	*/
					        
                        }
					}
					
        //}
       }      
//       var v  = document.getElementById("hdnQty").value;
//        alert("v" + v); 
//alert(document.getElementById("quantity1").value);
        var url="checkout/system.aspx?id="+document.getElementById("ddCountry").value+"&type=ctry&qty="+document.getElementById("quantity1").value;
        //alert(url);
  		xmlHttp.open("GET",url,true);
        xmlHttp.send(null);	
        //document.getElementById("hiddenCountry").value=document.getElementById("ddCountry").value;
      
    }
    else
    {
         //document.getElementById("sub").innerHTML="$" + document.getElementById("txtval").value;           
         //document.getElementById("hiddenCountry").value="";
         document.getElementById("spanshippingMethod").innerHTML="<p style='margin-top:-10px'></p>";
		 document.getElementById("spanShippingOption").innerHTML="<p style='margin-top:-10px'></p>"
		 document.getElementById("chooseinsurance").innerHTML="<p style='margin-top:-10px'></p>";
		document.getElementById("insuranceoption").innerHTML="<p style='margin-top:-10px'></p>";
		document.getElementById("spanInsurance1").innerHTML="<p style='margin-top:-10px'></p>";
	    document.getElementById("spanInsurance2").innerHTML="<p style='margin-top:-10px'></p>";
	    document.getElementById("spanInsurance3").innerHTML="<p style='margin-top:-10px'></p>";
		document.getElementById("spnfedexrate").innerHTML ="<p style='margin-top:-10px'></p>";
        document.getElementById("span2").innerHTML="<p style='margin-top:-10px'></p>";
        document.getElementById("span3").innerHTML="<p style='margin-top:-10px'></p>";
        document.getElementById("spanInsurance3").innerHTML="<p style='margin-top:-10px'></p>";
        document.getElementById("chooseshipping").innerHTML="<p style='margin-top:-10px'></p>";
		document.getElementById("shippingoption").innerHTML="<p style='margin-top:-10px'></p>";
    }
}
function show_NonUs(ab)
{
   document.getElementById("chooseshipping").innerHTML="Select ShipTo State :";
   document.getElementById("shippingoption").innerHTML=ab;
   document.getElementById("chooseinsurance").innerHTML="";
   document.getElementById("insuranceoption").innerHTML="";	
}
function showZip()
{
//alert("rex");
    var e = document.getElementById("ddlState"); // select element
    var strUser = e.options[e.selectedIndex].text;     
    if(document.getElementById("ddlState").value!=0)
    {
    
        xmlHttp=ajaxFunction();
        xmlHttp.onreadystatechange=function()
        {
                    if(xmlHttp.readyState==1)
					{
					//alert("vinod");
					 document.getElementById("insuranceoption").innerHTML="<img src='checkout/images/a1.gif'/><img src='checkout/images/loading.gif'/>";
                     document.getElementById("chooseinsurance").innerHTML="<p style='margin-top:-10px'></p>";
					 document.getElementById("insuranceoption").innerHTML="<p style='margin-top:-10px'></p>";
                     document.getElementById("spanshippingMethod").innerHTML="<p style='margin-top:-10px'></p>";
					 document.getElementById("spanShippingOption").innerHTML="<p style='margin-top:-10px'></p>";
					 document.getElementById("spnfedexrate").innerHTML = "<p style='margin-top:-10px'></p>";
					 document.getElementById("spanInsurance1").innerHTML="<p style='margin-top:-10px'></p>";
					 document.getElementById("spanInsurance2").innerHTML="<p style='margin-top:-10px'></p>";
					 document.getElementById("spanInsurance3").innerHTML="<p style='margin-top:-10px'></p>";
                     
					}
					if(xmlHttp.readyState==4)
					{
					    var r=xmlHttp.responseText					    
					    //alert(r);
					   document.getElementById("chooseinsurance").innerHTML="Enter ShipTo Zip Code :";
					   document.getElementById("insuranceoption").innerHTML=r.split("eee",1);					                  
					    /*if(document.getElementById("hiddenZip").value!="")
                        {                        
                            document.getElementById("txtZip").value = document.getElementById("hiddenZip").value;                                
                            showShippngmethod(document.getElementById("txtZip").event,document.getElementById("txtZip"));
                        }	*/
                       
					}
					
        }  
        //document.getElementById("hiddenState").value = strUser;     
        
        var url="checkout/system.aspx?id="+strUser+"&type=state";  
        //alert(url);    
  		xmlHttp.open("GET",url,true);
        xmlHttp.send(null);	
       
      
    }
     else
    {
         document.getElementById("sub").innerHTML="$" + document.getElementById("txtval").value;               
         //document.getElementById("hiddenCountry").value="";<p style='margin-top:-10px'></p><p style='margin-top:-10px'></p>
         document.getElementById("chooseinsurance").innerHTML="";
		 document.getElementById("insuranceoption").innerHTML="";
		 document.getElementById("spanshippingMethod").innerHTML="<p style='margin-top:-10px'></p>";
		 document.getElementById("spanShippingOption").innerHTML="<p style='margin-top:-10px'></p>";
		 document.getElementById("spnfedexrate").innerHTML = "<p style='margin-top:-10px'></p>";
		 document.getElementById("spanInsurance1").innerHTML="<p style='margin-top:-10px'></p>";
		 document.getElementById("spanInsurance2").innerHTML="<p style='margin-top:-10px'></p>";
		 document.getElementById("spanInsurance3").innerHTML="<p style='margin-top:-10px'></p>";
       
    }
}
function showShippngmethod(event,f)
{
    //alert("Anij");
   if (!/^\d*$/.test(f.value))
   {
   f.value = f.value.replace(/[^\d]/g,"");
   document.getElementById("errmsg").innerHTML="<font color='red'>Enter Only Digits</font>";
   
   }
   else
   {
       document.getElementById("errmsg").innerHTML="";
       var x = document.getElementById("txtZip").value       
       if(x.length > 4)
       {        
         var strUser = document.getElementById("txtZip").value;
         //alert(strUser);
         xmlHttp=ajaxFunction();
        xmlHttp.onreadystatechange=function()
        {
                    if(xmlHttp.readyState==1)
					{
					//alert("hai");
					 document.getElementById("errmsg").innerHTML="<img src='checkout/images/a1.gif'/><img src='checkout/images/loading.gif'/>";                   
                     
					}
					if(xmlHttp.readyState==4)
					{
					   if(x.length >= 5){
					    var r=xmlHttp.responseText
					    var abc = r.split("eee",1);
					   document.getElementById("errmsg").innerHTML="";
					   document.getElementById("spanshippingMethod").innerHTML="Shipping Method :";
					   document.getElementById("spanShippingOption").innerHTML= abc;
					   //document.getElementById("hiddenZip").value = strUser;	                  			  
					   document.getElementById("spnfedexrate").innerHTML = "$ 0.00" ;
					   document.getElementById("spanInsurance1").innerHTML="Select Insurance :";
					   document.getElementById("spanInsurance2").innerHTML="<select id=ddlinsurance onchange=showinsurnce_1();><option value=0.00>-----Select-----</option><option value=2.00>$100</option><option value=4.00>$200</option><option value=6.00>$300</option><option value=8.00>$400</option><option value=10.00>$500</option><option value=12.00>$600</option><option value=14.00>$700</option><option value=16.00>$800</option><option value=18.00>$900</option><option value=20.00>$1000</option></select>";
					   document.getElementById("spanInsurance3").innerHTML="$ "+document.getElementById("ddlinsurance").value;                  
					 
					    /*if(document.getElementById("hiddenShipping").value != "")
                        { 
                            document.getElementById("ddlshippingMethod").selectedIndex = getSelectedIndex(document.getElementById("ddlshippingMethod"),document.getElementById("hiddenShipping").value,"txt");                             
                            fedexShippingMethod();
                        }	                       			  
                        if(document.getElementById("hiddenInsurance").value!="")
                        {
                            document.getElementById("ddlinsurance").selectedIndex = getSelectedIndex(document.getElementById("ddlinsurance"),document.getElementById("hiddenInsurance").value,"");                           
                            showinsurnce_1();
                        }*/	
                        }	
					}					
        }      
       // document.getElementById("hiddenZip").value = strUser;   
        var url="checkout/system.aspx?id="+zipCode(document.getElementById("txtZip").value)+"&type=shipping&state="+document.getElementById("ddlState").value+"&qty="+document.getElementById("quantity1").value;    
//        var url="system.aspx?id="+document.getElementById("txtZip").value+"&type=shipping&state="+document.getElementById("ddlState").value;
        
  		xmlHttp.open("GET",url,true);
        xmlHttp.send(null);	
       }    
       else
       {
            document.getElementById("spanshippingMethod").innerHTML="<p style='margin-top:-10px'></p>";
			document.getElementById("spanShippingOption").innerHTML="<p style='margin-top:-10px'></p>";
			document.getElementById("spanInsurance1").innerHTML="<p style='margin-top:-10px'></p>";
			document.getElementById("spanInsurance2").innerHTML="<p style='margin-top:-10px'></p>";
			document.getElementById("spnfedexrate").innerHTML="<p style='margin-top:-10px'></p>";
			document.getElementById("spanInsurance3").innerHTML="<p style='margin-top:-10px'></p>";
       }    
   }
}
function zipCode(code)
{
    var checkCode = code;
    var ziped = checkCode.substring(0,3);
    //alert(ziped);
    return ziped;
}
function fedexShippingMethod()
{
      var e = document.getElementById("ddlshippingMethod"); 
    var strUser = e.options[e.selectedIndex].text; 
     var report = document.getElementById("ddlinsurance").value;
     //alert(report);
    if(document.getElementById("ddlshippingMethod").value !=-1)
    {
         //document.getElementById("hdnShippingFedex").value =  strUser;
        // alert("hdnshipingfedex" + document.getElementById("hdnShippingFedex").value  );
        document.getElementById("spnfedexrate").innerHTML = "$ " + document.getElementById("ddlshippingMethod").value;
        var ddlReport = document.getElementById("ddlshippingMethod").value;        
        var tot = Math.round(calculator(ddlReport)*Math.pow(10,2))/Math.pow(10,2);
        if(report != 0.00)
        {
            var v = eval(tot) + eval(report);
           document.getElementById("sub").innerHTML="$ "  + v;
       }
       else
       {
           var v = eval(tot);
           document.getElementById("sub").innerHTML="$ "  + v;
       }
       //document.getElementById("hiddenShipping").value = strUser;
       //alert("Shipping fedex method options :" + document.getElementById("hiddenShipping").value); 
    }
    else
    {
        //document.getElementById("hdnShippingFedex").value = "";
         document.getElementById("spnfedexrate").innerHTML = "$ 0.00"
          var t = document.getElementById("txtval1").value;           
          var t1 = eval(t) + eval(report); 
         document.getElementById("sub").innerHTML = "$ " + t1;
          //document.getElementById("hiddenShipping").value = "";
    }
}
function showshipping()
{
    var e = document.getElementById("ddlshipping"); // select element
    var strUser = e.options[e.selectedIndex].text; 
//alert(strUser);
    var total,total_1;
     var ddlReport = document.getElementById("ddlshipping").value;
    //alert(ddlReport);
     var report = document.getElementById("ddlinsurance").value;
    if(document.getElementById("ddlshipping").value!=0)
    { 
     document.getElementById("span2").innerHTML="$ " + Math.round(ddlReport*Math.pow(10,2))/Math.pow(10,2);
     var tot = Math.round(calculator(ddlReport)*Math.pow(10,2))/Math.pow(10,2);
     document.getElementById("sub").innerHTML="$ "  + tot;
     //document.getElementById("ImageButton1").style.visibility="visible"; 
    // document.getElementById("hiddenShipping").value = strUser;
    
	}
	if(document.getElementById("ddlshipping").value==0)
    { 
        document.getElementById("span2").innerHTML="";
        var t = calculator(ddlReport)+eval(report);
        document.getElementById("sub").innerHTML="$ " + t;
        //document.getElementById("ImageButton1").style.visibility="hidden"; 
        //document.getElementById("hiddenShipping").value = "";
    }
	
}
function showinsurnce()
{
    var e = document.getElementById("ddlinsurance"); // select element
    var strUser = e.options[e.selectedIndex].value;     
     var report = document.getElementById("ddlinsurance").value;
     var ddlReport = document.getElementById("ddlshipping").value;
    if(document.getElementById("ddlinsurance").value!=0)
    { 
     document.getElementById("span3").innerHTML="$ " + report;  
     var v =   eval(calculator(ddlReport)+ eval(report));
     document.getElementById("sub").innerHTML="$ " + Math.round(v*Math.pow(10,2))/Math.pow(10,2)
     //document.getElementById("hiddenInsurance").value = strUser;
     // document.getElementById("insurance").value = document.getElementById("ddlinsurance").value;
	}	
	else
	{
	    document.getElementById("span3").innerHTML="";
	    var r = Math.round(calculator(ddlReport)*Math.pow(10,2))/Math.pow(10,2);
	    document.getElementById("sub").innerHTML="$ " + r;
	    //document.getElementById("hiddenInsurance").value="";
	    //document.getElementById("insurance").value = "";
	}
}
function showinsurnce_1()
{
    var e = document.getElementById("ddlinsurance"); // select element
    var strUser = e.options[e.selectedIndex].value;     
    var report = document.getElementById("ddlinsurance").value;
    var ddlReport = document.getElementById("ddlshippingMethod").value;   
    if(document.getElementById("ddlinsurance").value!=0)
    { 
      document.getElementById("spanInsurance3").innerHTML="$ " + report;  
      if(ddlReport != -1)
      {
          var v =   eval(calculator(ddlReport)+ eval(report));
          document.getElementById("sub").innerHTML="$ " + Math.round(v*Math.pow(10,2))/Math.pow(10,2)
      }
      else
      {
         var v =   eval(calculator(report));
          document.getElementById("sub").innerHTML="$ " + Math.round(v*Math.pow(10,2))/Math.pow(10,2)
      }
//      document.getElementById("hiddenInsurance").value = strUser;
      //document.getElementById("insurance").value = document.getElementById("ddlinsurance").value;
	}	
	else
	{
	    document.getElementById("spanInsurance3").innerHTML="$0.00";
	    var r = Math.round(calculator(ddlReport)*Math.pow(10,2))/Math.pow(10,2);
	    document.getElementById("sub").innerHTML="$ " + r;
//	    document.getElementById("hiddenInsurance").value="";
	    //document.getElementById("insurance").value = "";
	}
}
function calculator(r)
{
     var a = r;
     var total;
     var subtotal = document.getElementById("txtval1").value;  
    //alert("txtval1= " +  document.getElementById("txtval1").value);
     total = eval(a)+eval(subtotal);
     //alert(total);
     return total;
}
function show_visible()
{  
  /* if(document.getElementById("hiddenCountry").value != "")
   {
      
       var si=getSelectedIndex(document.getElementById("ddCountry"),document.getElementById("hiddenCountry").value,"txt");
       //alert(si);
        document.getElementById("ddCountry").selectedIndex=si;*/
      // alert(document.getElementById("ddCountry").value);
      if(document.getElementById("hdncart").value != "")
      {
          if(document.getElementById("ddCountry").value == "UNITED STATES")
          {   
            show();                     
          }  
          else
          {        
            //show();
          }  
      }
      else
      {
            //alert("null");
      }  
 }  

function getSelectedIndex(obj,v,ty)
{
    for(i=0;i<obj.length;i++)
    {
        //alert("i= "+ i);
        if(ty == "txt")
        {            
            if(obj.options[i].text==v)
            {
                      return i;
            }
        }
        else
        {
            if(obj.options[i].value==v)
            {
               //alert(obj.options[i].value);
                return i;
            }
        }
    }
}
function check()
{

    if(document.getElementById("hiddenCountry").value!="")
    {
         //alert("function check " + getSelectedIndex(document.getElementById("ddCountry"),document.getElementById("hiddenCountry").value,"txt"));
        document.getElementById("ddCountry").selectedIndex = getSelectedIndex(document.getElementById("ddCountry"),document.getElementById("hiddenCountry").value,"txt");
      //alert("anij");
        show();
    }
}

function googleCheckout()
{	
	if(document.getElementById("ddCountry").value == "UNITED STATES")
	{
	    var iNo=document.getElementById("itemNo").value;	  
	    var pName = document.getElementById("pName").value;	  
	    var subtot = document.getElementById("txtval").value;	 
	    var qty = document.getElementById("qty").value;	
	    var mdlId = document.getElementById("modelid").value;  
	  if(document.getElementById("ddlState").value != 0)
	  {
	    if(document.getElementById("txtZip").value != "")
	    {
	        if(document.getElementById("ddlshippingMethod").value != -1)
	        {
	            var e = document.getElementById("ddlshippingMethod");
	            var ship = e.options[e.selectedIndex].text;	
	            var ship2 = ship.split(",",1);
	            var insu = document.getElementById("ddlinsurance").value; 	       
	            if(ship!=null)
	            { 
                    if((ship.indexOf('USPS')!=-1) || (ship.indexOf('First Class')!=-1))
                    {
                        if(insu != 0)
                        {
                            var shipvalue = eval(document.getElementById("ddlshippingMethod").value) + eval(document.getElementById("ddlinsurance").value)
                            window.location.href="http://www.buycomputermemory.com/checkout/default.aspx?itemNo="+iNo+"&product="+pName+"&subtotal="+subtot+"&shipping="+ship2+"&shipvalue="+shipvalue+"&qty="+qty+"&mdlid="+mdlId;
                        }
                        else
                        {
                            alert("Please select insurance for USPS, a minimum of $100 should be selected.");
                        }
                          
                    }
                    else
                    {
                          var shipvalue = eval(document.getElementById("ddlshippingMethod").value) + eval(document.getElementById("ddlinsurance").value)
                         window.location.href="http://www.buycomputermemory.com/checkout/default.aspx?itemNo="+iNo+"&product="+pName+"&subtotal="+subtot+"&shipping="+ship2+"&shipvalue="+shipvalue+"&qty="+qty+"&mdlid="+mdlId;
                    }
                }
	        }
	        else
	        {
	            alert("Please select Shipping Method");
	        }
	     }
	     else
	     {
	        alert("Please Enter Zip Code");
	     }
      }
      else
      {
            alert("Please select your state");
      }  
	    
	}
	else
	{
	    var iNo=document.getElementById("itemNo").value;
	    var pName = document.getElementById("pName").value;
	    var subtot = document.getElementById("txtval").value;
	    var mdlId = document.getElementById("modelid").value;  
	    var qty = document.getElementById("qty").value;
	    if(document.getElementById("ddlshipping").value != 0)
	    {
	        var e = document.getElementById("ddlshipping");
	        var ship = e.options[e.selectedIndex].text;	
	        var ship2 = ship.split(",",1);
	       
	           var shipvalue = eval(document.getElementById("ddlshipping").value) + eval(document.getElementById("ddlinsurance").value)
	            window.location.href="http://www.buycomputermemory.com/checkout/default.aspx?itemNo="+iNo+"&product="+pName+"&subtotal="+subtot+"&shipping="+ship2+"&shipvalue="+shipvalue+"&qty="+qty+"&mdlid="+mdlId;
	       
	    }
	    else
	    {
	         alert("Please select Shipping Method");
	    }
	   
	    
	}
}