﻿// // Javascript for Help user control.

// Defining constant strings control IDs
var HELP_MODAL_POPUP_ID = "TitleBanner1_HELP_ModalPopupExtender";
var HELP_MAIN_DIV_ID = "TitleBanner1_Help1_lbMessage";
var HELP_CLOSE_LABEL_ID = "TitleBanner1_Help1_lbClose";

// Callback constants.
var HELP_SEPARATOR = 'HELP_&';
var HELP_SHOW_ACTION = "SHOW";


// CALLBACK METHODS *****************************************************

function HELP_callServer(key)
{   
    //Construct callback message.
    var callbackMessage =  "action=" + HELP_SHOW_ACTION + "&key=" + key;
    
    // INVOKING CALLBACK
    HELP_DoCallBack(callbackMessage, "Help"); 
}


function HELP_processMyResult (returnMessage, context)
{
    var splittedReturnMessage = returnMessage.split(HELP_SEPARATOR);
    var action = splittedReturnMessage[0];

    switch (action) {
        case HELP_SHOW_ACTION:
             
             var text = splittedReturnMessage[1];  
             
             var mainDiv = document.getElementById(HELP_MAIN_DIV_ID);
             
             mainDiv.innerHTML = text;
            
             HELP_Show();
             
        break
    }
}

function HELP_postMyError(returnmessage, context)
{
    alert("Callback Error: " + returnmessage + ", " + context);
}

/* ---------------------------------------------------------------- */

function HELP_ShowDialog(key)
{
    HELP_callServer(key);
}

function HELP_Show()
{      
    // OPEN MODAL POPUP WINDOW
    var modalPopupBehavior = $find(HELP_MODAL_POPUP_ID);
    if(modalPopupBehavior != null)
    {
        modalPopupBehavior.show();     
        
        var hlClose = document.getElementById(HELP_CLOSE_LABEL_ID);
        hlClose.focus();
        
    }    
}

function HELP_Close()
{      
    // CLOSE MODAL POPUP WINDOW
    var modalPopupBehavior = $find(HELP_MODAL_POPUP_ID);
    if(modalPopupBehavior != null)
    {
        modalPopupBehavior.hide();
    }  
}

//** Key Events
//*
//*

function HELP_stopEvent(e) {
	if(!e) var e = window.event;
	
	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}

function HELP_OnKeyDown(e)
{
  if (e.keyCode == 27 || e.keyCode == 13) 
  {
    HELP_Close();
    stopEvent(e);
  } 
}