// 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 });

}

$(document).ready(function () {

        if($("#input_pwd").val() == 'heslo') {
            //alert($("#input_pwd").attr('type'));
        }

        $("#search_string").focus(function() {
            var val = $(this).val();            
            if(val == 'hµadané slovo') {
                $(this).val('');
            }
        });

        $("#search_string").blur(function() {
            var val = $(this).val();
            if(val == '') {
                $(this).val('hµadané slovo');
            }
        });
        
        $("#input_login").focus(function() {            
            var val = $(this).val();            
            if(val == 'meno') {                
                $(this).val('');
            }
        });

        $("#input_login").blur(function() {
            var val = $(this).val();
            if(val == '') {
                $(this).val('meno');
            }
        });

        $("#input_pwd").focus(function() {
            var val = $(this).val();
            if(val == 'heslo') {
                $(this).val('');
            }
        });

        $("#input_pwd").blur(function() {
            var val = $(this).val();
            if(val == '') {
                $(this).val('heslo');
            }
        });

	$("#menu-main ul.sf-menu").superfish({
		animation: 		{height:'show'},
		speed: 			500,
		delay: 			400,
		autoArrows:    	false,
	    dropShadows:   	false
	});

//	$("a[rel^='lightbox']").prettyPhoto({
//		animationSpeed: 'fast', /* fast/slow/normal */
//		padding: 50, /* padding for each side of the picture */
//		opacity: 0.35, /* Value betwee 0 and 1 */
//		showTitle: true, /* true/false */
//		allowresize: true, /* true/false */
//		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
//		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
//		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
//		modal: false, /* If set to true, only the close button will close the window */
//		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
//		callback: function(){} /* Called when prettyPhoto is closed */
//	});
});
