function addEvent(obj, type, fn) {
	if (obj.attachEvent) {
		obj['e' + type + fn] = fn;
		obj[type + fn] = function() { obj['e' + type + fn] (window.event); }
		obj.attachEvent('on' + type, obj[type + fn] );
	} else {
		obj.addEventListener(type, fn, false);
	}
}

function removeEvent(obj, type, fn ) {
	if (obj.detachEvent) {
		obj.detachEvent('on' + type, obj[type + fn] );
		obj[type+fn] = null;
	} else {
		obj.removeEventListener( type, fn, false);
	}
}

function newwindow(coverURL) {
	var coverwin = window.open(coverURL,'cover','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=710,height=580');
}

function lyricwindow(lyricURL) {
	var lyricwin = window.open(lyricURL,'lyric','toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=650');
}

function compwindow(compURL) {
	var compwin = window.open(compURL,'comp','toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=450');
}

function bookwindow(bookURL)     {
	var bookwin=window.open(bookURL,'book','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=480,height=550');
}

function demowindow(demoURL) {
	var demowin = window.open(demoURL,'demo','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=450');
}

function mapwindow(popupURL) {
	var mapwindow = window.open(popupURL,"FindTune",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=470,height=170');
}

function announce(annURL) {
	var s = getCookie('announce');
	if (s != 1) {
		announceWin = window.open(annURL,'announcement','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=320');
	}
}

function amazonwindow(url,name) {
	var amznwin=window.open(url,name,'location=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes,width=380,height=450,screenX=10,screenY=10,top=10,left=10');
	amznwin.focus();
}

function helpWindow(helpURL) {
	var helpwin = window.open(helpURL, '','toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=0,resizable=1,width=600,height=460');
}

function setScrollArea() {
	var h = (document.body.offsetHeight - (document.getElementById('contract').className != 'hide'? document.getElementById('bodyScroll').offsetTop : 24) -4);
	var hp = (h < 1?1:h) + "px";
	document.getElementById('bodyScroll').style.height = hp;
}

function initMenu() {
	document.getElementById('loading').className = "hide";
	document.getElementById('menuLinks').className = "menuLinks";
	document.getElementById('timeDisplay').className = "timeDisplay";
	var s = getCookie('menuState');
	if (s == null) { s = 1; }
	showMenu(s);
	setScrollArea();
	if(document.location.href.indexOf('#')!=-1) {
		document.location.href=document.location.href;
	}
}

function showMenu(show) {
	if(show==0) { aI.hideAreas(pMap); }
	document.getElementById('contract').className = (show == 1 ? "show": "hide");
	document.getElementById('expand').className = (show == 0 ? "show": "hide");
	if(brVersion == '') {
		document.getElementById('expand').style.marginTop = "-5px";
	}
	setScrollArea();
	if(show==1) { aI.showArea(pageRef,pMap); }
	document.cookie = "menuState=" + show;
}

function setMenu() {
	var s = getCookie('menuState');
	if(s==0) { aI.hideAreas(pMap); }
	setScrollArea();
	if(s==1) { aI.showArea(pageRef,pMap); }
}

function showAbout(show) {
	if (document.getElementById('about') == null) { return }
	divAbout = document.getElementById('about');
	if(show==0) {
		divAbout.className = "hide";
	} else {
		divAbout.style.top = (document.getElementById('menuLinks').offsetTop) + 'px';
		divAbout.style.left = document.body.offsetWidth - 360 + 'px';
		divAbout.className = "dAbout";
	}
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0)
			return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
    	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function tabOver(pObj) {
	pObj.style.backgroundColor="#f3efcd";
}

function tabOff(pObj) {
	pObj.style.backgroundColor="#d6d6b5";
}
