//to call the respective validate function per page
function submitForm(from)
{
	var page=document.forms[0].pn.value;
	var validationResult=false;
	if(page==1)
	{
	 validationResult=validateCommuterSignup();	 
	}
	else if(page==2)
	{
	 validationResult=validatePersonalProfile();	 
	}
	else if(page==3)
	{
	 validationResult=validatePaymentInformation();	 
	}
	else if(page==4)
	{
	 return true;
	}
	else if(page==5)
	{		
	 validationResult=validateCompanyProfile();	 		  
	}
	else if(page==6)
	{
	 //return true;
	 //checking for valid compressed day off
	 reEvaluateCompressedDayOffSelection();
	 validationResult=true;
	}
	
	if(validationResult)
	{
		if(from!="L")
		return true;
		else
		document.forms[0].submit();
	}
	else if(!validationResult)
	{		
		if(from!="L") return false;	
	}
}

//to validate the commuter signup form
function validateCommuterSignup()
{
	var errorMessage="";
	var ctrPlan=0;
	var selectedPlan="";
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="selectedPlan")
		{
			if(document.forms[0].elements[i].checked)
			{
				ctrPlan++;
				selectedPlan=document.forms[0].elements[i].value;
			}
		}	
	}
	if(ctrPlan!=1)
	{
		errorMessage="Please select a Service Plan";
	}
	else
	{
		if(selectedPlan==1)
		{
			if(trim(document.getElementById("subCouponCode").value).length>0)
			{
				errorMessage="Coupon is not valid for Free Plan, please change your plan selection";
			}
		}
	}
	
	if(trim(errorMessage).length!=0)
	{
		alert(errorMessage);
		return false;	
	}
	else
	{
		return true;
	}
}

//to validate the personal profile form
function validatePersonalProfile()
{
	var errorMessage="";
		
	if(document.getElementById("userName"))
	{	
		document.getElementById("userName").value=
		trim(document.getElementById("userName").value);
		if(document.getElementById("userName").value.length<6)
		 errorMessage="Username must not be less than 6 characters\n";			
	}
	if(document.getElementById("password"))
	{
		document.getElementById("password").value=
		trim(document.getElementById("password").value);
		if(document.getElementById("password").value.length<6)
		 errorMessage+="Password must not be less than 6 characters\n";
	}
	if(document.getElementById("passwordConfirm"))
	{
		document.getElementById("passwordConfirm").value=
		trim(document.getElementById("passwordConfirm").value);
		if(document.getElementById("password").value!=
			document.getElementById("passwordConfirm").value)
		 errorMessage+="The two password's doesn't match\n";
	}
	if(document.getElementById("firstName"))
	{
		document.getElementById("firstName").value=
		trim(document.getElementById("firstName").value);
		if(document.getElementById("password").value.length==0)
		 errorMessage+="Please provide first name \n";
	}
	if(document.getElementById("lastName"))
	{
		document.getElementById("lastName").value=
		trim(document.getElementById("lastName").value);
		if(document.getElementById("password").value.length==0)
		 errorMessage+="Please provide last name \n";
	}
	if(document.getElementById("address"))
	{
		document.getElementById("address").value=
		trim(document.getElementById("address").value);
		if(document.getElementById("address").value.length==0)
		 errorMessage+="Please provide address \n";
	}
	if(document.getElementById("city"))
	{
		if(document.getElementById("city").selectedIndex==0)
		 errorMessage+="Please provide city \n";
	}
	if(document.getElementById("state"))
	{		
		if(document.getElementById("state").selectedIndex==0)
		 errorMessage+="Please provide state \n";
	}
	if(document.getElementById("metroMarket"))
	{		
		if(document.getElementById("metroMarket").selectedIndex==0)
		 errorMessage+="Please provide metro market \n";
	}
	if(document.getElementById("zip"))
	{
		document.getElementById("zip").value=
		trim(document.getElementById("zip").value);
		if(document.getElementById("zip").value.length==0)
		 errorMessage+="Please provide zip \n";
	}
	if(document.getElementById("emailAddress"))
	{
		document.getElementById("emailAddress").value=
		trim(document.getElementById("emailAddress").value);
		if(document.getElementById("emailAddress").value.length==0)
		 errorMessage+="Please provide email address \n";
	}
	if(document.getElementById("xStreet1"))
	{
		document.getElementById("xStreet1").value=
		trim(document.getElementById("xStreet1").value);
		if(document.getElementById("xStreet1").value.length==0)
		 errorMessage+="Please provide Cross Street X \n";
	}
	if(document.getElementById("xStreet2"))
	{
		document.getElementById("xStreet2").value=
		trim(document.getElementById("xStreet2").value);
		if(document.getElementById("xStreet2").value.length==0)
		 errorMessage+="Please provide Cross Street Y \n";
	}
	
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
	return true;

}

//to validate the payment information
function validatePaymentInformation()
{
	var errorMessage="";
	
	if(document.getElementById("nameOnCC"))
	{
		document.getElementById("nameOnCC").value=
		trim(document.getElementById("nameOnCC").value);
		if(document.getElementById("nameOnCC").value.length==0)
		 errorMessage+="Please provide card holder's name \n";
	}
	if(document.getElementById("nameOnCC"))
	{
		document.getElementById("ccNumber").value=
		trim(document.getElementById("ccNumber").value);
		if(document.getElementById("ccNumber").value.length==0)
		 errorMessage+="Please provide credit card number \n";
		else if(document.getElementById("ccNumber").value.length<16)
		 errorMessage+="Credit card number must not be less than 16 digits \n";
	}
	if(document.getElementById("ccExpirationMonth"))
	{	
		if(document.getElementById("ccExpirationMonth").selectedIndex==0)
		 errorMessage+="Please provide credit card expiration month \n";		
	}
	if(document.getElementById("ccExpirationYear"))
	{
		if(document.getElementById("ccExpirationYear").selectedIndex==0)
		 errorMessage+="Please provide credit card expiration year \n";		
	}
	
	if(document.getElementById("billingSameAsMailing"))
	{
		//if billing address is not same as mailing then validate the address
		//components
		if(!document.getElementById("billingSameAsMailing").checked)
		{	
			if(document.getElementById("billingAddress"))
			{
				document.getElementById("billingAddress").value=
				trim(document.getElementById("billingAddress").value);
				if(document.getElementById("billingAddress").value.length==0)
				 errorMessage+="Please provide billing address \n";
			}
			if(document.getElementById("billingCity"))
			{
				document.getElementById("billingCity").value=
				trim(document.getElementById("billingCity").value);
				if(document.getElementById("billingCity").value.length==0)
				 errorMessage+="Please provide city \n";
			}
			if(document.getElementById("billingState"))
			{
				document.getElementById("billingState").value=
				trim(document.getElementById("billingState").value);
				if(document.getElementById("billingState").value.length==0)
				 errorMessage+="Please provide state \n";
			}
			if(document.getElementById("billingZipCode"))
			{
				document.getElementById("billingZipCode").value=
				trim(document.getElementById("billingZipCode").value);
				if(document.getElementById("billingZipCode").value.length==0)
				 errorMessage+="Please provide zip \n";
			}
		}
	}
	
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
	return true;
}

//to validate the company profile
function validateCompanyProfile()
{
	var errorMessage="";
	if(document.getElementById("compXstreet1"))
	{
		document.getElementById("compXstreet1").value=
			trim(document.getElementById("compXstreet1").value);
		if(document.getElementById("compXstreet1").value.length==0)
		 errorMessage+="Please provide Cross Street X \n";

	}
	if(document.getElementById("compXstreet2"))
	{	
		document.getElementById("compXstreet2").value=
			trim(document.getElementById("compXstreet2").value);
		if(document.getElementById("compXstreet2").value.length==0)
		 errorMessage+="Please provide Cross Street Y \n";
	}
	
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
	return true;
}


//to validate login form
function validateLoginForm(from)
{
	var errorMessage="";
	
	if(document.getElementById("userName"))
	{	
		document.getElementById("userName").value=
		trim(document.getElementById("userName").value);
		if(document.getElementById("userName").value.length<6)
		 errorMessage="Username must not be less than 6 characters\n";			
	}
	if(document.getElementById("password"))
	{
		document.getElementById("password").value=
		trim(document.getElementById("password").value);
		if(document.getElementById("password").value.length<6)
		 errorMessage+="Password must not be less than 6 characters\n";
	}
	if(trim(errorMessage))
	{
		alert(errorMessage);
		//return false;
		if(from!="L")
			return false;
	}
	else
	{
		if(from!="L")
		return true;
		else
		document.forms[0].submit();		
	}
		
}

//to validate password retreival form
function validatePwdRetrieveForm()
{
	var errorMessage="";
	
	if(document.getElementById("userName"))
	{	
		document.getElementById("userName").value=
		trim(document.getElementById("userName").value);
		if(document.getElementById("userName").value.length<6)
		 errorMessage="Please input username\n";			
	}
	if(document.getElementById("email"))
	{
		document.getElementById("email").value=
		trim(document.getElementById("email").value);
		if(document.getElementById("email").value.length<6)
		 errorMessage+="Please input email\n";
	}
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
		return true;
		
}

function submitCommuteLogForm(from)
{
	var validationResult=false;
	validationResult=validateCommuteLog();		
	if(validationResult)
	{
		if(from!="L")
		return true;
		else
		document.forms[0].submit();
	}
	else if(!validationResult)
	{		
		if(from!="L") return false;	
	}	
}

function validateCommuteLog()
{
	var errorMessage="";
	var isChecked=false;
	var isDARChoosen=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_mon" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Monday's travel mode\n";

	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_tue" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Tuesday's travel mode\n";
	
	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_wed" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Wednesday's travel mode\n";
	
	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_thu" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Thursday's travel mode\n";
	
	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_fri" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Friday's travel mode\n";

	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_sat" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Saturday's travel mode\n";
	
	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="travelMode_sun" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;
			//if(document.forms[0].elements[i].value=="DAR") isDARChoosen=true;
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide Sunday's travel mode\n";

	if(isDARChoosen)
	{		
		isChecked=false;
		for(i=0;i<document.forms[0].elements.length;i++)
		{
			if(document.forms[0].elements[i].name=="reason_dar" && document.forms[0].elements[i].checked==true)
			{
				isChecked=true;
				if(document.forms[0].elements[i].value=="4")
				{
					if(trim(document.getElementById("reason_dar_other_text").value).length==0)
						errorMessage+="Please provide other reason for choosing alternate driving route\n";
				}
				break;
			}
		}		
		
		if(!isChecked) errorMessage+="Please select a reason for opting for alternative driving route\n";	
	}
	
	//checking for valid compressed day off
	reEvaluateCompressedDayOffSelection();
	
	
	if(trim(errorMessage))
	{
		alert("All the fields in this page are mandatory. However you can come back anytime in the next 14 days and modify the information as many times as you want. Following are the errors that was found while processing the information provided.\n\n"+errorMessage);
		return false;
	}
	else
	return true;
	
}

function reEvaluateCompressedDayOffSelection()
{
	for(j=0;j<document.forms[0].elements.length;j++)
	{
		if(document.forms[0].elements[j].value=="CDO")
		{
			//alert(document.forms[0].elements[j].name+" val= "+document.forms[0].elements[j].value);
			if(document.forms[0].elements[j].checked)
			{
				//alert("here...1.."+document.forms[0].elements[j].name);
				checkIfEligibleForCompressedDayOff(document.forms[0].elements[j]);
			}
		}		
	}	
}

function submitRideMatchCasualRequest(from)
{
	if(document.forms[0].action=="ridematch_request.php")
	return true;
	var validationResult=false;
	validationResult=validateRideMatchCasualRequest();	
	if(validationResult)
	{
		if(from!="L")
		return true;
		else
		document.forms[0].submit();
	}
	else if(!validationResult)
	{		
		if(from!="L") return false;	
	}	
}

function validateRideMatchCasualRequest()
{
	var errorMessage="";
	if(document.getElementById("requestorOrigin").selectedIndex==-1)
	{
		errorMessage="Please select a point of origin\n";
	}
	
	if(document.getElementById("eventDateMonth").selectedIndex==-1)
	{
		errorMessage+="Please select the month of the event\n";
	}
	
	if(document.getElementById("eventDateDay").selectedIndex==-1)
	{
		errorMessage+="Please select the day of the event\n";
	}
	
	if(document.getElementById("eventDateYear").selectedIndex==-1)
	{
		errorMessage+="Please select the year of the event\n";
	}
	
	if(document.getElementById("leaveByHour").selectedIndex==-1)
	{
		errorMessage+="Please select the hour for the time you want to leave\n";
	}
	
	if(document.getElementById("leaveByMinute").selectedIndex==-1)
	{
		errorMessage+="Please select the minute for the time you want to leave\n";
	}
	
	if(document.getElementById("leaveByAmPm").selectedIndex==-1)
	{
		errorMessage+="Please select either A.M. or P.M. for the time you want to leave\n";
	}
	
	isChecked=false;
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="rideDrivePref" && document.forms[0].elements[i].checked==true)
		{
			isChecked=true;			
			break;
		}
	}
	if(!isChecked) errorMessage+="Please provide your ride drive preference\n";
	
	if(document.getElementById("destinationStateFips").selectedIndex==0)
	{
		errorMessage+="Please select your destination state\n";
	}
	
	if(document.getElementById("destinationPoi").selectedIndex==0)
	{
		if(trim(document.getElementById("destinationCrossStreetX").value).length==0 || trim(document.getElementById("destinationCrossStreetY").value).length==0)
		{
			errorMessage+="Please select your destination point of interest or enter your destination cross street X & Y\n";
		}
	}	
	
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
	return true;
}

function getCityWiseBuddycountForSelectedState(stateFips,stateName)
{
	document.forms['stateChoice'].stateFips.value=stateFips;
	document.forms['stateChoice'].stateName.value=stateName;
	document.forms['stateChoice'].submit();
}

function getCityWiseBuddycountForSelectedState_demo(stateFips,stateName)
{	
	document.forms['demoStateChoice'].stateFips.value=stateFips;
	document.forms['demoStateChoice'].stateName.value=stateName;
	document.forms['demoStateChoice'].submit();
}


function getBuddiesForSelectedCity(cityStateId)
{
	document.forms['cityChoice'].cityStateId.value=cityStateId;
	document.forms['cityChoice'].submit();
}

function submitCompanySearchForm()
{	
	if(document.getElementById("compFirstLetter").selectedIndex==-1)
	{
		alert("Please select the first letter of the company you want to search");
		return false;
	}
	return true;
}

function submitAddCompany()
{	
	var validationResult=false;
	validationResult=validateAddCompanyForm();	
	if(validationResult)
	{	
		document.forms[0].action="persist_company_data.php";
		return true;		
	}
	else if(!validationResult)
	{		
	 return false;	
	}
}

function validateAddCompanyForm()
{
	var errorMessage="";
	if(trim(document.getElementById("companyName").value).length==0)
	{
		errorMessage="Please input company name\n";
	}
	if(trim(document.getElementById("streetAddress").value).length==0)
	{
		errorMessage+="Please input street address\n";
	}
	if(trim(document.getElementById("crossStreetX").value).length==0)
	{
		errorMessage+="Please input cross street X\n";
	}
	if(trim(document.getElementById("crossStreetY").value).length==0)
	{
		errorMessage+="Please input cross street Y\n";
	}
	if(!document.getElementById("stateFips").selectedIndex>0)
	{
		errorMessage+="Please select state\n";
	}
	if(!document.getElementById("cityStateId").selectedIndex>0)
	{
		errorMessage+="Please select city\n";
	}
	if(trim(document.getElementById("zipCode").value).length==0)
	{
		errorMessage+="Please input zip code\n";
	}
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
	return true;
}

function submitRidematchSearchForm(from)
{
	if(document.forms[0].action=="ridematch.php")
	return true;
	var validationResult=false;
	validationResult=validateRidematchSearchForm();	
	if(validationResult)
	{
		if(from!="L")
		return true;
		else
		document.forms[0].submit();
	}
	else if(!validationResult)
	{		
		if(from!="L") return false;	
	}		
	
}

function validateRidematchSearchForm()
{
	var errorMessage="";
	if(document.getElementById("searchStateFips").selectedIndex==-1)
	{
		errorMessage="Please select state\n";
	}
	if(document.getElementById("searchOriginZipCode").value.length==0)
	{
		errorMessage+="Please input originating zip\n";
	}	
	if(document.getElementById("searchDestinationZipCode").value.length==0 && (document.getElementById("searchDestinationPoi").selectedIndex==-1 || document.getElementById("searchDestinationPoi").selectedIndex==0))
	{
		errorMessage+="Please input destination zip or select destination point of interest\n";
	}		
	else if(document.getElementById("searchDestinationZipCode").value.length!=0 && document.getElementById("searchDestinationPoi").selectedIndex>0)
	{
		errorMessage+="Please input either destination zip or select destination point of interest\n";
	}
	if(trim(errorMessage))
	{
		alert(errorMessage);
		return false;
	}
	else
	return true;
}

function email_buddies(userId,cmsId)
{
	var buddyIdentifier="";
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].name=="buddyNameEmail" && document.forms[0].elements[i].checked)
		{
			buddyIdentifier+=document.forms[0].elements[i].value+",";
		}
	}
	if(buddyIdentifier.length>0)
	{		
		if(buddyIdentifier.substring((buddyIdentifier.length-1),buddyIdentifier.length)==",")
		buddyIdentifier=buddyIdentifier.substring(0,buddyIdentifier.length-1);
		var strUrl="ridematch_email.php?uid="+userId+"&cmsId="+cmsId+"&bne="+buddyIdentifier;
		winPop(strUrl,420,500);
	}
	else
	{
		alert("Please select buddies to email");
	}
}

function emailBuddyFromRidematchList(userId,cmsId)
{
	var buddyIdentifier="";
	
	buddyIdentifier=document.getElementById("ridematchRequestList").options[document.getElementById("ridematchRequestList").selectedIndex].value;
	if(buddyIdentifier.length>0)
	{		
		//buddyIdentifier=buddyIdentifier.substring(0,buddyIdentifier.length-1);
		var strUrl="ridematch_email.php?uid="+userId+"&cmsId="+cmsId+"&bne="+buddyIdentifier;
		winPop(strUrl,420,500);
	}
	else
	{
		alert("Please select buddies to email");
	}
}


var pansize = 0.80;

function pan(direction)
{
	var x, y;
	
	if(direction == 'n') {
		x = (600-1)/2.0;
		y = 0 - 600*pansize + 600/2.0;
	} 
	else if(direction == 'nw') {
		x = 0 - 600*pansize + 600/2.0;
		y = 0 - 600*pansize + 600/2.0;
	} 
	else if(direction == 'ne') {
		x = (600-1) + 600*pansize - 600/2.0;
		y = 0 - 600*pansize + 600/2.0;
	} 
	else if(direction == 's') {
		x = (600-1)/2.0;
		y = (600-1) + 600*pansize - 600/2.0;
	} 
	else if(direction == 'sw') {
		x = 0 - 600*pansize + 600/2.0;
		y = (600-1) + 600*pansize - 600/2.0;
	} 
	else if(direction == 'se') {
		x = (600-1) + 600*pansize - 600/2.0;
		y = (600-1) + 600*pansize - 600/2.0;
	} 
	else if(direction == 'e') {
		x = (600-1) + 600*pansize - 600/2.0;
		y = (600-1)/2.0;
	} 
	else if(direction == 'w') {
		x = 0 - 600*pansize + 600/2.0;
		y = (600-1)/2.0;
	}
	else if(direction == 'h') {
		document.getElementById("goHome").value=1;
	}
	//alert(x+" / "+y);
	document.forms[0].mapX.value=x;
	document.forms[0].mapY.value=y;
	document.getElementById("zoomInLevel").value=1;
	document.getElementById("zoomOutLevel").value=1;
	document.getElementById("zoom").value=0;
	document.getElementById("panDir").value=1;
	
	//alert("ZSZ = "+document.getElementById("zoomSize").value);
	//alert("Z = "+document.getElementById("zoomSize").value);
	
	document.forms[0].submit();
}

function zoom(zoom)
{
	if(zoom==1)
	{
		var zoomInLevel=document.getElementById("zoomInLevel").value; 
		document.getElementById("zoomInLevel").value=++zoomInLevel;
		document.getElementById("zoomOutLevel").value=1;
	}
	else if(zoom==-1)
	{
		var zoomOutLevel=document.getElementById("zoomOutLevel").value; 
		document.getElementById("zoomOutLevel").value=++zoomOutLevel;
		document.getElementById("zoomInLevel").value=1;
	}
	document.getElementById("zoom").value=zoom;
	document.getElementById("isZoom").value=1;
	document.forms[0].submit();
}

function resetMapParam()
{ 
	document.getElementById("zoom").value=1;
	document.getElementById("city").selectedIndex=0;
	document.getElementById("zipCode").selectedIndex=0;	
}

function enableDriveAltRouteOption(theElement)
{	
	var theElementName=theElement.name;
	var selectedDarOptionDay=theElementName.substr(theElementName.lastIndexOf("_")+1);
	if(theElement.value=="DA" || theElement.value=="CPD" || theElement.value=="VPD")
	{
		document.getElementById("dar_"+selectedDarOptionDay).disabled="";
	}
	else
	{
		document.getElementById("dar_"+selectedDarOptionDay).checked=false;
		document.getElementById("dar_"+selectedDarOptionDay).disabled="disabled";
	}	
}

function logoutUser(param1,param2)
{
	window.location="http://commuteone.tann.com/logout.php?"+param1+"&"+param2;
}

function moveMapToSelectedZipCode()
{
	if(document.getElementById("zipCode").selectedIndex!=0)
	{
		document.getElementById("city").selectedIndex=0;
		document.getElementBy;document.forms[0].submit();	
	}
}

function moveMapToSelectedCity()
{
	if(document.getElementById("city").selectedIndex!=0)
	{
		document.getElementById("zipCode").selectedIndex=0;
		document.getElementBy;document.forms[0].submit();	
	}
}

function getPointsOfInterest(calledFrom)
{
	var stateElementId="";
	var action="";
	if(calledFrom=='R')
	{
		stateElementId="destinationStateFips";
		action="ridematch_request.php";
	}
	else if(calledFrom=='S')
	{
		stateElementId="searchStateFips";
		action="ridematch.php";
	}
	
	if(document.getElementById(stateElementId).selectedIndex>0 && document.getElementById("poiTypeId").selectedIndex>0)
	{
		document.forms[0].action=action;
		document.forms[0].submit();		
	}

}

function calculateWorkHours()
{
	//alert("here");
	arriveWorkHour=document.getElementById("hour_arrive_work").options[document.getElementById("hour_arrive_work").selectedIndex].value;
	arriveWorkMin=document.getElementById("minute_arrive_work").options[document.getElementById("minute_arrive_work").selectedIndex].value;	
	leaveWorkHour=document.getElementById("hour_left_for_home").options[document.getElementById("hour_left_for_home").selectedIndex].value;
	leaveWorkMin=document.getElementById("minute_left_for_home").options[document.getElementById("minute_left_for_home").selectedIndex].value;	
	arriveWorkTimeInMin=(arriveWorkHour*60)+parseInt(arriveWorkMin);
	//alert("ARR W H="+arriveWorkHour+" M="+arriveWorkMin+" TINMIN="+arriveWorkTimeInMin);
	leaveWorkTimeInMin=(leaveWorkHour*60)+parseInt(leaveWorkMin);	
	//alert("ARR W H="+leaveWorkHour+" M="+leaveWorkMin+" TINMIN="+leaveWorkTimeInMin);
	workHoursInMin=leaveWorkTimeInMin-arriveWorkTimeInMin;
	//alert("WH = "+workHoursInMin);
	return workHoursInMin;
}


function checkIfEligibleForCompressedDayOff(theElement)
{
	var noOfEligibleCompDayOff=0;
	var currentCompDayOffSelCount=0;
	var warnMessage="One Compressed Day off is allowed for work days longer than 10 hours per day.\nTwo Compressed Days off is allowed for work days longer than 12 hours per day.";
	var workHours=calculateWorkHours();	
	if(workHours>=600 && workHours<720)
	{	
		noOfEligibleCompDayOff=1;
	}
	else if(workHours>=720)
	{	
		noOfEligibleCompDayOff=2;
	}
	else
	{
		theElement.checked=false;
		alert(warnMessage);
		return;
	}
	
	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].value=="CDO")
		{
			if(document.forms[0].elements[i].checked)
			{
				currentCompDayOffSelCount++;
			}
		}		
	}
	//alert("EL CDO ="+noOfEligibleCompDayOff+" CCDO ="+currentCompDayOffSelCount);
	if(currentCompDayOffSelCount>noOfEligibleCompDayOff)
	{
		theElement.checked=false;
		alert(warnMessage);
	}
	
}



//utility functions

function winPop(url,w,h,myname)
{
  showme=window.open(url,myname,'width='+w+',height='+h+',top=100,left=150,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no')
}

function winPopWithScroll(url,w,h,myname)
{
  showme=window.open(url,myname,'width='+w+',height='+h+',top=100,left=150,resizable=no,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no')
}

function getToTheAddress(pageName)
{
	window.location="http://commuteone.tann.com/"+pageName;
}

/*
function showWindow(thepage) 
{
winoption='menubar=no,status=no,width=420,height=380,titlebar=no,toolbar=no,scrollbars=yes,top=0,left=0';
window.open(thepage, "new", winoption);
}
*/

function trim(s)

{

// Remove leading spaces and carriage returns

while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))

{

s = s.substring(1,s.length);

}

// Remove trailing spaces and carriage returns

while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))

{

s = s.substring(0,s.length-1);

}

return s;

}

