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

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

function submit_menu_changes(menu,subpage,page) {

	var list = $(menu + '_menu_list_edit');
	var list_postvars = serialize_menu_list(list);
	
	// if (name != '') c = '&c=' + name; else c = ''
	
	Droppables.remove(menu + '_menu_ajax_recycle_bin');
	
	new Ajax.Request('index.php?m=Menu.edit', {
		method: 'post',
		evalScripts: true,
		parameters: '&menu=' + menu + '&s=' + subpage + '&action=save&page=' + page + '&' + 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]=" + escape($F('new_item_name')) + "&";			
		} else {
			id = elements[i].id.substring(10);
			result += "item_order[" + i + "]=" + id + "&";
			result += "item_name[" + id + "]=" + escape($F('item_name_' + id)) + "&";
		}
	}	
	
	for (i=0; i < deleted.length; i++) {
		result += "deleted=" + deleted + "&";
	}
	
	return result;
}

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

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 osage_email(email) {
	new Ajax.Request('index.php?m=email', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=email&email=' + email,
		onComplete: function(transport) {
			$('content_agenda2').update();
			$('content_agenda2').update(transport.responseText);
		}
	});
}

function osage_achtergrond(achtergrond,sub_pagina,hoofd_pagina) {
	
	new Ajax.Request('index.php?m=achtergrond', {
		method: 'post',
		evalScripts: true,
		parameters: '&action=achtergrond&achtergrond=' + achtergrond + '&sub_pagina=' + sub_pagina + '&hoofd_pagina=' + hoofd_pagina,
		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);
		}
	});
}