﻿function addcart(hid)
{    
    document.grt_form.method="post";    
	document.grt_form.action="/ajax/ajax_add_cart.aspx?hid=" + hid;	
	document.grt_form.submit();
}
function delete_cart(sid)
{
    document.aspnetForm.method="post";
	document.aspnetForm.action="/ajax/ajax_del_shopcart.aspx?sid=" + sid;
	document.aspnetForm.submit();
}

var xmlHttp;
var scid;
function change_qty(sid,e,obj)
{ 
     var key;
    if(document.all)
        key=e.keyCode;
    else if(document.getElementById)
        key=e.which;
    else
        key=e.keyCode;
    
    if(key>=48 && key<=57 || key>=96 && key<=105 || key==8 || key==46 || key==13)
    {
    if(document.getElementById("qty"+sid).value>99)
    {
        alert("Please enter the quantity less than 100");
        document.getElementById("qty"+sid).value="";
        return false;
    }       
    scid = sid;
    xmlHttp=getxmlhttp();
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
      var time=new Date();
    var url="/Ajax/ajax_change_qty.aspx";
    url=url+"?sid="+sid;
    url=url+"&qty="+document.getElementById("qty"+sid).value+"&time="+time.getTime();   
    xmlHttp.open("GET",url,false);    
    xmlHttp.send(null);         
    var amount=xmlHttp.responseText;
    amount=amount.split('$');
   
    if(document.getElementById("div_"+scid)!=null)
    {
        document.getElementById("div_"+scid).innerHTML="";
        document.getElementById("div_"+scid).innerHTML=amount[0];
    }
    if(document.getElementById("div_"+scid)!=null)
    {
        document.getElementById("div_total").innerHTML="";
        document.getElementById("div_total").innerHTML=amount[1]; 
    }
     
    if (document.getElementById("ctl00_ContentPlaceHolder1_shiphid")!=null)
    document.getElementById("div_total").innerHTML=parseFloat(amount[1])+parseFloat(document.getElementById("ctl00_ContentPlaceHolder1_shiphid").value)+ " (Rs)";
    }
    else
    {
        var val=obj.value;
        obj.value=val.replace(/[^0-9]/,'');
        alert("Please enter numeric values only");
        return false;
    }
}

function giftvoucher_addcart()
{ 
    var url;
    url="/ajax/ajax_add_cart.aspx?";
    if ((document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500")!=null) && (document.getElementById("ctl00_ContentPlaceHolder1_drp_coup1000")!=null))
    {
        if((document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500").value == "0") && (document.getElementById("ctl00_ContentPlaceHolder1_drp_coup1000").value == "0"))
        {
            alert("Please select no of coupons");
            document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500").focus();
            return false;
        }
        else
        {
            if((document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500").value != "0") && (document.getElementById("ctl00_ContentPlaceHolder1_drp_coup1000").value == "0"))
            {
                url += "cp500=" + document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500").value;
            }
            else if((document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500").value == "0") && (document.getElementById("ctl00_ContentPlaceHolder1_drp_coup1000").value != "0"))
            {
                url += "cp1000=" + document.getElementById("ctl00_ContentPlaceHolder1_drp_coup1000").value;
            }
            else
            {
                url += "cp500=" + document.getElementById("ctl00_ContentPlaceHolder1_drp_coup500").value + "&cp1000=" + document.getElementById("ctl00_ContentPlaceHolder1_drp_coup1000").value;
            }
            xmlHttp=GetXmlHttpObject();
            if (xmlHttp==null)
              {
              alert ("Your browser does not support AJAX!");
              return;
              } 
            xmlHttp.onreadystatechange=stateChanged;
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }
    }
    return true;
}
function stateChanged()
 {
    if(xmlHttp.readyState==4)
    {
        var addcart=xmlHttp.responseText.split("$");
          if (addcart[0]!="")
            {
               document.location=addcart[0];
            }
    }
 }

function getxmlhttp()
{
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;
}