/* ================================================================
This copyright notice must be kept untouched in the stylesheet at
all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/pro_drop_1.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any
way to fit your requirements.
=================================================================== */
stuHover = function() {
    var cssRule;
    var newSelector;

    if (!document.styleSheets) return;

    for (var i = 0; i < document.styleSheets.length; i++)
    if (document.styleSheets[i].rules) {
            for (var x = 0; x < document.styleSheets[i].rules.length ; x++) {
        cssRule = document.styleSheets[i].rules[x];
        if (cssRule.selectorText.indexOf("LI:hover") >= 0) {
                    newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
                    document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
        }
            }
    }

    var getElm = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<getElm.length; i++) {
        getElm[i].onmouseover=function() {
            this.className+=" iehover";
        }
        getElm[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" iehover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", stuHover);


/* ================================================================
added: timeout for menues
===================================================================
cat: js: Is a directory
cat: prototype: Is a directory
cat: scriptaculous: Is a directory
*/
// JavaScript Document

function switchtab(prefix, id) {
    var tab = document.getElementById(prefix+id);
    if(tab != null) {
        var all_elems = document.getElementsByTagName("a");
        if(all_elems && all_elems.length > 0) {
            for(i = 0; i < all_elems.length; i++) {
                elem = all_elems[i];
                if(elem.id && elem.id.substring(0, prefix.length) == prefix) elem.className = "none";
            }
            tab.className = "active-tab";
        }
    }
}


function highlighttab(tab) {
    document.getElementById(tab).className="highlight-tab";
}


function switchbox (prefix,id) {
    togglebox (prefix,id,false);
}

function togglebox (prefix,id,toggle) {
    var box = document.getElementById(prefix+id);
    if(box != null) {
        var boxstyle = box.style.display;
        var alldivs = document.getElementsByTagName("div");
        if(alldivs != null && alldivs.length > 0) {
            for(i = 0; i < alldivs.length; i++) {
                elem = alldivs[i];
                if(elem.id.substring(0,prefix.length) == prefix) elem.style.display = "none";
            }
            if(toggle) {
                if (boxstyle=="none") {
                    box.style.display = "block";
                } else {
                    box.style.display = "none";
                }
            } else {
                box.style.display = "block";
            }
        }
    }
}

function showhidebox (box) {
    if(document.getElementById(box) != null) {
        if(document.getElementById(box).style.display=="none") {
            $(box).show();
        } else {
            $(box).hide();
        }
    }
}

function popupWin(theURL,winName,features) {
    return window.open(theURL,winName,features);
}

function show_contact_form (div_id) {
    var form_parts = new Array("contact_printarticle","contact_orderrelated","contact_printsamples","contact_support","contact_orderingquestions","contact_generalquestions");
    for(i=0; i < form_parts.length; i++) {
        box = document.getElementById(form_parts[i]);
        if(box != null) {
            if(box.id == "contact_"+div_id) {
                box.style.display="block";
            } else {
                box.style.display="none";
            }
        }
    }
}

function addresscomplex(href) { 
    var targetDiv = document.getElementById('addresscomplex');
    new Ajax.Request(href, {
           method: 'post',
           parameters: 'template=addresscomplex',
           //onLoading: $('addresscomplex').innerHTML = '<img src="../global/working-ani.gif"/>',
           onComplete: function(transport) {
/*
           if (transport.status == 200) {  
               element = document.getElementById('addresscomplex'); 
               element.innerHTML = transport.responseText;    
*/
               if (transport.readyState == 4 && transport.status == 200) {
                   targetDiv.innerHTML = transport.responseText;
               }
           }
        }
    )
}

function submit_addresscomplex_form(href,form_id) { 
    
    //collect form data
    var data = $('FormAddressbook').serialize();
     
    new Ajax.Updater('addresscomplex', href, {
           method: 'post',
           evalScripts: true,
           parameters: 'template=addresscomplex&'+data
    });
}
