// JavaScript Document

/* AJAX Request */
	
	var xmlHttpReq;
	if(typeof XMLHttpRequest != 'undefined') 
	{
	  try 
	  {
		xmlHttpReq = new XMLHttpRequest();
	  } 
	  catch(e) 
	  {
		  try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
		  try {
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlHttpReq = false;
		  }
		 }
	  }
	}
	else
	{
	  try {
		  xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		  xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		  xmlHttpReq = false;
		}
	  }
	}
	
	function sendRequest(getOrPost, page, params)
	{
	  var strResult;
	  if(getOrPost.toUpperCase() == "POST")
	  {
		xmlHttpReq.open("POST", page, false);
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.send(params);
	  }
	  else
	  {
		xmlHttpReq.open("GET", page + "?" + params, false);
		xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpReq.send(null);
	  }
	  strResult = xmlHttpReq.responseText;
	  return strResult;
	}

	function goTo(page, type)
	{			
		if(type)
			document.getElementById('ref-box').innerHTML = sendRequest("POST", "ref_box.php", "sender=sendRequest&id=" + page +"&type=" + type);			
		else
			document.getElementById('ref-box').innerHTML = sendRequest("POST", "ref_box.php", "sender=sendRequest&id=" + page);
	}

/* Other */

function CheckInput(x){
	if(x.length < 3){
		alert("Pre vyhľadávanie musíte zadať minimálne 3 znaky!");
		return false;
	}else{
		return true;
	}
}

function checkEmail(adresa)
{
	var pozice_zavinace = adresa.indexOf("@");
	if (pozice_zavinace < 0)
		return false;
	var cast_pred_zavinacem = adresa.substring(0,pozice_zavinace);
	var cast_po_zavinaci = adresa.substring(pozice_zavinace+1,adresa.length);
	if (cast_po_zavinaci.indexOf("@") >= 0)
		return false;
	if (cast_pred_zavinacem.length <= 0)
		return false;
	if (cast_po_zavinaci.length <= 0)
		return false;
	var pozice_posledni_tecky = cast_po_zavinaci.lastIndexOf(".");
	if (pozice_posledni_tecky < 0)
		return false;
	var pocet_znaku_za_posledni_teckou = cast_po_zavinaci.length - pozice_posledni_tecky - 1;
	if (pocet_znaku_za_posledni_teckou < 2  ||  pocet_znaku_za_posledni_teckou > 3)
		return false;
	var pozice_dvou_tecek_vedle_sebe = adresa.indexOf("..");
	if (pozice_dvou_tecek_vedle_sebe >= 0)
		return false;
	if (cast_pred_zavinacem.charAt(0) == "."  ||  cast_pred_zavinacem.charAt(cast_pred_zavinacem.length-1) == ".")
		return false;
	if (cast_po_zavinaci.charAt(0) == "."  ||  cast_po_zavinaci.charAt(cast_po_zavinaci.length-1) == ".")
		return false;
	return true;
}

function SubmitBulletinForm(id){
	if(!checkEmail(id.mail.value)){
		alert('Zadaná adresa nie je platnou emailovou adresou!');
		return false;
	}
	else{
		return true;
	}
}

function CheckContactForm(id){
	if(id.cname.value == ''){
		alert('Položka meno je povinná, prosím vyplnte ju!');
		id.cname.focus();
		return false;
	}else if(!checkEmail(id.cemail.value)){
		alert('Zadaná emailová adresa nie je platnou adresou!');
		id.cemail.focus();
		return false;
	}else if(id.ccontent.value == ''){
		alert('Text správy je povinný, prosím vyplnte ho!');
		id.ccontent.focus();
		return false;
	}	
	else if(id.rsecurity.value == ''){
		alert('Prosím prepíšte overovací kód!');
		id.rsecurity.focus();
		return false;
	}
	else{
		return true;
	}
}

var count = 0;
var intID;

function showProductNav(){
	var id = document.getElementById('nav_product_item');
	id.style.display = 'block'	
	window.clearInterval(intID);
	count = 0;
}

function Clear(){
	window.clearInterval(intID);
	count = 2;
}

function hideProductNav(){
	
	if(count == 1){
		var id = document.getElementById('nav_product_item');
		id.style.display = 'none'
		Clear();
		count = 0;
	}else{
		window.clearInterval(intID);
		intID = window.setInterval("hideProductNav()", 1000);
		count = 1;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

function findPos(obj)
{
	var left = findPosX(obj);
	var top = findPosY(obj);
	
	return [left , top];
}

function thumbShow(pid, id, posx, posy){
	var obj = document.getElementById(id);
	var pos = findPos(pid);
	obj.style.left = (pos[0] + posx) + 'px';
	obj.style.top = (pos[1] + posy) + 'px';
	obj.style.display = 'block';
}

function thumbHide(id){
	var obj = document.getElementById(id);
	obj.style.display = 'none';
}

function show(id)
{
	$(id).appear({ duration: 0.5 });

}

function hide(id)
{
	//$('login_box').style.display = 'block';
	$(id).fade({ duration: 0.5 });

}