
var MasterpageID = "ctl00_cphMaster_";

function SearchOnFocus(ctrl)
{
    if(ctrl.value == document.getElementById('ctl00_cphMaster_LeftNav1_AbtWinesSearch_hdnSearchWines').value)
    {
        ctrl.value = '';
    }
}
function SearchOnBlur(ctrl)
{   	  	  
    if(ctrl.value == "")
        ctrl.value = document.getElementById('ctl00_cphMaster_LeftNav1_AbtWinesSearch_hdnSearchWines').value;	        
  	   
}

function GuaranteeOnFocus(ctrl)
{
    if(ctrl.value == document.getElementById('ctl00_cphMaster_WineGuarantee1_hdnWineGuarantee').value)
    {
        ctrl.value = '';
    }
   
}
function GuaranteeOnBlur(ctrl)
{   	  	  
    if(ctrl.value == "")
        ctrl.value = document.getElementById('ctl00_cphMaster_WineGuarantee1_hdnWineGuarantee').value;
      
}

function DoSearch() {	
	var x = document.getElementById('ctl00_cphMaster_LeftNav1_AbtWinesSearch_keyword').value;
	// search
	if (x != "") {
	    var x1 = x.replace("@","");
	    var x2 = x1.replace("#","");
	     var x3 = x2.replace("&","");
	     var x4 = x3.replace("?","");
		window.location = "../search_results.aspx?keyword=" + x4;
		return false;
	} else {
		alert(GetString("EnterProperSearchItem"));
		return false;
	}		
}
// Set site language on cookie
function SetSiteLanguage(ctrl)
{ 
    setCookie('currentCulture',document.getElementById(ctrl.id).value,30);    
    // reload the page with the selected culture    
    window.location.reload();
    
}

// get cookie
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}
// set cookie
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function GetString(keyName)
{
    var localizedKeyName = keyName;
    if(getCookie("currentCulture") == 'fr-ch')
    {
        localizedKeyName = "fr" + keyName;
    }
    if(getCookie("currentCulture") == 'de-ch')
    {
        localizedKeyName = "de" + keyName;
    }    
    return eval(localizedKeyName);
}

//Function to Validate in Login Page
function fnLoginValidation()
{
    document.getElementById(MasterpageID + "txtEmailId").style.background = '#efefef';
    if(trim(document.getElementById(MasterpageID + "txtEmailId").value).length == 0 )
    {
        alert(GetString("EnterEmail"));
        document.getElementById(MasterpageID + "txtEmailId").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtEmailId").focus();
        return false;
    }

    document.getElementById(MasterpageID + "txtEmailId").style.background = '#efefef';
    var e = document.getElementById(MasterpageID + "txtEmailId").value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!(filter.test(e))) 
    {       
        alert(GetString("InvalidEmail"));        
        document.getElementById(MasterpageID + "txtEmailId").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtEmailId").focus();
        return false;
    }

    document.getElementById(MasterpageID + "txtPassword").style.background = '#efefef';
    if((document.getElementById(MasterpageID + "rdoOldCustomer").checked == true) && (trim(document.getElementById(MasterpageID + "txtPassword").value).length == 0 ))
    {
        alert(GetString("EnterPassword"));
        document.getElementById(MasterpageID + "txtPassword").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtPassword").focus();
        return false;
    }
    return true;
}

//disable/enable password field based on login option
function fnChangeLogin()
{
    document.getElementById(MasterpageID + "rdoOldCustomer").checked = true;
    document.getElementById('ctl00_cphMaster_btnLogin').value = GetString("Login");
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

//Validation on New User Registration
function fnValidateUserRegistration()
{
    document.getElementById(MasterpageID +"txtFirstName").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtFirstName").value).length == 0) {
        alert(GetString("EnterFirstName"));
        document.getElementById(MasterpageID +"txtFirstName").style.background = '#FFFFcc';
        document.getElementById(MasterpageID +"txtFirstName").focus();
        return false;
    }
    document.getElementById(MasterpageID +"txtLastName").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtLastName").value).length == 0) {
        alert(GetString("EnterLastName"));
        document.getElementById(MasterpageID +"txtLastName").style.background = '#FFFFcc';
        document.getElementById(MasterpageID +"txtLastName").focus();
        return false;
    }
    
    document.getElementById(MasterpageID + "txtEmailID").style.background = '#efefef';
    if(trim(document.getElementById(MasterpageID + "txtEmailID").value).length == 0 )
    {
        alert(GetString("EnterEmail"));
        document.getElementById(MasterpageID + "txtEmailID").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtEmailID").focus();
        return false;
    }

    document.getElementById(MasterpageID + "txtEmailID").style.background = '#efefef';
    var e = document.getElementById(MasterpageID + "txtEmailID").value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!(filter.test(e))) 
    {
        alert(GetString("InvalidEmail"));
        document.getElementById(MasterpageID + "txtEmailID").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtEmailID").focus();
        return false;
    }
    
    document.getElementById(MasterpageID + "txtConfirmEmailID").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtEmailID").value) != trim(document.getElementById(MasterpageID + "txtConfirmEmailID").value)) {
            alert(GetString("EmailDoNotMatch"));
            document.getElementById(MasterpageID + "txtConfirmEmailID").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtConfirmEmailID").focus();
            return false;
        }

    document.getElementById(MasterpageID + "txtPassword").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtPassword").value).length < 6) {
            alert(GetString("PasswordAtleast6Char"));
            document.getElementById(MasterpageID + "txtPassword").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtPassword").focus();
            return false;
        }
         
        document.getElementById(MasterpageID + "txtConfirmPassword").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtPassword").value) != trim(document.getElementById(MasterpageID + "txtConfirmPassword").value)) {
            alert(GetString("PasswordDoNotMatch"));
            document.getElementById(MasterpageID + "txtConfirmPassword").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtConfirmPassword").focus();
            return false;
        }
        
        document.getElementById(MasterpageID + "txtAddress1").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtAddress1").value).length == 0) {
            alert(GetString("EnterAddress"));
            document.getElementById(MasterpageID + "txtAddress1").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtAddress1").focus();
            return false;
        }
         
         document.getElementById(MasterpageID + "txtZipCode").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtZipCode").value).length == 0) {
            alert(GetString("EnterZipcode"));
            document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtZipCode").focus();
            return false;
        }
        
        if(document.getElementById("city") == null)
            {
                if ((document.getElementById(MasterpageID + "spnCity") == null) || (document.getElementById("city1") != null))
                {
                    alert(GetString("EnterValidZipcode"));
                    document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
                    document.getElementById(MasterpageID + "txtZipCode").focus();
                    return false;
                }               
            }
            else
            {   
                if(document.getElementById("city").options != null)
                {  
                   if(document.getElementById("city").options.length == 1)
                    {                
                        alert(GetString("EnterValidZipcode"));
                        document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
                        document.getElementById(MasterpageID + "txtZipCode").focus();
                        return false;  
                    }
                    else
                    {                   
                        document.getElementById("city").style.background = '#efefef';
                        if ((document.getElementById("city").value == GetString("ClickToSelectSuburb")) 
                        || (document.getElementById("city").value == GetString("EnterPostCode")))
                        {
                            alert(GetString("SelectValidSuburb"));
                            document.getElementById("city").style.background = '#FFFFcc';
                            document.getElementById("city").focus();
                            return false;           
                        }
                    }
                }
            }
        
         document.getElementById(MasterpageID + "txtPhone").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtPhone").value).length == 0) {
            alert(GetString(EnterPhoneNumber));
            document.getElementById(MasterpageID + "txtPhone").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtPhone").focus();
            return false;
        }
        else
	      {
      		var e = document.getElementById(MasterpageID + "txtPhone").value;
            var numericexp = /^[0-9]+$/;
            if (!(e.match(numericexp)))
            {
		        alert(GetString(InvalidPhoneNumber));
		        document.getElementById(MasterpageID + "txtPhone").style.background = '#FFFFcc';
		        document.getElementById(MasterpageID + "txtPhone").focus();
		        return false;
      		}
         }
         
return true;
}
function Zipfocus() 
{
    document.getElementById(MasterpageID + "hdnZipCode").value = document.getElementById(MasterpageID + "txtZipCode").value;
}

function ZipCheck() 
{

    if(document.getElementById(MasterpageID + "hdnZipCode").value != document.getElementById(MasterpageID + "txtZipCode").value)
    {  
        ZipChange();
    }
}

//Modified on 29 Jul 09 by Siva - To validate whether the State is available for the selected zip code.
//For Zipcode, city populate using Ajax
function ZipChange() 
{
    document.getElementById(MasterpageID + "hdnZipCode").value = document.getElementById(MasterpageID + "txtZipCode").value;
    document.getElementById(MasterpageID + "spnCity").innerHTML = '<select name=city id=city><option>' + GetString("EnterZipcode") + '</option></select>';
    
    if (document.getElementById(MasterpageID + "txtZipCode").value.length == 0) return false;

    var SuburbSelection = ajax_request('processing.aspx?Action=GetSuburbs&zip=' + trim(document.getElementById(MasterpageID + "txtZipCode").value));

    if (SuburbSelection == GetString("InvalidPostcode")) {
        alert(GetString("InvalidPostcode"));
        document.getElementById(MasterpageID + "txtZipCode").value="";
        document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtZipCode").focus();
        return false;
    } else {
        document.getElementById(MasterpageID + "spnCity").innerHTML = SuburbSelection;
        
        if (SuburbSelection.indexOf('select') == -1) {
            //SelectState();
            document.getElementById(MasterpageID + "hdnCity").value = SuburbSelection;
            //document.getElementById(MasterpageID + "txtPhone").focus();
        } 
        
    }
    return true;
}

// Selecting the State for the given zipcode using Ajax
function SelectState()
{
    var State = ajax_request('processing.aspx?Action=GetState&zip=' + document.getElementById(MasterpageID + "txtZipCode").value);
    if (State == 'NA')
    {
        alert(GetString("StateNAForZip"));
        document.getElementById(MasterpageID + "spnCity").innerHTML = '<select name=city id=city><option>' + GetString("EnterPostCode") + '</option></select>';
        document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtZipCode").focus();
        return false;
    }
    else
    {
        document.getElementById(MasterpageID + "ddlState").value = State;
        CheckShippingState(State);
        return true;    
    }
}

// Check whether we can Ship to the State using Ajax
function CheckShippingState(State)
{
    var blnShipToState = ajax_request('processing.aspx?Action=CheckShippingState&State=' + State);
    
    if (blnShipToState == 'False')
    {
        var oDDL = document.getElementById(MasterpageID + "ddlState");
        var curText = oDDL.options[oDDL.selectedIndex].text;
        var message = GetString("UnableToShipTo") + curText;
        alert(message);
        document.getElementById(MasterpageID + "spnCity").innerHTML = '<select name=city id=city><option>' + GetString("EnterPostCode") + '</option></select>';
        document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtZipCode").focus();
        return false;
    }
        return true;    
}

function ajax_request(url) {
    if (window.XMLHttpRequest) {
        AJAX = new XMLHttpRequest();
    } else {
        AJAX = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (AJAX) {
        AJAX.open("GET", url, false);
        AJAX.send(null);
        return AJAX.responseText;
    } else {
        alert(GetString("BrowserIncompatible"));
    }
}

//Validate Shipping Address
function fnValidateShippingAddress()
{

    document.getElementById(MasterpageID + "txtFirstName").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtFirstName").value).length == 0) {
        alert(GetString("EnterFirstName"));        
        document.getElementById(MasterpageID + "txtFirstName").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtFirstName").focus();
        return false;
    }
    document.getElementById(MasterpageID + "txtLastName").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtLastName").value).length == 0) {
        alert(GetString("EnterLastName"));
        document.getElementById(MasterpageID + "txtLastName").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtLastName").focus();
        return false;
    }
   
        document.getElementById(MasterpageID + "txtAddress1").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtAddress1").value).length == 0) {
            alert(GetString("EnterAddress"));
            document.getElementById(MasterpageID + "txtAddress1").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtAddress1").focus();
            return false;
        }
        
//        document.getElementById(MasterpageID + "txtCity").style.background = '#efefef';
//        if (trim(document.getElementById(MasterpageID + "txtCity").value).length == 0) {
//            alert(GetString("EnterCity"));
//            document.getElementById(MasterpageID + "txtCity").style.background = '#FFFFcc';
//            document.getElementById(MasterpageID + "txtCity").focus();
//            return false;
//        }
        
        if(document.getElementById("city1")!=null)
        {
            //document.getElementById(MasterpageID + "city1").style.background = '#efefef';
            
            if (trim(document.getElementById("city1").value)== "Please Click here to select suburb" || trim(document.getElementById("city1").value)=="")
             {
                alert(GetString("SelectCity"));
                document.getElementById("city1").style.background = '#FFFFcc';
                document.getElementById("city1").focus();
                return false;
            }
        }
         
        document.getElementById(MasterpageID + "txtZipCode").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtZipCode").value).length == 0) {
            alert(GetString("EnterZipcode"));
            document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtZipCode").focus();
            return false;
        }
        /*
        if(document.getElementById("city") == null)
            {
                if ((document.getElementById(MasterpageID + "spnCity") == null) || (document.getElementById("city1") != null))
                {
                    alert(GetString("EnterValidZipcode"));
                    document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
                    document.getElementById(MasterpageID + "txtZipCode").focus();
                    return false;
                }               
            }
            else
            {   
                if(document.getElementById("city").options != null)
                {  
                   if(document.getElementById("city").options.length == 1)
                    {                
                        alert(GetString("EnterValidZipcode"));
                        document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
                        document.getElementById(MasterpageID + "txtZipCode").focus();
                        return false;  
                    }
                    else
                    {                   
                        document.getElementById("city").style.background = '#efefef';
                        if ((document.getElementById("city").value == GetString("ClickToSelectSuburb")) 
                        || (document.getElementById("city").value == GetString("EnterPostCode")))
                        {
                            alert(GetString("SelectValidSuburb"));
                            document.getElementById("city").style.background = '#FFFFcc';
                            document.getElementById("city").focus();
                            return false;           
                        }
                    }
                }
            }*/
         
return true;
}


//PaymentOptions, Forgot Password pages script has been added 
//Start Here

function ClientCheck() 
{
    var valid = false;
    //var ctrlID = "ctl00_cphMaster_";
    var grid = document.getElementById(MasterpageID + "gvPaymentDetails");
    var cell;
        
    //loop starts from 1. rows[0] points to the header.
    for (var i = 1; i < grid.rows.length; i++)
    {
        cell = grid.rows[i].cells[0];
        //loop according to the number of childNodes in the cell
        for (var j=0; j<cell.childNodes.length; j++)
        {         
            //if childNode type is CheckBox and its checked       

    
            if (cell != null && cell.childNodes[j].type =="checkbox" && cell.childNodes[j].checked)
            {
                //assign the status of the Select All checkbox to the cell checkbox within the grid
                valid = true;
                break;
            }
        }
    }
    if (!valid) 
    {
        alert(GetString("SelectCreditCardToDel"));
        return false;
    }
    else
    {
	    if (confirm(GetString("ConfirmCreditCardDel"))==true)
		    return true;
	    else
		    return false;
    }
    //return valid;
}

function validate() 
{
    var var1 = new Date();
    var CurrMonth = var1.getMonth();
    var CurrYear = var1.getFullYear();
    //var ctrlID = "ctl00_cphMaster_";
    var ccnum = trim(document.getElementById(MasterpageID + "txtCardNumber").value);
    var seccode = trim(document.getElementById(MasterpageID + "txtSecCode").value);
   
//    if (document.getElementById(MasterpageID + "ddlPayment").value == 'Select') 
//    {
//        alert('Please select the payment type.');
//        document.getElementById(MasterpageID + "ddlPayment").style.background = '#FFFFcc';
//        document.getElementById(MasterpageID + "ddlPayment").focus();
//        return false;
//    }
    document.getElementById(MasterpageID + "txtCardNumber").style.background = '#efefef';
    //alert(ccnum.length);
    if(ccnum.length > 0)
    {
         //ccnum = ccnum.replace(/ /g, '').replace(/-/g, '');
         document.getElementById(MasterpageID + "txtCardNumber").style.background = '#efefef';     
                 
        if (!isValidCardNumber(ccnum)) 
        {
            alert(GetString("EnterValidCreditCard"));
            document.getElementById(MasterpageID + "txtCardNumber").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtCardNumber").focus();
            return false;
        }
        document.getElementById(MasterpageID + "txtSecCode").style.background = '#efefef';
        
         if (seccode.length <= 2)
        {
            alert(GetString("EnterValidSecCode"));
            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtSecCode").focus();
            return false;
        }
        
        //Only for Amex card it should accept 4 digit security code
        else if(seccode.length == 4 && !(ccnum.substring(0,2) == "34" || ccnum.substring(0,2) == "37") )
        {
            alert(GetString("EnterValidSecCode"));
            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtSecCode").focus();
            return false;
        }
        else if(seccode.length == 3 && (ccnum.substring(0,2) == "34" || ccnum.substring(0,2) == "37") )


        {
            alert(GetString("EnterValidSecCode"));
            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtSecCode").focus();
            return false;
        }
        
        if (!isValidSecCode(seccode)) 
        {
            alert(GetString("Enter3or4DigitSecCode"));
            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtSecCode").focus();
            return false;
        }
        
//        if (seccode.length != 3)
//        {
//            alert(GetString("EnterValidSecCode"));
//            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
//            document.getElementById(MasterpageID + "txtSecCode").focus();
//            return false;
//        }
//        
//        if (!isValidSecCode(seccode)) 
//        {
//            alert(GetString("Enter3DigitSecCode"));
//            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
//            document.getElementById(MasterpageID + "txtSecCode").focus();
//            return false;
//        }
        
        document.getElementById(MasterpageID + "ddlMonth").style.background = '#efefef';
        if (document.getElementById(MasterpageID + "ddlMonth").selectedIndex == 0)
         {
            alert(GetString("EnterExpMonth"));
            document.getElementById(MasterpageID + "ddlMonth").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "ddlMonth").focus();
            return false;
        }

       document.getElementById(MasterpageID + "ddlYear").style.background = '#efefef';
        if (document.getElementById(MasterpageID + "ddlYear").selectedIndex == 0) 
        {
            alert(GetString("EnterExpyear"));
            document.getElementById(MasterpageID + "ddlYear").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "ddlYear").focus();
            return false;
        }
        
       document.getElementById(MasterpageID + "ddlMonth").style.background = '#efefef';
        if ((document.getElementById(MasterpageID + "ddlMonth").value < CurrMonth+1)&&( document.getElementById(MasterpageID + "ddlYear").value <= CurrYear)) 
        {
            alert(GetString("ExpDateLessThanCurrDate"));
            document.getElementById(MasterpageID + "ddlMonth").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "ddlMonth").focus();
            return false;
        }
    }
    else
    {
        alert(GetString("EnterValidCreditCard"));
        document.getElementById(MasterpageID + "txtCardNumber").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtCardNumber").focus();
        return false;
    }
}
    
function isValidCardNumber(strNum)
{
    //var nCheck = 0;
    var nDigit = 0;
    //var bEven = false;
    var checksum = 0;
    //var nDigitCheck = strNum.substring(0,6);
    
    var blnIsAcceptableCard = false;
    
    if(strNum.length < 13 || strNum.indexOf(' ') != -1)
    {
        return false;
    }
    //Visa 
    if(strNum.substring(0,1) == "4" && (strNum.length == 13 || strNum.length == 16))
    {   
        blnIsAcceptableCard = true;
    }
    //Master Card                  
    if(strNum.substring(0,2) >= "51" && strNum.substring(0,2) <= "55" && strNum.length == 16)
    {
        blnIsAcceptableCard = true;
    }      
    //American Express       
    if((strNum.substring(0,2) == "34" || strNum.substring(0,2) == "37") && strNum.length == 15)
    {
        blnIsAcceptableCard = true;
    }  
    if (blnIsAcceptableCard == false) 
    {
        return false;    
    } 

    for (var n=(2-(strNum.length % 2)); n<=strNum.length; n+=2)
    {
        checksum += parseInt(strNum.charAt(n-1));
    }
    for (n =(strNum.length % 2) + 1; n<strNum.length; n+=2) 
    {
        var cDigit = strNum.charAt(n);
        if (isDigit(cDigit))
       {
	    cDigit = parseInt(strNum.charAt(n-1)) * 2;
	    if (cDigit < 10) 
	    {
	     checksum += cDigit; 
	     } 
	     else 
	     { checksum += (cDigit-9); 
	     }
       }
        else if (cDigit != ' ' && cDigit != '.' && cDigit != '-') 
        {
	    return false;
        }
    }

	return (checksum % 10) == 0;
}

function isValidSecCode(strNum)
{
    var nCheck = 0;
    var nDigit = 0;
    var bEven = false;
    var result = false;
    for (n = strNum.length - 1; n >= 0; n--) 
    {
        var cDigit = strNum.charAt(n);
        if (isDigit(cDigit)) 
        {
            var nDigit = parseInt(cDigit, 10);
            nCheck += nDigit;
        }
        else 
        {
            return false;
        }
    }
    return true;
}
        
function isDigit(c) 
{
    var strAllowed = "1234567890";
    return (strAllowed.indexOf(c) != -1);
}

function validateEmail() 
{
    document.getElementById(MasterpageID + "txtEmail").style.background = '#efefef';
    var e = document.getElementById(MasterpageID + "txtEmail").value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!(filter.test(e))) 
    {
        alert(GetString("InvalidEmail"));
        document.getElementById(MasterpageID + "txtEmail").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtEmail").focus();
        return false;
    }
    return true;
}

function validatePassword()
{
    document.getElementById(MasterpageID + "txtPassword").style.background = '#efefef';
    if (document.getElementById(MasterpageID + "txtPassword").value.length < 6) 
    {
        alert(GetString("PasswordAtleast6Char"));
        document.getElementById(MasterpageID + "txtPassword").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtPassword").focus();
        return false;
    }

    document.getElementById(MasterpageID + "txtPasswordRepeat").style.background = '#efefef';
    if (document.getElementById(MasterpageID + "txtPassword").value != document.getElementById(MasterpageID + "txtPasswordRepeat").value) 
    {
        alert(GetString("PasswordDoNotMatch"));
        document.getElementById(MasterpageID + "txtPasswordRepeat").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtPasswordRepeat").focus();
        return false;
    }
    return true;
}

//End Here


// Function to call the pages by selecting the dropdown in helpful hints pages
//Start
function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//End


function fnValidateQuantity()
{ 
    var regExp = /^[0-9]*$/;  
    if(document.getElementById(MasterpageID + "txtQuantity") != null)
    {
        document.getElementById(MasterpageID + "txtQuantity").style.background = '#efefef';
            if (trim(document.getElementById(MasterpageID + "txtQuantity").value).length == 0) {
            alert(GetString("EnterQuantity"));
            document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtQuantity").focus();
            return false;
        }
        else if (1 > (trim(document.getElementById(MasterpageID + "txtQuantity").value)))
        {
            alert(GetString("QuantityCannotBeZero"));
            document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtQuantity").focus();
            return false;
        }
        else if ((trim(document.getElementById(MasterpageID + "txtQuantity").value)) > 999)
        {
            alert(GetString("QuantityGreaterThan999"));
            document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtQuantity").focus();
            return false;
        }
        else if(regExp.test(trim(document.getElementById(MasterpageID + "txtQuantity").value))==false)
	    {
            alert(GetString("EnterValidNumericQuantity"));
	        document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtQuantity").focus();
            return false;
	    }	
	}
    return true;
}


 function EditShoppingCart()
 {
   window.location="Shopping_Cart.aspx?action=edit";

 }
 
  function verifyAge() 
  {  
  if (!(document.getElementById("age_verif3").checked))
  { 
	alert(GetString("Certify21YearsOlder"));
	document.getElementById("age_verif3").style.background = '#FFFFcc';
	document.getElementById("age_verif3").focus(); 	
	return false;
  }
  else
  {
    //document.getElementById("checkout").submit();
    return true;
  }
}
   
    function checkOne(rdoIdOriginal)
    {
        var rdoId = rdoIdOriginal;
        var rdoCommonID;
        if(rdoId.indexOf('rdo1') > 0)
        {        
            rdoCommonID = rdoId.replace('rdo1','')
        }
        if(rdoId.indexOf('rdo2') > 0)
        {        
            rdoCommonID = rdoId.replace('rdo2','')
        }
        if(rdoId.indexOf('rdo3') > 0)
        {        
            rdoCommonID = rdoId.replace('rdo3','')
        }
        //var items=document.getElementById("frmSearchResults"); //your form name
        var items = document.aspnetForm;
        for(var i=0;i<items.length;i++)
        {
            if(items.elements[i].type=="radio")//detect radio button
            {
                  if(items.elements[i].id.indexOf("productsList")>-1)//datalist name
                  {
                    if(items.elements[i].id.indexOf(rdoCommonID)>-1) // prefixed client ID for checking
                            items.elements[i].checked=false;
                    if(items.elements[i].id == rdoIdOriginal)
                        items.elements[i].checked=true;
                  } 
            }
        }
    }
    var gblQty;
    function updateQtyVer1(xx, x, id, oldQty, QtyThreshold) 
	{
	    gblQty = id;
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_submitPromo").disabled = true;

		var prodid = parseInt(id.value);
		if(prodid>parseInt(QtyThreshold, 10) && parseInt(QtyThreshold, 10) > 0)
		{
		    alert(GetString("EnterQuantityNotMoreThan").replace("[X]", QtyThreshold));
			setTimeout("gblQty.select()", 1);
			return false;
		}
		if (prodid > 0 && prodid < 1000) 
		{
		    if(oldQty != eval(prodid))
		    {		    
			    // update quantity field
			    window.location.href = "shopping_cart.aspx?action=update&id=" + x + "&qty=" + eval(prodid);
			}
			else if(oldQty == eval(prodid))
			{
			    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = false;
	            document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = false;
	            document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = false;
	            document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = false;
	            document.getElementById("ctl00_cphMaster_submitPromo").disabled = false;
			}
		} 
		else if (prodid > 999) 
		{
		    alert(GetString("QuantityGreaterThan999"));
		    setTimeout("gblQty.select()", 1);
		} 
		else if (prodid < 0 ) 
		{
		    alert(GetString("EnterValidQuantity"));
		    setTimeout("gblQty.select()", 1);
		}
		else if(prodid == 'NaN')
		{
            alert(GetString("EnterValidNumericQuantity"));
		    setTimeout("gblQty.select()", 1);
		} 
		else {
			alert(GetString("QuantityCannotBeZero"));
			setTimeout("gblQty.select()", 1);
		}
	}
   
	function updateQty(xx, x, id, oldQty) 
	{
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_submitPromo").disabled = true;

		var prodid = parseInt(id.value);
		if (prodid > 0 && prodid < 1000) 
		{
		    if(oldQty != eval(prodid))
		    {		    
			    // update quantity field
			    window.location.href = "shopping_cart.aspx?action=update&id=" + x + "&qty=" + eval(prodid);
			}
			else if(oldQty == eval(prodid))
			{
			    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = false;
	            document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = false;
	            document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = false;
	            document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = false;
	            document.getElementById("ctl00_cphMaster_submitPromo").disabled = false;
			}
		} 
		else if (prodid > 999) 
		{
		    alert(GetString("QuantityGreaterThan999"));
		    id.focus();		
		} 
		else if (prodid < 0 ) 
		{
		    alert(GetString("EnterValidQuantity"));
		    id.focus();		
		}
		else if(prodid == 'NaN')
		{
            alert(GetString("EnterValidNumericQuantity"));
		    id.focus();		
		} 
		else {
			alert(GetString("QuantityCannotBeZero"));
			id.focus();
		}
	}
	function clearCart() 
	{
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_submitPromo").disabled = true;

		if (confirm(GetString("ConfirmDeleteAllItems"))) {			
			window.location.href = "shopping_cart.aspx?action=deleteall";
		} 
		else 
		{
			document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = false;
			document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = false;
	        document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = false;
	        document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = false;
	        document.getElementById("ctl00_cphMaster_submitPromo").disabled = false;
		}
	}
	
	function updateQtyPB(xx, x, id) 
	{
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_submitPromo").disabled = true;

		var prodid = id.value;
		if (prodid > 0 && (prodid % 6) == 0 ) {
			// update quantity field
			window.location.href = "shopping_cart.aspx?action=update&id=" + x + "&qty=" + eval(prodid);
		} else {
			alert(GetString("EnterQtyInMultiplesOf6"));
			id.focus();
		}
	}
	
	function removeItem(x) 
	{
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = true;
	    document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = true;
	    document.getElementById("ctl00_cphMaster_submitPromo").disabled = true;
		
		if (confirm(GetString("ConfirmDeleteThisItem"))) {
			// update quantity field
			location.href = "shopping_cart.aspx?action=delete&id=" + x;
		} 
		else 
		{
		    document.getElementById("ctl00_cphMaster_btnContinueShoppingTop").disabled = false;
			document.getElementById("ctl00_cphMaster_btnContinueShoppingBottom").disabled = false;
	        document.getElementById("ctl00_cphMaster_btnCheckoutTop").disabled = false;
	        document.getElementById("ctl00_cphMaster_btnCheckoutBottom").disabled = false;
	        document.getElementById("ctl00_cphMaster_submitPromo").disabled = false;
		}
	}
	
	function SubmitPromo()
	{
	    var promoCode = document.getElementById("txtPromo").value;
		if (promoCode == "") 
		{
		    alert(GetString("EnterPromoCode"));
		    document.getElementById("txtPromo").focus();		
		} 
		else 
		{
			location.href = "shopping_cart.aspx?coupon_code=" + promoCode;
		}
	}	
	function IsNumeric(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 RedirectForCheckout()
	{
	   
       var url = window.location;
       var fullhost = window.location.hostname;
	   if (IsNumeric(fullhost) == false && fullhost.indexOf("alpha")==-1 && fullhost.indexOf("beta")==-1 && fullhost.indexOf("staging")==-1) 
       {
        window.location.href = "https://"  + fullhost + "/AddressForm.aspx";
       }
       else 
       {
       window.location.href = "AddressForm.aspx";
       }
	}
    
    
    
function fnEmailSignupValidation()
{
  var title = (document.getElementById('ctl00_cphMaster_ddlTitle').options[document.getElementById('ctl00_cphMaster_ddlTitle').selectedIndex].text);
   
    document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#efefef';
    if(trim(document.getElementById("ctl00_cphMaster_txtEmailID").value).length == 0 )

    {
        alert(GetString("EnterEmail"));
        document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#FFFFcc';
        document.getElementById("ctl00_cphMaster_txtEmailID").focus();
        return false;
    }

    document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#efefef';
    var e = document.getElementById("ctl00_cphMaster_txtEmailID").value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!(filter.test(e))) 
    {       
        alert(GetString("InvalidEmail"));        
        document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#FFFFcc';
        document.getElementById("ctl00_cphMaster_txtEmailID").focus();
        return false;
    }
//    document.getElementById("ctl00_cphMaster_txtFirstName").style.background = '#efefef';
//        if (trim(document.getElementById("ctl00_cphMaster_txtFirstName").value).length == 0) {
//        alert(GetString("EnterFirstName"));
//        document.getElementById("ctl00_cphMaster_txtFirstName").style.background = '#FFFFcc';
//        document.getElementById("ctl00_cphMaster_txtFirstName").focus();
//        return false;
//    }
//    document.getElementById("ctl00_cphMaster_txtLastName").style.background = '#efefef';
//        if (trim(document.getElementById("ctl00_cphMaster_txtLastName").value).length == 0) {
//        alert(GetString("EnterLastName"));
//        document.getElementById("ctl00_cphMaster_txtLastName").style.background = '#FFFFcc';
//        document.getElementById("ctl00_cphMaster_txtLastName").focus();
//        return false;
//    }  
//     document.getElementById("ctl00_cphMaster_txtLastName").style.background = '#efefef';
     
    var EmailSignUp = ajax_request('processing.aspx?Action=EmailSignUp&EmailId=' + trim(document.getElementById("ctl00_cphMaster_txtEmailID").value) + '&Title=' + trim(title) + '&FirstName=' + trim(document.getElementById("ctl00_cphMaster_txtFirstName").value) + '&LastName=' + trim(document.getElementById("ctl00_cphMaster_txtLastName").value));  
     
    if(EmailSignUp == "True")
    {        
       document.getElementById("ctl00_cphMaster_txtEmailID").value = "";
       document.getElementById("ctl00_cphMaster_txtFirstName").value = "";
       document.getElementById("ctl00_cphMaster_txtLastName").value = "";
       //alert(GetString("ThanksForSubscribing1"));
       document.getElementById("ctl00_cphMaster_emailerror1").innerHTML = GetString("ThanksForSubscribing1");        
       document.getElementById("ctl00_cphMaster_emailerror1").style.color = '#810541'; 
       return false;
    }
//    else
//    {
//        return false;
//    }
    return true;
}

function fnKatalogSignupValidation()
{
   var title = (document.getElementById('ctl00_cphMaster_ddlTitle').options[document.getElementById('ctl00_cphMaster_ddlTitle').selectedIndex].text);
    
    document.getElementById("ctl00_cphMaster_txtFirstName").style.background = '#efefef';
        if (trim(document.getElementById("ctl00_cphMaster_txtFirstName").value).length == 0) {
        alert(GetString("EnterFirstName"));
        document.getElementById("ctl00_cphMaster_txtFirstName").style.background = '#FFFFcc';
        document.getElementById("ctl00_cphMaster_txtFirstName").focus();
        return false;
    }
    document.getElementById("ctl00_cphMaster_txtLastName").style.background = '#efefef';
        if (trim(document.getElementById("ctl00_cphMaster_txtLastName").value).length == 0) {
        alert(GetString("EnterLastName"));
        document.getElementById("ctl00_cphMaster_txtLastName").style.background = '#FFFFcc';
        document.getElementById("ctl00_cphMaster_txtLastName").focus();
        return false;
    }  
//     document.getElementById("ctl00_cphMaster_txtLastName").style.background = '#efefef';

//    document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#efefef';
//    if(trim(document.getElementById("ctl00_cphMaster_txtEmailID").value).length == 0 )
//    {
//        alert(GetString("EnterEmail"));
//        document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#FFFFcc';
//        document.getElementById("ctl00_cphMaster_txtEmailID").focus();
//        return false;
//    }

    document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#efefef';
    if(!trim(document.getElementById("ctl00_cphMaster_txtEmailID").value).length == 0)
    {
        var e = document.getElementById("ctl00_cphMaster_txtEmailID").value;    
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (!(filter.test(e))) 
        {       
            alert(GetString("InvalidEmail"));        
            document.getElementById("ctl00_cphMaster_txtEmailID").style.background = '#FFFFcc';
            document.getElementById("ctl00_cphMaster_txtEmailID").focus();
            return false;
        }   
    } 
    document.getElementById("ctl00_cphMaster_txtAddress1").style.background = '#efefef';
        if (trim(document.getElementById("ctl00_cphMaster_txtAddress1").value).length == 0) {
        alert(GetString("EnterStreet"));
        document.getElementById("ctl00_cphMaster_txtAddress1").style.background = '#FFFFcc';
        document.getElementById("ctl00_cphMaster_txtAddress1").focus();
        return false;
    }
   
    document.getElementById("ctl00_cphMaster_txtZipCode").style.background = '#efefef';
        if (trim(document.getElementById("ctl00_cphMaster_txtZipCode").value).length == 0) 
        {        
            if (!IsNumeric(trim(document.getElementById("ctl00_cphMaster_txtZipCode").value)))
            {
                alert(GetString("EnterZipcode"));
                document.getElementById("ctl00_cphMaster_txtZipCode").style.background = '#FFFFcc';
                document.getElementById("ctl00_cphMaster_txtZipCode").focus();
                return false;
            }
        }
         
        if (trim(document.getElementById("ctl00_cphMaster_txtZipCode").value).length < 4) 
        {
            //if (!IsNumeric(trim(document.getElementById("ctl00_cphMaster_txtZipCode").value)))
            //{
                alert(GetString("EnterValidZipcode"));
                document.getElementById("ctl00_cphMaster_txtZipCode").style.background = '#FFFFcc';
                document.getElementById("ctl00_cphMaster_txtZipCode").focus();
                return false;
            //}
        } 
         var e = document.getElementById("ctl00_cphMaster_txtZipCode").value;
                    var numericexp = /^[0-9]+$/;
                    if (!(e.match(numericexp)))
                    {
                         alert(GetString("EnterValidZipcode"));
                        document.getElementById("ctl00_cphMaster_txtZipCode").style.background = '#FFFFcc';
                        document.getElementById("ctl00_cphMaster_txtZipCode").focus();
                        return false;
                    }
        document.getElementById("ctl00_cphMaster_txtLocality").style.background = '#efefef';
        if (trim(document.getElementById("ctl00_cphMaster_txtLocality").value).length == 0) {
        alert(GetString("EnterLocality"));
        document.getElementById("ctl00_cphMaster_txtLocality").style.background = '#FFFFcc';
        document.getElementById("ctl00_cphMaster_txtLocality").focus();
        return false;
    } 
//       if (!document.getElementById("chkoutKatalog").checked) {
//					
//					 alert(GetString("AgeGT18"));
//					
//					document.getElementById("chkoutKatalog").focus();
//					document.getElementById("chkoutKatalog").style.background = '#FFFFcc';
//					return false;
//			  }	
//     var chkKatalog;
//     if (document.getElementById("chkoutKatalog").checked)
//     {
//        chkKatalog= "Y"
//     }
//     else
//     {
//        chkKatalog="N"
//     }
//     
//     
//    var KatalogSignUp = ajax_request('processing.aspx?Action=KatalogSignUp&EmailId=' + trim(document.getElementById("ctl00_cphMaster_txtEmailID").value) + '&Title=' + trim(title) + '&FirstName=' + trim(document.getElementById("ctl00_cphMaster_txtFirstName").value) + '&LastName=' + trim(document.getElementById("ctl00_cphMaster_txtLastName").value) + '&Address=' + trim(document.getElementById("ctl00_cphMaster_txtAddress1").value)+ '&ZipCode=' + trim(document.getElementById("ctl00_cphMaster_txtZipCode").value) + '&Locality=' + trim(document.getElementById("ctl00_cphMaster_txtLocality").value) + '&chkKatalog=' + trim(chkKatalog));
//   
//    if(KatalogSignUp = true)
//    {   
//       document.getElementById("ctl00_cphMaster_txtEmailID").value = "";
//       document.getElementById("ctl00_cphMaster_txtFirstName").value = "";
//       document.getElementById("ctl00_cphMaster_txtLastName").value = ""; 
//       document.getElementById("ctl00_cphMaster_txtAddress1").value = "";
//       document.getElementById("ctl00_cphMaster_txtLocality").value= "";
//       document.getElementById("ctl00_cphMaster_txtZipCode").value= ""; 
//    }
//    else
//    {
//        return false;
//    }
    return true;
}

function launchpopup(popup)
{
	var url = popup;

	window.open(url,'popup','height=660,width=640,scrollbars=yes,resizable=no,left = 100,top = 20');
}

function ChangeLoginButton(SelectedRadioButton)
{
    if(SelectedRadioButton == "NewCustomer")
    {
        document.getElementById('ctl00_cphMaster_btnLogin').value = GetString("Register");
    }
    else if(SelectedRadioButton == "OldCustomer")
    {
        document.getElementById('ctl00_cphMaster_btnLogin').value = GetString("Login");
    }
}
function ValidateCaseSelection(strElementType)
{
    var maxNoOfQty = trim(document.getElementById('hdnMaxAllowedQty').value);
    var maxNoOfCase = trim(document.getElementById('hdnMaxAllowedCases').value); 
    var SelectedNoOfCase = 0;
    var SelectedNoOfQty = 0;
    var elementArray = document.forms["form"].elements;
    var blnSelected = false;    
    //loop starts from 1. rows[0] points to the header.
    for (i=1; i<elementArray.length; i++)
    {            
        var element =  elementArray[i];
        
//        if (element.id.indexOf("preference") != -1)
//        {
            if( element.type == strElementType)
            {
                if (element.checked == true)
                {
                    blnSelected = true;
                    SelectedNoOfCase += 1;                            
                }
            }
            if( element.type == "text")
            { 
                if (blnSelected == true)               
                {
                    if (ValidateQty(element) == true)
                    {
                        SelectedNoOfQty += parseInt(trim(element.value));
                    }
                    else
                    {
                        element.select();
                        return false;
                    }
                }                
                blnSelected = false;
            }
        //}                
    }
    if(SelectedNoOfCase == 0)
    {
        alert(GetString("SelectACase"));
        return false;
    }
    if((SelectedNoOfCase > maxNoOfCase))
    {
        alert(GetString("LtdNoPerHousehold").replace("[X]", maxNoOfCase));
        return false;
    }
    if (SelectedNoOfQty > maxNoOfQty) {
        alert(GetString("MaxQtyPerHousehold").replace("[X]", maxNoOfQty));
        return false;
    }
    EnableQtyTextBox(strElementType);
    document.forms["form"].submit();
}
function EnableQtyTextBox(strElementType)
{
    var SelectedACase;
    SelectedACase = false;
    var elementArray = document.forms["form"].elements;
    //loop starts from 1. rows[0] points to the header.
    for (i=1; i<elementArray.length; i++)
    {            
        var element =  elementArray[i];
        if( element.type == strElementType)
        {
            if (element.checked == true)
            {
                SelectedACase = true;                           
            }
            else
            {
                SelectedACase = false;
            }
        }
        if(element.type == "text" && SelectedACase == true)
        {
            SelectedACase = false;
            element.disabled = false;
            if(element.value == "")
            {
                element.value = 1;
                element.select();
            }            
        }
        else if(element.type == "text" && SelectedACase == false)
        {
            element.disabled = true;
            element.value = "";
        }
    }
}
function ValidateQty(id) 
{
    var regExp = /^[0-9]*$/;
    if(regExp.test(trim(id.value))==false || trim(id.value) == "")
	{
        alert(GetString("EnterValidNumericQuantity"));
	    id.select();
	    return false;
	}
	if (parseInt(id.value) == 0) {
		alert(GetString("QuantityCannotBeZero"));
		id.select();
		return false;
	}
	return true;
//	var maxNoOfCase = trim(document.getElementById('maxAllowedCases').value);
//	if(maxNoOfCase !="" && maxNoOfCase>0)
//	{
//	    if (parseInt(id.value) > maxNoOfCase) {
//		    alert(GetString("QuantityGreaterThan999").replace("999", maxNoOfCase));
//		    id.select();
//		    return;
//	    }
//	}
}
