//<SCRIPT LANGUAGE=javascript>
// the commented <SCRIPT> tags allows editing this file 
// using Visual InterDev's HTML/script editor

// Copyright (c) 2004, Lindsay Bigelow

////////////////////////////////////////
//** search for initialSelect in Select list and select that item.
// NOTE: requires sorted list!
// @param win       - a Window object reference
// @param formName  - String; name of Form which contains select list
// @param listName  - String; name of select list
// @param patt      - String; string to search for (prefix OK; not case-sensitive)
// @param selectFirstOnFailure  - boolean; if match not found: if true, select first item; else, selection unchanged
// @author LB 25-Sep-2002 
//
function listSelect(win, formName, listName, patt, selectFirstOnFailure) {
    patt = patt.toLowerCase();
    var list1  = win.document.forms[formName].elements[listName];
    var ll = list1.options.length;
    var lp = 0;
    var hp = ll - 1;
    var max = Math.floor(ll / 2);
    var i, s;
    // do a binary search
    while (true) {
        if (--max < 0) break; // list wasn't sorted; abort
        if (hp < lp) break;
        i = Math.floor((lp + hp) / 2);
        s = list1.options[i].text.toLowerCase();
        if (s < patt)
            lp = i + 1;
        else if (s > patt)
            hp = i - 1;
        else
            break;
    }
    if (0 != list1.options[i].text.toLowerCase().indexOf(patt)) {
        // found close match; try looking for exact prefix match in nearby list items:
        if ( (i < (ll - 1)) && (0 == list1.options[i + 1].text.toLowerCase().indexOf(patt)) )
            i++;
        else
        if ( (i > 0) && (0 == list1.options[i - 1].text.toLowerCase().indexOf(patt)) )
            i--;
        else
        if (selectFirstOnFailure)
            i = 0;
        else
            return;
    }
    list1.options[i].selected = true;
    try { win.document.forms[formName].elements["btnEdit"].disabled=false; } catch(e) {;}
    return;
}

////////////////////////////////////////
// for droplist style lookup page
//
function popup1(initialSelect, page) {
    try {
        var popWidth  = 550;
        var popHeight = 150;
        var popLeft   = Math.floor(screen.availWidth * .85 - popWidth);
        var popTop    = Math.floor(screen.availHeight * .5 - popHeight);
        var opts =  "toolbar=no,location=no,menubar=no,dependent=yes,titlebar=no,directories=no,alwaysRaised=yes";
            opts += ",status=no";
            opts += ",resizable=no";
            opts += ",scrollbars=no";
            opts += ",width="   + popWidth + ",height="  + popHeight;
            opts += ",left="    + popLeft  + ",top="     + popTop;
            opts += ",screenX=" + popLeft  + ",screenY=" + popTop;
        var popwin = window.open("", "lookup", opts);
        popwin.focus();
        popwin.location = '/c2dweb/includes/' + page + '.asp';

        if (initialSelect == "") 
            return;   //===>
    }
    catch(e) {
        alert("error: " + e);
        popwin.close();
        return;
    }
    try { 
        var cnt = 0, fc = 0;
        for ( ; ((fc < 1) && (cnt < 100)); cnt++ ) {  //force document to load completely...
            fc = popwin.document.forms.length;
        }
        //@ listSelect(win, formName, listName, patt, selectFirstOnFailure)
        listSelect(popwin, "form1", "list1", initialSelect, true);
    }
    catch(e) {
        ;// ignore any errors
    }
}

// ** show search help:
function showSearchHelp() {
    try {
        window.open(
                "/c2dweb/ixtiphlp3.htm", 
                "SearchHelp", 
                "width=600,height=400,toolbar=no,status=no,location=no," +
                "menubar=yes,resizable=yes,titlebar=yes,directories=no,scrollbars=yes"
              );
    }
    catch(e) {
        alert("error: " + e);
    }
}

// ** private - unescape XML escaped chars:
function unescapeX(src) {
    var s = new String(src);
    return s.replace(/&quot;/g, "\"")
            .replace(/&#39;/g, "\'")
            .replace(/&lt;/g, "<")
            .replace(/&gt;/g, ">")
            .replace(/&#92;/g, "\\")
            .replace(/&amp;/g, "&");
}

// ** show hilited results:
function showHilited(vpath, qry) {
    try {
        var qry1 = escape('' + unescapeX(qry));
        var url = "/c2dweb/hilite2.asp"
               + "?vp=" + vpath
               + "&qry=" + qry1
        window.open(
                url, 
                "_blank", 
                "width=640,height=480,toolbar=yes,status=yes,location=yes," + 
                "menubar=yes,resizable=yes,titlebar=yes,directories=no,scrollbars=yes"
              );
    }
    catch(e) {
        alert("error: " + e);
    }
}

// ** open graphic:
function showGraphic(id) {
    try {
        var hgt = 500; //500;  // parseInt(screen.availHeight) * 0.5; 
        var wid = 800; //640;  // parseInt(screen.availWidth) * 0.5;  
        var url = "/c2dweb/showgrafic2.asp?job=" + id 
        var loc = "no";    // yes for debugging
        window.open(
                url, 
                "_blank", 
                "width=" + wid + ",height=" + hgt + //,left=50,top=20" +
                ",toolbar=no,status=yes,location=" + loc + 
                ",menubar=no,resizable=yes,titlebar=yes" + 
                ",directories=no,scrollbars=yes"
              );
    }
    catch(e) {
        alert("error: " + e);
    }
}

// open file (DWG):
function showFile(id) {
    try {
        var hgt = 500; //500;  // parseInt(screen.availHeight) * 0.5; 
        var wid = 800; //640;  // parseInt(screen.availWidth) * 0.5;  
        var url = "/c2dweb/showgrafic2.asp?imgDWG.x=100&job=" + id 
        var loc = "no";    // yes for debugging
        window.open(
                url, 
                "_blank", 
                "width=" + wid + ",height=" + hgt + //,left=50,top=20" +
                ",toolbar=no,status=yes,location=" + loc + 
                ",menubar=no,resizable=yes,titlebar=yes" + 
                ",directories=no,scrollbars=yes"
              );
    }
    catch(e) {
        alert("error: " + e);
    }
}

// ** show detail in a new window:
function showDetail(id) {
    try {
        var url = "/c2dweb/finder.asp" + "?detail=" + id;
        window.open(
                url, 
                "_blank", 
                "width=720,height=480,toolbar=yes,status=yes,location=yes," + 
                "menubar=yes,resizable=yes,titlebar=yes,directories=no,scrollbars=yes"
              );
    }
    catch(e) {
        alert("error: " + e);
    }
}

//</SCRIPT>

