/*
Module Name : SSRSJS_textBoxTypeRestrictor
Description : This function can be used to restrict input type for a text field or anysuch field. Currently three types are being handled : AlphaNum, Num and Alpha
Developer : Tajinder Singh Namdhari
Developed On : 12-05-2008
Modified On : 09-10-2009
License : LGPL
Company : SSRSJS Organisation
Website : http://www.ssrsjs.org
*/

/*Procedure to implement SSRSJS_textBoxTypeRestrictor

Call function on 'onKeyUp', 'onKeyPress' or other required event
	
	txtBoxType(trgt,trgtType)
		trgt -> DOM Id for field to be restricted; e.g. txtFname
		trgtType -> Type the field to be restricted to; e.g. alphanum
		
	e.g. <input type='text' id='txtFname' name='txtFname' onKeyUp='txtBoxType(this.id,"alpha");'>
*/


function txtBoxType(trgt,trgtType,except)
{
	var except=((except=='undefined')||(except==null))?'':except;
	switch(trgtType)
	{
		case 'alphanum':
		{
			var restChars=Array("?","/","*","-","_","&","^","%","$","#","@","!","~","`","'",";",":",">","<","[","]","{","}","|","\\","(",")","=","+",",",'"',".");
			var currVal=trgt.value;
			var valLmt=currVal.length;
			var currPos=-1;
			var repDone=0;
			
			for(c=0;c<32;c++)
			{
				if((currVal.indexOf(restChars[c])!=-1)&&(except.indexOf(restChars[c])==-1))
				{
					currVal=currVal.replace(restChars[c],'');
					c--;
					repDone=1;
				}
			}
			if(repDone==1)
			{	trgt.value=currVal;	}
			
			break;
		}
		case 'alpha':
		{
			var restChars=Array("0","1","2","3","4","5","6","7","8","9","?","/","*","-","&","^","%","$","#","@","!","~","_","`","'",";",":",">","<","[","]","{","}","|","\\","(",")","=","+",",",'"',".");
			var currVal=trgt.value;
			var valLmt=currVal.length;
			var currPos=-1;
			var repDone=0;
			
			for(c=0;c<42;c++)
			{
				if((currVal.indexOf(restChars[c])!=-1)&&(except.indexOf(restChars[c])==-1))
				{
					currVal=currVal.replace(restChars[c],'');
					c--;
					repDone=1;
				}
			}
			if(repDone==1)
			{	trgt.value=currVal;	}
			
			break;
		}
		case 'num':
		{
			var restChars=Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","?","/","*","-","&","^","%","$","#","@","!","~","`","'",";",":",">","<","[","]","{","}","|","\\","(",")","=","+",",",'"',".");
			var currVal=trgt.value;
			var valLmt=currVal.length;
			var currPos=-1;
			var repDone=0;
			for(c=0;c<57;c++)
			{
				if(((currVal.indexOf(restChars[c].toLowerCase())!=-1)||(currVal.indexOf(restChars[c].toUpperCase())!=-1))&&((except.indexOf(restChars[c].toUpperCase())==-1)&&(except.indexOf(restChars[c].toLowerCase())==-1)))
				{
					currVal=currVal.replace(restChars[c].toLowerCase(),'');
					currVal=currVal.replace(restChars[c].toUpperCase(),'');
					c--;
					repDone=1;
				}
			}
			if(repDone==1)
			{	trgt.value=currVal;	}
			
			break;
		}
		case 'float':
		{
			var restChars=Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","?","/","*","-","&","^","%","$","#","@","!","~","`","'",";",":",">","<","[","]","{","}","|","\\","(",")","=","+",",",'"'," ");
			var currVal=trgt.value;
			var valLmt=currVal.length;
			var currPos=-1;
			var repDone=0;
			for(c=0;c<56;c++)
			{
				if(((currVal.indexOf(restChars[c].toLowerCase())!=-1)||(currVal.indexOf(restChars[c].toUpperCase())!=-1))&&((except.indexOf(restChars[c].toUpperCase())==-1)&&(except.indexOf(restChars[c].toLowerCase())==-1)))
				{
					currVal=currVal.replace(restChars[c].toLowerCase(),'');
					currVal=currVal.replace(restChars[c].toUpperCase(),'');
					c--;
					repDone=1;
				}
			}
			
			while(currVal.indexOf(' ')!=-1)
			{	currVal = currVal.replace(' ','');	}
			
			if((repDone==1)||(currVal.length>0))
			{	trgt.value=currVal;	}
			
			var dotPos = currVal.indexOf('.');
			if(dotPos !=-1)
			{
				if(currVal.substr(dotPos+1, currVal.length - dotPos -1).indexOf('.')!=-1)
				{
					trgt.value = parseFloat(trgt.value);
				}
			}
			
			break;
		}
	}
}
