function setCookie(name,value) {
  time=new Date();
  endtime=new Date(time.getTime()+256*86400000);
  document.cookie=name+"="+value+";path=/;domain=.durak.hlop.de;expires="+endtime.toGMTString()+";";
}
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 (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}


function style(id, position, top, left, zindex, height, width){
  css = document.getElementById(id).style;
  css.position = position;
  css.top      = top+'px';
  css.left     = left+'px';
  css.zIndex   = zindex;
  css.height   = height+'px';
  css.width    = width+'px';
}

function Link(url){
	if(url=='durak') {
		document.getElementById('menu_r').style.display = "none";
		document.getElementById('loaded').style.display = "none";
		document.getElementById('loading').style.display = "none";
		document.getElementById('durak').style.display  = "block";
	}
	else {
		document.getElementById('menu_r').style.display = "block";
		document.getElementById('loaded').style.display = "block";
		document.getElementById('durak').style.display  = "none";
		loadURL(url,'');
	}
}

function CardBack(url){
	setCookie('deck',url);
	Images['back'].src = url;
	document.getElementById("staple").style.backgroundImage = 'url('+Images['back'].src+')';
	document.getElementById("cardback").style.backgroundImage = 'url('+Images['back'].src+')';
	for (i = 0; i < 36; i++) {
		document.getElementById("cardp2" + i).style.backgroundImage = 'url('+Images['back'].src+')';
	}
}

function bg_color(color){
	setCookie('body',color);
	var bg_body = document.getElementsByTagName('body')[0].style;
	bg_body.backgroundColor = color;
}

function popup_chat(){
  screenbreite = screen.width;
  screenhoehe = screen.height;
  width = 590;
  height = 385;
  bildbreite = width + 20;
  bildhoehe = height + 25;
  xoffset = (screenbreite - bildbreite) / 2;
  yoffset = (screenhoehe - bildhoehe) / 2;
  fenster = window.open('http://chat.irussian.de/',"CHAT","width=" + width +",height=" + height +",toolbar=no,location=no,directories=no,status =no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,left=" + xoffset + ",top=" + yoffset)
}


function XMLHttp() {
    if(window.XMLHttpRequest) {
    	try { req = new XMLHttpRequest(); }
		catch(e) { req = false; }
    }
	else if(window.ActiveXObject) {
       	try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e) {
        	try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e) { req = false; }
		}
	}
	return req;
}

function CallInProgress(xmlHttp){
	if(xmlHttp) {
		switch (xmlHttp.readyState) {
			case 1:
			case 2:
			case 3: return true;
			default: return false;
		}
	} else { return false; }
}

var httpGet  = XMLHttp();
var httpSave = XMLHttp();
var httpOn   = XMLHttp();
var SCom;

function loadURL(url,opt){
	document.getElementById('loading').style.display = "block";
	if (httpGet && !CallInProgress(httpGet)) {
		httpGet.open('GET', '/index/'+url+'.php'+opt, true);
		httpGet.onreadystatechange = function () {
			if (httpGet.readyState == 4) {
				if ((httpGet.status == 200 || httpGet.status == 0)){
					document.getElementById('loading').style.display = "none";
					document.getElementById('loaded').innerHTML = httpGet.responseText;
				}
			}
		};
		httpGet.send(null);
	}
}

function dataSave(type){
	if (httpSave && !CallInProgress(httpSave)) {
		httpSave.open('GET', '/index/save.php?type='+type, true);
		httpSave.onreadystatechange = function () {
			if (httpSave.readyState == 4) {
				if ((httpSave.status == 200 || httpSave.status == 0)){
					//document.getElementById('loaded').innerHTML = httpGet.responseText;
					if(type>0&&type<4){
						showSay(httpSave.responseText);
						window.clearTimeout(SCom);
						SCom = window.setTimeout("hideSay()",5000);
					}
				}
			}
		};
		httpSave.send(null);
	}
}
function showSay(msg){
	document.getElementById("say_msg").innerHTML = msg;
	document.getElementById("msg_say").style.visibility = "visible";
}
function hideSay(){
	document.getElementById("msg_say").style.visibility = "hidden";
}
function playerOnline(){
	if (httpOn && !CallInProgress(httpOn)) {
		httpOn.open('GET', '/index/online.php', true);
		httpOn.onreadystatechange = function () {
			if (httpOn.readyState == 4) {
				if ((httpOn.status == 200 || httpOn.status == 0)){
					document.getElementById('d_online').innerHTML = httpOn.responseText;
				}
			}
		};
		httpOn.send(null);
	}
	setTimeout("playerOnline()",60000);
}
function playerOnlineM(){
	if (httpOn && !CallInProgress(httpOn)) {
		httpOn.open('GET', '/index/online.php?s=m', true);
		httpOn.onreadystatechange = function () {
			if (httpOn.readyState == 4) {
				if ((httpOn.status == 200 || httpOn.status == 0)){
					document.getElementById('d_online').innerHTML = httpOn.responseText;
				}
			}
		};
		httpOn.send(null);
	}
	setTimeout("playerOnlineM()",60000);
}