var ua = navigator.userAgent;
var g_fWin32 = (ua.lastIndexOf('Win') != -1) &&  (ua.lastIndexOf('Windows 3.1') == -1) && (ua.lastIndexOf('Win16') == -1);
var g_fMac = (ua.lastIndexOf('Mac') != -1);
var g_fWebTV = (ua.lastIndexOf('WebTV') != -1);
var g_fMSIE6 = (ua.lastIndexOf('MSIE 6.') != -1);
var g_fMSIE5 = (ua.lastIndexOf('MSIE 5.') != -1);
var g_fMSIE4 = (ua.lastIndexOf('MSIE 4.') != -1);
var g_fMSIE3 = (ua.lastIndexOf('MSIE 3.') != -1);
var g_fNS7 = (ua.lastIndexOf('Netscape/7.0') != -1);
var g_fNS4 = (ua.lastIndexOf('Mozilla/4') != -1) && (ua.lastIndexOf('MSIE') == -1);
var g_fNS3 = (ua.lastIndexOf('Mozilla/3') != -1) && (ua.lastIndexOf('MSIE') == -1);
var g_fActiveX = g_fWin32 && (g_fMSIE4 || g_fMSIE5);
var g_fDHTML = (g_fMSIE4 || g_fMSIE5) && g_fNS4;
var arrow;

function AbsoluteY(obj)
{
	var pos = 0;
	while ( obj && obj.offsetParent != null )
	{
		pos += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return pos + 1;
}

function showContextHelp(element) {
	if (!(g_fMSIE4 || g_fMSIE5 || g_fMSIE6)|| g_fMac) return;
	if (!(document.readyState == 'complete')) return;
	if (arrow != null) arrow.style.visibility = "hidden";
	
	// show the appropriate arrow & fyi text
	ctxHelp1.innerHTML = eval('document.all.' + HelpText[element][1] + '.innerHTML');
	arrow = eval('document.all.x' + HelpText[element][0]);
	if (arrow != null) {
		arrow.style.visibility = "visible";
		arrow.innerHTML = '<IMG vspace=0 hspace=0 style=position:relative;left:1; src=' + strImagePath + 'lftarrow.gif>';
		oldArrow = arrow;
		document.all.ctxHelp.style.pixelTop = AbsoluteY(arrow) - Offset;
		window.event.cancelBubble = true;
	}
}

function cancelEvent()
{
	event.cancelBubble = true;
	event.returnValue = false;
}

//Task ID: 2809 - Mark B. 2-8-02
function alphaNumField(elem)
{
	//debugger;
	if (elem.value == '') return true;

	var strElemVal = elem.value;
	if (strElemVal.search(/[^a-z0-9 ]/gi) != -1) {
		var strNewVal = strElemVal.replace(/[^a-z0-9 ]/gi, '');
		elem.value = strNewVal;
		elem.focus();
		cancelEvent();
		alert('You have entered invalid characters in this field. This field can only accept letters and numbers without any special characters like punctuation. For example, "123 Main St. Apt. #444" should be typed as "123 Main St Apt 444". We have removed the incorrect characters. Please review your data before you continue.');
		return false;
	}
	else {
		return true;
	}

}

//Task ID: 2809 - Mark B. 2-8-02
function alphaField(elem)
{
	if (elem.value == '') return true;

	var strElemVal = elem.value;
	if (strElemVal.search(/[^a-z ]/gi) != -1) {
		cancelEvent();
		var strNewVal = strElemVal.replace(/[^a-z ]/gi, '');
		elem.value = strNewVal;
		elem.focus();
		alert('You have entered invalid characters in this field. This field can only accept letters without any special characters like punctuation or numbers. If you need to input a number in this field, please spell it out. For instance, "29 Palms" should be written as "Twentynine Palms". We have removed the incorrect characters. Please review your data before you continue.');
		return false;
	}
	else {
		return true;
	}

}

function cleanNumber(strNum)
{
	if (!strNum) return strNum;
	strNum = replace(strNum, '$', '', 0);
	strNum = replace(strNum, ',', '', 0);
	strNum = replace(strNum, '%', '', 0);	
	return strNum;
}

function replace(buf, szFind, szReplace, lStart)
{
	var lFind = 0;
	var szBuf = new String(buf);
	if (!lStart) lStart = 0;
	while (lFind != -1) {
		lFind = szBuf.indexOf(szFind, lStart);

		if (g_fMSIE3) {
			if (lFind != 0 &&(lFind == '' || lFind == null)) lFind = -1;
		}

		if (lFind != -1) {
			szBuf = szBuf.substring(0,lFind) + szReplace + szBuf.substring(lFind + szFind.length);
			lStart = lFind + szReplace.length;
		}
	}
	return szBuf;
}

function formatField(field, format, decPlaces)
{
	switch (format.toUpperCase()) {
	case 'CURRENCY':
		field.value = formatCurrency(field.value, decPlaces);
		break;
	case 'NUMBER':
		field.value = formatNumber(field.value, decPlaces);
		break;
	case 'PERCENT':
		field.value = formatPercent(field.value, decPlaces);
		break;
	case 'ALPHA':
		alphaField(field);
	case 'ALPHANUMERIC':
		alphaNumField(field);
	}
}

function formatPercent(value, decPlaces)
{
	return formatNumericValue('',value,decPlaces,'%');
}

function formatCurrency(value, decPlaces)
{
	return formatNumericValue('$',value,decPlaces,'');
}

function formatNumber(value, decPlaces)
{
	return formatNumericValue('',value,decPlaces,'');
}

function formatNumericValue(leadChar,value,decPlaces,trailChar)
{
	var numValue = cleanNumber(value);
	if (isNaN(numValue) || numValue=='') return value;
	var strValue = new String(Math.round(eval(numValue)*Math.pow(10,decPlaces)));
	while (strValue.length<=decPlaces) strValue = '0' + strValue
	var decPoint = strValue.length - decPlaces;
	var n;
	if (decPlaces>0) strValue = strValue.substring(0,decPoint) + '.' + strValue.substring(decPoint,strValue.length)
	for (n=decPoint-3; n>0; n=n-3) strValue = strValue.substring(0,n) + ',' + strValue.substring(n,strValue.length)
	return leadChar + strValue + trailChar;
}

function keyHandler(elem, focusObject, count)
{
	if (elem.value.length == count && ((event.keyCode > 47 && event.keyCode < 58) || (event.keyCode > 95 && event.keyCode < 106))) {
		focusObject.select();
	}
}

	function btnSpeak_OnClick()
	// ''''''''''''''''''''''''''''''''''''''''''''''''
	// open child window that allows customers to enter
	// a phone number and talk to customer agent
	// ''''''''''''''''''''''''''''''''''''''''''''''''
	{
		//var strSpeakToAgent = 'sk8l2anhh6eln4sv';
		javascript:window.open('deadend.html','','height=340,width=400,left=100,top=150');void(0)
	}
