var db = (document.compatMode && document.compatMode.toLowerCase() != "backcompat") ? document.documentElement : (document.body || null);

function isIE()
{
	var n = navigator.userAgent.toLowerCase();
	var v = parseInt(navigator.appVersion);
	
	if ((n.indexOf("msie") != -1) && (n.indexOf("opera") == -1))
	{
		return true;
	}
	
	return false;
}

function getInt(x,y)
{
	return isNaN(y = parseInt(x)) ? 0 : y;
}

function getWinWidth()
{
	return (db && db.clientWidth) ? db.clientWidth : (window.innerWidth || 0);
}

function getWinHeight()
{
	return getInt((db && db.clientHeight) ? db.clientHeight : (window.innerHeight || 0));
}

function getScrollPosX()
{
	return getInt(window.pageXOffset || (db ? db.scrollLeft : 0));
}

function getScrollPosY()
{
	return getInt(window.pageYOffset || (db ? db.scrollTop : 0));
}

function browserRelated(ff,ie)
{	
	if (isIE()) return ie;
	else return ff;
}

function highlightThumb(_this,over,y,start)
{
	if (over)
	{
		var shadow;
		var position;

		if (y)
			position = 'no-repeat center ' + y + 'px';
		else
			position = 'no-repeat';

		if (start)
			shadow = 'start-shadow.jpg';
		else
			shadow = 'shadow.jpg';

		_this.style.background = 'url(images/' + shadow + ') ' + position;
	}
	else
	{
		_this.style.background = '';
	}
}

function highlight(_this,over)
{
	if (over) _this.style.backgroundColor = '#6E8CB1';
	else _this.style.backgroundColor = '#8AA5C7';
}

function highlightRow(_this,c)
{
	_this.style.backgroundColor = c;
}

function highlightForm(_this,focused,defstr)
{
	if (focused)
	{
		if (defstr && _this.value == defstr) _this.value = "";
	}
	else
	{
		if (defstr && _this.value == "") _this.value = defstr;
	}
}

function receiveCard(_this)
{
	if (_this.value)
	{
		if (_this.value.length >= 3)
		{
			location.href = PATH_HTTP+"karte_abholen-"+_this.value+".html";
			return true;
		}
		else
		{
			am.reportMessage("ecard_code_invalid");
			return false;
		}
	}
	
	am.reportMessage("ecard_code_empty");
	return false;
}

function confirmMsg(e)
{	
	if (confirm(am.getMessage(e)))
	{
		return true;
	}
	
	return false;
}

function toggle(_this,trigger,arr_display)
{
	var ie = 0;
	var ff = 1;
		
	if (_this.style.display == "none")
	{
		if (trigger == "toggle")
		{
			if (arr_display) _this.style.display = (isIE()) ? arr_display[ie] : arr_display[ff];
			else _this.style.display = "block";
		}
	}
	else
	{
		_this.style.display = "none"
	}
}

function regenerateCode()
{//do it two times reduces the bugappereance (strange thing)
	for(var laufDuSau=0;laufDuSau<2;laufDuSau++)
	{
		if ($("cmg").src.indexOf("?x=") != -1)
		{
			$("cmg").src = $("cmg").src.replace(/\?x=\d.+\B/,"?x="+Math.round(Math.random()*1000000000000));
		}
		else
		{
			$("cmg").src = $("cmg").src+"?x="+Math.round(Math.random()*1000000000000);
		}	
	}	
}

function get_wallpaper(id,size)
{
	location.href = PATH_HTTP+"index.php?site=wallpaper&id="+id+"&download="+size;
}

function tbi(_this,img)
{
	_this.style.background = "url("+PATH_IMG+img+")";
}

function snl(loc)
{
	location.href = loc;
}

function gbSmiley(code)
{
	$("gb_msg").focus();
	$("gb_msg").value += " "+code+" ";
}

function rate_game(id, rate)
{
	location.href = PATH_HTTP+"rate_game.php?id="+id+"&rate="+rate;
}

function openflashgame(gamename)
{
	window.open(PATH_HTTP+'flashgames.php?name='+gamename+'&g_ort=popup', "flashgame",'width=480,height=280,left=200,top=200');
}

function setCookie(name,value,expires,path,domain)
{
	var curCookie = name+"="+escape(value)+((expires) ? "; expires="+expires.toGMTString() : "")+((path) ? "; path="+path : "")+((domain) ? "; domain="+domain : "");
	document.cookie = curCookie;
}

function $(id)
{
  return document.getElementById(id);
}

/* * * * * * * * * */
function debug(obj)
{
	var i = 0;
	var list;
	
	for (prop in obj)
	{
		list += prop+" => "+obj[prop]+"\n";
		
		if (i%20 == 0)
		{
			alert(list);
			list = "";
		}
		i++;
	}
}

//new upload functions
function doUploadPublic(upload_id) {
	var error = "";

	if (!$("upload").value)
		error += "- " + am.getMessage("upload_file_empty") + "\n";

	if (error) {
		alert(am.getMessage("error_headline") + '\n\n' + error);
		$("btn_upload").disabled = false;
	} else {
		document.getElementById('uploadInfo').style.display='block';
		document.getElementById('uploadInfo').style.height='40px';
		frames["iframeUploadInfo"].location.href=PATH_HTTP + "bildupload/progressBar.php?upload_id=" + upload_id;
		setTimeout("document.getElementById('upform').submit()", 2000);
	}
}

function doUploadMember(upload_id) {
	var error = "";

	if (!$("up_cat").value)
		error += "- " + am.getMessage("upload_cat_empty") + "\n";
	if (!$("up_name").value)
		error += "- " + am.getMessage("upload_name_empty") + "\n";
	if (!$("up_desc").value)
		error += "- " + am.getMessage("upload_desc_empty") + "\n";
	if (!$("up_keys").value)
		error += "- " + am.getMessage("upload_keys_empty") + "\n";
	if (!$("upload").value)
		error += "- " + am.getMessage("upload_file_empty") + "\n";

	if (error) {
		alert(am.getMessage("error_headline") + '\n\n' + error);
		$("btn_upload").disabled = false;
	} else {
		document.getElementById('uploadInfo').style.display='block';
		document.getElementById('uploadInfo').style.height='40px';
		frames["iframeUploadInfo"].location.href=PATH_HTTP + "bildupload/progressBar.php?upload_id=" + upload_id;
		setTimeout("document.getElementById('upform').submit()", 2000);
	}
}
