/* 
Script made by Martial Boissonneault © 2003 http://getElementById.com/
This script may be used and changed freely as long as this msg is intact
Visit http://getElementById.com/ for more free scripts and tutorials.
*/
function isBlank(str){ 
	for(var i=0; i<str.length;i++){ 
	var caractere = str.charAt(i) 
		// check for space, tab and enter
		if((caractere!=" ") && (caractere!="\t") &&(caractere!="\n")){ 
			return false 
		} 
	return true 
	} 
} 

function validateForm(f){ 
var fieldEmpty = ""; 
	// check if input type text and textarea are empty
	for(var noElement=0;noElement<f.elements.length;noElement++){ 
		var element = f.elements[noElement]; 
		if(((element.type == "text")||(element.type == "textarea")) && !element.optional){ 
			if(element.value==null || element.value=="" || isBlank(element.value)){ 
				fieldEmpty = fieldEmpty + "\n - " + element.name; 
			} 
		} 
	} 
	if(fieldEmpty){ 
		alert("those fields are empty:" + "\n" + fieldEmpty);
		return false; 
	} 
	if(!isValidEmail(document.form.email.value)){
		alert("Invalid Email");
		return false;
	 }
	if(!isMatchingEmails(document.form.email.value, document.form.email2.value)){
	 	alert("Email addresses must match");
		document.form.email.focus();
		document.form.email.blur();
		document.form.email.select();
		
		return false;
	}
	return true; 
} 

function resetFields(){ 
	// reset button confirm message
	if(confirm("Are you sure you want to reset ???")) 
		return true; 
	else 
		return false;
} 
// Check that an email address is valid based on RFC 821 (?)
function isValidEmail(email) {
	if (email != '' && email.search) {
      if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
      else return false;
	}
	
   // allow empty strings to return true - screen these with either a 'required' test or a 'length' test
   else return true;
}

function isMatchingEmails(str1, str2){
	if(str1 == str2)
		return true;
	else
		return false;
	
}

function optionalFields(){ 
	// here you set to true all your optional field
	//document.myForm.email.optional=true; 
	//document.form.address.optional=true; 
} 
//changes the colour of the text fields, etc as mouse moves over/in
function changeCSS(obj, bgColor, bdColor, ftColor) {
   	if (document.getElementById) {
		obj.style.backgroundColor = bgColor;
		obj.style.borderColor = bdColor;
		obj.style.color = ftColor;
	}
}
