$(document).ready(function() {
   // put all your jQuery goodness in here.
   // Do not instantiate elements until the document has finished loading

   	var cookieLang = $.cookie('currentCulture');   	   	
   	   	  
   	if (cookieLang == null) {
   		tb_show("Sprache / Langue","TB_inline?height=120&width=300&inlineId=hiddenModalContent");
   	}
   	
   	else if (cookieLang != null) {
   		$("#ship-to").show();
   	}  

	
	//Accordion functions
	$('.accordion-list:not(:first)').hide();
	
	$('.accordion-list:first').show();
	
	$('.accordion-header:first').addClass('active');	
	$('.accordion-list:first').addClass('content-active');
	
	$('.accordion-header').click(function () {
		$('.accordion-list:visible').slideUp().prev().removeClass('active');
		$('.accordion-list:visible').removeClass('content-active');
		$(this).addClass('active').next().slideDown();
		$('.accordion-list').addClass('content-active');
		
	});
	


		// Accordion - uses jQuery UI includes
		//$("#accordion").accordion({ header: "h3", autoHeight: false });
				
		// Main Navigation Drop Down Menu
		$('li.sitenavTab').hover(function() {
			$(this).find('.sitenavDropDown').show();
			//$(this).find('a.sitenavLink').css('backgroundColor', '#c1d34b');
			$(this).find('a.sitenavLink').addClass("sitenavHover");

		}, function() {
			$(this).find('.sitenavDropDown').hide();
			//$(this).find('a.sitenavLink').css('backgroundColor', '#830136');
			$(this).find('a.sitenavLink').removeClass("sitenavHover");
		});
		
		//Sign Up Form Validation
    	$(".email-signup #ctl00_cphMaster_WineGuarantee1_submit").click(function(){
        
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var email = $("#ctl00_cphMaster_WineGuarantee1_emailsignup").val();
				
		if(email == '') {
			$(".email-error").replaceWith('<div class="email-error"><p>' + GetString("ForgotToEnterEmail") + '</p></div>');
		} else if(!emailReg.test(email)) {
			$(".email-error").replaceWith('<div class="email-error"><p>' + GetString("EnterValidEmail") + '</p></div>');
		} else {
		  		$(".track").html('<img src="http://directwines.bm23.com/public/actionpage/subscriber_add/?fn=Mail_ActionPage_FormResponse&pid=4lweygh2lk1peq9twrr70pojexuh8&ssid=12512&email=' +  email + '&list_data[208133]=checked" width="0" height="0" border="0" alt=""/>');
		  		$(".email-signup").html('<p>' + GetString("ThanksForSubscribing") + '</p>')
		}
		return false;
		});
		
	});
	
	// Wine Shop 4 Panel Feature - uses jQuery UI includes
	$(function() {
		$("#tabs").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 7000);
		
	// Search Results - Mouseover Image - looks for small image something_s.jpg and shows
	// large image something_l.jpg in the mouse over. Settings can be found in jquery.thumbhover.js
	$("img[title*='product-case-img']").thumbPopup({
				imgSmallFlag: "",
				imgLargeFlag: ""
		});
	});
	
	

$(document).ready(function() {

$.validator.setDefaults({
	success: "valid"
});

jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    //return true;
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
	   
	phone_number.match(/^[0-9]*$/);
}, GetString("SpecifyPhoneNumber"));

jQuery.validator.addMethod("validateDate", function(strDate, element) {
    //Validating the format DD/MM/YYYY
    var regExp = /^[0-9]*$/;
    if (strDate.length==10)
    {
        for(var intCount=0;intCount<10;intCount++)
        {
            if (intCount!=2 && intCount!=5)
            {
                if(regExp.test(strDate.charAt(intCount))==false)
                {
                    return(false);
                }
            }
        }
        if (strDate.charAt(2)!='/' || strDate.charAt(5) !='/')
        {
            return(false);
        }
    }
    else
    {
        return(false);
    }
    //Validating the date
    var DateParts = strDate.split("/");    
    var dt = new Date(); 
    dt.setFullYear(DateParts[2],DateParts[1]-1,DateParts[0])
    
    if(dt.getDate()!=DateParts[0])
    {
        return(false);
    }
    else if(dt.getMonth()!=DateParts[1]-1)
    {
        //this is for the purpose JavaScript starts the month from 0
        return(false);
    }
    else if(dt.getFullYear()!=DateParts[2])
    {
        return(false);
    }    
    // if the year is less than the min limit 1900, alert the user
    if(dt.getFullYear() < 1900)
    {
        return(false);
    }
    return(true);
}, GetString("EnterValidDate"));

jQuery.validator.addMethod("validateAge", function(strDate, element) {
    var DateParts = strDate.split("/");    
    var dt = new Date(); 
    dt.setFullYear(DateParts[2],DateParts[1]-1,DateParts[0])
    //validating for greater than 18 yrs
    var today = new Date();
    if(today.getFullYear() - dt.getFullYear() < 18)
    {
        return(false);
    }
    else if(today.getFullYear() - dt.getFullYear() == 18)
    {
        if(today.getMonth() - dt.getMonth() < 0)
        {   
            return(false);
        }
        else if(today.getMonth() - dt.getMonth() == 0)
        {
            if(today.getDate() - dt.getDate() < 0)
            {
                return(false);
            }
        }
    }               
    return(true);
}, GetString("AgeGT18"));

jQuery.validator.addMethod("select_suburb",function(value, element) 
        { 
            if ((element.value == "")|| (element.value == "Please Click here to select suburb"))
            {
            return false;
            }
            else
            {
            return true;
            }
        }, GetString("SelectCity")); 
	
	// Registration Form Validation - using jquery.validate.min.js			
	$(".registration #aspnetForm").validate({
		rules: {
			ctl00$cphMaster$txtFirstName: "required",
			ctl00$cphMaster$txtLastName: "required",
			ctl00$cphMaster$txtEmailID: {
    			email: true,
    			required:true
    		},
    		ctl00$cphMaster$txtConfirmEmailID: {
    			equalTo: "#ctl00_cphMaster_txtEmailID",
    			email: true,
    			required: true
    		},
    		ctl00$cphMaster$txtPassword: {
    			minlength: 6,
    			required: true
    		},
    		ctl00$cphMaster$txtConfirmPassword: {
      			equalTo: "#ctl00_cphMaster_txtPassword",
      			minlength: 6,
      			required: true
    		},
    		ctl00$cphMaster$txtAddress1: {
    			required: true
    		},
    		ctl00$cphMaster$txtCity: {
    			required: true
    		},    		
    		ctl00$cphMaster$txtZipCode: {
    			required:true,
    			minlength: 4
    		},
    		ctl00$cphMaster$txtPhone: {
    			required: true,
      			phoneUS: true
    		},
    		ctl00$cphMaster$txtDOB: {
    			required: true,
    			validateDate: true,
    			validateAge: true
    		},
    		city1:{
    		    select_suburb: true  		    
    		}   	
  		},
  		messages: {
  		ctl00$cphMaster$txtFirstName: GetString("SpecifyFirstName"),
  		ctl00$cphMaster$txtLastName: GetString("SpecifyLastName"),
  		ctl00$cphMaster$txtConfirmEmailID: GetString("ConfirmEmail"),
  		ctl00$cphMaster$txtPassword: {
  		required: GetString("EnterAPassword"),
  		minlength: GetString("YourPwdAtleast6Char")
  		},
  		ctl00$cphMaster$txtConfirmPassword: {
  		required: GetString("ConfirmPassword"),
  		minlength: GetString("YourPwdAtleast6Char")
  		},
  		ctl00$cphMaster$txtAddress1: GetString("EnterAddress"),
  		ctl00$cphMaster$txtCity: GetString("EnterCity"),
  		ctl00$cphMaster$txtZipCode: {
  		required: GetString("EnterZipcode"),
  		minlength: GetString("EnterValidZipcode")
  		}  		
  		}
	});
	
	
});	

