/***********************************************************
* function to set the state of a control and any error
* text
*/
function setCtlState(ctl, blnError) {
	var COLOR_ERROR = "salmon";
	var COLOR_NOERROR = "white";

	if (blnError)
		ctl.style.backgroundColor = COLOR_ERROR;
	else
		ctl.style.backgroundColor = COLOR_NOERROR;
}

//**********************************************************
//*	determine if phone/fax/mobile no is valid
//*
function verifyPhone(strValue, strTitle) {
	var strError = "";
	
	strValue = extractDigits(strValue);

	c = strValue.substr(0,1);
	if (c > "1") {
		strError = strTitle + " must begin with a 0 or 1";
	}
	else if (strValue.length == 10) {
		// reformat
		if (strValue.substr(0,1) != "0" || strValue.substr(0,2) == "04")
			strValue = strValue.substr(0, 4) + " " + strValue.substr(4, 3) + " " + strValue.substr(7, 3);
		else
			strValue = strValue.substr(0, 2) + " " + strValue.substr(2, 4) + " " + strValue.substr(6, 4);
	}
	else if (strValue.length == 6 && strValue.substr(0,2) == "13") {
		strValue = strValue.substr(0, 2) + " " + strValue.substr(2, 2) + " " + strValue.substr(4, 2);
	}
	else {
		strError = strTitle + " must be 10 digits";
	}
	
	this.Valid = (strError == "");
	this.Value = strValue;
	this.Error = strError;
}

//********************************************************
//*	function to determin if character argument is a digit.
//*
function isDigit(chr) {
	return (chr >= '0' && chr <= '9');
}

//********************************************************
//*	function to determin if character argument is alphabetic.
//*
function isAlpha(chr) {
	var rslt;
	
	if (chr == " ")
		rslt = true;
	else if ((chr.toUpperCase() >= "A") && (chr.toUpperCase() <= "Z"))
		rslt = true;
	else
		rslt = false;
	
	return rslt;
}

//********************************************************
//*	determine string contains only digits
//*
function isNumeric(str) {
	var blnRslt = true;
	var c;
	
	for (i=0; i < str.length; i++) {
		c = str.charAt(i);
		if (!isDigit(c))
			blnRslt = false;
	}
	return blnRslt;
}

//********************************************************
//*	function to determine if argument is alphanumeric.
//*
function isAlphaNumeric(str) {
	var rslt = true;
	var i;
	var strChar;
	
	for (i=0; i<str.length; i++) {
		strChar = str.substr(i,1);
		if (isDigit(strChar) || isAlpha(strChar)) {
			// ok
		}
		else {
			rslt = false;
		}
	}
	
	return rslt;
}

//********************************************************
//*  extract digits from string
//*
function extractDigits(strSrc) {
	var strBuf
	var c, i;
	
	strBuf = "";
	for (i = 0; i < strSrc.length; i++) {
		c = strSrc.substr(i, 1);
		if (isDigit(c))
			strBuf += c;
	}
	return strBuf;
}

//********************************************************
//*  extract digits & '.' from string
//*
function extractDecimal(strSrc) {
	var strBuf
	var c, i;
	
	strBuf = "";
	for (i = 0; i < strSrc.length; i++) {
		c = strSrc.substr(i, 1);
		if (isDigit(c) || c == ".")
			strBuf += c;
	}
	return strBuf;
}

//********************************************************
//*  Execute the browsers back command.
//*
function historyBack(intBack) {
	var stepBack = intBack * -1;
	
	if (intBack == '1') {
		history.go(-1);
	}
	else {
		history.go(-2);
	}
		
	//if (intBack == '') {
	//	history.go(-5);
	//}
	//else {
	//	history.go(intBack);
	//}	
	//history.back()
}

function redirect(path) {
	window.navigate(path);
}
