﻿

// ------------------------------------------------------------------------------------

var oldMSIE = false;

function initializeForm () {

	if ($.browser.msie && $.browser.version.substr(0, 1) <= '7')
		oldMSIE = true;

	$("#country").load("/database/countries.html");

}

// ------------------------------------------------------------------------------------

function validate(form) {

	var errorText;
	var error = false;

	//	Clear all errors from from the previous submission
	
	$('.errorText').remove();
	

  	if (form.firstName.value == "") {
		$('<p class="errorText">Your first name is required<p>').insertAfter('#firstName');
		if (!error)
    		form.firstName.focus();
    	error = true;
  	}
 
   	if (form.lastName.value == "") {
		$('<p class="errorText">Your last name is required<p>').insertAfter('#lastName');
		if (!error)
    		form.lastName.focus();
    	error = true;
  	}
 
 	if (form.organization.value == "") {
 		$('<p class="errorText">An organization name is required<p>').insertAfter('#organization');
   		if (!error)
    		form.organization.focus();
    	error = true;
  	}
 
	if (form.country.options[form.country.selectedIndex].text == "Select a country") {
		$('<p class="errorText">A country name is required<p>').insertAfter('#country');
   		if (!error)
    		form.country.focus();
    	error = true;
  	}

  	if (form.email.value == "" && form.workPhone.value == "") {
		$('<p class="errorText">An email address is required if a telephone number is not supplied.<p>').insertAfter('#email');
		if (!error)
    		form.email.focus();
    	error = true;
  	}

	if (form.human.options[form.human.selectedIndex].text != "Bridge") {
 		$('<p class="errorText">Select the structure common to both images. Hint: Try "Bridge"<p>').insertAfter('#human');
		if (!error)
    		form.reference.focus();
    	error = true;
  	}

	if (error)
		return (false);
	else
		return (true);
}

