

/* jQuery modalBox  */ 



// insert data (ins_data) to modal box 
function modalBox_call_Data(ins_data){
			
				jQuery.fn.modalBox({ 
					directCall : {
						data : ins_data
					}
				});
			
			
			
			}
// insert source block to modal box 
function modalBox_call_Source(insert_page){
				
				jQuery.fn.modalBox({ 
				
					directCall : {
						source : insert_page
						
					}
				});
}
/////////////////////////////////////////////////////////////

// jquery tabs 
function my_tabs(tab_element, content_element ) { 

//When page loads...
$("." + content_element ).hide(); //Hide all content
	$(".ukaz").addClass("active").show(); //Activate first tab
	$(".ukaz").show(); //Show first tab content

	//On Click Event
	$("ul." + tab_element + " li").click(function() {

		$("ul." + tab_element + " li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$("." + content_element ).hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		//$(activeTab).show(); //show active ID content
		
		$(activeTab).fadeIn(400); //Fade in the active ID content
		//$.scrollTo('.tabs_1_container', 0, {offset:0});	
		return false;
	});


}



// hide/show element na zaklade vybratej hodnoty v selekte
	$("select.napln2").livequery('change', function(){ 
	
	var hodnota = $(this).val();
		
		if (hodnota == 1) {
			$('.' + $(this).attr('id')).removeClass('skry');
			}
		else { 
		 	$('.' + $(this).attr('id')).addClass('skry');
		}	
	}); 


// upload image
$("#buttonUpload").livequery('click', function() {
ajaxFileUpload();
});

// del image
$(".del_image").livequery('click', function() {

del_image($(this).siblings('input').val());
});


// limit textarea
function limitChars(textid, limit, infodiv)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#' + infodiv).html((limit - textlength));
		return true;
	}
}



/* disable inputs po check checkbox */


 $("#totozne").livequery('click', function(){  
 
  if($(this).is(':checked'))
       {              
          $('.dis').attr('disabled', 'disabled');
		 		 
       }
  else {

	   $('.dis').removeAttr('disabled');
	  
	  }		   
 
 }); 








/* show/hide element  */
$(".toggle").livequery('click', function() {
	
	var target = this.id; // id prvku
	
	var target_class = $("#" + target ).attr('class').replace('toggle','').split("_")[1]; // vytiahnutie cisla za _ v mene class ( + odstranenie toggle class )
	
	$("." +  target).slideToggle('fast'); 
	
	
	if ( $("#" + target).hasClass('plus_' + target_class) ) {
	
			$("#" + target).removeClass('plus_'  + target_class );
			$("#" + target).addClass('minus_'  + target_class );
	
	} else {
			$("#" + target).removeClass('minus_'  + target_class );
			$("#" + target).addClass('plus_'  + target_class);
	}
	

});






// nacitanie dat po kliknuti na odkaz 


 $(".aj_data").livequery('click', function(){  
 
  var ident = $(this).attr('id'); 
  var hodnota = $(this).attr('value'); 
  
  vs_vyber(ident, hodnota);
  
 // return false;
 
 }); 






// add to parameter do uri

/**
* Add a URL parameter (or changing it if it already exists)
* @param {search} string  this is typically document.location.search
* @param {key}    string  the key to set
* @param {val}    string  value 
*/
var addUrlParam = function(search, key, val){
  var newParam = key + '=' + val,
      params = '?' + newParam;

  // If the "search" string exists, then build params from it
  if (search) {
    // Try to replace an existance instance

    params = search.replace(  new RegExp('([\?&])' + key + '[^&]*'), "$1" + newParam);
	
    // If nothing was replaced, then add the new param to the end
	
    if (params === search) {
      params += '&' + newParam;
    }
  }

  return params;
};


///////////////////////


// formatovanie cisel
function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}










/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// stare funkcie



// ukazanie skryvanie blokov
function showMe (it, box,it2, box2, it3, box3) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;

var vis = (box2.checked) ? "block" : "none";
document.getElementById(it2).style.display = vis;

var vis = (box3.checked) ? "block" : "none";
document.getElementById(it3).style.display = vis;
}

function hiddenMe (it, box, it2, box2, it3, box3) {
var vis = (box.checked) ? "none" : "block";
document.getElementById(it).style.display = vis;

var vis = (box2.checked) ? "none" : "block";
document.getElementById(it2).style.display = vis;

var vis = (box3.checked) ? "none" : "block";
document.getElementById(it3).style.display = vis;
}

// next ukazanie a skrytie 
function init(zobraz)
{
zobrazit(zobraz);
}
function zobrazit(id){
el=document.getElementById(id).style;
el.display=(el.display == 'none')?'block':'none';

}



// hinty pri formularoch

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	
	// repeat the same tests as above for selects
	var selects = document.getElementsByTagName("textarea");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	
	
	
}
addLoadEvent(prepareInputsForHints);
