// vim:ts=4:sw=4:noet

function getActiveStyleSheet() {
	var i, a;
	for(i = 0; (a = document.getElementsByTagName("link")[i]); ++i) {
		//if(a.getAttribute("media") != null && a.getAttribute("media").indexOf("screen") == -1)
		//	continue;
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")
				&& !a.disabled)
			return a.getAttribute("title");
	}
	return null;
}

function getDefaultStyleSheet() {
	var i, a;
	for(i = 0; (a = document.getElementsByTagName("link")[i]); ++i) {
		//if(a.getAttribute("media") != null && a.getAttribute("media").indexOf("screen") == -1)
		//	continue;
		if(a.getAttribute("rel").indexOf("style") != -1
				&& a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
			return a.getAttribute("title");
	}
	return null;
}

function getRandomStyleSheet() {
	var i, a, arr = new Array();
	for(i = 0; (a = document.getElementsByTagName("link")[i]); ++i) {
		//if(a.getAttribute("media") != null && a.getAttribute("media").indexOf("screen") == -1)
		//	continue;
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
			arr[arr.length] = a.getAttribute("title");
	}
	return arr[Math.floor(Math.random() * arr.length)];
}		

function setActiveStyleSheet(title) {
	var i, a;
	if(title == "none") {
		for(i = 0; (a = document.getElementsByTagName("link")[i]); ++i) {
			if(a.getAttribute("media") != null && a.getAttribute("media").indexOf("screen") == -1)
				continue;
			if(a.getAttribute("rel").indexOf("stylesheet") != -1)
				a.disabled = true;
		}
	} else {
		for(i = 0; (a = document.getElementsByTagName("link")[i]); ++i) {
			//if(a.getAttribute("media") != null && a.getAttribute("media").indexOf("screen") == -1)
			//	continue;
			if(a.getAttribute("rel").indexOf("stylesheet") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title)
					a.disabled = false;
			}
		}
	}
}

