function IsNumeric(strString)
	   //  check for valid numeric strings	
	   {
	   var strValidChars = "0123456789";
	   var strChar;
	   var blnResult = true;
	
	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
	      {
	      strChar = strString.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	         blnResult = false;
	         }
	      }
	   return blnResult;
}

// A function to validate the E-mail
 function validEmail(email) {
    invalidChars = " /:,;"

  if (email == "") {      // cannot be empty
   return false
  }
  for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters?
   badChar = invalidChars.charAt(i)
   if (email.indexOf(badChar,0) > -1) {
    return false
   }
  }
  atPos = email.indexOf("@",1)   // there must be one "@" symbol
  if (atPos == -1) {
   return false
  }
  if (email.indexOf("@",atPos+1) != -1) { // and only one "@" symbol
   return false
  }
  periodPos = email.indexOf(".",atPos)
  if (periodPos == -1) {     // and at least one "." after the "@"
   return false
  }
  if (periodPos+3 > email.length) {  // must be at least 2 characters after the "."
   return false
  }
  return true
}

function setCourse(val) {
	var courseid = document.getElementById("courseid");
	courseid.value = val;
}

function validateForm(goform){
//  var first = dojo.byId("first");
//  var last = dojo.byId("last");
//  var phone = dojo.byId("phone");
//  var email = dojo.byId("email");
//  var courseid = dojo.byId("courseid");
  
  var first = document.getElementById("first");
  var last = document.getElementById("last");
  var phone = document.getElementById("phone");
  var email = document.getElementById("email");
  var dob = document.getElementById("dob");
  var dl = document.getElementById("dl");
  var dlstate = document.getElementById("dlstate");
  var dlzip = document.getElementById("dlzip");
  var courseid = document.getElementById("courseid");
  var type = document.getElementById("type");
 
  if (type.value.length > 0) {     
  	goform.submit(); 
	return true;
	}

  if (first.value.length == 0) {
    alert('Please enter your first name to continue.');
    first.focus();
    return false;
  } else if (last.value.length == 0) {
    alert('Please enter your last name to continue.');
    last.focus();
    return false;
  } else if ((phone.value.length == 0)||(!IsNumeric(phone.value))||(phone.value.length < 10)) {
    alert('Please enter a valid 10 digit numeric phone number to continue.');
    phone.focus();
    return false;
  } else if ((email.value.length == 0)||!validEmail(email.value)) {
    alert('Please enter your email address to continue.');
    email.focus();
    return false;
  } else if (dob.value.length == 0) {
    alert('Please enter your date of birth to continue.');
    last.focus();
    return false;
  } else if (dl.value.length == 0) {
    alert('Please enter your drivers license number to continue.');
    last.focus();
    return false;
  } else if (dlstate.value.length == 0) {
    alert('Please enter the 2 digit state abbreviation from which your drivers license was issued to continue.');
    last.focus();
    return false;
  } else if (dlzip.value.length == 0) {
    alert('Please enter the zip code on your drivers license to continue.');
    last.focus();
    return false;
  } else if (courseid.value.length == 0) {
    alert('Please select a course to continue.');
    return false;
  } else {
    goform.submit();
  }
}

// Runs load events after the page is loaded instead of before page loads
// From here: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
				window.onload = func;
		} else {
				window.onload = function() {
						if (oldonload) {
								oldonload();
						}
						func();
				}
		}
}

var map = null;
var geocoder = null;
function createPoint(point, address){
    var marker = new GMarker(point);
    var link = "http://maps.google.com/maps?saddr="+address+"&daddr=";
    var label = "<b>Get directions to:</b><br>"+address+"<br><input type=button value='GO' onclick=\"document.location='"+link+"';\">";
  	GEvent.addListener(marker, "click", function() {
    	marker.openInfoWindowHtml(label);
  	});
	return marker;
}

function loadmap() {
		if (GBrowserIsCompatible()) {
		    map = new GMap2(document.getElementById("map"));
			if(map){
				address = "9300 Normandy Blvd, Jacksonville, FL";
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				geocoder = new GClientGeocoder();				
				map.setCenter(new GLatLng(38.0000, -95.677068), 4);
			    if (geocoder) {
				    geocoder.getLatLng(
				      address,
				      function(point) {
				        if (!point) {
				          //alert(address + " not found");
				        } else {
				        	map.addOverlay(createPoint(point,address));
				        	map.setCenter(new GLatLng(point.lat(), point.lng()), 12);
				        }
				      }
				    );
				  }
				
			}
			loadmap2();
		}
}

function loadmap2() {
		if (GBrowserIsCompatible()) {
		    map = new GMap2(document.getElementById("map"));
			if(map){
				address2 = "405 Fox Street, Jacksonville, FL";
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				geocoder = new GClientGeocoder();				
				map.setCenter(new GLatLng(38.0000, -95.677068), 4);
			    if (geocoder) {
				    geocoder.getLatLng(
				      address2,
				      function(point) {
				        if (!point) {
				          //alert(address + " not found");
				        } else {
				        	map.addOverlay(createPoint(point,address2));
				        	map.setCenter(new GLatLng(point.lat(), point.lng()), 12);
				        }
				      }
				    );
				  }
				
			}
		}
}


function goAddCourse(){
	document.goCourse.submit();
}

function deleteCourse(courseid){
	document.goDelCourse.delcourseid.value=courseid;
	document.goDelCourse.submit();
}

function editCourse(courseid){
	document.goEdtCourse.edtcourseid.value=courseid;
	document.goEdtCourse.submit();
}

function getDailyTip(){
	var today = new Date();
	var day = today.getDay();
	var dailytip = "";

	if (day == 0){
		dailytip = "<strong>Be Visible!<strong> Remember that motorists often have trouble seeing motorcycles and reacting in time. Make sure your headlight works and is on day and night. Use reflective strips or decals on your clothing and on your motorcycle. Flash your brake light when you are slowing down and before stopping.";
	} else if (day == 1) {
		dailytip = "<strong>Dress for safety!</strong> Wear a quality helmet and eye protection. Wear bright clothing and a light colored helmet. Wear leather or other thick, protective clothing. Choose long sleeves and pants, over-the-ankle boots, and gloves. Remember - the only thing between you and the road is your protective gear!";
	}  else if (day == 2) {
		dailytip = "<strong>Know your bike and how to use it!</strong> Get formal training and take refresher courses. Practice. Develop your riding techniques before going into heavy traffic. Know how to handle your bike in conditions such as wet or sandy roads, high winds, and uneven surfaces.";
	} else if (day == 3) {
		dailytip = "<strong>Group riding tip</strong> Periodically check the riders following in your rear view mirror. If you see a rider falling behind, slow down so they may catch up. If all the riders in the group use this technique, the group should be able to maintain a fairly steady speed without pressure to ride too fast to catch up.";
	} else if (day == 4) {
		dailytip = "<strong>Prevent Theft!</strong> Keep an eye on your bike. When parking at a public event, check your motorcycle periodically, especially immediately after leaving your bike, to make sure there are no suspicious individuals lurking about.";
	} else if (day == 5) {
		dailytip = "<strong>Prevent Theft!</strong> It isn't necessary that you provide a buyer with the title right away. A written document signed by the seller and buyer indicating price and method of payment can serve as proof of purchase. You can forward the title to the buyer once the check has cleared the bank.";
	} else {
		dailytip = "<strong>Prevent Theft!</strong> When selling your bike, make sure the potential buyer wasn't dropped off by another party and is planning to take a one-way test ride with your bike. Verify that the buyer owns the vehicle he or she arrived with, and that the vehicle is of equal or greater value than your bike.";
	}	            
	return dailytip;
}

function deleteStudent(id){
	document.forms.form2.studentid.value = id;
	document.forms.form2.submit();
}

function editStudent(id){
	document.forms.form3.studentid.value = id;
	document.forms.form3.submit();
}


function deleteComment(id){
	document.forms.form2.commentid.value = id;
	document.forms.form2.submit();
}

function editComment(id){
	document.forms.form3.commentid.value = id;
	document.forms.form3.submit();
}