function AjxRead( url) {
	var ajaxRequest = new AjaxRequest(url); //Create AjaxRequest object
	//ajaxRequest.setPostRequest('hideLoading()');
  ajaxRequest.sendRequest();  //Send the request	
  hideLoading('0');
}

function hideLoading( par) {
	//alert('asdf');
	
	//return '';
	if( par == '1') { 
	  new Effect.Fade("extraDiv2",{duration:.4});
	  //document.getElementById("extraDiv2").style.display = 'none';
	  
	}else{
		document.getElementById("extraDiv2").style.display = 'block';
	}
	
}



function ShowError( obj, img) {
	if ( obj != undefined) {
		obj.style.border = "1px solid red";
	}
	if ( img != undefined) {
		img.style.display = 'inline';
	}
}



function HideError( obj, img ) {
	if ( obj != undefined) {
		obj.style.border = "1px solid #666666";
	}
	if ( img != undefined) {
		img.style.display = 'none';
	}	
}

function ElementHideError(foc, idEl) {
	var docfoc = document.getElementById(foc+'-'+idEl);
	var img = document.getElementById(foc+'-'+idEl+'-img');
	HideError( docfoc, img);
}

function ElementError(foc, idEl) {
	var docfoc = document.getElementById(foc+'-'+idEl);
	var img = document.getElementById(foc+'-'+idEl+'-img');
	ShowError( docfoc, img);
}

function ClearElement(idEl) {
	var sel = document.getElementById(idEl);
	if ( sel != undefined) {
	while (sel.childNodes.length > 0)
    {
      sel.removeChild(sel.childNodes[0]);
    }
    
	}
}

function TruncateElement(idEl) {
	var obj = document.getElementById(idEl);
	var inp = obj.getElementsByTagName("input");
	var i = 0; 
	while (i < inp.length ) {
		if (inp[i].type == 'text') {
			inp[i].value = '';
		}
		i++;
	}
}

function AjxSubmit( idEl) {
	var ajaxRequest = new AjaxRequest('index.php'); //Create AjaxRequest object
	ajaxRequest.addFormElements(idEl);
	//ajaxRequest.addNameValuePair('ajax','true');
	ajaxRequest.setUsePOST();
	ajaxRequest.sendRequest();
	hideLoading('0');
}

function AjxDelete( idEl) {
	if (window.confirm('Naozaj chcete objekt odstrániť?')) {
		AjxSubmit(idEl)
	}
	
}

function ChangeVisible(idEl) {	
	if( Element.getStyle(idEl, 'display') == 'none' ) {
		Element.setStyle(idEl,'block');
	}else{
		Element.setStyle(idEl,'none');
	}
}

function Minize(idEl) {
	if( Element.getStyle(idEl, 'display') == 'none' ) {
		new Effect.Appear(idEl);
		Element.removeClassName($(idEl).parentNode, 'pack');
		Element.addClassName($(idEl).parentNode, 'unpack');
		
		
		$(idEl+"-img").src = "images_ic/arrow_in.png";
	}else{
		Element.setStyle(idEl,{display:'none'});
		Element.addClassName($(idEl).parentNode, 'pack');
		Element.removeClassName($(idEl).parentNode, 'unpack');
		//new Effect.DropOut($(idEl).parentNode);
		//window.setTimeout('Effect.Appear($(\''+idEl+'\').parentNode , {duration:.3})',1000);
		new Effect.Highlight($(idEl).parentNode);
		Cookie.set('minize-'+idEl, 1,20);
		$(idEl+"-img").src = "images_ic/arrow_out.png";
	}
}

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') = '1');
  }
};

function SortList(idEl, idInp, idForm) {
		var item = $(idEl).getElementsByTagName('input');
		var res = '';
		for(var i = 0; i < item.length; i++) {
			if (item[i].name== "order[]") {
				res += item[i].value + '|';
				
			}
		}
		$(idInp).value = res.substr(0,res.length - 1);
		AjxSubmit(idForm);
}
