var ho_next_sec = 1;
function ho_timeback(minute,visible) {
	var ho_tmbk = 1*minute;
	if(ho_next_sec == 0) {
		if(ho_tmbk > 0) {
			ho_tmbk = ho_tmbk-1;
			minute = ho_tmbk;
			if(minute < 10) {
				minute = '0' + minute;
			}
			document.getElementById('minute').innerHTML = minute;
		}
	} else {
		ho_next_sec = 0;
	}
	if(ho_tmbk > 0) {
		setTimeout('ho_timeback(' + minute + ',\'1\')',60000);
	} else {
		if(visible == 1) {
			document.getElementById('ho_timeback').innerHTML = '&nbsp;0:00';
			setTimeout('ho_timeback(' + minute + ',\'0\')',1000);
		} else {
			document.getElementById('ho_timeback').innerHTML = '';
			setTimeout('ho_timeback(' + minute + ',\'1\')',1000);
		}
	}
}

function set_attribute(id_name,id_i,attr,value,sum_id,other_value, bn_id_name,bn_id_i,bn_attr,bn_value,bn_sum_id,bn_other_value,id_ind,isie) {
	if(isie <= 1) {
		for(var i=1; i<=sum_id; i++) {
			document.getElementById(id_name+i).setAttribute(attr,other_value);
		}
		for(var i=1; i<=bn_sum_id; i++) {
			document.getElementById(bn_id_name+i).setAttribute(bn_attr,bn_other_value);
		}
		if(id_ind == 1) {
			document.getElementById(id_name+id_i).setAttribute(attr,value);
			if(bn_id_name != '') {
				document.getElementById(bn_id_name+bn_id_i).setAttribute(bn_attr,bn_value);
			}
		}
	} else {
		// isie = 2,3 (ie6,7) -> set_attribute_ie();
		set_attr_ie(id_name,id_i,attr,value,sum_id,other_value, bn_id_name,bn_id_i,bn_attr,bn_value,bn_sum_id,bn_other_value,id_ind,isie)
	}
}

function set_attr_ie(id_name,id_i,attr,value,sum_id,other_value, bn_id_name,bn_id_i,bn_attr,bn_value,bn_sum_id,bn_other_value,id_ind,isie) {
	if(isie >= 2) {
		// ie6,7
		if(attr == 'style') {
			if(other_value != '') {
				var tmp_o_attrs = new Array();
				tmp_o_attrs = other_value.split(' ');
				var o_params = new Array();
				var o_values = new Array();
				for (var i in tmp_o_attrs) {
					var tmp_o_params = new Array();
					tmp_o_params = tmp_o_attrs[i].split(':');
					o_params[i] = tmp_o_params['0'];
					o_values[i] = tmp_o_params['1'].substr(0,tmp_o_params['1'].length-1);
				}
				
				for(var j in o_params) {
					for(var i=1; i<=sum_id; i++) {
						if(o_params[j] == 'height') {
							document.getElementById(id_name+i).style.height = o_values[j];
						} else if(o_params[j] == 'width') {
							document.getElementById(id_name+i).style.width = o_values[j];
						} else if(o_params[j] == 'background-position') {
							document.getElementById(id_name+i).style.backgroundPosition = o_values[j];
						}/* else if(o_params[j] == 'background-image') {
							document.getElementById(id_name+i).style.backgroundImage = o_values[j];
						}*/ else if(o_params[j] == 'display') {
							document.getElementById(id_name+i).style.display = o_values[j];
						}
					}
				}
			}
			if(value != '') {
				var tmp_attrs = new Array();
				tmp_attrs = value.split(' ');
				var params = new Array();
				var values = new Array();
				for (var i in tmp_attrs) {
					var tmp_params = new Array();
					tmp_params = tmp_attrs[i].split(':');
					params[i] = tmp_params['0'];
					values[i] = tmp_params['1'].substr(0,tmp_params['1'].length-1);
				}
				
				for(var j in params) {
					if(id_ind == 1) {
						if(params[j] == 'height') {
							document.getElementById(id_name+id_i).style.height = values[j];
						} else if(params[j] == 'width') {
							document.getElementById(id_name+id_i).style.width = values[j];
						} else if(params[j] == 'background-position') {
							document.getElementById(id_name+id_i).style.backgroundPosition = values[j];
						}/* else if(params[j] == 'background-image') {
							document.getElementById(id_name+id_i).style.backgroundImage = values[j];
						}*/ else if(params[j] == 'display') {
							document.getElementById(id_name+id_i).style.display = values[j];
						}
					}
				}
			}
		} else if (attr == 'class') {
			for(var i=1; i<=sum_id; i++) {
				document.getElementById(id_name+i).className = other_value;
			}
			if(id_ind == 1) {
				document.getElementById(id_name+id_i).className = value;
			}
		}
		if(bn_attr == 'style') {
			if(bn_other_value != '') {
				var tmp_bn_o_attrs = new Array();
				tmp_bn_o_attrs = bn_other_value.split(' ');
				var bn_o_params = new Array();
				var bn_o_values = new Array();
				for (var i in tmp_bn_o_attrs) {
					var tmp_bn_o_params = new Array();
					tmp_bn_o_params = tmp_bn_o_attrs[i].split(':');
					bn_o_params[i] = tmp_bn_o_params['0'];
					bn_o_values[i] = tmp_bn_o_params['1'].substr(0,tmp_bn_o_params['1'].length-1);
				}
				
				for(var j in bn_o_params) {
					for(var i=1; i<=bn_sum_id; i++) {
						if(bn_o_params[j] == 'height') {
							document.getElementById(bn_id_name+i).style.height = bn_o_values[j];
						} else if(bn_o_params[j] == 'width') {
							document.getElementById(bn_id_name+i).style.width = bn_o_values[j];
						} else if(bn_o_params[j] == 'background-position') {
							document.getElementById(bn_id_name+i).style.backgroundPosition = bn_o_values[j];
						}/* else if(bn_o_params[j] == 'background-image') {
							document.getElementById(bn_id_name+i).style.backgroundImage = bn_o_values[j];
						}*/ else if(bn_o_params[j] == 'display') {
							document.getElementById(bn_id_name+i).style.display = bn_o_values[j];
						}
					}
				}
			}
			if(bn_value != '') {
				var tmp_bn_attrs = new Array();
				tmp_bn_attrs = bn_value.split(' ');
				var bn_params = new Array();
				var bn_values = new Array();
				for (var i in tmp_bn_attrs) {
					var tmp_bn_params = new Array();
					tmp_bn_params = tmp_bn_attrs[i].split(':');
					bn_params[i] = tmp_bn_params['0'];
					bn_values[i] = tmp_bn_params['1'].substr(0,tmp_bn_params['1'].length-1);
				}
				
				for(var j in bn_params) {
					if(id_ind == 1 && bn_id_name != '') {
						if(bn_params[j] == 'height') {
							document.getElementById(bn_id_name+bn_id_i).style.height = bn_values[j];
						} else if(bn_params[j] == 'width') {
							document.getElementById(bn_id_name+bn_id_i).style.width = bn_values[j];
						} else if(bn_params[j] == 'background-position') {
							document.getElementById(bn_id_name+bn_id_i).style.backgroundPosition = bn_values[j];
						}/* else if(bn_params[j] == 'background-image') {
							document.getElementById(bn_id_name+id_i).style.backgroundImage = bn_values[j];
						}*/ else if(bn_params[j] == 'display') {
							document.getElementById(bn_id_name+bn_id_i).style.display = bn_values[j];
						}
					}
				}
			}
		} else if (bn_attr == 'class') {
			for(var i=1; i<=sum_id; i++) {
				document.getElementById(bn_id_name+i).className = bn_other_value;
			}
			if(id_ind == 1) {
				document.getElementById(bn_id_name+id_i).className = bn_value;
			}
		}
	}
}

var layer_msg = new Array();
function get_layer_messages() {
	xmlhttp = GetXmlHttpObject();
	var nocache = Math.random();
	var url = '/mds/get_layer_messages.php?nocache=' + nocache;
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4) {
			var tmp_layer_msg_str = xmlhttp.responseText;
			set_layer_msg(tmp_layer_msg_str);
		}
	}
	xmlhttp.open('GET',url,true);
	xmlhttp.send(null);
}

function set_layer_msg(msgs_str) {
	var tmp_layer_msg = new Array();
	tmp_layer_msg = msgs_str.split('||');
	for (var i=0; i<12; i++/* in tmp_layer_msg*/) {
		layer_msg[i] = new Array();
		layer_msg[i] = tmp_layer_msg[i].split('|');
	}
}

function show_msglayer(row) {
	document.getElementById('darktitle').innerHTML = layer_msg[row][2];
	document.getElementById('darktext').innerHTML = layer_msg[row][3];
	document.getElementById('darkbtns').innerHTML = layer_msg[row][4];
	document.getElementById('dark').style.display = 'block';
	jumptoanchor('logo',200);
}

function hide_msglayer() {
	document.getElementById('dark').style.display = 'none';
}

function get_innerheight() {
	var visibleheight = window.innerHeight-15;
	if(visibleheight > 0) {
	} else {
	var visibleheight = document.documentElement.clientHeight;
	}
	// -10 is because of the 10px tv-frame and some diff
	return visibleheight;
}

	
function GetXmlHttpObject() {
	if(window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if(window.ActiveXObject) {
		// code for IE6, IE5
		return new ActiveXObject('Microsoft.XMLHTTP');
	}
	return null;
}

function set_innerheight(frame,src) {
	// get screen inner height for game sizes
	load_frame(frame,src + '&innerheight=' + get_innerheight());
}

var scrollcount;
function jumptoanchor(anchorname,pixel) {
	window.scrollTo(getAnchorPosition(anchorname).x,getAnchorPosition(anchorname).y);
	window.scrollBy(0,pixel);
	scrolltoanchor(0-pixel);
	scrollcount = 0;
}

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		var wh=1;
	} else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		var wh=2;
	} else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		var wh=3;
	} else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
		}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
		}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		var wh=4;
	} else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		var wh=5;
	}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

function scrolltoanchor(pixel) {
	if(Math.abs(pixel)>1 || scrollcount <20) {
		var temppixel = Math.round(pixel/3);
		window.scrollBy(0,temppixel);
		var newpixel = pixel - temppixel;
		scrollcount++;
		setTimeout('scrolltoanchor(' + newpixel + ');',50);
	} else {
		scrollcount = 0;
	}
}

var overlay_ctrl_time = 9;
var overlay_time;
function overlay_timeback(ifstop) {
	if(ifstop == 0) {
		if(overlay_ctrl_time > 0) {
			setTimeout('overlay_timeback(0);',1000);
			overlay_time = overlay_ctrl_time;
			document.getElementById('timeback').innerHTML = overlay_time;
			overlay_time--;
			overlay_ctrl_time--;
		} else if(overlay_time == overlay_ctrl_time) {
			setTimeout('overlay_timeback(1);',0);
		}
	} else {
		document.getElementById('overlay_ad').style.display = 'none';
		document.getElementById('gamecontainer').style.display = 'block';
		//set_attribute('gamecontainer','','style','display:block','0','','overlay_ad','','style','display:none','',' ','1');
		overlay_ctrl_time = 0;
	}
}

function load_frame(frame, src) {
	document.getElementById(frame).src = src;
}

function iframe_offset(frame,isie,height) {
	if(isie > 1) {
		document.getElementById(frame).height = height+'px';
	} else {
		document.getElementById(frame).height = document.getElementById(frame).contentDocument.body.offsetHeight;
	}
}

function inner_html(id,text) {
	document.getElementById(id).innerHTML = text;
}

function bookmarksite(){
	var title = 'Jatekbarlang';
	var url = 'http://www.jatekbarlang.eu';
	if (window.sidebar) {// firefox 
		window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {// ie
		window.external.AddFavorite(url, title);
	}
}

function sethomepage() {
	if (document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage('http://www.jatekbarlang.eu');
	} else if (window.sidebar) {
		show_msglayer(10);
	}
}

function onload_focus(input) {
	document.getElementById(input).focus();
}

function input_value(id,value) {
	document.getElementById(id).value = value;
}

function parts_order(id1,id2) {
	var value1name = document.getElementById('parts_data_name_'+id2).value;
	var value1partall = document.getElementById('parts_data_partall_'+id2).value;
	var value2name = document.getElementById('parts_data_name_'+id1).value;
	var value2partall = document.getElementById('parts_data_partall_'+id1).value;
	document.getElementById('parts_data_name_'+id1).value = value1name;
	document.getElementById('parts_data_partall_'+id1).value = value1partall;
	document.getElementById('parts_data_name_'+id2).value = value2name;
	document.getElementById('parts_data_partall_'+id2).value = value2partall;
}

function cntclk(clicked_id) {
	xmlhttp = GetXmlHttpObject();
	var nocache = Math.random();
	var url = '/mds/click_counter.php?nocache=' + nocache + '&clicked_id=' + clicked_id;
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4) {
			var clicked_url = xmlhttp.responseText;
		}
	}
	xmlhttp.open('GET',url,true);
	xmlhttp.send(null);
}
