/* ///////////////////////////////////////////// */

function validateSampleForm(form){
	var alertMsg = "Please enter data for the following missing fields:\n\n"
	
	if(form.frmFirstName.value==""){
		alertMsg = alertMsg + "  First Name: \n"
	}
	if(form.frmLastName.value==""){
		alertMsg = alertMsg + "  Last Name: \n"
	}
	//valifdate email address
	var emailID=document.profile.frmEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	if(form.drpRoles.value==""){
		alertMsg = alertMsg + "  Role: \n"
	}
	if ((form.frmPassword1.value!="") || (form.frmPassword2.value!="")){
		//alert("here");
		if(form.frmPassword1.value!=form.frmPassword2.value){
			alertMsg = alertMsg + "  Passwords do not match.  Please re-enter them. \n"
		}
	}
	if (alertMsg == "Please enter data for the following missing fields:\n\n"){
		return true;
	} 	
	else {
		alert(alertMsg);
		return false;
	}
}

/* ///////////////////////////////////////////// */

function validatePollingForm(form){
	var alertMsg = "Please enter data for the following missing fields:\n\n"
	//alert("hi");
	//return false

	if(form.frmStreetNumber.value==""){
		alertMsg = alertMsg + "  Street Number: \n"
	}
	
	if(form.frmStreetName.value==""){
		alertMsg = alertMsg + "  Street Name: \n"
	}
	
	if(form.drpStreetSuffix.selectValue==""){
		alertMsg = alertMsg + "  Street Suffix: \n"
	}
	
	if(form.drpStreetDirection.selectedValue==""){
		alertMsg = alertMsg + "  Street Prefix: \n"
	}
	
	if(form.frmZip.value==""){
		alertMsg = alertMsg + "  Zip Code: \n"
	}
	
	if (alertMsg == "Please enter data for the following missing fields:\n\n"){
		return true;
	} 	
	else {
		alert(alertMsg);
		return false;
	}
}


function validateRegStatusForm(form){
	var alertMsg = "Please make the following corrections:\n\n"
	//alert("hi");
	//return false
	if(form.frmLastName.value==""){
		alertMsg = alertMsg + "  Last Name: \n"
	}
	
	if((form.frmSSN.value=="") && (form.frmDLN1.value=="" || form.frmDLN2.value=="" || form.frmDLN3.value=="")){
		alertMsg = alertMsg + "  The Last 4 Digits of Your Social Security Number,  or Your Drivers License Number. \n"		
	}
	
	if((form.frmSSN.value!="") && (form.frmDLN1.value!="" || form.frmDLN2.value!="" || form.frmDLN3.value!="")){
		alertMsg = alertMsg + "  Please Either Enter The Last 4 Digits of Your Social Security Number,  or Your Drivers License Number. \n"		
	}
	
	if (alertMsg == "Please make the following corrections:\n\n"){
		return true;
	} 	
	else {
		alert(alertMsg);
		return false;
	}
}

function validateUploadForm(form){
	var alertMsg = "Please enter data for the following missing fields:\n\n"
	//alert("hi");
	//return false
	if(form.frmTitle.value==""){
		alertMsg = alertMsg + "  Document Title: \n"
	}
	//if(form.frmDescription.value==""){
	//	alertMsg = alertMsg + "  Document Description: \n"
	//}
	//if(form.myFile.value==""){
	//	alertMsg = alertMsg + "  File to be Uploaded: \n"
	//}
	//if(form.drpResultsDate.selectValue==""){
	//	alertMsg = alertMsg + "  Election Results Date: \n"
	//}
	
	if (alertMsg == "Please enter data for the following missing fields:\n\n"){
		return true;
	} 	
	else {
		alert(alertMsg);
		return false;
	}
}


function validateContactForm(form){
	var alertMsg = "Please enter data for the following missing fields:\n\n"
	//alert("In function");
	//return false
	if(form.frmNameField.value==""){
		alertMsg = alertMsg + "  Name: \n"
	}
	if(form.frmComments.value==""){
		alertMsg = alertMsg + "  Comments: \n"
	}
	
	if(form.drpSubject.selectedIndex==""){
		alertMsg = alertMsg + "  Subject: \n"
	}
	
	//valifdate email address
	var emailID=form.frmEmailAddress
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	if (alertMsg == "Please enter data for the following missing fields:\n\n"){
		return true;
	} 	
	else {
		alert(alertMsg);
		return false;
	}
}

/* ///////////////////////////////////////////// */

//validate email address.

function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("Invalid E-mail Address")
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("Invalid E-mail Address")
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail Address")
		return false
	}

		if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail Address")
		return false
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail Address")
		return false
		}

		if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail Address")
		return false
		}
	
		if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail Address")
		return false
		}

 		return true					
}


