jQuery(document).ready(function() {
	jQuery('a[rel^="ext"]').attr('target', '_blank');
	
 	jQuery("#vip-email").defaultValue("Sign up for our VIP list");
	selectLocations();
	
	var v1 = jQuery(".jvalidate").validate();
	
	//Make distinct validator for form submit
	var v2 = jQuery("#form-vip-email").validate();
	

	jQuery.validator.addMethod("phone", function(value) {
		/* Make the Phone # Optional - Only validate when value is present */
		if(jQuery.trim(value) == ""){
			return true;
		}else{
			var re = new RegExp(/^[\(]?(\d{0,3})[\)]?[\s]?[\-]?(\d{3})[\s]?[\-]?(\d{4})[\s]?[x]?(\d*)$/);
			return re.exec(value.toUpperCase());
		}
	}, "Please enter a valid Phone Number");
	
	//selectMainMenu("mm-");
	//selectMainMenu("mil-",1);

});

function selectLocations(){
	    jQuery(".select-location-row").toggle(
      function () {
        jQuery(".select-location .sf-item").slideDown("fast");
      },
      function () {
        jQuery(".select-location .sf-item").slideUp("fast");
      }
    );
};

function customRange(input) {
		return {minDate: (input.id == "check_out" ? jQuery("#check_in").datepicker("getDate") : null), maxDate: (input.id == "check_in" ? jQuery("#check_out").datepicker("getDate") : null)};
};

var active_toggle = null;
function toggle(el){
	el = jQuery(el);
	var thetoggle = jQuery("#"+el.attr("rel"));

	if(active_toggle != null){
			active_toggle.slideUp('normal');

			if(active_toggle.attr("id") != thetoggle.attr("id")){
				showToggle(thetoggle);
			}else{
				active_toggle = null;
			}
	}else{
		showToggle(thetoggle);
	}

};

function showToggle(thetoggle){
	thetoggle.slideDown('normal');
	active_toggle = thetoggle;
};

var prevpage = "";
var prevsubpageactive = "";

function selectMainMenu(prefix, idx){
	if(idx ==undefined){
		idx = 0;
	}
	
	var thepagename;
	if(subsection.length == 0){
		thepagename = "home"
	}else{
		
		thepagename = subsection[idx];
		
		if(idx == 2 && hassubitems){
			jQuery("#"+prefix+thepagename).parent().addClass("down")
		}
		
		
	}
		jQuery("#"+prefix+thepagename).addClass("selected");
		if(prevpage !=""){
			jQuery("#"+prefix+prevpage).removeClass("selected");
		}
		//alert("#"+prefix+thepagename);
		prevpage ="#"+prefix+thepagename;

};