﻿function OpenCommonMediaPlayer(FileURL, TilteText, Url) {
    var oWindow = window.radopen(Url, "rwMediaPlayer");
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    oWindow.setSize(myWidth - 25, myHeight - 10);

    oWindow.set_title("");
    oWindow.show();
}


function GetRadWindow() {

    var oWindow = null;
    if (window.radWindow != null || window.frameElement != null) {
        if (window.radWindow)
            oWindow = window.radWindow;
        else if (window.frameElement.radWindow)
            oWindow = window.frameElement.radWindow;
    }
    return oWindow;

}

function CloseRadWindow() {
    GetRadWindow().close();
}

function RefreshParentPage() {
    var oWindow = GetRadWindow();
    if (oWindow != null) {
        var locationURL = oWindow.BrowserWindow.location.href;
        oWindow.BrowserWindow.location.href = GetRadWindow().BrowserWindow.location.href;
        CloseRadWindow();
    }
}

function ResizeRadWindow(Width, Height) {
    var RadWindow = GetRadWindow();
    RadWindow.setSize(Width, Height);
    RadWindow.center();
}

function RedirectParentPage(url) {
    var locationURL = GetRadWindow().BrowserWindow.location.href;
    GetRadWindow().BrowserWindow.location.href = url;
    CloseRadWindow();
}

//the following code use radconfirm to mimic the blocking of the execution thread.
//The approach has the following limitations:
//1. It works inly for elements that have *click* method, e.g. links and buttons
//2. It cannot be used in if(!confirm) checks
window.blockConfirm = function(text, mozEvent, oWidth, oHeight, callerObj, oTitle) {
    var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually 
    //Cancel the event 
    ev.cancelBubble = true;
    ev.returnValue = false;
    if (ev.stopPropagation) ev.stopPropagation();
    if (ev.preventDefault) ev.preventDefault();

    //Determine who is the caller 
    var callerObj = ev.srcElement ? ev.srcElement : ev.target;

    //Call the original radconfirm and pass it all necessary parameters 
    if (callerObj) {
        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again. 
        var callBackFn = function(arg) {
            if (arg) {
                callerObj["onclick"] = "";
                if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz 
                else if (callerObj.tagName == "A") //We assume it is a link button! 
                {
                    try {
                        eval(callerObj.href)
                    }
                    catch (e) { }
                }
            }
        }

        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);

    }
    return false;
}
function ShowAlert(messageToDisplay, messageTitle) {
    GetRadWindowManager().CloseAll();
    var oWnd = radalert(messageToDisplay, 330, 100, messageTitle);
    oWnd.add_close(OnClientClose);
}

//Water mark
function OnFocus(elementId, defaultText) {
    if (document.getElementById(elementId).value == "") {
        document.getElementById(elementId).className = "normal";
        document.getElementById(elementId).value = "";
    }
}
function OnBlur(elementId, defaultText, ctrl) {
    var textValue = document.getElementById(elementId).value;

    if (textValue == defaultText || textValue.length == 0) {
        document.getElementById(elementId).className = "watermark" + defaultText;
        document.getElementById(elementId).value = "";
    }
    else
        document.getElementById(elementId).className = "normal";

    //Sets the focus
    document.getElementById(ctrl).focus();
}
