/**************Copyright 2000 ID Communications Limited************/

function IsComplete(FormName,ElementName,ErrorStr)
{
var FieldOk  = true;
if (document.forms[FormName].elements[ElementName].value == '')
     { 
        if (ErrorStr != "0") alert(ErrorStr);
        document.forms[FormName].elements[ElementName].focus();
        FieldOk = false ;
     }
return (FieldOk);
}
var sMessagingUser;
function UserFeedback(oFormEle)
{ oFormEle.focus();}
function isDigit(c) {return ((c>=0)&&(c<=9)) }
function isEmpty(s) {return ((s==null)&&(s.length==0))}
var whitespace="\t\n\r";
function isWhitespace(s) 
	{var i;
	// Is s empty?
	if (isEmpty(s)) return true;
	
	//search char by char to find a whitespace. If found return false, else retun true
	for (i=0; i<s.length;i++)
	{
	//check that current char isn't whitespace
	var c=s.charAt(i);
	if (whitespace.indexOf(c)==-1)return false;
	}

	// All chars are whitespace
	return true;
	}
function isInt(oFormEle)
{var sValue=oFormEle.value
	// search chars one by one to find a non-numeric char. If found return false, else true
	for (vari=0;i<sValue.length;i++)
		{
		// check current char is a number
		var c=sValue.charAt(i)
		if (c==" ") { } // allow spaces
		else if (!isDigit(c)) 
			{ UserFeedback(oFormEle);
			alert("Please use ony numerals.");
			return false;
			}
		}
// All chars are numbers
return true;
}
function isEmail(s,sEmailError)
{ 
var isEmailOK=false;
isEmailOK=ForceEntry(s,sEmailError,50);
	if (isEmailOK) 
		{// there must be >=1 char before @, so start looking at char 2 (position=1)
		var i=1;
		var sValue=s.value;
		var sLength=sValue.length;
		// look for @
		while ((i<sLength) && (sValue.charAt(i) !="@"))
			{i++}
		if ((i>=sLength) || (sValue.charAt(i) !="."))
			var isEmailOK2=false;
		else i+=2;
		// look for .
		while ((i<sLength) && (sValue.charAt(i)!="."))
			{i++}
		// there must be at least one char after the .
		if ((i>=sLength-1) || (sValue.charAt(i)!="."))
			{var isEmailOK2=false; }
		else
			{isEmailOK2=true;}
		if (isEmailOK2)
			{return true;}
		else
			{alert(sEmailError);
			s.focus();
			return false;
			}
		}
	else
	{return false;}
}
function ForceEntry(val,str,sze)
{var strInput=new String(val.value);
if ((strInput.length>sze) && (sze!=null))
	{ // alert("You have entered too many characters. Expected a maxumin of "+sze+".");
	val.focus();
	return false;
	}
if (isWhitespace(strInput))
	{alert(str);
	val.focus();
	return false;
	}
else	{return true;}
}
function isIntRange(oFormEle,iMin,iMax,sType)
{// first confirm it is an integer
bInt=isInt(oFormEle);
if (bInt)
	{var sVal=oFormEle.value;
	if ((sVal>=iMin)&&((iMax==0) || (sVal<=iMax)))
		{return true;}
	else
		{if (sVal<=iMin)
			{alert("Expected "+sType+" should be greater than "+iMin);}
		else
			{alert(sType+" shoul be less than "+iMax);}
		oFormEle.focus();
		return false;
		}
	}
}

function isDate(s,sDateError)
{
var isDateOK=true;
var sValue=s.value;
var sLength=sValue.length
if (sLength!=8) {isDateOK=false;}
	if (isDateOK)
	{
		for (var i=0;i<sLength;i++)
		{	// check for digits
			if  (!((i!=2)||(i!=5)))
				{ if (!isDigit(sValue.charAt(i))) isDateOK=false}
			//check for '/'
			if ((i==2)||(i==5))
				{ if (sValue.charAt(i) !="/")	isDateOK=false }		
		}
		//check month
		if ( (parseInt(sValue.slice(3,5),10)>12) || (parseInt(sValue.slice(3,5),10)<1) ) isDateOK=false
		//check day
		if ( (parseInt(sValue.slice(0,2),10)>31) || (parseInt(sValue.slice(0,2),10)<1) ) isDateOK=false	
		//check year
		if ( (parseInt(sValue.slice(6,8),10)>99) || (parseInt(sValue.slice(6,8),10)<00) ) isDateOK=false
	}

if (isDateOK) return true;
else
	{alert(sDateError); 
	s.focus(); 
	return false; }

}

function isPrice(s,sPriceError)
{
var isPriceOK=true;
var sValue=s.value;
var sLength=sValue.length
	for (var i=0;i<sLength;i++)
	{	// check for digits and '.'
		if (!isDigit(sValue.charAt(i)))
			if (sValue.charAt(i)!='.')  {isPriceOK=false}
	}
if (isPriceOK) return true;
else
	{alert(sPriceError); 
	s.focus(); 
	return false; }

}