function writeCookie() 
{
  var today = new Date();
  var the_date = new Date("December 31, 2099");
  var the_cookie_date = the_date.toGMTString();
  var the_cookie = "myWidth="+ window.screen.availWidth;
  var the_cookie = the_cookie + ";expires=" + the_cookie_date;
  document.cookie = the_cookie;
}

function check_mail(s)
{
  var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

  return filter.test(s);
}

function HasNumeric(sText)
{
  var ValidChars = "0123456789";
  var HasNumber=false;
  var Char;

  for (i = 0; i < sText.length && HasNumber == false; i++) {
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) > 0) {
      HasNumber = true;
    }
  }

  return HasNumber;
}

function IsNumeric(sText)
{
  var ValidChars = "0123456789";
  var IsNumber=true;
  var Char;

  for (i = 0; i < sText.length && IsNumber == true; i++) {
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }

  return IsNumber;
}

function floatval(mixed_var)
{
  mixed_var += "";
  mixed_var = mixed_var.replace(/€/g, "");
  mixed_var = mixed_var.replace(/ /g, "");
  mixed_var = mixed_var.replace(/&nbsp;/g, "");
  mixed_var = mixed_var.replace(/,/g, ".");

  return (parseFloat(mixed_var) || 0);
}

function number_format(number, decimals, dec_point, thousands_sep)
{
  var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
  var d = dec_point == undefined ? "." : dec_point;
  var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
  var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

function validate(form_id)
{
  var error = false;
  var error_message = "";

  $('#' + form_id + ' .text.required, #' + form_id + ' textarea.required, #' + form_id + ' select.required, #' + form_id + ' .file.required').each(
    function(index) {
      if ($(this).val() == "") {
        error_message += "* " + $(this).attr("title") + "\n";
        error = true;
      }
    }
  );

  $('#' + form_id + ' .checkbox.required').each(
    function(index) {
      if ($(this).is(':checked') == false) {
        error_message += "* " + $(this).attr("title") + "\n";
        error = true;
      }
    }
  );

  if ($('#' + form_id + ' .captcha').is(':visible'))
    if ($('#' + form_id + ' .captcha input').val() == "") {
      error_message += "* Nezadali ste kontrolný text";
      error = true;
    } else if ($('#' + form_id + ' .captcha input').css('background-color') == 'rgb(255, 221, 221)' || $('#' + form_id + ' .captcha input').css('background-color') == '#fdd') {
      error_message += "* Zadali ste nesprávny kontrolný text";
      error = true;
    }

  if (error)
    alert(error_message);

  return !error;
}

function captcha_new(el)
{
  new Date().getTime();
  var timestamp = Number(new Date());
  $(el).attr('src', '/com_captcha.php?' + timestamp);
}

function captcha_verify(el)
{
  $.ajax({ url: '/com_captcha_verify.php?captchavalue=' + $(el).val(), success: function(response) {
    if (response == 1)
      $(el).css('background', '#dfd');
    else
      $(el).css('background', '#fdd');
  }});
}

var submitted = false;
	function check_form() {
	  var error = 0;
	  var error_message = "Pri vyplnení formulára došlo k chybe!\nProsím, opravte nasledujúce skutočnosti:\n\n";
	
	  if(submitted){ 
	    alert( "Tento formulár už bol odoslaný. Stlačte, prosím, ok a vyčkajte, kým sa stránka nespracuje."); 
	    return false; 
	  }
	   
	  var kontakt = document.reservation.elements['content[Kontakt]'].value;
 
    	if (kontakt == '' || kontakt.length < 2) {
	      error_message = error_message + "* Neuviedli ste kontakt na Vás.\n";
	      error = 1;
	    }
	
	  if (error == 1) { 
	    alert(error_message); 
	    return false; 
	  } else { 
	    submitted = true; 
	    return true; 
	  } 
	}

$(document).ready(function() {
  $("a.lightbox").lightBox();
});
