function HoverMenu(e)
{
	if (!e) var e = window.event;
	var menu;
	
	switch (e.srcElement.tagName)
	{
		case "A":
			menu = e.srcElement.parentElement;
			break;
		case "IMG":
			menu = e.srcElement.parentElement.parentElement;
			break;
		default:
			menu = e.srcElement;
			break;
	}
	
	if (menu.className == "MenuItem")
	{
		menu.style.backgroundColor = "#000033";
		menu.style.width = "180";
	}
	if (menu.className == "MenuItemHover")
	{
		menu.style.backgroundColor = "transparent";
		menu.style.width = "180";
	}

	
}

function UnhoverMenu(e)
{
if (!e) var e = window.event;
	
	
	switch (e.srcElement.tagName)
	{
		case "A":
			menu = e.srcElement.parentElement;
			break;
		case "IMG":
			menu = e.srcElement.parentElement.parentElement;
			break;
		default:
			menu = e.srcElement;
			break;
	}
	
	if (menu.className == "MenuItem")
	{
		menu.className = "MenuItemHover";
	}
	if (menu.className == "MenuItemHover")
	{
		menu.className = "MenuItem";
	}
}

// Printing

// 
// IE only: attach eventhandlers.
// They trigger when a user  prints a web page; 
//     From File->Print, File->Print Preview or
//     by executing a window.print() command 
//
window.onbeforeprint=beforePrint
window.onafterprint=afterPrint

function beforePrint() {
    appendlinks(document);
}

function afterPrint() {
    //alert('afterPrint');
    removelinks("divPrint");
}


//
// Generic print function, called from the web page
//
function printContent() {
    if (window.print) {
           window.print();
    } else {
        alert("your browser doesn't support this function")
    }
}


// 
// When appending links to the document, do not 
// append links pointing to the following domains / sites
//

var excludedomains=["soderlind.no", "soderlind.org","localhost"]
var excludedomains=excludedomains.join("|")
rexcludedomains=new RegExp(excludedomains, "i")

//
// appendlinks(id)
// id = id of the part of the web page you want to extract links from
//      ex: document.body
//

function appendlinks(id){
    var strD = "<p/>";
    var num = 0;
    if (document.getElementById)
    {
        var links=id.getElementsByTagName("A")    
        var total=links.length
        
        strD += "<dl id=\"appendedlinks\" border=0>"
        strD += "<dt><h2>The following sites were linked to by this page</h2></dt>"
        for (i=0; i < total; i++){
            //alert(links[i].hostname.search(rexcludedomains));
            if (links[i].hostname.search(rexcludedomains) <= 0)
            {
            //alert(links[i].className);
				//allowed domains
				//if (links[i].href.indexOf("http:")!=-1) 
				//{
					//relative link
					//strD += '<dt>'+links[i].innerText+'</dt>'
					//strD += '<dd>http://www.stpatricks.org.nz/'+links[i]+'</dd>'
				//}
				if (links[i].className != "MenuLink" && links[i].parentElement.className != "MenuItem" && links[i].className != "NoPrint")
				{
					if((links[i].innerText != "")&&(links[i].innerText != " ") && (links[i].innerText != "here"))
					{
						strD += '<dt>'+links[i].innerText+'</dt>'
					}
					strD += '<dd>'+links[i]+'</dd>'
				}
				num++;
            }
            else
            {
				alert('nope');
            }
        }
        strD += "</dl>"

        //if (id.insertAdjacentHTML && num>0)
          //  id.insertAdjacentHTML("beforeEnd",strD);
          var printDIV = document.getElementById("divPrint");
          
        printDIV.innerHTML = strD;
           
			
    }
}

//
// removelinks(id)
// After the print job is done, remove the appended links from the document
// id = appendedlinks
//
function removelinks(id) {
    //if (document.getElementById){
    //    id.removeNode(true);
    //}
    //document.getElementById(id).style.display = "none";
    document.getElementById(id).innerHTML = "";
}
