function ResetForm(strFormID)
{
	document.getElementById(strFormID).reset();
}

function ValidateFields(strFormID, strAlertMessage)
{
	var frm = document.getElementById(strFormID);
	var strTextBoxID;
	var strLabelID;		
	var blnInvalid = false;
	var strLocation;
	var strEmailAddress;
		
	// loop through each element in the array
	for (ctr=0; ctr<document.getElementById(strFormID).length; ctr++)
	{
		if (document.getElementById(strFormID).elements[ctr].className == "RequiredField")
		{
			// save the id of the textbox to derive the id of the label
			strTextBoxID = document.getElementById(strFormID).elements[ctr].id;
			strLabelID = "lbl" + strTextBoxID
			
			if (document.getElementById(strFormID).elements[ctr].value == "")
			{												
				// change the label font color to red
				document.getElementById(strLabelID).style.color = "red";
					
				//set a flag indicating there are invalid entries
				blnInvalid = true;
			}
			else
			{	
				// change the label font color to the default... black
				document.getElementById(strLabelID).style.color = "black";
			}
		}

		if (document.getElementById(strFormID).elements[ctr].className == "RequiredEmailField")
		{
			// save the id of the textbox to derive the id of the label
			strTextBoxID = document.getElementById(strFormID).elements[ctr].id;
			strLabelID = "lbl" + strTextBoxID

			if ((document.getElementById(strFormID).elements[ctr].value.indexOf("@") < 0) && (document.getElementById(strFormID).elements[ctr].value.indexOf(".") < 0))
			{
				// change the label font color to red
				document.getElementById(strLabelID).style.color = "red";
					
				//set a flag indicating there are invalid entries
				blnInvalid = true;				
			}
			else
			{	
				// change the label font color to the default... black
				document.getElementById(strLabelID).style.color = "black";
			}
		}
	
	}

	// do not submit the form if there are any invalid entries
	if (blnInvalid == true)
	{
		alert("The identified fields contain missing or invalid information.");
	}
	else
	{
				
	  	if (strFormID == 'frmService') 
		{ 
			 strAlertMessage = "Thank you for submitting your request for a service appointment! Someone will be contacting you shortly.";

			 // Retrieve the selected service location from dropdown
			 strLocation = document.getElementById('ServiceLocation').value;
			 
			 if (strLocation == 'WESTSIDE') {
  	 			strEmailAddress = 'ashleyroad@woodiesautoservice.com';}
  	 	 	 if (strLocation == 'MIDTOWN1') {
  	 			strEmailAddress = 'charlottetown@woodiesautoservice.com';}
  	  		 if (strLocation == 'SOUTH') {
  	 			strEmailAddress = 'sharonroad@woodiesautoservice.com';}
  	   		 if (strLocation == 'INDEPENDENCE') {
  	 			strEmailAddress = 'independence@woodiesautoservice.com';}
  	   		 if (strLocation == 'UPTOWN') {
  	 			strEmailAddress = 'uptown@woodiesautoservice.com';}
  	   		 if (strLocation == 'MIDTOWN2') {
  	 			strEmailAddress = 'midtown@woodiesautoservice.com';}
			
			 
			 // Update the textboxes for appropriate redirection based on selected service location
		   	 document.getElementById('redirect').value = "http://www.woodiesautoservice.com/locations.htm#" + strLocation;
			 
		  	 document.getElementById('to').value = strEmailAddress;

		          // Show an alert dialog box using appropriate message
		          alert(strAlertMessage);

		          // Submit the appropriate form
	   	          document.getElementById(strFormID).submit();


		}
	  	else if (strFormID == 'frmSignup') 
		{
		      strAlertMessage = "Thank you for submitting your email address to join our email distribution.";
							
		      // Show an alert dialog box using appropriate message
		      alert(strAlertMessage);

		      // Submit the appropriate form
	   	      document.getElementById(strFormID).submit();
                  }

	}					
}
