﻿var contentManager = function() {
    this.pageId = null;
    this.content = null;
    this.showStartPartnershipLink = false;
    this.hideNavMenu = false;
    this.jsonservice = new JSONService();
    this.gup = function(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null) {
            return ""
        }
        else {
            return results[1];
        }
    }
    this.enableEditor = function() {
        tinyMCE.init({
            // General options
			entity_encoding: "raw",
            mode: "textareas",
            theme: "advanced",
            font_size_style_values: "8pt,10pt,12pt,14pt,18pt,24pt,36pt",
            plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

            // Theme options
            //theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
            //theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            //theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
            //theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
            theme_advanced_buttons1: "save,|,bold,italic,underline|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,|,forecolor,backcolor",
            theme_advanced_buttons3: "tablecontrols,|,hr,|,template,media,code,fullscreen",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            theme_advanced_resizing: true,

            // Example content CSS (should be your site CSS)
            content_css: "css/content.css",

            // Drop lists for link/image/media/template dialogs
            template_external_list_url: "tinymce/lists/template_list.js",
            //external_link_list_url: "tinymce/lists/link_list.js",
            external_link_list_url: "services/content.aspx?action=fetchlinks&expires=0",
            //external_image_list_url: "content_assets/content_images.js",
            external_image_list_url: "services/content.aspx?action=fetchassets&expires=0",
            //media_external_list_url: "lists/media_list.js"
            media_external_list_url: "services/content.aspx?action=fetchvideos&expires=0"
        });
    }
    this.load = function() {
        this.pageId = this.gup("id");
        this.fetchBreads();
    };
    this.loadPage = function(pageId) {
        document.location = "page.htm?id=" + pageId;
    };

    this.fetchBreads = function() {
        if (cookie.user.rcode == "CM") {
            this.jsonservice.loadScript("content_fetchbreads_0001", "services/content.aspx?action=fetchbreads&id=" + this.pageId + "&callback=myContentMgr.setBreads&expires=0");
        }
        else {
            this.jsonservice.loadScript("content_fetchbreads_0001", "services/content.aspx?action=fetchbreads&id=" + this.pageId + "&callback=myContentMgr.setBreads&expires=600");
        }
    };
    this.setBreads = function(strJson) {
        var objJson = eval("(" + strJson + ")");
        var strTitle = "<span style='cursor:hand;' title='Home' onclick='document.location=\"default.htm\"'>Home</span>";
        var strDocTitle = "Home"
        if (objJson.rows.length > 0) {
            for (var intCount = 0; intCount < objJson.rows.length; intCount++) {
                strTitle += " > <span style='cursor:hand;' title='" + objJson.rows[intCount].title + "' onclick='document.location=\"page.htm?id=" + objJson.rows[intCount].id + "\"'>" + objJson.rows[intCount].title + "</span>";
                strDocTitle += " > " + objJson.rows[intCount].title;
            }
        }
        else {
            strTitle += " > Page Does Not Exist";
        }
        document.title = strDocTitle;
        mybread.render(strTitle);
        //this.fetchContentTabId();
        this.checkPartnershipLink();

    };
    //    this.fetchContentTabId = function() {
    //        if (cookie.user.rcode == "CM") {
    //            this.jsonservice.loadScript("content_fetchcontenttabid_0001", "services/content.aspx?action=fetchcontenttabid&id=" + this.pageId + "&callback=myContentMgr.setContentTabId&expires=0");
    //        }
    //        else {
    //            this.jsonservice.loadScript("content_fetchcontenttabid_0001", "services/content.aspx?action=fetchcontenttabid&id=" + this.pageId + "&callback=myContentMgr.setContentTabId&expires=600");
    //        }
    //    };
    //    this.setContentTabId = function(strJSON) {
    //        var strHtml = [];
    //        var objJson = eval("(" + strJSON + ")");
    //        if (objJson.message) {
    //            return;
    //        }
    //        if (objJson.rows[0].id == 3) {
    //            this.showStartPartnershipLink = true;
    //        }
    //        if (objJson.rows[0].id == 4) {
    //            this.hideNavMenu = true;
    //        }
    //        this.fetchNavMenu();
    //    };
    this.checkPartnershipLink = function() {
        switch (this.pageId) {
            case "17":
            case "21":
            case "22":
            case "23":
            case "24":
            case "25":
            case "26":
            case "27":
            case "28":
                this.showStartPartnershipLink = true;
                break;
            default:
                break;
        }
        this.fetchNavMenu();
    };
    this.fetchNavMenu = function() {
        if (cookie.user.rcode == "CM") {
            this.jsonservice.loadScript("content_fetchcontent_0001", "services/content.aspx?action=fetchnavmenu&id=" + this.pageId + "&role=CM&callback=myContentMgr.setNavMenu&expires=0");
        }
        else {
            this.jsonservice.loadScript("content_fetchcontent_0001", "services/content.aspx?action=fetchnavmenu&id=" + this.pageId + "&callback=myContentMgr.setNavMenu&expires=600");
        }
    };
    this.setNavMenu = function(strJSON) {
        var objJson = eval("(" + strJSON + ")");
        if (objJson.message) {
            return;
        }
        var strHtml = [];
        var isVisible = null;
        var isChecked = null;
        var isContent = null;
        var divNavMenu = document.getElementById("leftnavmenu1");
        strHtml[strHtml.length] = '<table cellspacing="10" cellpadding="0" border="0" width="100%">';
        if (this.hideNavMenu == false) {
            for (var i = 0; i < objJson.rows.length; i++) {
                isChecked = (objJson.rows[i].isvisible == "Y") ? "checked=\"checked\"" : "";
                isVisible = objJson.rows[i].isvisible;
                isContent = objJson.rows[i].iscontent;
                if (isContent == "Y") {
                    if (cookie.user.rcode == "CM") {
                        strHtml[strHtml.length] = '    <tr><td valign="top"><input type="checkbox" id="isvisible" ' + isChecked + ' onclick="myContentMgr.updateVisibility(this, \'' + objJson.rows[i].id + '\')" /></td><td width="100%"><span class="content-sections-link" onclick="myContentMgr.loadPage(\'' + objJson.rows[i].id + '\');" title="' + objJson.rows[i].title + '">' + objJson.rows[i].title + '</span>';
                    }
                    else {
                        if (isVisible == "Y") {
                            strHtml[strHtml.length] = '    <tr><td></td><td><span class="content-sections-link" onclick="myContentMgr.loadPage(\'' + objJson.rows[i].id + '\');" title="' + objJson.rows[i].title + '">' + objJson.rows[i].title + '</span>';
                        }
                    }
                }
                else {
                    if (isVisible == "Y") {
                        strHtml[strHtml.length] = '    <tr><td></td><td><span class="content-sections-link" onclick="myContentMgr.loadPage(\'' + objJson.rows[i].id + '\');" title="' + objJson.rows[i].title + '">' + objJson.rows[i].title + '</span>';
                    }
                }
                if (cookie.user.rcode == "CM") {
                    strHtml[strHtml.length] = '     <td><a href="javascript:myContentMgr.updateMenuSequence(' + objJson.rows[i].id + ',\'U\');">&uarr;</a></td>';
                    strHtml[strHtml.length] = '     <td><a href="javascript:myContentMgr.updateMenuSequence(' + objJson.rows[i].id + ',\'D\');">&darr;</a></td>';
                }
            }
            strHtml[strHtml.length] = '     </td></tr>';
            strHtml[strHtml.length] = '</table>';
            if (this.showStartPartnershipLink == true) {
                strHtml[strHtml.length] = '<div id="id_startpartnership" style="padding-left: 10px; padding-top: 5px;">';
                strHtml[strHtml.length] = '<a href="javascript:application.apply();"><img src="assets/start_partnership.gif" /></a>';
                strHtml[strHtml.length] = '</div>';
            }
            divNavMenu.innerHTML = strHtml.join('');
        }
        else {
            divNavMenu.style.display = "none";
        }
        this.fetchContent();
    };
    this.fetchContent = function() {
        if (cookie.user.rcode == "CM") {
            this.jsonservice.loadScript("content_fetchcontent_0001", "services/content.aspx?action=fetchcontent&id=" + this.pageId + "&callback=myContentMgr.setContent&expires=0");
        }
        else {
            this.jsonservice.loadScript("content_fetchcontent_0001", "services/content.aspx?action=fetchcontent&id=" + this.pageId + "&callback=myContentMgr.setContent&expires=600");
        }
    };
    this.setContent = function(strJSON) {
        var objJson = eval("(" + strJSON + ")");
        this.content = objJson.rows[0];
        var strHtml = [];
        var divHypertext = document.getElementById("hypertext1");
        strHtml[strHtml.length] = '<table cellspacing="10" cellpadding="0" border="0" width="100%">';
        if (objJson.rows.length > 0) {
            strHtml[strHtml.length] = '    <tr><td>' + objJson.rows[0].hypertext + '</td></tr>';
        }
        else {
            strHtml[strHtml.length] = '    <tr><td><h3 style="color:red">This may be an menu page without content <br\>or this page does not exist!!!</h3>Please update any links pointing to this page or add a new page!</td></tr>';
        }
        strHtml[strHtml.length] = '</table>';
        divHypertext.innerHTML = strHtml.join('');
        
        var keyword;
        var chkExact;
        if ($.query.get('keyWord')) {
            keyword = $.query.get('keyWord');
        }
        else
        {
            keyword = '';
        }
        
        if ($.query.get('chkExact') && $.query.get('chkExact')=='true') {
            chkExact = true;
        }
        else
        {
            chkExact = false;
        }
        
        
        if(keyword != "")
        {
            highLightSearch.highlightSearchTerms(keyword,"hypertext1",chkExact);
        }
    };
    this.updateVisibility = function(objCheck, menu_id) {
        var visible = (objCheck.checked == true) ? "Y" : "N";
        if (cookie.user.rcode == "CM") {
            this.jsonservice.loadScript("content_updatevisibility_0001", "services/content.aspx?action=updatevisibility&id=" + menu_id + "&visible=" + visible + "&callback=myContentMgr.setVisibility&expires=0");
        }
    };
    this.setVisibility = function(strJSON) {
        var objJson = eval("(" + strJSON + ")");
        if (objJson.message) {
            return;
        }
    };
    this.updateMenuSequenceSuccess = function(strJSON) {
        var objJson = eval("(" + strJSON + ")");
        this.fetchNavMenu();
        mymenu.load();
        if (objJson.message) {
            return;
        }
    };
    this.updateMenuSequence = function(menu_id, direction) {
        if (cookie.user.rcode == "CM") {
            this.jsonservice.loadScript("content_fetchcontent_0001", "services/content.aspx?action=updatemenusequence&menu_id=" + menu_id + "&direction=" + direction + "&callback=myContentMgr.updateMenuSequenceSuccess&expires=0");
        }
    };
    this.setMenuAction = function(intAction) {
        if (intAction == 1) {
            document.getElementById("menu1form").action = "services/content.aspx?action=deletepullmenu";
        }
        if (intAction == 2) {
            document.getElementById("menu1form").action = "services/content.aspx?action=updatepullmenu";
        }
    };
    this.updateMenuCheck = function() {
        if (document.getElementById("title1").value == "") {
            alert("Please enter a value for Title!")
            document.getElementById("title1").focus();
            return false;
        }
        if (document.getElementById("parent_id").value == "0") {
            alert("Please select TAB!")
            document.getElementById("parent_id").focus();
            return false;
        }
        return true;
    };
    this.updateMenu = function(menuId) {
        var objPullMenu = mymenu.pullmenu;
        var intParentId = null;
        var strTitle = null;
        var intCount = 0;
        for (intCount = 0; intCount < objPullMenu.length; intCount++) {
            if (objPullMenu[intCount].id == menuId) {
                intParentId = objPullMenu[intCount].parent_id;
                strTitle = objPullMenu[intCount].title;
            }
        }
        var strHtml = [];
        strHtml[strHtml.length] = '<form style="margin:0px;" id="menu1form" action="services/content.aspx?action=updatepullmenu" method="post" onsubmit="return myContentMgr.updateMenuCheck();">';
        strHtml[strHtml.length] = '<input type="hidden" name="page_id" value="' + this.pageId + '">';
        strHtml[strHtml.length] = '<input type="hidden" name="id" value="' + menuId + '">';
        strHtml[strHtml.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" width="100%">Edit Menu</td>';
        strHtml[strHtml.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2">';
        strHtml[strHtml.length] = '             <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td colspan="2">';
        strHtml[strHtml.length] = '                         <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                             <tr>';
        strHtml[strHtml.length] = '                                 <td>Title</td>';
        strHtml[strHtml.length] = '                                 <td width="100%"><input type="text" style="width:100%" name="title1" id="title1" /></td>';
        strHtml[strHtml.length] = '                             </tr>';
        strHtml[strHtml.length] = '                             <tr>';
        strHtml[strHtml.length] = '                                 <td nowrap="nowrap">Select Tab</td>';
        strHtml[strHtml.length] = '                                 <td nowrap="nowrap">&nbsp;<select name="parent_id" id="parent_id" /><option value="0">Select Tab</option></select></td>';
        strHtml[strHtml.length] = '                             </tr>';
        strHtml[strHtml.length] = '                         </table>';
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '             </table>';
        strHtml[strHtml.length] = '         </td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" align="left"><input type="submit" value="Delete" onclick="myContentMgr.setMenuAction(1);" />';
        strHtml[strHtml.length] = '         <td class="edit-title" align="right" nowrap="nowrap"><input type="submit" value="Update" onclick="myContentMgr.setMenuAction(2);" />&nbsp;<input type="button" value="Close" onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '</table>';
        strHtml[strHtml.length] = '</form>';

        var editDiv = document.getElementById('editDiv');
        editDiv.style.width = "300px";
        editDiv.innerHTML = strHtml.join('');
        document.getElementById("title1").value = strTitle;

        //load tabs match to the parent_id
        var objSelect = document.getElementById("parent_id");
        var objOption = null;
        for (var intCount = 0; intCount < objPullMenu.length; intCount++) {
            objOption = document.createElement("OPTION");
            objOption.value = objPullMenu[intCount].id;
            if (objPullMenu[intCount].level == 0) {
                objOption.innerText = objPullMenu[intCount].title;
                if (intParentId == objPullMenu[intCount].id) {
                    objOption.setAttribute("selected", true);
                }
                objSelect.appendChild(objOption);
            }
        }
        shadow.show(editDiv, false);
    };
    this.addMenuCheck = function() {
        if (document.getElementById("title1").value == "") {
            alert("Please enter a value for Title!")
            document.getElementById("title1").focus();
            return false;
        }
        if (document.getElementById("parent_id").value == "0") {
            alert("Please select TAB!")
            document.getElementById("parent_id").focus();
            return false;
        }
        return true;
    };
    this.addMenu = function() {
        var objPullMenu = mymenu.pullmenu;
        var strHtml = [];
        strHtml[strHtml.length] = '<form style="margin:0px;" id="menu1form" action="services/content.aspx?action=addpullmenu" method="post" onsubmit="return myContentMgr.updateMenuCheck();">';
        strHtml[strHtml.length] = '<input type="hidden" name="page_id" value="' + this.pageId + '">';
        strHtml[strHtml.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" width="100%">Add Menu</td>';
        strHtml[strHtml.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2">';
        strHtml[strHtml.length] = '             <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td colspan="2">';
        strHtml[strHtml.length] = '                         <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                             <tr>';
        strHtml[strHtml.length] = '                                 <td>Title</td>';
        strHtml[strHtml.length] = '                                 <td width="100%"><input type="text" style="width:100%" name="title1" id="title1" /></td>';
        strHtml[strHtml.length] = '                             </tr>';
        strHtml[strHtml.length] = '                             <tr>';
        strHtml[strHtml.length] = '                                 <td nowrap="nowrap">Select Tab</td>';
        strHtml[strHtml.length] = '                                 <td nowrap="nowrap">&nbsp;<select name="parent_id" id="parent_id" /><option value="0">Select Tab</option></select></td>';
        strHtml[strHtml.length] = '                             </tr>';
        strHtml[strHtml.length] = '                         </table>';
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '             </table>';
        strHtml[strHtml.length] = '         </td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2" class="edit-title" align="right"><input type="submit" value="Add" />&nbsp;<input type="button" value="Close" onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '</table>';
        strHtml[strHtml.length] = '</form>';

        var editDiv = document.getElementById('editDiv');
        editDiv.style.width = "350px";
        editDiv.innerHTML = strHtml.join('');

        //load tabs match to the page_id
        var objSelect = document.getElementById("parent_id");
        var objOption = null;
        for (var intCount = 0; intCount < objPullMenu.length; intCount++) {
            objOption = document.createElement("OPTION");
            objOption.value = objPullMenu[intCount].id;
            if (objPullMenu[intCount].level == 0) {
                objOption.innerText = objPullMenu[intCount].title;
                objSelect.appendChild(objOption);
            }
        }
        shadow.show(editDiv, false);
    };
    this.setContentAction = function(intAction) {
        if (intAction == 1) {
            document.getElementById("content1form").action = "services/content.aspx?action=deletecontent";
        }
        if (intAction == 2) {
            document.getElementById("content1form").action = "services/content.aspx?action=updatecontent";
        }
    };
    this.updateContentCheck = function() {
        if (document.getElementById("title1").value == "") {
            alert("Please enter a value for Title!")
            document.getElementById("title1").focus();
            return false;
        }
        if (document.getElementById("parent_id").value == "0") {
            alert("Please select TAB!")
            document.getElementById("parent_id").focus();
            return false;
        }
        return true;
    };
    this.updateContent = function() {
        var objContent = this.content;
        var objPullMenu = mymenu.pullmenu;
        var intParentId = null;
        var intContentId = null;
        var sectionTitle = null;
        var sectionHtml = null;
        var allowDelete = 'Y';

        intParentId = objContent.parent_id;
        intMenuId = objContent.menu_id;
        sectionTitle = objContent.title;
        sectionHtml = objContent.hypertext;
        allowDelete = objContent.allowdelete;
        var strHtml = [];
        strHtml[strHtml.length] = '<form style="margin:0px;" id="content1form" action="services/content.aspx?action=updatecontent" method="post" onsubmit="return myContentMgr.updateContentCheck();">';
        strHtml[strHtml.length] = '<input type="hidden" name="page_id" value="' + this.pageId + '">';
        strHtml[strHtml.length] = '<input type="hidden" name="menu_id" value="' + intMenuId + '">';
        strHtml[strHtml.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" width="100%">Edit Content</td>';
        strHtml[strHtml.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2">';
        strHtml[strHtml.length] = '             <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td colspan="2">';
        strHtml[strHtml.length] = '                         <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                             <tr>';
        strHtml[strHtml.length] = '                                 <td>Title</td>';
        strHtml[strHtml.length] = '                                 <td width="100%"><input type="text" style="width:100%" name="title1" id="title1" /></td>';
        strHtml[strHtml.length] = '                                 <td nowrap="nowrap">&nbsp;<select name="parent_id" id="parent_id" /><option value="0">Select Tab</option></select></td>';
        strHtml[strHtml.length] = '                             </tr>';
        strHtml[strHtml.length] = '                         </table>';
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td colspan="2"><textarea style=width:100%;height:350px;" name="hypertext" id="hypertext"></textarea></td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '             </table>';
        strHtml[strHtml.length] = '         </td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        if (allowDelete == 'Y') {
            strHtml[strHtml.length] = '         <td class="edit-title" align="left"><input type="submit" value="Delete" onclick="myContentMgr.setContentAction(1);" /></td>';
        } else {
            strHtml[strHtml.length] = '         <td class="edit-title" align="left">This Page Cannot be Deleted</td>';
        }
        strHtml[strHtml.length] = '         <td class="edit-title" align="right" nowrap="nowrap"><input type="submit" value="Update" onclick="myContentMgr.setContentAction(2);" />&nbsp;<input type="button" value="Close" onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '</table>';
        strHtml[strHtml.length] = '</form>';

        var editDiv = document.getElementById('editDiv');
        editDiv.style.width = "650px";
        editDiv.innerHTML = strHtml.join('');
        document.getElementById("title1").value = sectionTitle;
        document.getElementById("hypertext").value = sectionHtml;

        //load tabs match to the parent_id
        var objSelect = document.getElementById("parent_id");
        var objOption = null;
        var intCount0 = 0;
        var intCount1 = 0;
        var intParentMenuId = 0;
        for (intCount0 = 0; intCount0 < objPullMenu.length; intCount0++) {
            objOption = document.createElement("OPTION");
            objOption.value = objPullMenu[intCount0].id;
            intParentMenuId = objPullMenu[intCount0].id;
            if (objPullMenu[intCount0].level == 0) {
                objOption.innerHTML = objPullMenu[intCount0].title;
                objOption.style.backgroundColor = "#49A3FF";
                objOption.style.color = "white";
                if (intParentId == objPullMenu[intCount0].id) {
                    objOption.setAttribute("selected", true);
                }
                objSelect.appendChild(objOption);
                for (intCount1 = 0; intCount1 < objPullMenu.length; intCount1++) {
                    objOption = document.createElement("OPTION");
                    objOption.value = objPullMenu[intCount1].id;
                    if (intParentId == objPullMenu[intCount1].id) {
                        objOption.setAttribute("selected", true);
                    }
                    if (objPullMenu[intCount1].level == 1 && objPullMenu[intCount1].parent_id == intParentMenuId) {
                        objOption.innerHTML = "&nbsp;&nbsp;&nbsp;>>&nbsp;" + objPullMenu[intCount1].title;
                        objSelect.appendChild(objOption);
                    }
                }
            }
        }
        this.enableEditor();
        shadow.show(editDiv, false);
    };
    this.addContentCheck = function() {
        if (document.getElementById("title1").value == "") {
            alert("Please enter a value for Title!")
            document.getElementById("title1").focus();
            return false;
        }
        if (document.getElementById("parent_id").value == "0") {
            alert("Please select TAB!")
            document.getElementById("parent_id").focus();
            return false;
        }
        return true;
    }
    this.addContent = function() {
        var objPullMenu = mymenu.pullmenu;
        var strHtml = [];
        strHtml[strHtml.length] = '<form style="margin:0px;" id="section1form" action="services/content.aspx?action=addcontent" method="post" onsubmit="return myContentMgr.addContentCheck();">';
        strHtml[strHtml.length] = '<input type="hidden" name="page_id" value="' + this.pageId + '">';
        strHtml[strHtml.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" width="100%">Add New Page</td>';
        strHtml[strHtml.length] = '         <td class="edit-title"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2">';
        strHtml[strHtml.length] = '             <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td colspan="2">';
        strHtml[strHtml.length] = '                         <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                             <tr>';
        strHtml[strHtml.length] = '                                 <td>Title</td>';
        strHtml[strHtml.length] = '                                 <td width="100%"><input type="text" style="width:100%" name="title1" id="title1" /></td>';
        strHtml[strHtml.length] = '                                 <td nowrap="nowrap">&nbsp;<select name="parent_id" id="parent_id" /><option value="0">Select Tab</option></select></td>';
        strHtml[strHtml.length] = '                             </tr>';
        strHtml[strHtml.length] = '                         </table>';
        strHtml[strHtml.length] = '                     </td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td colspan="2"><textarea style=width:100%;height:350px;" name="hypertext" id="hypertext"></textarea></td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '             </table>';
        strHtml[strHtml.length] = '         </td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2" class="edit-title" align="right" nowrap="nowrap"><input type="submit" value="Add" />&nbsp;<input type="button" value="Close" onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '</table>';
        strHtml[strHtml.length] = '</form>';

        var editDiv = document.getElementById('editDiv')
        editDiv.style.width = "650px";
        editDiv.innerHTML = strHtml.join('');

        //load tabs match to the parent_id
        var objSelect = document.getElementById("parent_id");
        var objOption = null;
        var intCount0 = 0;
        var intCount1 = 0;
        var intParentMenuId = 0;
        for (intCount0 = 0; intCount0 < objPullMenu.length; intCount0++) {
            objOption = document.createElement("OPTION");
            objOption.value = objPullMenu[intCount0].id;
            intParentMenuId = objPullMenu[intCount0].id;
            if (objPullMenu[intCount0].level == 0) {
                objOption.innerHTML = objPullMenu[intCount0].title;
                objOption.style.backgroundColor = "#49A3FF";
                objOption.style.color = "white";
                objSelect.appendChild(objOption);
                if (objPullMenu[intCount0].id == this.pageId) {
                    objOption.setAttribute("selected", true);
                }
                for (intCount1 = 0; intCount1 < objPullMenu.length; intCount1++) {
                    objOption = document.createElement("OPTION");
                    objOption.value = objPullMenu[intCount1].id;
                    if (objPullMenu[intCount1].level == 1 && objPullMenu[intCount1].parent_id == intParentMenuId) {
                        objOption.innerHTML = "&nbsp;&nbsp;&nbsp;>>&nbsp;" + objPullMenu[intCount1].title;
                        objSelect.appendChild(objOption);
                        if (objPullMenu[intCount1].id == this.pageId) {
                            objOption.setAttribute("selected", true);
                        }
                    }
                }
            }
        }
        this.enableEditor();
        shadow.show(editDiv, false);
    };
    this.uploadMediaCheck = function() {
        if (document.getElementById("title1").value == "") {
            alert("Please enter a value for Title!")
            document.getElementById("title1").focus();
            return false;
        }
        if (document.getElementById("image1").value == "") {
            alert("Please select a file to Upload!")
            document.getElementById("image1").focus();
            return false;
        }
        return true;
    }
    this.mediachanged = function() {
        try {
            var strFile = document.getElementById("image1").value;
            var pos = strFile.lastIndexOf("\\");
            strFile = strFile.substring(pos + 1);
            pos = strFile.lastIndexOf(".");
            strFile = strFile.substring(0, pos);
            document.getElementById("title1").value = strFile;
        }
        catch (e) {
        }
    };
    this.uploadMedia = function() {
        var strHtml = [];
        strHtml[strHtml.length] = '<form style="margin:0px;" id="media1form" action="services/content.aspx?action=addasset" method="post" onsubmit="return myContentMgr.uploadMediaCheck();" enctype="multipart/form-data">';
        strHtml[strHtml.length] = '<input type="hidden" name="page_id" value="' + this.pageId + '">';
        strHtml[strHtml.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td class="edit-title" width="100%">Upload Media</td>';
        strHtml[strHtml.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2">';
        strHtml[strHtml.length] = '             <table cellspacing="0" cellpadding="2" border="0" width="100%">';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td>Title</td>';
        strHtml[strHtml.length] = '                     <td width="100%"><input type="text" style="width:200px" name="title1" id="title1" /></td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '                 <tr>';
        strHtml[strHtml.length] = '                     <td>Media</td>';
        strHtml[strHtml.length] = '                     <td width="100%"><input type="file" style="width:100%" name="image1" id="image1" onchange="myContentMgr.mediachanged();" /></td>';
        strHtml[strHtml.length] = '                 </tr>';
        strHtml[strHtml.length] = '             </table>';
        strHtml[strHtml.length] = '         </td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '     <tr>';
        strHtml[strHtml.length] = '         <td colspan="2" class="edit-title" align="right" nowrap="nowrap"><input type="submit" value="Upload" />&nbsp;<input type="button" value="Cancel" onclick="shadow.hide()" /></td>';
        strHtml[strHtml.length] = '     </tr>';
        strHtml[strHtml.length] = '</table>';
        strHtml[strHtml.length] = '</form>';

        var uploadMedia = document.getElementById('uploadMedia');
        uploadMedia.innerHTML = strHtml.join('');
        shadow.show(uploadMedia, false);
    };
    this.eventHandler = function(ev) {
        if (ev.altKey && (ev.keyCode == 122)) {
            cookie.create("edit", "true", 60);
            document.location = document.location;
        }
    };
};
var myContentMgr = new contentManager();
myContentMgr.load();

/*
if (window.addEventListener) { // Mozilla, Netscape, Firefox
window.addEventListener("keydown", myContentMgr.eventHandler, false);
} else { // IE
document.attachEvent("onkeydown", myContentMgr.eventHandler);
}
*/

