﻿// Bookmark Page
function BookmarkPage() {
    url = location.href;
    title = document.getElementsByTagName("title")[0].innerHTML.match(/\S.*\S/)[0];
    if (window.sidebar)
    //window.sidebar.addPanel(title, url, ""); -- doesn't work right
        alert("Press CTRL+D to bookmark this page");
    else if (window.opera && window.print) {
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    } else if (document.all)
        window.external.AddFavorite(url, title);
}


// Print Preview
function PrintView(print_area) {
    var pv = window.open();
    pv.document.writeln('<HTML><HEAD><title>Printer-Friendly View</title>')
//    pv.document.writeln('<LINK href= type="text/css" rel="stylesheet" media="print">')
    pv.document.writeln('<base target="_self"></HEAD>')
    pv.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
    pv.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
    pv.document.writeln('<form method="post">');
    pv.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
    pv.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');
    pv.document.writeln('onclick="javascript:location.reload(true);window.print();">');
    pv.document.writeln('<INPUT ID="CLOSE" type="button" ' +
                        'value="Close" onclick="window.close();">');
    pv.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');
    pv.document.writeln(document.getElementById(print_area).innerHTML);
    pv.document.writeln('</form></body></HTML>');
}

function SelectAllCheckboxes(spanChk) {
    var oItem = spanChk.children;
    var theBox = (spanChk.type == "checkbox") ? spanChk : spanChk.children.item[0];
    xState = theBox.checked;
    elm = theBox.form.elements;
    for (i = 0; i < elm.length; i++) {
        if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
            if (elm[i].checked != xState) {
                elm[i].click();
            }
        }
    }
}

function SubmitOnEnter(e, o) {
    var key = (window.event) ? e.keyCode : ((e.which) ? e.which : 0);
    if (key == 13) {
        if(o) document.getElementById(o).click();
        return false;
    } else {
        return true;
    }
}

function ClearOnFocus(o, t) {
    if (o.value == t) {
        o.value = '';
    } else {
        o.select();
    }
}

function SetDefaultOnBlur(o, t) {
    if (o.value.match(/\S/) == null) {
        o.value = t;
    }
}
