/****************************General Validation Functions*****************************/
/************************************************
Purpose	:	Function to check for integer
Logic	:	Parse the string and find Integers
***********************************************/
function checkNum(instring)
{
	if(instring=="0")
		return true;
	else
	{
		//Radix parameter is given with parseInt to avoid octal conversions
		x = parseInt(instring,10);
		if (isNaN(x))
			return false;
		else
		{
			if(x>0)
				if(instring==x) 
					return true;
				else
					return false;
			else
			return false;
		}
	}

}


//***********************************************
//Purpose	:	To verify the Email format. 
 //***********************************************/
var whitespace="\t\n\r";

function isEmpty(s)
   {
     return((s==null) ||(s.length==0)); 
   }


function isWhitespace(s)
  {
    var i;
    if(isEmpty(s))
    return true;
    for(i=0;i<s.length;i++)
       {
         //Check that current character isn't whitespace
         var c=s.charAt(i);
         if(whitespace.indexOf(c)==-1)
         return false;
       }

//All characters are whitespace
return true;


}

/*function isEmail(s)
{ 
 if(isEmpty(s))
 if(isEmail.arguments.length==1)
  return defaultEmptyOK;
 else
 return (isEmail.arguments[1]==true); 
 
 if(isWhitespace(s)) 
  return false;

//there must be >=1 character before @, so start looking at characters
//posiion 1(ie second character)
var i=1; 
slength=s.length;
while( ( i<slength) && (s.charAt(i) != "@") )
{
 i++;
} 

if( (i >=  s.length) || (s.charAt(i)!= "@"))
  return false;
 else i+=2;
  

while( ( i<slength) && (s.charAt(i) != ".") )
{
 i++;  
}

 
if( (i >=  s.length-1) || (s.charAt(i)!= "."))
  return false;
 else return true; 
 } */

function trim(str)
{
		/* This function trims left and right spaces
		   for a given string	*/

		var lCnt;
		var rCnt;
		var strRev;
		var strRes;

		lCnt=0;
		rCnt=0;
		strRev="";

		// Reverse String
		for(var i=str.length-1;i>=0 ;i--)
		{
			strRev= strRev + str.charAt(i);
		}

		// Take Count of Left spaces
		for(var i=0;i<str.length;i++)
		{
			if(str.charCodeAt(i)!=32)
			{
				break;
			}else
				{
					lCnt=lCnt+1;
				}
		}
		// Take Count of Right spaces

		for(var i=0;i<strRev.length;i++)
		{
			if(strRev.charCodeAt(i)!=32)
			{
				break;
			}else
				{
					rCnt=rCnt+1;
				}
		}
		// Send the Result String
		strRes=str.substr(lCnt,str.length-rCnt-lCnt);
		return strRes;
}

function Length_TextField_Validator()
{
// Check the length of the value of the element named text_name
// from the form named form_name if it's < 3 and > 10 characters
// display a message asking for different input
if ((form_name.text_name.value.length < 3) || (form_name.text_name.value.length > 10))
{
// Build alert box message showing how many characters entered
mesg = "You have entered " + form_name.text_name.value.length + " character(s)\n";
mesg = mesg + "Valid entries are between 3 and 10 characters.\n";
mesg = mesg + "Please verify your input and submit again.";
alert(mesg);
// Place the cursor on the field for revision
form_name.text_name.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
return (true);
}

function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {	
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}
