//
// $RCSfile: global.js,v $
// $Revision: 1.7 $
// $Date: 2007/03/09 22:21:12 $
//

/*
* Returns a page element by its id in a non browser specific way.
*/
function getEl(id) {
    if (document.layers) { return document.layers[id]; }
    else if (document.all) { return document.all[id]; }
    else if (document.getElementById) { return document.getElementById(id); }
}
// code for window popups
function openWin(url) {
    var win = window.open(url,'newWindow','width=850,height=550,menubar=yes,location=no,statusbar=yes,personalbar=no,scrollbars=yes,resize=yes');
}

function lTrim(str)
{
    var re
    re  = /^\s*/;
    str = (str.replace(re,''));
    return str;
}   

function rTrim(str)
{
    var len = str.length;
    var cnt = len-1;
    while(str.charAt(cnt) == " ")
    {
        cnt = cnt - 1;
        if (cnt <=0)
            break;
    }
    str = str.slice(0,cnt+1);
    return str;
}   

function trimString(str)
{
    return lTrim(rTrim(str));
}

function checkSearchTerm(searchQuery) {
	if (!searchQuery) searchQuery = document.getElementById("q01");
    if (trimString(searchQuery.value)=="" || 
        trimString(searchQuery.value)=="*")
    {
        var frmSearchText=document.getElementById(searchQuery.id + "-searchText"); 
        frmSearchText.innerHTML = "Please enter a Search Term";
        searchQuery.value="";
        searchQuery.focus();
        return false;
    }
    // copy rankBy if it exists
    else if (document.forms[2] && document.forms[2].rankBy) {
    	searchQuery.form.rankBy.value = document.forms[2].rankBy.value;
    }
    return true;
}

function doKeyPress(e)
{
    var cAscii;
    var returnValue = true;
    if(!e) e=window.event;
    cAscii=(e.keyCode)?e.keyCode:((e.which)?e.which:0);
    if (cAscii==13) //enter key pressed
    {
        returnValue = checkSearchTerm();
    }
    return returnValue;
}
