
/*
	Removes the spaces from begin of string and from end.
	It means, if string is "  string   " it makes "string"
	Params:
		str string [string witch need to check]
*/
function trimString (str) {

	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);

	return str;
}
//---------------------------------------------------------------

function previewArtwork(id, artwork_id, rank, url, search_url)
{
	var obj = document.getElementById(id);
	
	if (obj)
	{
		obj.style.display = 'block';
		
		var boxWidth = 438;
		var boxHeight = 355;
		
		var docwidth = 750;
		//var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth;
		var docheight = document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);
		
		var xcoord = Math.round((docwidth - boxWidth) / 2);
		var ycoord = Math.round((docheight - boxHeight) / 2);
		
		var yy = document.all? truebody().scrollTop : pageYOffset;
		if (yy > 0)
			ycoord = ycoord + yy;
		
		obj.style.left = xcoord+"px";
		obj.style.top = ycoord+"px";
		
		var ajax = new sack();
		ajax.setVar("artwork_id", artwork_id);
		ajax.setVar("rank", rank);
		ajax.setVar("url", url);
		ajax.setVar("search_url", search_url);
		ajax.requestFile = "/includes/preview_artwork.php";
		ajax.method = 'POST';
		ajax.element = 'box_inner';
		ajax.runAJAX();
	}
	
	return false;
}
//---------------------------------------------------------------

function hidePopUp(id) {
	document.getElementById(id).style.display = 'none';
	if (document.getElementById('box_inner'))
		document.getElementById('box_inner').innerHTML = "";
	return false;
}
//---------------------------------------------------------------

function truebody() {
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
//---------------------------------------------------------------

/*
	Load Paint application
*/
function loadApplication(id)
{
	var obj = document.getElementById(id);
	
	if (obj)
	{
		obj.style.display = 'block';
		
		var boxWidth = 823;
		var boxHeight = 623;
		
		var docwidth = 750;
		var realdocwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth;
		var docheight = document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);

		var xcoord = Math.round((docwidth - boxWidth) / 2);
		var ycoord = Math.round((docheight - boxHeight) / 2);
		
		if (ycoord < 0)
			ycoord = 0;
		
		var yy = document.all? truebody().scrollTop : pageYOffset;
		if (yy > 0)
			ycoord = ycoord + yy;

		setOverlay(realdocwidth, docheight, yy, docwidth);

		obj.style.left = xcoord+"px";
		obj.style.top = ycoord+"px";
	}
	
	return false;
}
//---------------------------------------------------------------

function setOverlay(dw, dh, scroll_top, contentW)
{
	var obj = document.getElementById('overlay');
	
	if (dw && dh && obj)
	{
		var xcoord = 0;
		var ycoord = 0;

		if (dw > contentW)
			xcoord = Math.round((contentW - dw) / 2);

		obj.style.display = 'block';
		obj.style.width = dw + 'px';
		obj.style.height = dh + scroll_top + 'px';
		obj.style.left = xcoord+"px";
		obj.style.top = ycoord+"px";
	}
}
//---------------------------------------------------------------

function hideOverlay()
{
	var obj = document.getElementById('overlay');
	
	if (obj)
		obj.style.display = 'none';
}
//---------------------------------------------------------------

function hideApplication(id) {
	document.getElementById(id).style.display = 'none';
	hideOverlay();
	
	return false;
}
//---------------------------------------------------------------

function clearField(obj)
{
	if (obj)
	{
		if (obj.value == 'password')
			obj.value = '';
	}
}
//---------------------------------------------------------------

function checkField(obj)
{
	if (obj)
	{
		if (obj.value == '')
			obj.value = 'password';
	}
}
//---------------------------------------------------------------
