﻿
var RefreshPageOnClose = false;
var PopUp = false;

function OpenPositionedWindow(oButton, url, windowName) {
    var oWnd = window.radopen(url, windowName);
}

function openRadWindow(url, _RefreshPageOnClose) {
    RefreshPageOnClose = _RefreshPageOnClose;
    var oWnd = radopen(url, "RadWindow1");
    oWnd.center();
}

function openRadWindowResize(url, _RefreshPageOnClose, _Width, _Height) {
    RefreshPageOnClose = _RefreshPageOnClose;
    var oWnd = radopen(url, "RadWindow1");
    oWnd.setSize(_Width, _Height);
    oWnd.center();
}


function OnRadWindowClose() {

    if (RefreshPageOnClose == true)
        document.location.href = document.location.href;


}



function SetMemberDLL(ControlID, Member_ID, Member_Name) {

    var combo = $find(ControlID);
    var comboItem = new Telerik.Web.UI.RadComboBoxItem();
    comboItem.set_text(Member_Name);
    comboItem.set_value(Member_ID);
    combo.trackChanges();
    combo.get_items().add(comboItem);
    comboItem.select();
    combo.commitChanges();

}

//GetRadWindow obtains a reference to the hosting RadWindow"

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow)
        oWindow = window.radWindow;
    else if (window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
    return oWindow;
}

function CloseOnReload() {
    GetRadWindow().close();
}

function RefreshParentPage() {
    GetRadWindow().BrowserWindow.location.reload();
}

//CallFn shows how to call a predefined function
// in an opened RadWindow. A javascript function named
// CalledFn() must exist in RadWindow1's content
function CallFn() {
    var oWnd = GetRadWindowManager().getWindowByName("RadWindow1");
    oWnd.get_contentFrame().contentWindow.CalledFn();
}

function CalledFn() {
    var oWnd = GetRadWindowManager().getWindowByName("RadWindow1");
    oWnd.get_contentFrame().contentWindow.CalledFn();
}


// CallFnOnParent shows how to call a function
// in the parent page. A javascript function named CalledFn
// must exist in the parent page.
function UpdateParent(control_name) {
    GetRadWindow().BrowserWindow.ReceieveUpdate(control_name);
}

function ReceieveUpdate(control_name) {
    // SEND FUNCTION TO SERVER SIDE

}


function returnToParent() {


    //get a reference to the RadWindow
    var oWnd = GetRadWindow();
    oWnd.close();


}





function popWinCustom(url, width, height) {
    window.open(url, "popWindow", "width=" + width + ",height=" + height + ",toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1");
}

function setToBlock(divName) {
    if (document.getElementById(divName) != null) {
        document.getElementById(divName).style.display = "block";
    }
}
function setToNone(divName) {
    if (document.getElementById(divName) != null) {
        document.getElementById(divName).style.display = "none";
    }
}

function DivIsBlock(divName) {
    if (document.getElementById(divName) != null) {
        if (document.getElementById(divName).style.display == "block")
            return true;
        else
            return false;
    }
}

function ShowMore(PartialDivName) {
    setToNone('Summary_' + PartialDivName);
    setToBlock('Complete_' + PartialDivName);
}

function ShowDiv(PartialDivName) {

    if (DivIsBlock('sdiv_' + PartialDivName))
        setToNone('sdiv_' + PartialDivName);
    else
        setToBlock('sdiv_' + PartialDivName);
}

function HighLight(objectID) {

    var i = objectID.className.indexOf('HighLight');
    var j = objectID.className.indexOf('Selected');

    if (j == -1) {
        if (i != -1) {
            objectID.className = objectID.className.substring(0, i);
        } else {
            objectID.className = objectID.className + 'HighLight';
        }
    }
    return true;
}

function HighLightUsingName(objectName) {

    var objectID = document.getElementById(objectName);
    var i = objectID.className.indexOf('HighLight');
    var j = objectID.className.indexOf('Selected');
    if (j == -1) {
        if (i != -1) {
            objectID.className = objectID.className.substring(0, i);
        } else {
            objectID.className = objectID.className + 'HighLight';
        }
    }
    return true;
}





var Url = {

    // public method for url encoding
    encode: function(string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function(string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


var isPop = false;

// CENTER WINDOW
var popup_blocker_shown = 0;
var xMax; var yMax;
if (document.all) {
    xMax = screen.width; yMax = screen.height;
} else {
    if (document.layers) {
        xMax = window.outerWidth; yMax = window.outerHeight;
    } else { var xMax = 640; yMax = 480; }
}

function popWin(url, popWidth, popHeight) {

    var fakeNum = (new Date()).getTime() % 1000000000;
    var windowName = "winpopc" + fakeNum;

    var features = "width=" + popWidth + ",height=" + popHeight + ",";

    var xOffset = (xMax - popWidth) / 2, yOffset = (yMax - popHeight) / 2;

    if (xOffset > 0 && yOffset > 0) {
        features += "screenX=" + xOffset + ",left=" + xOffset + ",";
        features += "screenY=" + yOffset + ",top=" + yOffset + ",";
    }


    features += "scrollbars=yes,status=yes,resizable=yes";


    var mywin;

    eval('my' + 'wi' + 'n = ' + 'w' + 'i' + 'nd' + 'ow.o' + 'pe' + 'n(ur' + 'l' + ', windowName, features)' + ';');

    if (mywin != null) {
        if (mywin.opener == null) { mywin.opener = self; }
        mywin.focus();
    } else {
        if (popup_blocker_shown == 0) {
            popup_blocker_shown = 1;
            alert("This site uses pop-ups (profiles, alerts, etc..). Please turn off your pop-up blocker.");
        }
    }
    return mywin;


}



function CheckAll(CheckBoxID, checkVal) {

    re = new RegExp(CheckBoxID + '$')  //generated control name starts with a colon

    for (i = 0; i < document.forms[0].elements.length; i++) {

        elm = document.forms[0].elements[i]

        if (elm.type == 'checkbox') {

            if (re.test(elm.name)) {

                elm.checked = checkVal

            }
        }
    }
}