// JavaScript Document
function changeText_tab01(){
	document.getElementById('tabText').innerHTML="For answers to commonly asked questions <a href='#'>click here</a>.";
}
function changeText_tab02(){
	document.getElementById('tabText').innerHTML="To view what others have said about us <a href='#'>click here</a>.";
}
function changeText_tab03(){
	document.getElementById('tabText').innerHTML="Check out the stories that was are making...<a href='#'>click here</a>.";
}


function resetForm()
{
	document.patientForm.reset();
}

function checkNames(object)
{
	
	myCheck = /[^A-Za-z\s]/;
	checkThisExp = myCheck.test(document.patientForm[eval(object)].value);
	if(checkThisExp)
	{
		alert("Sorry, this character is not allowed. Please refrain from using special characters.");
		theString = document.patientForm[eval(object)].value;
		charNum = theString.length;
		charNum = charNum -1;
		document.patientForm[eval(object)].value = theString.substring(0, Number(charNum));		
	}
}

function checkStreet(object)
{
	myCheck = /[^A-Za-z\s0-9\-]/;
	checkThisExp = myCheck.test(document.patientForm[eval(object)].value);
	if(checkThisExp)
	{
		alert("Sorry, this character is not allowed. Please refrain from using special characters.");
		theString = document.patientForm[eval(object)].value;
		charNum = theString.length;
		charNum = charNum -1;
		document.patientForm[eval(object)].value = theString.substring(0, Number(charNum));		
	}
}

function checkFor(object)
{
	myCheck = /\W/;
	
	checkThisExp = myCheck.test(document.patientForm[eval(object)].value);
	
	if(checkThisExp)
	{
		alert("Sorry, this character is not allowed. Please refrain from using special characters.");
		theString = document.patientForm[eval(object)].value;
		charNum = theString.length;
		charNum = charNum -1;
		document.patientForm[eval(object)].value = theString.substring(0, Number(charNum));		
	}
}

function checkForNonNumbers(object)
{
	myRe = /\D/;
	
	checkThisExp = myRe.test(document.patientForm[eval(object)].value);
	
	if(checkThisExp)
	{
		alert("Only numbers are allowed for this field.");
		theString = document.patientForm[eval(object)].value;
		charNum = theString.length;
		charNum = charNum -1;
		document.patientForm[eval(object)].value = theString.substring(0, Number(charNum));
	}
}

function checkSkip(from, to)
{
	charStr = document.patientForm[eval(from)].value;
	charCount = charStr.length;
	if(charCount=="3")
	{
		document.patientForm[eval(to)].focus();	
	}
}

function checkSpecChar(object)
{
	myCheck = /&/;
	myCheck2 = /=/;

	checkThisExp = myCheck.test(document.patientForm[eval(object)].value);
	check2ThisExp = myCheck2.test(document.patientForm[eval(object)].value);
	
	if(checkThisExp || check2ThisExp)
	{
		alert('Please refrain from using the "&" and "=" characters in this field.');
		theString = document.patientForm[eval(object)].value;
		charNum = theString.length;
		charNum = charNum -1;
		document.patientForm[eval(object)].value = theString.substring(0, Number(charNum));
	}
	
}

function autoCountry()
{
	var prov = new Array();
	prov[0] = "Alberta";
	prov[1] = "British Columbia";
	prov[2] = "Manitoba";
	prov[3] = "New Brunswick";
	prov[4] = "Newfoundland and Labrador";
	prov[5] = "Nova Scotia";
	prov[6] = "Ontario";
	prov[7] = "Prince Edward Island";
	prov[8] = "Quebec";
	prov[9] = "Saskatchewan";
	prov[10] = "Northwest Territories";
	prov[11] = "Nunavut";
	prov[12] = "Yukon";
	
	
	for(i=0; i<13; i++)
	{
		if(document.patientForm[10].value == prov[i])
		{
			document.patientForm[11].select.options[1].selected;
			//document.patientForm[11].options[1].selected;
		}
	}
}




function patientSubmit()
{
	var noBlanks = "true";
	var regExpCheck = "pass";
	
	//Regular Expressions setup
	myCheck2 = /=/;
	myCheck = /&/;
	myRe = /\D/;
	strDayPhone = document.patientForm[13].value+document.patientForm[14].value+document.patientForm[15].value;
	strContactPhone = document.patientForm[29].value+document.patientForm[30].value+document.patientForm[31].value;
	
	dayPhoneExp = myRe.test(strDayPhone);
	contactPhoneExp = myRe.test(strContactPhone);
	
	firstNameExp = myCheck.test(document.patientForm[0].value);
	secondNameExp = myCheck.test(document.patientForm[1].value);
	addressExp = myCheck.test(document.patientForm[8].value);
	cityExp = myCheck.test(document.patientForm[9].value);
	postalZipExp = myCheck.test(document.patientForm[12].value);
	emailExp = myCheck.test(document.patientForm[25].value);
	questionsExp = myCheck.test(document.patientForm[35].value);
	hearExp = myCheck.test(document.patientForm[36].value);
	
	
	firstNameExp2 = myCheck2.test(document.patientForm[0].value);
	secondNameExp2 = myCheck2.test(document.patientForm[1].value);
	addressExp2 = myCheck2.test(document.patientForm[8].value);
	cityExp2 = myCheck2.test(document.patientForm[9].value);
	postalZipExp2 = myCheck2.test(document.patientForm[12].value);
	emailExp2 = myCheck2.test(document.patientForm[25].value);
	questionsExp2 = myCheck2.test(document.patientForm[35].value);
	hearExp2 = myCheck2.test(document.patientForm[36].value);
	
	
	//Regular Expressions check for =
	if(firstNameExp2)
	{
		alert('Please do not use the "=" character in the name field');
		document.patientForm[0].focus();
		noBlanks = "false";
	}

	if(secondNameExp2)
	{
		alert('Please do not use the "=" character in the name field');
		document.patientForm[1].focus();
		noBlanks = 'false';
	}
	
	if(addressExp2)
	{
		alert('Please do not use the "=" character in the address field');
		document.patientForm[8].focus();
		noBlanks = 'false';
	}
	
	if(cityExp2)
	{
		alert('Please do not use the "=" character in the city field');
		document.patientForm[9].focus();
		noBlanks = 'false';
	}
	
	if(postalZipExp2)
	{
		alert('Please do not use the "=" character in the postal/zip code field');
		document.patientForm[12].focus();
		noBlanks = 'false';
	}
	
	if(emailExp2)
	{
		alert('Please do not use the "=" character in the email field');
		document.patientForm[25].focus();
		noBlanks = 'false';
	}
	
	if(questionsExp2)
	{
		alert('Please do not use the "=" character in the "questions and comments" field');
		document.patientForm[35].focus();
		noBlanks = 'false';
	}
	
	if(hearExp2)
	{
		alert('Please do not use the "=" character in the "How did you hear about us" field');
		document.patientForm[36].focus();
		noBlanks = 'false';
	}
	
	//Regular Expressions check for &
	if(firstNameExp)
	{
		alert('Please do not use the "&" character in the name field');
		document.patientForm[0].focus();
		noBlanks = "false";
	}

	if(secondNameExp)
	{
		alert('Please do not use the "&" character in the name field');
		document.patientForm[1].focus();
		noBlanks = 'false';
	}
	
	if(addressExp)
	{
		alert('Please do not use the "&" character in the address field');
		document.patientForm[8].focus();
		noBlanks = 'false';
	}
	
	if(cityExp)
	{
		alert('Please do not use the "&" character in the city field');
		document.patientForm[9].focus();
		noBlanks = 'false';
	}
	
	if(postalZipExp)
	{
		alert('Please do not use the "&" character in the postal/zip code field');
		document.patientForm[12].focus();
		noBlanks = 'false';
	}
	
	if(emailExp)
	{
		alert('Please do not use the "&" character in the email field');
		document.patientForm[25].focus();
		noBlanks = 'false';
	}
	
	if(questionsExp)
	{
		alert('Please do not use the "&" character in the "questions and comments" field');
		document.patientForm[35].focus();
		noBlanks = 'false';
	}
	
	if(hearExp)
	{
		alert('Please do not use the "&" character in the "How did you hear about us" field');
		document.patientForm[36].focus();
		noBlanks = 'false';
	}
	
	
	//Regular Expressions check
	/*if(dayPhoneExp=="true")
	{
		alert("Please enter a valid day-time phone number.");
		noBlanks = "false";
	}*/
	if(contactPhoneExp=="true")
	{
		alert("Please enter a valid contact phone number.");
		noBlanks = "false";
	}
	
	
	
	if(document.patientForm[0].value == "")
	{
		alert("Please enter a first name.");
		noBlanks = "false";
	}
	if(document.patientForm[1].value == "")
	{
		alert("Please enter a last name.");
		noBlanks = "false";
	}
	/*if(!document.patientForm[2].checked&&!document.patientForm[3].checked){
		alert("Please select your sex.");	
	}
	if(document.patientForm[7].value=="noAge")
	{
		alert("Please select an age.");
		noBlanks = "false";
	}
	if(document.patientForm[4].value=="Day")
	{
		alert("Please select the day of your birthday.");
		noBlanks = "false";
	}
	if(document.patientForm[5].value=="Month")
	{
		alert("Please enter the month of your birthday.");
		noBlanks = "false";
	}
	if(document.patientForm[6].value=="Year")
	{
		alert("Please enter the year of your birthday.");
		noBlanks = "false";
	}
	if(document.patientForm[8].value=="")
	{
		alert("Please enter a street address.");
		noBlanks = "false";
	}
	if(document.patientForm[9].value=="")
	{
		alert("Please enter a city.");
		noBlanks = "false";
	}
	if(document.patientForm[10].value=="NoState")
	{
		alert("Please enter a province or state.");
		noBlanks = "false";
	}
	if(document.patientForm[11].value=="NoCountry")
	{
		alert("Please enter a country.");
		noBlanks = "false";
	}
	if(document.patientForm[12].value=="")
	{
		alert("Please enter a postal/zip code");
		noBlanks = "false";
	}
	if(document.patientForm[13].value==""||document.patientForm[14].value==""||document.patientForm[15].value=="")
	{
		alert("Please enter a day phone.");
		document.patientForm[13].focus();
		noBlanks = "false";
	}*/
		if(document.patientForm[25].value=="")
	{
		alert("Please enter an email address.");
		noBlanks = "false";
	}
	if(document.patientForm[25].value!=document.patientForm[26].value)
	{
		alert("There was an error confirming your email address. Please re-enter your email address.");
		document.patientForm[25].value = '';
		document.patientForm[26].value = '';
		document.patientForm[25].focus();
		noBlanks = "false";
	}/*
	
	if(document.patientForm[27].value=="noDOTW")
	{
		alert("Please enter the best day of the week to contact you.");
	}
	if(document.patientForm[28].value=="noTime")
	{
		alert("Please enter the best time of the day to contact you.");
	}*/
	if(document.patientForm[29].value==""||document.patientForm[30].value==""||document.patientForm[31].value=="")
	{
		alert("Please enter your contact number.");
		document.patientForm[29].focus();
		noBlanks = "false";
	}
	
	if(!document.patientForm[37].checked)
	{
		alert("You must accept our terms and conditions in order to continue.");	
		document.patientForm[37].focus();
		noBlanks = "false";
	}
	
	
	if(noBlanks == "true")
	{
		document.patientForm.submit();
	}
}

function doItAge()
{
	var flag = "";
	if(document.getElementById("day").selectedIndex == 0 || document.getElementById("month").selectedIndex == 0 || document.getElementById("year").selectedIndex == 0)
	{
		flag = "no";
	}
	else
	{
		flag = "yes";	
	}
	if(flag == "yes")
	{
		var addAge = 0;
		currentDate = new Date();
		date = currentDate.getDate();
		month = currentDate.getMonth() + 1;
		year = currentDate.getFullYear();
		
		xYear = document.getElementById("year").value;
		xMonth	= document.getElementById("month").selectedIndex;
		xDate = document.getElementById("day").value;
		
		
		if(xMonth < month)
		{
			
			addAge = addAge+1;
		}
		else if(xMonth > month)
		{
			
			addAge = addAge+0;
		}
		else if(xMonth == month)
		{
			
			if(xDate < date)
			{
				addAge = addAge+1;	
			}
			else if(xDate > date)
			{
				addAge = addAge+0;	
			}
			else if(xDate == date)
			{
				addAge = addAge+1;	
			}
			
		}
		var age = (2007-xYear)+addAge;
		
		document.getElementById("info_age").selectedIndex = age-1;
	}
}


function thoughtsSubmit()
{
	var noBlanks = "true";
	
	if(document.thoughtsForm[0].value == "")
	{
		alert("Please enter a name.");
		noBlanks = "false";
	}
	if(document.thoughtsForm[7].value == "")
	{
		alert("Please enter a message.");
		noBlanks = "false";
	}
	if(noBlanks == "true")
	{
		document.thoughtsForm.submit();
	}
}

function testMe()
{
	if(document.patientForm[37].checked)
	{
		alert("yes");	
	}
	else
	{
		alert("no");	
	}
}
