/*
	MAIN JS FUNCTIONS FOR SKI.DK
	all rights reserved
	
	VERSION: 		0.2
	LAST MODIFIED:	27-MAR-2007
	MODIFIED BY:	msa@cubizz.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all:oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

/* add to favorites */
function addfavorites() {
	var url=location.href; 
	var title=document.title; 
	if (window.sidebar)								// firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print) {			// opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)							// ie
		window.external.AddFavorite(url, title);
}

/* send to a friend */
function send_to_a_friend() {
	var panel = document.getElementById("staf");
	panel.style.display = (panel.style.display!="block")? "block":"none";
	/* todo: scroll to staf-panel, if it's above the page fold (ie. user has scrolled down and clicked the staf link at the bottom of the page) */
	return (panel.style.display=="block");
}


/* window.onload handler */
function init() {
	/* hide "add to favorites" icon from Safari */
	if (navigator.appVersion.indexOf("Safari")>0) {
		var es = getElementsByClassName(document,"a","hidefromsafari");
		for (var i=0;i<es.length;i++) es[i].style.display = 'none';
	}
}
window.onload = init;