﻿



var cUpdating = "Updating...";
var DefaultMask = "MaskedDiv";

jQuery.fn.DisableEnterKey =
    function () {
        return this.each(function () {
            $(this).keydown(function (e) {
                var key = e.charCode || e.keyCode || 0;
                // return false for the enter key
                return (key != 13);
            })
        })
    };



function ResizeDocumentPreviewDialog() {
    $("#ADimageDialog").dialog('open');
    $("#ADimageDialog").dialog({ width: $("#ADimageSource").width() + 42,
        height: $("#ADimageSource").height() + 70, modal: true, resizable: false,
        position: [($(window).width() - $("#ADimageSource").width()) / 2, 5]
    });
}
function ShowDocumentPreviewDialog(sTitle, sNotes, sImage, sType) {
    $("#ADimageDialog").dialog({ title: sTitle });
    var p = document.getElementById("ADparagraph");
    p.innerHTML = sNotes;

    if (sType == "pdf") {
        alert("PDF Document");
        return false;
    }
    var i = document.getElementById("ADimageSource");
    i.src = sImage + "&width=" + ($(window).width() - 160);
    return false;
}

function SetDatePickers() {
    $(".DatePicker").datepicker({
        buttonImage: '/Images/Calendar_Icon.png',
        buttonText: "Pick a Date",
        buttonImageOnly: true,
        showButtonPanel: true,
        showOtherMonths: true,
        dateFormat: 'dd-M-yy',
        showOn: 'both'
    });
    $(".DatePickerFull").datepicker({
        buttonImage: '/Images/Calendar_Icon.png',
        buttonText: "Pick a Date",
        buttonImageOnly: true,
        showButtonPanel: true,
        showOtherMonths: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: 'dd-M-yy',
        showOn: 'both'
    });
}

function PreparePanelForUpdate(id) {
    $("#" + id).empty();
    $("#" + id).text(cUpdating);
}
function AddRadio(o, group, value, text, selected, clickfunction) {
    var id = "radio" + group + value;
    rdo = document.createElement('input');
    rdo.setAttribute('type', 'radio');
    rdo.setAttribute('name', group);
    rdo.setAttribute('value', value);
    if (selected)
        rdo.setAttribute('checked', 'checked');
    rdo.setAttribute('id', id);
    if (clickfunction != null)
        rdo.onclick = clickfunction;

    o.appendChild(rdo);
    if (text != '') {
        var l = document.createElement('label');
        l.setAttribute("for", id);
        AddText(l, text);
        o.appendChild(l);
    }
}
function ClearPanel(o) {
    alert("ClearPanel is deprecated.");
}
function AddText(o, text) {
    var t = document.createTextNode(text);
    o.appendChild(t);
}
function AddRawText(o, text) {
    o.innerHTML += text;
}

//Catch all for AJAX web service errors. Display a message and then force a PostBack
function OnServiceError(result) {
    alert("Error: " + result.get_message());
    ForceSubmit();
}
//Calls the ASP.Net postback .
function ForceSubmit() {
    ShowMask("PleaseWaitDiv", 50, 250, DefaultMask);
    document.form1.submit();
}
// Take a URL and return a string upto and including the last '/'
function URLFolder(ss) {
    var s = "";
    i = ss.indexOf("/");
    while (i >= 0) {
        s += ss.substring(0, i + 1); ss = ss.substring(i + 1);
        i = ss.indexOf("/");
    }
    return s;
}
//Returns the file of a URL
function URLFile(ss) {
    i = ss.indexOf("/");
    while (i >= 0) {
        ss = ss.substring(i + 1); i = ss.indexOf("/");
    }
    return ss;
}

function XMLfromString(s) {
    if (window.DOMParser) {
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(s, "text/xml");
    }
    else // Internet Explorer
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(s);
    }
    return xmlDoc;
}

function ChangeCSS(theClass, element, value) {
    var cssRules;

    var added = false;
    for (var i = 0; i < document.styleSheets.length; i++) {

        if (document.styleSheets[i]['rules']) {
            cssRules = 'rules';
        } else if (document.styleSheets[i]['cssRules']) {
            cssRules = 'cssRules';
        } else {
            return;
        }

        for (var j = 0; j < document.styleSheets[i][cssRules].length; j++) {
            if (document.styleSheets[i][cssRules][j].selectorText == theClass) {
                if (document.styleSheets[i][cssRules][j].style[element]) {
                    document.styleSheets[i][cssRules][j].style[element] = value;
                    added = true;
                    break;
                }
            }
        }
        if (!added) {
            if (document.styleSheets[i].insertRule) {
                document.styleSheets[i].insertRule(theClass + ' { ' + element + ': ' + value + '; }', document.styleSheets[i][cssRules].length);
            } else if (document.styleSheets[i].addRule) {
                document.styleSheets[i].addRule(theClass, element + ': ' + value + ';');
            }
        }
    }
}

function ValueOfRadio(name) {
    var Val = "";
    for (j = 0; j < document.form1.elements.length; j++)
        if (document.form1.elements[j].name == name)
            if (document.form1.elements[j].checked)
                Val = document.form1.elements[j].value;
    return Val;
}
//Sets a given element with the parameter result
function SR_SetValueLabel(result, id) {
    id = "#" + id;
    $(id).text(result);
}

//$(document).ready(function () {
//});

