/**************************************************
 * js-functions.js
 * 10.09.2008
 * prashant@asdrc.net
 *
 **************************************************
 * include this file in body or in header 
 * 
 **************************************************/
	
	//encode url
	function urlencode(str) {
		str = escape(str);
		str = str.replace('+', '%2B');
		str = str.replace('%20', '+');
		str = str.replace('*', '%2A');
		str = str.replace('/', '%2F');
		str = str.replace('@', '%40');
		return str;
	}
	
	// trim string
	function Trim(s) 
	{
		var temp = s;
		return temp.replace(/^\s+/,'').replace(/\s+$/,'');
	}
	
	function Validate_Email(str)
	{
		// validate email address
		// return false if invalid address else true
		
		if (str.indexOf("@") == "-1")
		{			
			return false ;
		} 
		var at= "@" ;
		var dot="." ;
		var lat=str.indexOf(at) ;
		var lstr = str.length ;
		var ldot=str.indexOf(dot) ;
		
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at) + 1 ==lstr)
		{
		   	// checked if @ ia the last charecter			
		   return false ;
		}
		
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot) + 1 == lstr)
		{
			// checked if . presend			
		    return false ;
		}				
		
		return true ;
	}
	
	// allow to type numbers onley call this fuctnion on onkeypress event of textbox
	function isNumberKey(evt)
  	{
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
		{
            return false;
		}
		else
		{
        	return true;
		}
    }


	// check if number return true 
	function IsNumeric(sText)
	{
   		var ValidChars = "0123456789";
   		var IsNumber=true;
   		var Char;
 
	   	for (i = 0; i < sText.length && IsNumber == true; i++) 
      	{ 
      		Char = sText.charAt(i); 
      		if (ValidChars.indexOf(Char) == -1) 
         	{
         		IsNumber = false;
         	}
      	}
   		return IsNumber;   
	}
