
var FxFxMasterpageID = "ctl00_hldrContent_";

// 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));
	
}

// 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("emailsignupDIV").style.visibility = "hidden";
        document.getElementById("email-error").innerHTML = "Thank you, you have been subscribed.";
    }
    return true;
}

//Function to Validate EmailID while Sign-up
function fnValidateEmail()
{
    document.getElementById(FxMasterpageID + "txtEmailId").style.background = '#efefef';
    if(trim(document.getElementById(FxMasterpageID + "txtEmailId").value).length == 0 )
    {
        alert("Please enter the E-Mail address");
        document.getElementById(FxMasterpageID + "txtEmailId").style.background = '#FFFFcc';
        document.getElementById(FxMasterpageID + "txtEmailId").focus();
        return false;
    }

    document.getElementById(FxMasterpageID + "txtEmailId").style.background = '#efefef';
    var e = document.getElementById(FxMasterpageID + "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(FxMasterpageID + "txtEmailId").style.background = '#FFFFcc';
        document.getElementById(FxMasterpageID + "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
        }
}
}
}											  

function isValidCardNumber (strNum) 
{
    var nDigit = 0;
    var checksum = 0;
    
    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);
}

//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;
     }
   
  if (!(document.getElementById("CheckAge").checked))
  { 
    alert('Please certify that you are 18 years or older.');
    document.getElementById("CheckAge").style.background = '#FFFFcc';
    document.getElementById("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)) || ((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 Suburbs and zipcode
function ValdateSuburb(spnCity, City, PostCode, SelCity)
{
    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;
    }    
     if(document.getElementById(City) == null)
    {
        if ((document.getElementById(spnCity) == null) || (document.getElementById(SelCity) != null))
        {
            alert("Please enter valid post code");
            document.getElementById(PostCode).style.background = '#FFFFcc';
            document.getElementById(PostCode).focus();
            return false;
        }               
    }
    else
    { 
        if(document.getElementById(City).options != null)
        {  
          
           if(document.getElementById(City).options.length == 1)
            {                
                alert("Please enter valid post code");
                document.getElementById(PostCode).style.background = '#FFFFcc';
                document.getElementById(PostCode).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;           
                }
            }
        }
    }
    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 a 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,6);

    if (((300000 <= nDigitCheck) && (309999 >= nDigitCheck)) || ((601100 <= nDigitCheck) && (601199 >= nDigitCheck))) 
    {
        alert("Sorry, we don't accept Diners and Discover 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 BillingAddress_ZipChange() 
{
    var PostCode = "PostCode";
    var City = "spnCity";
    ZipChange(PostCode, City);
}
function BillingAddressForm_ZipChange(ctrlPostCode) 
{    
    //var PostCode = "ctl00$cphMaster$PostCode";
    var City = "ctl00_cphMaster_spnCity";
    ZipChange(ctrlPostCode, City);
}


function ShippingAddress_ZipChange(PostCode) 
{
   // var PostCode = "shipping_PostCode";
    var City = "spnShippingCity";
    ZipChange(PostCode, City);
}

function ZipChange(PostCode, City) 
{   
    document.getElementById(City).innerHTML = '<select name=Sel'+ City +' id=Sel'+ City +'><option>Please enter your post code</option></select>';
    var SuburbSelection = ajax_request('processing.aspx?Action=GetSuburbs&zip=' + trim(PostCode.value) + '&SelectId='+ City);            
    if (SuburbSelection == 'Not a valid Post code')
     {
        alert(SuburbSelection);
        PostCode.style.background = '#FFFFcc';
        PostCode.value = "";   
        PostCode.focus();                
        return false;
    } 
    else 
    {
       // alert(SuburbSelection);
        document.getElementById(City).innerHTML = SuburbSelection;
//        if (SuburbSelection.indexOf('select') == -1) 
//        {
//            //document.getElementById(Phone).focus();
//        } 
//        else {
//            frmRegister.Suburb.focus();
//        }
    }
    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 1-877-975-9463 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 added to validate the WineCellar page ratio buttons in GridView
function fnValidateWineCellar()
{
    var x1cnt, x2cnt;
    x1cnt = 0;
    x2cnt = 0;
    //alert(list.rows.length);
    
    var elementArray = document.forms["frmWineOffer"].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;
    }    
}

//Function added to validate the WineCellar Continuity page ratio buttons in GridView
function fnValidateWineCellarContinuity()
{
    var cnt;
    cnt = 0;
    
    var elementArray = document.forms["frmWineOffer"].elements;
    for (i=1; i<elementArray.length; i++)
    {
        var element =  elementArray[i];
        if (element.name.indexOf("chkX2") != -1)
        {
            if( element.type == "checkbox" && element.checked == true)
            {
                cnt += 1;
                if (cnt > 1)
                {
                    alert("You can select maximum of one case");
                    return false;
                }
            }
        }
    } 
    
    if (cnt == 0)
    {
        alert("Please select the case");
        return false;
    }    
}


//Added by Infosys(Ram) on 27JAN2010 for BUG ID - 1103
function fnValidateSelectedItems()
{
    var cnt;
    cnt = 0;
    
    var elementArray = document.forms["frmWineOffer"].elements;
    
    for (i=1; i<elementArray.length; i++)
    {
        var element =  elementArray[i];
        if (element.name.indexOf("chkX2") != -1)
        {
            if( element.type == "checkbox" && element.checked == true)
            {
                cnt += 1;
                if (cnt > 1)
                {
                    alert("You can select maximum of one case");
                    return false;
                }
            }
        }
    } 
    
    
    if (cnt == 0)
    {
        alert("Please select the case");
        return false;
    }  
    else if (document.getElementById("chkbxDisclaimer").checked == false)  
    {
            alert("Please tick the disclaimer box");
            document.getElementById("chkbxDisclaimer").style.background = '#FFFFcc';
            document.getElementById("chkbxDisclaimer").focus();
            return false;
    }
}
//End of Modification by Infosys(Ram) on 27JAN2010 for BUG ID - 1103

function new_window()
{
    newwindow=window.open("privacypolicy.aspx",'xczzxc','top=50,left=250,width=700,height=650,scrollbars=yes');
    newwindow.focus();
}
function new_domain()
{
    newwindow=window.open("domain.aspx",'xczzxc','top=50,left=250,width=700,height=650,scrollbars=yes');
    newwindow.focus();
}
function new_Popup(strpage)
{
    newwindow=window.open(strpage,'xczzxc','top=50,left=250,width=700,height=650,scrollbars=yes');
    newwindow.focus();
}

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;
}
function launchpopup(popup)
{
	var url = popup;

	window.open(url,'popup','height=460,width=860,scrollbars=yes,resizable=yes,left = 50,top = 20');
}

// START - INFOSYS (Gowri) - 17-DEC-09 - Bug # 1000
// validate the Prize Draw fields
function validatePrizeDrawInfo()
{    
      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; 
  }
  
    // date 
    document.getElementById("birth_date").style.background = '#efefef';
     if (trim(document.getElementById("birth_date").value).length == 0) 
    {
        alert('Please enter your date of birth');
        document.getElementById("birth_date").style.background = '#FFFFcc';
        document.getElementById("birth_date").focus();
        return false;    
    }
    else
    {
         if(!isDate(document.getElementById("birth_date").value))
         {            
            document.getElementById("birth_date").style.background = '#FFFFcc';
            document.getElementById("birth_date").focus();
            return false;
         }
         // check if the age is greater than 18 with DOB
         today = new Date();
         var dob = new Date(trim(document.getElementById("birth_date").value));
         if(dob > today)
         {
            alert("Please enter valid date of birth");
            document.getElementById("birth_date").style.background = '#FFFFcc';
            document.getElementById("birth_date").focus();
            return false;
         }
         else
         {         
            var diff_date =  today - dob;
            var one_year=31536000000;            
            if(Math.floor(diff_date/one_year) < 18)
            {   
                alert("You must be 18 years or older");
                document.getElementById("birth_date").style.background = '#FFFFcc';
                document.getElementById("birth_date").focus();
                return false;
            }   
        }
    }   

  
  document.getElementById("PostCode").style.background = '#efefef';  
     if (trim(document.getElementById("PostCode").value).length > 0) 
    {
        var e = document.getElementById("PostCode").value;
        var numericexp = /^[0-9]+$/;
        if (!(e.match(numericexp)) || ((document.getElementById("PostCode").value).length < 4))
        {
            alert('Please enter valid post code');
            document.getElementById("PostCode").style.background = '#FFFFcc';
            document.getElementById("PostCode").focus();
            return false;
        } 
        //Validate the 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;
  }

    
    if (trim(document.getElementById("phone").value).length > 0) 
    {
        var e = document.getElementById("phone").value;
        var numericexp = /^[0-9]+$/;
        if (!(e.match(numericexp)) || ((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;
        }
    }
     
      if (!(document.getElementById("CheckAge").checked))
      { 
        alert('Please certify that you are 18 years or older.');
        document.getElementById("CheckAge").style.background = '#FFFFcc';
        document.getElementById("CheckAge").focus(); 
    	
        return false; 
      }
     return true;
     
}
function copyPrizeDrawFields() 
{
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("shipping_address").value = document.getElementById("address").value;
        document.getElementById("shipping_phone").value = document.getElementById("phone").value;
        
        var SelspnCity = document.getElementById("SelspnCity");
        
        if ((trim(document.getElementById("PostCode").value).length > 0) && 
        (SelspnCity != null) &&
        (trim(document.getElementById("SelspnCity").value).length > 0))
        {
            document.getElementById("shipping_PostCode").value = document.getElementById("PostCode").value;
            ShippingAddress_ZipChange("shipping_PostCode");
            document.getElementById("SelspnShippingCity").value = document.getElementById("SelspnCity").value
        }
}
}
}	
function PrizeDrawAddress_ZipChange() 
{
    var PostCode = "PostCode";
    var City = "spnCity";
    ZipChangeinPrizeDraw(PostCode, City);
}
function ZipChangeinPrizeDraw(PostCode, City) 
{   
    document.getElementById(City).innerHTML = '<select name=Sel'+ City +' id=Sel'+ City +'><option>Please enter your post code</option></select>';
    var SuburbSelection = ajax_request('processing.aspx?Action=GetSuburbs&zip=' + trim(document.getElementById(PostCode).value) + '&SelectId='+ City);            
    if (SuburbSelection == 'Not a valid Post code')
     {
        alert(SuburbSelection);
         document.getElementById(PostCode).style.background = '#FFFFcc';
        document.getElementById(PostCode).value = "";   
        document.getElementById(PostCode).focus();                      
        return false;
    } 
    else 
    {       
        document.getElementById(City).innerHTML = SuburbSelection;
    }
    return true;
}

/***************--- Script for Date validation Starts ---***********/
// 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
}
/***************--- Script for Date validation Starts ---***********/
// END - INFOSYS (Gowri) - 17-DEC-09 - Bug # 1000

/***************--- Script to validate mutliSelection ---***********/
// START - INFOSYS (RAM) - 08-JUNE-10 - Bug # 1310
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.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("Please select a case");
        return false;
    }
    if((SelectedNoOfCase > maxNoOfCase))
    {
        alert("Please understand that because of the really good offer, we can offer only [X] items per household.".replace("[X]", maxNoOfCase));
        return false;
    }
    if (SelectedNoOfQty > maxNoOfQty) {
        alert("The maximum number of quantity you can order per household is [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;
    //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("Please enter 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 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))
         {
            //alert('Please enter a valid date');
            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 a valid email address');
            document.getElementById(MasterpageID + "txtEmail").style.background = '#FFFFcc';
            document.getElementById(MasterpageID + "txtEmail").focus();
            return false;
        }
     }
    return true;
}
// END - INFOSYS (RAM) - 08-JUNE-10 - Bug # 1310