var submitted = false;
show = 'show';
hide = 'hide';
var isIE = false;
if (document.all)
	isIE = true;

function SetFocus()
{
	if (document.frmSearch)
	{
		if (document.frmSearch.query)
			document.frmSearch.query.focus();
	}
}

function ShowCaption(caption)
{
	return window.status = caption;
}

function SubmitFormByLink(name, btnName, func)
{
	//alert(eval('document.' + name + '.' + btnName).value)
	form = eval('document.' + name);
	eval('document.' + name + '.' + btnName).value = 'yes';
	if (!submitted)
	{
		if (func.length > 0)
		{
			x = eval(func);
			if (x)
			{
				submitted = true;
				form.submit();
			}
		}
		else
		{
			submitted = true;
			form.submit();
		}
	}
	return;
}

function SubmitFormByKey(keyValue, FormName, btnName, FuncToRun)
{
	//form = eval('document.' + FormName);
	//eval('document.' + FormName + '.' + btnName).value = 'yes';
}

function ConditionsPopup(fieldName)
{
	url = '/quote/ConditionsPopup.asp?fieldName=' + fieldName;
	opts = 'resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,copyhistory=0,width=550,height=400,modal=yes';
	window.open(url, '_blank', opts);
}

function UpdateStatusCode(url, code, codeMsg)
{
	doNotes = '';
	if (code == 'RE')
	{
		if (confirm('Press OK to add notes to, or cancel to skip.'))
			doNotes = 'yes';
	}
	location.href = url + '?newStatus=' + code + '&doNotes=' + doNotes;
}

function AddDateStamp(name)
{
	for (var fi = 0; fi < document.forms.length; fi++)
	{
		for (var ei = 0; ei < document.forms[fi].length; ei++)
		{
			obj = document.forms[fi].elements[ei];
			if (name == obj.name)
			{
				obj.value = GetDateStamp() + ': \n' + obj.value;
				return;
			}
		}
	}
}

function GetDateStamp()
{
	var mDate = new Date;
	y = mDate.getYear();
	m = mDate.getMonth() + 1;
	d = mDate.getDate();
	t = PadChar(2, '0', mDate.getHours()) + ":" + PadChar(2, '0', mDate.getMinutes()) + ":" + PadChar(2, '0', mDate.getSeconds());
	sDate = m + "/" + d + "/" + y + " " + t;
	return sDate;
}

function PadChar(len, chrX, strX)
{
	strX = new String(strX);
	if (strX.length < len)
	{
		while (strX.length < len)
			strX = chrX + strX;
	}
	return strX;
}

function ShowTip(arrowX,layerX,text)
{
	baseY = 271;
	aLayer = getLayer("TipArrow");
	if (aLayer)
	{
		if (isIE)
			moveLayerTo(aLayer, arrowX, baseY);
		else
			moveLayerTo(aLayer, arrowX, baseY-6);
	}

	oLayer = getLayer("TipWindow");
	tLayer = getLayer("TipWindowInner");
	if (oLayer && tLayer)
	{
		writeToLayer(tLayer, text);
		if (isIE)
			moveLayerTo(oLayer, layerX, baseY+4);
		else
			moveLayerTo(oLayer, layerX, baseY+2);
	}
	return true;
}

function HideTip()
{
	aLayer = getLayer("TipArrow");
	oLayer = getLayer("TipWindow");

	if (aLayer)
		moveLayerTo(aLayer, 0, -1000);
	if (oLayer)
		moveLayerTo(oLayer, 0, -1000);
		
	return true;
}

function OpenPopup(url, width, height)
{
	OpenPopup=window.open(url, '_blank', 'width='+width+',height='+height+',resizable=no,toolbar=no,location=no,statusbar=no');
}

function OpenEmailWindow() 
{
	OpenEmailWindow=OpenPopup('/newmail.asp', 450, 470);
}

function FormatZip()
{
	
	var objkeycode = event.keyCode;

	//allow the ctrl and alt key to function so keyboard refresh and app control still works
	if(event.ctrlKey || event.altKey)
		return true;

	//enable the dash(-)(189) key.  This is needed for zips with extensions.
	if (objkeycode == 189)
		return true;

	//for keyboard num pads
	if(objkeycode > 95 && objkeycode < 106)
	{
		return true;
	}	
			
	//disable all the high end key strokes ie; {}[]|\, etc..
	if (objkeycode > 57)
		return false;
	
	//disable the shiftkey unless its used in sequence with the tabkey.
	if(event.shiftKey && objkeycode == 9)
		return true;
	else if(event.shiftKey)
		return false;
		
	//only except values 0 - 9
	if(objkeycode > 47 && objkeycode < 58)
	{
		return true;
	}
	//disable the alpha keys along with the spacebar
	else if((objkeycode >= 65 && objkeycode <= 90) || objkeycode == 32)
	{
		return false;	
	}
}

function UploadFile(mode)
{
	window.open("/filecenter/FileCenter.asp?mode=" + mode,"UploadWindow","width=660,height=550,left=10,top=10,resizable=no,toolbar=0,location=0");
}

// returns the reverse of the specified string.
function RevStr(str)
{
	revstr = "";
	for (i_revstr = str.length; i_revstr > 0; --i_revstr)
		revstr += str.substring(i_revstr - 1, i_revstr);
	return revstr;
}

function GetFile(id, target)
{
	window.open("/filecenter/GetFile.asp?id=" + id + "&target=" + target,"_blank","width=500,height=400,top=10,left=10,resizable=yes,menubar=yes,toolbar=no,location=no,status=yes,scrollbars=yes");
}