var slideshow_time = 5000;



var divs = new Array();
var next;
var actual;

var gal_divs = new Array();
var gal_menu_divs = new Array();
var gal_actual = 0;
var gal_a_width = 0;

var fg_scroll_to;



var divy = new Array();

//  slideshow functions

function get_divs()
{
a_divs = document.getElementById('slideshow').childNodes;

if(navigator.appName == "Microsoft Internet Explorer")
{
for(i=0; i<a_divs.length; i++)
{
if(a_divs[i].nodeName == "DIV")
{
divs[divs.length] = a_divs[i];
divs[divs.length - 1].style.filter = "alpha(opacity=0)";
divs[divs.length - 1].style.zIndex = 0;

div_img = divs[divs.length - 1].getElementsByTagName("img");

if(div_img[0].offsetHeight < 158)
{
div_img_top = Math.floor((158 - div_img[0].offsetHeight) / 2);
div_img[0].style.top = div_img_top + "px";
}
}
}
divs[0].style.filter = "alpha(opacity=100)";
divs[0].style.zIndex = 1;
}

else
{
for(i=0; i<a_divs.length; i++)
{
if(a_divs[i].nodeName == "DIV")
{
divs[divs.length] = a_divs[i];
divs[divs.length - 1].style.opacity = 0;

div_img = divs[divs.length - 1].getElementsByTagName("img");

if(div_img[0].offsetHeight < 158)
{
div_img_top = Math.floor((158 - div_img[0].offsetHeight) / 2);
div_img[0].style.top = div_img_top + "px";
}
}
}
divs[0].style.opacity = 1;
divs[0].style.zIndex = 1;
}
}





function slide_div(div_id)
{
next = div_id + 1;
actual = div_id;

if(next >= divs.length)
{
next = 0;
}

if(navigator.appName == "Microsoft Internet Explorer")
{
for(i=0; i<divs.length; i++)
{
divs[i].style.filter = "alpha(opacity=0)";
divs[i].style.zIndex = 0;
}
}

else
{
for(i=0; i<divs.length; i++)
{
divs[i].style.opacity = 0;
divs[i].style.zIndex = 0;
}
}

fade_div(next, 0);
}




function fade_div(div_id, opc)
{
if(navigator.appName == "Microsoft Internet Explorer")
{
a_opc = opc + 5;
}
else
{
a_opc = opc + 0.05;
}

next = div_id;
divs[next].style.zIndex = 1;


if(navigator.appName == "Microsoft Internet Explorer")
{
if(a_opc <= 100)
{
divs[next].style.filter = "alpha(opacity="+a_opc+")";
divs[next].style.zIndex = 1;

f_opc = 100 - a_opc;
divs[actual].style.filter = "alpha(opacity="+f_opc+")";

window.setTimeout("fade_div(next, a_opc);", 30);
}

else
{
divs[next].style.filter = "alpha(opacity=100)";
divs[next].style.zIndex = 1;
divs[actual].style.filter = "alpha(opacity=0)";

window.setTimeout("slide_div(next);", slideshow_time);
}
}

else
{
if(a_opc <= 1)
{
divs[next].style.opacity = a_opc;
divs[next].style.zIndex = 1;
divs[actual].style.opacity = 1 - a_opc;

window.setTimeout("fade_div(next, a_opc);", 30);
}

else
{
divs[next].style.opacity = 1;
divs[actual].style.opacity = 0;
window.setTimeout("slide_div(next);", slideshow_time);
}
}
}




//  gallery functions

function gal_get_divs()
{
if(gal_a_divs = document.getElementById('prevs_id'))
{
gal_a_divs = document.getElementById('prevs_id').childNodes;

for(i=0; i<gal_a_divs.length; i++)
{
if(gal_a_divs[i].nodeName == "DIV")
{
gal_divs[gal_divs.length] = gal_a_divs[i];
}
}
gal_divs[0].style.display = "block";


gal_menu_a_divs = document.getElementById('foto_menu').childNodes;

for(i=0; i<gal_menu_a_divs.length; i++)
{
if(gal_menu_a_divs[i].nodeName == "DIV")
{
gal_menu_divs[gal_menu_divs.length] = gal_menu_a_divs[i];
}
}

gal_slide_div(0);
}
}



function gal_slide_div(gal_div_id)
{
gal_actual = gal_div_id;

for(i=0; i<gal_divs.length; i++)
{
gal_divs[i].style.display = "none";
gal_divs[i].style.left = "0px";
gal_divs[i].style.zIndex = 0;
}

gal_divs[gal_div_id].style.display = "block";
gal_divs[gal_div_id].style.zIndex = 1;


a_gal_img = gal_divs[gal_div_id].childNodes;

gal_img = new Array();

for(i=0; i<a_gal_img.length; i++)
{
if(a_gal_img[i].nodeName == "A")
{
gal_img[gal_img.length] = a_gal_img[i];
}
}


gal_a_width = 118 * (gal_img.length + 1);

gal_divs[gal_div_id].style.width = gal_a_width + "px";


for(i=0; i<gal_menu_divs.length; i++)
{
gal_menu_divs[i].removeAttribute("class");
}

gal_menu_divs[gal_div_id].setAttribute("class", "active");
}






//  gallery scroll

function scroll_fotog(direction)
{
window.clearInterval(fg_scroll_to);

prev_element = gal_divs[gal_actual];
x_pos = prev_element.offsetLeft;

if(direction == 1)
{
if(x_pos >= 0)
{
prev_element.style.left = 0;
}
else
{
prev_element.style.left = x_pos + 40 + "px";
fg_scroll_to = window.setTimeout("scroll_fotog(1);", 25);
}
}
else
{
if(x_pos < - gal_a_width + 603)
{
prev_element.style.left = - gal_a_width + 603 + "px";
}
else
{
prev_element.style.left = x_pos - 40 + "px";
fg_scroll_to = window.setTimeout("scroll_fotog(0);", 25);
}
}
}



function stop_scroll()
{
window.clearInterval(fg_scroll_to);
}




//  ***

function min_height()
{
if(document.getElementById('content_left') && document.title.indexOf("Úvod") == -1 && document.title.indexOf("Aktuality") == -1)
{
cl_divs = document.getElementById('content_left').getElementsByTagName("div");
if(cl_divs[1].offsetHeight < 482)
{
cl_divs[1].style.height = 482 + "px";
}
}
}




function clear_form(el_id, form_string)
{
var element = document.getElementById(el_id);
if(element.value == form_string)
{
element.value = "";
}
}




function reset_form(el_id, form_string)
{
var element = document.getElementById(el_id);
if(element.value == "")
{
element.value = form_string;
}
}




function clear_form_pass(el_id, form_string)
{
var element = document.getElementById(el_id);

if(navigator.appName != "Microsoft Internet Explorer")
{
element.setAttribute("type", "password");
}

if(element.value == form_string)
{
element.value = "";
}
}




function reset_form_pass(el_id, form_string)
{
var element = document.getElementById(el_id);
if(element.value == "")
{
element.value = form_string;

if(navigator.appName != "Microsoft Internet Explorer")
{
element.setAttribute("type", "text");
}
}
}



function check_form_data(value, string)
{
if(value == string || value == "")
{
return false;
}
else
{
return true;
}
}




function send_info_mail()
{
var XMLhttp_cont = false;
var send_data = true;


var kontakt_id = document.getElementById('mail_kontakt_id').value;
var meno_id = document.getElementById('mail_meno_id').value;
var dopyt_id = document.getElementById('mail_dopyt_id').value;
var as_id = document.getElementById('mail_as_id').value;

var post = kontakt_id + "[###]" + meno_id + "[###]" + dopyt_id + "[###]" + as_id;


if(check_form_data(kontakt_id, "Váš e-mail") == false)
{
send_data = false;
alert("Zadali ste nesprávny e-mail.");
return false;
}

if(kontakt_id.indexOf("@") == -1 || kontakt_id.indexOf(".") == -1)
{
send_data = false;
alert("Zadali ste nesprávny e-mail.");
return false;
}

if(check_form_data(meno_id, "Vaše meno") == false)
{
send_data = false;
alert("Zadali ste nesprávne meno.");
return false;
}

if(check_form_data(dopyt_id, "Sem napíšte Vašu otázku alebo požiadavku") == false)
{
send_data = false;
alert("Zadali ste nesprávny dopyt.");
return false;
}


if(send_data == true)
{
if(window.XMLHttpRequest)
{
XMLhttp_cont = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLhttp_cont = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert("Your browser could not create XMLHttpRequest.");
}

if(XMLhttp_cont)
{
XMLhttp_cont.open("POST", "ajax/ajax_mail_contact.php", true);
XMLhttp_cont.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
XMLhttp_cont.onreadystatechange = function()
{
if(XMLhttp_cont.readyState == 4 && XMLhttp_cont.status == 200)
{
if(XMLhttp_cont.responseText == "Vaša požiadavka bola odoslaná.")
{
document.getElementById('mail_kontakt_id').value = "Váš e-mail";
document.getElementById('mail_meno_id').value = "Vaše meno";
document.getElementById('mail_dopyt_id').value = "Sem napíšte Vašu otázku alebo požiadavku";
document.getElementById('mail_as_id').value = "Overovací kód";
}
alert(XMLhttp_cont.responseText);
}
}
XMLhttp_cont.send("post="+post);
}

else
{
alert("Error");
}
}
}



function rezervuj(kurt, den, hod)
{
post = kurt + "[###]" + den + "[###]" + hod;


var XMLhttp = false;

if(window.XMLHttpRequest)
{
XMLhttp = new XMLHttpRequest();
}

else if(window.ActiveXObject)
{
XMLhttp = new ActiveXObject("Microsoft.XMLHttp");
}

else
{
alert("Your browser could not create XMLHttpRequest.");
}

if(XMLhttp)
{
XMLhttp.open("POST", "ajax/ajax_rezervuj_confirm.php", true);
XMLhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
XMLhttp.onreadystatechange = function()
{
if(XMLhttp.readyState == 4 && XMLhttp.status == 200)
{
if(window.confirm(XMLhttp.responseText))
{
rezervuj_confirmed(post)
}
}
}

XMLhttp.send("post="+post);
}

else
{
alert("Error");
}
}



function rezervuj_confirmed(post)
{
var XMLhttp = false;

if(window.XMLHttpRequest)
{
XMLhttp = new XMLHttpRequest();
}

else if(window.ActiveXObject)
{
XMLhttp = new ActiveXObject("Microsoft.XMLHttp");
}

else
{
alert("Your browser could not create XMLHttpRequest.");
}

if(XMLhttp)
{
XMLhttp.open("POST", "ajax/ajax_rezervuj.php", true);
XMLhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
XMLhttp.onreadystatechange = function()
{
if(XMLhttp.readyState == 4 && XMLhttp.status == 200)
{
document.getElementById('ajax_output').innerHTML = XMLhttp.responseText;
}
}

XMLhttp.send("post="+post);
}

else
{
alert("Error");
}
}




function produkty_change()
{
var XMLhttp_pl = false;

pid = document.getElementById('produkty_sel_id').value;

if(window.XMLHttpRequest)
{
XMLhttp_pl = new XMLHttpRequest();
}

else if(window.ActiveXObject)
{
XMLhttp_pl = new ActiveXObject("Microsoft.XMLHttp");
}

else
{
alert("Your browser could not create XMLHttpRequest.");
}

if(XMLhttp_pl)
{
XMLhttp_pl.open("POST", "ajax/produkty_change.php", true);
XMLhttp_pl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
XMLhttp_pl.onreadystatechange = function()
{
if(XMLhttp_pl.readyState == 4 && XMLhttp_pl.status == 200)
{
document.getElementById('ajax_output').innerHTML = XMLhttp_pl.responseText;
}
}

XMLhttp_pl.send("pid="+pid);
}

else
{
alert("Error");
}
}




function cancel_reservation(rid)
{
if(window.confirm("Naozaj si prajete zrušiť túto rezerváciu?"))
{
var XMLHttp = false;

if(window.XMLHttpRequest)
{
XMLHttp = new XMLHttpRequest();
}

else if(window.ActiveXObject)
{
XMLHttp = new ActiveXObject("Microsoft.XMLHttp");
}

else
{
alert("Your browser could not create XMLHttpRequest.");
}

if(XMLHttp)
{
XMLHttp.open("POST", "ajax/cancel_reservation.php", true);
XMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
XMLHttp.onreadystatechange = function()
{
if(XMLHttp.readyState == 4 && XMLHttp.status == 200)
{
document.getElementById('ajax_output').innerHTML = XMLHttp.responseText;
}
}

XMLHttp.send("rid="+rid);
}

else
{
alert("Error");
}
}
}




/****************************************************************************/


window.onload = function()
{
min_height();
get_divs();
gal_get_divs();


if(divs.length > 1)
{
window.setTimeout("slide_div(0);", slideshow_time);
}

if(navigator.appName != "Microsoft Internet Explorer")
{
if(document.getElementById('id_pass'))
{
document.getElementById('id_pass').setAttribute("type", "text");
}
}
}
