startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("mainNav");
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;

//Itemize characters to remove
function cleanStringChars (str) 
{
	return str.replace(/[\(\)\.\-\s,]/g, "");
}
//Remove all non-digits
function cleanStringDigits (str) 
{
	return str.replace(/[^\d]/g, "");
}


function checkQuote() 
{
	//alert("1");

	var errorContent = "";
	
	//if (!(document.empl.lead_name_last.value == "test"))
	//{
	//	return true;
	//}
	
	document.empl.lead_name.value = document.empl.lead_name.value.replace(/^\s+|\s+$/g,"");

	if (document.empl.lead_name.value.length < 1)
	{
		errorContent = errorContent + "Please enter a Full Name - First Last\n";
	}
	else
	{
		var spaceIndex = document.empl.lead_name.value.indexOf(" ");
		
		if (spaceIndex <= 0)
		{
			errorContent = errorContent + "Please enter a Full Name - First Last\n";
		}
		else
		{		
			document.empl.lead_name_first.value = document.empl.lead_name.value.substr(0,spaceIndex);
			document.empl.lead_name_last.value = document.empl.lead_name.value.substr(spaceIndex+1,(document.empl.lead_name.value.length-(spaceIndex+1)));
			//alert("=" + document.empl.lead_name_first.value + " " + document.empl.lead_name_last.value + "=");
		}	
	}

	if (!(checkEmail(document.empl.lead_email.value)))
	{
		errorContent = errorContent + "Please enter a valid E-mail address\n";
	}
	
	document.empl.phone1.value = cleanStringChars(document.empl.phone1.value);
	document.empl.phone1.value = cleanStringDigits(document.empl.phone1.value);
	
	if (!(checkPhone(document.empl.phone1.value)))
	{
		errorContent = errorContent + "Please enter a valid 10 digit Phone Number\n";
	}
	else
	{
		document.empl.lead_phone1.value = document.empl.phone1.value.substr(0,3);
		document.empl.lead_phone2.value = document.empl.phone1.value.substr(3,3);
		document.empl.lead_phone3.value = document.empl.phone1.value.substr(6,4);
		//alert(document.empl.lead_phone1.value + "-" + document.empl.lead_phone2.value + "-" + document.empl.lead_phone3.value);
	}
		
	if (document.empl.lead_from_zip.value == "Zip Code")
	{
		errorContent = errorContent + "Please enter a valid 5 digit From Zip Code\n";
	}
	else if (!(checkZip(document.empl.lead_from_zip.value)))
	{
		errorContent = errorContent + "Please enter a valid 5 digit From Zip Code\n";
	}
	//alert("2");

	if (document.empl.lead_from_city.value == "City")
	{
		errorContent = errorContent + "Please enter From City\n";
	}
	else
	{
		if (document.empl.lead_from_city.value.length < 1)
		{
			errorContent = errorContent + "Please enter From City\n";
		}	
	}
	
	if (document.empl.lead_from_state.selectedIndex == 0)
	{
		errorContent = errorContent + "Please enter From State\n";
	}	



	if (document.empl.lead_to_zip.value == "Zip Code")
	{
		errorContent = errorContent + "Please enter a valid 5 digit To Zip Code\n";
	}
	else if (!(checkZip(document.empl.lead_to_zip.value)))
	{
		errorContent = errorContent + "Please enter a valid 5 digit To Zip Code\n";
	}

	
	if (document.empl.lead_to_city.value == "City")
	{
		errorContent = errorContent + "Please enter To City\n";
	}
	else
	{
		if (document.empl.lead_to_city.value.length < 1)
		{
			errorContent = errorContent + "Please enter To City\n";
		}	
	}
	
	if (document.empl.lead_to_state.selectedIndex == 0)
	{
		errorContent = errorContent + "Please enter To State\n";
	}	

//	var to_flag = false;
//
//	if (document.empl.lead_to_zip.value == "Zip Code")
//	{
//		to_flag = false;
//	}
//	else if (checkZip(document.empl.lead_to_zip.value))
//	{
//		to_flag = true;
//	}
////	alert("31");
//	if ((document.empl.lead_to_city.value.length > 0) && (document.empl.lead_to_state.selectedIndex > 0))
//	{
//		to_flag = true;
//		
//		if (document.empl.lead_to_city.value == "City")
//		{
//			to_flag = false;
//		}
//	}
////	alert("4");
//
//
//	if (!(to_flag))
//	{
//		errorContent = errorContent + "Please enter either To Zip or To City/State\n";
//	}	
	
	if (document.empl.move_type.selectedIndex == 0)
	{
		errorContent = errorContent + "Please enter Type Of Move\n";
	}
//	alert("5");
	
	
	if (document.empl.move_date_month.selectedIndex == 0 || document.empl.move_date_day.selectedIndex == 0 || document.empl.move_date_year.selectedIndex == 0)
	{
		errorContent = errorContent + "Please enter the complete Move Date\n";		
	}
	else
	{
		var todayDate = new Date();
		//alert("todayDate=" + todayDate);
		
		var enteredDate = new Date();
		//alert("enteredDate=" + enteredDate);
		//alert("Date-1");
		
		//alert("0=" + document.empl.date_month.selectedIndex);
		//alert("1=" + document.empl.date_month.options[document.empl.date_month.selectedIndex].text);
		//alert("2=" + parseInt(document.empl.move_date_month.options[document.empl.move_date_month.selectedIndex].text));
		var tempMonth = parseInt(document.empl.move_date_month.options[document.empl.move_date_month.selectedIndex].text);
		tempMonth = tempMonth-1;
		enteredDate.setMonth(tempMonth);
		//alert("3=" + enteredDate.getMonth());	

		//alert("Date-2");
		enteredDate.setDate(parseInt(document.empl.move_date_day.options[document.empl.move_date_day.selectedIndex].value));
		//alert("2=" + parseInt(document.empl.move_date_day.options[document.empl.move_date_day.selectedIndex].value));

		//alert("Date-3");
		enteredDate.setYear(parseInt(document.empl.move_date_year.options[document.empl.move_date_year.selectedIndex].value));
		//alert("3=" + parseInt(document.empl.move_date_year.options[document.empl.move_date_year.selectedIndex].value));
		enteredDate.setHours(0);

		//alert("Date-4");
		enteredDate.setMinutes(0);

		//alert("Date-5");
		//teredDate.setSeconds(0);

		//alert("Date-6");
		//alert(todayDate);
		//alert(enteredDate);

		if (enteredDate < todayDate)
		{
			errorContent = errorContent + "Please enter a Move Date that is after today's date\n";		
		}
		//alert("Date-7");
	
	}
	//alert("6");
	//alert(errorContent.length);
	//alert(errorContent);


	if (errorContent.length > 0)
	{
		errorContent = "Please correct the following errors:\n\n" + errorContent;
		alert(errorContent);
		return false;
	}
	else
	{
		return true;
	}
		
	//document.getElementById("error").innerHTML = errorContent;
}

function checkEmail(theEmail) 
{
	//START email CHECK
	var at_flag = 0;
	var dot_flag = 0;
	var elength_flag = 0;

	if(theEmail.length >= 5)
	{
		elength_flag = 1;

		for(a=0;a<theEmail.length;a++)
		{
			if(theEmail.charAt(a) == '@')
			{
				at_flag = 1;

				if((theEmail.charAt(a+1) == '.') || (theEmail.charAt(a+1) == ' ') || (theEmail.charAt(a+1) == ' '))
				{
					at_flag = 0;
				}
			}
			else if(theEmail.charAt(a) == '.')
			{
				dot_flag = 1;

				if((theEmail.charAt(a+1) == "") || (theEmail.charAt(a+1) == " ") || (theEmail.charAt(a+1) == "@"))
				{
					at_flag = 0;
				}
			}

			if(a==0)
			{
				if(theEmail.charAt(a) == '@')
				{
					at_flag = 0;
				}
				
				if(theEmail.charAt(a) == '.')
				{
					dot_flag = 0;
				}
			}
		}// End of for loop
	}// End of length condition

	if((at_flag != 1) || (dot_flag != 1) || (elength_flag != 1))
	{
		return false;
	}
	
	return true;
}
// END email CHECK

function checkPhone(str) 
{
	var stripped = str.replace(/[\(\)\.\-\ ]/g, '');

	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) 
	{
	   //error = "The phone number contains illegal characters.";
	   return false;
	}

	if (!(stripped.length == 10)) 
	{
		//error = "The phone number is the wrong length. Make sure you included an area code.\n";
		return false;
	}
	
	return true;
}

function checkZip(strZip) 
{
	var stripped = strZip.replace(/[\(\)\.\-\ ]/g, '');

	//strip out acceptable non-numeric characters

	if (!(stripped.length == 5))
	{
		//error = "The zip is the wrong length. Make sure you included an area code.\n";
		return false;
	}
	
	
	return true;
}