//Sample Code
//<script language="javascript" src="include/form_validation.js"></script>
//var myForm = new validateForm("f1")
//myForm.controlProp("first_name",3,1,"First Name Enter Only Characters") 
//myForm.startValidate 'Return true or false

//Control Type
//1	-	Numeric Only
//2	-	Float Value(2 decimal)
//3	-	Enter Characters Only
//4 	- 	Characters with Space
//5	-	Alpha Numeric Only
//6 	- 	Alpah Numeric with space
//7 	-	 Alpha Numeric with hypen
//8	-	Email
//9	-	Url
//10 - Enter Characters

//Option Type
//0	-	Not Required
//1	-	Required

function validateForm(form_name)
{
	this.form_name = form_name
	this.control_name = new Array();
	this.control_type = new Array();
	this.control_option = new Array();
	this.control_msg = new Array();
	this.controlProp = controlProp;
	this.startValidate = startValidate
}
function controlProp(name,type,option,msg)
{
	this.control_name[this.control_name.length]=name;
	this.control_type[this.control_type.length]=type;
	this.control_option[this.control_option.length]=option;
	this.control_msg[this.control_msg.length]=msg;
}
function startValidate()
{
	var fieldcat= new Array(11)
	fieldcat[1]= /^[0-9]+$/
	fieldcat[2]=/^(\b([0-9]{1,13})(((\.{0,1})([0-9]{1,2}))?))$/
	fieldcat[3]= /^[a-zA-Z]+$/					
	fieldcat[4]= /^[a-zA-Z\s]+$/
	fieldcat[5]=/^[a-zA-Z0-9]+$/
	fieldcat[6]= /^[a-zA-Z0-9\s]+$/
	fieldcat[7]= /^[a-zA-Z0-9\-]+$/
	fieldcat[8]=/^[a-zA-Z0-9]+((\_|\.|\-|\~|\'){0,1}[a-zA-Z0-9])+(\@{1})(([a-zA-Z0-9*])(\-?|\_?|\~?))+(\.{1}([a-zA-Z0-9]{2,3}))+$/ //email
	fieldcat[9]=/^\b(([w|W]{3})(\.{1}))+(((\-?|\_?)[a-zA-Z0-9*])*)(\.{1}([a-zA-Z0-9]{2,3}))+$/
	fieldcat[10] = /$/
	
	for(var i=0;i<myForm.control_name.length;i++)
	{
		var control_name = document.forms[myForm.form_name].elements[myForm.control_name[i]]
		var control_value; 
		
		if(control_name.type == "select-one")
			control_value = control_name.options[control_name.selectedIndex].value
		else if(control_name.type == "checkbox")
		{
			if(control_name.checked == true)
				control_value = control_name.value
			else
				control_value = ""
		}		
		else
			control_value = control_name.value
			
		if(control_value == "" && myForm.control_option[i] == 1)
		{
			alert(getControlAlert(control_name.type) + " " + myForm.control_msg[i])
			control_name.focus()
			return false
		}	
		else if(control_value != "")
		{
			if(fieldcat[myForm.control_type[i]].test(control_value) == false)
			{
				alert("Invalid " + myForm.control_msg[i])
				control_name.focus()
				return false
			}	
		}	
	}
	return true
}
function getControlAlert(control_name)
{
switch(control_name)
{
	case "select-one":
		return "Select"
	case "checkbox":
		return "Check"
	default:
		return "Enter"
}
}
