function formValidator(){
	// Make quick references to our fields
	var strike = document.getElementById('planestrikeangle');
	var dip = document.getElementById('planedipangle');
	var strikesense = document.getElementById('planestrikesense');
	var dipsense = document.getElementById('planedipsense');
	var latitude = document.getElementById('latitude');
	var longitude = document.getElementById('longitude');
	var scale = document.getElementById('scale');
	
	// Check each input in the order that it appears in the form!
	if(isAtitude(strike, "Strike must be a value from 0 to 90; 0 for NS and 90 for EW; also 0 for horizontal")){
		if(isAtitude(dip, "Dip must be a value from 0 to 90; 0 for horizontal and 90 for vertical")){
			if(isLatitude(latitude, "Latitude must be from -90 (southern hemisphere) to 90 (northern hemisphere)")){
				if(isLongitude(longitude, "Longitude must be from -180 (western hemisphere) to 180 (eastern hemisphere)")){
					if(isScale(scale, "Scale cannot be greater than 100 or less than 0.1")){
						if(isSense(strikesense, dipsense, "The Strike Sense does not match with the Dip Sense")){
							return true;
						}
					}
				}
			}
		}
	}
	
	
	return false;
	
}

function isAtitude(elem, helperMsg){
	var num=elem.value;
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	} else if(num<=90 && num>=0){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isLatitude(elem, helperMsg){
	var num=elem.value;
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	} else if(num<=90 && num>=-90){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isLongitude(elem, helperMsg){
	var num=elem.value;
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	} else if(num<=180 && num>=-180){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isScale(elem, helperMsg){
	var num=elem.value;
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	} else if(num<=100 && num>=0.1){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isSense(selem, delem, helperMsg){

	if(selem.value=="NW" && delem.value=="NE"){
		return true;
	} else if(selem.value=="NW" && delem.value=="SW"){
		return true;
	} else if(selem.value=="NE" && delem.value=="NW"){
		return true;
	} else if(selem.value=="NE" && delem.value=="SE"){
		return true;
	} else if(selem.value=="NS" && delem.value=="E"){
		return true;
	} else if(selem.value=="NS" && delem.value=="W"){
		return true;
	} else if(selem.value=="EW" && delem.value=="N"){
		return true;
	} else if(selem.value=="EW" && delem.value=="S"){
		return true;
	} else if(selem.value=="Horizontal (None)" && delem.value=="Horizontal (0)"){
		return true;
	} else{
		alert(helperMsg);
		delem.focus();
		return false;
	}
}
