	var DHTML = (document.getElementById || document.all || document.layers);
	
	function getObjNN4(obj,name)
	{
		var x = obj.layers;
		var foundLayer;
		for (var i=0;i<x.length;i++)
		{
			if (x[i].id == name)
			 	foundLayer = x[i];
			else if (x[i].layers.length)
				var tmp = getObjNN4(x[i],name);
			if (tmp) foundLayer = tmp;
		}
		return foundLayer;
	}	

	function getObj(name)
	{
	  if (document.getElementById)
	  {
	  	this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
	  }
	  else if (document.all)
	  {
			this.obj = document.all[name];
			this.style = document.all[name].style;
	  }
	  else if (document.layers)
	  {
			this.obj = getObjNN4(document,name);
			this.style = this.obj;
	  }
	}

	function ValidatorChangeState(name, show)
	{
		if (!DHTML) return;
		validator = new getObj(name);
		
		if (show)
		{
			validator.style.display = "inline";
		}
		else
		{
			validator.style.display = "none";
		}
	}
	
	function RequiredFieldValidator(value)
	{
		return (value != "");
	}
	
	function Trim(s)
	{
		if (typeof(s) != "string")
			return null;
		
		var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
		return (m == null) ? "" : m[1];
	}					

	function GeneralValidator(control, validator_type, error_msg)
	{
		control.value = Trim(control.value);
		if (validator_type == "RequiredFieldValidator")
		{
			if (control.options)
				valid = RequiredFieldValidator(control.options[control.selectedIndex].value);
			else
				valid = RequiredFieldValidator(control.value);
				
			validator_name = "RequiredFieldValidator_" + control.name;
		}
		else
		{
			alert("Invalid validator type");
			return false;
		}
		
		if (!valid)
		{
			ValidatorChangeState(validator_name, true);								
			alert(error_msg);
			control.focus();
			if (control.select)
				control.select();
			return false;
		}
		else
		{
			ValidatorChangeState(validator_name, false);
			return true;
		}
	}

