function fieldSelect(id){
	document.getElementById(id).src="img/checked.gif";
}

function setFocus(hello){
		document.getElementById(hello).focus();
		document.getElementById(hello).select();
}

function checkPasswords(){
	
	if(document.getElementById("passwd1").value.length < 5){
		alert("You need to input at least a six-letter password");
		return false;
	}
	else if(document.getElementById("passwd2").value.length < 5){
		alert("You need to repeat that password");
		return false;
	}
	else if(document.getElementById("passwd1").value != document.getElementById("passwd2").value){
		alert("The passwords mismatches, please re-type");
		return false;	
	}
	else 
		return true;
}




function checkPassLength(id){
	if(document.getElementById(id).value.length < 6 && document.getElementById(id).value.length != 0){
		alert("The password must at least contain 6 letter or characters");
		setTimeout("setFocus(\"" + id + "\")", 50);
	}
}

function checkOnlyDigits(hello){
	no = 0;
	var thisString = document.getElementById(hello).value;
	stringLength = thisString.length;
	for(i = 0; i < stringLength; i++){
		currChar = thisString.charAt(i);
		if(currChar != '0' && currChar != '1' 
			&& currChar != '2' && currChar != '3' 
			&& currChar != '4' && currChar != '5' 
			&& currChar != '6' && currChar != '7' 
			&& currChar != '8' && currChar != '9'
			&& currChar != '+' && currChar !='-' && currChar != ' ')
			no++;

	}
	if(no > 0){
		alert("Invalid chars in this field, please enter only digits");
		document.getElementById(hello).focus();
		document.getElementById(hello).select();
		setTimeout("setFocus(\"" + hello  + "\")", 50);
	}
			 
}


function checkEmail(hello){
	emailOK = 0;
	thisString = 0;
	i = 0;
	ok = true;
	thisString = document.getElementById(hello).value;
	stringLength = thisString.length;
	if(stringLength > 0){
		for(i = 0; i < stringLength; i++){
			if(thisString.charAt(i) == '@')
				emailOK = 1;
		}
		if(thisString.charAt(stringLength-4) == '.' || thisString.charAt(stringLength-3) == '.' || thisString.charAt(stringLength-5) == '.')
			emailOK++;
		if(emailOK != 2){
			ok = false;
			alert("Invalid email address, please check your typing");
			//setTimeout("setFocus(\"" + hello  + "\")", 50);
		}
	}
	return ok;
}


function checkRegisterForm(){
	var ok = true;
	
	if(document.getElementById("orgName").value == 0){
		ok = false;
		alert("Please specify your organisation");
	}
	else if(document.getElementById("field").value == 0){
		ok = false;
		alert("Please specify a field");
	}
	else if(document.getElementById("country").value == 0){
		ok = false;
		alert("Please specify country");
	}
	else if(document.getElementById("contactPerson").value == 0){
		ok = false;
		alert("Please specify contact person");
	}
	// FOR THE EMAIL
	else if(document.getElementById("contactEmail").value == 0){
		ok = false;
		alert("Please specify a contact e-mail");
	}
	else if(!checkEmail("contactEmail")){
		ok = false;
	}
	else if(document.getElementById("login").value == 0){
		ok = false;
		alert("Please select a login name");
	}
	else if(document.getElementById("passwd1").value == 0){
		ok = false;
		alert("Please enter a password"); 
	}
	else if(document.getElementById("passwd2"). value  == 0){
		ok = false;
		alert("Please retype the password");
	}
	else if(document.getElementById("passwd1").value != document.getElementById("passwd2").value){
		ok = false;
		alert("The passwords does not match, please try again");
	}
	return ok; 
}

function checkEditForm(){
	var ok = true;
	
	if(document.getElementById("orgName").value == 0){
		ok = false;
		alert("Please specify your organisation");
	}
	else if(document.getElementById("field").value == 0){
		ok = false;
		alert("Please specify a field");
	}
	else if(document.getElementById("country").value == 0){
		ok = false;
		alert("Please specify country");
	}
	else if(document.getElementById("contactPerson").value == 0){
		ok = false;
		alert("Please specify contact person");
	}
	// FOR THE EMAIL
	else if(document.getElementById("contactEmail").value == 0){
		ok = false;
		alert("Please specify a contact e-mail");
	}
	else if(!checkEmail("contactEmail")){
		ok = false;
	}
	else if(document.getElementById("login").value == 0){
		ok = false;
		alert("Please select a login name");
	}
	else if(document.getElementById("passwd1").value != document.getElementById("passwd2").value){
		ok = false;
		alert("The passwords does not match, please try again");
	}
	return ok; 
}
	
		
