// TODO: Remove after Telerik does the hotfix for the toolbar issue at start of January 2008.
function OnClientLoad(editor) {
    var topZone = editor.DockingZones.TopZone;
    var topWidth = topZone.offsetWidth;
    if (topWidth == 0) {
        topZone.style.width = "100px";
        var oInterval = window.setInterval(function() {
            if (topZone.offsetWidth > 0) {
                window.clearInterval(oInterval);
                editor.WrapperElement.onresize();
            }
        }, 100);

        var toggleResize = false;
        editor.WrapperElement.onresize = function() {
            toggleResize = !toggleResize;
            if (toggleResize) {
                topZone.style.width = topZone.offsetWidth + "px";
            }
        };
    }
}
function writeDocument(s) { document.write(s); }

// Get the value of the cookie with the specified name.
function getCookie(sName) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }

    // a cookie with the requested name does not exist
    return null;
}
function popupwindow(url,width,height) {
    // open a window <a href="javascript:popupwindow('poppedexample.html','400','400');">Pop it</a> 
    var newwindow;
    newwindow = window.open(url, 'name', 'height=' + height + ',width=' + width + '');
    if (window.focus) { newwindow.focus() }
}

function createFlashMedia(siteUrl, flashFilename, mediaItemId, width, height, autoplay) {
    try {
        if (!width || isNaN(width)) width = 320;
        if (!height || isNaN(height)) height = 240;
        var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
        var flash = '';
        var auto = (autoplay == "true") ? "true" : "false";
        var visitorId = getCookie("ID");
        var movie = '/FLASHFLA/VideoPlayer.swf?runCuePoints=yes&siteUrl=' + siteUrl + '&videoFilename=' + flashFilename + '&startPlay=' + auto + '&mediaItemId=' + mediaItemId + '&visitorId=' + visitorId;

        if (isIE) {
            flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="FLVPlayer" align="middle">';
            flash += '<param name="allowScriptAccess" value="sameDomain" />';
            flash += '<param name="movie" value="' + movie + '" />';
            flash += '<param name="quality" value="high" />';
            flash += '<param name="base" value="/FLASHFLA/" />';
            flash += '<param name="bgcolor" value="#ffffff" />';
            flash += '<param name="allowFullScreen" value="true" />';
            flash += '<param name="wmode" value="transparent" />';
            flash += '<param name="startPlay" value="' + auto + '" />';
            flash += '<param name="flashvars" value="runCuePoints=yes&siteUrl=' + siteUrl + '&videoFilename=' + flashFilename + '&mediaItemId=' + mediaItemId + '&startPlay=' + auto + '&visitorId=' + visitorId + '" />';
            flash += '<embed src="' + movie + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="FLVPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true"/>';
            flash += '</object>';
        }
        else {
            flash = '<embed src="' + movie + '" quality="high" startPlay="' + auto + '" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="FLVPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true"/>';
        }
        document.write(flash);
    }
    catch (ex) { alert(ex); }
}

function createFlashMp3(flashFilename, mediaItemId, width, height) {
    try {
        if (!width || isNaN(width)) width = 320;
        if (!height || isNaN(height)) height = 240;
        var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
        var flash = '';
        var visitorId = getCookie("ID");
        var movie = flashFilename;

        if (isIE) {
            flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="Mp3Player" align="middle">';
            flash += '<param name="allowScriptAccess" value="sameDomain" />';
            flash += '<param name="movie" value="' + movie + '" />';
            flash += '<param name="quality" value="high" />';
            flash += '<param name="base" value="/FLASHFLA/" />';
            flash += '<param name="bgcolor" value="#ffffff" />';
            flash += '<param name="allowFullScreen" value="true" />';
            flash += '<param name="wmode" value="transparent" />';
            flash += '<embed src="' + movie + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="Mp3Player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true"/>';
            flash += '</object>';
        }
        else {
            flash = '<embed src="' + movie + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="Mp3Player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true"/>';
        }
        document.write(flash);
    }
    catch (ex) { alert(ex); }
}

function insertFlashMedia(containerElementId, removeAllChildren, siteUrl, flashFilename, mediaItemId, width, height) {
    try {
        var elContainer = document.getElementById(containerElementId);
        if (!elContainer) return;

        if (removeAllChildren == true) {
            for (var i = elContainer.childNodes.length - 1; i >= 0; i--)
                elContainer.removeChild(elContainer.childNodes[i]);
        }
        
        if (!width || isNaN(width)) width = 320;
        if (!height || isNaN(height)) height = 240;
        var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
        var flash = '';
        var visitorId = getCookie("ID");
        var movie = '/FLASHFLA/VideoPlayer.swf?runCuePoints=yes&siteUrl=' + siteUrl + '&videoFilename=' + flashFilename + '&mediaItemId=' + mediaItemId + '&visitorId=' + visitorId;

        if (isIE) {
            flash = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="FLVPlayer" align="middle">';
            flash += '<param name="allowScriptAccess" value="sameDomain" />';
            flash += '<param name="movie" value="' + movie + '" />';
            flash += '<param name="quality" value="high" />';
            flash += '<param name="base" value="/FLASHFLA/" />';
            flash += '<param name="bgcolor" value="#ffffff" />';
            flash += '<param name="allowFullScreen" value="true" />';
            flash += '<param name="wmode" value="transparent" />';
            flash += '<param name="flashvars" value="runCuePoints=yes&siteUrl=' + siteUrl + '&videoFilename=' + flashFilename + '&mediaItemId=' + mediaItemId + '&visitorId=' + visitorId + '" />';
            flash += '<embed src="' + movie + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="FLVPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true"/>';
            flash += '</object>';
        }
        else {
            flash = '<embed src="' + movie + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="FLVPlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowfullscreen="true"/>';
        }

        elContainer.innerHTML = flash;
    }
    catch (ex) { alert(ex); }
}

function createFlashCornerVideo(FlashGuideFile, vidBaseURL, FlashGuideWidth, FlashGuideHeight) {
    try {
        //Detect IE5.5+
        version = 0
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            temp = navigator.appVersion.split("MSIE")
            version = parseFloat(temp[1])
        }

        var flash;

        if (version >= 5.5) //NON IE browser will return 0
        {
            flash = "<div id='DivFlash' style='position:fixed; position:absolute; _top:expression((document.body.scrollTop+document.body.clientHeight-this.clientHeight)-20); _left:expression((document.body.scrollRight+document.body.clientWidth-this.clientWidth)-20); bottom:20; right:20; z-index:1;'>";
            flash += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " >";
            flash += "<param name='allowScriptAccess' value='sameDomain' />";
            flash += "<param name='movie' value='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "' />";
            flash += "<param name='quality' value='high' />";
            flash += "<param name='bgcolor' value='#ffffff' />";
            flash += "<param name='wmode' value='transparent'>";
            flash += "<param name='scale' value='exactfit' />";
            flash += '<param name="allowFullScreen" value="true" />';
            flash += "<embed src='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "' scale='exactfit' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " quality='high' bgcolor='#ffffff' wmode='transparent' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' allowfullscreen='true'/>  ";
            flash += "</object></div>";
        } else {
            flash = "<div id='DivFlash' style='position:fixed; bottom:20; right:20; z-index:1;'>";
            flash += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " >";
            flash += "<param name='allowScriptAccess' value='sameDomain' />";
            flash += "<param name='movie' value='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "' />";
            flash += "<param name='quality' value='high' />";
            flash += "<param name='bgcolor' value='#ffffff' />";
            flash += "<param name='wmode' value='transparent'>";
            flash += "<param name='scale' value='exactfit' />";
            flash += '<param name="allowFullScreen" value="true" />';
            flash += "<embed src='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "' scale='exactfit' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " quality='high' bgcolor='#ffffff' wmode='transparent' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' allowfullscreen='true'/>  ";
            flash += "</object></div>";
        }
        document.write(flash);
    } catch (ex) {
        alert(ex);
    }
}

function createFlashCornerVideoACStop(FlashGuideFile, vidBaseURL, FlashGuideWidth, FlashGuideHeight) {
    try {

        //Detect IE5.5+
        version = 0
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            temp = navigator.appVersion.split("MSIE")
            version = parseFloat(temp[1])
        }

        var flash;

        if (version >= 5.5) //NON IE browser will return 0
        {

            flash = "<div id='DivFlash' style='position:fixed; position:absolute; _top:expression((document.body.scrollTop+document.body.clientHeight-this.clientHeight)-20); _left:expression((document.body.scrollRight+document.body.clientWidth-this.clientWidth)-20); bottom:20; right:20; z-index:1;'>";
            flash += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " >";
            flash += "<param name='allowScriptAccess' value='sameDomain' />";
            flash += "<param name='movie' value='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "&action=stop' />";
            flash += "<param name='quality' value='high' />";
            flash += "<param name='bgcolor' value='#ffffff' />";
            flash += "<param name='wmode' value='transparent'>";
            flash += "<param name='scale' value='exactfit' />";
            flash += '<param name="allowFullScreen" value="true" />';
            flash += "<embed src='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "&action=stop' scale='exactfit' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " quality='high' bgcolor='#ffffff' wmode='transparent' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' allowfullscreen='true'/>  ";
            flash += "</object></div>";
        } else {
            flash = "<div id='DivFlash' style='position:fixed; bottom:20; right:20; z-index:1;'>";
            flash += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " >";
            flash += "<param name='allowScriptAccess' value='sameDomain' />";
            flash += "<param name='movie' value='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "&action=stop' />";
            flash += "<param name='quality' value='high' />";
            flash += "<param name='bgcolor' value='#ffffff' />";
            flash += "<param name='wmode' value='transparent'>";
            flash += "<param name='scale' value='exactfit' />";
            flash += '<param name="allowFullScreen" value="true" />';
            flash += "<embed src='" + FlashGuideFile + "?vidBaseURL=" + vidBaseURL + "&action=stop' scale='exactfit' align='middle' width=" + FlashGuideWidth + " height=" + FlashGuideHeight + " quality='high' bgcolor='#ffffff' wmode='transparent' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' allowfullscreen='true'/>  ";
            flash += "</object></div>";
        }
        document.write(flash);
    } catch (ex) {
        alert(ex);
    }
}

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.href = getRadWindow().BrowserWindow.location.href;
}
