//<!-- TOPIC Javascript Libraries -->
// Pops up alert with the provided message
// Include this with amessages.js

// then clear the associated form control
function AlertMsg(iMsg) {
	var szErr = szInvalidParam
	if (iMsg == 1) {
		szErr = szInvalidMsg
	} else if (iMsg == 2) {
		szErr = szBlankMsg
	} 
	alert(szErr)
}

// return true if a valid number or blank
function IsNum(ctlNum) {
    var szIn = ctlNum.value
    var cChar = " "
    var iLen = szIn.length;
    if (iLen && iLen > 1) {
        if (szIn.substring(0,1) == "-")  {
             var szTemp = szIn.substring(1,iLen)
             szIn = szTemp;
        }
    }
    // this will get rid of leading spaces
    while (szIn.substring(0,1) == ' ') 
        szIn = szIn.substring(1, szIn.length);
    
    // this will get rid of trailing spaces 
    while (szIn.substring(szIn.length-1,szIn.length) == ' ')
        szIn = szIn.substring(0, szIn.length-1);

    for (var i = 0; i < szIn.length; i++) {
        cChar = szIn.charAt(i)
        if (cChar < "0" || cChar > "9") {
		AlertMsg(1)
		var szLine = ""
		if (ctlNum.type == "text"		|| 
			ctlNum.type == "textarea" 	||
			ctlNum.type == "password" 	|| 
			ctlNum.type == "file") 
		{
			szLine = "document." + document.forms[document.forms.length - 1].name + "." + ctlNum.name + ".focus(); " + "document." + document.forms[document.forms.length - 1].name + "." + ctlNum.name + ".select()"
		} else {
			szLine = "document." + document.forms[document.forms.length - 1].name + "." + ctlNum.name + ".focus();" 
		}
		setTimeout(szLine, 1);
		return false
        }
    }
    return true
}

// determine if a text input is empty or not. Return false if not empty;
// return true if not blank, and alert with a message and focus on the control
function IsNotBlank(ctlInput) {
	var szStr = "" + ctlInput.value
	var bEmpty = true
	
	if (ctlInput && ctlInput.type && ctlInput.type.indexOf("select") >= 0)
	{
		if (ctlInput.selectedIndex == 0)
		{
			bEmpty = true
		}
		else
		{
			bEmpty = false		
		}
	}
	else
	{
		for (var i=0; i<szStr.length; i++) {
			if (szStr.charAt(i) != " " && szStr.charAt(i) != "") {
				bEmpty =false
				break
			}
		}
		
	}
	if (bEmpty) {
		AlertMsg(2)
		if (ctlInput.type == "text"		|| 
			ctlInput.type == "textarea" 	||
			ctlInput.type == "password" 	|| 
			ctlInput.type == "file") 
		{
			szLine = "document." + document.forms[document.forms.length - 1].name + "." + ctlInput.name + ".focus(); " + "document." + document.forms[document.forms.length - 1].name + "." + ctlInput.name + ".select()"
		} else {
			szLine = "document." + document.forms[document.forms.length - 1].name + "." + ctlInput.name + ".focus();" 
		}
		setTimeout(szLine, 1);
		return false;
	}
	return true;
}
