// new
function setImgSrc()
{
	var imgpath = PATH_HTTP+'customimage.php?maxim='+$('encode_maxim').value+'&motiv='+$('newmotiv').value+'&fontsize='+$('newfontsize').value+'&fgcolor='+$('newfgcolor').value+'&bgcolor='+$('newbgcolor').value+'&fonttype='+$('newfonttype').value+'&shadow='+$('newshadow').value+'&pos_x='+$('newpos_x').value+'&pos_y='+$('newpos_y').value;
	$('customImg').src = imgpath;
}

function select_value(_this)
{
	return _this.options[_this.selectedIndex].value;
}

function es_form()
{
	$('sendform').submit();
}

function es_position(_x, _y)
{
	$('newpos_x').value = eval($('newpos_x').value)+eval(_x);
	$('newpos_y').value = eval($('newpos_y').value)+eval(_y);
	setImgSrc();
	//es_form();
}

function es_fonttype(ttf)
{
	$('newfonttype').value = ttf;
	es_form();
}
function es_fontcolor(color)
{
	$('newfgcolor').value = color;
	es_form();
}
function es_backcolor(color)
{
	$('newbgcolor').value = color;
	$('newshadow').value = '1';
	es_form();
}

function es_fontsize(nextfont)
{
	
	$('newfontsize').value = eval($('newfontsize').value) + eval(nextfont);
	
	if($('newfontsize').value > 48)
	{
		$('newfontsize').value = 48;
	}
	if($('newfontsize').value < 12)
	{
		$('newfontsize').value = 12;
	}
	setImgSrc();
	//es_form();
	
}

function es_motiv(motiv)
{
	$('newmotiv').value = motiv;
	es_form();
}

function es_foreground(value)
{
	if(value)
	{
		$('foreground').style.visibility = 'visible';
		posForeground();
	}
	else
	{
		$('foreground').style.visibility = 'hidden';
	}
}

function es_charsLeft(_this)
{
	_this.value = _this.value.replace(/'/,"´");
	
	if (_this.value.length >= 255)
	{
		_this.value = _this.value.substr(0,255);
		$('es_cl').innerHTML = 255;
		
		return false;
	}
	
	$('es_cl').innerHTML = _this.value.length;
}

var db = (document.compatMode && document.compatMode.toLowerCase() != "backcompat") ? document.documentElement : (document.body || null);
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 posForeground()
{
	if($('foreground'))
	{
		if($('foreground').style.visibility == 'visible')
		{
			var y = getInt(getScrollPosY()+(getWinHeight()-300)/2)
			$('foreground').style.top = y+'px';
			var x = getInt(getScrollPosX()+(getWinWidth()-700)/2)
			$('foreground').style.left = x+'px';		
		}
	}
}