/*********************************************
/	eShopSystem.cz
/
/
/
/**********************************************/


/**
 *		FACEBOOK - JavaScript SDK
 *		
 */
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/cs_CZ/all.js#xfbml=1&appId=278004092242162";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


/**
 *	je to element
 *	
 *	@param	string	element
 *	@return bool
 */
function _isElement(element){
    var result;
    if($(element).length > 0){ result = true; }else{ result = false }  
    return result;
}


/**
 *	Zjistí zda-li je email správný
 *
 *	@param	string	emailAddress
 */
function _checkEmail(emailAddress) {
	var pattern = 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);
	return pattern.test(emailAddress);
}


/**
 *	checkForm - trida pro inicializaci a kontrolu formulare
 *
 *
 *
 *
 */
var checkForm = {
	_validLength: function(object)
	{
			var isValid = true;
			if (object.attr("value").length < 1) {
				isValid = false;
				// Pridam objektu chybovou tridu
				object.addClass("error");
			} else {
				// Odeberu mu chybovou tridu
				object.removeClass("error");
			}
			return isValid;
	},
	_checkEmail: function(emailAddress)
	{
		var pattern = 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);
		return pattern.test(emailAddress);
	},
	_elementsNames: {
		"f_name":{0:"Jméno",1:"Nevyplněné jméno a příjmení."},
		"f_email":{0:"Email",1:"Špatně zadaný email."},
		"f_phone":{0:"Telefon",1:"Nevyplněný telefon."},
		"f_text":{0:"Text",1:"Nevyplněný text zprávy."},
	},
}
checkForm._check = function(obj,name)
{
	var data = obj.val();
	if(data == this._elementsNames[name][0])
		return this._elementsNames[name][1]+' ';
	switch(name)
	{
		case "f_email":
			if(!this._validLength(obj) && !this._checkEmail(data))
				return this._elementsNames[name][1]+' ';
		break;
		case "f_name":
		case "f_text":
		case "f_phone":
			if(!this._validLength(obj))
				return this._elementsNames[name][1]+' ';
		break;
		default:
			if(!this._validLength(obj))
				return "Nevyplnili jste všechna pole."+' ';
		break;
	}
	return false;
}
checkForm.checkSend = function(form,custom_names)
{
	var success = true;
	var errorText = "";
	var thiss = this;	
	var arr_names = $.extend(this._elementsNames,($.isPlainObject(custom_names))?custom_names:{});
	
	$.each(arr_names,function(i,e){
		$(form+" ."+i).val(e[0]);
		$(form+" ."+i).focusin(function() {
			if($(this).val()==e[0])
			{
				$(this).val("");
				$(this).css('color','black');
			}
		});
		$(form+" ."+i).focusout(function() {
			if($(this).val()=="")
			{
				$(this).val(e[0]);
				$(this).css('color','#7F7F7F');
			}
		});
	});
	
	$(form).submit(function() {
		success = true;
		errorText = "";
		$.each(arr_names,function(i,e){
			$(form+" ."+i).each(function(){
				ret = thiss._check($(this),i);
				if(ret != false)
				{
					success = false;
					errorText += ret;
				}
			});
		});

		if (success)
			$(".hlaska_green").animate({"bottom" : "0"},400,function() {});				
		else {
			if (!_isElement(".hlaska_red")) {
				$('body').append('<div class="hlaska_red"><div class="centerwrapper"><p id="error-text">'+ errorText +'</p></div></div>');
				$(".hlaska_red").animate({"bottom" : "0"},400,function() {});
			} else {
				$("#error-text").text(errorText);
				$(".hlaska_red").animate({"bottom" : "0"},400,function() {});
			}
			
			$(".hlaska_red").click(function(){
				$(".hlaska_red").animate({"bottom" : "-61"},400,function() {});
			});	
		}
		
		return success;
    });
};


/**
 *	var_dump - PHP ekvivalent
 *
 *	@param	object	obj
 *
 */
function var_dump(obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";
    }
    alert(out);
    var pre = document.createElement('pre');
    pre.innerHTML = out;
    document.body.appendChild(pre)
}


/**
 *	Vytvori z elementu slider
 *
 *	@param	string	element_a
 *	@param	string	element_b
 *	@param	int		width
 *	@param	int		step
 */
function _makeSlider(element_a,element_b,width,step)
{
	function set_step(slider, step_x, step_max) {
		$(slider).addClass('moving');
		$(slider).animate({marginLeft: 0 - width * (step_x - 1)}, 300, function() {
			$(slider).removeClass('moving');
			
			if (step_x == step_max) $(slider).siblings("span.next").removeClass("active");
			else $(slider).siblings("span.next").addClass("active");
				
			if (step_x == 1) $(slider).siblings("span.prev").removeClass("active");
			else $(slider).siblings("span.prev").addClass("active");
		});
	}
	// slider -- aktuality
	var size = $(element_a+' '+element_b).size();
	var slider = element_a+" .slider";
	sliderwrapper = element_a;
	$(slider).width(width * size);
	$(slider).animate({marginLeft: -width * (step - 1)}, 0);
	
	$(sliderwrapper+' .next').click(function(event){
		if(!($(slider).hasClass('moving'))) {
			if (step < size) {
				step += 1;
				set_step(slider, step, size);
			}
		}
	});
	$(sliderwrapper+" .prev").click(function(event){
		if(!($(slider).hasClass('moving'))) {
			if (step > 1) {
				step -= 1;
				set_step(slider, step, size);
			}
		}
	});
}


/**
 *	Pokud odskroluji vice nez 152 pixelu menu budu porad drzet nahore - mimo uvodni stranku
 *
 *
 *
 */
function _scrollMenu()
{

	// Na uvodni strance
	var top = (!$("body").hasClass("index"))?169:137;
	if($(window).scrollTop() > top)
	{
		if($("body").hasClass("index"))
			$("#absolutemenu").addClass("fixed");
		else
		{
			$("#absolutemenu").css("top",-5);
			$("#absolutemenu").css("position","fixed");
		}
		//$("#absolutemenu").css("top","-5px");
		if (!_isElement("#linkBack"))
		{
			$("#absolutemenu2").append("<a href='#' id='linkBack'>Zpět nahoru</a>");						
			// Tlacitko, ktere nas posune nahoru
				$("#linkBack").click(function(event)
			{
				//window.alert("oo");
        event.preventDefault();
				var full_url = this.href;
				var parts = full_url.split("#");
				var trgt = parts[1];
				var target_offset = $("a[name="+trgt+"]").offset();
				var target_top = ((target_offset)?target_offset.top:45)-45;
				$('html, body').animate({scrollTop:target_top}, 700);
				return false;
			});
		}
	} else {
		if($("body").hasClass("index"))
			$("#absolutemenu").removeClass("fixed");
		else
		{
			$("#absolutemenu").css("top",169);
			$("#absolutemenu").css("position","absolute");
		}
		if (_isElement("#linkBack"))
			$("#linkBack").remove();
	}
}


/**
 *	Skrolovani ceniku
 *
 *
 */
function _scrollCenik()
{
	var elem = "#cenik-box";
	
	if($(window).scrollTop() > 302) {
		if($(window).scrollTop() > 502){ 
      if(!$(elem).attr('temptop')){  
        var temptop = $(elem).css('top');
        $(elem).attr('temptop',temptop);
      }
      $(elem).css({"top":-183,"position":"fixed"});
            
    }else{
      if($(elem).css("position")== "fixed" )
        $(elem).css({"top":$(elem).attr('temptop'),"position":"absolute"});
      else
        $(elem).css({"top":$(elem).offset(),"position":"absolute"});
    } 
    
    
		$("div.fullinfo").css({
      'top':331,
      'background-image':'url(/img/jsboxmoved.png)',
      'background-color':'transparent'});
    
		
		
	} else {
    $(elem).css({"position":"static"});
		$("div.fullinfo").css({
      'top':0,
      'background-image':'url(/img/jsboxbgtop.png)',
      'background-color':'#fff'});
    
	}
}

/**
 *	prepinac detailu ceniku variant + info polozek
 *
 *
 *
 */
function runCenikVariantsSwitch(){
  if($(".jsswitch-wrapper2").length > 0 ){
    //var variantsfade = 1500;
    /*alert('box'); */
		$(".overflow").html('<div id="cenik-box">'+$(".overflow").html()+'</div>');
		$(".overflow").css('width',950);
		$(".overflow").css('height',376);
		
		
		$(".cdiv_jsswitch").hover(
      function(){        
        
        $(this).next().css('z-index','1');
        $(this).css('background','url(/img/jsboxsmallbgbottom2.png) no-repeat');
        $(this).css('background-position','0px 0px');
        $(this).next().fadeIn(50);
      },
      function(){        
        $(this).next().css('z-index','0');
        $(this).css('background','none');
        $(this).next().fadeOut(100); 
      }    
    );
	}
}


/**
 *	Vygenerování HTML pro kroků číslovaný seznam
 *
 *
 */
function _makeSteps()
{
	var krok = 1;
	$("ol").each(function(){
		$(this)
		.css("listStyleType", "none")
		.addClass("grbullets")
		.find("> li").each(function(i){
			$(this).prepend('<span class="step">'+ (krok++) +'.</span>');
		});
	});
}


/**
 *	Zmeni checkboxy na prepinac ano/ne
 *
 *
 *
 */
function redesignCheckboxs(){
	$(".formRezervace input[type=checkbox]").each(function(){
		var par = $(this).parent();
		var chckbx_id = $(this).attr("id");
		var chckbx_name = $(this).attr("name");
		var chckbx_ch = $(this).attr("checked");
	  var poptavka = false;
	  
		if(chckbx_name=="contact_neweshop"){
			poptavka = window.location.href.indexOf('#');
      
      if(poptavka>0) 
        poptavka = window.location.href.substr(poptavka)=="#poptavka";
      else
        poptavka = false;		  
		}
		var chckbx_str = '<input type="checkbox" '+((chckbx_id)?'id="'+chckbx_id+'" ':'')+((chckbx_name)?'name="'+chckbx_name+'" ':'')+((chckbx_ch||poptavka)?'checked="checked" haxed="checked" ':'')+' style="display:none;" />';

		par.html('<span class="button-anone">'+par.text()+'</span>'+chckbx_str);
		var chckbx = par.find('input[type=checkbox]');
		var span = par.find('span');
		span.css("background-position",(chckbx_ch||poptavka)?"0% 0%":"0% 100%");
		
		span.disableTextSelect();
		span.click(function(){
       
			if($(this).next().attr("haxed") == "checked" ){
				$(this).css("background-position","0% 100%");
				$(this).next().removeAttr("haxed");
				$(this).next().removeAttr("checked");
			} else {
				$(this).css("background-position","0% 0%");				
        $(this).next().attr("haxed","checked");
        $(this).next().attr("checked","checked");
        
			}
		});
	});
}

/**
 *	index -  reference
 *
 *
 *
 */   
 
function ref_movetoendleft_final(){
  var autotimerdelay = 4000;
  $(".div_refslider").children().first().remove();
  $(".div_refslider").attr('moving','no');
  
    clearTimeout(RefSlideTimeout);
    RefSlideTimeout = setTimeout('ref_nextimage()',autotimerdelay);      
  
} 
/*---------------------------------*/
function ref_movetoendright_final(){
  var autotimerdelay = 4000;
  $(".div_refslider").children().last().remove();
  $(".div_refslider").attr('moving','no');
  
    clearTimeout(RefSlideTimeout);
    RefSlideTimeout = setTimeout('ref_previmage()',autotimerdelay);      
  
}
/*---------------------------------*/ 
function ref_nextimage(){
 
  var timerdelay = 700;
  
  
  if( ($(".div_refslider").length != undefined) && ($(".div_refslider").attr('moving')=='no' ) ){
    $(".div_refslider").attr('moving','yes');
    var felement = $(".div_refslider").children().first(); 
    felement.clone().appendTo(".div_refslider");
    felement.css('position','relative');
    felement.animate({marginLeft:'-220'},timerdelay,'swing');    
    setTimeout('ref_movetoendleft_final()',timerdelay);
  }
}
/*---------------------------------*/
function ref_previmage(){
 
  var timerdelay = 700;
  
  
  if( ($(".div_refslider").length != undefined) && ($(".div_refslider").attr('moving')=='no' ) ){
    $(".div_refslider").attr('moving','yes');
    var felement = $(".div_refslider").children().last(); 
    felement.css({'position':'relative','margin-left':-220});
    felement.clone().prependTo(".div_refslider");    
    $(".div_refslider").children().first().animate({marginLeft:'0'},timerdelay,'swing');    
    setTimeout('ref_movetoendright_final()',timerdelay);
  }
}
  


/*---------------------------------*/ 
function refsmall_nextimage(elem){
 
  var timerdelay = 700;
  
  var slider = $(elem).next().next().children().first();
  
  
  if( (slider.length != undefined) && (slider.attr('moving')=='no' ) ){
    slider.attr('moving','yes');
    var felement = slider.children().first(); 
    felement.clone().appendTo(slider);
    felement.css('position','relative');
    felement.animate({marginLeft:'-120'},timerdelay,'swing');
    felement.queue(function(){
      $(this).parent().attr('moving','no'); 
      $(this).remove();            
    });

  }
}
/*---------------------------------*/
function refsmall_previmage(elem){
 
  var timerdelay = 700;
  
  var slider = $(elem).next().children().first();
 
  
  if( (slider.length != undefined) && (slider.attr('moving')=='no' ) ){
    slider.attr('moving','yes');
    var felement = slider.children().last(); 
    felement.css({'position':'relative','margin-left':-120});
    felement.clone().prependTo(slider);    
    slider.children().first().animate({marginLeft:'0'},timerdelay,'swing');
    felement.queue(function(){
      $(this).parent().attr('moving','no'); 
      $(this).parent().children().last().remove();            
    });   
  }
}

/*---------------------------------*/
function runRefSlider(){
  var autotimerdelay = 4000;
  
  if($(".referenceswrapper").length != 0 ){
    $(".div_refslider").attr('moving','no');
    $(".referenceswrapper .next").click(ref_nextimage);
    $(".referenceswrapper .prev").click(ref_previmage);
    
    RefSlideTimeout = setTimeout('ref_nextimage()',autotimerdelay);
  }
  
  if( ($(".div_ref_imagesbox").length != 0 ) ){
    $(".div_smallrefslider").attr('moving','no');
    
    if( $(".references-wrapper .next").length != 0 ){
      
       $(".next").attr("onclick", "refsmall_nextimage(this)" );
       $(".prev").attr("onclick", "refsmall_previmage(this)" );
      
    }
  }
}



/**
 *	index - obrazky monitoru
 *
 *
 *
 */
function intro_nextimage(){
    if( ($('#monitortext').length != 0) ){
      var nextdelay = 5000;
      var fadeindelay = 700;
      var numitems = 4;
      var fadeoutalpha = 0.7;  
      var fadeoutdelay = (fadeindelay)*(numitems-1);
      
      if( $('#monitortext .cli_mt_active').length != 0 ){
        var active = $('#monitortext .cli_mt_active');
        var activeid = active.attr('id');
        activeid = parseInt(activeid.substr(activeid.length-1,1));
        $('#img_monitor_' + activeid.toString()).css('z-index',0);
        setTimeout("$('#img_monitor_"+activeid.toString()+"').fadeOut()",fadeindelay);
        
        $('.cli_mt_active').fadeTo(fadeoutdelay,fadeoutalpha);
        active.removeClass('cli_mt_active');
        
        if(++activeid < numitems){
          $('#li_mt_' + activeid.toString()).addClass('cli_mt_active');
          $('.cli_mt_active').fadeTo(fadeindelay,1);
          $('#img_monitor_' + activeid.toString()).css('z-index',1);
          $('#img_monitor_' + activeid.toString()).fadeIn(fadeindelay);
        }
      }else{
        $('#monitortext li').fadeTo(fadeindelay,fadeoutalpha);
        $('#li_mt_0').addClass('cli_mt_active');
        $('#img_monitor_0').fadeIn(fadeindelay);
        $('.cli_mt_active').fadeTo(fadeindelay,1);
      
      }
      clearTimeout(IntroSlideTimeout);
      IntroSlideTimeout=setTimeout("intro_nextimage()",nextdelay);
    }

}

function intro_itemover(){
  var nextdelay = 5000;
      var fadeindelay = 700;
      var numitems = 4;
      var fadeoutalpha = 0.7;  
      var fadeoutdelay = (fadeindelay)*(numitems-1);
      
      
  if( ($('#monitortext').length != 0) ){
      
      clearTimeout(IntroSlideTimeout);
      
      if( $('#monitortext .cli_mt_active').length != 0 ){
        var active = $('#monitortext .cli_mt_active');
        var activeid = active.attr('id');
        activeid = parseInt(activeid.substr(activeid.length-1,1));
          $('#img_monitor_' + activeid.toString()).css('z-index',0);
          setTimeout("$('#img_monitor_"+activeid.toString()+"').fadeOut()",fadeindelay);
      
        active.fadeTo(fadeoutdelay,fadeoutalpha);
        
        active.removeClass('cli_mt_active');
         
        activeid = $(this).attr('id');
        activeid = parseInt(activeid.substr(activeid.length-1,1));
         
        $(this).addClass('cli_mt_active');
        $('.cli_mt_active').fadeTo(fadeindelay,1);
        $('#img_monitor_' + activeid.toString()).css('z-index',1);
        $('#img_monitor_' + activeid.toString()).fadeIn(fadeindelay);
        
        
      }else{
        var activeid = $(this).attr('id');
        activeid = parseInt(activeid.substr(activeid.length-1,1));
        
        $('#monitortext li').fadeTo(fadeindelay,fadeoutalpha);
        $(this).addClass('cli_mt_active');
        $(this).fadeTo(fadeindelay,1);
        $('#img_monitor_' + activeid.toString()).css('z-index',1);          
        $('#img_monitor_' + activeid.toString()).fadeIn(fadeindelay);
        
        
      
      }
      
      
      IntroSlideTimeout=setTimeout("intro_nextimage()",nextdelay);
    }

}
 
function runIntro(){
  var startdelay = 5000;
  if( $('#monitortext').length != 0 ){
    $("#monitortext li").hover(intro_itemover);
    IntroSlideTimeout=setTimeout("intro_nextimage()",startdelay);
  }       
}

/**
 *	onload
 *
 *
 *
 */
$(document).ready(function() {
	$.fn.fancybox.build();
	
  $("a.lightbox").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'overlayShow': true
	});	
	
	redesignCheckboxs();
	runIntro();
	runCenikVariantsSwitch();

	
	// Scrollovaci eventy
	$(window).scroll(function() {
		_scrollMenu();
		_scrollCenik();
	});
  
  // klik na # anchory : pojezd na anchor - top menu
  
  var anchorselect = window.location.href.indexOf('#');  
  if(anchorselect>0){ 
    anchorselect = window.location.href.substr(anchorselect+1);
    if(anchorselect.length>0){	
		var actualUrl = window.location.href.substr(0,window.location.href.length-anchorselect.length-1);			
		if(actualUrl.match('novinky')=='novinky'){			
			$('div.moreinfo.'+anchorselect).show();									
			$('div.moreinfo.'+anchorselect).parent().addClass("active");						
			var buttonObj = $('div.moreinfo.'+anchorselect).parent().find("span.cspan_closetxt");			
			  if( buttonObj.html()!=null ){	    
			  var temphtml = buttonObj.parent().html(); 			  
				temphtml = temphtml.slice(0,temphtml.indexOf("<span"));				
			  buttonObj.parent().html( buttonObj.text()+'<span class="cspan_closetxt">'+temphtml+"</span>" );
			}			
		}
		var target_offset = $("a[name="+anchorselect+"]").offset();
		var target_top = target_offset.top - 85;	  
		$('html, body').animate({scrollTop:target_top}, 500);
    }
  }
  
  $(".ca_anchor").click(function(event){
     event.preventDefault();
      var full_url = this.href;
     
      var parts = full_url.split("#");
      var trgt = parts[1];
      
      if(trgt.length > 0){
        var target_offset = $("a[name="+trgt+"]").offset();
        var target_top = target_offset.top - 85;
        $('html, body').animate({scrollTop:target_top}, 500);
      }
	  //upraveno
	  window.location.href=this.href;	  
  });  	
	
	// Slidery
	_makeSlider('.actualnewswrapper','.actualnews',447,1);
	runRefSlider();
  //_makeSlider('.referenceswrapper','.references',447,1);
	
	// ul cislovani
	_makeSteps();


  if($("#neweshop").length > 0){
    
    if( $("#neweshop").attr("checked") != undefined )
      $("#div_newshop_more").slideDown("fast");  
    else
      $("#div_newshop_more").slideUp("fast");
    
    $("#neweshop").prev().click(function(){
    
      if( $("#neweshop").attr("checked") != undefined )
        $("#div_newshop_more").slideDown("fast");  
      else
        $("#div_newshop_more").slideUp("fast");
    } );
  }
	
	// uprava HTML pro nektere prvky
	$('div.buttonlarge').append('<div class="buttonlarge2"></div><div class="buttonlarge3"></div>');
	$('div.buttonall').append('<div class="buttonall2"></div><div class="buttonall3"></div>');
	
	$('div.info div.popupinfo2').append('<div class="bgt"></div>');
	
	$('a.lightbox').append('<div class="cdiv_lupa"></div>');
		
		
	// Otviraci-zaviraci bloky s textem 	
	$('div.mainbox.modul div.mainbox2 div.clickable').click(function(event) {
		$(this).children('p').children('a').click(function(){
			window.location.href=$(this).attr('href');
			return false;
		});
		event.preventDefault();
		var buttonObj = $(this).parent().find("span.cspan_closetxt");		
		if( buttonObj.html()!=null ){	    
			var temphtml = buttonObj.parent().html(); 
			temphtml = temphtml.slice(0,temphtml.indexOf("<span"));
			buttonObj.parent().html( buttonObj.text()+'<span class="cspan_closetxt">'+temphtml+"</span>" );		
			if($(this).parent().hasClass('active')) {					
				$(this).siblings("div.moreinfo").hide(200);						
				$(this).parent().removeClass("active");
			} else {						
				$(this).siblings("div.moreinfo").show(200);						
				$(this).parent().addClass("active");
				var target_offset = $(this).parent().offset();
				var target_top = target_offset.top-70;
				$('html, body').animate({scrollTop:target_top}, 700);
			}
		}
	});
	
	// input pole	
	/*$("input[type=text]").focus(function(event) {
		$(this).attr('value','');
	});
	
	$("textarea").focus(function(event) {
		$(this).val("");
	});*/
	
	// Info popupy napovedy
	$("div.info").hover(function(){
		$(this).find(".popupinfo").fadeIn("slow");
	});
	
	$("div.info").mouseleave(function(){
		$(this).find(".popupinfo").fadeOut("slow");
	});
	
	
	
	/*if(_isElement(".popupinfo")) {
		$(".popupinfo").css("display","none;");
	} **/
	// vsechny odkazy - kotvy ve strance, pokud nejsou shadowbox budou hezky plynule skrolovat
	

	//    
  /*
	$(window).scroll(function() {
		_scrollMenu();
		_scrollCenik();
	}); */
	
	
	// Validace formulářů
	checkForm.checkSend("#form-vzkaz",{"f_email":{0:"Váš Email/Telefon",1:"Chybně vyplněný Email/Telefon."},
									   "f_text":{0:"Text zprávy, kterou nám chcete zaslat – ať již jde o poptávku, dotaz nebo prostě jen názor.",1:"Text zprávy není vyplněn."},
									   "f_name":{0:"Vaše jméno",1:"Jméno není vyplněno."}});

	// Validace formulare .formRezervace
	/*if (_isElement(".formRezervace"))
	{
		checkForm.checkSend(".formRezervace",{"f_email":{0:"TelMail",1:"chyba"}});
	}*/
	
	if (_isElement(".formRezervace")) {
	
		$(".formRezervace").submit(function() {
			var formRezervaceValid = true;
			var errorText = "";
			
			
			if (!validLength($(this).find("input[name=contact_name]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněné jméno a příjmení. "; }
			
			var email = $(this).find("input[name=contact_email]");
			if (!_checkEmail(email.attr("value")))
			{ 
				email.addClass("error");
				errorText = errorText + "Špatně zadaný email. ";
				formRezervaceValid = false;
			} else {
				email.removeClass("error");
			}
			
			if (!validLength($(this).find("input[name=contact_cureshop]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný stávající shop. "; }
			if (!validLength($(this).find("input[name=contact_phone]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný telefon. "; }
			if (!validLength($(this).find("textarea[name=contact_text]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný text zprávy. "; }
			
			if (formRezervaceValid) {
				$(".hlaska_green").animate({"bottom" : "0"},400,function() {});				
			} else {
				if (!_isElement(".hlaska_red")) {
					$('body').append('<div class="hlaska_red"><div class="centerwrapper"><p>'+ errorText +'</p></div></div>');
					$(".hlaska_red").animate({"bottom" : "0"},400,function() {});
				}
				$(".hlaska_red").click(function(){
					$(".hlaska_red").hide();
				});	
			}
			return formRezervaceValid;
		});
		
			
	}
});

/**
 *	Dalsi
 *
 *
 *
 */


/*var pform = {
				"input[name=pcontact_name]":	$("input[name=pcontact_name]").val(),
				"input[name=pcontact_phone]":	$("input[name=pcontact_phone]").val(),
				"textarea[name=pcontact_text]":	$("textarea[name=pcontact_text]").val(),
				"input[name=pcontact_email]":	$("input[name=pcontact_email]").val()
				};*/

/*var checkForm = {
	_validLength: function(object)
	{
			var isValid = true;
			if (object.attr("value").length < 1) {
				isValid = false;
				// Pridam objektu chybovou tridu
				object.addClass("error");
			} else {
				// Odeberu mu chybovou tridu
				object.removeClass("error");
			}
			return isValid;
	},
	__checkEmail: function(emailAddress)
	{
		var pattern = 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);
		return pattern.test(emailAddress);
	},
	_ElementsNames: new Array({
		"f_name":"Nevyplněné jméno a příjmení.",
		"f_email":"Špatně zadaný email.",
		"f_phone":"Nevyplněný telefon.",
		"f_text":"Nevyplněný text zprávy.",
	}),
}
checkForm.checkSend = function(form)
{
	var success = true;
	
	
	
	$.map(this._ElementsNames,function(e,i){
		$(form).find("." + this._ElementsNames[i])
		
	});
	
};
		


$(".impPart-form").submit(function() {
			var formRezervaceValid = true;
			var errorText = "";
			
			// Jmeno
			if (!validLength($(this).find("input[name=pcontact_name]")))
			{
				formRezervaceValid = false;
				errorText = errorText + "Nevyplněné jméno a příjmení. ";
			}
			
			var email = $(this).find("input[name=pcontact_email]");
			if (!_checkEmail(email.attr("value"))) { 
				email.addClass("error");
				errorText = errorText + "Špatně zadaný email. ";
				formRezervaceValid = false;
			} else {
				email.removeClass("error");
			}

			if (!validLength($(this).find("input[name=pcontact_phone]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný telefon. "; }
			if (!validLength($(this).find("textarea[name=pcontact_text]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný text zprávy. "; }
			
			if (formRezervaceValid) {
				$(".hlaska_green").animate({"bottom" : "0"},400,function() {});				
			} else {
				if (!_isElement(".hlaska_red")) {
					$('body').append('<div class="hlaska_red"><div class="centerwrapper"><p>'+ errorText +'</p></div></div>');
					$(".hlaska_red").animate({"bottom" : "0"},400,function() {});
				}
			}
			return formRezervaceValid;
		});*/
//checkForm.validate(".form");

/*function ValidateForm()
{
	var pform = {
				"pcontact_name":	$("input[name=pcontact_name]").val(),
				"pcontact_phone":	$("input[name=pcontact_phone]").val(),
				"pcontact_text":	$("textarea[name=pcontact_text]").val(),
				"pcontact_email":	$("input[name=pcontact_email]").val()
				};
	for(var i in pform)
	{
		alert($("*[name="+i+"]").val());
		$("*[name="+i+"]").focusin(function(e){
			alert(1);
		});
	}
	
	$(".impPart-form").submit(function() { 
			var formRezervaceValid = true;
			var errorText = "";
			
			$(".impPart-form").each(function(index,element){
				
				
			});
			
			// Jmeno
			if (!validLength($(this).find("input[name=pcontact_name]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněné jméno a příjmení. "; }
			
			var email = $(this).find("input[name=pcontact_email]");
			if (!_checkEmail(email.attr("value"))) { 
				email.addClass("error");
				errorText = errorText + "Špatně zadaný email. ";
				formRezervaceValid = false;
			} else {
				email.removeClass("error");
			}

			if (!validLength($(this).find("input[name=pcontact_phone]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný telefon. "; }
			if (!validLength($(this).find("textarea[name=pcontact_text]"))) { formRezervaceValid = false; errorText = errorText + "Nevyplněný text zprávy. "; }
			
			if (formRezervaceValid) {
				$(".hlaska_green").animate({"bottom" : "0"},400,function() {});				
			} else {
				if (!_isElement(".hlaska_red")) {
					$('body').append('<div class="hlaska_red"><div class="centerwrapper"><p>'+ errorText +'</p></div></div>');
					$(".hlaska_red").animate({"bottom" : "0"},400,function() {});
				}
			}
			return formRezervaceValid;
		});
}*/

function isElement(element){
    var result;
    if($(element).length > 0){ result = true; }else{ result = false }  
    return result;
}
