// Ad swapping

var currAd = 0;
var swapSecs = 10;

function openAdPage() {
    var newURL, adId, newURL;
    if (currAd > 0) {
        adId = raAds[currAd].Fld4;
        newURL = raAds[currAd].Fld3;
        sendAdInfo(adId, 'M');
        if (newURL.StrAt('mailto:') > 0) {
            gotoNewLocation(newURL, false);
        } else {
            gotoNewLocation(newURL, true);
        }
    }
}

// sendAdInfo() - Send the current click selection
function sendAdInfo(cId, adQual) {
    var url, soapObj, cKey1, cKey2;

    if (cId.length > 0) {
        url = "/cps/svc/NoteClickInfo.wwsoap";
        soapObj = new SOAPClientParameters();
        cKey1 = "%DF%96%9D%AF%AF%9C%93%8A%B2%DF";
        cKey2 = "%DF%A9%BE%B1%B4%DF%AD%B2%BA%DF";
        soapObj.add("cLogin", cKey1);
        soapObj.add("cPassword", cKey2);
        soapObj.add("cAdID", cId);
        soapObj.add("cQualifiers", adQual);
	    SOAPClient._sendSoapRequest(url, "LoadClickInfo", soapObj, true,
	      null, null);
    }
    return true;
}

function swapAds() {
    var numAds, newPosn, oImg;
    numAds = raAds.length - 1;

    newPosn = currAd + 1;
    if (newPosn > numAds) {
        newPosn = 1;
    }

    oImg = idObj('AdPic');
    if (oImg)   {
        oImg.setAttribute('src', raAds[newPosn].Fld1);
        oImg.setAttribute('alt', "Click to go to " + raAds[newPosn].Fld2);
    }
    currAd = newPosn;
    setTimeout("swapAds()",swapSecs*1000);
}

// Menu items
lastHit = null;

// resizeIFrame() - Resize our page's IFrame height
function resizeIFrame(nFFHt, nIEHt, menuID) {
    var nHt, oIFrame, oFooter, newTop;
    oIFrame = idObj("FramePage");
    if (Browser.StrAt('ie') == 1) {
        nHt = nIEHt;
    } else {
        nHt = nFFHt;
    }
    oIFrame.style.height = nHt + 'px';
    oFooter = idObj("footer2");
    newTop = 170 + nHt + 40;
    oFooter.style.top = newTop + 'px';
    if ((menuID != topPageID) && menuID.length > 0) {
        if (lastHit) {
            removeClass(lastHit, "sansData");
        }
        lastHit = idObj(menuID);
        addClass(lastHit, "sansData");
        topPageID = menuID;
    }
}

// forceMenuOptionOn() - Force Menu option on
function forceMenuOptionOn(menuID) {
    if (menuID.length > 0) {
        if (lastHit) {
            removeClass(lastHit, "sansData");
        }  else  {
            lastHit = idObj(menuID);
            removeClass(lastHit, "sansData");
        }
    }
}

// checkAddSearchBar() - Don't show the Add Search Bar button if inappropriate
function checkAddSearchBar() {
    var bHideIt, sOurURL, oFrame;

    // Hide if its already installed or IE is less than 7 or FF is less than 2
    bHideIt = false;
    sOurURL = "http://www.alicorp.com";
    if (document.URL.indexOf("http://www.alicorp.com") > -1 &&
      window.external.IsSearchProviderInstalled(sOurURL)) {
        bHideIt = true;
    } else if (Browser.indexOf("ie") > -1) {
        if (Browser < "ie7") {
            bHideIt = true;
        }
    } else if (Browser.indexOf("firefox") > -1) {
        if (Browser < "firefox2") {
            bHideIt = true;
        }
    }
    if (!bHideIt) {
        oFrame = idObj("ALISrchBar");
        removeClass(oFrame, "hidden");

        // Setup our timer to hide the search bar after 20 seconds
        setTimeout("hideALISrchBar()",20000);
    }
}

function hideALISrchBar()   {
    var oFrame
    oFrame = idObj("ALISrchBar");
    addClass(oFrame, "hidden");
}

function closeSrchFrame() {
    var oFrame;
    oFrame = idObj("ALISrchBar");
    addClass(oFrame, "hidden");
}

function BrowBarHelp() {
    openPopup(700, 600, "yes", "yes", 'AdSrchHl.htm', false, false, true);
}

function installSearchEngine() {
    if (window.external && ("AddSearchProvider" in window.external)) {
        window.external.AddSearchProvider(
          "http://www.alicorp.com/ALISrch.xml");
    } else {
        alert("No search engine support");
    }
}

function GetMenuPage(oLink, fullPage) {
    var destURL, oFrame, oLabel, cCurrID
    if (!oLink) {
        oLink = idObj(topPageID);
        fullPage = topPageFull;
        topPageID = '';
    } else {
        if (hasClass(oLink, 'sansData')) {
            return false;
        }
    }
    destURL = oLink.className;

    // Make the link go away
    if (!Empty(destURL))  {
        var nPosn = destURL.StrAt('.')
        if (nPosn > 0)  {
            cCurrID = destURL.Left(nPosn);
            oLabel = idObj(cCurrID);
            if (oLabel) {
                if (hasClass(oLabel, 'LinkLook')) {
                    removeClass(oLabel, 'LinkLook');
                }
            }
        }
    }
    if (!Empty(oldPageID))  {
        var nPosn = oldPageID.StrAt('.')
        if (nPosn > 0)  {
            cCurrID = oldPageID.Left(nPosn);
            oLabel = idObj(cCurrID);
            if (oLabel) {
                if (!hasClass(oLabel, 'LinkLook')) {
                    addClass(oLabel, 'LinkLook');
                }
            }
        }
    }
    oldPageID = destURL;

    if (hasClass(oLink, 'sansData')) {
        removeClass(oLink, 'sansData');
        destURL = oLink.className;
        addClass(oLink, 'sansData');
    } else {
        destURL = oLink.className;
    }
    if (!Empty(topParameter))  {
        destURL = destURL + '?parameter^' + topParameter;
        topParameter = "";
    }
    if (fullPage)  {
        window.location.href = destURL;
        return false;
    }

    // New page will reset menu
    oFrame = idObj('FramePage');
    oFrame.src = destURL;
    return false;
}

function showOpenMsg() {
    if (!Empty(openMsg))  {
        alert(openMsg);
        openMsg = "";
    }
}

function menuClick() {
    var oNav = idObj('navigation');
    if (hasClass(oNav, 'hidden'))  {
        removeClass(oNav, 'hidden');
    }  else  {
        addClass(oNav, 'hidden');
    }
}

function setupPMMenuPage() {
    var oImg;
    // checkAddSearchBar();
    GetMenuPage();
    if (raAds.length > 0) {
        addClass(idObj('ALIPic2'), 'hidden')
        removeClass(idObj('AdPic'), 'hidden')
        swapAds();
    }

    // Wait for the IFrame to load before we show our message
    if (openMsg) {
        oFrame = idObj('FramePage');
        addListener(oFrame, 'onload', showOpenMsg);
    }
}

addLoadListener(setupPMMenuPage);

