var new_menu_item_index = 1;
var deleted = new Array();

function refresh_menu(menu) {
	window.location.href=window.location.href;
}

function submit_menu_changes(parent_id, type) {
	var list = $(type + '_menu_list_edit');
	var list_postvars = serialize_menu_list(list);
	

	Droppables.remove(type + '_menu_ajax_recycle_bin');
	
	new Ajax.Request('index.php?m=Menu.edit', {
		method: 'post',
		evalScripts: true,
		parameters: '&type=' + type + '&parent_id=' + parent_id + '&action=save&' + list_postvars,
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function serialize_menu_list(list) {
	var result = "";
	
	var elements = list.immediateDescendants();
	
	for (i=0; i<elements.size(); i++) {
		if (elements[i].id.substring(0,3) == 'new') {
			result += "item_order[" + i + "]=-1&";
			result += "item_name[-1]=" + $F('new_item_name') + "&";			
		} else if (elements[i].id.substring(0,4) == 'menu'){
			id = elements[i].id.substring(10);
			result += "item_order[" + i + "]=" + id + "&";
			result += "item_name[" + id + "]=" + $F('item_name_' + id) + "&";
		}
	}	
	
	for (i=0; i < deleted.length; i++) {
		result += "deleted=" + deleted + "&";
	}
	
	return result;
}

function infi_submit_content(id) {
	
	new Ajax.Request('index.php?m=Content.edit', {
		method: 'post',
		evalScripts: true,
		parameters: '&id=' + id + '&action=save&content_text=' + escape($F('content_text')),
		onComplete: function(transport) {
			window.location.href=window.location.href;
		}
	});
		
	return false;
}

function press_enter(username,password) {
	
	if (window.event.keyCode == 13)
		{
		infi_logon(username,password)
		}
}

function infi_logon(username,password) {
	
	new Ajax.Request('index.php?m=login', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=login&login=' + username + '&pass=' + password,
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function osage_email(email) {
	
	new Ajax.Request('index.php?m=email', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=email&email=' + email,
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function osage_achtergrond(achtergrond) {
	
	new Ajax.Request('index.php?m=achtergrond', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=achtergrond&achtergrond=' + achtergrond,
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function infi_logout() {
	new Ajax.Request('index.php?m=logout', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=logout',
		onComplete: function(transport) {
			$('modal_container').update();
			$('modal_container').update(transport.responseText);
		}
	});
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function mm_showhidelayers() { //v6.0
  var i,p,v,obj,args=mm_showhidelayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}