﻿//function dosearch() {
//    alert("1");
//    var myForm = document.forms['searchForm'];
//    alert("2");
//    if (!myForm) {
//        alert("3");
//        myForm = document.searchForm;
//    }
//    alert("4");
//    myForm.submit();
//}



function changeLanguage(language) {


    //alert( "appName: " + navigator.appName + "\n appVersion: " + navigator.appVersion + "\n appCodeName: " + navigator.appCodeName + "\n userAgent: " + navigator.userAgent);
    // get form this way for widest browser support
    //var myForm = document.forms['languageChoiceForm'];
    //if (!myForm) {
    //    myForm = document.languageChoiceForm;
    //}
    var myForm = document.forms['aspnetForm'];
    if (!myForm) {
        myForm = document.aspnetForm;
    }
    var curLang = myForm.lang.value;
    myForm.lang.value = language;
    myForm.submit();
}


/**
* THIS VERSION WORKS BEST of all I've found on the Internet, to 
* get top/left position of an html element.  Works on IE, Firefox,
* Safari.
*
* Returns the absolute X and Y positions of an object.
* @param {HTMLObject} obj HTML Object.
* @return {Object} Returns an accessor with .x and .y values.
*/
function getXY(obj)
{
var curleft = 0;
var curtop = 0;
var border;
var padding;
if (obj.offsetParent)
{
do
{
// XXX: If the element is position: relative we have to add borderWidth
if (getStyle(obj, 'position') != 'absolute')
{
if (border = getStyle(obj, 'border-top-width')) curtop += parseInt(border);
if (border = getStyle(obj, 'border-left-width')) curleft += parseInt(border);

if (padding = getStyle(obj, 'padding-top')) curtop += parseInt(padding);
if (padding = getStyle(obj, 'padding-left')) curleft += parseInt(padding);
}
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
while (obj = obj.offsetParent)
}
else if (obj.x)
{
curleft += obj.x;
curtop += obj.y;
}

    //alert("getXY returning top: " + curtop + " left: " + curleft);
return {'x': curleft, 'y': curtop};
}
/**
* Returns the specified computed style on an object.
* @param {HTMLObject} obj HTML Object
* @param {String} styleProp Property name.
* @return {Mixed} Computed style on object.
*/
function getStyle(obj, styleProp) {
    if (obj.currentStyle)
        return obj.currentStyle[styleProp];
    else if (window.getComputedStyle)
        return document.defaultView.getComputedStyle(obj, null).getPropertyValue(styleProp);
}


var dropMenuId = 0;
var hideDelay = 500;
var timer = 0;

// open hidden layer
function dropMenu(id, parentid) {
    // cancel close timer
    clearHideDelay();

    // close old layer
    if (dropMenuId) {
        dropMenuId.style.visibility = 'hidden';
    }

    // get new layer and show it
    dropMenuId = document.getElementById(id);

    var navParent = document.getElementById(parentid);  // position of parent

    // yup, it's a beautiful kludge!  padding, etc. in the parent is throwing this off
    if (parentid.toString().indexOf('NavBar') > -1) {
        dropMenuId.style.top = (getXY(navParent).y + 23) + 'px';
        dropMenuId.style.left = (getXY(navParent).x - 10) + 'px';
    }
    else {
        if (navigator.appName == "Netscape") {
            dropMenuId.style.top = (getXY(navParent).y + 25) + 'px';
        }
        else {
            dropMenuId.style.top = (getXY(navParent).y + 26) + 'px';
        }
        dropMenuId.style.left = (getXY(navParent).x + 15) + 'px';
    }

    dropMenuId.style.visibility = 'visible';

}

function hideMenu() {
    if (dropMenuId) {
        dropMenuId.style.visibility = 'hidden';
        dropMenuId = 0;
    }
}

function setHideDelay() {

    timer = window.setTimeout(hideMenu, hideDelay);
}

function clearHideDelay() {
    if (timer) {
        window.clearTimeout(timer);
        timer = null;
    }
}



var showingEuropeMap = 0;
var showingUSMap = 0;


function ajaxShowHideMap(mapId, alwaysShow) {

    // VERY KLUDGY, but it works.  So there!
   
    var myForm = document.forms['aspnetForm'];
    if (!myForm) {
        myForm = document.aspnetForm;
    }
    var curLang = myForm.lang.value;

    if (mapId.toString().indexOf("europe") >= 0) {
        var ukMapElement = document.getElementById(mapId);
        var linkElement = document.getElementById('europeLink');
        if (showingEuropeMap > 0) {
            if (alwaysShow.toString().indexOf("false") >= 0) {  // don't collapse if alwaysShow is true
                showingEuropeMap = 0;
                linkElement.style.background = 'url(\'images/LeftBlueArrowSmall2.png\') no-repeat left center';
                ukMapElement.innerHTML = '';
            }
        }
        else {
            showingEuropeMap = 1;
            linkElement.style.background = 'url(\'images/DownBlueArrowSmall.png\') no-repeat left center';
            var xmlHttp = new XMLHttpRequest();
            if (curLang == 'de') {  // do same for all languages.  oh what a hack!
                xmlHttp.open("GET", "xmlFiles/ukMap.de.xml", true);  // german
            }
            else {
                xmlHttp.open("GET", "xmlFiles/ukMap.xml", true);  // english default
            }
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                        ukMapElement.innerHTML = xmlHttp.responseText;
                    }
                }
            }
            xmlHttp.send(null);
        }
    }
    else {   // US map
        var usMapElement = document.getElementById(mapId);
        var linkElement = document.getElementById('americaLink');
        if (showingUSMap > 0) {
            if (alwaysShow.toString().indexOf("false") >= 0) {  // don't collapse if alwaysShow is true
                showingUSMap = 0;
                linkElement.style.background = 'url(\'images/LeftBlueArrowSmall2.png\') no-repeat left center';
                usMapElement.innerHTML = '';
            }
        }
        else {
            showingUSMap = 1;
            linkElement.style.background = 'url(\'images/DownBlueArrowSmall.png\') no-repeat left center';
            var xmlHttp = new XMLHttpRequest();
            if (curLang == 'de') {  // do same for all languages.  oh what a hack!
                xmlHttp.open("GET", "xmlFiles/usMap.de.xml", true);  // german
            }
            else {
                xmlHttp.open("GET", "xmlFiles/usMap.xml", true);  // english default
            }
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                        //alert(xmlHttp.responseText);
                        usMapElement.innerHTML = xmlHttp.responseText;
                    }
                }
            }
            xmlHttp.send(null);
        }
    }
}


function ajaxCollapseSection(elementId) {

    document.getElementById(elementId).innerHTML = '';

    collapseSectionLink(elementId);

}

function expandSectionLink(elementId) {

    // hide the link that expands section (yup, this is a hack)
    var elExpandLinkId = elementId.toString() + 'ExpandLink';
    elExpandLink = document.getElementById(elExpandLinkId);

    elExpandLink.style.visibility = 'hidden';
    elExpandLink.style.width = 0;
    elExpandLink.style.height = 0;

    // show the link that collapses section (yup, this is a hack)
    var elCollapseLinkId = elementId.toString() + 'CollapseLink';
    elCollapseLink = document.getElementById(elCollapseLinkId);

    elCollapseLink.style.visibility = 'visible';
    elCollapseLink.style.width = 'auto';
    elCollapseLink.style.height = 'auto';
    elCollapseLink.style.background = 'url(\'images/DownBlueArrowSmall.png\') no-repeat left center';
}
function collapseSectionLink(elementId) {

    // show the link that expands section (yup, this is a hack)
    var elExpandLinkId = elementId.toString() + 'ExpandLink';
    elExpandLink = document.getElementById(elExpandLinkId);

    elExpandLink.style.visibility = 'visible';
    elExpandLink.style.width = 'auto';
    elExpandLink.style.height = 'auto';

    // hide the link that collapses section (yup, this is a hack)
    var elCollapseLinkId = elementId.toString() + 'CollapseLink';
    elCollapseLink = document.getElementById(elCollapseLinkId);

    elCollapseLink.style.visibility = 'hidden';
    elCollapseLink.style.width = 0;
    elCollapseLink.style.height = 0;

}

