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 bookmark_us(url, title){

if (window.sidebar) // firefox
    window.sidebar.addPanel(title, location.href, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',location.href);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
} 
else if(document.all)// ie
    window.external.AddFavorite(location.href, title);
}

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: {
					equal: document.getElementById("valValue").value	
				}
		},
		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) {
		   form.submit();
			$("#formErrors").html("Čekejte formulář se odesílá.");
			$("#formErrors").addClass("info-ok");		   
		 },				
		rules: {
				math: {
					equal: document.getElementById("valValue").value	
				}
		},
		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(){	   
	//$("select, input:checkbox, input:radio, input:file").uniform();				   
	initSmoothMenu('smoothmenu1','ddsmoothmenu');
	initSmoothMenu('smoothmenu2','ddsmoothmenu2');
	$(".butt").button();

	initEditForm("myForm");
	
	initAjaxForm("ajaxForm");
	$(".multiselect").multiselect();
	
	
	$(".externalCbox").colorbox({iframe:true, innerWidth:800, innerHeight:550, transition:"none",});
	$(".menuCbox").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:true, 
							initialWidth:0, 
							initialHeight:0, 
							innerWidth:150, 
							innerHeight:150, 
							maxHeight:"80%"});

	$(".helpBox").colorbox({inline:true, href: function(){return $(this).attr('href');}, transition: 'easeOutBack', initialWidth:0, initialHeight:0, innerWidth:300, opacity:0.5});
	
	$(".fotoCbox").colorbox({photo:true, slideshow:true, transition:"elastic", speed:300});
	
	/*$("#bcTarget").barcode("9934567890128", "ean13");  */ 
	
	
/*$.getScript('http://jquery-translate.googlecode.com/files/jquery.translate-1.3.2.min.js', function(){ //when the script is loaded
$.translate(function(){ //when the Google Language API is loaded
$.translate().ui('select', 'option') //generate dropdown
 
 
.change(function(){
$('#translateit').translate( 'en', { //revert to english first
not: 'select, pre'
})
 
.translate( 'en',  $(this).val(), {
not: 'select, pre',
async:  true,
toggle: true,
walk: false
});
})
 .val('Czech') //select English as default
 .appendTo('#topMenu'); //insert the dropdown to the page
});
});
*/
	
});





	

/*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 closeHs() {
 $.fn.colorbox.close();
 }
 
  function loadContent(where,what){
	time = 200;
	//alert(where+" / "+what);
	halftime = (time/2)/1000;
	var inner = document.getElementById(where).innerHTML;
	$("#"+where).html('<div class=\"whiteBack padding3\" style=\"position:absolute; top:0; right:0; width:16px; margin:5px;\"><img src="/system/img/ajax-horizontal.gif"></div>'+inner);
	$("#"+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 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 DoNav(theUrl)
  {
  document.location.href = theUrl;
  }
  

var map = null;
var geocoder = null;

function load() {

if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	geocoder = new GClientGeocoder();
	map.addControl(new GSmallMapControl());

	
	}
	var address = document.getElementById("address").value; 
	if (geocoder) {
	geocoder.getLatLng(
	address,
		function(point) {
			if (!point) {
			alert(address + " not found");
			} else {
			map.setCenter(point, 7);
			var marker = new GMarker(point);
			map.addOverlay(marker);
			/*marker.openInfoWindowHtml(address);*/
			}
		}
	);
	
}
}




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 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
		});
}




