/*
Shared JavaScript Library
*/

function doOnlineHelp()
{
	if(typeof vHelpTopic!='undefined' && vHelpTopic!='')
	{
		jsDialog('dlgHelp', 400, 500, '&topic='+vHelpTopic);
	}
	else
		alert('No help has been defined for this topic.');
}

function insertDatePicker(sFieldName, sTitle)
{
	var vField = eval('document.forms[0].'+sFieldName);
	//hides in read mode
	if(vField) document.write('<a href="javascript:showCalendarControl(document.forms[0].'+sFieldName+');"><img alt="Click to show calendar" src="/icons/calendar.gif" border="0"></a>');
}


//typeahead stuff ---------------------------------

var g_sTypeString = '';

function resetTypeAhead()
{
	g_sTypeString='';
}

function doTypeAhead(e, vField)
{	
	
	if(e.keyCode==27)
	{
		resetTypeAhead();
		return;
	}
	
	//check if an IE browser hit the enter key
	//if they did fire the onchange event
	if(e.keyCode==13 && jsHasProperty(vField, 'onchange') && document.all) //document.all detects IE only
	{
		vField.onchange();
		return;
	}
		
	//http://www.quirksmode.org/js/keys.html
	if(e.keyCode==8) //delete key
	{
		if(g_sTypeString.length>0) g_sTypeString = g_sTypeString.substring(0, g_sTypeString.length-1);
	}
	else
	{
		var sKey = String.fromCharCode(e.charCode || e.keyCode); //String.fromCharCode(e.keyCode);
		g_sTypeString += sKey ;
	}	
	e.returnValue = false;
	window.status = '[' + g_sTypeString + ']';
	var sStr = g_sTypeString;
	if(sStr==null || sStr.length==0) return;
	sStr = sStr.toLowerCase();
	for( i=0; i<vField.length; i++)
	{		
		var sEntry = vField.options[i].text.toLowerCase();		
		if( sEntry.indexOf(sStr)>=0 ) //find anywhere in string
		{			
			//window.status = 'found: ['+sStr + '] at ' + i;
			vField.selectedIndex = i;
			return;
		}
	}
		
}

//end typeahead stuff ---------------------------------



function invalidField( vField, szAlertMessage )
{
	if( jsGetFieldValue(vField) == "")
	{		
		alert( szAlertMessage );
		jsFieldFocus(vField);
		return true;
	}	
	return false;
}

function deleteRecord(sWhat, sID)
{
	if(confirm('Are you sure you want to permanently delete this record?'))
	{
		location.href = 'DeleteItem?OpenAction&what='+ sWhat + '&id='+ sID +'&from=' + escape(location.href);
	}
}


