

/*--------------------------------------------------|

| validation                                        |

|---------------------------------------------------|

| Copyright (c) 2005-2006 NetCB Solutions(pty)ltd.  |

|                                                   |

| This script contains functions that can be used   |

| for input validation                              |

|--------------------------------------------------*/

// Functions that can be used for input validation on the client side

/**
* Function isEmail()
* Checks whether the supplied str is a valid email or not
*/
function isEmail(email)
{
	//
	// email must end with 2-4 characters
	// email cannot begin with a space( ) or the @ sign.
	// email must have a dot(.) after the @ sign
	
	var alpha="a-zA-Z0-9";
	
	filter="^[^@\\s]+@(["+alpha+"+\\-]+\\.)+["+alpha+"]["+alpha+"]["+alpha+"]["+alpha+"]?$";
	//filter="\b[" +alpha+ "._%-]+@[" +alpha+ ".-]+\.[a-zA-Z]{2,4}\b"
	isemail = new RegExp(filter);

	isemail = email.match(isemail);
	if (isemail != null)
	{
		return true;
	}
	else
	{
		return false;
	}
}

/**
*	function isNumber
*   Checks whether the number provieded is an integer
*
*/
function isNumber(num) {

	//if (num=="")
	//	return false;
	if(isBlank(num)) return false;
		
	var isnum = new RegExp("[0-9]+$");
	return isnum.test(num);

}

/**
    function isBlank() 
	Checks whether the str provided is blank(TRUE) or not(FALSE)
	This function also checks for blank spaces as empty
*/	
function isBlank(str) {

    for(var count = 0; count < str.length; count++) {
        var charac = str.charAt(count);
        if ((charac != ' ')) return false;
    }
  
    return true;

}

/**
	function isOptionSelected()
	Returns true if there is an option selected within a SELECT element in 
	the document referenced.

*/
function isOptionSelected(elementReference) {
	if(elementReference.selectedIndex==-1) return false;
	else return true;
}



	
