	/*
		PURPOSE			:	JavaScript Functions
		VERSION			:	1.0.0	
		DATE			:	2006-07-02
		DESCRIPTION		:	
	*/

	//Strips the leading and trailing spaces off the string
	function trim(str){
		var n=str;

		while(n.length>0 && n.charAt(0)==' ') {
			n=n.substring(1,n.length);
		}
		while(n.length>0 && n.charAt(n.length-1)==' ') {		
			n=n.substring(0,n.length-1);
		}
		return n;
	}


	//function to submit form through a button
	//SubmitForm(document.forms(0),'filename') -- to call this function
	function SubmitForm(myform,strTargetFile)
	{
		myform.action = strTargetFile;
		myform.submit();
	}
	
	function ValidateEmail(email)
	{
	// a very simple email validation checking. 
	// you can add more complex email checking if it helps 
		var splitted = email.match("^(.+)@(.+)$");
		if(splitted == null) return false;
		if(splitted[1] != null )
		{
		  var regexp_user=/^\"?[\w-_\.]*\"?$/;
		  if(splitted[1].match(regexp_user) == null) return false;
		}
		if(splitted[2] != null)
		{
		  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		  if(splitted[2].match(regexp_domain) == null) 
		  {
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) return false;
		  }// if
		  return true;
		}
		return false;
	}
		
	//function to check if number or not
	function IsNumber(field)
	{
		var charpos = field.value.search("[^0-9]"); 
		if(field.value.length > 0 &&  charpos >= 0) 
			{ 
			return "FALSE";
			}//if 
		else
			return "TRUE";
	}
	
	//functino to alert n' focus
	function AlertFocus(MSG,OBJECT)
	{
		alert(MSG);
		OBJECT.focus();
	}//end of function
		
	/*** functions for ControlPanel ***/	
	function ToggleAll(checked)	{
		len = document.frm_list.elements.length;
		var i = 0;
		for(i = 0; i < len; i++) {
			document.frm_list.elements[i].checked = checked;
		}
	}//end of function

	//function to set status
	function SaveStatus() {
		SubmitForm(document.forms(0),'ToggleStatus.php');
	}

//function to confirm delete
	function ConfirmDelete() {
		var strCon	=	confirm('Remove selected records?');
		if(strCon) {
				SubmitForm(document.forms(0),'Remove.php');
		}else {
			return false;
		}
	}
	/*** Eof unctions for ControlPanel ***/	
