$(document).ready(function() {
	
	/* Removes or adds default value to text inputs */
	$("input.labelinside, textarea.labelinside").each(function(i){
        if ( $(this).val().length == 0 ) {                    
            $(this).val($(this).attr('title'));
            $(this).addClass("default");
        }
    });
    $("input.labelinside, textarea.labelinside").focus(function(e){
        if ( $(this).val() == $(this).attr('title') ) {
            $(this).val('');
            $(this).removeClass("default");
        }
    });
    $("input.labelinside, textarea.labelinside").blur(function(e){
        if ( $(this).val() == '' ) {
            $(this).val($(this).attr('title'));
            $(this).addClass("default");
        }
	 });	 
	 
	 /* This Triggers the form action aka: submits form */
	 $('div.form div.button').click(function() {
	 	$('#header-form').submit();
	 });
	 $('div.form div.button').click(function() {
	 	$('#middle-form').submit();
	 });
	 
	/* Adds/removes bg color on types list when hovered */
	 $('div#resources li').mouseover(function() {
		$(this).addClass('highlight');
	 });
	 $('div#resources li').mouseout(function() {
		$(this).removeClass('highlight');
	 });
	 
/* Removes or adds default value to text inputs with passwords */
$("input.labelinside-password").each(function(i){
	if ( $(this).val().length == 0 ) {                    
		$(this).val($(this).attr('title'));
		$("input.password-login").hide();
	}
});
$("input.labelinside-password").focus(function(e){
	if ( $(this).val() == $(this).attr('title') ) {
		$(this).val('');
		$(this).hide();
		$("input.password-login").show();
		$("input.password-login").get(0).focus();
	}
});

$("input.password-login").blur(function(e){
	if ( $(this).val() == '' ) {
		$(this).hide();
		$("input.labelinside-password").show();
		$("input.labelinside-password").val($("input.labelinside-password").attr('title'));

	}
 });	 

		 
});
	
	/* This makes our navigation dropdowns appear/disappear */
	var activeInfoDiv = null;
	
	function changeInfoDiv(div) {
	if(!arguments[0] && activeInfoDiv) {
		document.getElementById(activeInfoDiv).style.display = 'none';
		activeInfoDiv = null;
	}
	else if(div != activeInfoDiv) {
		if(activeInfoDiv) {
			document.getElementById(activeInfoDiv).style.display = 'none';
		}
		document.getElementById(div).style.display = 'block';
		activeInfoDiv = div;
	}
}

function is_valid_zipcode(zipcode) {  
    var reg = /^([0-9]{5})$/;
    return reg.test(zipcode); 
}


function FormCheck(form, zipcode, select) {
    var siteURL ="";
	var insurance_type = $(select).val();
	
		siteURL ="/" + insurance_type + "/";
		siteURL = siteURL + "?zip=" + $(zipcode).val();
		
		$(zipcode).removeClass('error');
	
		if ( !is_valid_zipcode($(zipcode).val()) ) {
			$(zipcode).addClass('error');
			alert("Please enter a valid zip code.");
			return false;
			$(zipcode).focus()
		}else{
			
			if(insurance_type != '') {
	
				window.open(siteURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
				$(form).submit();
				return true;
			
			}
		}
	
}        
