/*
FileName - JSFunctions.js 
Purpose  - This file includes the common Javascript functions(validation functions)
		    1) ValidateNumber (allows to enter only digits)
			2) ValidatePrice (allows to enter digits and dot(decimal))
			3) ValidateNull(obj,msg) (validates form fields to be null) parameters - textfield,message
			4) ValidatePhoneFields(obj1,obj2,obj3,msg) (validates null state of those form fields which have three text boxes ..like phone number,SSN)
			5) ValidateEmail(obj) (Validates email address)
Author   - Anjali 
Date(Last Modified) - 10/28/2003
*/

//allows to enter only digits
function ValidateNumber()
{

	if ((event.keyCode>=48) && (event.keyCode<=57))
		return true;
	else
		return false;	
}

//allows to enter digits and dot(decimal)
function ValidatePrice()
{
	if (((event.keyCode>=48) && (event.keyCode<=57)) || (event.keyCode==46))
		return true;
	else
		return false;	
}

//validates form fields to be null
function ValidateNull(obj,msg)
{
	var objFrm = eval(obj);
	if (objFrm.value=="") 
	{
		alert("Please enter the "+msg);
		objFrm.focus();
		return false;
	}
	return true;
}

//validates null state of those form fields which have three text boxes ..like phone number,SSN
function ValidatePhoneFields(obj1,obj2,obj3,msg)
{
	var objFrm1 = eval(obj1);
	var objFrm2 = eval(obj2);
	var objFrm3 = eval(obj3);
	if ((objFrm1.value=="") || (objFrm2.value=="") || (objFrm3.value==""))
	{
		alert("Please enter the "+msg);
		objFrm1.focus();
		return false;
	}
	return true;
}


//validates email address
function ValidateEmail(obj)
{
	var objFrm = eval(obj);
	if (objFrm.value=="")
	{
		alert("Please enter the Email Address");
		objFrm.focus();
		return false;
	}
	else
	{
		if (objFrm.value.indexOf("@")==-1)
		{
			alert("Invalid Email Address! No @ sign.");
			objFrm.focus();
			return false;
		}
		var arr=objFrm.value.split("@");
		if (arr[1].indexOf(".")==-1)
		{
			alert("Invalid Email Address! No dot after @ sign.");
			objFrm.focus();
			return false;
		}
	}
	return true;
}

//validates length of textarea 
function ValidateLength(obj,lth,fieldname)
{
	var objFrm = eval(obj);
	if (objFrm.value.length>lth)
	{
		alert(fieldname +" should not exceed " + lth + " characters");
		objFrm.focus();
		return false;
	}
	return true;
}
