﻿//printPreview(str_parent) - Generates a print preview in pop-up
function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
}

function printPreviewDaaG(str_parent) {
    var p = window.open("", "blah", "width=800,height=500,status=no,menubar=no,toolbar=no,resizable=yes,location=no,scrollbars=yes")
    var url = window.location.href;
    var http = url.split('//')[0];
    var nohttp = url.split('//')[1];
    var domain = nohttp.split('/')[0];
    var url = http + '//' + domain + '/';
    var browser = navigator.userAgent;

    p.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    p.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml">');
    p.document.writeln('<head>');
    p.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
    p.document.writeln('<title>Print Preview</title>');
    p.document.writeln('<link href="/dir_style/PrintPreview.css" rel="stylesheet" type="text/css" media="screen" />');
    p.document.writeln('<link href="/dir_style/Print.css" rel="stylesheet" type="text/css" media="print" />');
    p.document.writeln('</head>');
    p.document.writeln('<body>');
    p.document.writeln('<div class="PrintContainer">');
    p.document.writeln('<form method="post">');
    p.document.writeln('<div class="PrintButtonBar">');
    if (browser.indexOf("Safari") == -1) {
        p.document.writeln('<INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();">');
    } else {
        p.document.writeln('Please use File->Print to print this page.');
    }
    p.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">');
    p.document.writeln('</div>');

    if (str_parent == 'ctl00_ctl00_ctl00_ctl00_cph_Content_cph_Content_cph_Content_cph_Content_pnl_Map') {
        document.getElementById('div_TitleMap').className = "tableTitle Visible";
    }
    else if (str_parent == 'ctl00_ctl00_ctl00_ctl00_cph_Content_cph_Content_cph_Content_cph_Content_pnl_Table') {
        document.getElementById('div_TitleTable').className = "tableTitle Visible";
    }

    var str = document.getElementById(str_parent).innerHTML;
    p.document.writeln(str);
    p.document.writeln('</form>');
    p.document.writeln('</div>');
    p.document.writeln('</body>');
    p.document.writeln('</html>');

    document.getElementById('div_TitleMap').className = "tableTitle Hidden";
    document.getElementById('div_TitleTable').className = "tableTitle Hidden";
}

function printPreview(str_parent) {
    var p = window.open("", "blah", "width=800,height=500,status=no,menubar=no,toolbar=no,resizable=yes,location=no,scrollbars=yes")
    //var p = window.open();
    var url = window.location.href;
    var http = url.split('//')[0];
    var nohttp = url.split('//')[1];
    var domain = nohttp.split('/')[0];
    var url = http + '//' + domain + '/';
    var browser = navigator.userAgent;

    p.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    p.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml">');
    p.document.writeln('<head>');
    p.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
    p.document.writeln('<title>Print Preview</title>');
    p.document.writeln('<link href="/dir_style/PrintPreview.css" rel="stylesheet" type="text/css" media="screen" />');
    p.document.writeln('<link href="/dir_style/Print.css" rel="stylesheet" type="text/css" media="print" />');
    p.document.writeln('</head>');
    p.document.writeln('<body>');
    p.document.writeln('<div class="PrintContainer">');
    p.document.writeln('<form method="post">');
    p.document.writeln('<div class="PrintButtonBar">');
    if (browser.indexOf("Safari") == -1) {
        //p.document.writeln('<a href="javascript:window.blah.location.href = window.location.href;window.print();">Print</a>');
        p.document.writeln('<INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();">');
        //p.document.writeln('<INPUT ID="PRINT" type="button" value="Print" onclick="window.print();">');
    } else {
        p.document.writeln('Please use File->Print to print this page.');
    }
    p.document.writeln('<INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();">');
    p.document.writeln('</div>');
    //Remove script tags and everything in between
    if (str_parent == "printContainerTable") {
        document.getElementById('tableTitle').className = "tableTitle Visible";
    }
    
    var str = document.getElementById(str_parent).innerHTML;
    while (str.indexOf('<SCRIPT') != -1) {
        var intfirst = str.indexOf('<SCRIPT');
        var intlast = str.indexOf('</SCRIPT>') + 9;
        str = str.substring(0, intfirst) + str.substring(intlast, str.length);
    }
    p.document.writeln(str);
    p.document.writeln('</form>');
    p.document.writeln('</div>');
    p.document.writeln('</body>');
    p.document.writeln('</html>');

    document.getElementById('tableTitle').className = "tableTitle Hidden";
}

// printHelp

function printHelp(int_ID, int_HelpLevel) {
    var p = window.open("../Help/?HelpLevel=" + int_HelpLevel + "&id=" + int_ID, "Help", "width=400,height=300,status=no,menubar=no,toolbar=no,resizable=yes,location=no,scrollbars=yes")
}

// setCollapsePanels
    
function setCollapsePanels() {

    $("DIV.jq_CollapseHeader").toggle(

        function() {

            $(this).next("div.jq_CollapseContent").show("normal");

            $(this).attr("class", $(this).attr("class").replace("jq_CollapseHeader", "jq_CollapseHeaderOpen"));

        },

        function() {

            $(this).next("div.jq_CollapseContent").hide("normal");

            $(this).attr("class", $(this).attr("class").replace("jq_CollapseHeaderOpen", "jq_CollapseHeader"));

        });

    $("DIV.jq_CollapseHeaderOpen").toggle(

        function() {

            $(this).next("div.jq_CollapseContent").hide("normal");

            $(this).attr("class", $(this).attr("class").replace("jq_CollapseHeaderOpen", "jq_CollapseHeader"));

        },

        function() {

            $(this).next("div.jq_CollapseContent").show("normal");

            $(this).attr("class", $(this).attr("class").replace("jq_CollapseHeader", "jq_CollapseHeaderOpen"));

        });

}

// clear_form_elements(ele)
// Clears values from all inputs that are children of element

function clear_form_elements(ele) {

    $(ele).find(':input').each(function() {
        switch (this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}
