function jsSetTitle(t)
{
    if (top.frames["Header"])
    {
        var id = top.frames["Header"].document.getElementById('lblPageTitle');
        if (id)
        {
            id.innerHTML = t;
            return;
        }
    }
    //alert('Cannot find Header.lblPageTitle');
}

function SetFocus(id)
{
    var d = document.getElementById(id);
    if ( ! d )
        d = parent.document.getElementById(id);
    if (d)
        d.focus();
}

function jsButtonHigh(e)
{
    if ( ! e )
    {
      //alert('jsButtonHigh: no object!');
      return;
    }
	if (UCase(e.className) != "BUTTONDEAD")
		e.className = "btnMouseOver";
}

function jsButtonLow(e)
{
    if ( ! e )
    {
      //alert('jsButtonLow: no object!');
      return;
    }
	if (UCase(e.className) != "BUTTONDEAD")
		e.className = "btnMouseOut";
}

function IsEnterKey(e)
{
	var keycode = 0;
	if (window.event)
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	return (keycode == 13);
}

function Trim(s)
{
	return RTrim(LTrim(s));
}

function LTrim(s)
{
	return String(s).replace( /^\s*/, "" );
}

function RTrim(s)
{
	return String(s).replace( /\s*$/, "" );
}

function LCase(s)
{
	return String(s).toLowerCase();
}

function UCase(s)
{
	return String(s).toUpperCase();
}

function Len(s)
{
	return String(s).length;
}

function Left(str, n)
{
	if (n <= 0)
		return "";
	if (n > String(str).length)
		return str;
	return String(str).substring(0,n);
}

function Right(s, n)
{
	if (n <= 0)
		return "";
	if (n > String(s).length)
		return s;
	var iLen = String(s).length;
	return String(s).substring(iLen, iLen - n);
}

function IsNumeric(s)
{
	var ValidChars = "0123456789";
	for (var i = 0; i < s.length; i++)
		if (ValidChars.indexOf(s.charAt(i)) == -1)
			return(false);
	return(true);
}

function check_field(fieldID, fieldlabel)
{
	if (frmMain[fieldID].value == "invalid")
	{
		alert('Please pick ' + fieldlabel + '.');
		frmMain[fieldID].focus();
		return false;
	}
	//alert('Examined :' + fieldlabel + ':, fieldID=:' + fieldID + ':.');
	return true;
}

function myparseInt(s)
{
	if (s.charAt(0) == '0' && s.length > 1)
		return s.charAt(1);	// avoid treating as octal
	return parseInt(s);
}

function validateUSDate(strValue) {
/*
Return true if the date is valid (allowed formats: mm/dd/yyyy and m/d/yy)
Separator can be one of:   / . -
*/
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/;

	if (!objRegExp.test(strValue))
		return false; // doesn't match pattern, so is a bad date

	var arrayDate = strValue.split(/\D/);	// split at nondigits into month, day, year
	// dom = "days of months"
	dom = new Array ( 0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	var intMonth = myparseInt(arrayDate[0]);
	if (intMonth < 1 || intMonth > 12)
		return false;

	var intDay = myparseInt(arrayDate[1]); 
	var intYear = parseInt(arrayDate[2]);

	if (intDay <= 0 || intDay > 31)
		return false;

	if (intYear < 100)
	{
		if (intYear > 50)
			intYear += 1900;
		else
			intYear += 2000;
	}
	if (intYear < 1900 || intYear > 2100)
		return false;

	if (intMonth == 2)
	{
		if ( (intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28) )
        	return true;
		else
			return false;
    }  
	if (intDay <= dom[intMonth])
		return true;

	return false;
}


/*
 * Here are 3 "pretty" forms of the typical JavaScript dialogs.  The trick is
 * to use the fancier VBScript dialogs if running on IE.  Note that any file
 * that expects to use these routines MUST INCLUDE THE VBSCRIPT, too.
 *      prettyConfirmCancel(titlebar, message)
 *      prettyConfirmAreYouSure(titlebar, message)
 *      prettyPrompt(titlebar, message, default)
 * Among other differences, the titlebar is always ignored unless running IE.
 */
function prettyConfirmCancel(title,messExtra)
{
	return dualConfirm(
			title,
			"Are you sure you want to discard your changes?", "Press OK to discard, or Cancel to return.",
			"Are you sure you want to cancel?", "Press Yes to proceed, or No to return.",
			messExtra);
}

function prettyConfirmAreYouSure(title,messExtra)
{
	return dualConfirm(
			title,
			"Are you sure?", "Press OK to proceed, or Cancel to return.",
			"Are you sure?", "Press Yes to proceed, or No to return.",
			messExtra);
}

function prettyPrompt(title,mess,def)
{
   retVal = (CanRunVb()) ? makeInputBox(title,mess,def) : prompt(mess,def);
   return retVal;
}

function prettyOK(title,mess)
{
    if (CanRunVb())
    {
        MyMsgBox(title,mess);
    }
    else
    {
        alert(mess);
    }
}

function CanRunVb()
{
    var retval = false;
    try
    {
        // Handy browser tester page http://www.b2knet.com/
        if ( VbFunctionThatReturnsOne() == 1 )
            retval = true;
    }
    catch(err)
    {
        // alert("in catch, testing for VB");
    }
    return retval;
}

function dualConfirm(title,js1,js2,vb1,vb2,messExtra)
{
	s = (messExtra == "") ? "" : "\r\n\r\n" + messExtra;
	if (CanRunVb())
	{
		icon = 3;
		defbut = 1;
		retVal = makeMsgBox(title,vb1+s+"\r\n\r\n"+vb2,icon,4,defbut,0);
		return(retVal==6);
	}
	return confirm(js1+s+"\r\n\r\n"+js2);
}



