// JavaScript Document
// common functions used for forms handling
// ******************************************************************
// VALIDATION -------------------------------------------------------
// ******************************************************************
// General validity check for Email addresses
	//Email validation function
	function validEmail(email)
	{	// define the set of invalid characters
		invalidChars =" /:,;"
		// Email field empty??
		if (email=="") { return false; }
		// check for presence of invalid chars
		for (i=0; i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if (email.indexOf(badChar,0) > -1) { return false; }
		}
		// check for #@' positioning
		atPos = email.indexOf("@",1);
		if (atPos == -1) { return false; }
		// check that there isnt more than 1 '@'
		if (email.indexOf("@",atPos+1) > -1) { return false; }
		// check positioning of '.'
		periodPos = email.indexOf(".",atPos);
		if ( periodPos == -1) { return false; }	
		if ( periodPos+3 > email.length) { return false; }
		// above only checks for at least 2 chars after 1st period (including other periods)
		// maybe should check for at least 2 chars after the last period...basically repeat function above
		return true;
	}
// ******************************************************************
// Validate a phone number
	function validPhone(number)
	{
		validNumbers = "0123456789()"
		// if the number is empty it's ok ... it's not compulsory
		// FOR NOW
		if (number=="") {return true; }
		
		// check to see if all chars are numbers
		for (i=0; i<number.length; i++) {
			Char = number.charAt(i);
			if (validNumbers.indexOf(Char,0) < 0) { return false; }
		}
		return true;
	}
// ******************************************************************	
// Validate a group of Radio Buttons
	function validRadioGroup (radioGroup) {
		selected = -1;
		for (i=0; i<radioGroup.length; i++) {
			if (radioGroup[i].checked)  {
				selected = i;
			}
		}
		if (selected == -1) {
			return false;
		}
		return true;
	}
// ******************************************************************
// OTHER COMMON -----------------------------------------------------
// ******************************************************************
// put focus and select
	function FocusAndSelect(What) {
		What.focus();
		What.select();
	}
	

	