// JavaScript Document
var a = null;
var b = null;
var height = null;

function loginToggle()

{
	  //Get a reference to the link on the page
	  // with an id of "mylink"
	  var a = document.getElementById("login");

	  //Set code to run when the link is clicked
	  // by assigning a function to "onclick"
		// Your code here...
		if(a.style.display == 'inline')

		{
			document.getElementById('loginInputEmail').value = '';
			document.getElementById('loginInputPassword').value = '';
			a.style.display = 'none';
		}
		else
		{
			a.style.display = 'inline';
		}
}

function animate()
{
	height = parseInt(b.style.height);
	b.style.height = parseInt(b.style.height)+10+'px';
	if(height < 150)
	{
		setTimeout(animate, 20);
	}
}

function init()
{
	b = document.getElementById("loginForm");
	b.style.height = '0px';
	animate();
}

function loginClear()
{
	document.getElementById('invalidEmail').style.display = 'none';
	document.getElementById('invalidPassword').style.display = 'none';
}

function showLogin()
{
	loginToggle();
	init();
	loginClear();
}

function isValidEmail(sEmail)
{
	var toReturn = true;
	
	var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
	var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
	var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
	var sQuotedPair = '\\x5c[\\x00-\\x7f]';
	var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
	var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
	var sDomain_ref = sAtom;
	var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
	var sWord = '(' + sAtom + '|' + sQuotedString + ')';
	var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
	var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
	var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
	var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
	
	var reValidEmail = new RegExp(sValidEmail);
	
	if (reValidEmail.test(sEmail))
	{
		//return true;
		toReturn = true;
	}
	else
	{
		toReturn = false;
	}
	return toReturn;
}

function checkLoginFields(emailField, passwordField)
{
	var loginVal = true;
	var email = emailField.value;
	var password = passwordField.value;
	if (!isValidEmail(email))
	{
		document.getElementById('invalidEmail').style.display = 'inline';
		document.getElementById('loginInputEmail').value = '';
		loginVal = false;
	}
	else
	{
		document.getElementById('invalidEmail').style.display = 'none';
	}
	if ((password.length < 6)||(password.length > 20))
	{
		document.getElementById('invalidPassword').style.display = 'inline';
		document.getElementById('loginInputPassword').value = '';
		loginVal = false;
	}
	else if ((password.length >= 6)&&(password.length <= 20))
	{
		document.getElementById('invalidPassword').style.display = 'none';
	}
	return loginVal;
}

function checkRegistrationFields(email, emailConfirm, password, confirmPassword)
{
	var submitRegistration = true;
	var emailReg = email.value;
	var emailConfirmReg = emailConfirm.value;
	var passwordReg = password.value;
	var passwordRegConfirm = confirmPassword.value;
	
	if(!isValidEmail(emailReg))
	{
		email.value = '';
		document.getElementById('regInvalidEmail').style.display = 'inline';
		submitRegistration = false;
	}
	else
	{
		document.getElementById('regInvalidEmail').style.display = 'none';
		
		if(emailConfirmReg != emailReg)
		{
			document.getElementById('regConfirmEmail').style.display = 'inline';
			emailConfirm.value = '';
			submitRegistration = false;
		}
		else
		{
			document.getElementById('regConfirmEmail').style.display = 'none';
		}
	}
	
	if((passwordReg.length < 6)||(passwordReg.length > 20))
	{
		document.getElementById('regInvalidPassword').style.display = 'inline';
		document.getElementById('regPassword').value = '';
		submitRegistration = false;
	}
	else if ((passwordReg.length >= 6)&&(passwordReg.length <= 20))
	{
		document.getElementById('regInvalidPassword').style.display = 'none';
		
		if(passwordReg != passwordRegConfirm)
		{
			document.getElementById('passwordConfirmInvalid').style.display = 'inline';
			document.getElementById('regConfirmPassword').value = '';
			submitRegistration = false;
		}
		else
		{
			document.getElementById('passwordConfirmInvalid').style.display = 'none';
		}
	}
	
	return submitRegistration;
}

//Trim function
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//remove all whitespace function
function removeSpaces(string)
{
	return string.split(' ').join('');
}

function checkEditProfileFields(firstName, lastName, title, street, city, state, zip, phoneArea, phonePre, phoneSuffix, faxArea, faxPre, faxSuffix, cellArea, cellPre, cellSuffix, email)
{
	var editFirstName = trim(firstName.value);
	var editLastName = trim(lastName.value);
	var editTitle = trim(title.value);
	var editStreet = trim(street.value);
	var editCity = trim(city.value);
	var editState = trim(state.value);
	var editZip = trim(zip.value);
	var editPhoneArea = trim(phoneArea.value);
	var editPhonePre = trim(phonePre.value);
	var editPhoneSuffix = trim(phoneSuffix.value);
	var editFaxArea = trim(faxArea.value);
	var editFaxPre = trim(faxPre.value);
	var editFaxSuffix = trim(faxSuffix.value);
	var editCellArea = trim(cellArea.value);
	var editCellPre = trim(cellPre.value);
	var editCellSuffix = trim(cellSuffix.value);
	var editEmail = trim(email.value);
	// reg expression to check if all letters
	var alphaExp = /^[a-zA-Z]+$/;
	// reg expression to check if all numbers
	var numExp = /^[0-9]+$/;
	
	//initiate variable to set submit button to true
	var submitEdit = true;
	
	/*
	
	FIRST NAME VALIDATION
	
	*/
	//check if first name field is empty
	if(editFirstName.length == 0)
	{
		//turn on error message for first name field
		
		//if empty do not submit
		submitEdit = false;
	}
	else
	{
		//check if all characters are letters
		if(!(removeSpaces(editFirstName).match(alphaExp)))
		{
			//if not all letters turn on error message for first name field
			
			//if not all letters do not submit
			submitEdit = false;
		}
		//check that the total number of characters is less than or equal to 25
		else
		{
			if(editFirstName.length > 25)
			{
				//show error message for invalid first name field
				
				//if more than 25 characters do not submit form
				submitEdit = false;
			}
		}
	}
	
	/*
	
	LAST NAME VALIDATION
	
	*/
	//check if field is empty
	if(editLastName.length == 0)
	{
		//turn on error message
		
		//if empty do not submit
		submitEdit = false;
	}
	else
	{
		//check if all characters are letters
		if(!(removeSpaces(editLastName).match(alphaExp)))
		{
			//if not all letters turn on error message
			
			//if not all letters do not submit
			submitEdit = false;
		}
		//check that the total number of characters is less than or equal to 25
		else
		{
			if(editLastName.length > 25)
			{
				//show error message for invalid
				
				//if more than 25 characters do not submit form
				submitEdit = false;
			}
		}
	}
	
	/*
	
	TITLE VALIDATION
	
	*/
	//check if field is empty
	if(editTitle.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if too many characters
		if(editTitle.length > 50)
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
	}
	
	/*
	
	STREET VALIDATION
	
	*/
	//check if field is empty
	if(editStreet.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if too many characters
		if(editStreet.length > 40)
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
	}
	
	/*
	
	CITY VALIDATION
	
	*/
	//check if field is empty
	if(editCity.length == 0)
	{
		//turn on error message
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all letters
		if(!(removeSpaces(editCity).match(alphaExp)))
		{
			//if not all letters turn on error message
			//if not all letters do not submit
			submitEdit = false;
		}
		else
		{
			//check if not too many characters
			if(editCity.length > 30)
			{
				//turn on error message
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	STATE VALIDATION
	
	*/
	//check if empty
	if(editState.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all letters
		if(!(editState.match(alphaExp)))
		{
			//turn on error message
			
			//if not all letters do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editState.length != 2)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
			else
			{
				//check value against all possible states
				if((editState.toUpperCase() != "AL")&&(editState.toUpperCase() != "AK")&&(editState.toUpperCase() != "AZ")&&(editState.toUpperCase() != "AR")&&(editState.toUpperCase() != "CA")&&(editState.toUpperCase() != "CO")&&(editState.toUpperCase() != "CT")&&(editState.toUpperCase() != "DE")&&(editState.toUpperCase() != "DC")&&(editState.toUpperCase() != "FL")&&(editState.toUpperCase() != "GA")&&(editState.toUpperCase() != "HI")&&(editState.toUpperCase() != "ID")&&(editState.toUpperCase() != "IL")&&(editState.toUpperCase() != "IN")&&(editState.toUpperCase() != "IA")&&(editState.toUpperCase() != "KS")&&(editState.toUpperCase() != "KY")&&(editState.toUpperCase() != "LA")&&(editState.toUpperCase() != "ME")&&(editState.toUpperCase() != "MD")&&(editState.toUpperCase() != "MA")&&(editState.toUpperCase() != "MI")&&(editState.toUpperCase() != "MN")&&(editState.toUpperCase() != "MS")&&(editState.toUpperCase() != "MO")&&(editState.toUpperCase() != "MT")&&(editState.toUpperCase() != "NE")&&(editState.toUpperCase() != "NV")&&(editState.toUpperCase() != "NH")&&(editState.toUpperCase() != "NJ")&&(editState.toUpperCase() != "NM")&&(editState.toUpperCase() != "NY")&&(editState.toUpperCase() != "NC")&&(editState.toUpperCase() != "ND")&&(editState.toUpperCase() != "OH")&&(editState.toUpperCase() != "OK")&&(editState.toUpperCase() != "OR")&&(editState.toUpperCase() != "PA")&&(editState.toUpperCase() != "RI")&&(editState.toUpperCase() != "SC")&&(editState.toUpperCase() != "SD")&&(editState.toUpperCase() != "TN")&&(editState.toUpperCase() != "TX")&&(editState.toUpperCase() != "UT")&&(editState.toUpperCase() != "VT")&&(editState.toUpperCase() != "VA")&&(editState.toUpperCase() != "WA")&&(editState.toUpperCase() != "WV")&&(editState.toUpperCase() != "WI")&&(editState.toUpperCase() != "WY"))
				{
					//turn on error message
					
					//do not submit
					submitEdit = false;
				}
			}
		}
	}
	
	/*
	
	ZIP CODE VALIDATION
	
	*/
	//check if empty
	if(editZip.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editZip.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if not too many characters
			if(editZip.length > 5)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	PHONE AREA CODE VALIDATION
	
	*/
	//check if empty
	if(editPhoneArea.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editPhoneArea.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editPhoneArea.length != 3)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	PHONE PREFIX VALIDATION
	
	*/
	//check if empty
	if(editPhonePre.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editPhonePre.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editPhonePre.length != 3)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	PHONE SUFFIX VALIDATION
	
	*/
	//check if empty
	if(editPhoneSuffix.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editPhoneSuffix.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editPhoneSuffix.length != 4)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	FAX AREA CODE VALIDATION
	
	*/
	//check if empty
	if(editFaxArea.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editFaxArea.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editFaxArea.length != 3)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	FAX PREFIX VALIDATION
	
	*/
	//check if empty
	if(editFaxPre.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editFaxPre.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editFaxPre.length != 3)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	FAX SUFFIX VALIDATION
	
	*/
	//check if empty
	if(editFaxSuffix.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editFaxSuffix.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editFaxSuffix.length != 4)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}

	/*
	
	CELL AREA CODE VALIDATION
	
	*/
	//check if empty
	if(editCellArea.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editCellArea.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editCellArea.length != 3)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	CELL PREFIX VALIDATION
	
	*/
	//check if empty
	if(editCellPre.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editCellPre.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editCellPre.length != 3)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	CELL SUFFIX VALIDATION
	
	*/
	//check if empty
	if(editCellSuffix.length == 0)
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}
	else
	{
		//check if all numbers
		if(!(editCellSuffix.match(numExp)))
		{
			//turn on error message
			
			//do not submit
			submitEdit = false;
		}
		else
		{
			//check if too many characters
			if(editCellSuffix.length != 4)
			{
				//turn on error message
				
				//do not submit
				submitEdit = false;
			}
		}
	}
	
	/*
	
	EMAIL VALIDATION
	
	*/
	//check if email is valid
	if(!isValidEmail(editEmail))
	{
		//turn on error message
		
		//do not submit
		submitEdit = false;
	}

	return submitEdit;
}

function eventUploadOption(radioOption)
{
	var radioChoice = radioOption.value;
	
	if(radioChoice == "yes")
	{
		document.getElementById('addEventFile').disabled = false;
	}
	else
	{
		if(radioChoice == "no")
		{
			document.getElementById('addEventFile').disabled = true;
			document.getElementById('addEventFile').value = '';
		}
	}
}

function eventOptionRSVP(rsvpOption)
{
	var rsvpChoice = rsvpOption.value;
	
	if(rsvpChoice == "yes")
	{
		document.getElementById('addEventMonthRSVP').disabled = false;
		document.getElementById('addEventDayRSVP').disabled = false;
		document.getElementById('addEventYearRSVP').disabled = false;
	}
	else
	{
		if(rsvpChoice == "no")
		{
			document.getElementById('addEventMonthRSVP').disabled = true;
			document.getElementById('addEventDayRSVP').disabled = true;
			document.getElementById('addEventYearRSVP').disabled = true;
		}
	}
}

function eventOptionFee(feeOption)
{
	var feeChoice = feeOption.value;
	
	if(feeChoice == "yes")
	{
		document.getElementById('addEventFeeDollar').disabled = false;
		document.getElementById('addEventFeeCents').disabled = false;
	}
	else
	{
		if(feeChoice == "no")
		{
			document.getElementById('addEventFeeDollar').disabled = true;
			document.getElementById('addEventFeeCents').disabled = true;
		}
	}
}

function addEvent()
{
	var eventType
	var eventName
	var eventLocation
	var eventStreet
	var eventCity
	var eventState
	var eventZip
	var eventMonth
	var eventDay
	var eventYear
	var eventStartHour
	var eventStartMinute
	var eventStartAMPM
	var eventEndHour
	var eventEndMinute
	var eventEndAMPM
	var eventRSVP
	var eventMonthRSVP
	var eventDayRSVP
	var eventYearRSVP
	var eventUploadOption
	var eventUploadFile
}

function title(title)
{
	var alphaNumeric = /^[a-zA-Z0-9]+$/;
	var validTitle = true;
	var titleTrimmed = title.replace(/[^\w\s\.\&\-\,\(\)]/gi, '');
	
	if(title.length == 0)
	{
		validTitle = false;
	}
	else
	{
		if(titleTrimmed.length != title.length)
		{
			validTitle = false;
		}
	}
	return validTitle;
}

function agency(agency)
{
	var checkAlpha = /^[a-z\(.)\(,)\-]+$/gi;
	var validAgency = true;
	var agencyTrimmed = agency.replace(/[^a-z\(.)\(,)\-\s]/gi, '');
	
	if(agency.length == 0)
	{
		validAgency = false;
	}
	else
	{
		if(agencyTrimmed.length != agency.length)
		{
			validAgency = false;
		}
	}
	return validAgency;
}

function salary(salaryMin, salaryMax)
{
	var validSalary = true;
	
	//check if all empty
	if((salaryMin != '')||(salaryMax != ''))
	{
		//if not all empty, check if all have values
		if((salaryMin == '')||(salaryMax == ''))
		{
			//invalid
			validSalary = false;
		}
		else
		{
			if((!salaryMin.match(/^[0-9]+(\.[0-9]{2,2})$/gi))||(!salaryMax.match(/^[0-9]+(\.[0-9]{2,2})$/gi)))
			{
				validSalary = false;
			}
			if(salaryMin > salaryMax)
			{
				validSalary = false;
			}
		}
	}
	
	return validSalary;
}

function frequency(salaryMin, salaryMax, salaryFrequency)
{
	var validFrequency = true;
	
	if((salaryMin != '')||(salaryMax != ''))
	{
		if(salaryFrequency == 'none')
		{
			validFrequency = false;
		}
	}
	else if((salaryMin == '')&&(salaryMax == ''))
	{
		if(salaryFrequency != 'none')
		{
			validFrequency = false;
		}
	}
	
	return validFrequency;
}

function description(description)
{
	var validDescription = true;
	var descriptionTrimmed = description.replace(/[^\w\s]/gi, '');
	
	if(descriptionTrimmed.length == 0)
	{
		validDescription = false;
	}
	
	return validDescription;
}

function deadline(month, day, year)
{
	var validDate = true;
	
	//replace preceeding 0 in month if entered (example "08" becomes "8")
	month = month.replace(/[^1-9]/gi, '');
	//replace preceeding 0 in day if entered (example "03" becomes "3")
	day = day.replace(/[^1-9]/gi, '');
	var dateFull = String(year) + String(month) + String(day);
	var dateTrimmed = dateFull.replace(/[^0-9]/gi, '');
	
	var currentMonth = new Date().getMonth();
	currentMonth = currentMonth + 1;
	var currentDay = new Date().getUTCDate();
	var currentYear = new Date().getFullYear();
	
	var dateFullCurrent = String(currentYear) + String(currentMonth) + String(currentDay);	
	
	if(dateTrimmed.length != dateFull.length)
	{
		validDate = false;
	}
	if((month.length > 2)||(month.length < 1))
	{
		validDate = false;
	}
	if((day.length > 2)||(day.length < 1))
	{
		validDate = false;
	}
	if(year.length != 4)
	{
		validDate = false;
	}
	if((month < 1)||(month > 12))
	{
		validDate = false;
	}
	//check for too many days in February
	if((month == 2)&&(day > 28))
	{
		validDate = false;
	}
	else if(day > 31)
	{
		validDate = false;
	}
	//check if deadline entered is prior to todays date
	if(dateFull <= dateFullCurrent)
	{
		validDate = false;
	}
	
	return validDate;
}

function url(url)
{
	var validURL = true;
	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
	
	if(!regexp.test(url))
	{
		validURL = false;
	}
	
	return validURL;
}

function nameString(stringVal)
{
	var validString = true;
	var stringTrimmed = stringVal.replace(/[^a-z\s]/gi, '');
	
	if(stringTrimmed.length == 0)
	{
		validString = false;
	}
	else if(stringVal.length != stringTrimmed.length)
	{
		validString = false;
	}
	if(stringTrimmed.length > 25)
	{
		validString = false;
	}
	
	return validString;
}

function telephoneValid(phoneComplete)
{
	var validPhone = true;
	var numberTrimmed = phoneComplete.replace(/[^0-9]/, '');
	
	if(phoneComplete.length != numberTrimmed.length)
	{
		validPhone = false;
	}
	
	return validPhone;
}

function careerForm()
{
	//All called functions defined directly above this function
	
	var careerTitle = document.getElementById('title').value;
	var careerAgency = document.getElementById('agency').value;
	var careerSalaryMin = document.getElementById('salaryMin').value;
	var careerSalaryMax = document.getElementById('salaryMax').value;
	var careerSalaryFrequency = document.getElementById('salaryFrequency').value;
	var careerDescription = document.getElementById('careerDescription').value;
	var careerDeadlineMonth = document.getElementById('deadlineMonth').value;
	var careerDeadlineDay = document.getElementById('deadlineDay').value;
	var careerDeadlineYear = document.getElementById('deadlineYear').value;
	var careerLink = document.getElementById('infoLinkURL').value;
	var careerContactFirst = document.getElementById('contactFirst').value;
	var careerContactLast = document.getElementById('contactLast').value;
	var careerEmail = document.getElementById('contactEmail').value;
	var phoneArea = document.getElementById('profileEditPhoneArea').value;
	var phonePre = document.getElementById('profileEditPhonePre').value;
	var phoneSuffix = document.getElementById('profileEditPhoneSuffix').value;
	var phoneComplete = String(phoneArea) + String(phonePre) + String(phoneSuffix);
	var faxArea = document.getElementById('profileEditFaxArea').value;
	var faxPre = document.getElementById('profileEditFaxPre').value;
	var faxSuffix = document.getElementById('profileEditFaxSuffix').value;
	var faxComplete = String(faxArea) + String(faxPre) + String(faxSuffix);
	
	var returnValue = true;
	
	//call title validation
	if(!title(careerTitle))
	{
		returnValue = false;
		document.getElementById('invalidTitle').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidTitle').style.display = 'none';
	}
	
	//call agency validation
	if(!agency(careerAgency))
	{
		returnValue = false;
		document.getElementById('invalidAgency').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidAgency').style.display = 'none';
	}
	
	//call salary validation
	if(!salary(careerSalaryMin, careerSalaryMax, careerSalaryFrequency))
	{
		returnValue = false;
		document.getElementById('invalidSalary').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidSalary').style.display = 'none';
	}
	
	//call salary frequency validation
	if(!frequency(careerSalaryMin, careerSalaryMax, careerSalaryFrequency))
	{
		returnValue = false;
		document.getElementById('invalidFrequency').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidFrequency').style.display = 'none';
	}
	
	//call description validation
	if(!description(careerDescription))
	{
		returnValue = false;
		document.getElementById('invalidDescription').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidDescription').style.display = 'none';
	}
	
	//call deadline date validation
	if(!deadline(careerDeadlineMonth, careerDeadlineDay, careerDeadlineYear))
	{
		returnValue = false;
		document.getElementById('invalidDeadline').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidDeadline').style.display = 'none';
	}
	
	//call url validation
	if(!url(careerLink))
	{
		returnValue = false;
		document.getElementById('invalidLink').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidLink').style.display = 'none';
	}
	
	//if not empty, call string function
	if(careerContactFirst.length != 0)
	{
		if(!nameString(careerContactFirst))
		{
			returnValue = false;
			document.getElementById('invalidFirstName').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidFirstName').style.display = 'none';
		}
	}
	else
	{
		document.getElementById('invalidFirstName').style.display = 'none';
	}
	
	//call contact last name validation
	if(careerContactLast.length != 0)
	{
		if(!nameString(careerContactLast))
		{
			returnValue = false;
			document.getElementById('invalidLastName').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidLastName').style.display = 'none';
		}
	}
	else
	{
		document.getElementById('invalidLastName').style.display = 'none';
	}
	
	//check if email is empty, empty is ok
	if(careerEmail.length != 0)
	{
		//if email is not empty, call function to check validity
		if(!isValidEmail(careerEmail))
		{
			returnValue = false;
			document.getElementById('invalidEmail').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidEmail').style.display = 'none';
		}
	}
	else
	{
		document.getElementById('invalidEmail').style.display = 'none';
	}
	
	//if phone number is empty, do nothing
	if(phoneComplete.length != 0)
	{
		//if phone number not empty, it must be 10 digits
		if(phoneComplete.length != 10)
		{
			returnValue = false;
			document.getElementById('invalidPhone').style.display = 'inline';
		}
		//if not empty and 10 digits long, call phone validation
		else
		{
			if(!telephoneValid(phoneComplete))
			{
				returnValue = false;
				document.getElementById('invalidPhone').style.display = 'inline';
			}
			else
			{
				document.getElementById('invalidPhone').style.display = 'none';
			}
		}
		
	}
	else
	{
		document.getElementById('invalidPhone').style.display = 'none';
	}
	
	//if fax number is empty, do nothing
	if(faxComplete.length != 0)
	{
		//if phone number not empty, it must be 10 digits
		if(faxComplete.length != 10)
		{
			returnValue = false;
			document.getElementById('invalidFax').style.display = 'inline';
		}
		//if not empty and 10 digits long, call phone validation
		else
		{
			if(!telephoneValid(faxComplete))
			{
				returnValue = false;
				document.getElementById('invalidFax').style.display = 'inline';
			}
			else
			{
				document.getElementById('invalidFax').style.display = 'none';
			}
		}
		
	}
	else
	{
		document.getElementById('invalidFax').style.display = 'none';
	}
	

	return returnValue;
}

function whatsThis(w)
{
	  //Get a reference to the link on the page
	  // with an id of "mylink"
	  var w = document.getElementById(w);

	  //Set code to run when the link is clicked
	  // by assigning a function to "onclick"
		// Your code here...
		if(w.style.display == 'block')
		{
			w.style.display = 'none';
		}
		else
		{
			w.style.display = 'block';
		}
}

function memberTypeValid(memberType)
{
	var typeValid = true;
	
	if((memberType != 'agency')&&(memberType != 'vendor')&&(memberType != 'lifetime'))
	{
		typeValid = false;
	}
	
	return typeValid;
}

function streetValid(street)
{
	var validStreet = true;
	var regexp = /^[0-9\d]+(([\'\,\.\- #][a-zA-Z\d ])?[a-zA-Z\d]*[\.]*)*$/;
	
	if(!regexp.test(street))
	{
		validStreet = false;
	}
	
	return validStreet;
}

function stateValid(editState)
{
	var validState = true;
	
	if((editState.toUpperCase() != "AL")&&(editState.toUpperCase() != "AK")&&(editState.toUpperCase() != "AZ")&&(editState.toUpperCase() != "AR")&&(editState.toUpperCase() != "CA")&&(editState.toUpperCase() != "CO")&&(editState.toUpperCase() != "CT")&&(editState.toUpperCase() != "DE")&&(editState.toUpperCase() != "DC")&&(editState.toUpperCase() != "FL")&&(editState.toUpperCase() != "GA")&&(editState.toUpperCase() != "HI")&&(editState.toUpperCase() != "ID")&&(editState.toUpperCase() != "IL")&&(editState.toUpperCase() != "IN")&&(editState.toUpperCase() != "IA")&&(editState.toUpperCase() != "KS")&&(editState.toUpperCase() != "KY")&&(editState.toUpperCase() != "LA")&&(editState.toUpperCase() != "ME")&&(editState.toUpperCase() != "MD")&&(editState.toUpperCase() != "MA")&&(editState.toUpperCase() != "MI")&&(editState.toUpperCase() != "MN")&&(editState.toUpperCase() != "MS")&&(editState.toUpperCase() != "MO")&&(editState.toUpperCase() != "MT")&&(editState.toUpperCase() != "NE")&&(editState.toUpperCase() != "NV")&&(editState.toUpperCase() != "NH")&&(editState.toUpperCase() != "NJ")&&(editState.toUpperCase() != "NM")&&(editState.toUpperCase() != "NY")&&(editState.toUpperCase() != "NC")&&(editState.toUpperCase() != "ND")&&(editState.toUpperCase() != "OH")&&(editState.toUpperCase() != "OK")&&(editState.toUpperCase() != "OR")&&(editState.toUpperCase() != "PA")&&(editState.toUpperCase() != "RI")&&(editState.toUpperCase() != "SC")&&(editState.toUpperCase() != "SD")&&(editState.toUpperCase() != "TN")&&(editState.toUpperCase() != "TX")&&(editState.toUpperCase() != "UT")&&(editState.toUpperCase() != "VT")&&(editState.toUpperCase() != "VA")&&(editState.toUpperCase() != "WA")&&(editState.toUpperCase() != "WV")&&(editState.toUpperCase() != "WI")&&(editState.toUpperCase() != "WY"))
	{
		validState = false;
	}
	
	return validState;
}

function zipValid(zip)
{
	var validZip = true;
	var zipTrimmed = zip.replace(/[^0-9]/, '');
	
	if(zipTrimmed.length != 5)
	{
		validZip = false;
	}
	
	return validZip;
}

function membershipApp()
{
	var appMemberType = document.getElementById('memberType').value;
	var appNameFirst = document.getElementById('appNameFirst').value;
	var appNameLast = document.getElementById('appNameLast').value;
	var appTitle = document.getElementById('appTitle').value;
	var appAgency = document.getElementById('appAgency').value;
	var appStreet = document.getElementById('appStreet').value;
	var appCity = document.getElementById('appCity').value;
	var appState = document.getElementById('appState').value;
	var appZip = document.getElementById('appZip').value;
	var appEmail = document.getElementById('appEmail').value;
	var phoneArea = document.getElementById('appPhoneArea').value;
	var phonePre = document.getElementById('appPhonePre').value;
	var phoneSuffix = document.getElementById('appPhoneSuffix').value;
	var phoneComplete = String(phoneArea) + String(phonePre) + String(phoneSuffix);
	var faxArea = document.getElementById('appFaxArea').value;
	var faxPre = document.getElementById('appFaxPre').value;
	var faxSuffix = document.getElementById('appFaxSuffix').value;
	var faxComplete = String(faxArea) + String(faxPre) + String(faxSuffix);
	var cellArea = document.getElementById('appCellArea').value;
	var cellPre = document.getElementById('appCellPre').value;
	var cellSuffix = document.getElementById('appCellSuffix').value;
	var cellComplete = String(cellArea) + String(cellPre) + String(cellSuffix);
	var appDescription = document.getElementById('appDescription').value;
	var appOrganization = document.getElementById('appOrganization').value;
	
	var returnValue = true;
	
	//call title validation
	if(!memberTypeValid(appMemberType))
	{
		returnValue = false;
		document.getElementById('invalidMember').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidMember').style.display = 'none';
	}
	//call first name validation
	if(!nameString(appNameFirst))
	{
		returnValue = false;
		document.getElementById('invalidFirstName').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidFirstName').style.display = 'none';
	}
	//call last name validation
	if(!nameString(appNameLast))
	{
		returnValue = false;
		document.getElementById('invalidLastName').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidLastName').style.display = 'none';
	}
	//call position-job title validation
	if(!title(appTitle))
	{
		returnValue = false;
		document.getElementById('invalidPosition').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidPosition').style.display = 'none';
	}
	//call agency validation
	if(!agency(appAgency))
	{
		returnValue = false;
		document.getElementById('invalidAgency').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidAgency').style.display = 'none';
	}
	//call street validation
	if(!streetValid(appStreet))
	{
		returnValue = false;
		document.getElementById('invalidStreet').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidStreet').style.display = 'none';
	}
	//call city validation
	if(!nameString(appCity))
	{
		returnValue = false;
		document.getElementById('invalidCity').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidCity').style.display = 'none';
	}
	//call state validation
	if(!stateValid(appState))
	{
		returnValue = false;
		document.getElementById('invalidState').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidState').style.display = 'none';
	}
	//call zip validation
	if(!zipValid(appZip))
	{
		returnValue = false;
		document.getElementById('invalidZip').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidZip').style.display = 'none';
	}
	
	//check if email is empty, empty is ok
	if(appEmail.length != 0)
	{
		//if email is not empty, call function to check validity
		if(!isValidEmail(appEmail))
		{
			returnValue = false;
			document.getElementById('invalidAppEmail').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidAppEmail').style.display = 'none';
		}
	}
	else
	{
		returnValue = false;
		document.getElementById('invalidAppEmail').style.display = 'inline';
	}
	
	//Check if phone empty
	if(phoneComplete.length != 10)
	{
		returnValue = false;
		document.getElementById('invalidPhone').style.display = 'inline';
	}
	//if not empty and 10 digits long, call phone validation
	else
	{
		if(!telephoneValid(phoneComplete))
		{
			returnValue = false;
			document.getElementById('invalidPhone').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidPhone').style.display = 'none';
		}
	}
	//Check if fax empty
	if(faxComplete.length != 10)
	{
		returnValue = false;
		document.getElementById('invalidFax').style.display = 'inline';
	}
	//if not empty and 10 digits long, call phone validation
	else
	{
		if(!telephoneValid(faxComplete))
		{
			returnValue = false;
			document.getElementById('invalidFax').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidFax').style.display = 'none';
		}
	}
	//if cell number is empty, do nothing
	if(cellComplete.length != 0)
	{
		//if phone number not empty, it must be 10 digits
		if(cellComplete.length != 10)
		{
			returnValue = false;
			document.getElementById('invalidCell').style.display = 'inline';
		}
		//if not empty and 10 digits long, call phone validation
		else
		{
			if(!telephoneValid(cellComplete))
			{
				returnValue = false;
				document.getElementById('invalidCell').style.display = 'inline';
			}
			else
			{
				document.getElementById('invalidCell').style.display = 'none';
			}
		}
		
	}
	else
	{
		document.getElementById('invalidCell').style.display = 'none';
	}
	//check if description is empty
	if(appDescription.length != 0)
	{
		//if email is not empty, call function to check validity
		if(!description(appDescription))
		{
			returnValue = false;
			document.getElementById('invalidDescription').style.display = 'inline';
		}
		else
		{
			document.getElementById('invalidDescription').style.display = 'none';
		}
	}
	else
	{
		returnValue = false;
		document.getElementById('invalidDescription').style.display = 'inline';
	}
	//call position-job title validation to check for organization validity
	if(!title(appOrganization))
	{
		returnValue = false;
		document.getElementById('invalidOrganization').style.display = 'inline';
	}
	else
	{
		document.getElementById('invalidOrganization').style.display = 'none';
	}

	
	
	return returnValue;
}

function loginDownload()
{
	alert('You must be logged in to download the Directory');
}
