/*
	File name 	:	text_validation.js
	Description	:	This file is for validating text fields
*/

	var length_count = 0;
	var ns = (navigator.appName == "Netscape");


/*
	Function : checknumber
	Parameter: event
	Purpose  : It allows user to enter only numbers.
	Date     : 23.5.06
*/

	
	function check_number(e)
  	{
   		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		 
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END.

		if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126) || (key_index>=65 && key_index<=90) || (key_index>=97 && key_index<=122))
		{
			return false;
		}
		
		return true;
	}
	
	
	/*
	Function  : check_string
	parameter : event
 	purpose   : to provide validation for unwanted illegal characters and also for numbers
	Date      : 24.5.06
*/

	function check_string(e)
  	{

		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END.

		if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126) || (key_index>=48 && key_index<=57))
		{
			return false;
		}
		
		return true;
		
	}


 /*
	Function  : check_number_string
	parameter : event
 	purpose   : to provide validation for unwanted illegal characters
	Date      : 24.5.06
*/


	function check_number_string(e)
  	{

		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.

		if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126))
		{
			return false;
		}
		
		return true;
			
	}
	
	
/*
	Function  : check_number_special
	parameter : event,some special characters
 	purpose   : to provide validation for unwanted illegal characters.
              to allow some special characters passed
	Date      : 31.5.06
*/

	function check_number_special(e,chr1,chr2,chr3,chr4)
  	{

		if(!chr1)
				chr1=0;
		if(!chr2)
				chr2=0;
		if(!chr3)
				chr3=0;
		if(!chr4)
				chr4=0;
	
		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.


		if(key_index == chr1 || key_index == chr2 || key_index == chr3 || key_index == chr4)
		{
			return true;
		}
		else if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126) || (key_index>=65 && key_index<=90) || (key_index>=97 && key_index<=122))
		{
			return false;
		}
		
		return true;		
	}

/*
	Function  : check_string_special
	parameter : event, some special characters
 	purpose   : to provide validation for unwanted illegal characters.
              to allow some special characters passed
	Date      : 31.5.06
*/


	function check_string_special(e,chr1,chr2,chr3,chr4,chr5,chr6,chr7)
  	{

		if(!chr1)
				chr1=0;
		if(!chr2)
				chr2=0;
		if(!chr3)
				chr3=0;
		if(!chr4)
				chr4=0;
		if(!chr5)
				chr5=0;
		if(!chr6)
				chr6=0;
		if(!chr7)
				chr7=0;
	
		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.

		if(key_index == chr1 || key_index == chr2 || key_index == chr3 || key_index == chr4 || key_index == chr5 || key_index == chr6 || key_index == chr7)
		{
			return true;
		}
		else if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126) || (key_index>=48 && key_index<=57))
		{
			return false;
		}
		
		return true;
		
	}



/*
	Function  : check_ns_special
	parameter : event, some special characters
 	purpose   : to provide validation for unwanted illegal characters.
              to allow some special characters passed
	Date      : 31.5.06
*/

	function check_ns_special(e,chr1,chr2,chr3,chr4,chr5,chr6,chr7)
  	{

		if(!chr1)
				chr1=0;
		if(!chr2)
				chr2=0;
		if(!chr3)
				chr3=0;
		if(!chr4)
				chr4=0;
		if(!chr5)
				chr5=0;
		if(!chr6)
				chr6=0;
		if(!chr7)
				chr7=0;

		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.


		if(key_index == chr1 || key_index == chr2 || key_index == chr3 || key_index == chr4 || key_index == chr5 || key_index == chr6 || key_index == chr7)
		{
			return true;
		}
		else if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126))
		{
			return false;
		}
		
		return true;		
	}


/*
	Function  : check_ns_special_textarea
	parameter : event, size limit, text field value, some special characters
 	purpose   : to provide validation for unwanted illegal characters.
              to allow some special characters passed
	Date      : 31.5.06
*/

	function check_ns_special_textarea(e,size,value,chr1,chr2,chr3,chr4,chr5,chr6,chr7)
  	{

		if(!chr1)
				chr1=0;
		if(!chr2)
				chr2=0;
		if(!chr3)
				chr3=0;
		if(!chr4)
				chr4=0;
		if(!chr5)
				chr5=0;
		if(!chr6)
				chr6=0;
		if(!chr7)
				chr7=0;


		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		if(value == "")
		  length_count = 0;
		else
		  length_count = value.length;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.


		if(key_index == 8 || key_index == 0 || key_index == chr1 || key_index == chr2 || key_index == chr3 || key_index == chr4 || key_index == chr5 || key_index == chr6 || key_index == chr7)
		{
			return true;
		}
		else if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126))
		{
			return false;
		}
		else
		{
			if(length_count < size)
				return true;
			else
				return false;
		}
	}
	

/*
	Function  : check_ns_special_search
	parameter : event, some special characters
 	purpose   : to provide validation for unwanted illegal characters.
              to allow some special characters passed,search by enter key.
			  (This is specially written for search text boxes in main screens.
	Date      : 18.10.06
*/

	function check_ns_special_search(e,chr1,chr2,chr3,chr4,chr5,chr6,chr7)
  	{

		if(!chr1)
				chr1=0; 
		if(!chr2)
				chr2=0;
		if(!chr3)
				chr3=0;
		if(!chr4)
				chr4=0;
		if(!chr5)
				chr5=0;
		if(!chr6)
				chr6=0;
		if(!chr7)
				chr7=0;

		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.

//		alert(key_index);


		if(key_index == 13)	//if ENTER key is pressed
		{
			search_by_click(); 
		}
		else if(key_index == chr1 || key_index == chr2 || key_index == chr3 || key_index == chr4 || key_index == chr5 || key_index == chr6 || key_index == chr7)
		{
			return true;
		}
		else if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126))
		{
			return false;
		}
		
		return true;		
	}

/*
	Function : check_number_page_num()
	Parameter: event
	Purpose  : It allows user to enter only numbers and if enter key is pressed, it calls page_number_submit() function.
	Date     : 23.5.06
*/

	
	function check_number_page_num(e,top_bottom)
  	{
   		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		 
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END.

//		alert(top_bottom);

		if(key_index == 13)		//if ENTER key is pressed
		{
			page_number_submit(top_bottom);
		}
		if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126) || (key_index>=65 && key_index<=90) || (key_index>=97 && key_index<=122))
		{
			return false;
		}
		
		return true;
	}
	
	
/*
	Function  : check_number_special_interval()
	parameter : event,some special characters
 	purpose   : to provide submit_start_end_periods() function call when enter key is pressed without validation
				This is specially for songs name search
	Date      : 19.10.06
*/

	function check_number_special_interval(e,chr1,chr2,chr3,chr4)
  	{

		if(!chr1)
				chr1=0;
		if(!chr2)
				chr2=0;
		if(!chr3)
				chr3=0;
		if(!chr4)
				chr4=0;
	
		if(ns)
			var key_index = e.which;
  		else
			var key_index = window.event.keyCode;

		
//It allows TAB, SHIFT+HOME, SHIFT+END, DEL, HOME, END and _.


		if(key_index == 13)
		{
			submit_start_end_periods();
		}
		else if(key_index == chr1 || key_index == chr2 || key_index == chr3 || key_index == chr4)
		{
			return true;
		}
		else if((key_index>=33 && key_index<=47) || (key_index>=58 && key_index<=64) || (key_index>=91 && key_index<=96) || (key_index>=123 && key_index<=126) || (key_index>=65 && key_index<=90) || (key_index>=97 && key_index<=122))
		{
			return false;
		}
		
		return true;		
	}
	
	
/*
	Function  : LTrim
	parameter : text field value
 	purpose   : to remove white spaces in left of string. 
	Date      : 31.5.06
*/
	
	function LTrim(str)
	{
		if (str==null){return null;}
		for(var i=0;str.charAt(i)==" ";i++);
			return str.substring(i,str.length);
	}
	
/*
	Function  : RTrim
	parameter : text field value
 	purpose   : to remove white spaces in right of string.
	Date      : 31.5.06
*/
	function RTrim(str)
	{
		if (str==null){return null;}
		for(var i=str.length-1;str.charAt(i)==" ";i--);
			return str.substring(0,i+1);
	}
	
	/*
	Function  : Trim
	parameter : text field value
 	purpose   : to remove white spaces in both side of string.
	Date      : 31.5.06
*/

	function Trim(str)
	{
		return LTrim(RTrim(str));
	}
	
