﻿window.scrollTo = function() { };

// initialise jqmodal elements

$().ready(function() {
    if ($('#errorPopup')[0] != undefined)
        $('#errorPopup').jqm({ modal: true });

    if ($('#ConfirmPopup')[0] != undefined)
        $('#ConfirmPopup').jqm({ modal: true });        

    if (Sys != undefined)
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    function EndRequestHandler(sender, args) {
        if ($('.date-pick')[0] != null) {
            $('.date-pick').datePicker({
                startDate: '31/12/2008'
            });
        }
    }
});

$(function() {
    if ($('.date-pick')[0] != null) {
        $('.date-pick').datePicker({
            startDate: '31/12/2008'
        });
    }
});


function show(objID) {
    if (document.getElementById(objID).style.display == "block")
        document.getElementById(objID).style.display = "none";
    else
        document.getElementById(objID).style.display = "block";
}

function toggleRow(objID) {
    if (document.getElementById(objID).style.display == "table-row")
        document.getElementById(objID).style.display = "none";
    else
        document.getElementById(objID).style.display = "table-row";
}

function select(obj, phID, ddlID, val) {
    document.getElementById(ddlID).value = val;
    document.getElementById(phID).innerHTML = obj.innerHTML;
}

function enablePalete(objid, altObjId) {
    document.getElementById(objid).style.display = "none";
    document.getElementById(altObjId).style.display = "block";
}

function clearDefault(el) {
    if (el.defaultValue == el.value) el.value = ""
}

function checkErrors(valGroup) {
    if (!Page_ClientValidate(valGroup)) {

        var lastControl = "";

        for (i = 0; i < Page_Validators.length; i++) {

            if (Page_Validators[i].controltovalidate) {
                if (!Page_Validators[i].isvalid) {
                    var str = document.getElementById(Page_Validators[i].controltovalidate).parentNode.parentNode.className;
                    str = str.replace("error", "") + " error";
                    document.getElementById(Page_Validators[i].controltovalidate).parentNode.parentNode.className = str;
                }
                else {
                    if (Page_Validators[i].controltovalidate != lastControl) {
                        var str = document.getElementById(Page_Validators[i].controltovalidate).parentNode.parentNode.className;
                        str = str.replace("error", "");
                        document.getElementById(Page_Validators[i].controltovalidate).parentNode.parentNode.className = str;
                    }
                }

                lastControl = Page_Validators[i].controltovalidate;
            }

        }

        $('.errorrow').show();
    }
}

function showError(valGroup, objId) {
    if (!Page_ClientValidate(valGroup)) {
        document.getElementById(objId).style.border = "1px solid red";
        document.getElementById(objId).style.background = "#fbe2e3";
        document.getElementById(objId).style.height = "14px";
        document.getElementById(objId).style.width = "164px";
    }
}

function printImg(imgpath) {
    if (imgpath) {
        //build html for print page
        var html = "<HTML>\n<HEAD>\n" +
            $("head").html() +
            "\n</HEAD>\n<BODY>\n" +
            "<img src='" + imgpath + "'/>" +
            "\n</BODY>\n</HTML>";
        //open new window
        var printWP = window.open("", "printWebPart");
        printWP.document.open();
        //insert content
        printWP.document.write(html);
        printWP.document.close();
        //open print dialog
        printWP.print();
    }
}


