function Validator(frmname)
{
	this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
		alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
		this.formobj.old_onsubmit = this.formobj.onsubmit;
		this.formobj.onsubmit=null;
	}
	else
	{
		this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}

function set_addnl_vfunction(functionname)
{
	this.formobj.addnlvalidation = functionname;
}

function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}

function form_submit_handler()
{
	for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset && !this.elements[itr].validationset.validate())
		{
			return false;
		}
	}
	if(this.addnlvalidation)
	{
		str =" var ret = "+this.addnlvalidation+"()";
		eval(str);
		if(!ret) return ret;
	}
	return true;
}

function add_validation(itemname,descriptor,errstr)
{
	if(!this.formobj)
	{
		alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
	if(itemobj.length && isNaN(itemobj.selectedIndex) )
	//for radio button; don't do for 'select' item
	{
		itemobj = itemobj[0];
	}
	if(!itemobj)
	{
		alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
		itemobj.validationset = new ValidationSet(itemobj);
	}
	itemobj.validationset.add(descriptor,errstr);
}

function ValidationDesc(inputitem,desc,error)
{
	this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}

function vdesc_validate()
{
	if(!validateInput(this.desc,this.itemobj,this.error))
	{
		this.itemobj.focus();
		return false;
	}
	return true;
}

function ValidationSet(inputitem)
{
	this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}

function add_validationdesc(desc,error)
{
	this.vSet[this.vSet.length]= new ValidationDesc(this.itemobj,desc,error);
}

function vset_validate()
{
	for(var itr=0;itr<this.vSet.length;itr++)
	{
		if(!this.vSet[itr].validate())
		{
			return false;
		}
	}
	return true;
}

/*  checks the validity of an email address entered
*   returns true or false
*/
function validateEmail(email)
{
	var splitted = email.match("^(.+)@(.+)$");
	if(splitted == null) return false;
	if(splitted[1] != null )
	{
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null)
	{
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null)
		{
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null)
				return false;
		}// if
		return true;
	}
	return false;
}

function TestComparison(objValue,strCompareElement,strvalidator,strError)
{
	var bRet=true;
	var objCompare=null;
	if(!objValue.form)
	{
		alert("BUG: No Form object!");
		return false
	}
	objCompare = objValue.form.elements[strCompareElement];
	if(!objCompare)
	{
		alert("BUG: Element with name"+strCompareElement+" not found !");
		return false;
	}
	if(strvalidator != "eqelmnt" && strvalidator != "neelmnt")
	{
		if(isNaN(objValue.value))
		{
			alert(objValue.name+": Should be a number ");
			return false;
		}//if
		if(isNaN(objCompare.value))
		{
			alert(objCompare.name+": Should be a number ");
			return false;
		}//if
	}//if
	var cmpstr="";
	switch(strvalidator)
	{
		case "eqelmnt":
		{
			if(objValue.value != objCompare.value)
			{
				cmpstr = " should be equal to ";
				bRet = false;
			}//if
			break;
		}//case
		case "ltelmnt":
		{
			if(eval(objValue.value) >= eval(objCompare.value))
			{
				cmpstr =  " should be less than ";
				bRet = false;
			}
			break;
		}//case
		case "leelmnt":
		{
			if(eval(objValue.value) >  eval(objCompare.value))
			{
				cmpstr =  " should be less than or equal to";
				bRet = false;
			}
			break;
		}//case
		case "gtelmnt":
		{
			if(eval(objValue.value) <=  eval(objCompare.value))
			{
				cmpstr =  " should be greater than";
				bRet = false;
			}
			break;
		}//case
		case "geelmnt":
		{
			if(eval(objValue.value) < eval(objCompare.value))
			{
				cmpstr =  " should be greater than or equal to";
				bRet = false;
			}
			break;
		}//case
		case "neelmnt":
		{
			if(objValue.value.length > 0 &&	objCompare.value.length > 0 &&	objValue.
