var xmlHttp;

function showGenInfo(sex, age, rel, grov) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "generator.php";
	url = url + "?sex=" + sex;
	url = url + "&age=" + age;
	url = url + "&rel=" + rel;
	url = url + "&grov=" + grov;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function showBusKat(id) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "showbuskat.php";
	url = url + "?id=" + id;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChanged() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("genresponse").innerHTML = xmlHttp.responseText;
	}
}

function sendTips(to, mess, fil) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/tipsa_mail.php";
	url = url + "?to=" + to;
	url = url + "&tipsamess=" + mess;
	url = url + "&tipsafil=" + fil;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedTipsa;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedTipsa() {
	if (xmlHttp.readyState != 4) {
		document.getElementById("submitTips").value = "Skickar...";
		document.getElementById("submitTips").disabled = true;
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("tipssvar").innerHTML = xmlHttp.responseText;
		document.getElementById("submitTips").value = "Tipsa";
		document.getElementById("submitTips").disabled = false;
		document.getElementById("to").value = "";
		document.getElementById("mess").value = "";
	}
}

function postComment(namn, comment, fil, user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_comment.php";
	url = url + "?namn=" + namn;
	url = url + "&comment=" + comment;
	url = url + "&fil=" + fil;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedComment;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedComment() {
	if (xmlHttp.readyState != 4) {
		document.getElementById("comment_button").value = "Skickar...";
		document.getElementById("comment_button").disabled = true;
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("comments").innerHTML = xmlHttp.responseText;
		document.getElementById("comment_button").value = "Kommentera";
		document.getElementById("comment_button").disabled = false;
		document.getElementById("comment_text").value = "";
		window.location.hash = "kommentarer";
	}
}
function contentComment(cid, namn, comment, user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/content_comment.php";
	url = url + "?namn=" + namn;
	url = url + "&comment=" + comment;
	url = url + "&cid=" + cid;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedcontentComment;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedcontentComment() {
	if (xmlHttp.readyState != 4) {
		document.getElementById("comment_button").value = "Skickar...";
		document.getElementById("comment_button").disabled = true;
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("comments").innerHTML = xmlHttp.responseText;
		document.getElementById("comment_button").value = "Kommentera";
		document.getElementById("comment_button").disabled = false;
		document.getElementById("comment_text").value = "";
		window.location.hash = "comments";
	}
}
function deleteComment(id,page,user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_comment_del.php";
	url = url + "?id=" + id;
	url = url + "&page=" + page;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function(){stateChangeddeleteComment(id)}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangeddeleteComment(id) {
	if(document.getElementById("user_comments")){
		var p_elements = document.getElementById("user_comments").getElementsByTagName("p");
		var p_elements_id = new Array();
		for(i=0;i<p_elements.length;i++){
			p_elements_id[i] = new Array();
			p_elements_id[i][0] = p_elements[i].parentNode.id;
			if(p_elements[i].style.display=='none'){
				p_elements_id[i][1] = 'none';
			}
			else {
				p_elements_id[i][1] = 'block';
			}
		}
	}
	if (xmlHttp.readyState != 4) {
		document.getElementById(("com_a_"+id)).innerHTML = "Tar bort...";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		if(document.getElementById("comments")){
			document.getElementById("comments").innerHTML = xmlHttp.responseText;
			window.location.hash = "kommentarer";
		}
		if(document.getElementById("user_comments")){
			if(xmlHttp.responseText=='empty'){
				document.getElementById("com_msg").innerHTML = 'Du har inga kommentarer kvar!';
				document.getElementById("user_comments").innerHTML = '';
			}
			else {
				document.getElementById("user_comments").innerHTML = xmlHttp.responseText;
				for(i=0;i<p_elements_id.length;i++){
					if(document.getElementById(p_elements_id[i][0])){
						var recid = p_elements_id[i][0].substring(7);
						var elem_check = document.getElementById(p_elements_id[i][0]).getElementsByTagName("p");
						for(j=0;j<elem_check.length;j++){
							elem_check[j].style.display = p_elements_id[i][1];
							if(p_elements_id[i][1]=='none'){
								document.getElementById(('togicon_'+recid)).src = 'http://www.busring.se/img/icons/arrow_right.png';
							}
							else {
								document.getElementById(('togicon_'+recid)).src = 'http://www.busring.se/img/icons/arrow_down.png';
							}
						}
					}
				}
			}
		}
	}
}
function deleteContentComment(id,page,user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/content_comment_del.php";
	url = url + "?id=" + id;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function(){stateChangeddeletecontentComment(id)}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangeddeletecontentComment(id) {
	if (xmlHttp.readyState != 4) {
		document.getElementById(("com_a_"+id)).innerHTML = "Tar bort...";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {	
		document.getElementById("comments").innerHTML = xmlHttp.responseText;
		window.location.hash = "comments";
	}
}
function reportComment(id) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_comment_report.php";
	url = url + "?id=" + id;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function(){stateChangedreportComment(id)}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedreportComment(id) {
	if (xmlHttp.readyState != 4) {
		document.getElementById("report_"+id).innerHTML = "Skickar...";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("report_"+id).innerHTML = xmlHttp.responseText;
	}
}
function reportContentComment(id) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/content_comment_report.php";
	url = url + "?id=" + id;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function(){stateChangedreportcontentComment(id)}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedreportcontentComment(id) {
	if (xmlHttp.readyState != 4) {
		document.getElementById("report_"+id).innerHTML = "Skickar...";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("report_"+id).innerHTML = xmlHttp.responseText;
	}
}
function postVote(rating, fil, user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_vote.php";
	url = url + "?rating=" + rating;
	url = url + "&fil=" + fil;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedVote;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedVote() {
	if (xmlHttp.readyState != 4) {
		document.getElementById("votetxt").innerHTML = 'Röstar...';
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("votetxt").innerHTML = xmlHttp.responseText;
		for (i = 0; i < 5; i++) {
			document.getElementById('star' + i).src = '/img/star_off.png';
		}
	}
}
function contentVote(rating, cid) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/content_vote.php";
	url = url + "?rating=" + rating;
	url = url + "&cid=" + cid;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedcontentVote;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedcontentVote() {
	if (xmlHttp.readyState != 4) {
		document.getElementById("rate").innerHTML = '<img src="/img/phone_load.gif" />';		
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		setTimeout("printContentVote()",1500);		
	}
}
function printContentVote(){
	document.getElementById("rate").innerHTML = xmlHttp.responseText;
	
	var images = document.getElementById("rate").getElementsByTagName("img");		
	var c = 0;
	for(i=0;i<images.length;i++){
		str = images[i].src
		if(str.indexOf("phone_on.png") > -1){
			c = c+1;
		}
	}
	document.getElementById("rate").setAttribute("onmouseout", "highlightVote(" + c + ")");
}
function unmakeFav(fil, user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_unmakefav.php";
	url = url + "?fil=" + fil;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function(){stateChangedunmakeFav(fil)}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedunmakeFav(fil) {
	if (xmlHttp.readyState != 4) {
		document.getElementById(("fav_a_del_"+fil)).getElementsByTagName("a").href = "javascript:void";
		document.getElementById(("fav_img_del_"+fil)).src="/img/icons/arrow_anim.gif";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("user_fav").innerHTML = xmlHttp.responseText;
	}
}
function makeFav(user, fil) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_makefav.php";
	url = url + "?fil=" + fil;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangedmakeFav;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedmakeFav() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("fav").innerHTML = xmlHttp.responseText;
	}
}
function deleteRec(id) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}
	var url = "/rec_del.php";
	url = url + "?id=" + id;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function() {stateChangeddeleteRec(id)}
	if (confirm("Detta kommer att radera inspelningen, " + id + ".mp3, permanent från servern!")) {
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
}
function stateChangeddeleteRec(id) {
	if (xmlHttp.readyState != 4) {
		document.getElementById(("rec_a1_"+id)).getElementsByTagName("a").href = "javascript:void";
		document.getElementById(("rec_img_del_"+id)).src="/img/icons/arrow_anim.gif";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("user_rec").innerHTML = xmlHttp.responseText;
	}
}
function toggleRecPrivate(id,val) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "/rec_private.php";
	url = url + "?id=" + id;
	url = url + "&val=" + val;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = function(){stateChangedtoggleRecPrivate(id)}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function stateChangedtoggleRecPrivate(id) {
	if (xmlHttp.readyState != 4) {
		document.getElementById(("rec_a2_"+id)).getElementsByTagName("a").href = "javascript:void";
		document.getElementById(("rec_img_lock_"+id)).src="/img/icons/arrow_anim.gif";
	}
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("user_rec").innerHTML = xmlHttp.responseText;
	}
}
function deleteNews(id,user) {
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert("Browser does not support HTTP Request");
		return;
	}

	var url = "user_news_del.php";
	url = url + "?id=" + id;
	url = url + "&user=" + user;
	url = url + "&sid=" + Math.random();
	xmlHttp.onreadystatechange = stateChangeddeleteNews;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChangeddeleteNews() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("user_msg").innerHTML = xmlHttp.responseText;
	}
}
function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function sleep(time){
	var t = setTimeout("wake()",time);
}
function wake(){
	clearTimeout(t);
}
function highlightVote(c){
	if(document.getElementById('vote1')){
		for(i=1;i<=5;i++){
			if(i<=c){
				document.getElementById('vote'+i).src = '/img/phone_on.png';
			}
			else {
				document.getElementById('vote'+i).src = '/img/phone_off.png';
			}
		}
	}
}

function setDivHeights() {
	if (document.all) {
		var iLeftHeight = document.getElementById("leftcol").offsetHeight;
		var iRightHeight = document.getElementById("rightcol").offsetHeight;
		if (document.getElementById("maincontenttopwrapper2")) {
			var contentHeight = document
					.getElementById("maincontenttopwrapper2").offsetHeight;
		}
	} else {
		var iLeftHeight = document.getElementById("leftcol").clientHeight;
		var iRightHeight = document.getElementById("rightcol").clientHeight;
		if (document.getElementById("maincontenttopwrapper2")) {
			var contentHeight = document
					.getElementById("maincontenttopwrapper2").clientHeight;
		}
	}
	if (iLeftHeight > iRightHeight) {
		document.getElementById("rightcol").style.height = (iLeftHeight - 2)
				+ "px";
		if (document.getElementById("genresponse")) {
			if (document.getElementById("maincontenttopwrapper2")) {
				document.getElementById("genresponse").style.minHeight = (iLeftHeight - contentHeight)
						+ 8 + "px";
			} else {
				document.getElementById("genresponse").style.minHeight = (iLeftHeight - 200)
						+ "px";
			}
		}
	} else {
		document.getElementById("leftcol").style.height = (iRightHeight - 2)
				+ "px";
		if (document.getElementById("genresponse")) {
			if (document.getElementById("maincontenttopwrapper2")) {
				document.getElementById("genresponse").style.minHeight = (iLeftHeight - contentHeight)
						+ 8 + "px";
			} else {
				document.getElementById("genresponse").style.minHeight = (iLeftHeight - 200)
						+ "px";
			}
		}
	}
}
function setKnappHeight() {
	if (document.getElementById("1")) {
		if (document.all) {
			var rad1Height = document.getElementById("rad1").offsetHeight;
			var rad2Height = document.getElementById("rad2").offsetHeight;
			var rad3Height = document.getElementById("rad3").offsetHeight;
			var rad4Height = document.getElementById("rad4").offsetHeight;

			document.getElementById("1").style.height = rad1Height + "px";
			document.getElementById("2").style.height = rad1Height + "px";
			document.getElementById("3").style.height = rad1Height + "px";

			document.getElementById("4").style.height = rad2Height + "px";
			document.getElementById("5").style.height = rad2Height + "px";
			document.getElementById("6").style.height = rad2Height + "px";

			document.getElementById("7").style.height = rad3Height + "px";
			document.getElementById("8").style.height = rad3Height + "px";
			document.getElementById("9").style.height = rad3Height + "px";

			document.getElementById("*").style.height = rad4Height + "px";
			document.getElementById("0").style.height = rad4Height + "px";
			document.getElementById("#").style.height = rad4Height + "px";

		} else {
			var rad1Height = document.getElementById("rad1").clientHeight;
			var rad2Height = document.getElementById("rad2").clientHeight;
			var rad3Height = document.getElementById("rad3").clientHeight;
			var rad4Height = document.getElementById("rad4").clientHeight;

			document.getElementById("1").style.height = rad1Height + "px";
			document.getElementById("2").style.height = rad1Height + "px";
			document.getElementById("3").style.height = rad1Height + "px";

			document.getElementById("4").style.height = rad2Height + "px";
			document.getElementById("5").style.height = rad2Height + "px";
			document.getElementById("6").style.height = rad2Height + "px";

			document.getElementById("7").style.height = rad3Height + "px";
			document.getElementById("8").style.height = rad3Height + "px";
			document.getElementById("9").style.height = rad3Height + "px";

			document.getElementById("*").style.height = rad4Height + "px";
			document.getElementById("0").style.height = rad4Height + "px";
			document.getElementById("#").style.height = rad4Height + "px";
		}
	}
}
function setKnappHeight2() {
	if (document.getElementById("1")) {
		if (document.all) {
			var rad1Height = document.getElementById("rad1").offsetHeight - 90;
			var rad2Height = document.getElementById("rad2").offsetHeight - 90;
			var rad3Height = document.getElementById("rad3").offsetHeight - 90;
			var rad4Height = 70;
			if (rad1Height < 70) {
				rad1Height = 70;
			}
			if (rad2Height < 70) {
				rad2Height = 70;
			}
			if (rad3Height < 70) {
				rad3Height = 70;
			}
			document.getElementById("1").style.height = rad1Height + "px";
			document.getElementById("2").style.height = rad1Height + "px";
			document.getElementById("3").style.height = rad1Height + "px";

			document.getElementById("4").style.height = rad2Height + "px";
			document.getElementById("5").style.height = rad2Height + "px";
			document.getElementById("6").style.height = rad2Height + "px";

			document.getElementById("7").style.height = rad3Height + "px";
			document.getElementById("8").style.height = rad3Height + "px";
			document.getElementById("9").style.height = rad3Height + "px";

			document.getElementById("*").style.height = (rad4Height - 7) + "px";
			document.getElementById("0").style.height = rad4Height + "px";
			document.getElementById("#").style.height = rad4Height + "px";

		} else {
			var rad1Height = document.getElementById("rad1").clientHeight - 90;
			var rad2Height = document.getElementById("rad2").clientHeight - 90;
			var rad3Height = document.getElementById("rad3").clientHeight - 90;
			var rad4Height = 70;
			if (rad1Height < 70) {
				rad1Height = 70;
			}
			if (rad2Height < 70) {
				rad2Height = 70;
			}
			if (rad3Height < 70) {
				rad3Height = 70;
			}
			document.getElementById("1").style.height = rad1Height + "px";
			document.getElementById("2").style.height = rad1Height + "px";
			document.getElementById("3").style.height = rad1Height + "px";

			document.getElementById("4").style.height = rad2Height + "px";
			document.getElementById("5").style.height = rad2Height + "px";
			document.getElementById("6").style.height = rad2Height + "px";

			document.getElementById("7").style.height = rad3Height + "px";
			document.getElementById("8").style.height = rad3Height + "px";
			document.getElementById("9").style.height = rad3Height + "px";

			document.getElementById("*").style.height = (rad4Height - 7) + "px";
			document.getElementById("0").style.height = rad4Height + "px";
			document.getElementById("#").style.height = rad4Height + "px";
		}
	}
}
//FACEBOOK CONNECT

function feed_published_prank(prank) {

	var user_box = document.getElementById("user");

	// add in some XFBML. note that we set useyou=false so it doesn't display
	// "you"
	user_box.innerHTML = "<span>"
			+ "<fb:profile-pic uid=loggedinuser size=square facebook-logo=false></fb:profile-pic>"
			+ "Tjena <fb:name uid=loggedinuser firstnameonly=true useyou=false></fb:name>, du är nu inloggad via ditt Facebook-konto"
			+ "</span>";
	var data = {
		"link" : 'http://www.busring.se/rec/' + prank + '.html?ref=124'
	};
	FB.Connect.showFeedDialog(103940234080, data);

	// because this is XFBML, we need to tell Facebook to re-process the
	// document
	FB.XFBML.Host.parseDomTree();
}

// TOOLTIP FUNCTIONS

addLoadListener(initTooltips);

function initTooltips() {
	var tips = getElementsByAttribute("class", "hastooltip");

	for ( var i = 0; i < tips.length; i++) {
		attachEventListener(tips[i], "mouseover", showTip, false);
		attachEventListener(tips[i], "mouseout", hideTip, false);
	}

	return true;
}

function showTip(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}

	var target = getEventTarget(event);

	while (target.className == null
			|| !/(^| )hastooltip( |$)/.test(target.className)) {
		target = target.parentNode;
	}

	var tip = document.createElement("div");
	var content = target.getAttribute("title");

	target.tooltip = tip;
	target.setAttribute("title", "");

	if (target.getAttribute("id") != "") {
		tip.setAttribute("id", target.getAttribute("id") + "tooltip");
	}

	tip.className = "tooltip";
	tip.appendChild(document.createTextNode(content));

	var scrollingPosition = getScrollingPosition();
	var cursorPosition = [ 0, 0 ];

	if (typeof event.pageX != "undefined" && typeof event.x != "undefined") {
		cursorPosition[0] = event.pageX;
		cursorPosition[1] = event.pageY;
	} else {
		cursorPosition[0] = event.clientX + scrollingPosition[0];
		cursorPosition[1] = event.clientY + scrollingPosition[1];
	}

	tip.style.position = "absolute";
	tip.style.left = cursorPosition[0] + 10 + "px";
	tip.style.top = cursorPosition[1] + 10 + "px";
	tip.style.visibility = "hidden";

	document.getElementsByTagName("body")[0].appendChild(tip);

	var viewportSize = getViewportSize();

	if (cursorPosition[0] - scrollingPosition[0] + 10 + tip.offsetWidth > viewportSize[0] - 25) {
		tip.style.left = scrollingPosition[0] + viewportSize[0] - 25
				- tip.offsetWidth + "px";
	} else {
		tip.style.left = cursorPosition[0] + 10 + "px";
	}

	if (cursorPosition[1] - scrollingPosition[1] + 10 + tip.offsetHeight > viewportSize[1] - 25) {
		if (event.clientX > (viewportSize[0] - 25 - tip.offsetWidth)) {
			tip.style.top = cursorPosition[1] - tip.offsetHeight - 10 + "px";
		} else {
			tip.style.top = scrollingPosition[1] + viewportSize[1] - 25
					- tip.offsetHeight + "px";
		}
	} else {
		tip.style.top = cursorPosition[1] + 10 + "px";
	}

	tip.style.visibility = "visible";
	tip.style.zIndex = "100";

	return true;
}

function hideTip(event) {
	if (typeof event == "undefined") {
		event = window.event;
	}

	var target = getEventTarget(event);

	while (target.className == null
			|| !target.className.match(/(^| )hastooltip( |$)/)) {
		target = target.parentNode;
	}

	if (target.tooltip != null) {
		target.setAttribute("title", target.tooltip.childNodes[0].nodeValue);
		target.tooltip.parentNode.removeChild(target.tooltip);
	}

	return false;
}

function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else {
		var oldfn = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = fn;
		} else {
			window.onload = function() {
				oldfn();
				fn();
			};
		}
	}
}

function attachEventListener(target, eventType, functionRef, capture) {
	if (typeof target.addEventListener != "undefined") {
		target.addEventListener(eventType, functionRef, capture);
	} else if (typeof target.attachEvent != "undefined") {
		target.attachEvent("on" + eventType, functionRef);
	} else {
		eventType = "on" + eventType;

		if (typeof target[eventType] == "function") {
			var oldListener = target[eventType];

			target[eventType] = function() {
				oldListener();

				return functionRef();
			}
		} else {
			target[eventType] = functionRef;
		}
	}

	return true;
}

function getEventTarget(event) {
	var targetElement = null;

	if (typeof event.target != "undefined") {
		targetElement = event.target;
	} else {
		targetElement = event.srcElement;
	}

	while (targetElement.nodeType == 3 && targetElement.parentNode != null) {
		targetElement = targetElement.parentNode;
	}

	return targetElement;
}

function getViewportSize() {
	var size = [ 0, 0 ];

	if (typeof window.innerWidth != 'undefined') {
		size = [ window.innerWidth, window.innerHeight ];
	} else if (typeof document.documentElement != 'undefined'
			&& typeof document.documentElement.clientWidth != 'undefined'
			&& document.documentElement.clientWidth != 0) {
		size = [ document.documentElement.clientWidth,
				document.documentElement.clientHeight ];
	} else {
		size = [ document.getElementsByTagName('body')[0].clientWidth,
				document.getElementsByTagName('body')[0].clientHeight ];
	}

	return size;
}

function getScrollingPosition() {
	// array for X and Y scroll position
	var position = [ 0, 0 ];

	// if the window.pageYOffset property is supported
	if (typeof window.pageYOffset != 'undefined') {
		// store position values
		position = [ window.pageXOffset, window.pageYOffset ];
	}

	// if the documentElement.scrollTop property is supported
	// and the value is greater than zero
	if (typeof document.documentElement.scrollTop != 'undefined'
			&& document.documentElement.scrollTop > 0) {
		// store position values
		position = [ document.documentElement.scrollLeft,
				document.documentElement.scrollTop ];
	}

	// if the body.scrollTop property is supported
	else if (typeof document.body.scrollTop != 'undefined') {
		// store position values
		position = [ document.body.scrollLeft, document.body.scrollTop ];
	}

	// return the array
	return position;
}

function getElementsByAttribute(attribute, attributeValue) {
	var elementArray = new Array();
	var matchedArray = new Array();

	if (document.all) {
		elementArray = document.all;
	} else {
		elementArray = document.getElementsByTagName("*");
	}

	for ( var i = 0; i < elementArray.length; i++) {
		if (attribute == "class") {
			var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

			if (elementArray[i].className.match(pattern)) {
				matchedArray[matchedArray.length] = elementArray[i];
			}
		} else if (attribute == "for") {
			if (elementArray[i].getAttribute("htmlFor")
					|| elementArray[i].getAttribute("for")) {
				if (elementArray[i].htmlFor == attributeValue) {
					matchedArray[matchedArray.length] = elementArray[i];
				}
			}
		} else if (elementArray[i].getAttribute(attribute) == attributeValue) {
			matchedArray[matchedArray.length] = elementArray[i];
		}
	}

	return matchedArray;
}
function prank() {
	window.location.href = "http://www.busring.se/erase.php";
}
