/******************************************************************
Author name     :Elaya Manickam Narayanan.
Date Created	:19 June 2000
Purpose		    :Form Field validation
*******************************************************************/


//GENERAL FUNCTIONS

/*To set focus on the first element in the form
*****************************************************************
Purpose	: To set the focus on the first element in a form
Input	: none
Output	: none
Usage   : Call in the LOAD even in the body tag
*****************************************************************/

function setFocus()
{
	document.form1.elements[0].focus();
}
/*To trim leading spaces in the input 
*****************************************************************
Purpose	:To trim leading spaces in the input
Input	: a String
Output	: Trimmed String
*****************************************************************/
function trim(temp)
{
	var len=temp.length;
	var temp1;
	temp1="";
	for(i=0;i<len;i++)
	{
		if(temp.charAt(i)!=" ")		
				break;	
	}	
	for(j=i;j<len;j++)
	{
		temp1=temp1+temp.charAt(j);
	}		
	return temp1;
}

/*To check for spl chars in the input
*****************************************************************
Purpose	: checks for special chars in the input
Input	: a String
Output	: Boolean values - true if present, false if not present
*****************************************************************/

function splCharExists(temp)
{
	//var arr=new Array("!","@","#","%","^","'","&","*","(",")","_","+","-","|","\","{","}","[","]","`","~","<",">","?",",",".");
	var arr=new Array("!","@","#","%","^","'","&","*","(",")","_","+","-","|","\",","{","}","[","]")
	for(i=0;i<temp.length;i++)
		for(j=0;j<arr.length;j++)
			if (temp.charAt(i)==arr[j])
				return true;
	return false;			
}

/*To check if it is a number
*****************************************************************
Purpose	: checks if input is a number or not
Input	: a String
Output	: Boolean values - true if not a number, false if it is
*****************************************************************/
function isNotANumber(temp)
{
	if (isNaN(temp))
		return true;
	else
		return false;	
}

/*To clear all fields in a form and set focus to the top of the form
*****************************************************************
Purpose	: To clear all form fields
Input	: a String with which the fields have to be initialised after clearing
Output	: None, will Set the focus to the first field in the form
*****************************************************************/
function clearAll(temp)
{
	for(i=0;i<form1.length;i++)
	{
		if (document.form1.elements[i].type=="text")
		{
			document.form1.elements[i].value="";
			document.form1.elements[i].value=temp;
		}
		if(document.form1.elements[i].type=="checkbox")
		{
			document.form1.elements[i].checked=false;
		}
	}
	document.form1.elements[0].focus();		
}

/* Converted to regular expression by Ed Toro on 4/21/05
****************************************************************************************
Purpose	: To check for email
Input	: a String to be parsed for email check
Output	: boolean true, if valid email , false if not valid email
*****************************************************************/
function validEmail(temp)
{
	if (temp == null || temp.length == 0) 
       return false;

	var rTest = new RegExp("^[^. \"]([^\\s@\"]){1,}@((\\w+\\-+)|(\\w+\\.))*[a-zA-Z0-9]{1,62}\\.[a-zA-Z]{2,}$");
	return rTest.test(temp);
}

/*To check if input is a valid URL (Added Anew by Elaya Manickam Narayanan, on November 22 '2K)
****************************************************************************************
Purpose	: To check for URL validity
Input	: a String to be parsed for URL check
Output	: boolean true, if valid URL, false if not valid URL
*****************************************************************/
function validURL(temp)
{
//check if there are 5 characters after the last DOT (in case its something like  someurl.shtml)
	//Atleast one dot should exist in URL
	if(temp.lastIndexOf(".")==-1)
		return false;
	//calculate no. of characters after last dot
	var len;
	len=temp.length-temp.lastIndexOf(".")
	len--;
	if(len > 5)		
		return false;
	if(len < 2)
		return false;
	if(!isNaN(temp))
		return false;
//if everything is okay then email is valid , so
	return true;		
}

function checkAdobeReader()
{
    return true;
}