function showSiteWindow(id, userid, navcontainer){
	
	$.ajax({
		url		:	"/sites/new",
		type	: 	"POST",
		data	:	({
			id			: id,
			userid		: userid,
			navcontainer: navcontainer,
			use_ajax	: true,
			showWindow	: true
		}),
		datatype: 'html',
		success : function(data){
			$('#main .content').html(data);
		},
		error: function(data){
			alert('Fehler im Modul!');
		}
	})
}


function sites_edit_bindoptions(){
	$("#module_id-label").detach().appendTo(".site_edit_options");
	$("#module_id-element").detach().appendTo(".site_edit_options");

	$("#submodule_id-label").detach().appendTo(".site_edit_options");
	$("#submodule_id-element").detach().appendTo(".site_edit_options");

	$("#newsletter_submodul").detach().appendTo(".site_edit_options");

	$("#navtitle-label").detach().appendTo(".site_edit_options");
	$("#navtitle-element").detach().appendTo(".site_edit_options");

	$("#subject-label").detach().appendTo(".site_edit_options");
	$("#subject-element").detach().appendTo(".site_edit_options");

	$("#pre_site-label").detach().appendTo(".site_edit_options");
	$("#pre_site-element").detach().appendTo(".site_edit_options");


	$("#visible-label").detach().appendTo(".site_edit_options_visible");
	$("#visible-element").detach().appendTo(".site_edit_options_visible");
	

	$("#Cancel-label").detach().prependTo(".embedded_site .buttons");
	$("#Cancel-element").detach().prependTo(".embedded_site .buttons");

	$("#Speichern-label").detach().prependTo(".embedded_site .buttons");
	$("#Speichern-element").detach().prependTo(".embedded_site .buttons");




	$(".embedded_site #tabs_small_collapsed").detach().prependTo(".embedded_site .zend_form");
	$(".embedded_site .buttons").detach().prependTo(".embedded_site .zend_form");
	
}


function siteSwitchModul(id, userid, module_element, navcontainer){
	var newmoduleid = $(module_element).val();
	
	var navtitle = $('#navtitle').val();
	var subject = $('#subject').val();
	var pre_site = $('#pre_site').val();
	var visible = $('#visible').attr('checked');
	
	$("#main .content").fadeOut().delay(500).html();
	
	$.ajax({
		url		:	"/sites/new",
		type	: 	"POST",
		data	:	({
			id			: id,
			userid		: userid,			
			newmoduleid : newmoduleid,
			navcontainer: navcontainer,
			use_ajax	: true,
			showWindow	: true,
			refresh		: true
		}),
		datatype: 'html',
		success : function(data){
			$('#main .content').html(data).delay(500).fadeIn();
			var tabs = $('#tabs_small_collapsed').tabs();
			tabs.tabs('select',0);
			
			$('#navtitle').val(navtitle);
			$('#subject').val(subject);
			$('#pre_site').val(pre_site);
			if(visible == 'checked')
				$('#visible').attr('checked','checked');
			
		},
		error: function(data){
			alert('Fehler im Modul!');
		}
	})
}



function toggleSiteContent(c){
	if($('.site_content'+c).is(':hidden')){
		$('.site_content'+c).slideDown('slow');
	}else{
		$('.site_content'+c).slideUp('slow');		
	}
}

function sites_remove(id){

		$('#mastersites_container').append("<div id='mastersites_dialog' title='Seite entfernen'>Möchten Sie diese Seite wirklich entfernen?</div>");
		$('#mastersites_dialog').dialog(
		   {"option":"modal",
		   	zIndex: 3999 ,
		   	buttons: {
		   		"Abbrechen": function(){
		   			$(this).dialog("close");
		   		},
		   		"Ok": function(){
		   			$.ajax({
						url		:	"/sites/remove",
						type	: 	"POST",
						data	:	({
							id			: id,
							use_ajax	: true,
							showWindow	: true
						}),
						datatype: 'html',
						success : function(data){
							$('body').html(data);
						},
						error: function(data){
							alert('Fehler im Modul!');
						}
					})
					
		   		}
		   	}
		   }
		)

	
}


function sites_savepositions(arr, userid, navcontainer){
	$.ajax({
		url		:	"/sites/position",
		type	: 	"POST",
		data	:	({
			userid		: userid,
			arr			: arr,
			navcontainer: navcontainer,
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
		}
	})	 
}

function sites_changenavcontainer(id, userid, navcontainer){
	$.ajax({
		url		:	"/sites/changenavcontainer",
		type	: 	"POST",
		data	:	({
			userid		: userid,
			id			: id,
			navcontainer: navcontainer,
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
		}
	})	 
	
}


function sites_incPosition(arr, pos, userid){
	
	tmp = arr[pos+1];
	arr[pos+1] = arr[pos];
	arr[pos] = tmp;
	
	$.ajax({
		url		:	"/sites/position",
		type	: 	"POST",
		data	:	({
			userid		: userid,
			arr			: (arr),
			use_ajax	: true
		}),
		datatype: 'html',
		success : function(data){
			$('body').html(data);
		}
	})	 
}

function sites_decPosition(arr, pos, userid){
	if (pos > 0) {
		tmp = arr[pos - 1];
		arr[pos - 1] = arr[pos];
		arr[pos] = tmp;
		
		$.ajax({
			url: "/sites/position",
			type: "POST",
			data: ({
				userid: userid,
				arr: (arr),
				use_ajax: true
			}),
			datatype: 'html',
			success: function(data){
				$('body').html(data);
			}
		})
	}
}


function sites_setstartseite(siteid, userid){
	$.ajax({
		url		:	"/sites/setstartseite",
		type	: 	"POST",
		data	:	({
			use_ajax	: true,
			userid :  userid,
			siteid	: siteid
		}),
		datatype: 'html',
		success : function(data){
			$('body').html(data);
		},
		error: function(data){
		}
	})	
}


function loadSiteLinks(containername){
	var container_text = '';
	
	if(containername != '')
		container_text = '_'+containername;
		
	$.ajax({
		url		:	"/sites/loadsitesaslink",
		type	: 	"POST",
		data	:	({
			use_ajax	: true,
			containername :  containername
		}),
		datatype: 'html',
		success : function(data){
			$('#divLinkTypeSite'+container_text).html(data);
		},
		error: function(data){
		}
	})
}

