
function openNewWindow( url ) {
	popup = window.open( url , "photo" , "width=500,height=500,MENUBAR=no,scrollbars=no" );
	popup.focus();
}

function calcPoints() {
	var points = 0;

	if( document.forms[0].age.value == "29" ) points += 20;
	if( document.forms[0].age.value == "30-34" ) points += 10;
	if( document.forms[0].age.value == "35-39" ) points += 5;
	if( document.forms[0].age.value == "40" ) points += 0;
	
	if( document.forms[0].education.value == "phd" ) points += 45;
	if( document.forms[0].education.value == "masters" ) points += 35;
	if( document.forms[0].education.value == "degree" ) points += 30;

	if( document.forms[0].achievment.value == "income" ) points += 5;
	if( document.forms[0].achievment.value == "degree" ) points += 5;
	
	if( document.forms[0].englishlanguage.checked ) points += 10;
	if( document.forms[0].maintainence.checked ) points += 10;

	var earnings = new Number ( document.forms[0].earnings.value );

	if( earnings.toString() == "NaN" ) {
		alert( "3a. Declared earnings must be a number with no commas or letters" );
		document.forms[0].earnings.value = 0;
		document.forms[0].earnings.className = "Error";
	} else {
		document.forms[0].earnings.className = "";
	}

	var scaledEarnings = 0;

	switch( document.forms[0].country.value ) {
		case "A" :
			scaledEarnings = earnings;
			break;
		case "B" :
			scaledEarnings = earnings * 2.3;
			break;
		case "C" :
			scaledEarnings = earnings * 3.2;
			break;
		case "D" :
			scaledEarnings = earnings * 5.3;
			break;
		case "E" :
			scaledEarnings = earnings * 11.4;
			break;
	}

	if( scaledEarnings >= 25000 ) points += 5;
	if( scaledEarnings >= 30000 ) points += 10;
	if( scaledEarnings >= 35000 ) points += 5;
	if( scaledEarnings >= 40000 ) points += 5;
	if( scaledEarnings >= 50000 ) points += 5;
	if( scaledEarnings >= 55000 ) points += 5;
	if( scaledEarnings >= 65000 ) points += 5;
	if( scaledEarnings >= 75000 ) points += 5;
	if( scaledEarnings >= 150000 ) points += 35;
	
	document.forms[0].points.value = points;

}

function validateApplicantDetails() {

	var test = true;

	if( document.getElementById( 'firstname' ).value.length < 1 ) test = false;
	if( document.getElementById( 'surname' ).value.length < 1 ) test = false;
	if( document.getElementById( 'email' ).value.length < 1 ) test = false;
	if( document.getElementById( 'nationality' ).value.length < 1 ) test = false;
	if( document.getElementById( 'dobDay' ).value.length < 1 ) test = false;
	if( document.getElementById( 'dobMonth' ).value < 1 ) test = false;
	if( document.getElementById( 'dobYear' ).value.length < 1 ) test = false;
	//if( document.getElementById( 'employment' ).value.length < 1 ) test = false;
	if( document.getElementById( 'qualifications' ).value.length < 1 ) test = false;
	if( document.getElementById( 'institution' ).value.length < 1 ) test = false;
	if( document.getElementById( 'englishdegree' ).value.length < 1 ) test = false;
	//if( document.getElementById( 'ielts' ).value.length < 1 ) test = false;
	//if( document.getElementById( 'experience' ).value.length < 1 ) test = false;
	if( document.getElementById( 'residence' ).value.length < 1 ) test = false;
	//if( document.getElementById( 'income' ).value.length < 1 ) test = false;
	//if( document.getElementById( 'comments' ).value.length < 1 ) test = false;
	
	if( !test ) alert( "Please fill in all the fields marked with an asterisk (*)" );

	if( !emailcheck( document.getElementById( 'email' ).value ) ) {
		test = false;
		alert("Please enter a valid email address");
	}

	return test;
	
}

function emailcheck(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.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) 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 validatePoints() {

	var test = true;

	if( document.getElementById( 'points' ).value < 100 ) test = false;

	if( !test ) alert( "You must have 100 points or more to continue" );

	return test;
}