﻿/**
 *  BY LUKAS JEVICKY, 2009
 *  homepage: www.jevicky.cz [czech]
 *  depends on jQuery 1.3.x +
 */
  var DOMAIN_NAME = "";
  
  $(document).ready(function() {

    $("a[rel=mm]").fancybox({
	  'transitionIn'		: 'none',
	  'transitionOut'		: 'none',
	  'titlePosition' 	: 'over',
	  'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
	    return '<span id="fancybox-title-over">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	  }
	});
	
	$("#podminky").fancybox({
	  'titlePosition'		: 'inside',
	  'transitionIn'		: 'none',
	  'transitionOut'		: 'none',
	  'autoDimensions'	    : false,
	  'width'				: '75%',
	  'height'				: '75%'
	});

  });

  function requestVotes(getPage, divName) {
    $("#"+divName).load(getPage); 
    return false;
  }


  function requestData(getPage, divName) {
    $("#"+divName).load(getPage, function() {
      $("#"+divName).show();
    } );
    return false;
  }

  function odeslat() {
    var jmeno = encodeURIComponent(document.getElementById('jmeno').value);
	var prijmeni = encodeURIComponent(document.getElementById('prijmeni').value);
    var email = document.getElementById('email').value;
	var telefon = document.getElementById('telefon').value;
    var zprava = encodeURIComponent(document.getElementById('zprava').value);
    // test validace emailu
    var vyraz = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    if(vyraz.test(email) == false) {
      alert("Chybný tvar e-mailu. Prosím, zkontrolujte e-mailovou adresu a zkuste zprávu odeslat znovu.");
    } else if(trim(document.getElementById('jmeno').value) == '') {
	  alert("Prosíme o vyplnění Vašeho jména");
	} else if(trim(document.getElementById('prijmeni').value) == '') {
	  alert("Prosíme o vyplnění Vašeho přijmení");
	} else if(trim(document.getElementById('zprava').value) == '') {
	  alert("Prosíme o vyplnění Vašeho dotazu");
	} else {
      // zpracovani emailu z formulare, nasledne zobrazeni hlasky
      $("#zpracujZpravu").load(DOMAIN_NAME+"/inc/ajx/send_email.php?jmeno="+jmeno+"&prijmeni="+prijmeni+"&telefon="+telefon+"&email="+email+"&zprava="+zprava, function() {
      //  alert("Váš e-mail byl uložen. Děkujeme a přejeme příjemný den.");
      });
    }

  }
  
  function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
  }
  
  function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
  }
  
  function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
  }
