// Window opening functions
function open_window(url)
{var left = (screen.availWidth - 600) / 2; if(left < 0) left = 0;
var top = (screen.availHeight - 400) / 2; if(top < 0) top = 0;
lw = window.open(url + '&popup=1', 'lw', 'resizable=yes,top=' + top + ',left=' + left + ',height=400,width=600,toolbar=no,status=no,scrollbars=yes');
if(lw)
{lw.focus();}
}
function open_report_window(url) {
repw = window.open(url + '&popup=1','repw');
if(repw){repw.focus();}
}
function open_large_window(url) 
{var left = (screen.availWidth - 800) / 2; if(left < 0) left = 0;
var top = (screen.availHeight - 500) / 2; if(top < 0) top = 0;
llw = window.open(url + '&popup=1','llw','resizable=yes,top='+top+',left='+left+',height=500,width=800,toolbar=no,status=yes,scrollbars=yes');
if (llw) { llw.focus(); }
}
function open_large_window2(url) {
var left = (screen.availWidth - 800) / 2; if(left < 0) left = 0;
var top = (screen.availHeight - 500) / 2; if(top < 0) top = 0;
llw2 = window.open(url + '&popup=1','llw2','resizable=yes,top='+top+',left='+left+',height=500,width=800,toolbar=no,status=yes,scrollbars=yes');
if(llw2){llw2.focus();}
}
// field definition functions
function _lookup(field,lookup) {
open_window('/zlookup.aspx?popup=1&field=' + field + '&sqlookup=' + lookup);
}
function _lookupdate(field) {
dlw = window.open('/zCalendar.aspx?popup=1&field=' + field,'lw','resizable=no,top=200,left=400,height=280,width=250,toolbar=no,status=no,scrollbars=no');
if(dlw){dlw.focus();}
}
function MultiSelectLookup(field,lookup,controlid) {
open_window('/zlookup.aspx?popup=1&field=' + field + '&sqlookup=' + lookup + '&multiselect=1&multiselectpostbackcontrolid=' + controlid);
}

//The javascript function that can be called clientside to locate nested server controls that may have different prepended portions
// as part of there final Id when rendered, due to INamingContainer. e.g. usage: var x = GetElementByIdEndsWith("input","tbName").
// Pass in the tagname e.g. 'input' for textboxes, and the control.ClientId
function GetElementByIdEndsWith(tagName, endsWith) {
    var elements = document.getElementsByTagName(tagName);
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].id.endsWith(endsWith)) {
            return elements[i];
        }
    }
    return null;
}
String.prototype.endsWith = function (txt, ignoreCase)
{var rgx;
if (ignoreCase) {
        rgx = new RegExp(txt + '$', 'i');
    }
    else {
        rgx = new RegExp(txt + '$');
    }
    return this.match(rgx) != null;
}


