function GetRadWindow()  
{  
    var oWindow = null;
      
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog  
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)  
          
    return oWindow;  
}

function OpenLoginWindow()
{    
    window.radopen("/Login.aspx" , "Login");
}

function OpenContentAddWindow(contentPageId, contentGroupId, extendContentGroup, controlHolderWidth)
{    
    window.radopen("/ContentEditor.aspx?PageId="+contentPageId+"&GroupId="+contentGroupId+"&extend="+extendContentGroup+"&ControlHolderWidth="+controlHolderWidth  , "Popup");
}

function OpenEditorWindow(contentPageId, contentItemId, contentType, controlHolderWidth)
{    
    window.radopen("/"+DetermineEditorPage(contentType)+".aspx?PageId="+contentPageId+"&ItemId="+contentItemId+"&ControlHolderWidth="+controlHolderWidth , "Popup");
}

function OpenEditorAddWindow(contentPageId, contentGroupId, contentGroupName, editorPageAndControlStyle, controlHolderWidth)
{
    var array = editorPageAndControlStyle.split('|');
    var editorPage = array[0];
    var conditional="";
    if(array.length>1)
    {
        conditional = "&ControlStyle="+array[1];
    }   
    window.radopen("/"+editorPage+".aspx?PageId="+contentPageId+"&GroupId="+contentGroupId+"&GroupName="+contentGroupName +"&extend=true"+conditional+"&ControlHolderWidth="+controlHolderWidth , "Popup");
}

function OpenContentDeleteWindow(contentItemId, contentPageId)
{    
    window.radopen("/ContentDelete.aspx?ItemId="+contentItemId+"&PageId="+contentPageId+"&Delete=true" , "Popup");
}

/* Close RadWindow and execute parent javascript function */
function CallFunctionOnParentPageAndCloseWindow(fnName)
{
    GetRadWindow().Close();
    
    if (window[fnName])
    {
        window[fnName]();
    }
}

/* Sitemap Editor */
function OpenSiteMapEditor() {
    $("#ToolbarDiv").css('z-index', 1);
    $(".InPage_PublicationTypeNotification").css('z-index', 1);
    window.radopen("/SiteMapEditor.aspx", "Popup");
}

function OpenPageEditorWindow(pageId) {
    window.radopen("/PageEditor.aspx?PageId=" + pageId, "Popup");
}

function OpenSiteMapPageEditorWindow(pageId, parentPageId) {
    window.radopen("/SiteMapPageEditor.aspx?PageId=" + pageId + "&ParentPageId=" + parentPageId, "Popup");
}

/* Refresh parent window */
function RefreshPage()
{
    window.location.href=unescape(window.location);
}

 /* Auto hide scrollbars */
function OnClientShow(radWindow) {
    var oTop
    if (document.documentElement && document.documentElement.scrollTop) {
        oTop = document.documentElement.scrollTop;
        document.documentElement.scroll = "no";
        document.documentElement.style.overflow = "hidden";
        document.documentElement.scrollTop = oTop;

    } else if (document.body) {
        oTop = document.body.scrollTop;        
        document.body.style.overflow = "hidden";
        document.body.scrollTop = oTop;
    }    
}

 /* Reset window size and scrollbars */
function OnClientClose(radWindow) {
    if (document.documentElement && document.documentElement.scrollTop) {
        document.documentElement.scroll = "";
        document.documentElement.style.overflow = "";
    } else if (document.body) {
        document.body.scroll = "";
        document.body.style.overflow = "";
    }
}         
       
/* Close Window */
function CloseWindow()
{
    GetRadWindow().Close();
}

/* Show popup window */      
function ShowForm(url,name)
{
    if (name=='Help'){
        window.open(url,name,'left=20,top=20,width=740,toolbar=0,location=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
    }else{
       window.open(url,name);
    }
}

var popWin = "";
function OpenPopUpWindow(url, strWidth, strHeight) {
    if (popWin != "") {popWin.close()}    
    windowProperties = "toolbar=no,menubar=no,scrollbars=no,statusbar=no,height="+strHeight+",width="+strWidth+",left=50,top=50";
    popWin = window.open(url,'newWin',windowProperties);
}

function GetSelectedContentTypeAndStyle(clientId){
    var comboBox = $find(clientId);        
    var contentType;
    
    if(comboBox.get_value()){
        var array = comboBox.get_value().split('|');
        return DetermineEditorPage(array[0])+"|"+array[1];
        
    }else{
        return DetermineEditorPage(comboBox.get_text());
    }       
}

function DetermineEditorPage(contentType) {
    switch (contentType) {
        case "Rotator":
            return "RotatorEditor";
        case "YouTubeVideo":
            return "YouTubeEditor";
        case "Download":
            return "DownloadEditor";
        case "FAQ":
            return "FAQEditor";
        case "Flash":
            return "FlashEditor";
        case "Table":
            return "TableEditor";
        case "Template":
            return "TemplateEditor";
        case "ImageButton":
            return "ImageButtonEditor";
        case "BulletList":
            return "BulletListEditor";
        case "WeblogItem":
            return "WeblogItemEditor";
        case "NewsLetter":
            return "NewsLetterEditor";
        case "Banner":
            return "BannerEditor";
        default:
            return "ContentEditor";
    }
}

function confirm_delete(text)
{
  if (confirm(text)==true)
    return true;
  else
    return false;
}

/* disable hyperlnks in popup windows */
function disableLinksDuringPreview(divId) {
     $("#"+divId).click(function () { 
      return false;
    });
}