// CMSNET_client
var CMSNET_framework_path = "";

function CMSNET_CLIENT_doHideDialog() {
    document.getElementById("CMSNET_CLIENT_divPage").innerHTML = ''
    document.getElementById("CMSNET_CLIENT_divDialog").style.visibility = "hidden"
}

function CMSNET_CLIENT_doShowDialog() {
    var name = "popup"; // popup name
    var width = "500"; // popup width
    var height = "400"; // popup height
    //var left = (document.body.clientWidth /2) - (width /2);
    //var top = (document.body.clientHeight /2) - (height / 2);

    var theLeft;
    var theTop;
    var x;
    var y;
    var thescwidth;
    var thescheight;
    x = 300;
    y = 70;

    obj = document.getElementById("CMSNET_CLIENT_divDialog");
    if (document.documentElement) {
        theLeft = document.documentElement.scrollLeft;
        theTop = document.documentElement.scrollTop;
        thescwidth = document.body.clientWidth
        thescheight = document.body.clientHeight
    }
    else if (document.body) {
        theLeft = document.body.scrollLeft;
        theTop = document.body.scrollTop;
    }
    theLeft += x;
    theTop += y;
    obj.style.left = theLeft + 'px';
    obj.style.top = theTop + 'px';
    obj.style.width = width + 'px';
    obj.style.height = height + 'px';
    obj.style.zIndex = '1000';
    obj.style.visibility = 'visible';
    document.getElementById("CMSNET_CLIENT_divPage").style.height = height - 30 + 'px';
}

function CMSNET_CLIENT_doOpenDialog(pURL, pWidth, pHeight, pResizable) {
    var a = showModalDialog(pURL, null, "resizable=" + pResizable + ";status:yes;help:no;minimize:no;lmaximize:yes;border:thin;statusbar:no;dialogWidth:" + pWidth + "px;dialogHeight:" + pHeight + "px")
    return (a);

}

function CMSNET_CLIENT_doRefreshPage() {
    var strURL = document.location.href
    window.location.href = strURL;
}

function createAjaxObj() {
    var httprequest = false
    if (window.XMLHttpRequest) { // if Mozilla, Safari etc
        httprequest = new XMLHttpRequest()
        if (httprequest.overrideMimeType)
            httprequest.overrideMimeType('text/xml')
    }
    else if (window.ActiveXObject) { // if IE
        try {
            httprequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                httprequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) { }
        }
    }
    return httprequest
}

// CMSNET_ph

function CMSNET_PH_doEditSection(pPageID, pSectionID, pSectionType, pPath) {
    var pwidth = 990;
    var pheight = 700;

    if (pPath == 'undefined' || pPath == '') {
        pPath = "";
    }
    else {
        pPath = pPath.substr(0, pPath.lastIndexOf('/') + 1)

    }


    if (pSectionID == 'undefined') {
        pSectionID = pPageID;

    }

    if (pSectionType == 'undefined') {
        pSectionType = 'text';
    }

    if (pSectionType == 'video') {
        dialogPath = "ph_editvideo.aspx"
        pwidth = 850;
        pheight = 600;

    }
    else {
        dialogPath = "ph_edit01.aspx"
    }

    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=" + dialogPath + "&SectionID=" + pSectionID + "&PageID=" + pPageID + "&Type=" + pSectionType + "&path=" + pPath;
    var strResult;
    //alert(strURL)
    CMSNET_CLIENT_doOpenDialog(strURL, pwidth, pheight, "yes");
    CMSNET_SWITCH_doSwitchMode(1);
}

function CMSNET_PH_doAddSection(pPageID, pPHID) {
    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=ph_add.aspx&PageID=" + pPageID + "&PHID=" + pPHID

    //alert(strURL)
    var strResult = CMSNET_CLIENT_doOpenDialog(strURL, 410, 380, "no");
    //if (strResult == "OK") {
    CMSNET_SWITCH_doSwitchMode(2);
    //}
}

function CMSNET_PH_doDeleteSection(pSectionID) {
    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=ph_delete.aspx&SectionID=" + pSectionID
    var strResult = CMSNET_CLIENT_doOpenDialog(strURL, 410, 380, "no");
    CMSNET_SWITCH_doSwitchMode(2);
}


// CMSNET_switch

function CMSNET_SWITCH_doPosition(pCaption, pMode) {
    var temp1 = document.getElementById("globalLinks")
    var x = "5px"//temp1.offsetWidth - 30
    //var temp2 = '<li style="text-align:left;padding-right:' + x + 'px;border:0px">&nbsp;&nbsp;<a href="javascript:CMSNET_SWITCH_doSwitchMode(' + pMode + ')" onMouseover="dropdownmenu(this, event, \'anylinkmenu1\');">' + pCaption + '</a></li><iframe id="CMSNET_SWITCH_ifSwitch" name="CMSNET_SWITCH_ifSwitch" width="0" height="0" frameborder="0"></iframe>' + temp1.innerHTML
    /*
    var temp2 = '<li style="text-align:left;padding-right:' + x + 'px;border:0px">&nbsp;&nbsp;<a href="#" '
    if (pMode=="1") {
    temp2 += ' onclick="CMSNET_SWITCH_doSwitchMode(0)" '
    temp2 += ' onmouseover="mopen(\'m1\')" '
    } else {
    temp2 += ' onclick="CMSNET_SWITCH_doSwitchMode(1)" '
    }
    temp2 += '  onmouseout="mclosetime()">' + pCaption + '</a></li>' + temp1.innerHTML
            
    document.getElementById("globalLinks").innerHTML = temp2
    */

    var temp2 = '<div style="position:absolute;top:1px;left:20px"><a style="color:#fff" href="javascript:CMSNET_SWITCH_doSwitchMode(' + pMode + ')" '
    if (pMode == "1") {
        temp2 += ' onclick="CMSNET_SWITCH_doSwitchMode(0)" '
    } else {
        temp2 += ' onclick="CMSNET_SWITCH_doSwitchMode(1)" '
        temp2 += ' onmouseover="mopen(\'m1\')" '
    }
    temp2 += '  onmouseout="mclosetime()">' + pCaption + '</a><iframe id="CMSNET_SWITCH_ifSwitch" name="CMSNET_SWITCH_ifSwitch" width="0" height="0" frameborder="0"></iframe></div>'

    document.write(temp2)
}

function CMSNET_SWITCH_doSwitchMode(pMode) {
    var temp = document.location.href
    var strURL = CMSNET_framework_path + "sw.aspx?Referer=" + temp.replace("?", "[q]")
    strURL = strURL.replace("&", "[a]")
    strURL = strURL + "&Mode=" + pMode
    //alert(strURL);
    window.location.href = strURL;
}

function CMSNET_SWITCH_doChangeLanguage(pLangCode) {
    var temp = document.location.href
    var strURL = CMSNET_framework_path + "CMSNET_sw.aspx?Referer=" + temp.replace("?", "[q]")
    strURL = strURL.replace("&", "[a]")
    strURL += "&LangCode=" + pLangCode
    window.location.href = strURL
}

function CMSNET_SWITCH_doApproveToPublish(pPageID) {
    var strURL = CMSNET_framework_path + "CMSNET_dialog.aspx?dialogpage=CMSNET_page_publish.aspx&PageID=" + pPageID
    //alert(strURL)
    var strResult = CMSNET_CLIENT_doOpenDialog(strURL);
    //if (strResult == "OK") {
    CMSNET_SWITCH_doSwitchMode(1);
    //}
}

function CMSNET_SWITCH_doFlagForApproval() {
    var strURL = CMSNET_framework_path + "CMSNET_dialog.aspx?dialogpage=CMSNET_page_publish.aspx&Mode=Flag&PageID=" + pPageID
    //alert(strURL)
    var strResult = CMSNET_CLIENT_doOpenDialog(strURL);
    //if (strResult == "OK") {
    CMSNET_SWITCH_doSwitchMode(1);
    //}
}

function CMSNET_SWITCH_doShowPageProperties() {
}


function CMSNET_PageModal(pURL, pWidth, pHeight) {
    showModalDialog(pURL, null, "resizable=no;status:yes;help:no;minimize:no;lmaximize:yes;border:thin;statusbar:no;dialogWidth:" + pWidth + "px;dialogHeight:" + pHeight + "px")
}



///  --------------------------------------------------------

// Copyright 2006-2007 javascript-array.com

var timeout = 1000;
var closetimer = 0;
var ddmenuitem = 0;

// open hidden layer
function mopen(id) {
    // cancel close timer
    //mcancelclosetime();

    // close old layer
    //if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

    // get new layer and show it
    ddmenuitem = document.getElementById(id);
    ddmenuitem.style.top = "18px";
    ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose() {
    if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime() {
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

// close layer when click-out
document.onclick = mclose;




//Added for SiteMap
var curNode = 0
// Constant value of dialog width/height
var addDialogWidth = 580;
var addDialogHeight = 700;
var editDialogWidth = 650;
var editDialogHeight = 700;
var deleteDialogWidth = 580;
var deleteDialogHeight = 440

function doClickNode(pNodeID) {
    if (curNode != 0) {
        document.getElementById('node' + curNode).className = 'node'
    }
    curNode = pNodeID
    document.getElementById('node' + curNode).className = 'selnode'
}

function doAddNewPage() {
    try {
        var TypeID = document.getElementById('nod' + SelPageID).getAttribute('Type')
    }
    catch (err) { alert('Please select a page'); return false; }
    if (TypeID == 'undefined') {
        TypeID = 1;

    }
    switch (TypeID) {
        //case '3': 
        //alert("Creating a child node for a Redirection Page Type is not allowed!"); 
        //break; 
        default:
            var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageRedirectInsert.aspx&pageId=" + SelPageID
            var strResult = CMSNET_CLIENT_doOpenDialog(strURL, addDialogWidth, addDialogHeight, "yes");
            // JFUI - Only refresh window when needed
            if (strResult == 1) {
                CMSNET_SWITCH_doSwitchMode(1)
                //CMSNET_CLIENT_doRefreshPage();
            }
    }
}

function doEditPage(pPageID) {
    if (!pPageID == 'undefined' || !pPageID == '') {
        SelPageID = pPageID;
    }
    if (SelPageID == 0 || SelPageID == 'undefined') {
        alert('Please select a page');
        return false;
    } else {
        var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageRedirectUpdate.aspx&pageId=" + SelPageID
        var strResult = CMSNET_CLIENT_doOpenDialog(strURL, editDialogWidth, editDialogHeight, "yes");
        // JFUI - Only refresh window when needed
        if (strResult == 1) {
            CMSNET_SWITCH_doSwitchMode(1)
            //CMSNET_CLIENT_doRefreshPage();
        }
        else {
            return false;
        }
    }
}




function doDeletePage() {
    if (SelIndex == 0) {
    } else {
        var answer = confirm('You are about to Delete this page and all the pages underneath it. Continue?')
        if (answer) {
            var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageDelete.aspx&pageId=" + SelPageID
            var strResult = CMSNET_CLIENT_doOpenDialog(strURL, deleteDialogWidth, deleteDialogHeight, "yes");
            // JFUI - Only refresh window when needed
            if (strResult == 1) {
                CMSNET_SWITCH_doSwitchMode(1)
                //CMSNET_CLIENT_doRefreshPage();
            }
        }
    }
}


// For News

var addNewsDialogWidth = 550;
var addNewsDialogHeight = 620;
var editNewsDialogWidth = 550;
var editNewsDialogHeight = 620;
var deleteNewsDialogWidth = 550;
var deleteNewsDialogHeight = 340
function doAddNews(pPageID,pPageTypeID) {

    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageInsertNews.aspx&pageId=" + pPageID + "&pageTypeId=10"
    var strResult = CMSNET_CLIENT_doOpenDialog(strURL, addNewsDialogWidth, addNewsDialogHeight, "no");
    // JFUI - Only refresh window when needed
    if (strResult == 1) {
        CMSNET_SWITCH_doSwitchMode(1)
        //CMSNET_CLIENT_doRefreshPage();
    }
}

function doEditNews(pPageID) {
    if (SelPageID == 0 || SelPageID == 'undefined') {
        alert('Please select a news article');
        return false;
    } else {
    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageRedirectUpdate.aspx&pageId=" + SelPageID
        var strResult = CMSNET_CLIENT_doOpenDialog(strURL, editNewsDialogWidth, editNewsDialogHeight, "no");
        // JFUI - Only refresh window when needed
        if (strResult == 1) {
            CMSNET_SWITCH_doSwitchMode(1)
            //CMSNET_CLIENT_doRefreshPage();
        }
        else {
            return false;
        }
    }
}

function doMovetoArchive(pPageID) {
    if (SelPageID == 0 || SelPageID == 'undefined') {
        alert('Please select a news article');
        return false;
    } else {
        var answer = confirm('You are about to move this news article to Archives. Continue?')
        if (answer) {
            var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageArchiveNews.aspx&pageId=" + SelPageID
            var strResult = CMSNET_CLIENT_doOpenDialog(strURL, deleteNewsDialogWidth, deleteNewsDialogHeight, "no");
            // JFUI - Only refresh window when needed
            if (strResult == 1) {
                CMSNET_SWITCH_doSwitchMode(1)
                //CMSNET_CLIENT_doRefreshPage();
            }
        }
    }
}


function doDeleteNews(pPageID) {
    if (SelPageID == 0 || SelPageID == 'undefined') {
        alert('Please select a news article');
        return false;
    } else {
        var answer = confirm('You are about to Delete this news article. Continue?')
        if (answer) {
            var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageDeleteNews.aspx&pageId=" + SelPageID
            var strResult = CMSNET_CLIENT_doOpenDialog(strURL, deleteNewsDialogWidth, deleteNewsDialogHeight, "no");
            // JFUI - Only refresh window when needed
            if (strResult == 1) {
                CMSNET_SWITCH_doSwitchMode(1)
                //CMSNET_CLIENT_doRefreshPage();
            }
        }
    }
}


// For Article CALTEX

var addArticleDialogWidth = 550;
var addArticleDialogHeight = 620;
var editArticleDialogWidth = 550;
var editArticleDialogHeight = 520;
var deleteArticleDialogWidth = 550;
var deleteArticleDialogHeight = 340;


function doAddArticle(pPageID, pPageTypeID) {

    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageInsertArticle.aspx&pageId=" + pPageID + "&pageTypeId=" + pPageTypeID;
    var strResult = CMSNET_CLIENT_doOpenDialog(strURL, addArticleDialogWidth, addArticleDialogHeight, "no");
    // JFUI - Only refresh window when needed
    if (strResult == 1) {
        CMSNET_SWITCH_doSwitchMode(1)
        //CMSNET_CLIENT_doRefreshPage();
    }
}

function doEditArticle(pPageID) {
    if (SelPageID == 0 || SelPageID == 'undefined') {
        alert('Please select an article');
        return false;
    } else {
        var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageRedirectUpdate.aspx&pageId=" + SelPageID
        var strResult = CMSNET_CLIENT_doOpenDialog(strURL, editArticleDialogWidth, editArticleDialogHeight, "no");
        // JFUI - Only refresh window when needed
        if (strResult == 1) {
            CMSNET_SWITCH_doSwitchMode(1)
            //CMSNET_CLIENT_doRefreshPage();
        }
        else {
            return false;
        }
    }
}


function doDeleteArticle(pPageID) {
    if (SelPageID == 0 || SelPageID == 'undefined') {
        alert('Please select an article');
        return false;
    } else {
        var answer = confirm('You are about to Delete this article. Continue?')
        if (answer) {
            var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageDeleteArticle.aspx&pageId=" + SelPageID
            var strResult = CMSNET_CLIENT_doOpenDialog(strURL, deleteArticleDialogWidth, deleteArticleDialogHeight, "no");
            // JFUI - Only refresh window when needed
            if (strResult == 1) {
                CMSNET_SWITCH_doSwitchMode(1)
                //CMSNET_CLIENT_doRefreshPage();
            }
        }
    }
}



// For Articles
function doAddNewArticlePage(pPageID, pTemplateID, pSectionID) {
    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=ArticleInsert.aspx&pageId=" + pPageID + "&templateId=" + pTemplateID + "&sectionID=" + pSectionID

    //alert(strURL)

    var strResult = CMSNET_CLIENT_doOpenDialog(strURL, addDialogWidth, addDialogHeight, "no");
    // JFUI - Only refresh window when needed
    if (strResult == 1) {
        CMSNET_SWITCH_doSwitchMode(1)
        //CMSNET_CLIENT_doRefreshPage();
    }
}

function doEditArticlePage() {
    if (curNode == 0) {
        return false;
    }
    else {
        var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=ArticleUpdate.aspx&pageId=" + document.getElementById('node' + curNode).getAttribute('RecID')
        var strResult = CMSNET_CLIENT_doOpenDialog(strURL, editDialogWidth, editDialogHeight, "no");
        // JFUI - Only refresh window when needed
        if (strResult == 1) {
            CMSNET_SWITCH_doSwitchMode(1)
            //CMSNET_CLIENT_doRefreshPage();
        }
    }
}

function doDeleteArticlePage() {
    if (curNode == 0) {
        return false;
    }
    else {
        var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=ArticleDelete.aspx&pageId=" + document.getElementById('node' + curNode).getAttribute('RecID')
        var strResult = CMSNET_CLIENT_doOpenDialog(strURL, deleteDialogWidth, deleteDialogHeight, "no");
        // JFUI - Only refresh window when needed
        if (strResult == 1) {
            CMSNET_SWITCH_doSwitchMode(1)
            //CMSNET_CLIENT_doRefreshPage();
        }
    }
}


function ShowStatus1(pText, pID) {
    document.getElementById(pID).innerHTML = pText;
    document.getElementById(pID).style.display = "block";
    document.getElementById(pID).style.color = "green";

    var t = setTimeout("HideStatus('" + pID + "')", 5000);
}

function ShowStatus2(pText, pID) {
    document.getElementById(pID).innerHTML = pText;
    document.getElementById(pID).style.display = "block";
    document.getElementById(pID).style.color = "red";

    var t = setTimeout("HideStatus('" + pID + "')", 5000);
}

function HideStatus(pID) {
    document.getElementById(pID).innerHTML = " ";
}

function doBrowseRoot(pRootID, pHidRootID) {
    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageBrowse.aspx"
    var strResults = CMSNET_CLIENT_doOpenDialog(strURL, 410, 500, "no");

    //alert(strResults)
    var arResults = strResults.split("|")

    document.getElementById(pHidRootID).value = arResults[0]
    document.getElementById(pRootID).value = arResults[1]
}

function doBrowseTemplate(pTemplateID, pHidTemplateID) {
    var strURL = CMSNET_framework_path + "dialog.aspx?dialogpage=PageTemplateBrowse.aspx"
    var strResults = CMSNET_CLIENT_doOpenDialog(strURL, 380, 550, "no");

    if (strResults != 'undefined') {

        if (!strResults == 0) {
            var arResults = strResults.split("|");
            document.getElementById(pHidTemplateID).value = arResults[0];
            document.getElementById(pTemplateID).value = arResults[1];
            //CMSNET_SWITCH_doSwitchMode(1)
        }

    }
}


function doSelItem(pIndex, pPageID, pHidID) {
    var SelIndex = 0
    var SelPageID = 0

    document.getElementById('hidSelPageiD').value = ""
    document.getElementById(pHidID).value = ""

    var elem = document.getElementById('content');
    var divArr = elem.getElementsByTagName("div");
    for (var i = 0; i < divArr.length; i++) {
        if (divArr[i].name == "divArticle") {
            if (divArr[i].id == "divArticleItem" + pPageID) {
                divArr[i].className = "article_item_sel"
            }
            else {
                divArr[i].className = "article_item"
            }
        }
    }

    document.getElementById(pHidID).value = pPageID
    document.getElementById('hidSelPageiD').value = pPageID


    var inputArr = elem.getElementsByTagName("input");
    for (var i = 0; i < inputArr.length; i++) {
        if (inputArr[i].id == pHidID) {
        }
        else {
            inputArr[i].value = ""
        }
    }

    SelPageID = pPageID
    SelIndex = pIndex
}

function doCheckSelItem(pType, pHidID) {
    if (!document.getElementById(pHidID).value == "") {
        if (pType == 'Delete') {
            Ans = confirm('Are you sure you want to DELETE this article?');
        }
        else {
            Ans = confirm('Are you sure you want to MOVE this to the ' + pType + ' page?');
        }
        return Ans;
    }
    else {
        if (pType == 'Delete') {
            alert('Please select an article to DELETE');
        }
        else {
            alert('Please select an article to MOVE');
        }
        return false;
    }
}

function doHighlight(pID, pClassName) {
    document.getElementById(pID).className = pClassName
}

function doUndoHighlight(pID, pClassName) {
    document.getElementById(pID).className = pClassName
}


