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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function defScreenDimension () {
	var w,h;
	if (self.innerHeight) // all except Explorer
	{
		w = self.innerWidth;
		h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode == mit Doc-Type-Angabe in erster Zeile
	{
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	
	createCookie("GGLscreenWidth",w,0);
	createCookie("GGLscreenHeight",h,0);
}

// z-index=0 overlay external
// z-index=1 playground
// z-index=2 overlay internal
// z-index=3 highlighted

function showFloatWin(fwId,fwWidth,fwHeight,fwTitel,fwKategorie,fwOrderable,fwMyCard,fwSoldOut) {
	
	var top_float;
	var left_float;
	
	if ($("win"+fwId)) {
		// alert("Window " + fwId + " is already register is the DOM!!, be sure to use setDestroyOnClose()");
	} else {
		
		top_float=50+(nrOpenWindows*20);
		left_float=50+(nrOpenWindows*10);
		
		// show float window
		win= new Window("win"+fwId, {className: "mac_os_x", title:fwTitel, top:top_float, left:left_float, 
							 width:fwWidth, height:fwHeight, orderable: fwOrderable, soldout: fwSoldOut, mycard: fwMyCard, resizable: false, showEffectOptions: {duration:1}});
		win.setDestroyOnClose();
		win.toFront();	
		win.setAjaxContent("win.php?id="+fwId,{method: 'get'}, false, false);
		
		// if the first of a category
		if (nrOpenWindows==0) {
			// info for close
			actualCategory=fwKategorie;
		
			// show overlay
			$('overlay_in').style.visibility = 'visible';
			$('overlay_out').style.visibility = 'visible';
			
			// the others
			var elementList = document.getElementsByClassName(fwKategorie);
		
			for (var i = 0; i < elementList.length; i++) {
				elementList[i].style.zIndex=3;
			}
		}
		
		// update nrOpenWindows
		nrOpenWindows++;
	}
		
	// alert($('b100').style.zIndex);
}

function closeFloatWin() {
	nrOpenWindows--;
	
	if (nrOpenWindows==0) {
	
		// the others
		var elementList = document.getElementsByClassName(actualCategory);
	
		for (var i = 0; i < elementList.length; i++) {
			elementList[i].style.zIndex=1;
		}
		
		// hide overlay
		$('overlay_in').style.visibility = 'hidden';
		$('overlay_out').style.visibility = 'hidden';	
	}
}

function showOrderWin(fwId) {

	var order = new Window('OrderWin'+fwId, {className: "mac_os_x", title:"order", top:70, left:100, 
						 width:"330", height:"600", resizable: false, url: "order.php?id="+fwId, 
						 showEffectOptions: {duration:1}});
	order.toFront();
	order.setDestroyOnClose();
	order.show(); 
	
	nrOpenWindows++;
}

function idWrite(id,text) {
	document.getElementById(id).firstChild.nodeValue = text;
}

function nospam(user,domain) {
	window.location = "mailto:" + user + "@" + domain;
	return false;
}

function uffizi() {
	window.top.location = "http://uffizi.ch/";
	return false;
}
