﻿// JScript File

/*********************************************************************/
//    MESSAGES
/*********************************************************************/

var MSG_CONFIRM_PUBLISH = "This operation will replace the current help. Do you want to continue?";
var MSG_CONFIRM_DELETE = "All topics below this node will be removed. Do you want to continue?";
var MSG_CONFIRM_DISCARD_CHANGES = "This topic has not been saved. Discard the changes?";
var MSG_ALERT_BROWSER_INCOMPATIBLE = "Your browser can\'t handle this script";
var MSG_ALERT_TYPE_TITLE = "Type the title for this object.";
var MSG_ALERT_TITLE_FIELD_REQUIRED = "The title field is required.";
var MSG_ALERT_URL_FIELD_REQUIRED = "The url field is required.";
var ALT_TURN_HELP_ON = "Click to turn the help on";
var ALT_TURN_HELP_OFF = "Click to turn the help off";


/*********************************************************************/
//    HELP VIEWER
/*********************************************************************/

var xmlDoc;

var help_lastCtx = "";
var help_lastUrl = "";
		
function setHelp (helpMode) {
    
    if (helpMode) {
        document.onmouseup = function () {             
            event.cancelBubble = true;
            if (!(event.srcElement.imageUrlSwap)) {
                var ctx = event.srcElement.id;                        
                if (ctx == document.forms[0].id) {
                    ctx = "";
                }                        
                showHelp(ctx);            
            }
        }
    }
    else {    
        document.onmouseup = "";
    }
    
}

function swapHelpMode (obj) {
    
    var nameSrc = obj.src.substr(obj.src.lastIndexOf("/") + 1);
    var nameOrginal = obj.imageUrlOriginal.substr(obj.imageUrlOriginal.lastIndexOf("/") + 1);
    
    if (nameSrc == nameOrginal) {           
        document.body.style.cursor = "help";             
        obj.src = obj.imageUrlSwap;
        obj.alt = ALT_TURN_HELP_OFF;
        setHelp(true);
    } 
    else {                
        document.body.style.cursor = "default";     
        obj.src = obj.imageUrlOriginal;
        obj.alt = ALT_TURN_HELP_ON;
        setHelp(false);        
    }
}

function showHelp (ctx) {
    
    var link = document.location.pathname;	    
    var page = "pages/HelpViewer.aspx?controlId=" + ctx + "&page=" + link;    
    
    if (ctx != help_lastCtx || help_lastUrl != page) {    
        var wnd = window.open(help_path + page, 'help', 'location=no, menubar=no, status=yes, resizable=yes, titlebar=no, toolbar=no, top=200, left=160, height=460, width=835');
        wnd.focus();    
        help_lastCtx = ctx;
        help_lastUrl = page;
    }    

}

function resizeWindow () {
    var winW = 630, winH = 460;

    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.body.offsetWidth;
            if (document.compatMode && document.compatMode != "BackCompat") {
                winH = document.documentElement.clientHeight;
            }
            else {
                winH = document.body.clientHeight;
            }

        }
    }

    
    var topPanel = document.getElementById("top_Panel");
    var rightPanel = document.getElementById("right_Panel");
    var leftPanel = document.getElementById("left_Panel");
    
    topPanel.style.width = winW - 16;                        
    rightPanel.style.width = (winW - 260) < 0 ? 0 : winW - 280;     
    rightPanel.style.height = (winH - 60) < 0 ? 0 : winH - 60;          
    leftPanel.style.height = (winH - 60) < 0 ? 0 : winH - 60;     
}

/*********************************************************************/
//    HELP MANAGER
/*********************************************************************/
var fDirty = false;

function swapEvents () {
    document.onmouseup = function() {            
                
        var title;        
        if (event.srcElement.id == "txtTitle" ||
            event.srcElement.id == "txtUrl" ||
            event.srcElement.id == "txtControl") {
            
            return;
        }
        
        if (event.srcElement.value == null || event.srcElement.value == "" || !(event.srcElement.value)) {
            title = event.srcElement.id;
        }
        else {
            title = event.srcElement.value;
        }
        
        if (title == "") title = "Help for page";
        
        title = prompt(MSG_ALERT_TYPE_TITLE, title); 
        
        document.getElementById("txtTitle").value = title;   
        document.getElementById("txtControl").value = event.srcElement.id;
        document.getElementById("txtUrl").value = document.location.pathname;        
        
        event.cancelBubble = true;
        
        event.returnValue = false;
                
    }
}

function showHelpManager() {    
    window.open(help_path + "pages/HelpManager.aspx", "help", "location=no, menubar=no, status=yes, resizable=yes, titlebar=no, toolbar=no, top=200, left=160, height=460, width=835");
}

function InsertTopic() {
   var title = document.getElementById("txtTitle").value;
   var control = document.getElementById("txtControl").value;
   var url = document.getElementById("txtUrl").value;
   
   if (title == "") 
   {
      alert(MSG_ALERT_TITLE_FIELD_REQUIRED);
      document.getElementById("txtTitle").focus();
      return;
   }
   
   if (url == "") 
   {
      alert(MSG_ALERT_URL_FIELD_REQUIRED);
      document.getElementById("txtUrl").focus();
      return;
   }
   
   HelpWS.InsertTopic(title, control, url, onComplete);
   clearInputs();   
}
        
function onComplete(result) {
    alert(result);
}

function clearInputs() {
   document.getElementById("txtTitle").value = "";
   document.getElementById("txtControl").value = "";
   document.getElementById("txtUrl").value = "";
   
   document.getElementById("txtTitle").focus();
}

function confirmPublish() {
    return confirm(MSG_CONFIRM_PUBLISH);    
}


function confirmDelete() {
    return confirm(MSG_CONFIRM_DELETE);
}


function checkDirty() {
    if (fDirty) {        
        return confirm(MSG_CONFIRM_DISCARD_CHANGES);
    }
    else {
        var edt = document.getElementById("editor");
        if (edt) {
            var oEdt = FCKeditorAPI.GetInstance('editor');            
            if (oEdt.IsDirty()) {
                return confirm(MSG_CONFIRM_DISCARD_CHANGES);
            }            
        }        
    }
    return true;            
}

function setDirty() {
    fDirty = true;            
}

function clearDirty() {
    fDirty = false; 
    var edt = document.getElementById("editor");
    if (edt) {
        var oEdt = FCKeditorAPI.GetInstance('editor');                       
        oEdt.ResetIsDirty();
    }
}

function printHelp() {
    var win = window.open (help_path + "pages/print.htm", "print", "scrollbars=yes, status=yes, titlebar=yes, location=yes, menubar=no, toolbar=no, top=200, left=160, height=460, width=840");    
    var source = document.getElementById("right_Panel");
    
    win.onload = new function() {
        var target = win.document.getElementById("pnlContent");                
        target.innerHTML = source.innerHTML;
        win.print();            
    }    
    
    
}