﻿var HighlightAnimations = {};
function Highlight(el) {
    if (HighlightAnimations[el.uniqueID] == null) {
        HighlightAnimations[el.uniqueID] = AjaxControlToolkit.Animation.createAnimation({
            AnimationName : "color",
            duration : 0.5,
            property : "style",
            propertyKey : "backgroundColor",
            startValue : "#FFFF90",
            endValue : "#FFFFFF"
        }, el);
    }
    HighlightAnimations[el.uniqueID].stop();
    HighlightAnimations[el.uniqueID].play();
}

function ToggleHidden(value) {
    $find('<%=Tabs.ClientID%>').get_tabs()[2].set_enabled(value);
}

function CopyAddress() {
    alert("Copied : ");
}

function UpdateFiles() {
    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$Tabs$Panel1$ctlTabCustInfo$btn_FileUpdate", "", true, "", "", false, true));
}

function SelectAllMeters() 
{
    var chkbox;
    var i = 2;
    chkbox = document.getElementById('ctl00_ContentPlaceHolder1_Tabs_TabRequestForPricing_ctlTabRFP_dgdRFPMeters_ctl02_cbx_RFPIncludeInPricing');
    while (chkbox != null) 
    {
        chkbox.checked = true;
        i = i + 1;
        if (i <= 9)
        { chkbox = document.getElementById('ctl00_ContentPlaceHolder1_Tabs_TabRequestForPricing_ctlTabRFP_dgdRFPMeters_ctl0' + i + '_cbx_RFPIncludeInPricing'); }
        else
        { chkbox = document.getElementById('ctl00_ContentPlaceHolder1_Tabs_TabRequestForPricing_ctlTabRFP_dgdRFPMeters_ctl' + i + '_cbx_RFPIncludeInPricing'); }
    }
    return false;
}

function VerifyMeterTDSP(source, args) 
{
    //TODO: make this work for firefox. Currently firefox won't tell me what the source.clntnm is
    //Angie says that this can be put off for now.
    var selectedtdsps = false;
    for (i = 0; i < document.getElementById(source.clntnm).length; i++) 
    {        
        if (document.getElementById(source.clntnm).options[i].selected)
        { selectedtdsps = true; }
    }
    if (selectedtdsps == false) 
    {
        var chkbox;
        var i = 2;

        chkbox = document.getElementById('ctl00_ContentPlaceHolder1_Tabs_TabRequestForPricing_ctlTabRFP_dgdRFPMeters_ctl02_cbx_RFPIncludeInPricing');        
        while (chkbox != null) 
        {
            if (chkbox.checked == true)
            { selectedtdsps = true; }
            i = i + 1;
            if (i <= 9)
            { chkbox = document.getElementById('ctl00_ContentPlaceHolder1_Tabs_TabRequestForPricing_ctlTabRFP_dgdRFPMeters_ctl0' + i + '_cbx_RFPIncludeInPricing'); }
            else
            { chkbox = document.getElementById('ctl00_ContentPlaceHolder1_Tabs_TabRequestForPricing_ctlTabRFP_dgdRFPMeters_ctl' + i + '_cbx_RFPIncludeInPricing'); }           
        }
        if (selectedtdsps == false)
        { args.IsValid = false; }
        else
        { args.IsValid = true; }         
    }
    else
    { args.IsValid = true; }     
}

function myPdfDownload(editor) {
    // set result PDF page width
    var pageWidth = "1280px";

    //save current fullHTML property's value (server-side FullHTML property) 
    var saved_fullHTML = editor.fullHTML;

    // we want entire page HTML
    editor.fullHTML = true;

    // Editor content processing
    function sendToServer(strResult) {
        // set BODY padding for PDF
        strResult = strResult.replace(/<body/i, "<body style='padding:5px;'");

        // insert dummy DIV (tricking) with our width into the BODY
        strResult = strResult.replace(/(<body[^>]*>)/i, "$1<div style='width:" + pageWidth + "'>");
        strResult = strResult.replace(/(<\/body>)/i, "</div>$1");

        // set BASE property of HEAD (for Images with relative URL)
        strResult = strResult.replace(/(<\/head>)/i, "<base href='" + location.href + "'>$1");

        // create temporary FORM and TEXTAREA
        var _form = document.createElement("FORM");
        var _ta = document.createElement("TEXTAREA");

        _ta.name = "_ta_";
        _ta.style.width = "0px";
        _ta.style.height = "0px";
        _ta.style.display = "none";

        // set TEXTAREA's value with replaced content
        _ta.value = strResult.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;");

        _form.method = "post";        // post method
        _form.action = "GetPDF.aspx"; // Server-side handler

        // add temporary elements to document's body
        _form.appendChild(_ta);
        document.body.appendChild(_form);

        setTimeout(
                 function() {
                     _form.submit();   // submit our temporary FORM
                     setTimeout(
                              function() {
                                  // remove temporary elements
                                  _form.removeChild(_ta);
                                  document.body.removeChild(_form);
                              }
                             , 100);
                 }
                , 0);

        // restore fullHTML property
        editor.fullHTML = saved_fullHTML;
    }

    // process Editor's content
    editor.getContentWait(sendToServer);
}