

jQuery(document).ready(function(){


	// Place ID's of all required fields here.
	required = ["firstname", "lastname", "zip", "phone", "email", "date"];
	// If using an ID other than #email or #error then replace it here
	firstname = jQuery("#firstname");
	lastname = jQuery("#lastname");
	zip = jQuery("#zip");	
	phone = jQuery("#phone");
	email = jQuery("#email");
	date = jQuery("#date");	
	errornotice = jQuery("#error");
	// The text to show up within a field when it is incorrect
	emptyerror = "Please fill out this field.";
	emailerror = "Invalid Email";
	phoneerror = "Invalid Phone number";
	
	jQuery("#consult_form").submit(function(){	
		//Validate required fields
	//	alert('test');
		for (i=0;i<required.length;i++) {
			var input = jQuery('#'+required[i]);
			if ((input.val() == "First Name") || (input.val() == "Last Name") || (input.val() == "Preferred Phone") || (input.val() == "Zip Code") || (input.val() == "Email") || (input.val() == "MM/DD/YYYY") || (input.val() == emptyerror)) {
				input.addClass("error_input_field");
			} else {
				input.removeClass("error_input_field");
			}
		}

	var value = $('#phone').val().replace(/^\s\s*/, '').replace(/\s\s*$\./, '');
    var intRegex =  /^[0-9\-\+\.]+$/;
    if(!intRegex.test(value)) {
			phone.addClass("error_input_field");
			phone.val(phoneerror);
    }
//	/^\d+$\./;
/*$.validator.addMethod('phone', function(value, element) {
    return this.optional(element) || (/^\d{7,}$/).test(value.replace(/[\s()+\-\.]|ext/gi, ''));
});
*/


		// Validate the e-mail.

		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
			email.addClass("error_input_field");
			email.val(emailerror);
		}


		if ($('#message').val() == "") {
			$('#message').addClass("error_input_field");		
		} else {
			$('#message').removeClass("error_input_field");
		}

		if (jQuery('#nonconfidential').not(':checked')) {
			jQuery('#nonconfidential').next().addClass("error_label");
		}
		if (jQuery('#nonconfidential').is(':checked')) {
			jQuery('#nonconfidential').next().removeClass("error_label");
		}

		if (document.getElementById("state").selectedIndex == 0) {
			jQuery("#state").addClass("select_error");
		}
		else {
			jQuery("#state").removeClass("select_error");
		}

		if (document.getElementById("relationship").selectedIndex == 0) {
			jQuery("#relationship").addClass("select_error");
		}
		else {
			jQuery("#relationship").removeClass("select_error");
		}
		if (document.getElementById("type").selectedIndex == 0) {
			jQuery("#type").addClass("select_error");
		}
		else {
			jQuery("#type").removeClass("select_error");
		}

		
		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if (jQuery(":input").hasClass("error_input_field") || jQuery("span").hasClass("error_label") || jQuery("textarea").hasClass("error_input_field") || jQuery("select").hasClass("select_error")) {
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});
	
	
	
	jQuery.fn.clearOnFocus = function(){
    return this.focus(function(){
        var v = jQuery(this).val();
        jQuery(this).val( v === this.defaultValue ? '' : v );
    }).blur(function(){
        var v = jQuery(this).val();
        jQuery(this).val( v.match(/^\s+$|^$/) ? this.defaultValue : v );
    });
 
	};
	jQuery('input.input_field').clearOnFocus();

		$('.request_popup_close, .contact_popup_close').click(function() {
		$(this).parent().fadeOut();
		$('#backgroundPopup').hide();		
	});
	

// black screen dynamic height on window resize
	$(window).resize(function(){
	   var body_win_height = parseInt(document.body.clientHeight) ;
	   var win_height = parseInt(document.documentElement.clientHeight) ;

	   if( body_win_height > win_height) {
		$('#backgroundPopup').height(body_win_height);
	   } else {
		$('#backgroundPopup').height(win_height);
	   }
	});
	
   var body_win_height = parseInt(document.body.clientHeight) ;
   var win_height = parseInt(document.documentElement.clientHeight) ;

	   if( body_win_height > win_height) {
		$('#backgroundPopup').height(body_win_height);
	   } else {
		$('#backgroundPopup').height(win_height);
	   }

	$('.chart_img').click(function() {
		$('#backgroundPopup').show();
		$('#chart_wrapper').fadeIn();		
   
	 });
				// tab scripts
				
				$('#cerebral_palsy').click(function() {
					$('.Erbs_Palsy').hide(); 
					$('.Birth_Injuries').hide();
					$('.Cerebral_Palsy').fadeIn();
					$(this).addClass('default_tab');
					$(this).siblings().removeClass('default_tab');
				});
				$('#erbs_palsy').click(function() {
					$('.Birth_Injuries').hide();
					$('.Cerebral_Palsy').hide();					
					$('.Erbs_Palsy').fadeIn(); 					
					$(this).addClass('default_tab');
					$(this).siblings().removeClass('default_tab');					
				});
				$('#birth_injuries').click(function() {
					$('.Erbs_Palsy').hide(); 
					$('.Cerebral_Palsy').hide();					
					$('.Birth_Injuries').fadeIn();					
					$(this).addClass('default_tab');
					$(this).siblings().removeClass('default_tab');					
				});	
});
