
	//function to validate the text box	
	function tbValidater(txnName,txt ,validType, Req)
	{
		// Checking for the Mandetory field
		//alter ("in validater : " + txt);
		var checkStr = Trim(txt.value);
		//alert ("checkStr : " + checkStr);
		
		if (Req ==1)
		{
			if(checkStr == "")
			{
				alert ("The "+ txnName +" can  not be left blank");
				txt.focus();
				return (false);
			}
		}
		else if ( Req == 0 && checkStr == "")
		{
			return(true);
		}
		
		
		
		if (validType == 1) //only Text with -_
			{ 
				//alert (" the type is " + validType)
				var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'`. ";
				var checkStr = txt.value ;				
				var allValid = true;												
				for (i = 0;  i < checkStr.length;  i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;  j < checkOK.length;  j++)
					if (ch == checkOK.charAt(j))
						break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
				}
				//alert (" the Valid is " + allValid)
				if (!allValid)
				{
					alert("Please enter valid characters in the "+ txnName +" field.");
					txt.focus();
					return (false);
				}								
				return (true)
			}
			
		if (validType == 2) // only for numbers without decimal
			{ 
				
					// creating the vaid string for testing 											
					var checkOK = "0123456789";					
					var checkStr = txt.value ;
					var allValid = true;					
					
					for (i = 0;  i < checkStr.length;  i++)
					{
						ch = checkStr.charAt(i);
						for (j = 0;  j < checkOK.length;  j++)
						if (ch == checkOK.charAt(j))
							break;
						if (j == checkOK.length)
						{
							allValid = false;
							break;
						}
					}
					if (!allValid)
					{
						alert("Please enter only numbers in  " + txnName + " .");	
						txt.focus();
						return (false);
					}
			}
			
			
		if (validType == 3) // alpha numeric with -_
			{ 				
				var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789-_'`.";
				var checkStr = txt.value ;				
				var allValid = true;												
				for (i = 0;  i < checkStr.length;  i++)
				{
					ch = checkStr.charAt(i);
					for (j = 0;  j < checkOK.length;  j++)
					if (ch == checkOK.charAt(j))
						break;
					if (j == checkOK.length)
					{
						allValid = false;
						break;
					}
				}
				if (!allValid)
				{
					alert("Please enter valid characters in the field  "+ txnName +".");
					txt.focus();
					return (false);
				}								
				return (true)
			}
		if (validType == 4) // only for numbers with decimal
			{ 
				
					// creating the vaid string for testing 											
					var checkOK = "0123456789-.";					
					var checkStr = txt.value ;
					var allValid = true;					
					var MyString = new String(checkStr)
					var str=""
					
					for (m = 0;  m < MyString.length;  m++)
					{
					    if(Trim(MyString.charAt(m)) == "-")
					    {
					    }
					    else
					    {
					        str = str + MyString.charAt(m)
					        checkStr = str
					    }
					}
					
					if (str != "")
					{
					    if (isNaN(checkStr))
					    {
						    allValid = false;
					    }
    					
					    if ( allValid==true )
					    {
						    for (i = 0;  i < checkStr.length;  i++)
						    {
							    ch = checkStr.charAt(i);
							    for (j = 0;  j < checkOK.length;  j++)
							    if (ch == checkOK.charAt(j))
								    break;
							    if (j == checkOK.length)
							    {
								    allValid = false;
								    break;
							    }
						    }					
					    }
    										
					    if (!allValid)
					    {
						    alert("Please enter only numbers in  " + txnName + " .");	
						    txt.focus();
						    return (false);
					    }
                    }
			}
		if (validType == 98) // WebSite validator
			{ 					
					// creating the vaid string for testing 					
					//var checkOK = ".";					
					var checkStr = txt.value ;
					
					/*88888888888888888888888888888888
					var allValid = true;
					var dotlen;
					var checkStr1	;
					if (txt.value =="" )
					{					
						checkStr="" 
						strlen=0
					}
					else
					{
						strlen=checkStr.length						
					}
					dotlen=0
					alert(checkStr)
						
					if(strlen > 0)	
					{	while (strlen!=0)
						{	
							alert(checkStr)
							dotpos = checkStr.indexOf(".")
							alert(dotpos+ "dot position")	
							//alert ("first dot at" + dotlen);
							if (dotpos > 0 )		
							{
								
								dotlen=dotlen + 1;
								alert (dotlen+"dot length")
								if (dotlen > 2)
								{										
									alert("dot exceeds")
									allValid = false;
									break;									
								}
							}
							else	
							{
								if (dotlen < =2)
								{										
									alert("not enough dot ")
									allValid = false;
									break;									
								}								
							}				
							checkStr = checkStr.substr(dotpos+1)	
							strlen=checkStr.length																						
						}
						if (!allValid)
						{
							alert("address in webduududh in  " + txnName + " .");							
							txt.focus();
							return (false);
							}
						
					}					
					
					88888888888888888888888888888888	*/
					/*if (!webSiteCheck(txt.value))
					if (!webSiteCheck(txt.value))
					{						
						txt.focus();
						return (false);
					}	
					return (allValid);	*/			
			}

		if (validType == 99) // Email id
			{ 
				
					// creating the vaid string for testing 					
					//var checkOK = "0123456789/- ";					
					//var checkStr = txt.value ;
					var allValid = true;					
					
					if (!emailCheck(txt.value))
					{						
						txt.focus();
						return (false);
					}	
					return (allValid);				
			}
		if (validType == 100) // No validation
			{ 					
					return (true);				
			}

	}

// end of the Text Validity Function 

	
	// web site validator 
	function webSiteCheck (webStr)
		{
			return (true);
			
		}
	
	// email validator
	function emailCheck (emailStr)
	
		 {
			var checkTLD=1;
			var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
			var emailPat=/^(.+)@(.+)$/;
			var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
			var validChars="\[^\\s" + specialChars + "\]";
			var quotedUser="(\"[^\"]*\")";
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
			var atom=validChars + '+';
			var word="(" + atom + "|" + quotedUser + ")";
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
			var matchArray=emailStr.match(emailPat);
			if (matchArray==null)
				{
				alert("Email address seems incorrect (check @ and .'s)");
				return false;	
				}
			var user=matchArray[1];
			var domain=matchArray[2];
				for (i=0; i<user.length; i++) {
				if (user.charCodeAt(i)>127) 
				{
				alert("Ths username contains invalid characters.");
				return false;
				}
		}
			var atomPat=new RegExp("^" + atom + "$");
			var domArr=domain.split(".");
			var len=domArr.length;
			for (i=0;i<len;i++) {
				if (domArr[i].search(atomPat)==-1) {
						alert("The domain name does not seem to be valid.");
						return false;
					}
				}

	//if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	//	{
	//		alert("The email address must end in a well-known domain or two letter " + "country. eg:com,org etc");
	//		return false;
	//	}


	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
		}
	return true;

	}


function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function isblank(s)
{
	for(i=0;i<s.length;i++)
	{
		if(s.charAt(i)!=" ")
			return false;
	}
	return true;
}

function CheckValidString(strValue)
{
    var checkNotOK = ";,--,',.exe,cast(,char(,>,<,=,char (,cast (,.js,script,%3c,%3e,%3b,%2d%2d,uff1"; 
    var InvalidValidString = new String(checkNotOK)
    checkNotOKArr = InvalidValidString.split(",")
	var MyString = new String(strValue)
    var MyNewString = new String(MyString.toLowerCase())
	
	var allValid = true;
	for(i = 0;  i < checkNotOKArr.length-1;  i++)
	{
	   results = MyNewString.indexOf(checkNotOKArr[i])
		if(results != -1)
		{
		    allValid = false;
			break;
		}
	}
	if(!allValid)
    {
        alert("Please enter valid characters.\nCharacters like ' ; ', ' -- ', ' = ', '.js', 'script'  are invalid."); 
        return false;
    }
	return allValid
}



