function edit(id,displayform) {
		new Ajax.Request('/'+id+'/edit/', {
			method:'post',
			parameters: {display: displayform},
			evalScripts:true,
			onSuccess: function(transport)  {
				Element.replace('content'+id,transport.responseText);
			}
		})
}

function cancel(id,displayform) {
	if($('updateform'+id)) {
	new Ajax.Request('/'+id+'/', {
		method:'post',
		parameters: {display: displayform},
		evalScripts:true,
		onSuccess: function(transport)  {
			Element.replace('updateform'+id,transport.responseText);
		}
	});
	}
	// closes modal windows if they are open
	new Element.hide('modalWindow');
    new Element.hide('modalBackgroundDiv');
}

function updatecontent(id) {
	// If the object is menu, we update it and reload the page
	if($('updateform'+id).object && $('updateform'+id).object.value=="menu") {
		$('updateform'+id).submit();
	} // else we update content
	else new Ajax.Request('/'+id+'/', {
		method:'post',
		parameters: $('updateform'+id).serialize(true),
		evalScripts:true,
		onSuccess: function(transport)  {
			Element.replace('updateform'+id,transport.responseText);
		}
	})
	/*new Ajax.Updater('updateform'+id, '/content/'+id+'/update/', { method:'post', 
	parameters: $('updateform'+id).serialize(true)
 	});*/
}

function deletecontent(id) {
	if(window.confirm("Are you sure to delete selected item?")) {
		new Ajax.Request('/'+id+'/', { method:'post', 
		parameters: {method: 'delete'}
	 	});
		new Effect.SwitchOff('content'+id);
	}
}
function moveup(itemid) {
 	new Ajax.Updater('content', '/content/moveup', { method:'post', 
	parameters: {itemid: itemid},
	evalScripts: true
	 });
}
function movedown(itemid) {
	new Ajax.Updater('content', '/content/movedown', { method:'post', 
	parameters: {itemid: itemid},
	evalScripts: true
	 });
}

function getidentifier(id_tree) {
	$('identifierloading').toggle();
	new Ajax.Request('/content/getidentifier/', { 
	parameters: {id: id_tree, name: $('menuname').getValue() },
	onSuccess: function(transport){
		$('permalink').value = transport.responseText
		$('identifierloading').toggle()
	}
 	});
}

/* Opens new window */
function openwindow(url,wid,hei){
    wasOpen  = false;
    win = window.open(url,'','width='+wid+', height='+hei+',top=50,left=200,scrollbars=yes,resizable=yes');    
    return (typeof(win)=='object')?true:false;
  }
function pickpage(target) { // displays modal window
	openModalWindow(400,400);

	new Ajax.Updater('modalWindow', '/content/pickpage/'+target,{
	  evalScripts: true }
	);
}
function pickit(id,wherea) { // displays modal window
	$(id).value = wherea;
	closeModalWindow();
}
function newpage(parent) {
	openModalWindow(500,155);
	new Ajax.Updater('modalWindow', '/'+parent+'/', { method:'post', 
	parameters: {id_tree: parent,object: 'menu'},
	evalScripts: true
	 });
}
function editpage(id) {
	openModalWindow(500,155);
	new Ajax.Updater('modalWindow', '/'+id+'/edit/', { method:'post',
		evalScripts: true
		 });
}
function moveitem(id) { // displays modal window
	openModalWindow(400,400);

	//$('modalWindow').show();	
	//$('modalBackgroundDiv').show();
	new Ajax.Updater('modalWindow', '/content/'+id+'/moveitem/',{
	  evalScripts: true }
	);
}
function move(id,where) { // proceeds move of the item
	new Ajax.Request('/content/move', { method:'post', 
	parameters: {what: id, where: where},
	evalScripts: true
	 });
	
	closeModalWindow();
	window.setTimeOut(window.location.href = '/'+where+'/',3000);
}


/* Modal window */
function openModalWindow(cwidth,cheight) {
	
    var div = $('modalWindow');
    var bgDiv = $('modalBackgroundDiv');

	if(cwidth) div.style.width = cwidth + 'px';
	if(cheight) div.style.height = cheight + 'px';

    var docDim = new Element.getDimensions(document.body);
	//var docDim.height = document.body.getHeight;

    //get the size of the window and calculate where the box should be placed
    var wDim = getBrowserWindowSize();
    var dDim = new Element.getDimensions(div);
	
	
	var viewport_offset = div.viewportOffset(); 
	if (viewport_offset.top < 0) plus = -(viewport_offset.top);
	else plus = 1;
	
       div.style.top =  ((wDim.height - dDim.height) / 2) + 'px'; // plus + ((wDim.height...))
       div.style.left = ((wDim.width - dDim.width) / 2) + 'px';

       if (docDim.height > wDim.height) {
           wDim.height = docDim.height;
       }
	
       //bgDiv.style.width = wDim.width + 'px'; // set by CSS
       bgDiv.style.height = wDim.height + 'px';

	new Element.show(div);
    new Element.show(bgDiv);

	/*
	var viewport_dimensions = document.viewport.getDimensions();
	var container_offset = div.cumulativeOffset();
	var container_dimensions = div.getDimensions();*/
}
function closeModalWindow() {
    new Element.hide('modalWindow');
    new Element.hide('modalBackgroundDiv');
}
function getBrowserWindowSize() {
	
    var winW = 630, winH = 460;
	// Event.observe(window,'resize',this.outOfBoundsPositionHandler);
	
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!=-1) {
            winW = document.documentElement.offsetWidth; // or document.body
            winH = document.documentElement.offsetHeight;
        }
    }

    var rval = {
        width: winW,
        height: winH
    };

    return rval;
}

/* TREE MENU */

function expandmenu(obj,pref) { //v6.0
  var i;
  var obja = obj;
	
   if ((fobj=$(pref+"id_"+obj))!=null && (obimg=$(pref+"ec"+obj))!=null) 
   	{ 
	if(fobj.style.display == "none")
		{
		new Effect.BlindDown(pref+"id_"+obj,{ duration: 0.3 });
		//fobj.style.display="block";
		obimg.src = "/images/admin/colapse.gif";
		document.cookie = obja + "=block;";
		}
	else 
		{
		new Effect.BlindUp(pref+"id_"+obj,{ duration: 0.3 });
		//fobj.style.display="none";
		obimg.src = "/images/admin/expand.gif";
		document.cookie = obja + "=none;";
		}
    }
}
function showtree() // expands tree based on cookies
	{
	//MM_preloadImages('/images/admin/folder1.gif','/images/blank.gif','/images/admin/expand.gif','/images/admin/colapse.gif');
	var cookieList=document.cookie.split("; ");
	for(var i=0; i<cookieList.length; i++)
		{
		var name = cookieList[i].split("=");
	
		if((nobj = $("id_" + name[0]))!=null) nobj.style.display = name[1];
	
		if((obimg=$("ec"+name[0]))!=null)
			{
			if(nobj.style.display == "block") obimg.src="/images/admin/colapse.gif";
			else obimg.src="/images/admin/expand.gif";
			}
		}
	}
function parsecookies(){
	var cookieList=document.cookie.split("; ");
	var cookieArray = new Array();
	for (var i=0; i < cookieList.length; i++){
		var name = cookieList[i].split("=");
		cookieArray[unescape(name[0])] = unescape(name[1]);
		}
	return cookieArray;
	}
//alert('Cookies:' + parsecookies());


var dia = "áäčďéíľĺňóôŕšťúýÁČĎÉÍĽĹŇÓŠŤÚÝŽ";
var nodia = "aacdeillnoorstuyACDEILLNOSTUYZ";

function diaConvert(text) {
   var convertText = "";
   for(i=0; i<text.length; i++) {
      if(dia.indexOf(text.charAt(i))!=-1) {
         convertText += nodia.charAt(dia.indexOf(text.charAt(i)));
      }
      else {
         convertText += text.charAt(i);
      }
   }
   return convertText;
}