﻿function deleteFromCart(recId, prodId)
{   
    var objErrLabel=document.getElementById("lblError");
    var objMainDiv=document.getElementById("dvCartMain");
    var objDiscount=document.getElementById("dvCartDiscount");
    var objdvcart=document.getElementById("Uc_Header_New1_cartDetail");
    //alert(objErrLabel + " : " + objMainDiv);
    
    if(objErrLabel!=null && objMainDiv!=null && objDiscount!=null)  
    {    
        objdvcart.innerHTML="";
        if(recId!=null && prodId!=null)
        {
            //alert(recId + " : " + prodId);
            var xmlHttpReq = false;
            var self = this;
            if (window.XMLHttpRequest) 
            {
                self.xmlHttpReq = new XMLHttpRequest();        
            }
            else if (window.ActiveXObject) 
            {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");         
            }
            self.xmlHttpReq.open('POST', "ajaxCartFunction1.aspx", true);             
            self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            self.xmlHttpReq.onreadystatechange = function() 
            {
                if (self.xmlHttpReq.readyState == 4) 
                {          
                    document.getElementById("dvAjaxPic").style.display="none";
                    objMainDiv.style.display="block";
                    objDiscount.style.display="block";
                    var GetValue=new Array();
                    if(self.xmlHttpReq.responseText.indexOf('~' != -1))
                    {
                        GetValue=self.xmlHttpReq.responseText.split("~");
                    }
                    if(GetValue[0].toString()!="")
                    {
                        if(GetValue[0].toString()=="0")
                        {
                            objMainDiv.innerHTML="";
                            objDiscount.innerHTML="";
                            if(GetValue[1].toString()=="-")
                            {
                                window.location.href="cart_login.aspx";
                            }
                            else
                            {
                                objErrLabel.innerHTML=GetValue[1].toString();                         
                            }
                        }
                        else
                        {
                            
                            objMainDiv.innerHTML=GetValue[1].toString();
                            objDiscount.innerHTML=GetValue[2].toString();
                            objdvcart.innerHTML=GetValue[3].toString();
                            objErrLabel.innerHTML=""; 
                            updateAlsoBought();
                        }
                    }
                    else
                    {
                        alert("Ajax return not found...");
                    }
                }
                else
                {
                    document.getElementById("dvAjaxPic").style.display="block";
                    //objMainDiv.style.display="none";
                    //objDiscount.style.display="none";
                }
            }                
            self.xmlHttpReq.send("mode=2&recId="+recId + "&prodId="+prodId); 
        }
        else
        {
            alert("Invalid parameter. Try again.");
        }
    }
//    else
//    {
//        alert("Objects not found. Try again.");
//    }
}
function updateCart(mode, txtBoxIds)
{
    //alert("got it: " + mode );
    var objErrLabel=document.getElementById("lblError");
    var objMainDiv=document.getElementById("dvCartMain");
    var objDiscount=document.getElementById("dvCartDiscount");
    var objdvcart=document.getElementById("Uc_Header_New1_cartDetail");
    //alert(mode + " : " + txtBoxIds);
    
    if(objErrLabel!=null && objMainDiv!=null && objDiscount!=null) 
    {   
        var varProdId=new Array();
        varProdId=txtBoxIds.split("|");
        //alert(varProdId);
        var varTxtBoxProdId="";  
         objdvcart.innerHTML="";
        for(i=0;i<varProdId.length;i++)
        {
            if(varProdId[i].toString()!="")
            {                
                if(document.getElementById(varProdId[i].toString()))
                {
                    //alert(varTxtBoxProdId);
                    varTxtBoxProdId=varTxtBoxProdId + varProdId[i].toString() + "~" + document.getElementById(varProdId[i].toString()).value + "|";
                   // alert(varTxtBoxProdId);
                }
            }
        }
        
        if(varTxtBoxProdId!=null)
        {
           // alert(varTxtBoxProdId);
            var xmlHttpReq = false;
            var self = this;
            if (window.XMLHttpRequest) 
            {
                self.xmlHttpReq = new XMLHttpRequest();        
            }
            else if (window.ActiveXObject) 
            {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");         
            }
            self.xmlHttpReq.open('POST', "ajaxCartFunction1.aspx", true);             
            self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            self.xmlHttpReq.onreadystatechange = function() 
            {
                if (self.xmlHttpReq.readyState == 4) 
                {          
                    //alert("hi");
                    document.getElementById("dvAjaxPic").style.display="none";
                    objMainDiv.style.display="block";
                    objDiscount.style.display="block";
                    var GetValue=new Array();
                    if(self.xmlHttpReq.responseText.indexOf('~' != -1))
                    {
                        GetValue=self.xmlHttpReq.responseText.split("~");
                    }
                    if(GetValue[0].toString()!="")
                    {
                     //alert(GetValue[0].toString());
                        if(GetValue[0].toString()=="0")
                        {
                            objErrLabel.innerHTML=GetValue[1].toString();                         
                            objMainDiv.innerHTML=""; 
                             objDiscount.innerHTML="";
                        }
                        else
                        {
                            //alert(objMainDiv);
                            //alert(GetValue[1].toString());
                            objMainDiv.innerHTML=GetValue[1].toString();
                            objDiscount.innerHTML=GetValue[2].toString();
                            objdvcart.innerHTML=GetValue[3].toString();
                            objErrLabel.innerHTML=""; 
                        }
                    }
                    else
                    {
                        alert("Ajax return not found...");
                    }
                }
                else
                {
                    document.getElementById("dvAjaxPic").style.display="block";
                   // objMainDiv.style.display="none";
                    //objDiscount.style.display="none";
                }
            }                
            self.xmlHttpReq.send("mode=" + mode + "&strBoxIds="+varTxtBoxProdId);
        }
    }
//    else
//    {
//        alert("Objects not found. Try again.");
//    }
}
function updateCartForDiscount(mode, siteId, objName)
{
    var objDisc=document.getElementById(objName);
    var objErrLabel=document.getElementById("lblError");
    var objMainDiv=document.getElementById("dvCartDiscount");
    var objdvcart=document.getElementById("Uc_Header_New1_cartDetail");
    //alert(mode + " : " + mode + " siteid:" + siteId + " error div: " + objErrLabel + " main div: " + objMainDiv);
    //dvDiscErr
    if(objErrLabel!=null && objMainDiv!=null && objDisc!=null) 
    {
        //alert("got it: " + mode + " object: " + objDisc + " value: " + objDisc.value);
        var varDiscCode=objDisc.value;
        objErrLabel.innerHTML="";
        objdvcart.innerHTML="";
        if(varDiscCode!=null && varDiscCode!="")
        {
            var varDiscCode=objDisc.value;
            var xmlHttpReq = false;
            var self = this;
            if (window.XMLHttpRequest) 
            {
                self.xmlHttpReq = new XMLHttpRequest();        
            }
            else if (window.ActiveXObject) 
            {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");         
            }
            self.xmlHttpReq.open('POST', "ajaxCartFunction1.aspx", true);             
            self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            self.xmlHttpReq.onreadystatechange = function() 
            {
                if (self.xmlHttpReq.readyState == 4) 
                {          
                    document.getElementById("dvAjaxPic").style.display="none";
                    objMainDiv.style.display="block";
                    var GetValue=new Array();
                    if(self.xmlHttpReq.responseText.indexOf('~' != -1))
                    {
                        GetValue=self.xmlHttpReq.responseText.split("~");
                    }
                    if(GetValue[0].toString()!="")
                    {
                        if(GetValue[0].toString()=="0")
                        {
                            objErrLabel.innerHTML=GetValue[1].toString();                         
                            objMainDiv.innerHTML="";  
                            alert(GetValue[1].toString()); 
                        }
                        if(GetValue[0].toString()=="2")
                        {
                            objErrLabel.innerHTML=GetValue[1].toString();                         
                            objMainDiv.innerHTML=GetValue[2].toString();  
                            alert(GetValue[1].toString()); 
                        }
                        else
                        {
                        //alert(GetValue[1].toString()); 
                            objMainDiv.innerHTML=GetValue[1].toString();
                            objdvcart.innerHTML=GetValue[2].toString();
                           objErrLabel.innerHTML=""; 
                        }
                    }
                    else
                    {
                        alert("Ajax return not found...");
                    }
                }
                else
                {
                    document.getElementById("dvAjaxPic").style.display="block";
                    objMainDiv.style.display="none";                    
                }
            }                
            self.xmlHttpReq.send("mode=" + mode + "&siteId=" + siteId + "&discCode="+varDiscCode);
        }
        else
        {
            alert("Please enter your discount code. Then try again.");
        }
    }
//    else
//    {
//        alert("Object not found!");
//    }
}

function chkNumeric(obj)
{
    if(obj)
    {
        var varVal=obj.value;
        if(isNaN(varVal)||(varVal< 1))
        {
            alert("Quantity Must be at Least one.");
            obj.value=1;
        }
    }
    else
    {
        alert("Object not found!");
    }
}


function NumericCheck(strString)
//  check for valid numeric strings	
{
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}


function IsNumeric(e)
{
    // Calling procedure
    // onKeyPress=\"javascript:return IsNumeric(event);\" 
    //
    //alert(e);
	var KeyID = (window.event) ? event.keyCode : e.which;
	if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) ||
	   (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
	{
		return false;
	}
    return true;
}

function updateAlsoBought()
{
    var objMainDiv=document.getElementById("uc_alsoBought1_lblAlsoBought");
    if(objMainDiv!=null)
    {   
        var xmlHttpReq = false;
        var self = this;
        if (window.XMLHttpRequest) 
        {
            self.xmlHttpReq = new XMLHttpRequest();        
        }
        else if (window.ActiveXObject) 
        {
            self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");         
        }
        self.xmlHttpReq.open('POST', "ajaxCartFunction1.aspx", true);             
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() 
        {
            if (self.xmlHttpReq.readyState == 4) 
            {          
                document.getElementById("dvAjaxPic").style.display="none";
                objMainDiv.style.display="block";
                var GetValue=new Array();
                if(self.xmlHttpReq.responseText.indexOf('~' != -1))
                {
                    GetValue=self.xmlHttpReq.responseText.split("~");
                }
                if(GetValue[0].toString()!="")
                {
                    objMainDiv.innerHTML=GetValue[1].toString();
                }
                else
                {
                    alert("Ajax return not found...");
                }
            }
            else
            {
                document.getElementById("dvAjaxPic").style.display="block";
                objMainDiv.style.display="none";
            }
        }                
        self.xmlHttpReq.send("mode=4");
    }
    else
    {
        //alert("Objects not found. Try again.");
    }
}



//Function UpdateCart Menka

function updateCartNew(mode, txtBoxIds, e)
{
    //alert("got it: " + mode );
    //var objErrLabel=document.getElementById("lblError");
    var objMainDiv=document.getElementById("dvCartMain");
     var objDiscount=document.getElementById("dvCartDiscount");
    //alert(mode + " : " + txtBoxIds);
    
    alert(objDiscount);
    //alert( String.fromCharCode(KeyID));
    if(objMainDiv!=null && objDiscount!=null) //objErrLabel!=null && 
    {   
        var varProdId=new Array();
        varProdId=txtBoxIds.split("|");
        //alert(varProdId);
        var varTxtBoxProdId="";   
        for(i=0;i<varProdId.length;i++)
        {
            if(varProdId[i].toString()!="")
            {                
                if(document.getElementById(varProdId[i].toString()))
                {
                    //alert(varTxtBoxProdId);  document.getElementById(varProdId[i].toString()).value
                    var KeyID = (window.event) ? event.keyCode : e.which;
                    varTxtBoxProdId=varTxtBoxProdId + varProdId[i].toString() + "~" + String.fromCharCode(KeyID) + "|";
                    //alert(varTxtBoxProdId);
                }
            }
        }
        
        if(varTxtBoxProdId!=null)
        {
            //alert(varTxtBoxProdId);
            var xmlHttpReq = false;
            var self = this;
            if (window.XMLHttpRequest) 
            {
                self.xmlHttpReq = new XMLHttpRequest();        
            }
            else if (window.ActiveXObject) 
            {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");         
            }
            self.xmlHttpReq.open('POST', "ajaxCartFunction1.aspx", true);             
            self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            self.xmlHttpReq.onreadystatechange = function() 
            {
                if (self.xmlHttpReq.readyState == 4) 
                {          
                    //alert("hi");
                    //document.getElementById("dvAjaxPic").style.display="none";
                    objMainDiv.style.display="block";
                    objDiscount.style.display="block";
                    
                    var GetValue=new Array();
                    if(self.xmlHttpReq.responseText.indexOf('~' != -1))
                    {
                        GetValue=self.xmlHttpReq.responseText.split("~");
                    }
                    if(GetValue[0].toString()!="")
                    {
                     //alert(GetValue[0].toString());
                        if(GetValue[0].toString()=="0")
                        {
                           // objErrLabel.innerHTML=GetValue[1].toString();                         
                            objMainDiv.innerHTML="";
                            objDiscount.innerHTML="";  
                        }
                        else
                        {
                            //alert(objMainDiv);
                            //alert(GetValue[1].toString());
                            objMainDiv.innerHTML=GetValue[1].toString();
                            objDiscount.innerHTML=GetValue[2].toString();
                          //  objErrLabel.innerHTML=""; 
                        }
                    }
                    else
                    {
                        alert("Ajax return not found...");
                    }
                }
                else
                {
                    //document.getElementById("dvAjaxPic").style.display="block";
                    objMainDiv.style.display="none";
                    objDiscount.style.display="none";
                }
            }                
            self.xmlHttpReq.send("mode=" + mode + "&strBoxIds="+varTxtBoxProdId);
        }
    }
    else
    {
        //alert("Objects not found. Try again.");
    }
}