
function str_replace(search, replace, subject)
{
	var result = "";
	var  oldi = 0;
	for (i = subject.indexOf (search); i > -1; i = subject.indexOf (search, i))
	{
		result += subject.substring (oldi, i);
		result += replace;
		i += search.length;
		oldi = i;
	}
	return result + subject.substring (oldi, subject.length);
}

function convert_and_redirect(string)
{
	location.href= 'mailto:'+str_replace('(zavináč)','@',string);
}

function isDefined(variable) {
	return (!(!( variable||false )))
}


function SetAllCheckBoxes(FormName, FieldName, Source)
{
	if (Source.checked) {
        CheckValue = true;
	} else {
        CheckValue = false;
	}
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function chboxy(FormName, FieldName, Hodnoty, Source)
{
// upravena verze SetAllCheckBoxes pro zaskrnuti jen chboxu s value v array Hodnoty
// IE hack: blbec nechape indexOf
	if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}
// konec hacku
	
	if (Source.checked) {
        CheckValue = true;
	} else {
        CheckValue = false;
	}
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!Hodnoty)
		return;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		for(var i = 0; i < countCheckBoxes; i++) {
			if (Hodnoty.indexOf(parseInt(objCheckBoxes[i].value)) != -1)
				objCheckBoxes[i].checked = CheckValue;
		}
}

// vypocet hodnoty kategorie do db pro ulozeni nekolika hodnot v jedinem cisle
function multicat(FormName, FieldName, saveAsId)
{
	var saveAs = document.getElementById(saveAsId);
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes) {
		saveAs.value = 0;
	} else {
		var out = 0;
		for(var i = 0; i < countCheckBoxes; i++) {
		    if (objCheckBoxes[i].checked) {
		        out = out + Math.pow(2, objCheckBoxes[i].value);
			}
		}
		saveAs.value = out;
	}
}

function prace_onsubmit() {
	multicat('prace', 'kraj[]', 'lokalita-db');
	multicat('prace', 'obor[]', 'obor-db');
	multicat('prace', 'uvazek[]', 'uvazek-db');
	return true;
}

function goToUrl(theUrl) {
	document.location.href = WEBROOT + theUrl;
	return true;
}

function detail_show(id) {
	document.getElementById(id).style.display = 'block';
	return true;
}

function detail_hide(id) {
	document.getElementById(id).style.display = 'none';
	return true;
}

function empty(el) {
	var x = el.value;
	if (x.substring(1,0)==' ') {
	    el.value = '';
	    el.style.color = '#000000';
	}
	return true;
}

	
function changeImage(url) { 
	if (obr = document.getElementById('nejlepsi-zamestnavatel-logo')) {
		obr.src = url;	
	} 
}

// ajax nahrani value pro tag_id
function loadurl(tag_id, dest)	{
	try	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		alert('browser nepodporuje ajax');
	}
	xmlhttp.onreadystatechange = function() {
		triggered(tag_id);
	};
	xmlhttp.open("GET", dest);
	xmlhttp.send(null);
}

function triggered(tag_id) {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		document.getElementById(tag_id).innerHTML = xmlhttp.responseText;
	}
}

//ajax url
function instant_url() {
	//var nadpis = document.getElementById('nadpis').value();
	var kategorie = document.getElementById('kategorie').value;
	var url = document.getElementById('url').value;
	var nadpis = document.getElementById('nadpis').value;
	var dest = 'admin/texty_url_ajax/?kategorie='+escape(kategorie)+'&url='+escape(url)+'&nadpis='+(nadpis);
	//alert(dest);
	loadurl('url-box', dest);
}

$(function(){
	$('a[rel*=lightbox]').lightbox();
	$('a[rel*=lbox]').fancybox();
	
	
	$('#dat_vlozeno').datepicker({
		dateFormat: 'd. m. yy' 
	});

})
/*
function nedokoncena_objednavka() {
	if ()
	alert("nedokončené objednávky naleznete v administraci");
}
function info_zavreni() {
	if (potvrdit_zavreni_var!=true) {
		return true;
	}
	if (confirm("do you really want to close this window \n click ok  to exit; cancel to stop")){
  		return true; 
	}
	//location.href = document.url;
	//history.go(0);
	return false;
} 
*/
