function openURL( url, newWindow ) {
	if(newWindow) window.open(url, '', '');
	else window.location = url;
}


/* from A List Apart (http://www.alistapart.com/articles/alternate/)
 * 2010-03-09, 16:23 */
function getPreferredStyleSheet() {
	var i, a;
	
	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(-1 != a.getAttribute("rel").indexOf("style") && -1 == a.getAttribute("rel").indexOf("alt") && a.getAttribute("title")) return a.getAttribute("title");
	}

	return null;
}


/* from A List Apart (http://www.alistapart.com/articles/alternate/)
 * 2010-03-09, 16:23 */
function getActiveStyleSheet() {
	var i, a;

	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(-1 != a.getAttribute("rel").indexOf("style") && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}

	return null;
}


/* from A List Apart (http://www.alistapart.com/articles/alternate/)
 * 2010-03-09, 16:23 */
function setActiveStyleSheet( title ) {
	var i, a, main;
	var ret = false;

	for(i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(-1 != a.getAttribute("rel").indexOf("style") && a.getAttribute("title")) {
			a.disabled = true;
			if(title == a.getAttribute("title")) a.disabled = false;
			ret = true;
		}
	}

	return ret;
}


/* from A List Apart (http://www.alistapart.com/articles/alternate/)
 * 2010-03-09, 16:23 */
function createCookie( name, value, days) {
	if(days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
		else expires = "";

	document.cookie = name + "=" + value + expires + "; path=/";
}


/* from A List Apart (http://www.alistapart.com/articles/alternate/)
 * Has been modified
 * 2010-03-09, 16:23 */
function readCookie( name ) {
	name += "=";
	var cookies = document.cookie.split(';');

	for(var i = 0;i < cookies.length; i++) {
		while(' ' == cookies[i].charAt(0)) cookies[i] = cookies[i].substring(1, cookies[i].length);
		if(0 == cookies[i].indexOf(name)) return cookies[i].substring(name.length, cookies[i].length);
	}

	return null;
}


window.onload = function(e) {
	var stylesheetCookie = readCookie("mecon_style");
	var ok = false;
	if(stylesheetCookie) ok = setActiveStyleSheet(stylesheetCookie);
	if(!ok) setActiveStyleSheet("Default");
}

window.onunload = function(e) {
	createCookie("mecon_style", getActiveStyleSheet(), 365);
}

var stylesheetCookie = readCookie("mecon_style");
var ok = false;
if(stylesheetCookie) ok = setActiveStyleSheet(stylesheetCookie);
if(!ok) setActiveStyleSheet("Default");

