// This fuction is to check the special characters.
//fieldname = The Value of the field coming from form.
// message = The Message passed by the user.

function spChars(fieldname,message) 
{
	chars=new Array("~","`","!","#","$","%","^","&","*","(",")","+","=","|","\\","{","}","[","]",":",";","'","/","'","<",">","?",",","\"")
	var varLen=fieldname.value.length
	
	for (var i=0;i<varLen;i++)
		{
			
		 for(j=0 ;j<=chars.length;j++)
			{
			if (fieldname.value.charAt(i) == chars[j]) // to get the position of special character
				{
				strval = fieldname.value.charAt(i) // display the special character
				alert(message +"---- "+strval)				
				return false;
				}
			}
		}
		return true;	
		
}

// This fuction is to check numeric value.
// fieldname = The Value of the field coming from form.
// message = The Message passed by the user.

function digits(fieldname,message)
{
	
	var name = fieldname.value ;
	
		for(i=0;i<name.length;i++)
		{
			newChar = name.substring(i,i+1);
			if ((newChar >= 0 && newChar <= 9)== false)//checking for numeric value
			{
				alert(message);
				return false;
			}
		}
	return true;
	
}

// This fuction is to check alphabet value.
// fieldname = The Value of the field coming from form.
// message = The Message passed by the user.

function alphabet(fieldname,message)
{
	
	var name = fieldname.value ;
	var mess=message;	
		for(i=0;i<name.length;i++)
		{
			newChar = name.substring(i,i+1);
			
			if (((newChar >= 'a' && newChar <= 'z') == false) && ((newChar >= 'A' && newChar <= 'Z') == false)) 
			
			{
				alert(message);
				return false;
			}
		}
	return true;
	
}

// This fuction is to check email validation.
// fieldname = The Value of the field coming from form.
// message = The Message passed by the user.

function emailval(fieldname,message)
{
	//alert("hello");
	//var field = fieldname;  email field
  	var str = fieldname.value; 
	//alert(str);
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
        // Regular expression to check email validation 
  	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
  	if (!reg1.test(str) && reg2.test(str)) //email checking
		{ 				
   			return true;
	  	}
 	else
		{	
			mailval = str;
			alert(message);
			return false;
		}
	
}

// This fuction is to check empty field.
// fieldname = The Value of the field coming from form.
// message = The Message passed by the user.

function chkempty(fieldname,message)
{

		if (fieldname.value < 1) // checking for empty field 
		{
			alert(message);
			return false;			
		}
		return true;
}	

//Empty check Function
function empty()
{
	for(i=0;i<5;i++)
	{
		if(document.forms(0).elements(i).value == "")
		{
			alert("PLEASE FILL" + "   " + document.forms(0).elements(i).name.toUpperCase());
			document.forms(0).elements(i).focus();
			return false;
		}
		
	}
	return true;
}
//To use all these functions on KeyPress
//functions for Numeric,single quote and double quote,special characters
function sp_chars()
{
	if ((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97)) event.returnValue = false;
}
function single_quote()
{
	if (event.keyCode==34 || event.keyCode==39) event.returnValue = false;
}
function chkNumeric()
{
	if (event.keyCode < 46 || event.keyCode > 57) event.returnValue = false;
} 
function chkDate(fdate,message)
{
	strDate = fdate.value;
	//alert(strDate)
	//Must be longer than 7 characters, first (two) digit(s) NOT greater than 12, second (two) digit(s) NOT greater than 31 and last 4 greater than 1900
	if(strDate.length>7&&!(strDate.split("/")[0]*1>31)&&!(strDate.split("/")[1]*1>12)&&!(strDate.split("/")[2]*1<1900))
	{
		return true;	
	}
	else
	{
		alert(message);
		return false;
	}
}
