//usage:
//print "<a href='javascript:confirm_url(\"Ta bort filen?\",\"\")'>Ta bort</a>";
function confirm_url(text, url) {
	if (confirm(text) == true) {
		window.location = url
	}
}

function expand_menu(obj) {
	if (document.getElementById) {
		if (document.getElementById(obj).style.display=='block') {
			document.getElementById(obj).style.display='none'
		} else {
			document.getElementById(obj).style.display='block'
		}
	} else if (document.all) {
		if (document.all[obj].style.visibility == "visible") {
			document.all[obj].style.visibility = "hidden"
		} else {
			document.all[obj].style.visibility = "visible"
		}
	} else {
		if (document.layers[obj].visibility == "hide") {
			document.layers[obj].visibility = "show"
		} else {
			document.layers[obj].visibility = "hide"
		}
	}

}

function expand_box(obj) {
	obj = "box_" + obj;
	arrow = obj + "_arrow";
	if (document.getElementById) {
		//IE, Mozilla...
		if (document.getElementById(obj).style.display=='block') {
			document.getElementById(obj).style.display='none';
			document.getElementById(arrow).src = "/images/box_down.gif";
			document.getElementById(arrow).title = "&Ouml;ppna";
			setCookie(obj, 2);
		} else {
			document.getElementById(obj).style.display='block';
			document.getElementById(arrow).src = "/images/box_up.gif";
			document.getElementById(arrow).title = "St&auml;ng";
			setCookie(obj, 1);
		}
	} else if (document.all) {
		//NS4?
		if (document.all[obj].style.visibility == "visible") {
			document.all[obj].style.visibility = "hidden";
			document.all[arrow].src = "/images/box_down.gif";
			document.all[arrow].title = "&Ouml;ppna";
			setCookie(obj, 2);
		} else {
			document.all[obj].style.visibility = "visible";
			document.all[arrow].src = "/images/box_up.gif";
			document.all[arrow].title = "St&auml;ng";
			setCookie(obj, 1);
		}
	} else {
		//Opera?
		if (document.layers[obj].visibility == "hide") {
			document.layers[obj].visibility = "show";
			document.layers[arrow].src = "/images/box_down.gif";
			document.layers[arrow].title = "&Ouml;ppna";
			setCookie(obj, 2);
		} else {
			document.layers[obj].visibility = "hide";
			document.layers[arrow].src = "/images/box_up.gif";
			document.layers[arrow].title = "St&auml;ng";
			setCookie(obj, 1);
		}
	}
}


function getCookie(name) { // use: getCookie("name");
	var index = document.cookie.indexOf(name + "=");
	if (index == -1) {
		return null;
	}
	index = document.cookie.indexOf("=", index) + 1;
	var endstr = document.cookie.indexOf(";", index);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(index, endstr));
}


function setCookie(name, value) { // use: setCookie("name", value);
	var today = new Date();
	var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days
	if (value != null && value != "") 
		document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}


//validate form
function validate() {
	if (document.all) {
		//IEs object model
		if (document.form_new_post.text.value == "") {
			document.form_new_post.text.focus();
			return false;
		}
        if (document.form_new_post.cookie_name.value == "") {
			document.form_new_post.cookie_name.focus();
			return false;
		} 
		return true;
	} else {
		//n�got annat �n IE
		return true;
	}
}


//this is for jumping to a page in the image archive or the forum
function go_to_page(kontroll, bas_url) {
	if (document.getElementById) {
		window.location = bas_url + document.getElementById(kontroll).value
	} else if (document.all) {
		window.location = bas_url + document.all[kontroll].value
	} else {
		window.location = bas_url + document.layers[kontroll].value
	}
}

//this is used together with the menu fuctions below
var vald;

//not used anymore
function switchMeny(cellObj) {
	cellObj.onclick = "";
	cellObj.className = "menybildon";
	vald.onclick = function(){switchMeny(this);}
	vald.className = "menybildoff";
	subMeny.innerHTML = aSubmenyer[cellObj.id];
	vald = cellObj;
}

function switchMeny2(id) {
	var cellObj = document.getElementById("menu_"+id);
	cellObj.className = "menybildon";
	document.getElementById("submenu_"+id).style.display = 'inline';
	if (vald && vald != id) {
		var valdObj = document.getElementById("menu_"+vald);
		valdObj.className = "menybildoff";
		document.getElementById("submenu_"+vald).style.display = 'none';
	}
	vald = id;
}

function openClose(obj) {
	obj.style.display = (obj.style.display == 'none') ? 'block' : 'none';
}

function openCloseStr(id) {
	obj = document.getElementById(id)
	obj.style.display = (obj.style.display == 'none') ? 'block' : 'none';
}

function addMozillaPanel(url) {
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
        window.sidebar.addPanel ("Global Uppv&auml;rmning",url,"");
    }
    else {
        var rv = window.confirm ("Global Uppv&auml;rmning-sidebar kr&auml;ver en bra webbl&auml;sare. Vill du ladda ner en nu?");
        if (rv)
            document.location.href = "http://www.getfirefox.com/";
    }
}

function popUp(URL, width, height) {
    day = new Date();
    id = day.getTime();
    left = (screen.width - width) / 2;
    top = (screen.height - height) / 2;
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+height+',left='+left+',top='+top);");
}

function limitTextArea(textA,l) {
	if (textA.value.length > l) { 
		textA.value = textA.value.substring(0, l-1);
		return window.alert('Max '+ l +' tecken');
	}
}

