var loginActive = 0;
var searchActive = 1;

$(function() {
	
	//Contact Form
	$('#contact_form .error').hide();
	$("input#name").select().focus();
	$("#submit_btn").click(function() {
		sendEmail();
	});
	
	//Registration
	$('#registration .error').hide();
	
});

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function sendEmail() {
	
$('.error').hide();

var name = $("input#name").val();

	if (name == "") {
		alert('Enter a name');
		$("input#name").focus();
		return false;
	}

var email = $("input#email").val();

	if(isValidEmailAddress(email)) {

	} else {
		alert('Invalid Email');
		$("input#email").focus();
		return false;
	}
	
var phone = $("input#phone").val();

	if (phone == "") {
		alert('Enter a phone number');
		$("input#phone").focus();
		return false;
	}
	
var subject = $("input#subject").val();

	if (subject == "") {
		alert('Enter a subject');
		$("input#subject").focus();
		return false;
	}
	
var message = $("textarea#description").val();

	if (message == "") {
		alert('Enter a message');
		$("textarea#description").focus();
		return false;
	}
	
var recipient = $("#recipient").val();
	
var dataString = 'name=' + name + '&email=' + email + '&phone=' + phone + '&subject=' + subject + '&message=' + message + '&recipient=' + recipient;
//alert (dataString);return false;

$.ajax({
	type: "POST",
	url: "/includes/process.php",
	data: dataString,
	success: function() {
	$('#contact_form').html("<div id='message'></div>");
	$('#message').html("<h2 class='grey'>Thank you!</h2>")
	.hide()
	.fadeIn(500);
	}
});

return false;
    
}

function checkRegForm() {
	
	$('.error').hide();

var patientFirstName = $("input#patientFirstName").val();

	if (patientFirstName == "") {
		$('#patientFirstName_error').show();
		$("input#patientFirstName").focus();
		return false;
	}

var patientMiddleI = $("input#patientMiddleI").val();
/*
	if (patientMiddleI == "") {
		$('#patientMiddleI_error').show();
		$("input#patientMiddleI").focus();
		return false;
	}
*/

var patientLastName = $("input#patientLastName").val();

	if (patientLastName == "") {
		$('#patientLastName_error').show();
		$("input#patientLastName").focus();
		return false;
	}

var patientCity = $("input#patientCity").val();

	if (patientCity == "") {
		$('#patientCity_error').show();
		$("input#patientCity").focus();
		return false;
	}
	
var patientBirthMonth = $("select#patientBirthMonth").val();
var patientBirthDay = $("select#patientBirthDay").val();
var patientBirthYear = $("select#patientBirthYear").val();

var patientAddress = $("input#patientAddress").val();

var patientAddress2 = $("input#patientAddress2").val();

	if (patientAddress == "") {
		$('#patientAddress_error').show();
		$("input#patientAddress").focus();
		return false;
	}

var patientZIP = $("input#patientZIP").val();

	if (patientZIP == "") {
		$('#patientZIP_error').show();
		$("input#patientZIP").focus();
		return false;
	}

var patientHomePhone = $("input#patientHomePhone").val();

	if (patientHomePhone == "") {
		$('#patientHomePhone_error').show();
		$("input#patientHomePhone").focus();
		return false;
	}

var patientCellPhone = $("input#patientCellPhone").val();
/*
	if (patientCellPhone == "") {
		$('#patientCellPhone_error').show();
		$("input#patientCellPhone").focus();
		return false;
	}
*/

var patientMedAllergies = $("input#patientMedAllergies").val();

	if (patientMedAllergies == "") {
		$('#patientMedAllergies_error').show();
		$("input#patientMedAllergies").focus();
		return false;
	}

var patientCurrentAllergies = $("input#patientCurrentAllergies").val();

	if (patientCurrentAllergies == "") {
		$('#patientCurrentAllergies_error').show();
		$("input#patientCurrentAllergies").focus();
		return false;
	}

var emergencyName = $("input#emergencyName").val();

	if (emergencyName == "") {
		$('#emergencyName_error').show();
		$("input#emergencyName").focus();
		return false;
	}

var emergencyPhone = $("input#emergencyPhone").val();

	if (emergencyPhone == "") {
		$('#emergencyPhone_error').show();
		$("input#emergencyPhone").focus();
		return false;
	}

var responsibleFirstName = $("input#responsibleFirstName").val();

	if (responsibleFirstName == "") {
		$('#responsibleFirstName_error').show();
		$("input#responsibleFirstName").focus();
		return false;
	}

var responsibleMiddleI = $("input#responsibleMiddleI").val();
/*
	if (responsibleMiddleI == "") {
		$('#responsibleMiddleI_error').show();
		$("input#responsibleMiddleI").focus();
		return false;
	}
*/

var responsibleLastName = $("input#responsibleLastName").val();

	if (responsibleLastName == "") {
		$('#responsibleLastName_error').show();
		$("input#responsibleLastName").focus();
		return false;
	}
	
var responsibleBirthMonth = $("select#responsibleBirthMonth").val();
var responsibleBirthDay = $("select#responsibleBirthDay").val();
var responsibleBirthYear = $("select#responsibleBirthYear").val();

var responsibleCity = $("input#responsibleCity").val();

	if (responsibleCity == "") {
		$('#responsibleCity_error').show();
		$("input#responsibleCity").focus();
		return false;
	}

var responsibleAddress = $("input#responsibleAddress").val();
var responsibleAddress2 = $("input#responsibleAddress2").val();

	if (responsibleAddress == "") {
		$('#responsibleAddress_error').show();
		$("input#responsibleAddress").focus();
		return false;
	}

var responsibleZIP = $("input#responsibleZIP").val();

	if (responsibleZIP == "") {
		$('#responsibleZIP_error').show();
		$("input#responsibleZIP").focus();
		return false;
	}

var responsibleHomePhone = $("input#responsibleHomePhone").val();

	if (responsibleHomePhone == "") {
		$('#responsibleHomePhone_error').show();
		$("input#responsibleHomePhone").focus();
		return false;
	}

var responsibleWorkPhone = $("input#responsibleWorkPhone").val();
/*
	if (responsibleWorkPhone == "") {
		$('#responsibleWorkPhone_error').show();
		$("input#responsibleWorkPhone").focus();
		return false;
	}
*/

var responsibleRelationship = $("input#responsibleRelationship").val();

	if (responsibleRelationship == "") {
		$('#responsibleRelationship_error').show();
		$("input#responsibleRelationship").focus();
		return false;
	}
var primaryName = $("input#primaryName").val();
/*

	if (primaryName == "") {
		$('#primaryName_error').show();
		$("input#primaryName").focus();
		return false;
	}
*/

var primaryPolicyNum = $("input#primaryPolicyNum").val();
/*
	if (primaryPolicyNum == "") {
		$('#primaryPolicyNum_error').show();
		$("input#primaryPolicyNum").focus();
		return false;
	}
*/	
var primaryMailClaims = $("input#primaryMailClaims").val();
/*
	if (primaryMailClaims == "") {
		$('#primaryMailClaims_error').show();
		$("input#primaryMailClaims").focus();
		return false;
	}
*/
var primaryCity = $("input#primaryCity").val();
/*
	if (primaryCity == "") {
		$('#primaryCity_error').show();
		$("input#primaryCity").focus();
		return false;
	}
*/
var primaryState = $("#primaryState option:selected").text();
/*
	if (primaryState == '-- Select State --') {
		$('#primaryState_error').show();
		$("#primaryState").focus();
		return false;
	}
*/
var primaryZIP = $("input#primaryZIP").val();
/*
	if (primaryZIP == "") {
		$('#primaryZIP_error').show();
		$("input#primaryZIP").focus();
		return false;
	}
*/
var secondaryName = $("input#secondaryName").val();
/*
	if (secondaryName == "") {
		$('#secondaryName_error').show();
		$("input#secondaryName").focus();
		return false;
	}
*/
var secondaryPolicyNum = $("input#secondaryPolicyNum").val();
/*
	if (secondaryPolicyNum == "") {
		$('#secondaryPolicyNum_error').show();
		$("input#secondaryPolicyNum").focus();
		return false;
	}
*/
var secondaryMailClaims = $("input#secondaryMailClaims").val();
/*
	if (secondaryMailClaims == "") {
		$('#secondaryMailClaims_error').show();
		$("input#secondaryMailClaims").focus();
		return false;
	}
*/	
var secondaryPolicyNum = $("input#secondaryPolicyNum").val();
/*
	if (secondaryPolicyNum == "") {
		$('#secondaryPolicyNum_error').show();
		$("input#secondaryPolicyNum").focus();
		return false;
	}
*/	
var secondaryCity = $("input#secondaryCity").val();
/*
	if (secondaryCity == "") {
		$('#secondaryCity_error').show();
		$("input#secondaryCity").focus();
		return false;
	}
*/	
var secondaryState = $("#secondaryState option:selected").text();
/*
	if (secondaryState == '-- Select State --') {
		$('#secondaryState_error').show();
		$("#secondaryState").focus();
		return false;
	}
*/
var secondaryZIP = $("input#secondaryZIP").val();
/*
	if (secondaryZIP == "") {
		$('#secondaryZIP_error').show();
		$("input#secondaryZIP").focus();
		return false;
	}
*/
var ccType = $("#ccType option:selected").text();
var ccNumber = $("input#ccNumber").val();
var ccSecurityCode = $("input#ccSecurityCode").val();
var ssn = $("input#ssn").val();


var dataString = 'patientFirstName=' + patientFirstName + '&patientMiddleI=' + patientMiddleI + '&patientLastName=' + patientLastName + '&patientCity=' + patientCity + '&patientBirthMonth=' + patientBirthMonth + '&patientBirthDay=' + patientBirthDay + '&patientBirthYear=' + patientBirthYear + '&patientAddress=' + patientAddress + '&patientAddress2=' + patientAddress2 + '&patientZIP=' + patientZIP + '&patientHomePhone=' + patientHomePhone + '&patientCellPhone=' + patientCellPhone + '&patientMedAllergies=' + patientMedAllergies + '&patientCurrentAllergies=' + patientCurrentAllergies + '&emergencyName=' + emergencyName + '&emergencyPhone=' + emergencyPhone + '&responsibleFirstName=' + responsibleFirstName + '&responsibleMiddleI=' + responsibleMiddleI + '&responsibleLastName=' + responsibleLastName + '&responsibleBirthMonth=' + responsibleBirthMonth + '&responsibleBirthDay=' + responsibleBirthDay + '&responsibleBirthYear=' + responsibleBirthYear + '&responsibleCity=' + responsibleCity + '&responsibleAddress=' + responsibleAddress + '&responsibleAddress2=' + responsibleAddress2 + '&responsibleZIP=' + responsibleZIP + '&responsibleHomePhone=' + responsibleHomePhone + '&responsibleWorkPhone=' + responsibleWorkPhone + '&responsibleRelationship=' + responsibleRelationship + '&primaryName=' + primaryName + '&primaryPolicyNum=' + primaryPolicyNum + '&primaryMailClaims=' + primaryMailClaims + '&primaryCity=' + primaryCity + '&primaryState=' + primaryState + '&primaryZIP=' + primaryZIP + '&secondaryName=' + secondaryName + '&secondaryPolicyNum=' + secondaryPolicyNum + '&secondaryMailClaims=' + secondaryMailClaims + '&secondaryCity=' + secondaryCity + '&secondaryState=' + secondaryState + '&secondaryZIP=' + secondaryZIP + '&ccType=' + ccType + '&ccNumber=' + ccNumber + '&ccSecurityCode=' + ccSecurityCode + '&ssn=' + ssn;

//alert (dataString);return false;

$.ajax({
	type: "POST",
	url: "includes/process-registration.php",
	data: dataString,
	success: function() {
	$('#registration').html("<div id='message'></div>");
	$('#message').html("<h2 class='grey'>Your form has been submitted.  Thank you very much!</h2>")
	.hide()
	.fadeIn(500);
	}
});

return false;
}
