function validateProjectSubmission()
{
	// created november 2, 2004 - president election night - president george w. bush vs. senator john kerry
	// creator: raymond g.s. sidhu
	// a basic script that validates
	// the project submission before it is inserted into the database
	// no other validation will take place except on this form
	
	var formIsValid=true // assume its valid
	var errMsg="______________________________________________________________\n\n"
		errMsg+="The form was not submitted because of the following error(s).\n"
		errMsg+="Please correct these error(s) and try again.\n"
		errMsg+="______________________________________________________________\n\n"
		errMsg+="-The Following field(s) are missing or invalid:\n\n";
	
	// first things first
	if(document.form.tradeID.value==-1){
		formIsValid=false
		errMsg+="\t Service Type\n"
	}
	//if(document.form.projectArea.value==-1){
	//	formIsValid=false
	//	errMsg+="\t Project Area\n"
	//}
	if(document.form.ageOfHouse.value==-1){
		formIsValid=false
		errMsg+="\t Age of House\n"
	}
	if(document.form.budget.value==-1){
		formIsValid=false
		errMsg+="\t Project Budget\n"
	}
	if(document.form.preferredStartDate.value==-1){
		formIsValid=false
		errMsg+="\t Preferred Start Date\n"
	}
	if(document.form.projectStatus.value==-1){
		formIsValid=false
		errMsg+="\t Project Status\n"
	}
	if(document.form.completionDate.value==-1){
		formIsValid=false
		errMsg+="\t Desired Completion Date\n"
	}
	//if(document.form.howLongOwned.value==-1){
	//	formIsValid=false
	//	errMsg+="\t How Long Owned\n"
	//}
	if(document.form.isCommercialLocation.value==-1){
		formIsValid=false
		errMsg+="\t Commercial Location\n"
	}
	if(document.form.isInsuranceClaim.value==-1){
		formIsValid=false
		errMsg+="\t Insurance Claim\n"
	}
	
	// now check the user contact info
	if(removeLeadingAndTrailingChar(document.form.firstName.value, ' ')==""){
		formIsValid=false
		errMsg+="\t First Name\n"
	}
	if(removeLeadingAndTrailingChar(document.form.lastName.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Last Name\n"
	}
	if(removeLeadingAndTrailingChar(document.form.address.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Address\n"
	}
	if(removeLeadingAndTrailingChar(document.form.city.value, ' ')==""){
		formIsValid=false
		errMsg+="\t City\n"
	}
	if(document.form.state.value==-1){
		formIsValid=false
		errMsg+="\t State\n"
	}
	if(removeLeadingAndTrailingChar(document.form.zip.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Zip\n"
	}
	if(removeLeadingAndTrailingChar(document.form.phone.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Phone\n"
	}
	if(removeLeadingAndTrailingChar(document.form.phoneAlt.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Alternate Phone\n"
	}
	if(removeLeadingAndTrailingChar(document.form.email.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Email Address\n"
	}
	if(document.form.bestContactTime1.value==-1){
		formIsValid=false
		errMsg+="\t Best Contact Time Phone\n"
	}
	if(document.form.bestContactTime2.value==-1){
		formIsValid=false
		errMsg+="\t Best Contact Time Alternate Phone\n"
	}
	if(removeLeadingAndTrailingChar(document.form.projectComments.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Project Comments\n"
	}

	// return the value
	if(!formIsValid){
		alert(errMsg)
		return false
	}else{
		return true
	}
}
function removeLeadingAndTrailingChar(inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	return returnString;
}

function validateUserSignUp()
{
	// created november 2, 2004 - president election night - president george w. bush vs. senator john kerry
	// creator: raymond g.s. sidhu
	// a basic script that validates
	// the user sign before it is inserted into the database
	// no other validation will take place except on this form
	
	var formIsValid=true // assume its valid
	var errMsg="______________________________________________________________\n\n"
		errMsg+="The form was not submitted because of the following error(s).\n"
		errMsg+="Please correct these error(s) and try again.\n"
		errMsg+="______________________________________________________________\n\n"
		errMsg+="-The Following field(s) are missing or invalid:\n\n";
	
	if(document.form.usertype.value==-1){
		formIsValid=false
		errMsg+="\t Service Provider or Service Seeker\n"
	}	
	if(rltc(document.form.email.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Email Address\n"
	}	
	if(rltc(document.form.password.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Password \n"
	}	
	if(rltc(document.form.password.value, ' ')!=rltc(document.form.co_password.value, ' ')){
		formIsValid=false
		errMsg+="\t Confirm Password doesn't match \n"
	}	
	if(rltc(document.form.firstName.value, ' ')==""){
		formIsValid=false
		errMsg+="\t First Name\n"
	}
	if(rltc(document.form.lastName.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Last Name\n"
	}
	if(rltc(document.form.address.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Address\n"
	}
	if(rltc(document.form.city.value, ' ')==""){
		formIsValid=false
		errMsg+="\t City\n"
	}
	if(document.form.state.value==-1){
		formIsValid=false
		errMsg+="\t State\n"
	}
	if(rltc(document.form.zip.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Zip\n"
	}
	if(rltc(document.form.phone.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Phone\n"
	}
	if(document.form.bestContactTime1.value==-1){
		formIsValid=false
		errMsg+="\t Contact Time Phone\n"
	}
		
	// return the value
	if(!formIsValid){
		alert(errMsg)
		return false
	}else{
		return true
	}
		
}

function validateRateContractorSubmission()
{
	// created november 2, 2004 - president election night - president george w. bush vs. senator john kerry
	// creator: raymond g.s. sidhu
	// a basic script that validates
	// the user sign before it is inserted into the database
	// no other validation will take place except on this form
	var time=0,clean=0,court=0,budget=0,quality=0,value=0,communication=0;
	var formIsValid=true // assume its valid
	var errMsg="______________________________________________________________\n\n"
		errMsg+="The form was not submitted because of the following error(s).\n"
		errMsg+="Please correct these error(s) and try again.\n"
		errMsg+="______________________________________________________________\n\n"
		errMsg+="-The Following field(s) are missing or invalid:\n\n";
	
	if(rltc(document.form.firstName.value, ' ')==""){
		formIsValid=false
		errMsg+="\t First Name\n"
	}
	if(rltc(document.form.lastName.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Last Name\n"
	}
	if(rltc(document.form.email.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Email Address\n"
	}
	if(document.form.contractor.value==-1){
		formIsValid=false
		errMsg+="\t Select a Contractor\n"
	}

			// make sure a value is selected for each of the rating categories
			//time
			for(idx=0;idx<5;idx++){
				if(document.form.time[idx].checked){
					time=document.form.time[idx].value
				}
			}
			// cleanliness
			for(idx=0;idx<5;idx++){
				if(document.form.clean[idx].checked){
					clean=document.form.time[idx].value
				}
			}
			// courteous
			for(idx=0;idx<5;idx++){
				if(document.form.court[idx].checked){
					court=document.form.time[idx].value
				}
			}
			// budget
			for(idx=0;idx<5;idx++){
				if(document.form.budget[idx].checked){
					budget=document.form.time[idx].value
				}
			}
			// quality
			for(idx=0;idx<5;idx++){
				if(document.form.quality[idx].checked){
					quality=document.form.time[idx].value
				}
			}
			// value
			for(idx=0;idx<5;idx++){
				if(document.form.value[idx].checked){
					value=document.form.time[idx].value
				}
			}
			// communication
			for(idx=0;idx<5;idx++){
				if(document.form.comm[idx].checked){
					communication=document.form.time[idx].value
				}
			}
	
	if(time==0){
		formIsValid=false
		errMsg+="\t Timeliness\n"
	}
	if(clean==0){
		formIsValid=false
		errMsg+="\t Cleanliness\n"
	}
	if(court==0){
		formIsValid=false
		errMsg+="\t Courteousness\n"
	}
	if(budget==0){
		formIsValid=false
		errMsg+="\t Budget\n"
	}
	if(quality==0){
		formIsValid=false
		errMsg+="\t Quality\n"
	}
	if(value==0){
		formIsValid=false
		errMsg+="\t Value\n"
	}
	if(communication==0){
		formIsValid=false
		errMsg+="\t Communication\n"
	}
	
	if(rltc(document.form.comments.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Comments\n"
	}
	// return the value
	if(!formIsValid){
		alert(errMsg)
		return false
	}else{
		return true
	}
}

function rltc(inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	return returnString;
}

function checkEmailAddress(txt)
{
	if(txt.value=="") return;
	
	var regex=/^[_A-z0-9-]+(\.[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.([A-z]){2,4})$/;
	
	var email_valid=txt.value.match(regex);
	
	if(!email_valid)
	{
		alert("Your E-mail address appears to be invalid, Please Re-Enter It.")
			txt.value="";
			txt.focus()
			return;
	}
}

function showOverallRating(){

	// shows the overall rating in stars
	var html="";
	var rating=calculateOverallRating();
	for(idx=0;idx<rating;idx++){
		html+="<img src=images/star1.gif> "
	}
	document.getElementById("overallRating").innerHTML=html;
}
function calculateOverallRating(){
	
	var time=0,clean=0,court=0,budget=0,quality=0,value=0,communication=0;
	var numSelected=0;
	// time
	for(idx=0;idx<5;idx++){
		if(document.form.time[idx].checked){
			time=document.form.time[idx].value
			numSelected+=1;
		}
	}
	// cleanliness
	for(idx=0;idx<5;idx++){
		if(document.form.clean[idx].checked){
			clean=document.form.time[idx].value
			numSelected+=1;
		}
	}
	// courteous
	for(idx=0;idx<5;idx++){
		if(document.form.court[idx].checked){
			court=document.form.time[idx].value
			numSelected+=1;
		}
	}
	// budget
	for(idx=0;idx<5;idx++){
		if(document.form.budget[idx].checked){
			budget=document.form.time[idx].value
			numSelected+=1;
		}
	}
	// quality
	for(idx=0;idx<5;idx++){
		if(document.form.quality[idx].checked){
			quality=document.form.time[idx].value
			numSelected+=1;
		}
	}
	// value
	for(idx=0;idx<5;idx++){
		if(document.form.value[idx].checked){
			value=document.form.time[idx].value
			numSelected+=1;
		}
	}
	// communication
	for(idx=0;idx<5;idx++){
		if(document.form.comm[idx].checked){
			communication=document.form.time[idx].value
			numSelected+=1;
		}
	}
	
	// add them all up and divide by the number selected
	total=parseInt(time)+parseInt(clean)+parseInt(court)+parseInt(budget)+parseInt(quality)+parseInt(value)+parseInt(communication)
	numSelected=parseInt(numSelected);
	total=total/numSelected;
	total=parseInt(total);
	return total;
}

function validateContractorSignUp()
{
	// created november 2, 2004 - president election night - president george w. bush vs. senator john kerry
	// creator: raymond g.s. sidhu
	// a basic script that validates
	// the user sign before it is inserted into the database
	// no other validation will take place except on this form
	
	var formIsValid=true // assume its valid
	var errMsg="______________________________________________________________\n\n"
		errMsg+="The form was not submitted because of the following error(s).\n"
		errMsg+="Please correct these error(s) and try again.\n"
		errMsg+="______________________________________________________________\n\n"
		errMsg+="-The Following field(s) are missing or invalid:\n\n";
	
	if(rltc(document.form.title.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Title\n"
	}	
	if(rltc(document.form.company.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Company Name\n"
	}	
	if(rltc(document.form.address.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Address\n"
	}
	if(rltc(document.form.city.value, ' ')==""){
		formIsValid=false
		errMsg+="\t City\n"
	}
	if(document.form.state.value==-1){
		formIsValid=false
		errMsg+="\t State\n"
	}
	if(rltc(document.form.zip.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Zip\n"
	}
	if(rltc(document.form.phone.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Phone\n"
	}
	if(rltc(document.form.phoneAlt.value, ' ')==""){
		formIsValid=false
		errMsg+="\t Alternate Phone\n"
	}
	if(document.form.bestContactTime1.value==-1){
		formIsValid=false
		errMsg+="\t Contact Time Phone\n"
	}
	if(document.form.bestContactTime2.value==-1){
		formIsValid=false
		errMsg+="\t Contact Time Alternate Phone\n"
	}
		
	// return the value
	if(!formIsValid){
		alert(errMsg)
		return false
	}else{
		return true
	}
		
}
