String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
String.prototype.replaceAll = function(strA, strB) { return this.replace( new RegExp(strA,"g"), strB ); };

function PrintLink(SectionId) 
{
    var message = "<a href=\"javascript:PrintSection('" + SectionId + "')\"><img src=\"~/media/safety/prepare/images/print.ashx\" alt=\"\" />" +
        "<span class=\"hide\">Print " + SectionId + "</span></a>";

    document.writeln(message);
}

function PrintSection(ContentControlName)
{
    try
    {
        var oIframe = document.getElementById('ifrmPrint');
        var oContent = document.getElementById(ContentControlName).innerHTML;
        var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
        if (oDoc.document)
        {
          oDoc = oDoc.document;
        }

        oDoc.write(
            "<html><head><style>@media print{.dontprint{display:none;}}</style></head><body onload='this.focus(); this.print();'>" +
            oContent + "</body></html>");
        oDoc.close();
    }
    catch (e) { }
}

function JumpToSection() 
{
    var DropDownListControl = document.getElementById("ddlZipCodes");

    if (DropDownListControl && 
        DropDownListControl.type == "select-one" &&
        DropDownListControl.options[DropDownListControl.selectedIndex].value !== "")
    {
        window.location = "#" + DropDownListControl.options[DropDownListControl.options.selectedIndex].value;
    }
}

function GenerateZipCodeDropDownList(strZipCodeList)
{
    var DropDownList = "";

    if (strZipCodeList !== "")
    {
        DropDownList = 
            "<select id='ddlZipCodes' onchange='JumpToSection()'>\r\n" +
            "  <option value='' selected>Select Zip Code</option>\r\n";

        var ZipCodes = strZipCodeList.split(",");
        for(var idx=0;idx<ZipCodes.length;idx++)
        {
            var ZipCodeValue = ZipCodes[idx].trim();
            DropDownList = DropDownList + "  <option value='" + ZipCodeValue + "'>" + ZipCodeValue + "</option>";
        }

        DropDownList = DropDownList + "</select>";
    }

    return DropDownList;
}
