﻿//----------------------------------------------------------
// Copyright (C) Dublin Business School. All rights reserved.
//----------------------------------------------------------


// BEGIN ACCORDION JAVASCRIPT LIBRARY

var ContentHeight = 200;
var TimeToSlide = 250.0;
var openAccordion = '';
var openTitle = 'none';

window.onload = function() { init(); }

function getOuterHTML(obj) {
    temp = obj.cloneNode(true)
    div = document.createElement("div");
    div.appendChild(temp)
    outer = div.innerHTML
    return outer;
}

function init() {
    document.getElementById("accordianDiv").style.display = 'block';
    var objAccordion = null;
    objAccordion = document.getElementById("pnlBase").childNodes.item(0);
    if (objAccordion.nodeName != "TABLE") {
        alert("Table has to be the root HTML element.\r\nThe current root element is: " + objAccordion.nodeName);
        document.getElementById("pnlBase").innerHTML = "";
    }
    var intLength = objAccordion.rows.length;


    var blnTitle = true;
    var strHTMLBuffer = "";
    var lastItem;
    for (i = 0; i < intLength; i++) {
        var objTD = objAccordion.rows.item(i)//objAccordion.getElementsByTagName("tr").item(i);
        var objTD2 = objAccordion.rows.item(i + 1)//objAccordion.getElementsByTagName("tr").item(i);

        if (blnTitle == true) {
            var Title1 = getOuterHTML(objTD);
            var Title2 = getOuterHTML(objTD2);
            strHTMLBuffer += '<div class="AccordionTitle" id="TitleID' + i + '" onselectstart="return false;" onclick="runAccordion(' + i + ');"><table id="titleA' + i + '" border="0" width="100%" cellpadding="0" cellspacing="0">' + Title1 + '</table>\r\n<table id="titleB' + i + '" style="display:none;" border="0" width="100%" cellpadding="0" cellspacing="0">' + Title2 + '</table></div>\r\n';
            lastItem = i;
            i++;
        }
        else {
            var strInnerHTML = getOuterHTML(objTD);
            strHTMLBuffer += '<div id="Accordion' + (i - 2) + 'Content" class="AccordionContent" title="' + objTD.offsetHeight + '"><table border="0" width="100%" cellpadding="0" cellspacing="0">' + strInnerHTML + '</table></div>\r\n';
        }


        if (blnTitle == true)
            blnTitle = false;
        else
            blnTitle = true;


    }

    var objDIV = document.getElementById("AccordionContainer");
    objDIV.innerHTML = strHTMLBuffer;
    objDIV.style.width = (objAccordion.offsetWidth) + 'px';
    objDIV = document.getElementById("pnlBase");
    objDIV.innerHTML = "";

    runAccordion(lastItem);
}
//------------------------------------------------------------------------


function runAccordion(index) {
    var nID = "Accordion" + index + "Content";
    var qindex = index;
    if (openAccordion == nID)
        nID = '';

    if (openTitle == qindex)
        qindex = 'none';

    var objSelDivTitle = '';

    if (qindex == "none") {
        objSelDivTitle = document.getElementById("titleA" + qindex);
        if (objSelDivTitle != null) objSelDivTitle.style.display = "";
        objSelDivTitle = document.getElementById("titleB" + qindex);
        if (objSelDivTitle != null) objSelDivTitle.style.display = "none";

    }
    else {
        objSelDivTitle = document.getElementById("titleA" + qindex);
        if (objSelDivTitle != null) objSelDivTitle.style.display = "none";
        objSelDivTitle = document.getElementById("titleB" + qindex);
        if (objSelDivTitle != null) objSelDivTitle.style.display = "";
    }



    objSelDivTitle = document.getElementById("titleA" + openTitle);
    if (objSelDivTitle != null) objSelDivTitle.style.display = "";

    objSelDivTitle = document.getElementById("titleB" + openTitle);
    if (objSelDivTitle != null) objSelDivTitle.style.display = "none";



    setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'"
      + openAccordion + "','" + nID + "')", 33);

    openAccordion = nID;
    openTitle = qindex;

    var opening = (nID == '') ? null : document.getElementById(nID);
    var closing = (openAccordion == '') ? null : document.getElementById(openAccordion);
    //alert(closing.innerHTML);  
}

function animate(lastTick, timeLeft, closingId, openingId) {
    //9818547281
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var opening = (openingId == '') ? null : document.getElementById(openingId);
    var closing = (closingId == '') ? null : document.getElementById(closingId);

    ContentHeight = (openingId == '') ? 0 : opening.title;
    //alert(ContentHeight);
    if (timeLeft <= elapsedTicks) {
        if (opening != null)
            opening.style.height = ContentHeight + 'px';

        if (closing != null) {
            closing.style.display = 'none';
            closing.style.height = '0px';
        }
        return;
    }

    timeLeft -= elapsedTicks;
    var newClosedHeight = Math.round((timeLeft / TimeToSlide) * ContentHeight);
    if (opening != null) {
        if (opening.style.display != 'block')
            opening.style.display = 'block';
        opening.style.height = (ContentHeight - newClosedHeight) + 'px';
    }

    if (closing != null) {
        var Ex = closing.title;
        var newClosedHeightEx = Math.round((timeLeft / TimeToSlide) * Ex);
        if (opening != null)
            closing.style.height = newClosedHeightEx + 'px';
        else
            closing.style.height = (newClosedHeightEx) + 'px';
    }

    setTimeout("animate(" + curTick + "," + timeLeft + ",'"
      + closingId + "','" + openingId + "')", 33);
}

// END ACCORDION JAVASCRIPT LIBRARY

// BEGIN QUICK LINKS JAVASCRIPT LIBRARY

//This function called when the mouse hovers on the QuickLink Div
//This function sets a Variable "MouseIn" to true, 
//which means the mouse pointer is present inside the Div
function QuickLinkmousein() {
    MouseIn = true;
}


//This function called when the mouse goes out from the QuickLink Div
//This function sets a Variable "MouseIn" to false, 
//which means the mouse pointer is present outside the Div, 
//so that, after certain amount of time, this div will be automatically closed.
function QuickLinkmouseout() {
    MouseIn = false;
}

//This function sets the Timer
//So that, If after certain amount of time, 
//If the Mouse pointer is out of the div
//Then the div will automatically close
function timerQuickLink() {
    if (MouseIn == false)
        hideQuickLinkmenu();
}

//This function creates and display the Div(looking like drop downs)
//this will call to open Quick Link Div
function ShowQuickLinkMenu() {
    if (timerID == null) {
        timerID = setInterval(timerQuickLink, 600);
    }

    //Set the MouseIn var to true, indicates that 
    //the mouse pointer present inside the Div
    MouseIn = true;

    //Now the InnerHTML of the QuickLink Div, 
    //filled in a particular div at the time of Page Load
    //will be displayed as a drop down menu

    QuickLinksDivID = PassToControlID;
    QuickLinkMenuID = PassToMenuID;
    QuickLinkmenuobj = document.getElementById("QuickLinkMenuDiv");

    QuickLinkmenuobj.innerHTML = document.getElementById(QuickLinksDivID).innerHTML;
    QuickLinkmenuobj.contentheight = QuickLinkmenuobj.offsetHeight

    //Calculating the Offset dimentions of the div
    var divctrl = document.getElementById('QuickLinkAHrefID');
    var divBounds = Sys.UI.DomElement.getBounds(divctrl);

    QuickLinkmenuobj.style.left = divBounds.x + "px";
    QuickLinkmenuobj.style.top = divBounds.y + divBounds.height + "px";
    QuickLinkmenuobj.style.width = divBounds.width + 10 + "px";
    QuickLinkmenuobj.style.visibility = "visible"

    return false;
}


//This function will hide the QuickLink Div
function hideQuickLinkmenu() {
    if (window.QuickLinkmenuobj) {
        QuickLinkmenuobj.style.visibility = "hidden";
    }
}

//This function will Set the Delay of hiding the div
function delayhidemenu() {
    //Sets the timer, and call hideQuickLinkmenu() function 
    //after every 500 milisec to close the div
    delayhide = setTimeout("hideQuickLinkmenu()", 500)
}


//This function will call, when any Option is clicked from the Div
function GoToPage(url) {
    window.location = url;
}

// END QUICK LINKS JAVASCRIPT LIBRARY

// BEGIN CAROUSEL JAVASCRIPT LIBRARY



function carouselImage(name, imagePath, width, zoomImage, topBanner) {
    this.name = name;
    this.id = name;
    this.normalImage = imagePath;
    this.width = width;
    this.height = 120;
    this.zoomImage = zoomImage;
    this.topBanner = topBanner;
    this.topPosition = 0.00;
    this.leftPosition = 0.00;
    this.zoomState = ""; //in/out
    this.zoomTimer = null;
}

function setLeftPosition(elementId, newPosition) {
    var currentElement = document.getElementById(elementId);
    if (currentElement != null) {
        currentElement.style.left = newPosition + "px";
    }
}

function getPosition(elementId) {
    var currentElement = document.getElementById(elementId);
    if (currentElement != null && currentElement.offsetLeft != null) {
        return { left: currentElement.offsetLeft, top: currentElement.offsetTop };
    }
    return { left: 0, top: 0 };
}

function getSize(elementId) {
    var currentElement = document.getElementById(elementId);
    if (currentElement != null && currentElement.offsetHeight != null) {
        return { height: currentElement.offsetHeight, width: currentElement.offsetWidth };
    }
    return { height: 0, width: 0 };
}

function setBannerImage(imageSource) {
    if (imageSource != null && imageSource != ""
            && bannerControlId != null && bannerControlId != "") {
        var bannerElement = document.getElementById(bannerControlId);
        if (bannerElement != null) {
            bannerElement.src = imageSource;
        }
    }
}

function getCarouselImage(imageId) {
    var caImage = null;
    for (imageIndex = 0; imageIndex < carouselImageItemCount; imageIndex++) {
        if (carouselImages[imageIndex].id == imageId) {
            caImage = carouselImages[imageIndex];
            break;
        }
    }
    return caImage;
}

/*if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = ctrlSpeed;*/

function InitCarousel() {
    carouselImageItemCount = carouselImages.length;
    MAX_LEFT_POSITION = 0;
    MAX_RIGHT_POSITION = (parseInt(IMAGE_WIDTH) + parseInt(HORIZONTAL_SPACING)) * (carouselImageItemCount - 1);
    var caImage = null;

    for (imageIndex = 0; imageIndex < carouselImageItemCount; imageIndex++) {
        imageLeftPosition = MAX_LEFT_POSITION; //- (IMAGE_WIDTH + parseInt(HORIZONTAL_SPACING)*2);
        caImage = carouselImages[imageIndex];
        for (tempImageIndex = 0; tempImageIndex < imageIndex; tempImageIndex++) {
            imageLeftPosition = imageLeftPosition + carouselImages[tempImageIndex].width + parseInt(HORIZONTAL_SPACING) * 2;
        }
        //if(imageIndex)
        caImage.leftPosition = imageLeftPosition;
        caImage.order = imageIndex;
        setLeftPosition(carouselImages[imageIndex].id, imageLeftPosition);
    }

    var bannerElement = document.getElementById(bannerControlId);
    if (bannerElement != null && bannerElement.tagName.toLowerCase() == "img") {
        originalBannerSource = bannerElement.src;
    }

    //startScroll;
    myPause = setInterval("startScrolling()", 500);
}

function ready() {
    /*
    for (imageIndex=0;imageIndex<carouselImageItemCount;imageIndex++)
    { 
    if (document.images[imageIndex].complete == false)
    {
    return false;	
    break;
    }
    }
    */
    return true;
}

function startScrolling() {
    if (ready() == true) {
        window.clearInterval(myPause);
        myPause = null;
        myInterval = setInterval("autoScroll()", speed);
    }
}


function GetImageByPosition(Position) {
    for (GIBP = 0; GIBP < carouselImageItemCount; GIBP++) {
        var cImage = carouselImages[GIBP];
        if (cImage.order == Position)
            return cImage;
    }
    return null;
}
function ShiftImageToRight(Image) {
    for (SITR = 0; SITR < carouselImageItemCount; SITR++) {
        carouselImages[SITR].order--;
    }
    Image.order = (carouselImageItemCount - 1);
    var NextImg = GetImageByPosition(carouselImageItemCount - 2);
    Image.leftPosition = NextImg.leftPosition + NextImg.width + (parseInt(HORIZONTAL_SPACING) * 2);
    setLeftPosition(Image.id, Image.leftPosition);

}
function ShiftImageToLeft(Image) {
    for (SITL = 0; SITL < carouselImageItemCount; SITL++) {
        carouselImages[SITL].order++;
    }
    Image.order = 0;
    var NextImg = GetImageByPosition(1);
    Image.leftPosition = NextImg.leftPosition - NextImg.width - (parseInt(HORIZONTAL_SPACING) * 2);
    setLeftPosition(Image.id, Image.leftPosition);
}

function autoScroll() {
    if (scrollDirection == "left") {//Move left
        var currentImage = null;
        for (imageIndex = 0; imageIndex < carouselImageItemCount; imageIndex++) {
            currentImage = GetImageByPosition(imageIndex);

            if (currentImage.leftPosition < -(currentImage.width)) {
                ShiftImageToRight(currentImage);
            }
        }

        for (imageIndex = 0; imageIndex < carouselImageItemCount; imageIndex++) {
            currentImage = GetImageByPosition(imageIndex);
            currentImage.leftPosition = currentImage.leftPosition - MOVE_STEP;
            setLeftPosition(currentImage.id, currentImage.leftPosition);
        }
    }
    else if (scrollDirection = "right") {// Move right

        var currentImage = null;
        for (imageIndex = 0; imageIndex < carouselImageItemCount; imageIndex++) {
            currentImage = GetImageByPosition(imageIndex);

            if (currentImage.leftPosition > MAX_RIGHT_POSITION) {
                ShiftImageToLeft(currentImage);
            }

        }
        for (imageIndex = 0; imageIndex < carouselImageItemCount; imageIndex++) {
            currentImage = GetImageByPosition(imageIndex);
            currentImage.leftPosition = currentImage.leftPosition + MOVE_STEP;
            setLeftPosition(currentImage.id, currentImage.leftPosition);
        }

    }
    mode = 1;
}

function stopScroll() {
    if (mode == 1 && myInterval != null) {
        window.clearInterval(myInterval);
        myInterval = null;
    }
    if (mode == 0 && myPause != null) {
        window.clearInterval(myPause);
        myPause = null;
    }
}

function startScroll() {
    if (zoomElementArray.length > 0) {
        return;
    }
    if (mode == 1 && myInterval == null) {
        myInterval = setInterval("autoScroll()", speed);
    }
    if (mode == 0 && myPause == null) {
        myPause = setInterval("startScrolling()", 500);
    }
}

/////Image Zoom

function zoomingIn(caImage) {
    if (caImage != null) {
        var zoomElement = document.getElementById(caImage.id);
        if (zoomElement != null) {
            var tempHeight = parseFloat(zoomElement.style.height);
            var tempWidth = parseFloat(zoomElement.style.width);

            var tempTop = parseFloat(zoomElement.style.top);
            var tempLeft = parseFloat(zoomElement.style.left);

            if (tempHeight < MAX_ZOOM_HEIGHT) {
                var dW = zoomStep; //tempWidth*zoomfactor;
                var dH = zoomStep; //tempHeight*zoomfactor;

                zoomElement.style.width = (tempWidth + dW) + "px";
                zoomElement.style.height = (tempHeight + dH) + "px";
                zoomElement.style.left = (tempLeft - dW / 2 + dLeft) + "px";
                zoomElement.style.top = (tempTop - dH / 2) + "px";
            }
            else {
                if (caImage.zoomTimer != null) {
                    clearInterval(caImage.zoomTimer);
                    caImage.zoomTimer = null;
                }

                if (caImage.topBanner != "") {
                    setBannerImage(caImage.topBanner);
                }
            }
        }
    }
}

function zoomingOut(caImage) {
    if (caImage != null) {
        var zoomElement = document.getElementById(caImage.id);
        if (zoomElement != null) {
            //var size = getSize(caImage.id);
            var tempHeight = parseFloat(zoomElement.style.height);
            var tempWidth = parseFloat(zoomElement.style.width);

            //var pos = getPosition(caImage.id);
            var tempTop = parseFloat(zoomElement.style.top);
            var tempLeft = parseFloat(zoomElement.style.left);

            if (tempWidth > parseFloat(caImage.width)) {
                var dW = (-1) * zoomStep; //tempWidth*zoomfactor;
                var dH = (-1) * zoomStep; //tempHeight*zoomfactor;

                zoomElement.style.width = (tempWidth + dW) + "px";
                zoomElement.style.height = (tempHeight + dH) + "px";
                zoomElement.style.left = (tempLeft - dW / 2) + "px";
                zoomElement.style.top = (tempTop - dH / 2) + "px";
            }
            else {
                if (caImage.zoomTimer != null) {
                    clearInterval(caImage.zoomTimer);
                    caImage.zoomTimer = null;
                }

                zoomElement.style.width = parseFloat(caImage.width) + "px";
                zoomElement.style.height = parseFloat(caImage.height) + "px";
                zoomElement.style.top = parseFloat(caImage.topPosition) + "px";
                zoomElement.style.left = parseFloat(caImage.leftPosition) + "px";
                zoomElement.style.zIndex = 0;

                var imageElement = zoomElement.getElementsByTagName("img");
                if (imageElement != null && imageElement.length > 0)// imageElement.tagName == "img")
                {
                    imageElement[0].src = caImage.normalImage;
                }

                setBannerImage(originalBannerSource);
                caImage.zoomState = "";
                zoomedOut(caImage);
            }
        }
    }
}

function startZoomIn(what) {
    var element = document.getElementById(what);
    if (element != null) {
        var found = false;
        var zoomIndex = 0;
        for (zoomIndex = 0; zoomIndex < zoomElementArray.length; zoomIndex++) {
            if (zoomElementArray[zoomIndex] == what) {
                found = true;
                break;
            }
        }
        if (!found) {
            zoomElementArray.push(what);
            stopScroll();
            zoomIn(what);
        }
    }
}

function startZoomOut(what) {
    if (document.getElementById(what) != null) {
        var zoomIndex = 0;
        for (zoomIndex = 0; zoomIndex < zoomElementArray.length; zoomIndex++) {
            if (zoomElementArray[zoomIndex] == what) {
                var caImage = getCarouselImage(what);
                if (caImage != null && caImage.zoomState == "in") {
                    caImage.zoomState = "out";
                    if (caImage.zoomTimer != null) {
                        clearTimeout(caImage.zoomTimer);
                    }

                    var zoomElement = document.getElementById(caImage.id);
                    if (zoomElement != null) {
                        zoomElement.style.zIndex = 9999;
                    }
                    caImage.zoomTimer = setInterval(function() { zoomingOut(caImage); }, 30);
                }
            }
        }
    }
}


function zoomIn(what) {
    var caImage = getCarouselImage(what);
    if (caImage != null && caImage.zoomState == "") {
        var zoomElement = document.getElementById(what);

        if (zoomElement != null) {
            //var pos = getPosition(what);
            caImage.topPosition = parseFloat(zoomElement.style.top);
            caImage.leftPosition = parseFloat(zoomElement.style.left);

            //var size = getSize(what);
            caImage.height = parseFloat(zoomElement.style.height);
            caImage.width = parseFloat(zoomElement.style.width);

            var imageElement = zoomElement.getElementsByTagName("img");
            if (imageElement != null && imageElement.length > 0) {
                imageElement[0].src = caImage.zoomImage;
            }

            zoomElement.style.display = "block";
            zoomElement.style.position = "absolute";
            zoomElement.style.zIndex = 10000;
            caImage.zoomState = "in";
            if (caImage.zoomTimer != null) {
                clearTimeout(caImage.zoomTimer);
            }
            caImage.zoomTimer = setInterval(function() { zoomingIn(caImage); }, 30);
        }
    }
}

function zoomedOut(caImage) {
    if (caImage != null) {
        var zoomIndex = 0;
        for (zoomIndex = 0; zoomIndex < zoomElementArray.length; zoomIndex++) {
            if (zoomElementArray[zoomIndex] == caImage.id) {
                zoomElementArray.splice(zoomIndex, 1);
                break;
            }
        }
    }
    if (zoomElementArray.length == 0) {
        startScroll();
    }
}

function imgOver(what) {
    startZoomIn(what);
}

function clearimgOver(what) {
    startZoomOut(what);
}

function setScrollDirection(value) {
    stopScroll();
    scrollDirection = value;
    startScroll();
}

function navigateToUrl(url) {
    if (window && window.location) {
        window.location = url;
    }
}


// END CAROUSEL JAVSCRIPT LIBRARY

// BEGIN TARGETED SEARCH LIBRARY

var URL = "";
var SelectedStudyOption = "";
var TargetedSearchmenuobj;
var ie5 = document.all && !window.opera
var ns6 = document.getElementById

var MainMenuHideTimer = null;
var SubMenuHideTimer = null;
var MouseTSearchInMainMenu = false;
var MouseTSearchInSubMenu = false;
var SelectedProgram = "";


var EmptyStudyDivHeaderHTML = '<table cellpadding="0" cellspacing="0" border="0" ><tr ><td class="PopUpMenuDropDown">&nbsp;&nbsp;Study Option&nbsp;&nbsp;</td></tr></table>';

//This function is called when any option is selected either from Program Div or Study Option Div
function NewOptionSelected(event, controlID, selectedOption, targetPage, displayText) {
    URL = targetPage;

    //Hiding the Error Message respectively
    switch (controlID) {
        case "ProgramTab":
            SelectedStudyOption = "";
            SelectedProgram = selectedOption;
            document.getElementById("SelectProgramTitle").title = displayText;
            document.getElementById("StudyOptionTab").innerHTML = EmptyStudyDivHeaderHTML;
            document.getElementById("StudyOptionTitle").title = 'Select study Option';
            break;
        case "StudyOptionTab":
            SelectedStudyOption = selectedOption;
            document.getElementById("StudyOptionTab").innerHTML = displayText;
            document.getElementById("StudyOptionTitle").title = displayText;
            break;
    }

    hideTargetedSearchmenu();

    var StringToDisplay = displayText ? displayText : "";

    if (StringToDisplay.length > 18) {
        StringToDisplay = StringToDisplay.substring(0, 18);
        StringToDisplay += '...';
    }

    document.getElementById(controlID).innerHTML = '&nbsp;&nbsp;' + StringToDisplay;
    ShowTargetedSearchMenu(event, 'TargetedSearchAHrefID', DIV_ClientID);
}

//This script adds the innerText functionality to the browser if not present,
//Like, Mozilla does not have such function.     
if ((typeof HTMLElement != 'undefined') && HTMLElement.prototype.__defineGetter__ != 'undefined') {
    HTMLElement.prototype.__defineGetter__("innerText", function() {
        var r = this.ownerDocument.createRange();
        r.selectNodeContents(this);
        return r.toString();
    });
}


function Trim(str) {
    return str.replace(/\s/g, '').replace(/^\s+|\s+$/, '');
}


//This function will fill the StudyOption Div
function FillStudyDiv() {
    //Fill the Study Div
    TargetedSearchmenuobj = document.getElementById("popupSubmenu2");

    var requiredDivID = Trim(SelectedProgram);

    //Set the Title as Study Option
    document.getElementById("StudyOptionTab").innerHTML = EmptyStudyDivHeaderHTML;
    document.getElementById("StudyOptionTitle").title = "Select study Option";

    if (document.getElementById(requiredDivID) != null) {
        TargetedSearchmenuobj.innerHTML = document.getElementById(requiredDivID).innerHTML;
    }
    //If the Required Div is not present then fill the StudyOption Div with Empty row
    else {
        TargetedSearchmenuobj.innerHTML = document.getElementById("ProgramID").innerHTML; //ProgramID Div Contains Empty Row
    }
}

//This function will call when the GO Button in Targeted Search Div is pressed
function SubmitTargetSearch() {
    var isValidate = true;
    //Check Whether any Program option is selected or not
    if (Trim(document.getElementById("ProgramTab").innerText) == "Programme") {
        isValidate = false;
    }
    //Check Whether any Study Option is selected or not    
    if (SelectedStudyOption == "") {
        isValidate = false;
    }

    //If both Program & Study option is selected then post the Page to the desired Page, 
    //Otherwise display the proper Error Message, by making the 'visible' property of respective Error to 'TRUE' or 'VISIBLE'
    if (isValidate) {
        window.location = URL;
    }

    hideTargetedSearchmenu();
    ShowTargetedSearchMenu(event, 'TargetedSearchAHrefID', '<%=TargetedSearchsDiv.ClientID %>');

}

//This function called when the mouse hovers on the TargetedSearch Div
//This function sets a Variable "MouseTSearchInMainMenu" to true, 
//which means the mouse pointer is present inside the Div
function mouseInMainMenu() {
    MouseTSearchInMainMenu = true;

}

//This function called when the mouse goes out from the TargetedSearch Div
//This function sets a Variable "MouseTSearchInMainMenu" to false, 
//which means the mouse pointer is present outside the Div, 
//so that, after certain amount of time, this div will be automatically closed.   
function mouseOutMainMenu() {
    MouseTSearchInMainMenu = false;
}

//Setting MouseTSearchInSubMenu to true, So that the Div will open 
//untill the mouse pointer is present inside the div
function mouseInSubMenu() {
    //Calling mouseInMainMenu(), to set the "MouseTSearchInMainMenu" to true
    //So that main div will also open till the mouse present in the Sub Div
    mouseInMainMenu();
    MouseTSearchInSubMenu = true;
}

function mouseOutSubMenu() {
    //Calling mouseOutMainMenu(), to set the "MouseTSearchInMainMenu" to false
    //So that main div will also close when mouse pointer goes out of the Sub Div
    mouseOutMainMenu();
    MouseTSearchInSubMenu = false;
}

//This function sets the Timer of Main Menu Div
//So that, If after certain amount of time, 
//If the Mouse pointer is out of the div
//Then the div will automatically close
function MainMenuTimerFunction() {
    //If the mouse pointer present outside the Main div.
    //Then only hide the Main div
    if (MouseTSearchInMainMenu == false)
        hideMainDiv();
}

//This function sets the Timer of Sub Menu Div
//So that, If after certain amount of time, 
//If the Mouse pointer is out of the div
//Then the div will automatically close
function SubMenuTimerFunction() {
    //If the mouse pointer present outside the Sub div.
    //Then only hide the Sub div
    if (MouseTSearchInSubMenu == false)
        hideSubMenuDiv();
}

//This function creates and display the Divs(looking like drop downs)
//this will call to open 3 divs :-
//1. I am interested in DIV
//2. Program DIV
//3. Study Option DIV
function ShowTargetedSearchMenu(e, SourceID, DivID) {

    if (!document.all && !document.getElementById) {
        return;
    }
    if (MainMenuHideTimer == null) {
        //Set the interval to hide the Main Menu Div, ie. 5000ms or 5 Sec
        MainMenuHideTimer = setInterval(MainMenuTimerFunction, 5000);
    }
    if (SubMenuHideTimer == null) {
        //Set the interval to hide the Sub Menu Div, ie. 500ms or Half Sec
        SubMenuHideTimer = setInterval(SubMenuTimerFunction, 500);
    }

    MouseTSearchInMainMenu = true;
    MouseTSearchInSubMenu = true;

    TargetSearchclearhidemenu();

    //Getting the Root Attributes of the Root Control i.e "I am interested in" Div        
    var rootObj = document.getElementById("TargetedSearchAHrefID");
    var divBounds = Sys.UI.DomElement.getBounds(rootObj);

    switch (SourceID) {
        //If sourceID is "TargetedSearchAHrefID" then open the Main Drop Down Div 
        case "TargetedSearchAHrefID":
            TargetedSearchmenuobj = document.getElementById("popupTargetSearchmenu")
            TargetedSearchmenuobj.innerHTML = document.getElementById(DivID).innerHTML;
            TargetedSearchmenuobj.style.top = divBounds.y + (divBounds.height) + "px";
            TargetedSearchmenuobj.style.left = divBounds.x + "px";
            TargetedSearchmenuobj.style.height = "150px";
            TargetedSearchmenuobj.style.width = divBounds.width + "px";
            break;

        //If sourceID is "ProgramTab" then open the Programme Drop Down Div,  
        //by calculating its offset dimentions according to its parent Div 
        case "ProgramTab":
            TargetedSearchmenuobj = document.getElementById("popupSubmenu1");
            TargetedSearchmenuobj.innerHTML = document.getElementById(DivID).innerHTML;
            TargetedSearchmenuobj.style.top = divBounds.y + (divBounds.height + 68) + "px";
            TargetedSearchmenuobj.style.left = divBounds.x + 5 + "px";
            break;

        //If sourceID is "StudyOptionTab" then open the Programme Drop Down Div,  
        //by calculating its offset dimentions according to its parent Div 
        case "StudyOptionTab":
            //Filling the StudyOption Div
            FillStudyDiv();
            //Calculation the relative Height of the Study Option Div in Main/Root Div
            TargetedSearchmenuobj.style.top = divBounds.y + (divBounds.height + 115) + "px";
            TargetedSearchmenuobj.style.left = divBounds.x + 5 + "px";
            break;
    }

    //Hide the SubMenu Div before displaying the 
    hideSubMenuDiv();
    //Finally display the Div
    TargetedSearchmenuobj.style.visibility = "visible";
}

//This function will hide the Current open Div
function hideTargetedSearchmenu() {
    if (window.TargetedSearchmenuobj) {
        TargetedSearchmenuobj.style.visibility = "hidden";
    }
}

//This function is used to dynamically hide the Div
function TargetSearchDynamicHide(e) {
    mouseOutMainMenu();
    mouseOutSubMenu();
}

//This function will clear the Delay of hiding the div
function TargetSearchclearhidemenu() {
    mouseInMainMenu();
    mouseInSubMenu();
}

//this function is called to hide the Main Targetted Search Menu Div
function hideMainDiv() {
    if (!MouseTSearchInMainMenu) {
        document.getElementById('popupTargetSearchmenu').style.visibility = "hidden";
        hideSubMenuDiv();
    }
}

//this function is called to hide the Sub Menus Div ie Programme & Study Option Div
function hideSubMenuDiv() {
    document.getElementById("popupSubmenu1").style.visibility = "hidden";
    document.getElementById("popupSubmenu2").style.visibility = "hidden";
}

document.onclick = hideMainDiv;

// END TARGETED SEARCH JAVASCRIPT LIBRARY