// JavaScript Document LeadFirst, LLC. 2006


// CSS Dropdown Navigation for IE6-
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;


////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// for older browsers that do not support Array.push method
if(typeof Array.prototype.push == "undefined")
  Array.prototype.push = function(){
    var i=0;
    b=this.length,a=arguments;
    for(i;i<a.length;i++)this[b+i]=a[i];
    return this.length
  }


////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// select language
function selectBox(object){
	location.href = object.options[object.selectedIndex].value;
}




////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// form validation
var returnVal;
var highlight; // set error highlight var, set in error message build
var errorHighlight = new Array(); // collects input error to print in alert

function valForm(id){
	var obj;
	var flag;
	var error = new Array();
	var regEmail = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	var regNum = /^([0-9]+)$/;

	
	// clear error field highlight color
	if(highlight == 1){
		for(i=0; i<errorHighlight.length; i++){
			errorHighlight[i].style.backgroundColor = "#ffffff";
		}
		errorHighlight = new Array();
	}


	//determine form for validation
	var formType = document.getElementById(id).getAttribute('id');
 
 	switch(formType){
		case 'askExp':
			obj = document.getElementById(formType);
			validateAskExp();
			break;
		case 'login':
			obj = document.getElementById(formType);
			validateLogin();
			break;
		case 'probono':
			obj = document.getElementById(formType);
			validateProBono();
			break;
		case 'regArch':
			obj = document.getElementById(formType);
			validateRegArch();
			break;
		case 'trainApp':
			obj = document.getElementById(formType);
			validateTrainingApp();
			break;
	}


	// validate email
	function validateEmail(email,emailValue){		
		if(emailValue == ''){
			emailMes = "Please enter your email address.";
			error.push(emailMes);
			flag = 1;
			email.style.backgroundColor = "#99ddff"
			errorHighlight.push(email);
		return;
		}
		if(!emailValue.match(regEmail)){
			emailMes = "Please verify the email address you entered.";
			error.push(emailMes);
			flag = 1;
			email.style.backgroundColor = "#99ddff"
			errorHighlight.push(email);
			return;
		}
	}


	// validate zip code
	function validateZip(zip,zipValue){
		if(zipValue == ''){
			zipMes = "Please enter your zip code.";
			error.push(zipMes);
			flag = 1;
			zip.style.backgroundColor = "#99ddff"
			errorHighlight.push(zip);
			return;
		}
		if(!zipValue.match(regNum)){
			zipMes = "Please verify your zip code.";
			error.push(zipMes);
			flag = 1;
			zip.style.backgroundColor = "#99ddff"
			errorHighlight.push(zip);
			return;
		}
		
		if(zipValue.length < 5){
			zipMes = "Please verify your zip code.";
			error.push(zipMes);
			flag = 1;
			zip.style.backgroundColor = "#99ddff"
			errorHighlight.push(zip);
			return;
		}
	}

	
	//validate ask the experts form
	function validateAskExp(){
		// set required form values
		var first_name = obj.uFirstName.value;
		var last_name = obj.uLastName.value;
		var company = obj.uCompany.value;
		var phArea = obj.uPhoneArea.value;
		var phPre = obj.uPhonePre.value;
		var phPost = obj.uPhonePost.value;
		var email = obj.uEmail;
		var emailValue = obj.uEmail.value;
		var question = obj.uQuestion.value;
		
		if(first_name == ''){
			first_nameMes = "Please enter your first name.";
			error.push(first_nameMes);
			flag = 1;
			obj.uFirstName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uFirstName);
		}
		if(last_name == ''){
			last_nameMes = "Please enter your last name.";
			error.push(last_nameMes);
			flag = 1;
			obj.uLastName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uLastName);
		}
		if(company == ''){
			companyMes = "Please enter your company's name.";
			error.push(companyMes);
			flag = 1;
			obj.uCompany.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uCompany);
		}
		if((phArea == '') || (phPre == '') || (phPost == '')){
			phoneMes = "Please check your phone number.";
			error.push(phoneMes);
			flag = 1;
			obj.uPhoneArea.style.backgroundColor = "#99ddff"
			obj.uPhonePre.style.backgroundColor = "#99ddff"
			obj.uPhonePost.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uPhoneArea);
			errorHighlight.push(obj.uPhonePre);
			errorHighlight.push(obj.uPhonePost);
		}
		else{
			if((!phArea.match(regNum)) || (!phPre.match(regNum)) || (!phPost.match(regNum))){
				phoneMes = "Phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				obj.uPhoneArea.style.backgroundColor = "#99ddff"
				obj.uPhonePre.style.backgroundColor = "#99ddff"
				obj.uPhonePost.style.backgroundColor = "#99ddff"
				errorHighlight.push(obj.uPhoneArea);
				errorHighlight.push(obj.uPhonePre);
				errorHighlight.push(obj.uPhonePost);
			}
		}
		if(question == ''){
			questionMes = "Please submit a question.";
			error.push(questionMes);
			flag = 1;
			obj.uQuestion.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uQuestion);
		}
		validateEmail(email,emailValue);
	}


	function validateLogin(){
		// set required form values
		var email = obj.user;
		var emailValue = obj.user.value;
		var pass = obj.pass.value;

		if(pass == ''){
			passMes = "Please enter a password.";
			error.push(passMes);
			flag = 1;
			obj.pass.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.pass);
		}
		validateEmail(email,emailValue);
	}


	//validate pro bono application form
	function validateProBono(){
		var first_name = obj.uFirstName.value;
		var last_name = obj.uLastName.value;
		var email = obj.uEmail;
		var emailValue = obj.uEmail.value;
		var phArea = obj.uPhoneArea.value;
		var phPre = obj.uPhonePre.value;
		var phPost = obj.uPhonePost.value;
		var company = obj.uCompany.value;
		var add = obj.uAdd1.value;
		var city = obj.uCity.value;
		var state = obj.uState.value;
		var zip = obj.uZipPre;
		var zipValue = obj.uZipPre.value;
		var question = obj.uQuestion.value;

		if(first_name == ''){
			first_nameMes = "Please enter your first name.";
			error.push(first_nameMes);
			flag = 1;
			obj.uFirstName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uFirstName);
		}
		if(last_name == ''){
			last_nameMes = "Please enter your last name.";
			error.push(last_nameMes);
			flag = 1;
			obj.uLastName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uLastName);
		}
		validateEmail(email,emailValue);
		if((phArea == '') || (phPre == '') || (phPost == '')){
			phoneMes = "Please check your phone number.";
			error.push(phoneMes);
			flag = 1;
			obj.uPhoneArea.style.backgroundColor = "#99ddff"
			obj.uPhonePre.style.backgroundColor = "#99ddff"
			obj.uPhonePost.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uPhoneArea);
			errorHighlight.push(obj.uPhonePre);
			errorHighlight.push(obj.uPhonePost);
		}
		else{
			if((!phArea.match(regNum)) || (!phPre.match(regNum)) || (!phPost.match(regNum))){
				phoneMes = "Phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				obj.uPhoneArea.style.backgroundColor = "#99ddff"
				obj.uPhonePre.style.backgroundColor = "#99ddff"
				obj.uPhonePost.style.backgroundColor = "#99ddff"
				errorHighlight.push(obj.uPhoneArea);
				errorHighlight.push(obj.uPhonePre);
				errorHighlight.push(obj.uPhonePost);
			}
		}
		if(company == ''){
			companyMes = "Please enter your company's name.";
			error.push(companyMes);
			flag = 1;
			obj.uCompany.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uCompany);
		}
		if(add == ''){
			addMes = "Please enter your company's address.";
			error.push(addMes);
			flag = 1;
			obj.uAdd1.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uAdd1);
		}
		if(city == ''){
			cityMes = "Please enter your company's city.";
			error.push(cityMes);
			flag = 1;
			obj.uCity.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uCity);
		}
		if(state == ''){
			stateMes = "Please enter your company's state.";
			error.push(stateMes);
			flag = 1;
			obj.uState.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uState);
		}
		validateZip(zip,zipValue);
		if(question == ''){
			questionMes = "Please submit your reply to our question.";
			error.push(questionMes);
			flag = 1;
			obj.uQuestion.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uQuestion);
		}
	}


	//validate article archive registration form
	function validateRegArch(){
		// set required form values
		var first_name = obj.uFirstName.value;
		var last_name = obj.uLastName.value;
		var company = obj.uCompany.value;
		var zip = obj.uZipPre;
		var zipValue = obj.uZipPre.value;
		var email = obj.uEmail;
		var emailValue = obj.uEmail.value;
		var confirmEmail = obj.confirmEmail;
		var confirmEmailValue = obj.confirmEmail.value;
		var uPass = obj.uPass.value;
		
		if(first_name == ''){
			first_nameMes = "Please enter your first name.";
			error.push(first_nameMes);
			flag = 1;
			obj.uFirstName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uFirstName);
		}
		if(last_name == ''){
			last_nameMes = "Please enter your last name.";
			error.push(last_nameMes);
			flag = 1;
			obj.uLastName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uLastName);
		}
		if(company == ''){
			companyMes = "Please enter your company's name.";
			error.push(companyMes);
			flag = 1;
			obj.uCompany.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uCompany);
		}
		validateZip(zip,zipValue);
		if(uPass == ''){
			uPassMes = "Please enter a password.";
			error.push(uPassMes);
			flag = 1;
			obj.uPass.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uPass);
		}
		if(emailValue != confirmEmailValue){
			emailConfirmMes = "The email addresses you entered do not match, please reenter them.";
			error.push(emailConfirmMes);
			flag = 1;
			obj.confirmEmail.style.backgroundColor = "#99ddff"
			obj.uEmail.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.confirmEmail);
			errorHighlight.push(obj.uEmail);
			return;
		}
		else{
			if(confirmEmailValue == ''){
				uPassMes = "Please confirm your email.";
				error.push(uPassMes);
				flag = 1;
				obj.confirmEmail.style.backgroundColor = "#99ddff"
				errorHighlight.push(obj.confirmEmail);
			}
			validateEmail(email,emailValue);
		}
	}


	//validate training appointment form
	function validateTrainingApp(){
		// set required form values
		var first_name = obj.uFirstName.value;
		var last_name = obj.uLastName.value;
		var email = obj.uEmail;
		var emailValue = obj.uEmail.value;
		var phArea = obj.uPhoneArea.value;
		var phPre = obj.uPhonePre.value;
		var phPost = obj.uPhonePost.value;
		var uChoice1MM = obj.uChoice1MM.value;
		var uChoice1DD = obj.uChoice1DD.value;
		var uChoice1YY = obj.uChoice1YY.value;
		var uChoice2MM = obj.uChoice2MM.value;
		var uChoice2DD = obj.uChoice2DD.value;
		var uChoice2YY = obj.uChoice2YY.value;
		var uChoice3MM = obj.uChoice3MM.value;
		var uChoice3DD = obj.uChoice3DD.value;
		var uChoice3YY = obj.uChoice3YY.value;
 
 		if(first_name == ''){
			first_nameMes = "Please enter your first name.";
			error.push(first_nameMes);
			flag = 1;
			obj.uFirstName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uFirstName);
		}
		if(last_name == ''){
			last_nameMes = "Please enter your last name.";
			error.push(last_nameMes);
			flag = 1;
			obj.uLastName.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uLastName);
		}
		if((phArea == '') || (phPre == '') || (phPost == '')){
			phoneMes = "Please check your phone number.";
			error.push(phoneMes);
			flag = 1;
			obj.uPhoneArea.style.backgroundColor = "#99ddff"
			obj.uPhonePre.style.backgroundColor = "#99ddff"
			obj.uPhonePost.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uPhoneArea);
			errorHighlight.push(obj.uPhonePre);
			errorHighlight.push(obj.uPhonePost);
		}
		else{
			if((!phArea.match(regNum)) || (!phPre.match(regNum)) || (!phPost.match(regNum))){
				phoneMes = "Phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				obj.uPhoneArea.style.backgroundColor = "#99ddff"
				obj.uPhonePre.style.backgroundColor = "#99ddff"
				obj.uPhonePost.style.backgroundColor = "#99ddff"
				errorHighlight.push(obj.uPhoneArea);
				errorHighlight.push(obj.uPhonePre);
				errorHighlight.push(obj.uPhonePost);
			}
		}
		if((uChoice1MM == '') || (uChoice1DD == '') || (uChoice1YY == '')){
			uChoice1Mes = "Please enter a complete date for your first choice.";
			error.push(uChoice1Mes);
			flag = 1;
			obj.uChoice1MM.style.backgroundColor = "#99ddff"
			obj.uChoice1DD.style.backgroundColor = "#99ddff"
			obj.uChoice1YY.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uChoice1MM);
			errorHighlight.push(obj.uChoice1DD);
			errorHighlight.push(obj.uChoice1YY);
		}
		if((uChoice2MM == '') || (uChoice2DD == '') || (uChoice2YY == '')){
			uChoice2Mes = "Please enter a complete date for your second choice.";
			error.push(uChoice2Mes);
			flag = 1;
			obj.uChoice2MM.style.backgroundColor = "#99ddff"
			obj.uChoice2DD.style.backgroundColor = "#99ddff"
			obj.uChoice2YY.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uChoice2MM);
			errorHighlight.push(obj.uChoice2DD);
			errorHighlight.push(obj.uChoice2YY);
		}
		if((uChoice3MM == '') || (uChoice3DD == '') || (uChoice31YY == '')){
			uChoice3Mes = "Please enter a complete date for your third choice.";
			error.push(uChoice3Mes);
			flag = 1;
			obj.uChoice3MM.style.backgroundColor = "#99ddff"
			obj.uChoice3DD.style.backgroundColor = "#99ddff"
			obj.uChoice3YY.style.backgroundColor = "#99ddff"
			errorHighlight.push(obj.uChoice3MM);
			errorHighlight.push(obj.uChoice3DD);
			errorHighlight.push(obj.uChoice3YY);
		}
		validateEmail(email,emailValue);
	}
	
	
	// build error message
	if(flag == 1){
		errorString =error.join('\r\n');
		alert(errorString);
		returnVal= false;	
		highlight = 1;
	}
	else{
		returnVal= true;
	}
}

