function make_fav(linkObj){

	addUrl		= location.href;
	addTitle	= document.title;

	if(document.all && !window.opera){
		window.external.AddFavorite(addUrl,addTitle);
		return false;
	}
	else if (window.opera && window.print){
		linkObj.title = addTitle;
		return true;
	}
	else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')){
		if (window.confirm('Přidat mezi oblíbené?')){
			window.sidebar.addPanel(addTitle,addUrl,'');
			return false;
		}
	}
	window.alert('Bohužel to nejde (kvůli podpoře vašeho prohlížeče). Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.');
	return false;

  // source http://interval.cz/clanky/umoznete-pridat-stranku-k-oblibenym-odkazum/
}

function sure(text, url){
	var doit = confirm(text);
	if(doit === true){
		document.location = url;
	}else{
		return false;
	}
}
function showObj(id){
	if(document.getElementById(id)){
		document.getElementById(id).style.display = 'block';
		if(document.getElementById(id).className == 'allover'){
			fit(id);
		}
	}
}
function hideObj(id){

	if(document.getElementById(id)){
		document.getElementById(id).style.display = 'none';
	}
}
function switchObj(id){

	if(document.getElementById(id)){
		if(document.getElementById(id).style.display == 'block'){
			hideObj(id);
		}else{
			showObj(id);
		}
	}
}
function fit(id){
	obj = document.getElementById(id);
	obj.style.height = (document.getElementsByTagName("body")[0].offsetHeight) + "px";
}


function ajax(url, loc){

    if (url != 0){

		obj = document.getElementById(loc);
		oldclass = obj.className;
		if(obj.className == 'allover'){
			obj.innerHTML = '<div class="loading"></div>';
		}else{
			obj.className = oldclass + " loading";
		}
		if (window.ActiveXObject){
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else{
          httpRequest = new XMLHttpRequest();
        }

        httpRequest.open("GET", url, true);
		httpRequest.onreadystatechange= function () {
			processRequest(loc);
			obj.className = oldclass;
			if(loc == 'cart_tab'){
				showObj("cart_tab_notify");
			}
		};
        httpRequest.send(null);

      }
      else{

        document.getElementById(loc).innerHTML = "";

      }
}

function processRequest(loc){
	if(httpRequest.readyState == 4){
		if(httpRequest.status == 200){
			var mistoZobrazeni = document.getElementById(loc);
			mistoZobrazeni.innerHTML = httpRequest.responseText;
		}else{
			alert("Chyba pri nacitani stanky" + httpRequest.status + ":" + httpRequest.statusText);
			return false;
		}
	}
}


function post_form(form, iframeid, newdivid){
	var iframe = document.getElementById(iframeid);
	var newdiv = document.getElementById(newdivid);

	if(iframe && newdiv){
		cn = newdiv.className;
		newdiv.className = cn + ' loading';
		iframe.onload = function(){
			newdiv.className = cn;
			newdiv.innerHTML = this.contentWindow.document.body.innerHTML;
      return true;
		}

		form.target = iframe.id;
        form.submit();
		return false;
	}

  return true;
}

function hideCartNotification(){
    obj = document.getElementById('cart_tab_notify');
    if(obj){
        setTimeout(function(){ hideObj('cart_tab_notify'); }, 2500);
    }
}

$.fn.sorty = function(){
	$(this).each( function(){
		var id = $(this).attr('id');
		$(this).sortable({ 
			opacity: 0.6,
			cursor: 'move',
			update: function() {
				var order = $(this).sortable("serialize");
				$.post("/eat/sorty/", order, function(theResponse){
					$("#"+id).html(theResponse);
				});
			}
		});
	});
}

