var pocz = document.getElementById('pocz').innerHTML;

function clickedOutsideElement(elemId, evt) 
{
	var theElem = '';
	if(window.event)
	theElem = getEventTarget(window.event);
	else theElem = getEventTarget(evt);

	while(theElem != null) 
	{
		if(theElem.id == elemId)
		return false;
		theElem = theElem.offsetParent;
	}

	return true;
}

function getEventTarget(evt) 
{
	var targ = (evt.target) ? evt.target : evt.srcElement;

	if(targ != null) 
	{
		if(targ.nodeType == 3)
		targ = targ.parentNode;
	}

	return targ;
}

function resizePlayer()
{
	resized = 0;
	if (gid('playerDiv').style.width == '930px')
	{
		gid('playerDiv').style.width = '540px';
		gid('playerDiv').style.height = '430px';
		resized = 1;
	}	
	if (gid('playerDiv').style.width == '910px')
	{
		gid('playerDiv').style.width = '930px';
		gid('playerDiv').style.height = '700px';	
	}
	if (gid('playerDiv').style.width == '650px')
	{	
		gid('playerDiv').style.width = '910px';
		gid('playerDiv').style.height = '580px';
	}
	if (gid('playerDiv').style.width == '540px' && resized == 0)
	{
		gid('playerDiv').style.width = '650px';
		gid('playerDiv').style.height = '500px';
	}
}

function gid(id)
{
	return document.getElementById(id);
}

function pobierz(string,start,end)
{
	var t = string.split(start);
	var t2 = t[1].split(end);
	return t2[0];
}

function toggleMenu(divID,imgID)
{
	if (divID == 'mycustomscroll')
	{
		if (gid('hentaiList').style.visibility == 'visible')
		{
			gid('hentaiList').style.visibility = 'hidden';
		}else
		{
			gid('hentaiList').style.visibility = 'visible';		
		}
		if (gid('mangaList').style.visibility == 'visible')
		{
			gid('mangaList').style.visibility = 'hidden';
		}else
		{
			gid('mangaList').style.visibility = 'visible';		
		}
	}
	if (divID == 'mycustomscroll3')
	{
		if (gid('hentaiList').style.visibility == 'visible')
		{
			gid('hentaiList').style.visibility = 'hidden';
		}else
		{
			gid('hentaiList').style.visibility = 'visible';		
		}
	}	
	toggleDiv(divID);
	toggleDiv(imgID);
}

function toggleDiv(id)
{
	if (gid(id).style.display != '')
	{
		if (gid(id).style.display == 'none')
		{
			gid(id).style.display = 'block';
		}else
		{
			gid(id).style.display = 'none';
		}
	}else
	{
		src = pobierz(gid(id).src,pocz,'.');
		ext = pobierz(gid(id).src,'.',' ');
		test = src.split('D');
		if (test.length == 1)
		{
			src = pobierz(gid(id).src,pocz,'U.');
			gid(id).src = pocz + src + 'D.png';
		}else
		{
			src = pobierz(gid(id).src,pocz,'D.');
			gid(id).src = pocz + src + 'U.png';
		}
	}	
}
			
function hideDiv(id)
{
	gid(id).style.display = 'none';
}

function showDiv(id)
{
	gid(id).style.display = 'block';
}

function changeValue(id,value)
{
	var val = document.getElementById(id).innerHTML * 1;
	val = val + (value * 1);
	document.getElementById(id).innerHTML = val;	
}

function moveDiv(id,dir)
{
	var movable = document.getElementById(id);
	if (dir == "up" || dir == "down")
	{
		if (dir == "up")
		{
			var temp = movable.style.top.split("px");
			var newT = (temp[0] * 1) - 9;
		}else
		{
			var temp = movable.style.top.split("px");
			var newT = (temp[0] * 1) + 9;		
		}
		
		movable.style.top = newT + 'px';
	}else
	{
		if (dir == "left")
		{
			var temp = movable.style.left.split("px");
			var newT = (temp[0] * 1) - 7;		
		}else
		{
			var temp = movable.style.left.split("px");
			var newT = (temp[0] * 1) + 7;
		}
		movable.style.left = newT + 'px';		
	}
}

function startUpload(l)
{
	document.getElementById('progress'+l).style.display='block';
	document.getElementById('form'+l).style.display='none';	
	checkUploadStatus();
}

function checkUploadStatus()
{
	content = document.getElementById('uploadI').contentWindow.document.body.innerHTML;
	if (content)
	{
		test = content.split("File uploaded");
		if (test[1])
		{
			load_url('progressD','control.php?mode=endUpload&value=1');
		}else
		{
			load_url('progressD','control.php?mode=endUpload&value=1');
		}
	}else
	{
	setTimeout("checkUploadStatus();",300);
	}
}

function showComments(id)
{
	loadUrl('fullComments','actions.php?id='+id+'&action=showComments');
}

function loadForm(tag,id)
{
	advAJAX.submit(document.getElementById(id), {
    onSuccess : function(obj) 
	{
		document.getElementById(tag).innerHTML = obj.responseText;
		if (tag == 'com')
		{
			showComments(document.getElementById('content_id').innerHTML);
		}
	},
    onError : function(obj) 
	{
		alert("Error: " + obj.status); 
	}
});
}

function loadUrl(tag,url)
{
	advAJAX.setDefaultParameters
	({

	    retry: 2,
	    retryDelay: 2000,


		onLoading : function(obj)
		{
			if (document.getElementById(obj.tag+'StandBy')) 
			{
				document.getElementById(obj.tag+'StandBy').style.display='block';
			}
		},

		onError : function(obj) 
		{ 
			alert("Error: " + obj.status); 
		},

		onSuccess : function(obj) 
		{
	        document.getElementById(obj.tag).innerHTML = obj.responseText;
			if (document.getElementById(obj.tag+'StandBy')) 
			{
				document.getElementById(obj.tag+'StandBy').style.display='none';
			}			
		}
	});
		
	advAJAX.get({ tag: tag, url: pocz+url});

}

function clearValue(id,value)
{
	if (document.getElementById(id).value == value)
	{
		document.getElementById(id).value = '';
	}	
}

function restoreValue(id,value)
{
	if (document.getElementById(id).value == '')
	{
		document.getElementById(id).value = value;
	}	
}

function submitError(what,id)
{	
	if (what == 'movie')
	{
		if (id)
		{
		
			load_url('notWorkingSpan','submit.php?id='+id+'&what='+what);

		}
	}
}

function star_hover(which)
{
	for (var i=0;i<which;i++)
	{
		document.getElementById('star'+i).src=pocz+'files/images/star_full-trans.png';
	}
}

function star_reset()
{
	for (var i=0;i<5;i++)
	{
		document.getElementById('star'+i).src=pocz+'files/images/star_blank-trans.png';
	}

}

function submitEnter(myfield,e)
{

	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	{
		myfield.form.submit();
		return false;
	}else return true;
}

function disableSelection(target)
{
	if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function()
	{
		return false
	}
	else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
	else //All other route (ie: Opera)
	target.onmousedown=function()
	{
		return false
	}
	
target.style.cursor = "default"
}

function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}