

function isObject(id){
	 if(document.getElementById(id)){
		 return true;
	 } else {
		return false;
	};
}

function initSmoothMenu(menuid,cls) {
	if (isObject(menuid) == true) {
		ddsmoothmenu.init({
			mainmenuid: menuid, //menu DIV id
			orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
			classname: cls, //class added to menu's outer DIV
			//customtheme: ["#1c5a80", "#18374a"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		})
		
	};
}


function initFileButt(id) {

if (isObject(id) == true) {
      $("input."+id).filestyle({ 
          image: "../jquery/choose-file.gif",
          imageheight : 22,

          imagewidth : 82,
          width : 50
      });  
	  
}
	  

}

function initAjaxForm(id){
if (isObject(id) == true) {

	var ajaxForm = document.getElementById(id);
	var target = $(ajaxForm).attr('target');
	
	$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};	

	var validator = $("#"+id).validate({
		success: function(form) {

			},	
		error: function(form) {

			},					
		rules: {
				math: {
				}
		},
		messages: {
			math: {
				equal: "Vložte správný výsledek"
			}
		},
		invalidHandler: function() {
			$("#formErrors").html("Formulář není správně vyplněný.<br>Počet špatně vyplněných položek: " + validator.numberOfInvalids() + " ");
			$("#formErrors").addClass("info-ko");
		 },	
		submitHandler: function(form) {

		
			
		 var options = { 
				target: $(ajaxForm).attr('target'),  // target element(s) to be updated with server response 
				replaceTarget:	true,
				resetForm: false
				// other available options: 
				//url:       url         // override for form's 'action' attribute 
				//type:      type        // 'get' or 'post', override for form's 'method' attribute 
				//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
				//clearForm: true        // clear all form fields after successful submit 
				//resetForm: true        // reset the form after successful submit 
		 
				// $.ajax options can be used here too, for example: 
				//timeout:   3000 
			}; 		
			
			// pre-submit callback 
			function showRequest(formData, jqForm, options) { 
				var queryString = $.param(formData); 
				alert('About to submit: \n\n' + queryString); 
				return true; 
			} 
			 
			// post-submit callback 
			function showResponse(responseText, statusText, xhr, $form)  { 
				alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
					'\n\nThe output div should have already been updated with the responseText.'); 
				
			}
   			$('#ajaxForm').ajaxSubmit(options);
			
			$(target).html('<div style="text-align:center; padding:3px; position:relative; margin:1px 5px 0px 0px; float:right;  font-size:9px; color:red;"><img src="/system/img/ajax-horizontal.gif"> Čekejte zpracovávám data</div>'+$(target).html());
			
			$("#"+id+' input').attr("disabled", true);
			$("#"+id+' textarea').attr("disabled", true);
			$("#"+id+' input:submit').attr("disabled", true);	
			$("#formErrors").html("Čekejte formulář se odesílá.");
			$("#formErrors").addClass("info-ok");		
  	 	}	
	});

	
}
}

function initEditForm(id){
if (isObject(id) == true) {


	$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};	

	var validator = $("#"+id).validate({
		  invalidHandler: function() {		  
			$("#formErrors").html("Formulář není správně vyplněný.<br>Počet špatně vyplněných položek: " + validator.numberOfInvalids() + " ");
			$("#formErrors").addClass("info-ko");	
		  },		
		submitHandler: function(form) {
		var $inputs = $('#myForm input, #myForm textarea');
			$inputs.each(function() {
				if ($(this).val() == $(this)[0].title)
				{
					$(this).removeClass("defaultTextActive");
					$(this).val("");
				}				
			});
		   form.submit();
			$("#formErrors").html("Čekejte formulář se odesílá.");
			$("#formErrors").addClass("info-ok");		   
		 },				
		rules: {
				math: {
				}
		},
		messages: {
			math: {
				equal: "Vložte správný výsledek"
			}
		}
	});

	
}
}


function initPriceRange(id,currConversion,highestPrice,selectedLow,selectedHigh){

$("#"+id).slider({
			range: true,
			min: 0,
			max: highestPrice,
			values: [selectedLow,selectedHigh],
			slide: function(event, ui) {
				$("#lowestPrice").val(Math.floor(ui.values[0]));
				$("#highestPrice").val(Math.ceil(ui.values[1]));
				$("#minValue").html(Math.floor(ui.values[0]*currConversion));
				$("#maxValue").html(Math.ceil(ui.values[1]*currConversion));				
			}
		});
		$("#lowestPrice").val(Math.floor($("#"+id).slider("values", 0)));
		$("#highestPrice").val(Math.ceil($("#"+id).slider("values", 1)));
		$("#minValue").html(Math.floor($("#"+id).slider("values", 0)*currConversion));
		$("#maxValue").html(Math.ceil($("#"+id).slider("values", 1)*currConversion));		
}


$(document).ready(function(){	
$('.ajaxify').ajaxify();
	$('.ajaxify').click(function(){
	target = $(this).attr('target');
	width = $(target).innerWidth();
	height = $(target).innerHeight();
	leftMargin = (width/2)-100;
	topMargin = (height/2)-16;
	$(target).prepend('<div style=\"position:absolute; z-index:100; background-image: url(/system/img/lighten-90.png); top:0; right:0; height:' + height + 'px; width:' + width + 'px;\"><div style=" text-align:center; margin-top:' +topMargin + 'px;"><img src="/system/img/ajax-horizontal.gif"><br>Čekejte zpracovávám data ...</div></div>');
	}
	);
  	if($("#contentType").val()!="ajax"){
	
	//$("select, input:checkbox, input:radio, input:file").uniform();				   
	initSmoothMenu('smoothmenu1','ddsmoothmenu');
	initSmoothMenu('smoothmenu2','ddsmoothmenu2');
	$(".butt").button();
	$("#formButtons").buttonset();
	initEditForm("myForm");
	
	initAjaxForm("ajaxForm");
	
	var multiselect = $("body").find(".multiselect");
	if(multiselect.length > 0){$(".multiselect").multiselect();};

	
	$(".externalCbox").colorbox({iframe:true, innerWidth:800, innerHeight:550});
	$(".menuCbox").colorbox({inline:true, href: function(){return $(this).attr('href');}, initialWidth:0, initialHeight:0, innerWidth:200});
	$(".helpBox").colorbox({inline:true, href: function(){return $(this).attr('href');}, initialWidth:0, initialHeight:0, innerWidth:200});
	$(".itemCbox").colorbox({
							onClosed:function(){ document.documentElement.style.overflow = "auto"; }, 
							iframe:true, 
							preloading:true, 
							overlayClose:false, 
							initialWidth:0, 
							initialHeight:0, 
							innerWidth:150, 
							innerHeight:150, 
							maxHeight:"90%"});
	

	
	$(".fotoCbox").colorbox({photo:true, slideshow:true, transition:"elastic", maxHeight:"90%", maxWidth:"90%", speed:300});
		
		toggleMenu('.operationMenu','toggleElementOpened');	
		
		$(".signin").click(function() {
                $("div#signin_menu").slideToggle('fast');
				$(".signin").toggleClass("topmenu-open");
            });
			
			$("div#signin_menu").mouseup(function() {
				return false
			});
			$(document).mouseup(function(e) {
				if($(e.target).parent("a.signin").length==0) {
					$(".signin").removeClass("topmenu-open");
					$("div#signin_menu").hide();
				}
			});		
			
			$(".filterExtendedToggle").click(function() {
                $("div#filterExtended").slideToggle('fast','easeOutSine');
				$(".filterExtendedToggle").toggleClass("filterExtendedToggleOpen");
            });	
			
			$('#colorpickerField').ColorPicker({
				onSubmit: function(hsb, hex, rgb, el) {
					$(el).val(hex);
					$(el).ColorPickerHide();
				},
				onBeforeShow: function () {
					$(this).ColorPickerSetColor(this.value);
				},
				onChange: function (hsb, hex, rgb) {
					$('#colorpickerField').val(hex);
				}
			})
			.bind('keyup', function(){
				$(this).ColorPickerSetColor(this.value);
			});	
			
			$(".defaultInputText").focus(function(srcc)
			{
				if ($(this).val() == $(this)[0].title)
				{
					$(this).removeClass("defaultTextActive");
					$(this).val("");
				}
			});
			
			$(".defaultInputText").blur(function()
			{
				if ($(this).val() == "")
				{
					$(this).addClass("defaultTextActive");
					$(this).val($(this)[0].title);
				}
			});
			
			$(".defaultInputText").blur(); 	
			
			$(document).bind('cbox_cleanup', function(){
					var changed = $('#cboxIframe').contents().find('#withOutSaveClose').val();
					
					if(changed!="changed"){
						$.fn.colorbox.close_flag=true; 
 						 document.documentElement.style.overflow = "auto";	
					} else {
						var question = $('#cboxIframe').contents().find('#withOutSaveCloseQuestion').val();
						var answer = confirm(question);
						if (answer){
							$.fn.colorbox.close_flag=true;
 						 document.documentElement.style.overflow = "auto";											
						}	
						else{
							$.fn.colorbox.close_flag=false; 
						}
					}
			});	
			
			
			$('#datum1, #timeDatum').change(function() {
				
				if($('#datum_end').val()==""){$('#datum_end').val($('#datum1').val());};
				var datum = $('#datum1').val().split(".");
				var datumEnd = $('#datum_end').val().split(".");
				var datumFormated = datum[1]+"."+datum[0]+"."+datum[2];
				var datumEndFormated = datumEnd[1]+"."+datumEnd[0]+"."+datumEnd[2];
				
				var SDate = new Date(datumFormated+" "+$('#timeDatum').val());
				var EDate = new Date(datumEndFormated+" "+$('#timeDatumEnd').val());
				
				if(SDate > EDate)
					{
						
					$('#datum_end').val($('#datum1').val());
					$('#timeDatumEnd').val($('#timeDatum').val());
				}
				
				$( "#datum_end" ).datepicker( "option", "minDate", new Date(datumFormated) );

			});
			
			$('#datum_end, #timeDatumEnd').change(function() {
				
				if($('#datum1').val()==""){$('#datum1').val($('#datum_end').val());};
				var datum = $('#datum1').val().split(".");
				var datumEnd = $('#datum_end').val().split(".");
				var datumFormated = datum[1]+"."+datum[0]+"."+datum[2];
				var datumEndFormated = datumEnd[1]+"."+datumEnd[0]+"."+datumEnd[2];
				
				var SDate = new Date(datumFormated+" "+$('#timeDatum').val());
				var EDate = new Date(datumEndFormated+" "+$('#timeDatumEnd').val());
				
				if(SDate > EDate)
					{
				$('#datum1').val($('#datum_end').val());
				$('#timeDatum').val($('#timeDatumEnd').val());
				}

			});			
			
			$('.showTipsy').tipsy({gravity: 'n',html: true});
			
			$(".youtubeVideo").colorbox({iframe:true});
			
			$(".tableRowx:odd").css("background-color", "#eee");
			$(".tableRowx").hover( function(){
				$(this).css("background-color", "#fff");
			},
			function(){
				$(".tableRowx:odd").css("background-color", "#eee");
				$(".tableRowx:even").css("background-color", "#f5f5f5");
			});
			
			
			var maskedPhone = $("body").find(".masked-phone");
			if(maskedPhone.length > 0){$.mask.definitions['~']='[+-]'; $(".masked-phone").mask("+(999) 999 999 999"); };
			
			var maskedRC = $("body").find(".masked-rc");
			if(maskedRC.length > 0){$.mask.definitions['~']='[+-]'; $(".masked-rc").mask("999999/999?9"); };
			
			var maskedPsc = $("body").find(".masked-psc");
			if(maskedPsc.length > 0){$.mask.definitions['~']='[+-]'; $(".masked-psc").mask("999 99"); };	
								
	};
			
});





	

/*soundManager.url = '../soundmanager/';

soundManager.onload = function() {
// SM2 has loaded - now you can create and play sounds!
//soundManager.createSound('helloWorld','http://www.voltage.cz/cz/storage/markof/download/200912301119_02-From-Rino.mp3');
//soundManager.play('helloWorld');
}

function playSound(sound,name) {
	soundManager.createSound(name,sound);
	soundManager.play(name);  
}*/


 function refreshHs() {
 window.location = window.location.href;
 }
 
 function showSaving(content) {
	 //hs.htmlExpand(null, {maincontentText: content, dimmingOpacity:1, dimmingDuration:0, outlineType:null } );

 }
 
 function redirectPage(loc) {
 window.location = loc;
 }
 
  function redirectPageCSFD(loc) {
 var newLoc = loc+"&parseUrl="+document.getElementById('parseCsfdUrl').value;
 window.location = newLoc;
 } 
 
  function closeHs() {
	parent.$.fn.colorbox.close();	 	
 }
 
  function loadContent(where,what){
	target = "#"+where;
	width = $(target).innerWidth();
	height = $(target).innerHeight();
	
	//alert(where+"?"+what);

	$(target).prepend('<div style=\"display:none;\" class="ajax-loader-fader" id="ajax-loader-fader'+where+'"></div><div class="ajax-loader-info" id="ajax-loader-info'+where+'"><div class="ajax-loader-img" id="ajax-loader-img'+where+'"><img src="/system/img/ajax-horizontal.gif"></div><div class="ajax-loader-text" id="ajax-loader-text'+where+'">Nahrávám data ...</div></div>');
	leftMargin = (width-$("#ajax-loader-info"+where).innerWidth())/2;
	topMargin = (height-$("#ajax-loader-info"+where).innerHeight())/2;
	$("#ajax-loader-info"+where).css('margin-left',leftMargin);
	$("#ajax-loader-info"+where).css('margin-top',topMargin);
	$("#ajax-loader-fader"+where).css('height',height);
	$("#ajax-loader-fader"+where).css('width',width);	
	$("#ajax-loader-fader"+where).fadeIn(200);
	
	$(target).load(what, function() { 
		$.getScript("/js.js");	
		$(target).prepend('<div id="ajax-loader-fader"></div>');
		$("#ajax-loader-fader"+where).css('height',height);
		$("#ajax-loader-fader"+where).css('width',width);			
	 	$("#ajax-loader-fader"+where).fadeOut(200);
	 //$(target).hide("slide", { direction: "left" }, 1000);
	  });

 }
 
   function slideContent(where,what,direction,type,speed,easing,automatic){
	   
	target = "#"+where;
	width = $(target).innerWidth();
	height = $(target).innerHeight();
	var duration = speed;
	var ease = easing;
	
	if(automatic==false){
		stopCount(target.substr(6));
	}
	
	$(target).html('<div style=\"display:none;\" id="ajax-loader-clickStopper'+where+'" class="ajax-loader-clickStopper"></div><div id="ajax-loader-info'+where+'" class="ajax-loader-info"><div id="ajax-loader-img'+where+'" class="ajax-loader-img"><img src="/system/img/ajax-horizontal.gif"></div><div id="ajax-loader-text'+where+'" class="ajax-loader-text">Nahrávám data ...</div></div><div id="content-old'+where+'" class="content-old">'+$(target).html()+'</div><div id="content-new'+where+'" class="content-new">&nbsp;</div>');

	
	leftMargin = (width-$("#ajax-loader-info"+where).innerWidth())/2;
	topMargin = (height-$("#ajax-loader-info"+where).innerHeight())/2;
	$("#ajax-loader-info"+where).css('margin-left',leftMargin);
	$("#ajax-loader-info"+where).css('margin-top',topMargin);
	$("#ajax-loader-info"+where).css('display','none');
	$("#ajax-loader-info"+where).fadeIn(300);
	
	$("#ajax-loader-clickStopper"+where).css('height',height);
	$("#ajax-loader-clickStopper"+where).css('width',width);	
	$("#ajax-loader-clickStopper"+where).fadeIn(200);
	
	$(target).css('width',width);
	$(target).css('height',height);
	
	$("#content-old"+where).css('width',width);
	$("#content-old"+where).css('height',height);
	
	$("#content-new"+where).css('width',width);
	
	$("#content-new"+where).load(what, function() { 
	$("#ajax-loader-info"+where).fadeOut(500);	
	$("#ajax-loader-clickStopper"+where).fadeOut(200);	

		if(type=="slideHorizontal"){
			
			if(direction=="next"){
				var oldBlock = "right";
				var newBlock = "left";
			}else{
				var oldBlock = "left";
				var newBlock = "right";		
			};
			
			$("#ajax-loader-info"+where).fadeOut('fast');

			$(target).animate({height: $("#content-new"+where).innerHeight()}, duration );
			$("#content-old"+where).hide("slide", { direction: oldBlock ,duration: duration, easing:ease});
			$("#content-new"+where).show("slide", { direction: newBlock, duration: duration, easing:ease},  function() { 
				
	  			$(target).html($("#content-new"+where).html());
				
				if(automatic==true){
				doTimer(target.substr(6));
				} else {
					$.getScript("/js.js");
				}
			  });
		  
		};
		
		if(type=="slideVertical"){
			
			if(direction=="previous"){
				var oldBlock = "up";
				var newBlock = "down";
			}else{
				var oldBlock = "down";
				var newBlock = "up";		
			};
			
			$("#ajax-loader-info"+where).fadeOut('fast');
			$(target).animate({height: $("#content-new"+where).innerHeight()}, duration );
			
			$("#content-old"+where).hide("slide", { direction: oldBlock ,duration: duration, easing:ease});
			$("#content-new"+where).show("slide", { direction: newBlock, duration: duration, easing:ease},  function() { 
				
	  			$(target).html($("#content-new"+where).html());
				
				if(automatic==true){
				doTimer(target.substr(6));
				} else {
					$.getScript("/js.js");
				}
				
			  });
		  
		};		
	
		if(type=="fade"){
		
			$("#ajax-loader-info"+where).fadeOut('fast');
			$("#content-old"+where).fadeOut(speed);
			$(target).animate({height: $("#content-new"+where).innerHeight()}, duration );
			$("#content-new"+where).fadeIn(speed,  function() { 
				
				$(target).html($("#content-new"+where).html());
				
				if(automatic==true){
				doTimer(target.substr(6));
				} else {
					$.getScript("/js.js");
				}
			  });
		};	
	
  	});
	
	
 }
 
   function loadContent2(where,what){
	target = "#"+where;
	//alert(where+" / "+what);
	width = $(target).innerWidth();
	height = $(target).innerHeight();
	leftMargin = (width-150)/2;
	topMargin = (height-40)/2;
	$(target).prepend('<div style=\"position:absolute; text-align:center; z-index:100; background-image: url(/system/img/lighten-80.png); top:0; right:0; height:' + height + 'px; width:' + width + 'px;\"><div style="text-align:center;"><img src="/system/img/ajax-horizontal.gif"></div></div>');

	$("#"+where).load(what);
 }
 

 
 function showButt(element) {
	 	  //alert(element);
          var div = document.getElementById(element);
          div.style.visibility = "visible";
          div.style.display = "block";
          div.top = "50";
          div.left = "50";
}

 
function closeButt(element) {
         var div = document.getElementById(element);
         div.style.visibility = "hidden";
         div.style.display = "none";
}

 function showButtAnim(element) {
	 	  var n = $("#"+element).queue("fx");
		  if (n<1) {
          $("#"+element).fadeIn(200);
		  };
}

function closeButtAnim(element) {
          $("#"+element).fadeOut(200);
}

function hideSlide(element) {
          $("#"+element).slideUp(500);
}



function formCallback(result, form) {
	window.status = "valiation callback for form '" + form.id + "': result = " + result; }
	

 function hideScrollbar() {
 parent.document.documentElement.style.overflow = "hidden";
 document.documentElement.style.overflow = "hidden";
 }
 
 function showScrollbar() {
 parent.document.documentElement.style.overflow = "auto";
 document.documentElement.style.overflow = "auto";
 } 


function Smazat(url) {
if (confirm('Opravdu smazat?')) {location.href=url;return true;
}else{return false;}
}

function objGet(x) {
   if (typeof x != 'string') return x;
   else if (Boolean(document.getElementById))
      return document.getElementById(x);
   else if (Boolean(document.all))
      return eval('document.all.'+x);
   else if (Boolean(document.ids))
      return eval('document.ids.'+x);
   else
      return null;
}



function checkTree(){
  if(document.getElementById("mainTree")){
	treeObj = new DHTMLSuite.JSDragDropTree();
	treeObj.setTreeId('mainTree');
	treeObj.init();
	};
}

function setActiveZone(){
	
	var old = document.getElementById("itemZone").value;
	
	if(old!=''){
 	if(document.getElementById(old)){
		oldItem = document.getElementById(old);
		oldItem.style.backgroundImage = 'url(system/img/ok.png)';
		oldItem.style.backgroundRepeat = 'no-repeat';
		oldItem.style.backgroundPosition = 'center center';
	};		
	};		
}

function changeZone(id,sablona,zona) {
	
for (var i=0;i<document.katForm.zona.options.length;i++) {
    if (document.katForm.zona.options[i].value == zona)
        document.katForm.zona.options[i].selected = true;
		
	}
	
for (var i=0;i<document.katForm.sablona.options.length;i++) {
    if (document.katForm.sablona.options[i].value == sablona)
        document.katForm.sablona.options[i].selected = true;
		
	}
	
	var old = document.getElementById("itemZone").value;
	
	if(old!=''){
 	if(document.getElementById(old)){
		oldItem = document.getElementById(old);
		oldItem.style.backgroundImage = 'none';
		oldItem.style.backgroundRepeat = 'no-repeat';
		oldItem.style.backgroundPosition = 'bottom right';
	};		
	};	
	
	document.katForm.itemZone.value = id;
	
 	if(document.getElementById(id)){
		selectedItem = document.getElementById(id);
		selectedItem.style.backgroundImage = 'url(system/img/ok.png)';
		selectedItem.style.backgroundRepeat = 'no-repeat';
		selectedItem.style.backgroundPosition = 'center center';

	};	
	
	
}

function moveHtml(from,to){
	
	var content = document.getElementById(from).innerHTML;

	document.getElementById(to).innerHTML = content;
	document.getElementById(from).innerHTML = '';
	document.getElementById(from).style.display = 'none';

}

function updateValue(id,value){
	var currValues = $("#preRelativeIDs"+id).val();
	if(currValues!=""){
		$("#preRelativeIDs"+id).val(currValues+","+value);
	}else{
		$("#preRelativeIDs"+id).val(value);
	}
	var values = $("#preRelativeIDs"+id).val();
	updateRelItems(id);
}

function removeValue(id,value){
	
	loadContent('preRelativeItems'+id+'info','/actions.php?akce=deleteItemByID&items='+value);
	
	var newValues = "";
	var currValues = $("#preRelativeIDs"+id).val();
	var currValuesArr=currValues.split(",");
	var valNum=0;
while (valNum < currValuesArr.length)
 {
	 if(currValuesArr[valNum]!=value){newValues+=currValuesArr[valNum]+",";};
  	 valNum+=1;
 }
	newValues = newValues.substr(0,newValues.length-1);
	$("#preRelativeIDs"+id).val(newValues);
	updateRelItems(id);
}

function updateRelItems(id){
	var currValues = $("#preRelativeIDs"+id).val();
	if(currValues!=""){
	loadContent('preRelativeItems'+id,'/actions.php?akce=showItemsByIDs&formItemID='+id+'&items='+currValues);
	}else{
		$("#preRelativeItems"+id).html("<div class=\"info-ko\">Není záznam.</div>");
	}
}

function getSelBoxTitle(id,setInput){
		//alert($("#"+id+' option:selected').attr("title"));
		$("#"+setInput+'').val($("#"+id+' option:selected').attr("title"))
}

function fillDiv(divId,content){
	document.getElementById(divId).innerHTML = content;
}

function changeBox(cbox) {
	box =	document.getElementById(cbox);
	box.checked = !box.checked;
}

function datePicker(id){

	
		$('#'+id).datepicker({
			showAnim: 'slideDown',
			changeMonth: true,
			changeYear: true,
			closeText: 'Zavřít',
			prevText: '&#x3c;Dříve',
			nextText: 'Později&#x3e;',
			currentText: 'Nyní',
			monthNames: ['leden','únor','březen','duben','květen','červen',
        	'červenec','srpen','září','říjen','listopad','prosinec'],
			monthNamesShort: ['leden','únor','březen','duben','květen','červen',
        	'červenec','srpen','září','říjen','listopad','prosinec'],
			dayNames: ['neděle', 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota'],
			dayNamesShort: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
			dayNamesMin: ['ne','po','út','st','čt','pá','so'],
			weekHeader: 'Týd',
			dateFormat: 'dd.mm.yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			dateFormat: 'dd.mm.yy',
			showButtonPanel: true,
			showOtherMonths: true, 
			selectOtherMonths: true,
			showWeek: true
		});
}

function datePicker2(id,min_date,max_date){
	
		$('#'+id).datepicker({
			showAnim: 'slideDown',
			changeMonth: true,
			changeYear: true,
			closeText: 'Zavřít',
			prevText: '&#x3c;Dříve',
			nextText: 'Později&#x3e;',
			currentText: 'Nyní',
			monthNames: ['leden','únor','březen','duben','květen','červen',
        	'červenec','srpen','září','říjen','listopad','prosinec'],
			monthNamesShort: ['leden','únor','březen','duben','květen','červen',
        	'červenec','srpen','září','říjen','listopad','prosinec'],
			dayNames: ['neděle', 'pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', 'sobota'],
			dayNamesShort: ['ne', 'po', 'út', 'st', 'čt', 'pá', 'so'],
			dayNamesMin: ['ne','po','út','st','čt','pá','so'],
			weekHeader: 'Týd',
			dateFormat: 'dd.mm.yy',
			firstDay: 1,
			isRTL: false,
			showMonthAfterYear: false,
			dateFormat: 'dd.mm.yy',
			showButtonPanel: true,
			showOtherMonths: true, 
			selectOtherMonths: true,
			showWeek: true,
			showOn: "both",
			buttonImage: "/system/img/calendar_sm.png",
			buttonImageOnly: false,
			minDate: min_date,
			maxDate: max_date,
			yearRange: '-100:+1',
			showWeek: false
		});
}

function countPricesFromDop(){
	
	var changedInput = changed.name;
	var doporucena = $("#priceDop").val();
	var procento = $("#procento").val();
	var marze = $("#marze").val();
	var sleva = $("#sleva").val();
	var price = $("#price").val();
	var priceNak = $("#priceNak").val();
	var priceNakNoVat = $("#priceNakNoVat").val();
	var priceExt = $("#priceExt").val();
	var vyslednaCena = $("#vyslednaCena").val();
	
	if(priceExt!=""){
		priceExt = parseFloat(priceExt);
	}else{
		priceExt = 0;
	}	
	
	if(price!=""){
		price = parseFloat(price);
	}else{
		price = 0;
	}	
	
	if(changedInput=='priceDop'){
		
		if(marze!=""){
			var priceNak = Math.round(doporucena / ((marze /100)+1));
			$("#priceNak").val(priceNak);
			$("#priceNakNoVat").val(Math.round(priceNak/1.2));
		}
		
		if(procento!=''){
			
			var price = Math.round(doporucena*(( 100- procento )/100));
			
			$("#price").val(price);		
		}		
	}	
	
	if(changedInput=='priceNakNoVat'){
		var priceNak = Math.round(priceNakNoVat*1.2);
		$("#priceNak").val(priceNak);
	}
	
	if(changedInput=='priceNak'){
		var priceNakNoVat = Math.round(priceNak/1.2);
		$("#priceNakNoVat").val(priceNakNoVat);
	}
	
	if(changedInput=='priceExt'){

	}
	
	if(changedInput=='procento'){
		var price = Math.round(doporucena*(( 100- procento )/100));
		$("#price").val(price);		
		createCookie('procento',procento,365);	
	}
	
	if(changedInput=='marze'){
		var priceNak = Math.round(doporucena / ((marze /100)+1));
		$("#priceNak").val(priceNak);
		$("#priceNakNoVat").val(Math.round(priceNak/1.2));
		createCookie('marze',marze,365);
	}	
	

	var zisk = price-priceNak;
	var maxSleva = 100-(Math.round(priceNak/doporucena*1000)/10);
	
	$("#vynos").val(zisk);
	$("#maxSleva").val(maxSleva);

	if(sleva!="" && sleva!=undefined && changedInput!='vyslednaCena'){
		var cenaPoSleve = Math.round(doporucena/100*(100-sleva))+priceExt;
		$("#vyslednaCena").val(cenaPoSleve);
		$("#vynosPoSleve").val(Math.round(cenaPoSleve-priceNak));
	}else if(changedInput!='vyslednaCena'){
		var vyslednaCena = (price+priceExt);
		$("#vyslednaCena").val(vyslednaCena);
		$("#vynosPoSleve").val(zisk);
	}else if(changedInput=='vyslednaCena'){
		if(price!="" && priceExt==""){
			var priceExt = vyslednaCena-price;
			$("#priceExt").val(priceExt);
		} else if (priceExt!="" && price==""){
			var price = vyslednaCena-priceExt;
			$("#price").val(price);
		} else {
			var price = vyslednaCena-priceExt;
			$("#price").val(price);			
		};
		var zisk = price-priceNak;
		$("#vynosPoSleve").val(zisk);

	}
	
	if(zisk<=0){
		colorRed('vynosPoSleve');
	}else if(zisk>0){
		colorGreen('vynosPoSleve');
		
	}
}

function openUrlInCbox(object,url){
	if(object.value!=""){
		$.fn.colorbox({iframe:true, 
							preloading:true, 
							overlayClose:false, 
							initialWidth:0, 
							initialHeight:0, 
							innerWidth:150, 
							innerHeight:150, 
							maxHeight:"90%", href:url+object.value});
	}
}

function openUrlInCbox2(id,url){
	var idVal = $("#"+id).val();
	var itemHref = url+idVal;
	if(idVal!=""){
		$.fn.colorbox({iframe:true, 
							preloading:true, 
							overlayClose:false, 
							initialWidth:0, 
							initialHeight:0, 
							innerWidth:150, 
							innerHeight:150, 
							maxHeight:"90%", 
							href:itemHref});
	} else {
		alert("Nejdříve vyber položku!");
	}
}

var sekunda = new Array();
var timer = new Array();

function doTimer(blockID)
{
sekunda[blockID] = 0;
timedCount(blockID);
}


function timedCount(blockID)
{

	sekunda[blockID]=sekunda[blockID]+1;
	
	if(sekunda[blockID]==$("#autoNextBlock"+blockID+"Interval").val()) {
		sekunda[blockID] = 0;
		clearTimeout(timer[blockID]);
		$("#countDown"+blockID).val(sekunda[blockID]);
		if($("#autoNextBlock"+blockID+"Type").val()=="") {
			slideContent('block'+blockID,$("#autoNextBlock"+blockID+"Link").val());
		}
		
		if($("#autoNextBlock"+blockID+"Type").val()!="") {
		slideContent('block'+blockID,$("#autoNextBlock"+blockID+"Link").val(),'previous',$("#autoNextBlock"+blockID+"Type").val(),$("#autoNextBlock"+blockID+"Speed").val(),$("#autoNextBlock"+blockID+"Easing").val(),true);
		}
	
	}else{
		$("#countDown"+blockID).val(sekunda[blockID]);
		timer[blockID]=setTimeout("timedCount("+blockID+")",1000);
		
	};
	
	
}

function stopCount(blockID)
{
clearTimeout(timer[blockID]);
sekunda[blockID] = 0;
$("#countDown"+blockID).val(0);
}

function loadItemXML(xmlFile,onSuccess,object){
	var varList = [];
    var i = 0;
        // Get data and parse it into an array
	$("#content-inside").prepend("<div id='loading' style='position:absolute; top:70px; color:white; right:30%; background-color:red; padding:3px;'>Nahrávám ceny</div>");
    $.ajax({
    	type: "GET",
        url: xmlFile+object.value,
        dataType: "xml",
		cache: false,
        success: function(xml) {
           $(xml).find('record').each(function() {
                $(this).children().each(function(){
					varList[$(this)[0].tagName] = $(this).text();
		
				});
            }); //close each
			$("#content-inside").find("#loading").remove();
			updatePrices(varList);
        },
		error:  function(xml) {alert("Chyba načtení dat!");
		}
    });

}

function updatePrices(array) {
    // this code runs when the ajax call is complete
	var delka = 0;
	for (var object in array) {
	delka++;
	}
	
	var prices = [];
	var specstring=array["specPromText"];
	var specstringarr=specstring.split("#");
	var specPrices = false;
	
	for (keyVar in specstringarr) {
		var specString = specstringarr[keyVar];
		var specStringArr = specString.split("=>");
		
		if(specStringArr[0]=="specialPrices"){
			var specPrices = specStringArr[1];
		}
	}
	
	if(specPrices!=false){
	var specpricesarr=specPrices.split("|");	
	
		for (keyVar in specpricesarr) {
			var valueString = specpricesarr[keyVar];
			var valueStringArr = valueString.split("=");
			var itemOblast=array["forLocality"];
			var itemCategoryArr=itemOblast.split(",");
	
			var s = valueStringArr[0];
			var r = s.match(/[\d\.]+/g);
			
			if(r!=null){
				var promNameNew = valueStringArr[0].substr(0,valueStringArr[0].length-r[0].length);
				if(inArray(r[0], itemCategoryArr)){
					if(prices[promNameNew]==null){
					prices[promNameNew] = valueStringArr[1];
					
					}
				}
			}
		}
	}
	
	var delkaPrice = 0;
	for (var object in prices) {
	delkaPrice++;
	}	
	
	if(delkaPrice == 0){
		var info = "nejsou data";
		
		$("#price").val(info);
		$("#priceDop").val(info);
		$("#priceNak").val(info);
		$("#priceExt").val(info);
		$("#vynosPoSleve").val(info);
		$("#vyslednaCena").val(info);
		$("#maxSleva").val(info);
			
	} else {
	$("#price").val("");
	$("#priceDop").val(prices["price"]);
	countPricesFromDop(document.getElementById("priceDop"));
	$("#priceNak").val(prices["priceMin"]);
	countPricesFromDop(document.getElementById("priceNak"));
	$("#priceExt").val(prices["priceDopr"]);
	countPricesFromDop(document.getElementById("priceExt"));
	
	}
};

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

function toggleMenu(toggleFrame,toggleClss){

			$(toggleFrame+" .toggleElement").click(function() {
                $(toggleFrame+" .toggleContent").slideToggle('fast');
				$(toggleFrame+" .toggleElement").toggleClass(toggleClss);
            });
			
			$("div"+toggleFrame).mouseup(function() {
				return false
			});
			
			$(document).mouseup(function(e) {
				if($(e.target).parent("a"+toggleFrame).length==0) {
					$(toggleFrame+" .toggleElement").removeClass(toggleClss);
					$(toggleFrame+" .toggleContent").hide();
				
				}
			});
}

