/* author: Mike F Schulz */

/**************************************************
**************************************************/
function validateContactUs( form ) {
	with( form ) {

		if(isWhitespace(surname.value, "Enter your surname")) {
			surname.focus();
			return false;
		}			
		
		if(isWhitespace(firstname.value, "Enter your first name")) {
			firstname.focus();
			return false;
		}			
		
		if(isWhitespace(organisation.value, "Enter your Organisation")) {
			organisation.focus();
			return false;
		}			
		if(valEmail(emailaddress)) return false;
		if(isWhitespace(natureofrequest.value, "Enter your nature of request")) {
			natureofrequest.focus();
			return false;
		}			
				
	}
	return true;
}


/**************************************************
**************************************************/				
function isWhitespace (s, msg) {
	var i;
	// whitespace characters
	var whitespace = " \t\n\r";
			
	// Is s empty?
	if (isEmpty(s)) {
		alert(msg); 
		return true;
	}
				
	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.
				
	for (i = 0; i < s.length; i++) {
    	// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}
				
	// All characters are whitespace.
	alert(msg);
	return true;
}		
	
/**************************************************
**************************************************/				
function isWhitespaceNoMsg (s) { 
	var i;
	// whitespace characters
	var whitespace = " \t\n\r";

	// Is s empty?
	if (isEmpty(s)) return true;

   	// Search through string's characters one by one
	// until we find a non-whitespace character.
	// When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {
      	// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
	}

	// All characters are whitespace.
	return true;
}

/**************************************************
**************************************************/										
function isEmpty(s) {   
	return ((s == null) || (s.length == 0));
}		

/**************************************************
**************************************************/										
function valEmail(el) {
	var invalidChars = " /:,;";
 	if (el.value == "") {
   		alert("Please enter a Email Address.");
		el.focus();
		return (true);
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i);
    	if (el.value.indexOf(badChar,0) != -1) {
		   	alert("The Email Address contains an invalid character, please correct it.");
			el.focus();
			return (true);
	    }
	}
	atPos = el.value.indexOf("@",1);
	if (atPos == -1) {
	   	alert("The Email Address must contain an @ character.");
		el.focus();
		return (true);
	}
	if (el.value.indexOf("@",atPos+1) != -1) {
	   	alert("The Email Address must have letters before the @ character.");
		el.focus();
		return (true);
	}
	periodPos = el.value.indexOf(".",atPos);
	if (periodPos == -1) {
	   	alert("The Email Address must contain a . character.");
		el.focus();
		return (true);
	}
	if (periodPos+3 > el.value.length) {
	   	alert("The Email Address must have letters after the . character.");
		el.focus();
		return (true);
	}
	return (false);
}

/******************************************************/
/******************************************************/
function getElement(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		return document.getElementById;
	}
	else {
		if (document.layers) { // Netscape 4
			return document.id;
		}
		else { // IE 4
			return document.all.id;
		}
	}
	return null
}


