function CValidateBase_onCheck()
{
	CValidateBase_valid(this);
	this.checkValidity();
}

function CValidateBase_onKeyPress()
{

	var kc = event.keyCode;
	var kchar = String.fromCharCode(kc);
	
	// filter specific keys
	if (kc == 13)
	{
		if (this.noenter=="true" || this.noenter==true)
		{
			event.returnValue=false;
		}
	}
	else if (kchar == ".")
	{
		if (this.numeric=="true" || this.numeric==true)
		{
			if (this.value.indexOf(".", 0) >= 0)
			{
				event.returnValue=false;
			}
			if (this.float!="true" && this.float!=true)
			{
				event.returnValue=false;
			}
		}
	}

	else if (kchar == "-")
	{
		if (this.numeric=="true" || this.numeric==true)
		{
			if (this.negative!="true" && this.negative!=true)
			{
				event.returnValue=false;
			}
			else if (this.value.indexOf("-", 0) == 0)
			{
				this.value = this.value.slice(1);
				event.returnValue=false;
			}
			else
			{
				this.value = "-" + this.value;
				event.returnValue=false;
			}
		}
	}
	
	else if (kchar < '0' || kchar > '9')
	{
		if (this.numeric=="true" || this.numeric==true)
		{
			event.returnValue=false;
		}
	}

	this.keyFiltered = (event.returnValue==false);
}

function CValidateBase_onKeyUp()
{

	this.check();

	if (!this.isValid)
	{
		return;
	}
		
	var kc = event.keyCode;
	var kchar = String.fromCharCode(kc);
	
	// if the key has not been filtered out... 
	// ...might need to move to next field.
	
	if (this.keyFiltered==false && (kc > 47 || kc == 32) )
	{
		if (this.nextCtrl != null)
		{
			if ((this.value.length == this.maxLength) || (this.ConnType != null))
			{
				if (this.nextCtrl.focus)
				{
					this.nextCtrl.focus();
				
					if (this.nextCtrl.select)
					{
						this.nextCtrl.select();
					}
				}
			}
			
		}
	}
}

function CValidateBase_checkValidity()
{
	alert("No checkValidity Defined!");
}

function CValidateBase_setVal(val)
{
	this.value = val;
	this.checkValidity();
}

function CValidateBase_doValid()
{
	CValidateBase_valid(this);
}

function CValidateBase_valid(el)
{
	if (!el.submitCtrl.setInvalid)
	{
		bindings[el.submitCtrl.binding].construct(el.submitCtrl);
	}
	
	//var e;
	
	el.title="";
	el.style.backgroundColor="white";

	el.submitCtrl.setValid(el._uid);
	
	el.isValid=true;
}

function CValidateBase_invalid(el, tip)
{
	if (!el.submitCtrl.setInvalid)
	{
		bindings[el.submitCtrl.binding].construct(el.submitCtrl);
	}	
	
	el.title=tip;
	el.style.backgroundColor="mistyrose";
	el.submitCtrl.setInvalid(el._uid);
	el.isValid=false;
}


function EnableInUse( el )
{
	el.inuse = 1;

	// Check the fn exists before we call it so we can call EnableInUse()
	// before the document has loaded
	if ( el.check )
		el.check();
}


function DisableInUse( el )
{
	el.inuse = 0;

	// Don't do this here - just because we are removing an element in a form
	// from the validation process doesn't necessarily mean we want to change
	// the value of the element in any way (also the element may not have a
	// "value" property!)
	//
	// el.value = "";

	// Check the fn exists before we call it so we can call DisableInUse()
	// before the document has loaded
	if ( el.setSubmitValid )
		el.setSubmitValid();
}


function dochange()
{

	this.checkValidity();

}


function CValidateBase(el)
{


	var submitid = "submitbutton";
    if (el.submitid)
	{
		submitid = el.submitid;
	}

	var w;
	var bTop = false;

	var submit;

	for (w=window; !bTop && !submit; w=w.parent )
	{
		submit = w.document.all.item(submitid);
		if
			(submit==null)
		{
		//	alert("elem with id "+ submitid+ " not found in this window ");
		}
		else if
			(submit.length != null)
		{
			submit = submit[0];
		}


		bTop = (w==w.parent);
	}

	//var submit = document.all(submitid, 0);

	if (!submit)
	{
		alert("No submit control with id: " + submitid);
	}
			
	el.submitCtrl = submit;
		
	el._uid=el.sourceIndex + "-" + el.id;

	if (el.nextCtrl)
	{
		el.nextCtrl = document.all(el.nextCtrl, 0);
	}

	// Don't overwrite this:
	el.check = CValidateBase_onCheck;
	
	// events - typically not overridden:
	el.onkeypress = CValidateBase_onKeyPress;
	el.onkeyup  = CValidateBase_onKeyUp;

	// AL changed: the way it's define not seem to work should
	// do checkValidity();
//	el.onchange = CValidateBase_onCheck;
	el.onchange = dochange;


		//	el.onmousemove = CValidateBase_omMove;
		//	el.onmouseout = CValidateBase_omOut;
		
	// overrideables:
	el.checkValidity = CValidateBase_checkValidity;
	el.setval = CValidateBase_setVal;
	el.setSubmitValid = CValidateBase_doValid;

	// inuse=0 --> the field is hidden
	if (el.inuse == 0)
	{
		DisableInUse(el);
	}
}

//-------------------------

function CSubmit_setValid(uid)
{
	var len = this.CSubmit_invalidEls.length;
	var i;
	for(i = 0; i < len; i++)
	{
		if (this.CSubmit_invalidEls[i]==uid)
		{
			this.CSubmit_invalidEls[i]=this.CSubmit_invalidEls[len-1];
			this.CSubmit_invalidEls.length--;

			break; // from the for loop.
		}
	}
	
	if (this.CSubmit_invalidEls.length <= 0)
	{
		this.setEnabled( true );
	}
}

function CSubmit_setInvalid(uid)
{
	var len = this.CSubmit_invalidEls.length;
	var i;
	
	this.setEnabled(false);
	
	for(i=0; i<len; i++)
	{
		if (this.CSubmit_invalidEls[i]==uid)
		{
			return;
		}
	}
	
	this.CSubmit_invalidEls[len]=uid;
}

function CSubmit_setEnabled(bFlag)
{
	this.disabled = !bFlag;
}

function CSubmit(el)
{

	el.setValid = CSubmit_setValid;
	el.setInvalid = CSubmit_setInvalid;
	
	el.setEnabled = CSubmit_setEnabled;
	
	if (!el.CSubmit_invalidEls)
	{
		el.CSubmit_invalidEls = new Array();
	}
	
}

bindings.submit = new CBinding(CSubmit);
