//javascript trim funkcia
function jsTrim(str) {
	return str.replace(/^\s*|\s*$/g,'');
}

// Prepinanie class tlacitka
function textboxClass(obj, oldClass) {
	if ( !oldClass ) {
		oldClass = "textbox";
	}	
	if ( obj.className == oldClass ) {
		obj.className+= " active";
	} else {
		obj.className = oldClass;
	}
	//obj.blur();
}

//Prepinanie class tlacitka
function buttonClass(obj, oldClass) {
	if ( !oldClass ) {
		oldClass = "button";
	}	
	if ( obj.className == oldClass ) {
		obj.className+= " active";
	} else {
		obj.className = oldClass;
	}
	//obj.blur();
}
// Prepinanie class tr v tabulke
function trClass(obj, oldClass) {
	if ( !oldClass ) {
		oldClass = "riadok";
	}	
	if ( obj.className == oldClass ) {
		obj.className+= " active";
	} else {
		obj.className = oldClass;
	}
	//obj.blur();
}

// Prepinanie tabov
function switchTab(id) {
	//ulozim do pomocnej premennej typ zakaznika
	document.getElementById('hbTypZakazTab').value = id;
	//---------------------------------------+
	// prejdem zalozky, aktivujem/deaktivujem
	//-------------------------------------+
	div = document.getElementById('tabPlusTabulaTab');
	pole = div.getElementsByTagName('li');
	for (i=0; i < pole.length; i++) {
		pole[i].className = 'tab';
	}
	//--------------------------------------+
	// prejtem plochy, aktivujem/deaktivujem
	//-------------------------------------+
	div = document.getElementById('tabPlusTabulaTabula');
	pole = div.getElementsByTagName('div');
	for (i=0; i < pole.length; i++) {
		if ( pole[i].className == 'plocha' ) {
			pole[i].style.display = 'none';
		}
	}
	document.getElementById('t_'+id).className = 'tab_h';
	document.getElementById('t_'+id).blur();
	document.getElementById('p_'+id).style.display = 'block';
	if ( document.getElementById('hlaska') ) {
		document.getElementById('hlaska').style.display = 'none';
	}
	return false;
}

function otvor_obr_okno(img)
{ 	
    picfile = new Image(); 
    picfile.src =(img); 
    kontrolaSuboru(img); 
}
function kontrolaSuboru(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        urobOkno(img); 
    }
    else 
    {
        funzione="kontrolaSuboru('"+img+"')"; 
        intervallo=setTimeout(funzione,50); 
    }
}
function skontroluj_hodnotenie() {
	if ( document.getElementById('tbNazovHodnotenia').value == '' ) {
		window.alert('Názov musí byť vyplnený.');
		document.getElementById('tbNazovHodnotenia').focus();
		return false;
	} else {
		return true;
	}
}
function urobOkno(img)
{ 	
    ht = picfile.height + 20;
    wd = picfile.width + 20; 

    var args= "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
    return window.open(img, '', args); 
} 

function wopen(url, name, height, width, str1) {
       var str = "height=" + height + ",innerHeight=" + height;
       str += ",width=" + width + ",innerWidth=" + width;
	   
	   str += ", "+str1;
	   
	   
       if (window.screen) {
         var ah = screen.availHeight - 30;
         var aw = screen.availWidth - 10;

         var xc = (aw - width) / 2;
         var yc = (ah - height) / 2;

         str += ",left=" + xc + ",screenX=" + xc;
         str += ",top=" + yc + ",screenY=" + yc;
       }
       var win=window.open(url, name, str);
	   win.focus();
	   return win;
}

function buildQuery(id,elementID){
	var filter = document.getElementById(elementID);
	if (filter.value.indexOf(id)!=-1){
			filter.value=filter.value.replace("|"+id,"");
			filter.value=filter.value.replace(id,"");
	} else {
		filter.value+="|"+id;
	}
	if (filter.value[0]=="|")
		filter.value=filter.value.substr(1);
	document.getElementById("filter_form").submit();
}
function goToVyrobca(url) {
	var x = document.getElementById('cbVyrobca');
	var id = x.options.selectedIndex;
	if (x[id].value == "vsetky") {
		url = url + "vyrobca/";
	} else {
		url = url + "vyrobca/" + x[id].value;
	}
	window.location.href = url;
}

$(document).ready(function(){
	$('#taPoznamka').blur(function(){
		$.post(absolutCesta+"ajax.php", {poznamka_kosik:$(this).val()});
	})
});

