
var requestedmenuitem = '';
var currentmenuitem = '';
var originalmenuitem = '';
var closemenutimeout = null;

var hideAllMenuItems = false;

function openNewWindow(url) {
    window.location.href = url;
}

function formatCurrency(nStr) {
    nStr = parseFloat(nStr).toFixed(2);
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

function validateNumber(e, isdecimal) {
    var unicode = e.keyCode ? e.keyCode : e.charCode;

    if ((unicode > 47 && unicode < 58) || (unicode == 46) || (unicode > 36 && unicode < 41) || unicode == 8 || unicode == 9) {
        return true;
    } else {
        return false;
    }
}

function openPage(href) {
    window.location.href = href;
}

function openMenu() {
    originalmenuitem = readCookie("currentmenu");
    showmenuitem(originalmenuitem);
}

function closeMenuItems() {
    requestedmenuitem = '';
    if (hideAllMenuItems == undefined) {
        hideAllMenuItems = true
        if (closemenutimeout != null) window.clearTimeout(closemenutimeout);
        closemenutimeout = window.setTimeout("closeMenuItems()", 2000);
        return;
    }
    
    if (hideAllMenuItems == true && originalmenuitem != currentmenuitem) {
        showmenuitem(originalmenuitem);
    }
}

function showmenuitem(item) {
    if (item == undefined || item == "") return;

    if (currentmenuitem == item) {
        return;
        //toggleLayer(currentmenuitem);
        //currentmenuitem = '';
    }
    
    createCookie("currentmenu", item, 0);

    if (currentmenuitem != '') setTimeout("toggleLayer('" + currentmenuitem + "')", 350);

    currentmenuitem = item;
    toggleLayer(item);

    var itemheight = itemheight(item);

    doshowmenu(item, 15, 15, itemheight);
}

function doshowmenu(item, height, inc, maxheight) {
    document.getElementById(item).style.height = height;
    if ((inc > 0 && height < maxheight) || (inc < 0 && height > maxheight)) setTimeout("doshowmenu('" + item + "', " + (height + inc) + ", " + inc + ", " + maxheight + ");", 70);
}

function dohidemenu(item, height, inc, maxheight) {
    document.getElementById(item).style.height = height;
    if ((inc > 0 && height < maxheight) || (inc < 0 && height > maxheight)) setTimeout("doshowmenu('" + item + "', " + (height + inc) + ", " + inc + ", " + maxheight + ");", 70);
    //if(inc < 0 && height > maxheight)toggleLayer(item);
}

function itemheight(item) {
    var Height;

    var element = document.getElementById(item);

    if (element.scrollHeight > 0) { // all but Explorer Mac
        Height = element.scrollHeight;
    } else if (window.innerHeight && window.scrollMaxY) {// Firefox
        Height = element.innerHeight + element.scrollMaxY;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        Height = element.offsetHeight;
    }

    return Height;
}

function pageheight() {
    height = window.innerHeight;

    if (height == undefined) {
        height = document.documentElement.clientHeight;

        if (height == 0) { height = document.body.clientHeight; }
    }

    return height;
}

function pagewidth() {
    width = window.innerWidth;

    if (width == undefined) {
        width = document.documentElement.clientWidth;

        if (width == 0) { width = document.body.clientWidth; }
    }

    return width;
}

function toggleLayer(elem) {
    var vis;

    vis = elem.style;  // if the style.display value is blank we try to figure it out here

    try {
        if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
            vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';

        vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
    } catch (ex) {
        vis.display = '';
    }

}

function toggleLayerById(whichLayer) {
    var elem, vis;

    if (document.getElementById) // this is the way the standards work    
        elem = document.getElementById(whichLayer);
    else if (document.all) // this is the way old msie versions work      
        elem = document.all[whichLayer];
    else if (document.layers) // this is the way nn4 works    
        elem = document.layers[whichLayer];
    vis = elem.style;  // if the style.display value is blank we try to figure it out here

    if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
        
    vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function clearFormFieldValues(form) {

    var input;
    var inputs = form.getElementsByTagName('input');

    for (var i = 0; (input = inputs[i]); i++) {
        if (input.type == "text") {
            input.value = "";
        }
    }

    var inputs = form.getElementsByTagName('select');

    for (var i = 0; (input = inputs[i]); i++) {
        input.value = "";
    } 


}



//BWAA
function doMenuResize() {
    var pageInnerHeight = pageheight();
    var menuInnerHeight = itemheight("menu_body");

    if (pageInnerHeight > 400 && menuInnerHeight < (pageInnerHeight - 240)) {
        document.getElementById("menu_body").style.height = (pageInnerHeight - 240) + "px";
    }
}



//MEDICON

function forgotMediconPwd(imglocation) {
    openDialogBox("/modules/mediconconference/forgotpassword.aspx");
}

function advancedSearch(link) {
    if (document.getElementById("advancedsearch").style.display == '') {
        document.getElementById("advancedsearch").style.display = 'none';
        document.getElementById("ctl00_txtIsAdvancedSearch").value = '0';
        if (link != undefined) link.innerText = 'Advanced Search';
    } else {
        document.getElementById("advancedsearch").style.display = '';
        document.getElementById("ctl00_txtIsAdvancedSearch").value = '1';
        if (link != undefined) link.innerText = 'Simple Search';
    }
    if (menuvisible == true) document.getElementById('bannerads').style.top = document.getElementById('advancedsearch').style.display == 'none' ? '117px' : '242px';
}

function setDimensions() {
    if (pagewidth() > 1024) {
        document.getElementById("pageleftbg").style.height = itemheight("contentarea") + 'px';
        document.getElementById("pagerightbg").style.height = itemheight("contentarea") + 'px';
        document.getElementById("contentarea").style.height = itemheight("contentarea") + 'px';
    } else {
        document.getElementById("pageleftbg").style.display = 'none';
        document.getElementById("pagerightbg").style.display = 'none';
    }
    window.onscroll = doScroll;
}

var menuvisible = false;
var advisible = false;
function doScroll() {

    if (pageheight() < 600) return;

    var scrolltop = getScrollXY()[1];

    var loginvisible = 'none';

    try {
        loginvisible = document.getElementById('commonlogin').style.display;
    } catch (ex) {
    }

    if (scrolltop > BannerHeight) {
        if (menuvisible != true) {
            document.getElementById('menufixed').style.display = "";
            //document.getElementById('menufixed').style.left = findPosX(document.getElementById('contentarea')) + "px";
            menuvisible = true;

            try {
                var element = document.getElementById('conferencesearch');
                element.style.position = "fixed";
                element.style.top = '48px';
                element.style.zIndex = 100;

                var element = document.getElementById('advancedsearch');
                element.style.position = "fixed";
                element.style.top = '113px';
                element.style.zIndex = 100;
            } catch (ex) {
            }

            if (loginvisible == 'none') {
                bannertop = '48px';

                try {
                    if (BannerAdjustHeight == false) bannertop = document.getElementById('advancedsearch').style.display == 'none' ? '117px' : '242px';
                } catch (ex) {
                }

                try {
                    var element = document.getElementById('bannerads');
                    element.style.position = "fixed";
                    element.style.top = bannertop;
                    element.style.zIndex = 100;
                } catch (ex) {
                }
            }
        }
    }
    else if (menuvisible == true) {
        menuvisible = false;
        document.getElementById('menufixed').style.display = "none";

        try {
            document.getElementById('conferencesearch').style.position = "relative";
            document.getElementById('conferencesearch').style.top = "0px";
            document.getElementById('advancedsearch').style.position = "relative";
            document.getElementById('advancedsearch').style.top = "0px";
        } catch (ex) {
        }

        try {
            var element = document.getElementById('bannerads');
            element.style.position = "relative";
            element.style.top = '0px';
        } catch (ex) { 
        }
    }

    if (loginvisible != 'none') {
        if (scrolltop > (BannerHeight + 88)) {
            if (advisible == false) {
                advisible = true;
                try {
                    var element = document.getElementById('bannerads');
                    element.style.position = "fixed";
                    element.style.top = '48px';
                    element.style.zIndex = 100;
                } catch (ex) {
                }
            }
        } else if (advisible == true) {
            advisible = false;
            try {
                var element = document.getElementById('bannerads');
                element.style.position = "relative";
                element.style.top = '0px';
            } catch (ex) {
            }
        }
    }    

}

function rotateAd(currentAD) {
    if (document.getElementById("_AD" + currentAD) == null && currentAD == 0) return;

    document.getElementById("_AD" + currentAD).style.display = 'none';
    currentAD += 1;
    if (document.getElementById("_AD" + currentAD) == null) currentAD = 0;
    document.getElementById("_AD" + currentAD).style.display = '';

    window.setTimeout("rotateAd(" + currentAD + ");", 10000);
}

function swapImage(image) {
    if (image.src.match(/_over/) != null) {
        image.src = image.src.replace('_over', '');
    }
    else {
        image.onmouseout = function() { swapImage(image) };
        image.src = image.src.replace('.jpg', '_over.jpg');
    }
}

function toggleSiblingDiv(elem) {
    try {
        toggleLayer(elem.parentNode.nextSibling);
        return toggleLayer(elem.parentNode.getElementsByTagName('div')[0]);
    } catch (ex) {
    }
}

function openDialogBox(url) {
    window.open(url, '1', 'width=670,height=550,status=no,toolbar=no,menubar=no,location=no');
}

function openCityInfo(id) {
    window.open('cityinfo.aspx?id='+id, '1', 'width=844,height=654,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes');
}

function validateCheckbox(source, args) {
    args.IsValid = document.getElementById("ctl00_ContentPlaceHolder1_chkTerms").checked;
}

function validatePosition(source, args) {
    if (document.getElementById("ctl00_ContentPlaceHolder1_rptrRegistrationForm_ctl03_ddlDropdown").value == "Other, please specify..." && document.getElementById("ctl00_ContentPlaceHolder1_rptrRegistrationForm_ctl03_txtPosition").value == "") {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_rptrRegistrationForm_ctl03_ddlDropdown").value == "Other, please specify...") {
        document.getElementById("txtOtherPosition").value = document.getElementById("ctl00_ContentPlaceHolder1_rptrRegistrationForm_ctl03_txtPosition").value;
    }
    else {
        document.getElementById("txtOtherPosition").value = document.getElementById("ctl00_ContentPlaceHolder1_rptrRegistrationForm_ctl03_ddlDropdown").value;
    }
}


        function validateCreditCard(field, cardType) {

            var s = field.value;
            if (s.length > 0 && cardType != null) {
                // remove non-numerics
                var v = "0123456789";
                var w = "";
                for (i = 0; i < s.length; i++) {
                    x = s.charAt(i);
                    if (v.indexOf(x, 0) != -1)
                        w += x;
                }

                // check that the type of card conforms with that cards attributes
                // eg cardtype: prefix; length; algorithm;
                var pfx0 = "";
                var pfx1 = "";
                var pfxerr = 0;
                var pfxmsg1 = "The entered Credit Cards prefix DOES NOT match the Credit Card type.";
                pfxmsg1 += "\n" + "\n" + cardType + " cards should begin with ";
                var pfxmsg2 = "The entered Credit Cards number of characters DOES NOT match the Credit Card type.";
                pfxmsg2 += "\n" + "\n" + cardType + " cards MUST be ";

                switch (cardType) {
                    case "Mastercard":
                        pfxmsg1 += "51, 52, 53, 54 or 55.";
                        pfx0 = w.substr(0, 2);
                        if (pfx0 != "51" && pfx0 != "52" && pfx0 != "53" && pfx0 != "54" && pfx0 != "55") {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "16 numeric characters long.";
                        if (w.length != 16) pfxerr = 2;
                        break;

                    case "Visa":
                        pfxmsg1 += "4.";
                        pfx0 = w.substr(0, 1);
                        if (pfx0 != "4") {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "13 or 16 numeric characters long.";
                        if (w.length != 16 && w.length != 13) pfxerr = 2;
                        break;

                    case "Amex":
                        pfxmsg1 += "34 or 37.";
                        pfx0 = w.substr(0, 2);
                        if (pfx0 != "34" && pfx0 != "37") {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "15 numeric characters long.";
                        if (w.length != 15) pfxerr = 2;
                        break;

                    case "Diners Club":
                    case "Carte Blanche":
                        pfxmsg1 += "300, 301, 302, 303, 304, 305, 36 or 38.";
                        pfx0 = w.substr(0, 3);
                        pfx1 = w.substr(0, 2);
                        if (pfx0 == "300" || pfx0 == "301" || pfx0 == "302" || pfx0 == "303" || pfx0 == "304" || pfx0 == "305" || pfx1 == "36" || pfx1 == "38") {
                            pfxerr = 0;
                        }
                        else {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "14 numeric characters long.";
                        if (w.length != 14) pfxerr = 2;
                        break;

                    case "Discover":
                        pfxmsg1 += "6011.";
                        pfx0 = w.substr(0, 4);
                        if (pfx0 != "6011") {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "16 numeric characters long.";
                        if (w.length != 16) pfxerr = 2;
                        break;

                    case "enRoute":
                        pfxmsg1 += "2014 or 2149.";
                        pfx0 = w.substr(0, 4);
                        if (pfx0 != "2014" && pfx0 != "2149") {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "15 numeric characters long.";
                        if (w.length != 15) pfxerr = 2;
                        break;

                    case "JCB":
                        pfxmsg1 += "3, 1800 or 2131.";
                        pfx0 = w.substr(0, 1);
                        pfx1 = w.substr(0, 4);
                        if (pfx0 == "3" || pfx1 == "1800" || pfx1 == "2131") {
                            pfxerr = 0;
                        }
                        else {
                            pfxerr = 1;
                            break;
                        }
                        pfxmsg2 += "16 numeric characters long.";
                        if (w.length == 16 && pfx0 != "3") {
                            pfxerr = 2;
                            break;
                        }
                        pfxmsg2 += "15 numeric characters long.";
                        if (w.length == 15 && (pfx1 != "1800" || pfx1 != "2131")) pfxerr = 2;
                        break;

                    default:
                        pfxmsg1 = "Unknown Credit Card type";
                        pfxerr = 1;
                }

                switch (pfxerr) {
                    case 1:
                        pfxmsg1 += "\n" + "\n" + "Please check and re-enter the card type and/or number.";
                        //alert(pfxmsg1);
                        return false;
                    case 2:
                        pfxmsg2 += "\n" + "\n" + "Please check and re-enter the card type and/or number.";
                        //alert(pfxmsg2);
                        return false;
                }

                // validate number
                j = w.length / 2;
                if (j < 6.5 || j > 8 || j == 7) return false;
                k = Math.floor(j);
                m = Math.ceil(j) - k;
                c = 0;
                for (i = 0; i < k; i++) {
                    a = w.charAt(i * 2 + m) * 2;
                    c += a > 9 ? Math.floor(a / 10 + a % 10) : a;
                }
                for (i = 0; i < k + m; i++) c += w.charAt(i * 2 + 1 - m) * 1;
                if (c % 10 == 0) {
                    fieldName = w;
                }
                else {
                    pfxmsg1 = "The Credit Card number is invalid or was not entered correctly."
                    pfxmsg1 += "\n" + "\n" + "Please check and re-enter the number.";
                    //alert(pfxmsg1);
                    field.focus();
                    return false;
                }
            }
            return true;
        }
