function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
            return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.lastIndexOf(at)==(lstr-1)){
            return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.lastIndexOf(dot)==(lstr-1)){
		    return false
		}

        if (str.indexOf(at,(lat+1))!=-1){
            return false
        }

        if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
            return false
        }

        if (str.indexOf(dot,(lat+2))==-1){
            return false
        }
		
        if (str.indexOf(" ")!=-1){
            return false
        }

        return true					
}

function checkRadioSelection(group) { 
    for(var i=0; i<group.length; i++)
        if(group[i].checked)
            return true;
} 

function uploadCheckForm(form) {
	if (form.uploadPerson.value == "") {
		alert("Please enter your name.");
		form.uploadPerson.focus();
		return false ;
	}
	if ((form.uploadEmail.value == "") || (echeck(form.uploadEmail.value)==false)) {
        alert("Please enter a valid email address.");
		form.uploadEmail.focus();
		return false ;
	}
	if (form.uploadRegistration.value == "") {
		alert("Please enter the aircraft's registration.");
		form.uploadRegistration.focus();
		return false ;
	}
	if (form.uploadAirline.value == "") {
		alert("Please choose the aircraft's airline or enter a new one if it is not in the pulldown menu yet.");
		form.uploadAirline.focus();
		return false ;
	}
	if (form.uploadManufacturer.value == "") {
		alert("Please choose the aircraft's manufacturer or enter a new one if it is not in the pulldown menu yet.");
		form.uploadManufacturer.focus();
		return false ;
	}
	if (form.uploadGeneric.value == "") {
		alert("Please choose the aircraft's generic type or enter a new one if it is not in the pulldown menu yet.");
		form.uploadGeneric.focus();
		return false ;
	}
	if (form.uploadName.value == "") {
		alert("Please enter the aircraft's name.");
		form.uploadName.focus();
		return false ;
	}
	if (form.uploadPhotoFile.value != "") {
		if (!checkRadioSelection(form.uploadPhotoType)) {
			alert("Please select whether you are uploading a close-up photo.");
			return false ;
		}
		if (form.uploadCountry.value == "") {
			alert("Please choose the country where the photo was taken or enter a new one if it is not in the pulldown menu yet.");
			form.uploadManufacturer.focus();
			return false ;
		}
		if (form.uploadAirport.value == "") {
			alert("Please choose the airport where the photo was taken or enter a new one if it is not in the pulldown menu yet.");
			form.uploadGeneric.focus();
			return false ;
		}
		if ((form.uploadICAO.value == "") || (form.uploadICAO.value.length != "4")) {
			alert("Please enter the airport's 4-letter ICAO code.");
			form.uploadICAO.focus();
			return false ;
		}
		if ((form.uploadIATA.value != "") && (form.uploadIATA.value != "-") && (form.uploadIATA.value.length != "3")) {
			alert("Please enter the airport's 3-letter IATA code.");
			form.uploadIATA.focus();
			return false ;
		}
		if ((form.uploadDateYear.value == "") && (form.uploadDateYear.value.length != "4")) {
			alert("Please enter the year of the date the photo was taken.");
			form.uploadDateYear.focus();
			return false ;
		}
        if ((form.uploadDateMonth.value == "") && (form.uploadDateMonth.value.length != "2")) {
			alert("Please enter the month of the date the photo was taken.");
			form.uploadDateMonth.focus();
			return false ;
		}
        if ((form.uploadDateDay.value == "") && (form.uploadDateDay.value.length != "2")) {
			alert("Please enter the day of the date the photo was taken.");
			form.uploadDateDay.focus();
			return false ;
		}
    }

    return true ;
}
