//
// Validate currency:
//The following line must be include in the HTML file that used this script
//
//<OBJECT classid=CLSID:920B385E-1BDF-11D2-BC87-00A024A86646 height=1 id=CheckConn width=1></OBJECT>Conn Type :
//
function CValidateCurrency_omOut()
{


	if (this.range)
	{
		CheckCur.HRange = this.max;
		CheckCur.LRange = this.min;
	}

	CheckCur.Value = this.value;
	this.value = CheckCur.Value;

	if (CheckCur.IsNegative)
	{
		this.style.color=this.negcolor;
	}
	else
	{
		this.style.color=this.poscolor;
	}

	if (CheckCur.Completed == 0)
	{
	
		CValidateBase_invalid(this, CheckCur.StateAsStr);

		return;
	}

	this.title = CheckCur.StateAsStr;

	if (!CheckCur.State)
		CValidateBase_valid(this);

}
   

function CVCurrency_checkValidity()
{

	if (this.value == "")
	{
		CValidateBase_invalid(this, "Empty Field");
		return;
	}

	CheckCur.CurType = this.CurType;
	if (this.range)
	{
		//el.negative=(el.curmin < 0);
		CheckCur.HRange = this.max;
		CheckCur.LRange = this.min;

	}

	if (event.keyCode == 37)
	{
		return;
	}

	// reseting the range since we only have one obj

	CheckCur.Value = this.value;

	if (event.keyCode == 10 || event.keyCode == 13)
	{
		this.value = CheckCur.Value;
	}
	else
	{
		this.value = CheckCur.ValidInput;
	}

	if (CheckCur.Completed == 0)
	{
		CValidateBase_invalid(this, CheckCur.StateAsStr);
		return;
	}


	// we may have something like CheckSumError
	this.title = CheckCur.StateAsStr;
//	this.keyFiltered = (event.returnValue==false);


}

function CVCurrency(el)
{
	CValidateBase(el);

	el.checkValidity = CVCurrency_checkValidity;
	el.range = 0;

	if (el.CurType)
	{ 
		CheckCur.CurType = el.CurType;
	}
	else
	{
		CheckCur.CurType = "GBP";
	}

	if (el.curmin != null && el.curmax != null)
	{
		el.range = 1;
		CheckCur.HRange = el.curmax;
		CheckCur.LRange = el.curmin;
		if (CheckCur.State)
		{
			el.State = CheckCur.State;
			alert("Check input currency range ");
		}
		el.min = el.curmin;
		el.max = el.curmax;
	}
	


	//
	// this is used to cause validation when the cursor 
	// is not in the control
	//

	el.onmouseout = CValidateCurrency_omOut;
	el.onmousemove = CValidateCurrency_omOut;
	el.onblur = CValidateCurrency_omOut;

	if (!el.negcolor)
	{
		el.negcolor="red";
	}
	if (!el.poscolor)
	{
		el.poscolor="black";
	}
	// This can't be done automatically by the base class
	// ...Shame...

	el.checkValidity();
}




bindings.vcurrency = new CBinding(CVCurrency);

