<!--
/* -- script-level variables ------------------------------ */
var helperText = " (Please use the 'Select from List' link)";
var childWindow;
var childrenCount = 0;
/* -------------------------------------------------------- */

setBrowseCookie();

<!-- // Common page functions -----------------------------------
function isExplorer() {
    if (window.navigator.appName.toUpperCase() == "MICROSOFT INTERNET EXPLORER")
		return true;
	else
		return false;
}

function registerEnter() {
	var formPOST = document.formPOST;
	if (formPOST) {
	    for (var i = 0; i < formPOST.elements.length; i++) {
		    formPOST.elements[i].onKeyPress = userPressed
	    }
    }
}

function userPressed(event) {
    var frm;
    if (document.formPOST)
	    frm = document.formPOST;
	else
	    frm = document.forms[0];
	
	if (isExplorer()) {
		if (window.event.keyCode == 13)
		    frm.submit();
	}
	else {
		if (event.which == 13)
		    frm.submit();
	}
}

function signOn() {
	if (validate()) {
		document.signOn.action += "?Validate=1";
		document.signOn.submit();
	}
}

function validateSignOn() {
	var errors = "";//

	var username = String(document.signOn.username.value);
	var password = String(document.signOn.password.value);

	if (username.length < 4) errors += "- User name must be at least 4 characters long.\n";
	if (password.length < 4) errors += "- Password must be at least 4 characters long.\n";

	if (errors.length > 0) {
		window.alert("Errors: \n------------------------------------------\n" + errors);
		return false;
	}
	return true;
}

function popup(winurl, winname, width, height, winattribs) {
    if (typeof winattribs == "undefined") {
	    winattribs = 'toolbar=no, location=no, directories=no, status=yes, menubar=yes, resizable=yes, copyhistory=no, scrollbars=yes';
	}
	winattribs += ', width=' + width
	winattribs += ', height=' + height;
	// child open, close it first
	if (parseInt(childrenCount) > 0) {
		childWindow.close();
		childrenCount = 0;
	}
	childWindow = window.open(winurl, winname, winattribs);
	childrenCount = 1;
	childWindow.onUnload = childrenCount = 0;
	childWindow.focus();
}

function closeWindow() {
    if (document.all)
        window.open('','_parent','');
    window.close();
}

function navigateParent(pageAddress) {
    if (parent) {
        parent.window.location.href = pageAddress;
        parent.window.location.reload;
    }
    else
        navigate(pageAddress);
}

function navigate(pageAddress) {
	    window.location.href = pageAddress;
	    window.location.reload;
}

function goBookmark(anchorName) {
    if (dist) {
        var intDistance = parseInt(dist);
        if (!isNaN(intDistance))
            dist = intDistance + 1;
    }
    window.location.href = "#" + anchorName;
}

function reloadParent() {
    //-- Reload parent window to remove any stale data displayed there
    var parentwin = window.opener;
    if (isExplorer())
        parentwin.navigate(parentwin.document.location.href);
    else
        parentwin.location.reload;

    // Close child window
    window.close();
}

function reloadPage() {
    //-- Reload parent window to remove any stale data displayed there
    if (isExplorer()) {
        window.location.href = window.location.href;
    }
    else {
        window.location.href = window.location.href;
    }
}

function printPage() {
    var msg = 'This web site is optimized for Landscape print:\n';
    msg += 'Have you selected Landscape print?\n\n';
    msg += '  - If so, click "OK" to print this page.\n';
    msg += '  - If not, click "Cancel", then, in your browser, select "File", "Page Setup",\n       "Landscape" orientation.' 
    if (confirm(msg))
        window.print();
    return;
}


function setWindowOptions() {
    window.locationbar.visible = false;
    window.menubar.visible = false;
    window.personalbar.visible = false;
    window.scrollbars.visible = false;
    window.statusbar.visible = false;
    window.toolbar.visible = false;
}

function setWindowSize(winwidth, winheight) {
    window.resizeTo(winwidth, winheight)
}
//--------------------------------------------------------------->


<!-- // MacroMedia Image Preload functions -----------------------------------
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//--------------------------------------------------------------->


<!-- // Input handling functions ---------------------------------
function isValidEmailList(str) {
    var email, arrEmail = str.split(',');
    for (var idx = 0; idx < arrEmail.length; idx++) {
        email = Trim(arrEmail[idx]);
        if ((email.length > 0) && (!checkEmail(email)))
            return false;
    }
    return true;
}

function checkEmail(str) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(str)
}

function Trim(str) {
	str = String(str)
	var retString = "";
	var wasLetter = false;

	for(i = 0; i <= str.length; i++)
	{	if (wasLetter || (str.charAt(i) != ' '))
		{	retString = retString + str.charAt(i);
			wasLetter = true;
		}
	}
	wasLetter = false;

	str = retString;
	retString = ""

	for(i = str.length - 1; i >= 0; i--)
	{	if (wasLetter || (str.charAt(i) != ' '))
		{	retString = str.charAt(i) + retString;
			wasLetter = true;
		}
	}
	return String(retString);
}

function safetyTest(input) {
   	if (input.length == 0)
   	    return true;

	// prevent cross-site JavaScripting (detect <, >, /)
	var srchPattern = '(<)|(\%3C)|(>)|(\%3E)|(\/)|(\%2F)';
	// prevent SQL injection (detect ', =, ;, --)
	srchPattern += '|(\')|(\%27)|(=)|(\%3D)|(;)|(\%3B)|(\-\-)|(\%23\%23)';

	var myRegExp = new RegExp(srchPattern, "i");
	if (myRegExp.test(input))
	    return false;
	else
	    return true;
}

function trim(str) {
    return Trim(str);
}

function replace(strOrig, oldStr, newStr) {
    var firstPart = strOrig.substring(0, strOrig.indexOf(oldStr));
    var lastPart = strOrig.substring(strOrig.indexOf(oldStr) + oldStr.length, strOrig.length);
    return (firstPart + newStr + lastPart);
}

function populateParentInput(label, selection, uid) {
    if (typeof uid == 'undefined') {
        uid = '-1';
    }
    else {
        var hiddenElement = eval("window.opener.document.formPOST." + inputName + "Hidden");
    }
    var msg;
    var inputElement = eval("window.opener.document.formPOST." + inputName);
    
    if (String(inputElement.value).indexOf("" + selection) < 0) {
        var inpval = String(inputElement.value);
        if ((inpval.length > 0) && (inpval != helperText)) {
            inputElement.value += "; " + selection + "";
            if (uid != '-1')
                hiddenElement.value += "; " + uid + "";
        }
        else {
            inputElement.value = selection + "";
            if (uid != '-1')
                hiddenElement.value = uid + "";
        }
        msg = '"' + selection + '" added.';
    } else {
        msg = '"' + selection + '" already selected.';
    }
    msg = label + " " + msg + "\n\n";

    var pluralLabel, lastChar = label.charAt(label.length - 1);
    switch(lastChar) {
    case "y":
        pluralLabel = label.substr(0, label.length - 1) + 'ies';
        break;
    case "s":
        pluralLabel = label + "'";
        break;
    default:
        pluralLabel = label + 's';
    }
        
    msg += "Click [OK] to continue selecting " + pluralLabel + ",\n";
    msg += " or [Cancel] when done selecting " + pluralLabel + ".";
    if (confirm(msg) == false) {
        window.opener.focus();
        window.close();
    }
}
//--------------------------------------------------------------->


<!-- // Handle form input to left navbarfor project ID / search ref
function updateref() {
	setCookie('SEARCH_REFERENCE', document.formPOST.search_ref.value, 30, 'd');
}

/* ==== Form Control ======================================================== */

function closeForm() {
	if (this.opener)
		this.close();
	else {
	    if (typeof(url) != "undefined")
		    this.location.href = url;
		else
		    this.location.href = "/";
        this.location.reload;
    }
}

function submitForm() {
    if (document.formPOST) {
        if (typeof validate == "function") {
	        if (validate())
    		    document.formPOST.submit();
        }
        else {
		    document.formPOST.submit();
        }
    }
}

function goSignOn() {
    var url = "/nonsub/accountHelp.asp?action=SignOn";
    if (parent) {
        parent.window.location.href = url;
        parent.window.location.reload;
    }
    else {
        navigate(url);
    }
}

function getUniqueString() {
    var rand_no = Math.floor(Math.random() * 1000000000).toString();
    var now = new Date();  // current date & time
    var now_time = now.getTime().toString();
    var ret = now_time + rand_no;
    //alert("Unique value for cookie named 'browse': " + ret);
    return (ret);
}

function setBrowseCookie() {
    if (getCookieRE("browse") == null)
        setSessionCookie("browse", getUniqueString());
}

/* ==== iFrame ============================================================= */

function autoIframeSize(frameId) {
    try {
        frame = document.getElementById(frameId);
        innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
        var newHeight = innerDoc.body.scrollHeight;
        if (frame.style) {
            objToResize = frame.style;
            newHeight = newHeight + "px";
        }
        else {
            objToResize = frame;
        }
        objToResize.height = newHeight;
    }
    catch(err) {
        alert(err.message);
    }
}
//-->
