// JavaScript Document

//Load important images first
cssFile = new Image();
cssFile.src = "css/style.css";

aboutHeader = new Image(); 
aboutHeader.src="images/headerBgAbout.png";
doctorsHeader = new Image(); 
doctorsHeader.src="images/headerBgDoctors.png";
billPayHeader = new Image(); 
billPayHeader.src="images/headerBgBillPay.png";
FaqHeader = new Image(); 
FaqHeader.src="images/headerBgFAQ.png";
contactHeader = new Image(); 
contactHeader.src="images/headerBgContact.png";

//Main site nav
function homeOver() {
	document.getElementById("navHome").src="images/homeOver.png";
}
function homeOut() {
	document.getElementById("navHome").src="images/homeOut.png";
}
function aboutOver() {
	document.getElementById("navAbout").src="images/aboutOver.png";
}
function aboutOut() {
	document.getElementById("navAbout").src="images/aboutOut.png";
}
function meetOver() {
	document.getElementById("navMeet").src="images/meetOver.png";
}
function meetOut() {
	document.getElementById("navMeet").src="images/meetOut.png";
}
function billpayOver() {
	document.getElementById("navBillpay").src="images/billpayOver.png";
}
function billpayOut() {
	document.getElementById("navBillpay").src="images/billpayOut.png";
}
function formsOver() {
	document.getElementById("navForms").src="images/formsOver.png";
}
function formsOut() {
	document.getElementById("navForms").src="images/formsOut.png";
}
function faqOver() {
	document.getElementById("navFaq").src="images/faqOver.png";
}
function faqOut() {
	document.getElementById("navFaq").src="images/faqOut.png";
}
function contactOver() {
	document.getElementById("navContact").src="images/contactOver.png";
}
function contactOut() {
	document.getElementById("navContact").src="images/contactOut.png";
}

//CMS nav
function cmsHomeOver() {
	document.getElementById("cmsHome").src="images/home-over.png";
}
function cmsHomeOut() {
	document.getElementById("cmsHome").src="images/home-out.png";
}
function cmsPatientsOver() {
	document.getElementById("cmsPatients").src="images/patients-over.png";
}
function cmsPatientsOut() {
	document.getElementById("cmsPatients").src="images/patients-out.png";
}
function cmsViewOver() {
	document.getElementById("cmsView").src="images/view-over.png";
}
function cmsViewOut() {
	document.getElementById("cmsView").src="images/view-out.png";
}
function cmsEditOver() {
	document.getElementById("cmsEdit").src="images/edit-over.png";
}
function cmsEditOut() {
	document.getElementById("cmsEdit").src="images/edit-out.png";
}
function cmsContactsOver() {
	document.getElementById("cmsContacts").src="images/contacts-over.png";
}
function cmsContactsOut() {
	document.getElementById("cmsContacts").src="images/contacts-out.png";
}
function cmsPasswordOver() {
	document.getElementById("cmsPassword").src="images/password-over.png";
}
function cmsPasswordOut() {
	document.getElementById("cmsPassword").src="images/password-out.png";
}
function cmsLogoutOver() {
	document.getElementById("cmsLogout").src="images/logout-over.png";
}
function cmsLogoutOut() {
	document.getElementById("cmsLogout").src="images/logout-out.png";
}
function cmsHelpOver() {
	document.getElementById("cmsHelp").src="images/help-over.png";
}
function cmsHelpOut() {
	document.getElementById("cmsHelp").src="images/help-out.png";
}

//CLEAR THE LOGIN FORMS WHEN CLICKED
function clearName() {
	if(document.loginForm.topUsername.value == "User Name"){
		document.loginForm.topUsername.value = "";
	}
}
function returnName() {
	if(document.loginForm.topUsername.value == ""){
		document.loginForm.topUsername.value = "User Name";
	}
}
function clearPass() {
	if(document.loginForm.topPassword.value == "password"){
		document.loginForm.topPassword.value = "";
	}
}
function returnPass() {
	if(document.loginForm.topPassword.value == ""){
		document.loginForm.topPassword.value = "password";
	}
}

/*---------------------------------------------------------------------------------------
FORM VALIDATION
---------------------------------------------------------------------------------------*/
function eCheck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
		alert("You entered an invalid email address.");
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("You entered an invalid email address.");
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("You entered an invalid email address.");
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1){
		alert("You entered an invalid email address.");
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("You entered an invalid email address.");
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert("You entered an invalid email address.");
		return false;
	}
		
	if (str.indexOf(" ")!=-1){
		alert("You entered an invalid email address.");
		return false;
	}

	return true;					
}

function validateForm(){
	var firstID=document.signUpForm.firstName;
	if ((firstID.value==null)||(firstID.value=="")){
		alert("Please enter your first name.");
		firstID.focus();
		return false;
	}	
	
	var lastID=document.signUpForm.lastName;
	if ((lastID.value==null)||(lastID.value=="")){
		alert("Please enter your last name.");
		lastID.focus();
		return false;
	}	
	
	var addressID=document.signUpForm.address;
	if ((addressID.value==null)||(addressID.value=="")){
		alert("Please enter your address.");
		addressID.focus();
		return false;
	}	
	
	var phoneID=document.signUpForm.phone;
	if ((phoneID.value==null)||(phoneID.value=="")){
		alert("Please enter your phone number.");
		phoneID.focus();
		return false;
	}
	
	var socialID=document.signUpForm.social;
	if ((socialID.value==null)||(socialID.value=="")){
		alert("Please enter your SSN.");
		socialID.focus();
		return false;
	}
	
	var emailID=document.signUpForm.email;
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please enter your email address.");
		emailID.focus();
		return false;
	}
	
	var passwordID=document.signUpForm.password;
	if ((passwordID.value==null)||(passwordID.value=="")){
		alert("Please assign an account password.");
		passwordID.focus();
		return false;
	}
	
	if (eCheck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	
return true;
}


function validatePayment(){
	var nameID=document.payForm.cardName;
	if ((nameID.value==null)||(nameID.value=="")){
		alert("Please enter your name as it appears on your card.");
		nameID.focus();
		return false;
	}	
	
	var typeID=document.payForm.cardType;
	if ((typeID.value==null)||(typeID.value=="")){
		alert("Please enter the type of card you are using.");
		typeID.focus();
		return false;
	}	
	
	var numberID=document.payForm.cardNumber;
	if ((numberID.value==null)||(numberID.value=="")){
		alert("Please enter your card number.");
		numberID.focus();
		return false;
	}	
	
	var expireID=document.payForm.cardExpire;
	if ((expireID.value==null)||(expireID.value=="")){
		alert("Please enter the expiration date on your card.");
		expireID.focus();
		return false;
	}
	
	var zipID=document.payForm.billingZip;
	if ((zipID.value==null)||(zipID.value=="")){
		alert("Please enter your billing zip code.");
		zipID.focus();
		return false;
	}
	
	var amountID=document.payForm.amountPaid;
	if ((amountID.value==null)||(amountID.value=="")){
		alert("Please enter the amount you would like to pay.");
		amountID.focus();
		return false;
	}
			
return true;
}