
var MasterpageID = "ctl00_cphMaster_";
function new_window()
  {
    //newwindow=window.open("privacypolicy.aspx",'xczzxc','top=50,left=250,width=700,height=650,scrollbars=yes');
    var url = window.location;
    var fullhost = window.location.hostname;
    //window.location.href = "http://" + fullhost + "/privacypolicy.aspx";
    newwindow = window.open("http://" + fullhost + "/privacypolicy.aspx",'xczzxc','top=50,left=250,width=700,height=650,scrollbars=yes');
    newwindow.focus();
    return false;
  }

function fnDelete() 
{
    if(confirm("Are you sure you want to delete this address?"))
    {
    return true;        
    }
    else
    {
    return false;
    }
}
function EditShoppingCart()
 {
   window.location="Shopping_Cart.aspx?action=edit";

 }
 
function ValidateConfirmOrder() 
{       
    if(parseInt(document.getElementById(MasterpageID + "hdnNoOfBottles").value,10) < 6  && document.getElementById(MasterpageID + "hdnTotal").value < 800)   
    {
        alert('Please note: orders must be 6 or more bottles, or total over $800.');
        return false;
    }
    if(!(fnValidateCalendarControl()))
    {
        return false;
    }
    if (!(document.getElementById("age_verif3").checked))
    { 
        alert('Please certify that you are 18 years or older.');
        document.getElementById("age_verif3").style.background = '#FFFFcc';
        document.getElementById("age_verif3").focus(); 	
        return false;
    }
    //document.getElementById("checkout").submit();
    return true;
}
//Function to Validate in Login Page
function fnLoginValidation()
{
    //var emailReg = /^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/;
    
	//var emailReg =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailADDR = $("#"+ MasterpageID + "txtEmailId").val();
	//alert(emailADDR);
	
	if(emailADDR == '') {
		//$("#login-error").replaceWith('<div class="error">You forgot to enter an email address.</div>');
		$("#" + MasterpageID + "txtEmailId").css({'background-color' : '#FFF6A9'});
		$("#" + MasterpageID + "txtEmailId").focus();
		//hasError = true;
		alert("You forgot to enter an email address.");
		return false;}
	else if(!isValidEmail(emailADDR)) {
//		$("#login-error").replaceWith("<div class='error''>Your email address is invalid, please try again.</div>");
		$("#" + MasterpageID + "txtEmailId").css({'background-color' : '#FFF6A9'});
		$("#" + MasterpageID + "txtEmailId").focus();
//		hasError = true;
		alert("Your email address is invalid, please try again.");
		return false;
	}
	
    if((document.getElementById(MasterpageID + "rdoOldCustomer").checked == true) && (trim(document.getElementById(MasterpageID + "txtPassword").value).length == 0 ))
    {
        //alert("Please enter your password");
//        $("#login-error").replaceWith("<div class='error''>Please enter your password.</div>");
//        $("#" + MasterpageID + "txtPassword").css({'border' : '1px solid red','background-color' : 'white'});
//        $("#" + MasterpageID + "txtPassword").after("<br><span style='color:red;'>Password is invalid</span>.");
        document.getElementById(MasterpageID + "txtPassword").style.background = '#FFFFcc';
        alert("Please enter your password.");
        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;
}

// 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));
	
}

// Check if the input is a numeric value
function isNumeric(inputVal)
{
    var e = inputVal;
    var numericexp = /^[0-9]+$/;
    if (!(e.match(numericexp)))
    {
        return false;
    }
    return true;
}
//Wineshop results validation
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;
              } 
        }
    }
}

//Shopping cart validation
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;

    // sepcify the radix as 10 so that it treats the number as decimal
    // otherwise it treat the number as Hexadecimal if starts with 0x Or octal if starts with 0
    if(!isInteger(id.value))
    {
        $("#cart-error").replaceWith("<div class='error''>Please enter valid numeric quantity. </div>");
	    id.focus();
	    return;
    }
	var prodid = parseInt(id.value,10);		
	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
		{
		    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('Please enter a quantity upto 999');
	    $("#cart-error").replaceWith("<div class='error''>Please enter a quantity up to 999</div>");
	    id.focus();		
	} 
	else if (prodid < 0 ) 
	{
	    //alert('Please enter valid quantity');
	    $("#cart-error").replaceWith("<div class='error''>Please enter valid quantity.</div>");
	    id.focus();		
	}
	else if(prodid == 'NaN')
	{
        //alert('Please enter valid numeric quantity');
	    $("#cart-error").replaceWith("<div class='error''>Please enter valid numeric quantity.</div>");
	    id.focus();		
	} 
	else {
		//alert('Please enter a quantity greater than 0');
	    $("#cart-error").replaceWith("<div class='error''>Please enter a quantity greater than 0.</div>");
		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('Are you sure you want to delete all the items?')) {			
		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 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('Are you sure you want to delete this item?')) {
		// 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 = trim(document.getElementById("txtPromo").value);
	if (promoCode == "") 
	{
	    //alert('Please enter Promo Code');
	    $("#cart-error").replaceWith("<div class='error''>Please enter your Voucher Code.</div>");
	    $("#txtPromo").css({'border' : '1px solid red'});
	    document.getElementById("txtPromo").focus();		
	} 
	else if (promoCode == document.getElementById("ctl00_cphMaster_hdnAppliedPromo").value) 
	{
	    alert('Thank you for entering your voucher code. Your 12-bottle case will cost $999.');
	} 
	else if (promoCode == document.getElementById("ctl00_cphMaster_hdnAppliedPromoSubscriber").value) 
	{
	    alert('Thank you for entering your voucher code. Your 12-bottle case will cost $999');
	}
	else 
	{
		location.href = "shopping_cart.aspx?coupon_code=" + promoCode;
	}
}	

function RedirectForCheckout()
{
    if(parseInt(document.getElementById(MasterpageID + "hdnNoOfBottles").value,10) < 6 && document.getElementById(MasterpageID + "hdnTotal").value < 800)
    {
        alert('Please note: orders must be 6 or more bottles, or total over $800.');
        return false;
    }
//   var url = window.location;
//   var fullhost = window.location.hostname;
//   var host = fullhost.substring(0,3); 
//   //alert(host);
//   if (host == "www")
//   {
//    window.location.href = "https://www.laithwaiteswine.hk/AddressForm.aspx";
//   }
//   else 
//   {
//   window.location.href = "AddressForm.aspx";
//   }
   
   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";
   }
   
   
}


//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 RegionChange() 
{
    //document.getElementById(MasterpageID + "hdnZipCode").value = document.getElementById(MasterpageID + "txtZipCode").value;
    document.getElementById(MasterpageID + "spnDistrict").innerHTML = '<select name=ddlDistrict id=ddlDistrict runat=server><option>' + "Please Select Your Postal District" + '</option></select>';
    
    if (document.getElementById(MasterpageID + "ddlRegion").value == "Select") return false;

    var SuburbSelection = ajax_request('processing.aspx?Action=GetDistrict&Region=' + trim(document.getElementById(MasterpageID + "ddlRegion").value));

    document.getElementById(MasterpageID + "spnDistrict").innerHTML = SuburbSelection;
    
    return true;
}

//Validate Shipping Address
function fnValidateShippingAddress()
{

    document.getElementById(MasterpageID + "txtFirstName").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtFirstName").value).length == 0) {
        alert('Please enter your First name');
        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('Please enter your Last name');
        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('Please enter your Address');
        document.getElementById(MasterpageID + "txtAddress1").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtAddress1").focus();
        return false;
    }
    
    document.getElementById(MasterpageID + "ddlRegion").style.background = '#efefef';
    if (trim(document.getElementById(MasterpageID + "ddlRegion").value).length == 0 || trim(document.getElementById(MasterpageID + "ddlRegion").value) == "Select") {
        alert('Please select a Region');
        document.getElementById(MasterpageID + "ddlRegion").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "ddlRegion").focus();
        return false;
    }
    
    var ddlDistrict = document.getElementById(MasterpageID + "ddlDistrict");
    if (ddlDistrict == null)
    {
        ddlDistrict = document.getElementById("ddlDistrict");
    }
    ddlDistrict.style.background = '#efefef';
    if (trim(ddlDistrict.value).length == 0 || trim(ddlDistrict.value) == "Please Select Your Postal District") {
        alert('Please select a Postal District');
        ddlDistrict.style.background = '#FFFFcc';
        ddlDistrict.focus();
        return false;
    }      
        
    document.getElementById(MasterpageID + "txtPhone").style.background = '#efefef';
    if (trim(document.getElementById(MasterpageID + "txtPhone").value).length == 0)
    {
        alert('Please enter Shipping Address Phone ');
        document.getElementById(MasterpageID + "txtPhone").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtPhone").focus();
        return false;
    }  
    if (trim(document.getElementById(MasterpageID + "txtPhone").value).length < 8)
    {
        alert('Please enter valid Shipping Address Phone  - no spaces');
        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('Please enter valid Shipping Address Phone  - no spaces');
	        document.getElementById(MasterpageID + "txtPhone").style.background = '#FFFFcc';
	        document.getElementById(MasterpageID + "txtPhone").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("Please select a checkbox to delete the credit card.");
        return false;
    }
    else
    {
	    if (confirm("Are you sure you want to delete the selected card(s)?")==true)
		    return true;
	    else
		    return false;
    }
    //return valid;
}

function ValidatePaymentInfo() 
{
    var var1 = new Date();
    var CurrMonth = var1.getMonth();
    var CurrYear = var1.getFullYear();
    //var ctrlID = "ctl00_cphMaster_";
    var ccnum = document.getElementById(MasterpageID + "txtCardNumber").value;
    //var seccode = document.getElementById(MasterpageID + "txtSecCode").value;
    
    //alert(seccode);
    
//    ccnum = ccnum.replace(/ /g, '').replace(/-/g, '');
//    document.getElementById(MasterpageID + "txtCardNumber").style.background = '#efefef';

//    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)
    {
        if (!isValidCardNumber(ccnum)) 
        {
            //alert('Please enter a valid credit card number.');
            alert("We accept valid VISA, MasterCard, Amex and JCB cards only.");
            //alert(document.getElementById(MasterpageID + "lblError").value);
            document.getElementById(MasterpageID + "txtCardNumber").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtCardNumber").focus();
            return false;
        }
        if (IsCardAllowed(document.getElementById(MasterpageID + "txtCardNumber")) == false)
        {            
            return false;
        }

//        document.getElementById(MasterpageID + "txtSecCode").style.background = '#efefef';
//        
//        if (seccode.length != 3)
//        {
//            alert('Please enter valid sec code.');
//            document.getElementById(MasterpageID + "txtSecCode").style.background = '#FFFFcc';
//            document.getElementById(MasterpageID + "txtSecCode").focus();
//            return false;
//        }
//        
//        if (!isValidSecCode(seccode)) 
//        {
//            alert('Please enter 3 digits sec code.');
//            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").value == 'MM')
         {
            alert('Please enter the expiration month.');
            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").value == 'YYYY') 
        {
            alert('Please enter the expiration year.');
            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('Expiration date cannot be less than the current date.');
            document.getElementById(MasterpageID + "ddlMonth").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "ddlMonth").focus();
            return false;
        }
    }
    else
    {
        alert('Please enter a valid credit card number.');
        document.getElementById(MasterpageID + "txtCardNumber").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtCardNumber").focus();
        return false;
    }
}
    
function isValidCardNumber(strNum)
{
    var blnIsAcceptableCard = false;
    //var nCheck = 0;
    var nDigit = 0;
    //var bEven = false;
    var checksum = 0;
    var nDigitCheck = strNum.substring(0,6);
    
    //First level validation
    if(strNum.length < 13 || strNum.indexOf(' ') != -1)
    {
        return false;
    }
    
    //Second level validation
    //Visa                   4                 13, 16
    if(strNum.substring(0,1) == "4" && (strNum.length == 13 || strNum.length == 16))
    {   
        blnIsAcceptableCard = true;
    }
    //Master Card            51 to 55          16
    if(strNum.substring(0,2) >= "51" && strNum.substring(0,2) <= "55" && strNum.length == 16)
    {
        blnIsAcceptableCard = true;
    }
    //American Express       34, 37            15
    if((strNum.substring(0,2) == "34" || strNum.substring(0,2) == "37") && strNum.length == 15)
    {
        blnIsAcceptableCard = true;
    }
    //JCB number range = 3528000000000000-3589999999999999
    if(strNum.substring(0,4) >= "3528" && strNum.substring(0,4) <= "3589" && strNum.length == 16)
    {
        blnIsAcceptableCard = true;
    }
    
    //alert("Entered isValidCardNumber");
    if (blnIsAcceptableCard == false) 
    {
        return false;    
    } 

    //Third level validation
    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 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 (!isValidEmail(e)) 
    {
        alert('Please enter valid email address');
        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('Password must be at least 6 characters');
        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('Passwords does not match');
        document.getElementById(MasterpageID + "txtPasswordRepeat").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtPasswordRepeat").focus();
        return false;
    }
    return true;
}

//End Here


function fnValidateQuantity()
{
    document.getElementById(MasterpageID + "txtQuantity").style.background = '#efefef';
        if (trim(document.getElementById(MasterpageID + "txtQuantity").value).length == 0) {
        alert('Please enter the Quantity');
        document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtQuantity").focus();
        return false;
    }
    else if (1 > (trim(document.getElementById(MasterpageID + "txtQuantity").value)))
    {
        alert('Quantity cannot be Zero');
        document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtQuantity").focus();
        return false;
    }
    else if ((trim(document.getElementById(MasterpageID + "txtQuantity").value)) > 999)
    {
        alert('Quantity cannot be greater than 999');
        document.getElementById(MasterpageID + "txtQuantity").style.background = '#FFFFcc';
        document.getElementById(MasterpageID + "txtQuantity").focus();
        return false;
    }
     return true;
}
function ClearNewsletterFields()
{
document.getElementById(MasterpageID + "txtDate").value ="";
document.getElementById(MasterpageID + "txtEmail").value ="";
document.getElementById(MasterpageID + "txtDate").focus();
}

function ValidateNewsletterFields()
{
    // date 
    document.getElementById(MasterpageID + "txtDate").style.background = '#efefef';
    if(document.getElementById(MasterpageID + "txtDate").value != "")
    {
         if(!isDate(document.getElementById(MasterpageID + "txtDate").value))
         {
            document.getElementById(MasterpageID + "txtDate").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtDate").focus();
            return false;
         }
    }
    // email
    if(document.getElementById(MasterpageID + "txtEmail").value != "")
    {
        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 (!isValidEmail(e)) 
        {
            alert('Please enter valid email address');
            document.getElementById(MasterpageID + "txtEmail").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtEmail").focus();
            return false;
        }
     }
    return true;
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
function ajax_request(url) 
{
   AJAX = GetXmlHttpObject();           
    if (AJAX) {
        AJAX.open("GET", url, false);                
        AJAX.send(null);
        return AJAX.responseText;
    } else {
        alert('The browser you are using is not compatible. Please call (852) 3071 5085 to place your order.');
    }
}
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {            
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
    //Internet Explorer
        try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
function fnValidateCalendarControl()
{
	  if (document.getElementById(MasterpageID + "txtCalendar").value == '') {
			alert("Please select the Delivery Date.");
			document.getElementById(MasterpageID + "txtCalendar").focus();
			document.getElementById(MasterpageID + "txtCalendar").style.background = '#FFFFcc';
			return false;
	  }
    document.getElementById(MasterpageID + "txtCalendar").style.background = '#efefef';
    
    var selectedDate = document.getElementById(MasterpageID + "txtCalendar").value;
    var day = new Date();
    day.setDate(day.getDate() + 30);
    
    var dd=day.getDate();
    var mm=day.getMonth() + 1;
    var yyyy=day.getFullYear();
    
    if (mm.toString().length == 1)
        mm = "0" + mm;
    
    if (dd.toString().length == 1)
        dd = "0" + dd;
    
    var CalDate = dd + "/" + mm + "/" + yyyy;
    
       var str1  = CalDate; 
       var str2  = selectedDate;
       
       var dt1  = parseInt(str1.substring(0,2),10);
       var mon1 = parseInt(str1.substring(3,5),10); 
       var yr1  = parseInt(str1.substring(6,10),10); 
       
       var dt2   = parseInt(str2.substring(0,2),10); 
       var mon2  = parseInt(str2.substring(3,5),10); 
       var yr2   = parseInt(str2.substring(6,10),10); 
       var date1 = new Date(); 
       var date2 = new Date(); 
       date1.setFullYear(yr1,mon1-1,dt1)
       date2.setFullYear(yr2,mon2-1,dt2)
       if(date2 > date1)
        {
          alert("The selected delivery date should not be more than 30 days from current date.");
          document.getElementById(MasterpageID + "txtCalendar").style.background = '#FFFFcc';
          document.getElementById(MasterpageID + "txtCalendar").focus();      
          return false; 
        }
     return true;    
}
function isValidEmail(e)
{
      var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      if (!(filter.test(e))) 
      {
        return false;
      }
      return true;
}

// newsletter signup email validation
function fnEmailSignupValidation()
{
    document.getElementById("emailsignup").style.background = '#efefef';
    
    if(trim(document.getElementById("emailsignup").value).length == 0 )
    {    
        alert("Please enter the email address");
        document.getElementById("emailsignup").style.background = '#FFFFcc';
        document.getElementById("emailsignup").focus();
        return false;
    }

    document.getElementById("emailsignup").style.background = '#efefef';
    var e = document.getElementById("emailsignup").value;
    //var filter = /^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/;
    //var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!isValidEmail(e)) 
    {       
        alert("Please enter valid email address");        
        document.getElementById("emailsignup").style.background = '#FFFFcc';
        document.getElementById("emailsignup").focus();
        return false;
    }

    var EmailSignUp = ajax_request('processing.aspx?Action=EmailSignUp&EmailId=' + trim(document.getElementById("emailsignup").value));  

    if(EmailSignUp = true)
    {
        document.getElementById("emailsignup").style.visibility = "hidden";
         document.getElementById("email-submit").style.visibility = "hidden";
        document.getElementById("emailerror").innerHTML = "Thank you, you have been subscribed.";
    }
    return true;
}

function IsCardAllowed(strCardNumControl)
{
    var strCardNum = strCardNumControl.value;
    var strCCNumbers= getCookie("CCPrefixes");
    var CCNumbersSplit = new Array();
    CCNumbersSplit = strCCNumbers.split(",");
    var blnCardNumStartsWithCCNumList= false;
    if(getCookie("CCRestriction")=="1")
    {
        for (var i = 0; i < CCNumbersSplit.length; i++)
           {
                //if (strCardNum.substring(0,6) == CCNumbersSplit[i])
                if(strCardNum.indexOf(CCNumbersSplit[i],0)!=-1)    
               {
                  blnCardNumStartsWithCCNumList = true;
                  break;
               }  
           } 
     if(blnCardNumStartsWithCCNumList == true)
       {
          return true;
     }  
     else
     {
        alert(getCookie("CCErrorMsg"));
             strCardNumControl.select();
            return false;
     }    
    }
}
//function IsCardAllowed(strCardNumControl)
//{    
//    //Begin - Bug#2820 - Infosys(Siva)
//    var strCardNum = strCardNumControl.value;
//    var CCNumbersSplit = new Array(); 
//    var CCPromoSplit = new Array(); 
//    var blnCardNumStartsWithCCNumList= false;
//    var blnIsResponseCodeFound= false;
//    var strCCNumbers;
//    var ResponseCodesForCCRestriction;
//    
//    if (getCookie("CCPromo") == "8674002" || getCookie("CCPromo") == "8674003")
//    {
//        strCCNumbers = "377107,405803,419077,419078,442394,450936,496657,540034,541737,548803,548830,552083,552343,553398";
//        ResponseCodesForCCRestriction = "8674002,8674003";
//    }
//    else if(getCookie("CCPromo") == "8713002" || getCookie("CCPromo") == "8713004")
//    {
//        strCCNumbers = "476073,540804,541819,377106,453950";
//        ResponseCodesForCCRestriction = "8713002,8713004";
//    }    
//    CCNumbersSplit = strCCNumbers.split(",");
//    CCPromoSplit = ResponseCodesForCCRestriction.split(",");
//    //End - Bug#2820 - Infosys(Siva)
//    
//    for (var i = 0; i < CCPromoSplit.length; i++)
//    {
//        if (getCookie("CCPromo") == CCPromoSplit[i])
//        {
//            blnIsResponseCodeFound = true;
//            for (var j = 0; j < CCNumbersSplit.length; j++)
//            {
//                if (strCardNum.substring(0,6) == CCNumbersSplit[j])
//                {
//                    blnCardNumStartsWithCCNumList = true;
//                    break;
//                }
//            }
//        }
//     }
//     if(blnIsResponseCodeFound == false)
//     {
//        return true;
//     }
//     else
//     {
//        if(blnCardNumStartsWithCCNumList == true)
//        {
//            return true;
//        }
//        else
//        {
//            if (getCookie("CCPromo") == "8674002" || getCookie("CCPromo") == "8674003")
//            {
//                alert("Only Standard Chartered Credit Cards may be used for this offer.");
//                strCardNumControl.select();
//                return false;
//            }
//            else if(getCookie("CCPromo") == "8713002" || getCookie("CCPromo") == "8713004")
//            {
//                alert("Only DBS Credit Cards may be used for this offer.");
//                strCardNumControl.select();
//                return false;
//            }
//        }
//     }                  
//}

// 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 "";
}


$(document).bind('click', function(e) {
      var $clicked = $(e.target);
      if (! $clicked.parents().hasClass("site"))
      $("#target li.site").hide();
      $('#target li.selected').show();
    });

   
    $('#target li.site').not(':first').hide();
    $('#target li:first').show().addClass('selected');
    $('#target li:last').css('border','none');
    
    $("#target li.site").live('click', function() {
      $('#target li').removeClass('selected');
      $("#target li.site").hide();
      $(this).addClass('selected');
      $('#target li.selected').show();
    });
                        
    $("#target li.selected").live('click', function() {
      $("#target li.site").show();
      return false;
    });
    
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),10);
                    }
                    else
                    {
                        element.select();
                        return false;
                    }
                }                
                blnSelected = false;
            }
        //}                
    }
    if(SelectedNoOfCase == 0)
    {
        alert("Please select an item");
        return false;
    }
    if((SelectedNoOfCase > maxNoOfCase))
    {
        alert("Please understand that because of the really good offer we can offer only a limited number of items per household. You can select maximum of [X] item(s).".replace("[X]", maxNoOfCase));
        return false;
    }
    if (SelectedNoOfQty > maxNoOfQty) {
        alert("The total quantity should be maximum of [X]. Thank you for your understanding.".replace("[X]", maxNoOfQty));
        return false;
    }
    EnableQtyTextBox(strElementType);
    document.forms["form"].submit();
}
function EnableQtyTextBox(strElementType)
{
    var SelectedACase;
    SelectedACase = false;
    var elementArray = document.forms["form"].elements;
     var strItemID;
    //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)
        {
             strItemID = element.value;
            if (element.checked == true)
            {
                SelectedACase = true;                           
            }
            else
            {
                SelectedACase = false;
            }
        }
//        if(element.type == "text" && SelectedACase == true && (strItemID== "M0075308" || strItemID== "A0011308"))
//        {        
//            SelectedACase = false;                                  
//            element.value = 1;   
//            element.disabled = false;              
//            element.readOnly = true; 
//        }  
//        else 
        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("Please enter a valid numeric quantity");
	    id.select();
	    return false;
	}
	if (parseInt(id.value) == 0) {
		alert("Please enter a quantity greater than zero");
		id.select();
		return false;
	}
	return true;
}

//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 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 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('Please enter a quantity greater than zero and in multiples of six.');
//		$("#cart-error").replaceWith("<div class='error''>Please enter a quantity greater than zero and in multiples of six.</div>");
//		id.focus();
//	}
//}

//Validation on New User Registration
//function fnValidateUserRegistration()
//{
//    document.getElementById(MasterpageID +"txtFirstName").style.background = '#efefef';
//        if (trim(document.getElementById(MasterpageID + "txtFirstName").value).length == 0) {
//        alert('Please enter your First name');
//        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('Please enter your Last name');
//        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("Please enter the E-Mail address");
//        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 (!isValidEmail(e)) 
//    {
//        alert('Please enter valid email address');
//        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('Email addresses do not match');
//            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('Password must be at least 6 characters');
//            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('Passwords do not match');
//            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('Please enter your Address');
//            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('Please enter your Zipcode');
//            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("Please enter valid Zip code");
//                    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("Please enter valid Zip code");
//                        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 == "Please Click here to select suburb") 
//                        || (document.getElementById("city").value == "Please enter your post code"))
//                        {
//                            alert("Please select a valid suburb.");
//                            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('Please enter our Phone Number');
//            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('Invalid Phone number');
//		        document.getElementById(MasterpageID + "txtPhone").style.background = '#FFFFcc';
//		        document.getElementById(MasterpageID + "txtPhone").focus();
//		        return false;
//      		}
//         }
//         
//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('State is not available for the given zipcode. Please enter any other zipcode.');
//        document.getElementById(MasterpageID + "spnCity").innerHTML = '<select name=city id=city><option>Please enter your post code</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 = "Sorry, we will not be able to ship to " + curText;
//        alert(message);
//        document.getElementById(MasterpageID + "spnCity").innerHTML = '<select name=city id=city><option>Please enter your post code</option></select>';
//        document.getElementById(MasterpageID + "txtZipCode").style.background = '#FFFFcc';
//        document.getElementById(MasterpageID + "txtZipCode").focus();
//        return false;
//    }
//        return true;    
//}

//Function to Validate EmailID while Sign-up
//function fnValidateEmail()
//{
//    document.getElementById(MasterpageID + "txtEmailId").style.background = '#efefef';
//    if(trim(document.getElementById(MasterpageID + "txtEmailId").value).length == 0 )
//    {
//        alert("Please enter the E-Mail address");
//        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 (!isValidEmail(e)) 
//    {
//        alert('Please enter a valid email address');
//        document.getElementById(MasterpageID + "txtEmailId").style.background = '#FFFFcc';
//        document.getElementById(MasterpageID + "txtEmailId").focus();
//        return false;
//    }
//    return true;
//}


//function copyFields() 
//{
//if(document.getElementById("SameAsBillingAddress")!=null)
//{
//if (document.getElementById("SameAsBillingAddress").checked == true) 
//{
//        document.getElementById("shipping_title").value = document.getElementById("billing_title").value;
//        document.getElementById("shipping_first_name").value = document.getElementById("first_name").value;
//        document.getElementById("shipping_last_name").value = document.getElementById("last_name").value;
//        document.getElementById("SCompanyname").value = document.getElementById("BCompanyname").value;
//        document.getElementById("shipping_address").value = document.getElementById("address").value;
////        document.getElementById("shipping_address2").value = document.getElementById("address2").value;
//        document.getElementById("shipping_phone").value = document.getElementById("phone").value;
//        
//        if ((trim(document.getElementById("PostCode").value).length > 0) && (trim(document.getElementById("SelspnCity").value).length > 0))
//        {
//            document.getElementById("shipping_PostCode").value = document.getElementById("PostCode").value;
//            ShippingAddress_ZipChange();
//            document.getElementById("SelspnShippingCity").value = document.getElementById("SelspnCity").value
//        }
//}
//}
//}											  

//fn to validate the details in checkout page
//function validate() 
//{
//  //Validate the Billing Informations
//  if(!(ValidateBillingInformations()))
//     {
//        return false;
//     }
//     
//      //Validate the credit card Informations
//  if(!(ValidateCreditCardInfo()))
//     {
//        return false;
//     }
//  
//  //Validate the Shipping Informations
//  if(!(ValidateShippingInformations()))
//     {
//        return false;
//     }
//     
//  //Validate the Delivery Date
//  if(!(fnValidateCalendarControl()))
//     {
//        return false;
//     }
//   
//  if (!(document.getElementById(MasterpageID + "CheckAge").checked))
//  { 
//    alert('Please certify that you are 18 years or older.');
//    document.getElementById(MasterpageID + "CheckAge").style.background = '#FFFFcc';
//    document.getElementById(MasterpageID + "CheckAge").focus(); 
//	
//    return false; 
//  }
//return true; 
//}

//Validate the Billing Informations
//function ValidateBillingInformations()
//{
//    document.getElementById("first_name").style.background = '#efefef';
//  if (trim(document.getElementById("first_name").value).length == 0) 
//  { 
//    alert('Please enter your first name');
//    document.getElementById("first_name").style.background = '#FFFFcc';
//    document.getElementById("first_name").focus(); 
//    return false; 
//  } 
//  
//  document.getElementById("last_name").style.background = '#efefef';
//  if (trim(document.getElementById("last_name").value).length == 0) 
//  { 
//    alert('Please enter your last name');
//    document.getElementById("last_name").style.background = '#FFFFcc';
//    document.getElementById("last_name").focus(); 
//    return false; 
//  }
//  
//  document.getElementById("address").style.background = '#efefef';
//  if (trim(document.getElementById("address").value).length == 0) 
//  { 
//    alert('Please enter your billing address');
//    document.getElementById("address").style.background = '#FFFFcc';
//    document.getElementById("address").focus(); 
//    return false; 
//  }
//  
//  document.getElementById("PostCode").style.background = '#efefef';            
//    if (trim(document.getElementById("PostCode").value).length == 0) 
//    {
//        alert('Please enter your post code');
//        document.getElementById("PostCode").style.background = '#FFFFcc';
//        document.getElementById("PostCode").focus();
//        return false;
//    }                      
//    
//    //Validate the Billing Zipcode and Suburb
//  if(!(ValdateSuburb("spnCity", "SelspnCity", "PostCode", "city1")))
//     {
//        return false;
//     }
//  
//  document.getElementById("txtEmailID").style.background = '#efefef';
//  if (trim(document.getElementById("txtEmailID").value).length == 0) 
//  { 
//    alert('Please enter your email address');
//    document.getElementById("txtEmailID").style.background = '#FFFFcc';
//    document.getElementById("txtEmailID").focus(); 
//    return false; 
//  }
//  
//  document.getElementById("txtEmailID").style.background = '#efefef';
//  var e = document.getElementById("txtEmailID").value;
//  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
//  if (!(filter.test(e))) 
//  {
//    alert('Invalid email address');
//    document.getElementById("txtEmailID").style.background = '#FFFFcc';
//    document.getElementById("txtEmailID").focus();
//    return false;
//  }
//  
//  document.getElementById("txtConfirmEmailID").style.background = '#efefef';
//  if (trim(document.getElementById("txtEmailID").value) != trim(document.getElementById("txtConfirmEmailID").value)) 
//  {
//    alert('Email addresses do not match');
//    document.getElementById("txtConfirmEmailID").style.background = '#FFFFcc';
//    document.getElementById("txtConfirmEmailID").focus();
//    return false;
//  }

//    //Validate the Billing Phone number
//     if(!(ValidatePhoneNumber("phone")))
//     {
//        return false;
//     }
//     return true;
//}

//Validate Shipping Informations
//function ValidateShippingInformations()
//{
//    document.getElementById("shipping_first_name").style.background = '#efefef';
//  if (trim(document.getElementById("shipping_first_name").value).length == 0) 
//  { 
//    alert('Please enter your first name.');
//    document.getElementById("shipping_first_name").style.background = '#FFFFcc';
//    document.getElementById("shipping_first_name").focus(); 
//    return false; 
//  } 
//  
//  document.getElementById("shipping_last_name").style.background = '#efefef';
//  if (trim(document.getElementById("shipping_last_name").value).length == 0) 
//  { 
//    alert('Please enter your last name.');
//    document.getElementById("shipping_last_name").style.background = '#FFFFcc';
//    document.getElementById("shipping_last_name").focus(); 
//    return false; 
//  } 
//  
//  document.getElementById("shipping_address").style.background = '#efefef';
//  if (trim(document.getElementById("shipping_address").value).length == 0) 
//  { 
//    alert('Please enter your shipping address.');
//    document.getElementById("shipping_address").style.background = '#FFFFcc';
//    document.getElementById("shipping_address").focus(); 
//    return false; 
//  }
//  
//    //Validate the Shipping Zipcode and Suburb
//  if(!(ValdateSuburb("spnShippingCity", "SelspnShippingCity", "shipping_PostCode", "shipping_city1")))
//     {
//        return false;
//     }
//   
//  //Validate the Shipping Phone number
//  if(!(ValidatePhoneNumber("shipping_phone")))
//     {
//        return false;
//     }
//   return true;  
//}

//function to validate the phone number
//function ValidatePhoneNumber(Phone)
//{
// document.getElementById(Phone).style.background = '#efefef';
//    if (trim(document.getElementById(Phone).value).length == 0) 
//    {
//        alert('Please enter your phone number');
//        document.getElementById(Phone).style.background = '#FFFFcc';
//        document.getElementById(Phone).focus();
//        return false;
//    }
//    else
//    {
//        var e = document.getElementById(Phone).value;
//        var numericexp = /^[0-9]+$/;
//        if (!(e.match(numericexp)) || (trim(document.getElementById(Phone).value).length < 8))
//        {
//            alert('Please specify a valid phone number - no spaces');
//            document.getElementById(Phone).style.background = '#FFFFcc';
//            document.getElementById(Phone).focus();
//            return false;
//        }
//    }
//    return true; 
//}

//Validate Credit card details
//function ValidateCreditCardInfo()
//{
//    var var1 = new Date();
//    var CurrMonth = var1.getMonth();
//    var CurrYear = var1.getFullYear();
//    
//    if (trim(document.getElementById("ccnumEnter").value).length == 0) 
//  {
//    document.getElementById("ccnumEnter").focus();
//    alert('Please enter your credit card number.');
//    return false;
//  }
//  else
//  {
//    var ccnum = document.getElementById("ccnumEnter").value;
//    ccnum = ccnum.replace(/ /g, '').replace(/-/g, '');
//    document.getElementById("ccnumEnter").style.background = '#efefef';
//    
//    var nDigitCheck = ccnum.substring(0,4);

//    if (((3000 <= nDigitCheck) && (3059 >= nDigitCheck)) ||
//        ((3600 <= nDigitCheck) && (3699 >= nDigitCheck)) ||
//        ((3800 <= nDigitCheck) && (3889 >= nDigitCheck)) ||
//        ((6011 <= nDigitCheck) && (6011 >= nDigitCheck)) ||
//        ((3890 <= nDigitCheck) && (3899 >= nDigitCheck))) 
//    {
//        alert("Sorry, we don't accept Diners, Discover and Carte Blanche cards.");
//        document.getElementById("ccnumEnter").style.background = '#FFFFcc';
//        document.getElementById("ccnumEnter").focus();
//        return false;
//    } 
//    
//    if (!isValidCardNumber(ccnum)) 
//        {
//            alert('Please enter a valid credit card number.');
//            document.getElementById("ccnumEnter").style.background = '#FFFFcc';
//            document.getElementById("ccnumEnter").focus();
//            return false;
//        }
//    }
//  
//   if(document.getElementById("ccmo").value == 'MM') 
//   {
//	    alert('Please select credit card expiration month.');
//	    document.getElementById("ccmo").focus();
//	    return false;
//    } 
//    if(document.getElementById("ccyr").value == 'YYYY') 
//    {
//        alert('Please select credit card expiration year');
//	    document.getElementById("ccyr").focus();
//	    return false;
//    }
//	
//    if ((document.getElementById("ccmo").value < CurrMonth+1)&&( document.getElementById("ccyr").value <= CurrYear)) 
//    {
//        alert('Expiration date cannot be less than the current date');
//        document.getElementById("ccmo").style.background = '#FFFFcc';
//        document.getElementById("ccmo").focus();
//        return false;
//    }
//    
//    return true;
//}

         

//function new_window()
//{
//    newwindow=window.open("privacypolicy.aspx",'xczzxc','top=50,left=250,width=700,height=650,scrollbars=yes');
//    newwindow.focus();
//}
//function launchpopup(popup)
//{
//	var url = popup;

//	window.open(url,'popup','height=460,width=860,scrollbars=yes,resizable=yes,left = 50,top = 20');
//}

//Validation for contact us page
//function fnValidateContactUsInfo()
//{
//  document.getElementById(MasterpageID + "txtFirstName").style.background = '#efefef';
//  if (trim(document.getElementById(MasterpageID + "txtFirstName").value).length == 0) 
//  { 
//    alert('Please enter your First Name.');
//    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('Please enter your Last Name.');
//    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('Please enter your Email Address');
//    document.getElementById(MasterpageID + "txtEmailID").style.background = '#FFFFcc';
//    document.getElementById(MasterpageID + "txtEmailID").focus(); 
//    return false; 
//  }
//  else
//  {
//      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('Invalid Email Address');
//        document.getElementById(MasterpageID + "txtEmailID").style.background = '#FFFFcc';
//        document.getElementById(MasterpageID + "txtEmailID").focus();
//        return false;
//      }
//  }
//  //Validate the Phone number
//  if(!(ValidatePhoneNumber(MasterpageID + "txtPhone")))
//     {
//        return false;
//     }
// document.getElementById(MasterpageID + "ddlRegion").style.background = '#efefef';
//  if (document.getElementById(MasterpageID + "ddlRegion").value == 'Select') 
//  { 
//	alert('Please select your Postal Region');
//	document.getElementById(MasterpageID + "ddlRegion").focus(); 
//  	return false; 
//  }
//   document.getElementById(MasterpageID + "ddlDistrict").style.background = '#efefef';
//  if ((document.getElementById(MasterpageID + "ddlDistrict").value == 'Please Select Your Postal District') ||
//        (document.getElementById(MasterpageID + "ddlDistrict").value == 'Please Select Your Postal Region'))
//  { 
//	alert('Please select your Postal District.');
//	document.getElementById(MasterpageID + "ddlDistrict").focus(); 
//  	return false; 
//  }                 
//  
//  document.getElementById(MasterpageID + "txtMessage").style.background = '#efefef';
//  if (trim(document.getElementById(MasterpageID + "txtMessage").value).length == 0) 
//  { 
//    alert('Please enter your Message');
//    document.getElementById(MasterpageID + "txtMessage").style.background = '#FFFFcc';
//    document.getElementById(MasterpageID + "txtMessage").focus(); 
//    return false; 
//  }
//return true; 
//}





//Function added to validate the WineCellar page ratio buttons in GridView
//function fnValidateItemCount()
//{
//    var x1cnt, x2cnt;
//    x1cnt = 0;
//    x2cnt = 0;
//    //alert(list.rows.length);
//    
//    var elementArray = document.forms["offerd"].elements;
//    //loop starts from 1. rows[0] points to the header.
//    for (i=1; i<elementArray.length; i++)
//    {
//        var element =  elementArray[i];
//        //alert(element.id.indexOf("rdoX1"));
//        if (element.id.indexOf("chkX1") != -1)
//        {
//            if( element.type == "checkbox" && element.checked == true)
//            {
//                x1cnt += 1;
//                if (x1cnt > 2)
//                {
//                    alert("You can select maximum of two cases");
////                    for (i=1; i<elementArray.length; i++)
////                    {
////                        var element =  elementArray[i];
////                        element.checked = false;
////                    }
//                    return false;
//                }
//            }
//        }
//    }
//    
//    for (i=1; i<elementArray.length; i++)
//    {
//        var element =  elementArray[i];
//        if (element.name.indexOf("chkX2") != -1)
//        {
//            if( element.type == "checkbox" && element.checked == true)
//            {
//                x2cnt += 1;
//                
//                if (x2cnt > 1)
//                {
//                    alert("You can select maximum of two cases");
//                    return false;
//                }
//            }
//        }
//    } 
//    
//    if (x1cnt == 0 && x2cnt == 0)
//    {
//        alert("Please select the case");
//        return false;
//    }          
//    
//    if (x1cnt > 0 && x2cnt == 1) 
//    {
//        alert("You can select maximum of two cases");
////        for (i=1; i<elementArray.length; i++)
////        {
////            //Clear the radio buttons selection in the two cells
////            var element =  elementArray[i];
////            element.checked = false;
////        }   
//        return false;
//    }    
//}
