var expDays = 30;
var exp =  new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));

function init() {
	var menuid = GetCookie("menudisplay");
	if (menuid) {
		if (menuid.indexOf("sub") !=  -1) {
			showhide(menuid);
		}
	}
}
function initProjects(n)
{
	getProjects(n);
	setTimeout("initProjects("+n+")",10000);
}

function getProjects(limit)
{
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {
		document.getElementById("projects").innerHTML=oXML.responseText;
	}
	myConn.connect("xhconn_projects.tdp","GET","limit="+limit, fnWhenDone);
}

String.prototype.trim = function()
{
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}

function SetCookie(cookiename, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = "/";
	document.cookie = cookiename + "=" + escape(value) + ";expires=" + expires.toGMTString() + ";path=" + path;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr ==  - 1)endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(cookiename) {
	var arg = cookiename + "=";
	var alength = arg.length;
	var clength = document.cookie.length;
	var i = 0;
	while (i < clength) {
		var j = i + alength;
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function showhide(id) {
	if (document.getElementById) {
		if (id == "") {
			SetCookie("menudisplay", "", exp);
		}
		else {
			for(i=1;i<=3;i++) {
			if('sub'+i != id) {
				document.getElementById('sub'+i).style.display='none';
			}
			}
			var g = document.getElementById(id).style;
			g.display = (g.display == "none") ? "block" : "none";
			if(g.display== "none")
			{
				SetCookie("menudisplay", "", exp);
			} else {

				var menuid = GetCookie("menudisplay");
				SetCookie("menudisplay", id, exp);
			}
		}
	}
}

function setc(id) {
	SetCookie("menudisplay", id, exp);
}

function openWin(url, w, h) {
	var top = ((screen.availHeight-h)/2)-80;
	var left = ((screen.availWidth-w)/2);
	var r =  Math.floor(Math.random()*1000000);
	var wname='c55416dig4'+r
	var parem = 'status=0,menubar=0,resizable=1,copyhistory=no,directories=no,scrollbars=yes,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + '';
	var ywin = window.open(url, wname, parem);
	ywin.focus();
}

function galeria(id,im)
{
	openWin('galeria.php?id='+id+'&im='+im,560,530);
}

