	var driverName,at,dot,lat,lstr,ldot,lastdot,driverEmail,driverPassword,driverPhone,driverAddress,crossStreets, employerOccupation,employersCrossStreets,dailyCommute,imageValue,imageField,zipCodeValue;
	
	
	function hitEnter(myfield,e)
	{
		var keycode;
		if (window.event) 
			keycode = window.event.keyCode;
		else if (e) 
			keycode = e.which;
		else 
			return false;
	
		if (keycode == 13) {
			//myfield.form.submit();
			return true;
		}
		else
			return false;
	}
	
	function deleteMyProfile() {
		ret = confirm("Are you sure if want to delete the profile completely? You will lose all data");
		if(ret)
			jx.load("deleteMyProfile.php?driver_id=",function(data) {
					if(data == "success")
					{
						alert('Your profile has been successfully deleted.');
						window.location.href = "dm_dvr_profile_form.htm";
					}
				},'text','post');
	}

	
	/* zero means we're updating, 1 means new record */
	function checkRegistration(bZipRequired){		
				
				captcha = document.getElementById("recaptcha_response_field").value;
		if(captcha == ""){
			alert("You must fill in the reCAPTCHA field in order to submit or update your profile.");
			return false;
		}
				
		driverName = document.getElementById("driverName").value;
		if(driverName == ""){
			alert('Please fill in the name field.');
			document.getElementById("driverName").focus();
			return false;
		}
		
		driverEmail = document.getElementById("driverEmail").value;
			at="@";
			dot=".";
			lat=driverEmail.indexOf(at);
			lstr=driverEmail.length;
			ldot=driverEmail.indexOf(dot);
			lastdot=driverEmail.lastIndexOf(dot);
			
		city = document.getElementById("driverCity").value;
		
		if (city == "vanntest") {
			placesLatLng = new Array();	
		//	alert('marker count:' + iMarkerKindCount );
			for(position=1;position<=iMarkerKindCount;position++)
			{
				placesLatLng[position] = new Array();			
				for(i=0; i<aaGMarkers[position].length; i++) {
					placesLatLng[position][i] = aaGMarkers[position][i].getLatLng();	
				//	alert('marker #' + position + "," i + ": " +  placesLatLng[position][i]);
				}
				convertJsArrayToPhpArray( placesLatLng[position], 'places'+position, 'register' );
			}
		//	return false;
		}
			
		if(driverEmail == ""){
			alert('Please fill in the email field.');
			document.getElementById("driverEmail").focus();
			return false;
		}		
		
		if (driverEmail.indexOf(at)==-1){
		   alert("Invalid E-mail ID (a)");
		   return false;
		}
		if (driverEmail.indexOf(at)==-1 || driverEmail.indexOf(at)==0 || driverEmail.indexOf(at)==lstr){
		   alert("Invalid E-mail ID (b)");
		   return false;
		}
		if (driverEmail.indexOf(dot)==-1 || driverEmail.indexOf(dot)==0 || driverEmail.indexOf(dot)==lstr || driverEmail.substring(lastdot+1)==""){
		    alert("Invalid E-mail ID (c)");
		    return false;
		}
		 
		 if (driverEmail.indexOf(at,(lat+1)) !=-1){
		    alert("Invalid E-mail ID (d)");
		    return false;
		 }

		 if (driverEmail.substring(lat-1,lat)==dot || driverEmail.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID (e)");
		    return false;
		 }

		 if (driverEmail.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID (f)");
		    return false;
		 }
		
		 if (driverEmail.indexOf(" ") !=-1){
		    alert("Invalid E-mail ID (g)");
		    return false;
		 }
				
		if(bZipRequired){
			driverPassword = document.getElementById("driverPassword").value;
			if(driverPassword == ""){
				alert('Please fill in the password field.');
				document.getElementById("driverPassword").focus();
				return false;
			}
		}
		
		driverPhone = document.getElementById("driverPhone").value;
		if(driverPhone == ""){
			alert('Please fill in the phone number.');
			document.getElementById("driverPhone").focus();
			return false;
		}
		driverAddress = document.getElementById("driverAddress").value;
		if(driverAddress == ""){
			alert('Please fill in the address.');
			document.getElementById("driverAddress").focus();
			return false;
		}
		crossStreets = document.getElementById("crossStreets").value;
		if(crossStreets == ""){
			alert('Please fill in the cross streets.');
			document.getElementById("crossStreets").focus();
			return false;
		}
		employerOccupation = document.getElementById("employerOccupation").value;
		if(employerOccupation == ""){
			alert('Please fill in the employer occupation.');
			document.getElementById("employerOccupation").focus();
			return false;
		}
		employersCrossStreets = document.getElementById("employersCrossStreets").value;
		if(employersCrossStreets == ""){
			alert('Please fill in the employer cross streets.');
			document.getElementById("employersCrossStreets").focus();
			return false;
		}
		
		if(document.driverRegistrationForm.driverGender.value == 0){
			alert("Select gender");
			document.driverRegistrationForm.driverGender.focus();
			return false;
		}
		
		dailyCommute = document.getElementById("dailyCommute").value;
		if(dailyCommute == ""){
			alert('Please fill in the daily commute field.');
			document.getElementById("dailyCommute").focus(); 
			return false;
		}
		
		if (!document.driverRegistrationForm.drivingRecord[0].checked &&
				!document.driverRegistrationForm.drivingRecord[1].checked &&
				!document.driverRegistrationForm.drivingRecord[2].checked) {
				alert('Select clean driving record radio button.');				
					return false;
		}
		
		if (document.driverRegistrationForm.validDrivingLicense[0].checked &&
				document.driverRegistrationForm.validDrivingLicense[1].checked) {
				alert('Select valid drivers license radio button.');
					return false;
		}
		if(document.driverRegistrationForm.averageWeekdayMileage.value == 0){
			alert("Select average daily mileage for weekdays");
			document.driverRegistrationForm.averageWeekdayMileage.focus();
			return false;
		}
		if(document.driverRegistrationForm.averageWeekendMileage.value == 0){
			alert("Select average daily mileage for weekends");
			document.driverRegistrationForm.averageWeekendMileage.focus();
			return false;
		}
		
		imageValue = document.getElementById("vehicleimage").value;
		
		if(imageValue!=0){
		imageField = document.getElementById("vehicleimage").value;			
			var strPattern = /\.jpg$|\.jpeg$|\.gif$|\.png$|\.pjpeg$|\.tif$/i
			truth = strPattern.test(imageField);			
			if (truth == 0){
				alert("upload valid image");
				document.getElementById("vehicleimage").focus();
				return false;
			}
		}
		
		// zipCodeValue = document.getElementById("zipCodeValue").value;		
		if (aaGMarkers[1].length < 1) {
			alert("To submit your form, you must place at least one black home marker on the map.");
			return false;
		}

		if (aaGMarkers[1].length > 3) {
			alert("You may not place more than three black home markers on the map. Please use other pin colors for work, and other destinations.");
			return false;
		}
		
		// export the markers from javascript array to hidden html input values:
		placesLatLng = new Array();	
		
		// for each array of placed markers:
		for(iMarkerKind=1;iMarkerKind<=iMarkerKindCount;iMarkerKind++)
		{
			// get the lat long values into another array:
			placesLatLng[iMarkerKind] = new Array();			
			for(i=0; i<aaGMarkers[iMarkerKind].length; i++)
				placesLatLng[iMarkerKind][i] = aaGMarkers[iMarkerKind][i].getLatLng();				
			
			// turns javascript array into list of hidden html inputs:
			convertJsArrayToPhpArray( placesLatLng[iMarkerKind], 'places'+iMarkerKind, 'register' );
		}
	
		
		return true;
	}	
	
	
		
	// Function to convert javascript arrays to php arrays
	// helper method for checkRegistration -- vzm
	function convertJsArrayToPhpArray(array,name,form) {		
        if ( typeof( form ) == 'string' ) {
            form = document.getElementById( form );
        }
        var hidden = null;
        for( index in array ) {
            hidden = document.createElement( 'input' );
            hidden.setAttribute( 'type', 'hidden' );
            hidden.setAttribute( 'name', name + '[' + index +']' );
            hidden.setAttribute( 'value', array[index] );
            form.appendChild( hidden );
           // alert('marker value:' + array[index] + ');

        }
    }

