﻿control="ctl00_cphCenter_";
function updateProductList(hidID,catid,chkid)
{
    
    if(document.getElementById(hidID))
    {
	    var category=document.getElementById(hidID).value;
	    //alert(document.getElementById(chkid).checked);
	    //var index=category.indexOf(catid);
	    var type=0;
	    
	    if(document.getElementById(chkid).checked==true)
	    {
	        type=1
	    }
	    else
	    {
	        type=0
	    }
	    
	   var arrVal=new Array();
	    arrVal=category.split(",");
	    if(type==1)
	    {
	        //alert("1");
	        arrVal.push(catid);
	    }
	    else
	    {
	       // alert("2");
	        for(i=0;i<arrVal.length;i++)
	        {
	            if(arrVal[i]==catid)
	            {
	            // alert("3");
	             arrVal[i]="";
	            }
	        }
	    }
	    var newVal="";
	    for(i=0;i<arrVal.length;i++)
        {
            if(arrVal[i]!="")
            {
                newVal=newVal+arrVal[i]+",";
            }
        }
	    /*
	    

	    if((index< 0) && (type==1))
	    {
			    document.getElementById(hidID).value=category+catid+",";
	    }
	    else if((type==0) && (index >= 0))
	    {
			    if(index==0)
			    {
				    var cid=category.substring(catid.length+1);
				    document.getElementById(hidID).value=cid;
			    }
			    else
			    {
				    var cid1=category.substring(0,index);
				    var len=index+catid.length+1;
				    var cid2=category.substring(len);
				    document.getElementById(hidID).value=cid1+cid2;
			    }							
	    }*/
	    document.getElementById(hidID).value=newVal;
	    document.getElementById(control+'btnUpdateProds').click();
    }
}
function setLocation(url)
{
        window.location.href=url;
}
function numbersOnly(e)
{
    var unicode=e.charCode?e.charCode:e.keyCode;
   // alert(unicode)
    if((unicode>=48 && unicode<=57) || unicode==8 || unicode==9 || unicode==37 || unicode==39)
    {
        return true;
    }
    else
    {
         return false;
    }
	return true;
}

function chkProductQty(txtid)
{
    var val=document.getElementById(txtid).value;
    if(val=="")
    {
        document.getElementById(txtid).value="0";
    }
}
function selectshipping_radio(ctr) 
{
    selectshipping(document.getElementById(control+'hidShipType').value);
}
function selectshipping(ctr) 
{
	document.getElementById('dely'+ctr).style.display='block';
	document.getElementById('delcost'+ctr).style.color='#e44a05';
	for(i=1;i<=10;i++)
	{
	    if(parseInt(i,10)!=parseInt(ctr,10))
	    {
	        if(document.getElementById('dely'+i.toString()))
	        {
	            document.getElementById('dely'+i.toString()).style.display='none';
	        }
	        if(document.getElementById('delcost'+i.toString()))
	        {
	            document.getElementById('delcost'+i.toString()).style.color='#CCC';
	        }
	    }
	}
	document.getElementById(control+'hidShipType').value=ctr;
	document.getElementById(control+'lnkUpdateCode').click();
	 
}
function CopyAddress()
{
    if(document.getElementById(control+'chkSame').checked==true)
    {
        document.getElementById(control+'txtShipFirstName').value=document.getElementById(control+'txtFirstName').value;
        document.getElementById(control+'txtShipLastName').value=document.getElementById(control+'txtLastName').value;
        document.getElementById(control+'txtShipAddLine1').value=document.getElementById(control+'txtBillAddLine1').value;
        document.getElementById(control+'txtShipAddLine2').value=document.getElementById(control+'txtBillAddLine2').value;
        document.getElementById(control+'txtShipCity').value=document.getElementById(control+'txtBillCity').value;
        document.getElementById(control+'txtShipZip').value=document.getElementById(control+'txtBillZip').value;
        var indexBillCountry=document.getElementById(control+'ddlCountry').selectedIndex;
        var indexShipCountry=document.getElementById(control+'ddlShipCountry').selectedIndex;
        if(document.getElementById(control+'ddlCountry').options[indexBillCountry].value != document.getElementById(control+'ddlShipCountry').options[indexShipCountry].value)
        {
            document.getElementById(control+'btnUpdateDdlShip').click();
        }
        //setDropDownList(document.getElementById(control+'ddlShipCountry'),document.getElementById(control+'ddlCountry').options[index].value);
        
        if(document.getElementById(control+'ddlState'))
        {
            
            var index=document.getElementById(control+'ddlState').selectedIndex;
            setDropDownList(document.getElementById(control+'ddlShipState'),document.getElementById(control+'ddlState').options[index].value);
        }

        document.getElementById(control+'txtShipMobile').value=document.getElementById(control+'txtBillMobile').value;
        document.getElementById(control+'txtShipPhone').value=document.getElementById(control+'txtBillPhone').value;
    }    
}
function setDropDownList(elementRef, valueToSetTo)
{
    var isFound = false;

    for (var i=0; i<elementRef.options.length; i++)
    {
        if ( elementRef.options[i].value == valueToSetTo )
        {
        elementRef.options[i].selected = true;
        isFound = true;
        }
    }

    if ( isFound == false )
    {
       elementRef.options[0].selected = true;
    }
}
/**************************Searchg banner ***************************/
 function searchProducts() {
            var search = document.getElementById("txtBannerSearch").value;
            if (search.length > 0) {
                window.location.href = "/search/" + search + "/";
            }
            else {
                alert("Enter product to search");
                document.getElementById("txtBannerSearch").focus();
                
            }
        }

        function searchProductKeyPress(e) {
            var key0;
            if (e && e.which) {
                key0 = e.which;
            }
            else {
                if (!e && window.event) {
                    e = window.event;
                }
                if (e && e.keyCode) {
                    key0 = e.keyCode;
                }
            }

            if (key0 == 13) {
                searchProducts();
                return false;
            }
            ajax_search_products();
            return true;

        }
        function ajax_search_products() {
            val = document.getElementById("txtBannerSearch").value;
            val = val.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); //trimming white spaces
            if (val.length >= 3 ) {


                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;
                        }
                    }
                }
                xmlHttp.onreadystatechange = function() {
                    if (xmlHttp.readyState == 4) {
                        //alert(xmlHttp.responseText);

                        var resp = xmlHttp.responseText;
                        document.getElementById("divSearchResponse").innerHTML = resp;
                        document.getElementById("divSearchResponse").style.display = "block";
                        if (resp.length == 0) {
                            document.getElementById("divSearchResponse").style.display = "none";
                        }

                    }
                }
                xmlHttp.open("GET", "/ajax.aspx?action=searchproducts&search=" + val, true);
                xmlHttp.send(null);
            }
            else {
                document.getElementById("divSearchResponse").innerHTML = "";
                document.getElementById("divSearchResponse").style.display="none";
            }

        }
        function clearSearchDiv() {

            if (document.getElementById("hidSearchOver").value == "0") {
                document.getElementById("divSearchResponse").innerHTML = "";
                document.getElementById("divSearchResponse").style.display = "none";
            }
        }

        function divSearchOver(val) {
            document.getElementById("hidSearchOver").value = val;
        }
        function focusSearchTxt() {
            val = document.getElementById("txtBannerSearch").value;
            val = val.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); //trimming white spaces
            if (val == "Search By Name") {
                document.getElementById("txtBannerSearch").value = "";
            }
            else if (val.length == 0) {
            document.getElementById("txtBannerSearch").value = "Search By Name";
            }
        }

/****************Product Landing*************************/

function chkCLVals()
{
    
    if(document.getElementById(control+"txtCLLeftQty").value=="0" && document.getElementById(control+"txtCLRightQty").value=="0")
    {
        alert("Quantity Cannot be 0. Please Enter Quantity");
        return false;
    }
    if(document.getElementById(control+"txtCLLeftQty").value=="0")
    {
        if(!confirm("Are You Sure You Want to leave Left Qty as 0"))
        {
            return false;
        }
    }
    if(document.getElementById(control+"txtCLRightQty").value=="0")
    {
        if(!confirm("Are You Sure You Want to leave Right Qty as 0"))
        {
            return false;
        }
    }
    var indexLeft=document.getElementById(control+'ddlCLLeftPower').selectedIndex;
    var indexRight=document.getElementById(control+'ddlCLRightPower').selectedIndex;
    
    if(document.getElementById(control+"txtCLLeftQty").value!="0" && document.getElementById(control+'ddlCLLeftPower').options[indexLeft].value =="0.00")
    {
        if(!confirm("Are You Sure Your Left Power is 0.00"))
        {
            return false;
        }
    }
    if(document.getElementById(control+"txtCLRightQty").value!="0" &&document.getElementById(control+'ddlCLRightPower').options[indexRight].value =="0.00")
    {
        if(!confirm("Are You Sure Your Right Power is 0.00"))
        {
            return false;
        }
    }
        
}
function chkEFVals()
{
    
}
function chkSGVals()
{
    
}
