﻿$(document).ready(function() {
   // Use the each() method to gain access to each of the elements attributes
    $('#content img').each(function()
    {
      $(this).qtip(
      {
         content: '<div class="continuityToolTipHeader">Save Time and Money!</div><div class="continuityToolTip">Receive your refill at a designated frequency - <strong>Automatically</strong> and receive <strong>$2.00 shipping</strong>  on all Renew 2 You orders after your initial order</div>', 
         position: {
              corner: {
                 target: 'rightMiddle',
                 tooltip: 'leftMiddle'
              }
           },
         hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
         style: { 
            width: 250,
            padding: 10,
            background: '#fff',
            color: 'black',
            border: {
                width: 4,
                radius: 3,
                color: '#7B7462'
            },
            tip: 'leftMiddle',
            name: 'dark' // Inherit the rest of the attributes from the preset dark style
         }
      });
    });
    
    /// Created by:     Justin C Miller
    /// Created on:     2010-02-24
    /// Description:    Creates jquery popup window for Processing Fee 'whats this' on the Order Totals control
    ///  
    /// Updates:
    ///     Modified by:    
    ///     Modified on:    
    ///     Description:    
    $('#processingFeeWhatsThisDiv a').each(function()
    {
      $(this).qtip(
      {
         content: '<div class="processingFeeWhatsThisToolTip">' + $('<div/>').html($("#ProcessingFeeWhatsThisPopupTextHiddenValue").val()).text() + ' <a href="' + $("#ProcessingFeeWhatsThisPopupTextMoreInfoLinkHiddenValue").val() + '">' + $("#ProcessingFeeWhatsThisPopupTextMoreInfoLinkTextHiddenValue").val() + '</a></div>', 
         position: {
              corner: {
                 target: 'rightMiddle',
                 tooltip: 'leftMiddle'
              }
           },
         hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
         style: { 
            width: 250,
            padding: 10,
            background: '#fff',
            color: 'black',
            border: {
                width: 4,
                radius: 3,
                color: '#7B7462'
            },
            tip: 'leftMiddle',
            name: 'dark' // Inherit the rest of the attributes from the preset dark style
         }
      });
    });
    
    /// Created by:     Justin C Miller
    /// Created on:     2010-02-25
    /// Description:    Creates jquery popup window for Shipping Total View Details on the Order Totals control
    ///  
    /// Updates:
    ///     Modified by:    
    ///     Modified on:    
    ///     Description:    
    $('#shippingTotalViewDetailsDiv a').each(function()
    {
      $(this).qtip(
      {
         content: '<div class="shippingTotalViewDetailsToolTip">' + $('<div/>').html($("#shippingTotalViewDetailsPopupTextHiddenValue").val()).text() + ' <a href="' + $("#shippingTotalViewDetailsPopupTextMoreInfoLinkHiddenValue").val() + '">' + $("#shippingTotalViewDetailsPopupTextMoreInfoLinkTextHiddenValue").val() + '</a></div>', 
         position: {
              corner: {
                 target: 'rightMiddle',
                 tooltip: 'leftMiddle'
              }
           },
         hide: {
            fixed: true // Make it fixed so it can be hovered over
         },
         style: { 
            width: 250,
            padding: 10,
            background: '#fff',
            color: 'black',
            border: {
                width: 4,
                radius: 3,
                color: '#7B7462'
            },
            tip: 'leftMiddle',
            name: 'dark' // Inherit the rest of the attributes from the preset dark style
         }
      });
    });
   
    $(".RegistrationContainer").hide();
    
    $(".ShowFormButton").click(function() {
        $(".LoginNewUserText").hide();
        $(".RegistrationContainer").show();
        $(".Login").css('height','550px');
        return false;
    });
    
	$(".RegisterButton").click(function() {
	    var isValid;
	    var errorList;
	    errorList = "<ul class='ErrorMessageLabel'>";
	    isValid = true;
	    
	    if($(".RegisterEmailTextBox").val().length == 0){
	        $(".RegisterEmailTextBox").addClass("FormTextBoxError");
	        $(".RegisterEmailLabel").addClass("FormLabelError");
	        errorList += "<li>Please enter an email address.</li>";
	        isValid = false;
	    }
	    if($(".RegisterEmailTextBox").val() != $(".RegisterConfirmEmailTextBox").val()){
	        $(".RegisterConfirmEmailTextBox").addClass("FormTextBoxError");
	        $(".RegisterConfirmEmailLabel").addClass("FormLabelError");
	        $(".RegisterEmailTextBox").addClass("FormTextBoxError");
	        $(".RegisterEmailLabel").addClass("FormLabelError");
	        errorList += "<li>Email Address and Confirm Email Address do no match.</li>";
	        isValid = false;
	    }
	    if($(".RegisterPasswordTextBox").val().length == 0){
	        $(".RegisterPasswordTextBox").addClass("FormTextBoxError");
	        $(".RegisterPasswordLabel").addClass("FormLabelError");
	        errorList += "<li>Please enter your password.</li>";
	        isValid = false;
	    }
	    if($(".RegisterPasswordTextBox").val() != $(".RegisterConfirmPasswordTextBox").val()){
	        $(".RegisterConfirmPasswordTextBox").addClass("FormTextBoxError");
	        $(".RegisterConfirmPasswordLabel").addClass("FormLabelError");
	        $(".RegisterPasswordTextBox").addClass("FormTextBoxError");
	        $(".RegisterPasswordLabel").addClass("FormLabelError");
	        errorList += "<li>Password and Confirm Password do not match.</li>";
	        isValid = false;
	    }
	    if($(".RegisterQuestionsDropdown").val() == "-1") {
	        $(".RegisterQuestionsDropdown").addClass("FormSelectBoxError");
	        errorList += "<li>Please select a password reset question.</li>";
	        isValid = false;
	    }
	    if($(".RegisterPasswordAnswer").val().length == 0){
	        $(".RegisterAnswerLabel").addClass("FormLabelError");
	        errorList += "<li>Please enter a password reset answer</li>";
	        isValid = false;
	    }
        if(!isValid)
        {
            errorList += "</ul>";
            $(".RegistrationErrors").html(errorList);
            $(".Login").css('height','650px');
		    return false;
		}
	});
	
	 $(".MultShipToLinkButton").click(function() {
        //enableDisableMultShipToButton(false);
	    isValidBA = true;
	    isValidSH = true;
	        
	    /* we need to make sure we remove any error classes that my exist first, otherwise, they'll never be removed*/	
        removeErrorClasses();
	    
	    isValidBA = validateBillingAddress();
	    
		if(!isValidBA)
		{
		    $(".MultShipToLinkButton:disabled").removeAttr('disabled');
		    scroll(0,0);
		    return false;
		}
		
	});
	
	 $(".PaymentReviewButton").click(function() {
	    isValidBA = true;
	    isValidSH = true;
	        
	    /* we need to make sure we remove any error classes that my exist first, otherwise, they'll never be removed*/	
        removeErrorClasses();
	    
	    isValidBA = validateBillingAddress();
	    
	    // validate the shipping address if we need to
	    // if they are not shipping to their billing address, and they have not select an address from the radio button group, then we need to 
	    // validate the shipping form.
	    if(!$('.SHAlsoShippingAddressCheckBox').hasClass("SHAlsoShippingAddressCheckBoxChecked")){ 
	        if($(".ShippingAddressesRadioButtons input:checked").val() == 'NewAddress' || $(".ShippingAddressesRadioButtons input").val() == undefined){
                isValidSH = validateShippingAddress();
            }
	    }
		if(!isValidBA || !isValidSH)
		{
		    scroll(0,0);
		    return false;
		}
	});
	
	$(".ShippingAddressesRadioButtons").click(function() {
	    if($(".SHAlsoShippingAddressCheckBox").hasClass("SHAlsoShippingAddressCheckBoxChecked"))
	    {
	        toggleShippingAddressForm(false, true);
	        $('.SHAlsoShippingAddressCheckBox input').removeAttr("checked");
	        $(".SHAlsoShippingAddressCheckBox").removeClass("SHAlsoShippingAddressCheckBoxChecked");
	    }
	    
	    if($(".ShippingAddressesRadioButtons input:checked").val() == 'NewAddress' || $(".ShippingAddressesRadioButtons input").val() == undefined){

	        $(this).removeClass("ShippingAddressesRadioButtonsChecked");
	        toggleShippingAddressForm(false, false);
	    } else {
	        $(this).addClass("ShippingAddressesRadioButtonsChecked");
	        toggleShippingAddressForm(true, false);
	    }
	});

	
$('.SHAlsoShippingAddressCheckBox').click(shippingBoxChecked);
	

    
    //Redesign
    
     // Tabs
  $("ul.css-tabs:first").tabs("div.css-panes:first > div");
  
    // Dynamic Dropdown
    $('.topNavSeparator').hoverIntent({
         sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
         interval: 200, // number = milliseconds for onMouseOver polling interval    
         over: windowSlideDown, // function = onMouseOver callback (REQUIRED)    
         timeout: 400, // number = milliseconds delay before onMouseOut    
         out: windowSlideUp // function = onMouseOut callback (REQUIRED)
    });
    
    $('.topNavSeparatorLast').hoverIntent({
        sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
        interval:20, // number = milliseconds for onMouseOver polling interval    
        over: windowSlideDown, // function = onMouseOver callback (REQUIRED)    
        timeout: 400, // number = milliseconds delay before onMouseOut    
        out: windowSlideUp // function = onMouseOut callback (REQUIRED)
    });
    
    
    function windowSlideDown() {
        $(this).addClass('addBackground');
        $('div.topNavCategories', this).slideDown('slow');
    }
    function windowSlideUp() {
        $(this).removeClass('addBackground');
        $('div.topNavCategories', this).slideUp('slow');
    }

    //Weekly Special
    $('#weeklySpecial').click(showSpecial);
    $('#weeklySpecialClose').click(hideSpecial);
    
    if($.cookie('weeklySpecial') == null)
    {
        $.cookie('weeklySpecial', 'open');
        showSpecial();
    }
    else
    {
        hideSpecial();
    }
    
    function showSpecial() {
      $('#weeklySpecialOpen').slideDown('normal', function(){
          $(this).fadeIn('slow').animate({opacity:'1.0'}, 6000).slideUp('slow');
      });
    }
    function hideSpecial() {
      $('#weeklySpecialOpen').stop().slideUp('normal');
    }
    
    //Email Signup
    $('#emailSignup').click(showEmailSignup);
    $('#emailSignupClose').click(hideEmailSignup);
    
    function showEmailSignup() {
     $('#emailSignupOpen').slideDown('normal');
    }
    function hideEmailSignup() {
      $('#emailSignupOpen').slideUp('normal');
    }
    
    //Catalog QO
    $('#catalogQO').click(showQO);
    $('#catalogQuickOrderClose').click(hideQO);
    
    function showQO() {
      $('#catalogQuickOrderOpen').slideDown('normal');
    }
    function hideQO() {
      $('#catalogQuickOrderOpen').slideUp('normal');
    }
    
    
    //Image Swap
    $('.altImagesStacked').click(swapImage);
    
    function swapImage() {
        var smallSource = $(this).children().attr('src');
        var smallWidth = $(this).children().attr('width');
        var smallHeight = $(this).height();
        
        var largeSource = $('#productDetailImage').children().attr('src');
        var largeWidth = $('#productDetailImage').children().attr('width');
        var largeHeight = $('#productDetailImage').height();
        
        $('#productDetailImage').children().attr('src', smallSource);
        $('#productDetailImage').maxSize(350);
        $(this).children().attr('src', largeSource);
        
    }
    
    //Swap StickyFooter
    $('#hideBar').click(hideStickyFooter);
    $('#showBar').click(showStickyFooter);
    
     if($.cookie('stickyFooter') == null){
        showStickyFooter();
    }
    else{
       hideStickyFooter();
    }
    
    function hideStickyFooter(){
        $('#hideBar').hide();
        $('#stickyContent').hide();
        $('#showBar').show();
        $('.stickyFooter').addClass('shrinkStickyFooter');
        
        if(this.id == 'hideBar'){
             $.cookie('stickyFooter', 'hide');
        }
    }
    function showStickyFooter(){
        $('#showBar').hide();
        $('#stickyContent').show();
        $('#hideBar').show();
        $('.stickyFooter').removeClass('shrinkStickyFooter');
      
         if(this.id == 'showBar'){
             $.cookie('stickyFooter', null,{ expires: -1 }); 
        }
    }
    
    //Trim email unsubscribe boxes. 3/26/10 TW
    $('#ctl00_cphBody_EmailUnsubscribe1_EmailAddressTextBox').blur(trimText);
    $('#ctl00_cphBody_EmailUnsubscribe1_ConfirmEmailAddressTextBox').blur(trimText);
    $('#ctl00_cphBody_EmailSignup1_EmailAddressTextBox').blur(trimText);
    $('#ctl00_cphBody_EmailSignup1_ConfirmEmailAddressTextBox').blur(trimText);
    
    function trimText() {
        var textValue = this.value;
        textValue.trim();
        this.value = textValue.trim();
    }
    
    //AutoFill Search
    

});

function openModal()
{
    //alert($('#test').attr('id'));
    
    //Get the A tag
		var id = $('#test').attr('href');
		
    //Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000);
}




//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	

//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
	
	$('#modalSubmit').click(closeModal);
	
function closeModal()
{
   $('.window').hide();
}


// Javascript pulled from Old Master Page 

function OpenVeriSign()
    {
        window.open('https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=www.aswechange.com&lang=en');
    }
    
//function pageLoad(){
//                  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//               }

function EndRequestHandler(sender, args) {
 var hiddenVal = document.getElementById('refreshDisplay');
 var checkoutTabName = document.getElementById('checkoutTabName');

 if (checkoutTabName.getAttribute('value') != "MISSING"){
    if (hiddenVal.getAttribute('value')=='true'){
       var divObj = document.getElementById(checkoutTabName.getAttribute('value'));
       var divHTML = document.getElementById('divHTMLValueExt');
       if (divHTML.getAttribute('value') != ''){
        $(".MiniCartItemCount").html(divHTML.getAttribute('value'));
       }
    }   
 }
}  

function GreyOut()
    {
        var cvr = document.getElementById("cover");
        cvr.style.display = "block";
        cvr.style.width = "200%";
        cvr.style.height = "200%";
        
        var prc = document.getElementById("processing");
        prc.style.display = "block";
        
        var BrowserWidth;
        var BrowserHeight;
 
         // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
         if (typeof window.innerWidth != 'undefined')
         {
              BrowserWidth = window.innerWidth,
              BrowserHeight = window.innerHeight
         }
         // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
         else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
         {
               BrowserWidth = document.documentElement.clientWidth,
               BrowserHeight = document.documentElement.clientHeight
         }
         // older versions of IE
         else
         {
               BrowserWidth = document.getElementsByTagName('body')[0].clientWidth,
               BrowserHeight = document.getElementsByTagName('body')[0].clientHeight
         }

        prc.style.left = (BrowserWidth - 300) / 2;
        prc.style.top = (BrowserHeight - 200) / 2;
    }
    
     function ResetCheckOutTab(){
            var objPanelDynamic = document.getElementById('<%=pnlShoppingCartDynamic.ClientID.ToString()%>');	
            objPanelDynamic.style.visibility='hidden';
        }

function orderSubmitted()
{
    if (typeof(Page_ClientValidate) == 'function')
    {
        var CreditCardValidation = Page_ClientValidate('CreditCardValidationGroup');
        var AddressEntryValidation = Page_ClientValidate('AddressEntry');
        var EmailEntryValidation = Page_ClientValidate('EmailValidationGroup');
        
        if (CreditCardValidation == true && AddressEntryValidation == true && EmailEntryValidation == true)
        {
            //The GreyOut() function is in the header of the master page.
            //The GreyOut() function utilizes two divs which are located just under the body tag
            //called "cover" and "processing"
            GreyOut();
        }
        else
        {
            return false;
        }
    }
}

 function ShowGreyout() {
        var modalPopupBehavior = $find('PanelCoverBh');
        modalPopupBehavior.show();
        return false;
    }
    function HideGreyout() {
        var modalPopupBehavior = $find('PanelCoverBh');
        modalPopupBehavior.hide();
        return false;
    }

/// Original JQueryFunctions taken out of document ready

function checkAddressCookie()
{
    if($.cookie('addChecked') == 'show'){
        shippingBoxCheckedHelper(false);
    }
}

function shippingBoxChecked()
{
    shippingBoxCheckedHelper(true) ;
}	

/// Modified by:    Erica Mutsch
/// Modified on:    05/03/10
/// Description:    WO 2068 - fixed bug that caused the "use billing address for shipping" box to stay checked
///                           also disabled radio buttons when box is checked
function shippingBoxCheckedHelper(ValidateTheBillingAddress) {
 if($(".ShippingAddressesRadioButtons").hasClass("ShippingAddressesRadioButtonsChecked"))
{
    toggleShippingAddressForm(false, false)
    $(".ShippingAddressesRadioButtons input")[0].checked = true;
    $(".ShippingAddressesRadioButtons").removeClass("ShippingAddressesRadioButtonsChecked");
}

var isValidSH;
removeErrorClasses();
if($(".SHAlsoShippingAddressCheckBox").hasClass("SHAlsoShippingAddressCheckBoxChecked")) 
    {
        $(".MultShipToLinkButton:disabled").removeAttr('disabled');
        $(".SHAlsoShippingAddressCheckBox").removeClass("SHAlsoShippingAddressCheckBoxChecked");
        toggleShippingAddressForm(false, true);
        checkForBillingAddressChange(false);
        
         if($.cookie('addChecked') == 'show'){
            $.cookie('addChecked', null,{ expires: -1 });
         }
    } 
    else 
    {
        if(ValidateTheBillingAddress == true){
            isValidSH = validateBillingAddress();
        }// closes if
        
        if(isValidSH)
        {
            $(".MultShipToLinkButton").attr('disabled','disabled');
            $(".SHAlsoShippingAddressCheckBox").addClass("SHAlsoShippingAddressCheckBoxChecked");
            $('.SHAlsoShippingAddressCheckBox input').attr('checked','true');
		    $(".SHErrorMessageLabel").html("");
            toggleShippingAddressForm(true, true);
            checkForBillingAddressChange(true);
            
            if($.cookie('addChecked') == null){
                $.cookie('addChecked', 'show');
            }
        } 
        else 
        {
            $(".MultShipToLinkButton:disabled").removeAttr('disabled');
            $('.SHAlsoShippingAddressCheckBox input').removeClass("SHAlsoShippingAddressCheckBoxChecked");
            $('.SHAlsoShippingAddressCheckBox input').removeAttr("checked");
            
             if($.cookie('addChecked') == 'show'){
                $.cookie('addChecked', null,{ expires: -1 });
             }
        }
    }

}

    function toggleShippingAddressForm(enabled, autofill) {
        var arrFields = ["FirstNameTextBox","LastNameTextBox","Address1TextBox","Address2TextBox","CityTextBox","StateDDL","ZipTextBox","ZipExtTextBox","DayTimeTextBox1","DayTimeTextBox2","DayTimeTextBox3","EveningPhoneTextBox1","EveningPhoneTextBox2","EveningPhoneTextBox3"];

        if(enabled)
        {
            $.each(arrFields, function() {
                if(autofill)
                {
                    $(".SH" + this).val($(".BA" + this).val())
                }
                $(".SH" + this).attr("disabled", "disabled");
            })
        }
        else
        {
            $.each(arrFields, function() {
                if(autofill)
                {
                    $(".SH" + this).val('')
                }
                $(".SH" + this).removeAttr("disabled", "disabled");
            })
            $(".SHStateDDL").val("-1")
        }
    }
    
    function checkForBillingAddressChange(checkKeyUp) {
        var arrFields = ["BAFirstNameTextBox","BALastNameTextBox","BAAddress1TextBox","BAAddress2TextBox","BACityTextBox","BAZipTextBox","BAZipExtTextBox","BADayTimeTextBox1","BADayTimeTextBox2","BADayTimeTextBox3","BAEveningPhoneTextBox1","BAEveningPhoneTextBox2","BAEveningPhoneTextBox3"];
        if(checkKeyUp) {
            $.each(arrFields, function() {
                $("." + this).one("keyup", billingChanged);
                $('.BAStateDDL').change(billingChanged);
            })
        } else {
            $.each(arrFields, function() {
                $("." + this).unbind("keyup");
            })
        }
    }
    
    function billingChanged() {
        var arrFields = ["BAFirstNameTextBox","BALastNameTextBox","BAAddress1TextBox","BAAddress2TextBox","BACityTextBox","BAZipTextBox","BAZipExtTextBox","BADayTimeTextBox1","BADayTimeTextBox2","BADayTimeTextBox3","BAEveningPhoneTextBox1","BAEveningPhoneTextBox2","BAEveningPhoneTextBox3"];
        toggleShippingAddressForm(false, true);
        $('.SHAlsoShippingAddressCheckBox input').removeAttr("checked");
        $('.SHAlsoShippingAddressCheckBox').removeClass("SHAlsoShippingAddressCheckBoxChecked");
        
        $.each(arrFields, function() {
            $("." + this).unbind("keyup");
        })
    }
    
    function removeErrorClasses() {
    	$("label").removeClass("FormLabelError");
	    $(":input").removeClass("FormTextBoxError");
    }
    
    function validateBillingAddress() {
        var isValidBA;
        var billingErrorList;
        isValidBA = true;
        billingErrorList = "<ul class='ErrorMessageLabel'>";
        
        if($(".BAFirstNameTextBox").val().length == 0){
	        $(".BAFirstNameTextBox").addClass("FormTextBoxError");
	        $(".BAFirstNameLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter your first name.</li>";
	        isValidBA = false;
	    }
	    if($(".BALastNameTextBox").val().length == 0){
	        $(".BALastNameTextBox").addClass("FormTextBoxError");
	        $(".BALastNameLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter your last name.</li>";
	        isValidBA = false;
	    }	    
	    if($(".BAAddress1TextBox").val().length == 0){
	        $(".BAAddress1TextBox").addClass("FormTextBoxError");
	        $(".BAAddress1Label").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter your address.</li>";
	        isValidBA = false;
	    }	    
	    if($(".BACityTextBox").val().length == 0){
	        $(".BACityTextBox").addClass("FormTextBoxError");
	        $(".BACityLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter your city.</li>";
	        isValidBA = false;
	    }	 	    
	    if($(".BAStateDDL").val() == "Select State"){
	        $(".BAStateDDL").addClass("FormDropDownBoxError");
	        $(".BAStateLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter your state.</li>";
	        isValidBA = false;
	    }
	    if(!$(".BAZipTextBox").val().match(/\d{5}/)){
	        $(".BAZipTextBox").addClass("FormTextBoxError");
	        $(".BAZipLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter your state.</li>";
	        isValidBA = false;
	    }
	    if($(".BAZipExtTextBox").val().length > 0 && !$(".BAZipExtTextBox").val().match(/\d{4}/)){
	        $(".BAZipExtTextBox").addClass("FormTextBoxError");
	        $(".BAZipLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter a valid zip code extension.</li>";
	        isValidBA = false;
	    }
	    if(!$(".BADayTimeTextBox1").val().match(/\d{3}/)){
	        $(".BADayTimeTextBox1").addClass("FormTextBoxError");
	        $(".BADayTimePhoneLabel").addClass("FormLabelError");
	        $(".BADayTimeTextBox2").addClass("FormTextBoxError");
	        $(".BADayTimePhoneLabel").addClass("FormLabelError");
	        $(".BADayTimeTextBox3").addClass("FormTextBoxError");
	        $(".BADayTimePhoneLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter a valid day time phone number.</li>";
	        isValidBA = false;
	    } else {
	        if(!$(".BADayTimeTextBox2").val().match(/\d{3}/)){
	            $(".BADayTimeTextBox1").addClass("FormTextBoxError");
	            $(".BADayTimePhoneLabel").addClass("FormLabelError");
	            $(".BADayTimeTextBox2").addClass("FormTextBoxError");
	            $(".BADayTimePhoneLabel").addClass("FormLabelError");
	            $(".BADayTimeTextBox3").addClass("FormTextBoxError");
	            $(".BADayTimePhoneLabel").addClass("FormLabelError");
	            billingErrorList += "<li>Please enter a valid day time phone number.</li>";
	            isValidBA = false;
	        } else {
	            if(!$(".BADayTimeTextBox3").val().match(/\d{4}/)){
	                $(".BADayTimeTextBox1").addClass("FormTextBoxError");
	                $(".BADayTimePhoneLabel").addClass("FormLabelError");
	                $(".BADayTimeTextBox2").addClass("FormTextBoxError");
	                $(".BADayTimePhoneLabel").addClass("FormLabelError");
	                $(".BADayTimeTextBox3").addClass("FormTextBoxError");
	                $(".BADayTimePhoneLabel").addClass("FormLabelError");
	                billingErrorList += "<li>Please enter a valid day time phone number.</li>";
	                isValidBA = false;
	            }
	        }
	    }
	    	     
	    if(!$(".BAEmailTextBox").val().match(/^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*([A-Za-z0-9]+\-?)@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/)){
	        $(".BAEmailTextBox").addClass("FormTextBoxError");
	        $(".BAEmailLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Please enter a valid email address.</li>";
	        isValid = false;
	    }
	    if($(".BAEmailTextBox").val() != $(".BAConfirmEmailTextBox").val()){
	        $(".BAEmailTextBox").addClass("FormTextBoxError");
	        $(".BAEmailLabel").addClass("FormLabelError");
	        $(".BAConfirmEmailTextBox").addClass("FormTextBoxError");
	        $(".BAConfirmEmailLabel").addClass("FormLabelError");
	        billingErrorList += "<li>Email and Confirm Email does not match.</li>";
	        isValidBA = false;
        }
        
        if(!isValidBA)
        {
            billingErrorList += "</ul>";
            $(".BAErrorMessageLabel").html(billingErrorList);
		} else {
		    $(".BAErrorMessageLabel").html("");
		}
        return isValidBA;
    }
    
    function validateShippingAddress() {
        var isValidSH;
        var shippingErrorList;
        shippingErrorList = "<ul class='ErrorMessageLabel'>";
	    isValidSH = true;
	    
        if($(".SHFirstNameTextBox").val().length == 0){
            $(".SHFirstNameTextBox").addClass("FormTextBoxError");
            $(".SHFirstNameLabel").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter your first name.</li>";
            isValidSH = false;
        }
        if($(".SHLastNameTextBox").val().length == 0){
            $(".SHLastNameTextBox").addClass("FormTextBoxError");
            $(".SHLastNameLabel").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter your last name.</li>";
            isValidSH = false;
        }
        if($(".SHAddress1TextBox").val().length == 0){
            $(".SHAddress1TextBox").addClass("FormTextBoxError");
            $(".SHAddress1Label").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter your address.</li>";
            isValidSH = false;
        }	    
        if($(".SHCityTextBox").val().length == 0){
            $(".SHCityTextBox").addClass("FormTextBoxError");
            $(".SHCityLabel").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter your city.</li>";
            isValidSH = false;
        }	 	    
        if($(".SHStateDDL").val() == "-1"){
            $(".SHStateDDL").addClass("FormTextBoxError");
            $(".SHStateLabel").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter your state.</li>";
            isValidSH = false;
        }
        if(!$(".SHZipTextBox").val().match(/\d{5}/)){
            $(".SHZipTextBox").addClass("FormTextBoxError");
            $(".SHZipLabel").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter your zip code.</li>";
            isValidSH = false;
        }
        if($(".SHZipExtTextBox").val().length > 0 && !$(".SHZipExtTextBox").val().match(/\d{4}/)){
            $(".SHZipExtTextBox").addClass("FormTextBoxError");
            $(".SHZipLabel").addClass("FormLabelError");
            shippingErrorList += "<li>Please enter a valid zip code extension.</li>";
            isValidSH = false;
        }
    
    	if(!isValidSH)
		{
		    shippingErrorList += "</ul>";
            $(".SHErrorMessageLabel").html(shippingErrorList);
		} else {
		    $(".SHErrorMessageLabel").html("");
		}
    
        return isValidSH;
    }
    
    function enableDisableMultShipToButton(setToEnabled){
        if(setToEnabled == true){
            $(".MultShipToLinkButton:disabled").removeAttr('disabled');
        } else {
            $(".MultShipToLinkButton").attr('disabled','disabled');
        }
        
    }
    
        /* begin of the Photo Pers*/
function closeModal(){
   $('.window').hide();
}

function openModal()
{
    //Get the A tag
    var id = $('#test').attr('href');
            
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
      
    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
            
    //transition effect           
    $('#mask').fadeIn(1000);      
    $('#mask').fadeTo("slow",0.8);      
      
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
              
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);
      
    //transition effect
     $(id).fadeIn(2000);
}

/* end of the Photo Pers*/
//     var data = "cat, cat litter, cat and hat, dog, dog collar, dog leash, fish, fish fry, fishing".split(", ");
//    $("#ctl00_txtSearch").autocomplete(data);

    function openWin(pageName)
    {
        openWinWithProperties(pageName,"width=725, height=600,scrollbars=yes, menubar=no, resizable=yes");
    }
    
    function openWinWithProperties(pageName, winProperties)
    {
        window.open(pageName,null,winProperties);
    }