//Author:Lars Henrik Rotnes
//lhrotnes@kjelsaas-fotball.no
//*************************************************************************************//
//General validating functions
//*************************************************************************************//
//
//function checkEmail(sEmail, errMsg)						-> validating email fields
//function checkHTML(sField,ignoreColon, errMsg)			-> check for occurence of html chars




/**
*general function for checking an email address.
*
*sEmail, 	string = 	the email to be checked
*errMsg,	string = 	Optional, if this parameter is specified it will be displayed to
*						the user in a alert box when an invalid email address is validated.
*			      		Not provided -> No alertbox
**/
function checkEmail(sEmail, errMsg){
  //first check for html characters
  if( checkHTML(sEmail, false ) == false ){
    if(errMsg){
      alert(errMsg);
    }
    return false;
  }
	var c = new RegExp();
	c = /^.+@([-a-z0-9]+\.)+(\D{2,6})$/i;

	if( (sEmail.length < 3) || c.test(sEmail) == false ){
    if(errMsg){
      alert(errMsg);
    }
    return false;
	}

  //the email address was ok
  return true;
}





/**
*general function for checking strings for html tags/characters. 
*the function return true if the string contains no html charcters
*
*sField, string = the field to be checked
*ignoreColon boolean = 	value that indicate if the field to be checed for ':' character
*errMsg		 string =	Optional, if this parameter is specified it will be displayed to
*						the user in a alert box when an html text is validated.
*			      		Not provided -> No alertbox
**/
function checkHTML(sField,ignoreColon, errMsg){
  if (sField.search) {
		if( (ignoreColon && sField.search(/[\<\>]/) != -1)  || (!ignoreColon && sField.search(/[\<\>\:]/) != -1 )   ){ 
	        if(errMsg){
	          alert(errMsg);
	        }
        	return false;
    	}
	}
	return true;
}