http_request = false;
domain = 'www.amatorek.pl';

function show_tip(e, v, text)
{
	if (v.title)
	{
		var div = document.createElement("div");
		div.className = "layer_tip";
		div.innerHTML = text;
		v.title = '';
		v.move = function(e)
		{
			e = e || event;
				
			if (document.documentElement.scrollTop)
				scrollTop = document.documentElement.scrollTop; 
			else 
				scrollTop = document.body.scrollTop; 
				
			div.style.left = e.clientX + 20 + 'px';
			div.style.top = e.clientY - 40 + (scrollTop) + 'px';
		}
		v.move(e);
		document.body.appendChild(div);
		v.onmousemove = function(e)
		{
			v.move(e)
		}
		v.onmouseout = function(e)
		{
		  v.title = 'true';
		  document.body.removeChild(div);
		}
	}
}

function show_hide(id)
{
	obj = document.getElementById(id);
	
	if (obj.style.display == 'none')
		obj.style.display = 'block';
	else
		obj.style.display = 'none';
}

function show (id)
{
	document.getElementById(id).style.display = 'block';
}


function hide (id)
{
	document.getElementById(id).style.display = 'none';
}


function ajax_connect()
{
	if (window.XMLHttpRequest) 
	{ 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
			http_request.overrideMimeType('text/plain');
	} 
	else 
		if (window.ActiveXObject)
		{
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) 
			{
				try
				{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {}
			}
		}
}


function ajax_check_status()
{
	if(http_request.readyState == 4 && http_request.status == 200)
		return true;
	else
		return false;
}


function ajax_check_hash(hash)
{
	ajax_connect();
	
	http_request.onreadystatechange = function()
	{
		if (ajax_check_status())
			if (http_request.responseText == 0)
				document.getElementById('upload_hash').innerHTML = '<img src="/gfx/no.png" />';
			else
			{
				document.getElementById('upload_hash').innerHTML = '<img src="/gfx/yes.png" />';
				document.getElementById('submit_upload').disabled = false;
			}
	}

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=check_hash&hash=' + hash, true);
	http_request.send(null);
}

function ajax_login_check(login)
{
	ajax_connect();
	
	http_request.onreadystatechange = function()
	{
		if (ajax_check_status())
		{
			switch (http_request.responseText)
			{
				case '0':
					response = '<img src="/gfx/no.png" /> login zawiera niedozwolone znaki';
				break;
				
				case '1':
					response = '<img src="/gfx/yes.png" />';
				break;
				
				case '2':
					response = '<font style="color:red;"><img src="/gfx/no.png" /> login jest juz zajety</font>';
				break;
			}
			document.getElementById('register_login').innerHTML = response;
		}
	}

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=login_check&login=' + login, true);
	http_request.send(null);
}

function ajax_passwd_check(passwd)
{
	ajax_connect();
	
	http_request.onreadystatechange = function()
	{
		if (ajax_check_status())
			if (http_request.responseText == 0)
				document.getElementById('passwd_status1').innerHTML = '<img src="/gfx/no.png" />';
			else
				document.getElementById('passwd_status1').innerHTML = '<img src="/gfx/yes.png" />';
	}

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=passwd_check&passwd=' + passwd, true);
	http_request.send(null);
}


function ajax_add_favorite(id)
{
	ajax_connect();
	
	http_request.onreadystatechange = function()
	{
		if (ajax_check_status())
		{
			obj = document.getElementById('add_favorite');
			
			switch (http_request.responseText)
			{
				case '0':
					obj.innerHTML = '<font style="color:red;"><img src="/gfx/no.png" /> Ten film znajduje sie juz w Twojej liscie ulubionych</font>';
				break;
				
				case '1':
					obj.innerHTML = '<font style="color:green;"><img src="/gfx/yes.png" /> film zostal dodany do Twojej listy ulubionych.</font>';
				break;
				
				case '2':
					obj.innerHTML = '<font style="color:red;"><img src="/gfx/no.png" /> Przekroczyles limit listy ulubionych.</font>';
				break;
			}
		}
	}

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=add_favorite&id=' + id, true);
	http_request.send(null);
}

function ajax_rating(id, rate)
{
	ajax_connect();
	
	http_request.onreadystatechange = function()
	{
		if (ajax_check_status())
			if (http_request.responseText != 0)
			{
				document.getElementById('map_rating').innerHTML = '';
				document.getElementById('rating_img').useMap = '';
				document.getElementById('rating_img').src = '/gfx/rating/' + rate + '.png';
				document.getElementById('rating_status').innerHTML = 'Glos zostal oddany prawidlowo!';
			}
	}

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=rating&id=' + id + '&rate=' + rate, true);
	http_request.send(null);
}


function ajax_email_check(email)
{
	ajax_connect();
	
	http_request.onreadystatechange = function()
	{
		if (ajax_check_status())
			if (http_request.responseText == 0)
				document.getElementById('register_email').innerHTML = '<span style="color:red;"><img src="/gfx/no.png" /> adres email jest nieprawidlowy!</span>';
			else
				document.getElementById('register_email').innerHTML = '<img src="/gfx/yes.png" />';
	}

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=email_check&email=' + email, true);
	http_request.send(null);
}


function start_thumb(hash) 
{
	thumb = new Array();
	
	var i = 1;
	var d = 0;
	
	thumb[i + 1] = new Image;
	thumb[i + 1].src = 'http://content.amatorek.pl/' + hash + '/' + (i + 1) + '.jpg';

	interval_id = setInterval(
					  function()
					  { 
						  i++; 
						  
						  if (d == 0)
						  {
							  if (thumb[i].width == 0)
							  {
									d = i - 1;
									i = 1;
							  }
							  else
							  {  
								  thumb[i + 1] = new Image;
								  thumb[i + 1].src = 'http://content.amatorek.pl/' + hash + '/' + (i + 1) + '.jpg';
							  }
							  
						  }
						  else
							  if (i > d)
							  	i = 1;

						  document.getElementById('thumb' + hash).src = thumb[i].src; 
					  }
				  , 1000);
}

function url(order) 
{
	var gourl = order.options[order.selectedIndex].value; 
	window.self.location.href = gourl;
}


function stop_thumb(hash)
{
	clearInterval(interval_id);
	document.getElementById('thumb' + hash).src = 'http://content.amatorek.pl/'+ hash +'/3.jpg';
}


function online()
{
	ajax_connect();

	http_request.open('GET', 'http://' + domain + '/func/ajax.php?mode=online', true);
	http_request.send(null);	
}


function change_rating (id)
{
	var status;
	document.getElementById('rating_img').src = '/gfx/rating/' + id + '.png';
	
	switch (id)
	{
		case 0: status = 'Jak bardzo zadowolił Cię ten materiał?'; break;
		case 1: status = 'Całkowita porażka'; break;
		case 2: status = 'Minimalne pobudzenie'; break;
		case 3: status = 'Przyjemne uczucie'; break;
		case 4: status = 'Podniecony'; break;
		case 5: status = 'Orgazm!'; break;
	}
	
	document.getElementById('rating_status').innerHTML = status;
}

function check_adult (check)
{
	if (check != 1)
document.getElementById('layout').innerHTML = '<div style="width:515px; height:352px; background-image:url(\'/gfx/intro.png\'); background-repeat:no-repeat; margin:100px auto;"><div style="position:absolute; width:500px; margin:95px 0 0 7px;"><div style="font-size:20px; font-weight:bold; text-align:center;">UWAGA!</div><p style="font-size:15px; text-align:center; margin:5px 10px;">Serwis <strong>amatorek.pl</strong> zawiera treści o tematyce erotycznej róznego typu i przeznaczony jest <span style="text-decoration:underline;">tylko i wyłącznie</span> dla osób pelnoletnich (powyzej 18 roku zycia)!</p><p style="text-align:justify; margin:10px 0 15px 0; border:1px solid #F7B1C5; padding:3px;">Jeśli nie ukonczyłeś 18 roku życia, nie chcesz oglądać tego typu treści lub jest to niezgodne z prawem Twojego kraju, w którym znajdujesz się w tej chwili, nie wolno Ci wchodzić dalej! Wchodząc dalej oświadczasz, że jesteś osobą pełnoletnią, chcesz oglądać treści o tematyce erotycznej z własnej, nie przymuszonej woli oraz odbiór tych treści nie został Ci w żaden sposób narzucony.</p><p style="margin-left:380px; font-size:10px;">© amatorek.pl 2007-2009</p><div style="margin-top:18px; font-size:24px; font-weight:bold; text-align:center; letter-spacing:2px;"><a href="?enter" style="color:#fff; padding:2px 130px;">WCHODZĘ ><span style="text-decoration:blink;">></span>></a></div></div></div><div style="display:none;" id="time_counter"></div>';
	
}

setInterval("online()", 30000);
