/*
* --------------------------------------------------------------------
* FUNCTION : Cookie_set()
* --------------------------------------------------------------------
* DESCRIPTION: A function that sets cookie values properly
* PARAMETERS: The cookieName and cookieValue arguments are mandatory
*                but all other arguments are optional.
*                The expires argument is a Date object.
*                The path defines the part of the document tree on the server
*                that the cookie is valid for.
*                The domain argument allows multiple server hosts to be used.
*                The secure value is boolean and only applicable for use
*                with HTTPS: connections.
* OUTPUT : a cookie! :)
* --------------------------------------------------------------------
*/
function Cookie_set(cookieName, cookieValue, expires, path, domain, secure)
{
	document.cookie = escape(cookieName) + "=" + escape(cookieValue)
		+ (expires ?	"; EXPIRES="	+ expires.toGMTString() : "")
		+ "; PATH=/"
		+ (domain ?		"; DOMAIN="		+ domain				: "")
		+ (secure ?		"; SECURE"								: "");
}

/*
* --------------------------------------------------------------------
* FUNCTION : Cookie_remove()
* --------------------------------------------------------------------
* DESCRIPTION: removes a cookie
* PARAMETERS: cookieName - name of the cookie
* OUTPUT : none
* --------------------------------------------------------------------
*/
function Cookie_remove(cookieName){
	Cookie_set( cookieName, "", new Date(0));
}

/*
* --------------------------------------------------------------------
* FUNCTION : hideMenu()
* --------------------------------------------------------------------
* DESCRIPTION: Hides menu
* OUTPUT : none
* --------------------------------------------------------------------
*/
function hideMenu()
{
    //document.getElementById("HIDDEN_MENU").style.display = "";
    if(document.getElementById("hiddenTd")) document.getElementById("hiddenTd").style.display="";
    if (document.getElementById("leftmenu")) document.getElementById("leftmenu").style.display = "none";
    if (document.getElementById("shownav")) document.getElementById("shownav").style.display="";
    if (document.getElementById("hidenav")) document.getElementById("hidenav").style.display="none";
}
/*
* --------------------------------------------------------------------
* FUNCTION : hideMenuForNextPage()
* --------------------------------------------------------------------
* DESCRIPTION: Hides menu for next page
* OUTPUT : none
* --------------------------------------------------------------------
*/
function hideMenuForNextPage(){
    Cookie_remove("LEFTMENUCLOSED");
    Cookie_set("LEFTMENUCLOSED", "1");
}
/*
* --------------------------------------------------------------------
* FUNCTION : showMenu()
* --------------------------------------------------------------------
* DESCRIPTION: Shows menu
* OUTPUT : none
* --------------------------------------------------------------------
*/
function showMenu(){
    if(document.getElementById("leftmenu")) document.getElementById("leftmenu").style.display = "";
    if(document.getElementById("shownav")) document.getElementById("shownav").style.display = "none";
    if(document.getElementById("hidenav")) document.getElementById("hidenav").style.display = "";
    if(document.getElementById("hiddenTd")) document.getElementById("hiddenTd").style.display="none";

    //adjustlayout();
    //document.getElementById( "HIDDEN_MENU").style.display = "none";
    //document.getElementById( "LEFT_MENU").style.display = "";
    //Cookie_remove("LEFTMENUCLOSED");
    //Cookie_set("LEFTMENUCLOSED", "0");
    AdjustDiv();
}
/*
* --------------------------------------------------------------------
* FUNCTION : AdjustDiv()
* --------------------------------------------------------------------
* DESCRIPTION: Used in site to adjust div (see search results) when
*              users resize the browser window
* OUTPUT : none
* --------------------------------------------------------------------
*/
function AdjustDiv()
{
if (gBrowser == 'ns' && gBrowserVersionHi == '6')
{

    var d = document.getElementById("results");
    var t = document.getElementById("resultstable");
    if ((d!=null)&&(t!=null))
    {
        d.style.width = 100;
        var w = t.clientWidth;
        var bname = navigator.appName;
        if (bname.search(/netscape/i) == 0)
        {
            w=t.offsetWidth-2;
        }
    	if (w > 0) d.style.width = w;
    }
}

else {return;}
}

/*
* --------------------------------------------------------------------
* FUNCTION : toggleMenu()
* --------------------------------------------------------------------
* DESCRIPTION: Toggles left menu, sets or removes the cookie for it
* OUTPUT : none
* --------------------------------------------------------------------
*/
function toggleMenu() {
    var leftmenu= xGetElementById('leftmenu');
    if (leftmenu.style.display == 'none') {
        showMenu();
        document.cookie = "LEFTMENUCLOSED=0";
    } else {
        hideMenu();
        document.cookie = "LEFTMENUCLOSED=1";
        AdjustDiv();
    }
}


/*
* --------------------------------------------------------------------
* FUNCTION : HideMessageArea()
* --------------------------------------------------------------------
* DESCRIPTION: Hides the message area
* OUTPUT : none
* --------------------------------------------------------------------
*/
function HideMessageArea(){
    var tmpobj = document.getElementById("MESSAGE_AREA");
    if (tmpobj) tmpobj.style.display = "none";
}

/*
* --------------------------------------------------------------------
* FUNCTION : OnClickDropSubmenu()
* --------------------------------------------------------------------
* DESCRIPTION: Drops a submenu when an onclick event occurs
* PARAMETERS: id - id of the div
* OUTPUT : none
* --------------------------------------------------------------------
*/
function OnClickDropSubmenu(id) {
    var div = document.getElementById("div-" + id);
    var display = div.style.display;
    div.style.display = display == 'none' ? '' : 'none';
}

/*
* --------------------------------------------------------------------
* FUNCTION : manageMenu()
* --------------------------------------------------------------------
* DESCRIPTION: Manages menu
* OUTPUT : none
* --------------------------------------------------------------------
*/
function manageMenu() {
    if(gLeftMenuVar==1) {
        hideMenu();
    } else {
        showMenu();
    }
}

/*
* --------------------------------------------------------------------
* FUNCTION : GoTop()
* --------------------------------------------------------------------
* DESCRIPTION: goes straight to top
* OUTPUT : none
* --------------------------------------------------------------------
*/
function GoTop(){
    window.scrollTo(0,0);
}

/*
* --------------------------------------------------------------------
* FUNCTION : stripHTML()
* --------------------------------------------------------------------
* DESCRIPTION: strips html tags from a string
* PARAMETERS: strHTML - a string with some html code
* OUTPUT : string
* --------------------------------------------------------------------
*/
function stripHtml(strHTML) {
    // Replace all newLinet with .$!$. string
    strOutput = strHTML.replace(/\n/g, ".$!$.")
    // Replace all <script>s with an empty string
    aScript=strOutput.split(/\/script>/i);
    for(i=0;i<aScript.length;i++){
        aScript[i]=aScript[i].replace(/\<script.+/i,"");
    }
    strOutput=aScript.join('');
    // Replace all HTML tag matches with the empty string
    strOutput = strOutput.replace(/\<[^\>]+\>/g, "")
    // Remove empty lines
    strOutput = strOutput.replace(/\.\$\!\$\.\r\s*/g,"")
    // Replace all .$!$. with the empty string
    strOutput = strOutput.replace(/\.\$\!\$\./g,"")
    // Remove empty lines
    strOutput = strOutput.replace(/\r\ \r/g,"")
    //alert(strOutput)
    return strOutput;
}

/*
* --------------------------------------------------------------------
* FUNCTION : stripHTML()
* --------------------------------------------------------------------
* DESCRIPTION: strips html tags from a string
* PARAMETERS: strHTML - a string with some html code
* OUTPUT : string
* --------------------------------------------------------------------
*/

function chBtnStyle(bttn) {
    bttn.className="wmbttn4Hover";
}

function chBtnStyleBack(bttn) {
    bttn.className="wmbttn4";
}

/*
* --------------------------------------------------------------------
* FUNCTION : pWait(divName)
* --------------------------------------------------------------------
* DESCRIPTION: please wait...
* PARAMETERS: divName - name of the div to hide, WaitDiv to be shown
* --------------------------------------------------------------------
*/

function pWait(divName) {
    window.document.body.style.background='#FFFFFF';
    document.getElementById(divName).style.display='none';
    document.getElementById('WaitDiv').style.display='';
    WaitDisplay();
}

function openInterests() {
    window.open('interests.do','interest','scrollbars=no, resizable=yes, width=485, height=385, toolbar=no');
}
function openSections() {
    window.open('sections.do','section','scrollbars=no, resizable=yes, width=485, height=385, toolbar=no');
}

function openPrItnerests() {
    window.open('interestsprivate.do','privateInterest','scrollbars=no, resizable=yes, width=485, height=385, toolbar=no');
}

function openCountries() {
    window.open('countries.do','outletCountry','scrollbars=no, resizable=yes, width=485, height=385, toolbar=no');
}

function openSpecialities() {
    window.open('specialities.do?currentid=100001','speciality','scrollbars=no, resizable=yes, width=480, height=350, toolbar=no');
}
function openFrequency() {
    window.open('frequencies.do','frequency','scrollbars=no, resizable=yes, width=480, height=350, toolbar=no');
}

function OnMouseOverMenu(prm) {
                var MenuDiv = document.getElementById(Menus[prm]+"_div");
                MenuDiv.style.visibility = "visible";
                MenuOver[prm] = true;
            }
            function OnMouseOutMenu(prm)
            {
                MenuOver[prm] = false;
                setTimeout( "CheckMenu("+prm+")", gCheckMenuWaitTime);
            }
            function OnMouseOverMenuDiv(prm)
            {
                MenuOverDiv[prm] = true;
            }
            function OnMouseOutMenuDiv(prm)
            {
                MenuOverDiv[prm] = false;
                setTimeout( "CheckMenu("+prm+")", gCheckMenuWaitTime);
            }
            function OnMouseOverMenuItem(tr,prm)
            {
                MenuOverDiv[prm] = true;
                tr.style.backgroundColor="#666666";
            }
            function OnMouseOutMenuItem(tr)
            {
                tr.style.backgroundColor="#1F326E";
            }

            function CheckMenu(prm)
            {
                if( ! MenuOver[prm] && ! MenuOverDiv[prm]) {
                    var MenuDiv = document.getElementById(Menus[prm]+"_div");
                    MenuDiv.style.visibility = "hidden";
                }
            }

            function OnClickMenu(prm)
            {
                var MenuDiv = document.getElementById(Menus[prm]+"_div");
                MenuDiv.style.visibility = "hidden";
                MenuOver[prm] = MenuOverDiv[prm] = false;
            }
