
function load_document(webpage, language) {
		$('#webpage_document_edit').load('modules/ajax/webpage_document_edit.php', { webpage_id : webpage, language_id : language}, function(){																															
				$('#webpage_tab_container > ul').tabs('select', 1);																															
				});
		}
		

function add_folder(id) {
	
		var foldername = prompt("Enter a name for the folder");
			if(foldername) {
			$("#container").load("modules/navigation.php", {parent : id, name : foldername })
			
			}
	
		}
		

function delete_folder(id) {
		var foldername = confirm("Are you sure you want to delete this folder");
			if(foldername) {	
			$("#container").load("modules/navigation.php", {deletefolder : id })
			}
	
		}
function delete_webpage(id) {
		
				
				var document_name = $("#page-"+id).html();
				var webpage = $.prompt("<h1>Delete webpage ?</h1><br> <br>" + document_name  + "<br><br>Deleted webpage remain in the trash and can be recovered until you empty the trash.",
				{callback: mycallbackfunc,
			 buttons: { Cancel: false, Delete: true }
				}).corner();
			
			
				 function mycallbackfunc(v,m){
				 if(v) { $("#confirmation").load("modules/ajax/webpage_action.php", {remove : id});}	
				}
				
			}
		
		
function delete_media_attachment(id, matrix,name, page_id) {
			
			var webpage = $.prompt("<h1>Delete or remove flash movie ?</h1><br>" + name +"<br><br>You have the option to remove the file from this playlist but keep it in the media manager or delete it altogether.",
			{callback: mycallbackfunc2,
     		 buttons: { Cancel: false, Delete: 1, Remove : 2 }
			}).corner();
			
			 function mycallbackfunc2(v,m){
			if(v == 1) {  
				$("#webpage_files_wrapper").load("modules/ajax/webpage_attached_files.php", { webpage : page_id, delete_file : id});
				}
			if(v == 2) { 
				$("#webpage_files_wrapper").load("modules/ajax/webpage_attached_files.php", { webpage : page_id, remove_file : matrix});
				}
 			
		 	 //if(v) { $("#confirmation").load("modules/ajax/webpage_action.php", {remove : id});}	
			
			}
			
		}


function edit_attached_flash_video(video,width,height,caption,name,page) {

 var txt = "<h1>Edit video settings</h1>" + name + "<br><br>Height<br><input id='height' value='"+height+"'><br><br>Width<br><input id='width'value='"+width+"'><br><br>Caption<textarea id='caption'>"+caption+"</textarea> ";

 function mycallbackform(v,m){ 
      	var width = m.children('#width').val()
	  	var caption = m.children('#caption').val();
	   	var height =  m.children('#height').val();
		//$.prompt( video + " <hr>"  +width + "<hr> " + height + " <hr>" + caption );
		$("#webpage_files_wrapper").load("modules/ajax/webpage_attached_files.php", { edit : video, v_width : width , v_height : height, v_caption : caption , webpage : page});

	}


$.prompt(txt,{
      callback: mycallbackform,
      buttons: { Cancel: false, Save: true }}).corner(); 
}


function edit_attached_image(image,caption,name,page) {

 var txt = "<h1>Edit Image caption</h1>" + name + "<br><br>Caption<textarea id='caption'>"+caption+"</textarea> ";

 function send_edit_attached_image(v,m){ 
	  	var caption = m.children('#caption').val();
		//$.prompt( video + " <hr>"  +width + "<hr> " + height + " <hr>" + caption );
		//$("#webpage_files_wrapper").load("modules/ajax/webpage_attached_files.php", { edit : image, v_caption : caption , webpage : page});
		prompt('edit image');
	}


$.prompt(txt,{
      callback: send_edit_attached_image,
      buttons: { Cancel: false, Save: true }}).corner(); 
}


function set_website_status(status,page,nav) {
					$('#tab_webpage_articles').load("modules/ajax/webpage_list.php", { navigation: nav, public : status, webpage : page});		
				}


function set_webpage_tab(id) {
	$("#confirmation").load("modules/ajax/webpage_action.php", {tab : id});
	}
	
	
function set_contact_tab(id) {
	$("#confirmation").load("modules/ajax/contact_action.php", {tab : id});
	}

function set_group_tab(id) {
	$("#confirmation").load("modules/ajax/contact_action.php", {group_tab : id});
	}



function new_contact() {
	var txt = "<h1>Create new contact</h1>Since every email can only exist once within the system, please enter first the email of the contact to be created.<br><br>E-mail address of the new contact<br><input id='new_email' style='width:90%; margin-top:10px; margin-bottom:20px'><br><select id='create_user_account'><option value='1'>Create user account</option><option value='0'>Create only contact</option></select><br><br>If you only want to save some contact details, without creating a user account at the same time, leave the checkbox unchecked<br><br>";

 function check_if_email_exists(v,m){ 
      	var width = m.children('#width').val()
	  	var email = m.children('#new_email').val();
	   	var user_account =  m.children('#create_user_account').val();
		//$.prompt( video + " <hr>"  +width + "<hr> " + height + " <hr>" + caption );
		$("#confirmation").load("modules/ajax/contact_action.php", { new_email : email, create_user_account : user_account });
	}

	$.prompt(txt,{
     	 callback: check_if_email_exists,
     	 buttons: { Cancel: false, Create: true }}).corner(); 
	
}



function delete_contact(id) {
	var email = $("#contact_list_email_" + id).html();
	var name = $("#contact_list_name_" + id).html();
	var text = "<h1>Delete contact</h1>Are your sure you want to delete<br><br>"+ name +"<br> " + email+"<br><br>";
	
	var webpage = $.prompt(text,
			{callback: mycallbackfunc,
     		 buttons: { Cancel: false, Delete: true }
			}).corner();
			
			 function mycallbackfunc(v,m){
		 	 if(v) { $("#contact_list").load("modules/ajax/contact_list_all.php", {remove : id});}	
			}
	}


function edit_filesharing_permission(id, user_id) {
	$('#filesharing_edit_permission').load('modules/ajax/filesharing/edit_permission.php', {folder : id, user : user_id});
	}

function edit_filesharing_group_permission(id, group_id) {
	$('#filesharing_edit_permission').load('modules/ajax/filesharing/edit_group_permission.php', {folder : id, group : group_id});
	}


function create_tag() {
	var txt = "<h1>Create new contact</h1><input id='new_tag' style='width:90%; margin-top:10px; margin-bottom:20px'><br><br><br>";
 	function send_new_tag(v,m){
	  	var new_tag = m.children('#new_tag').val();
		//$.prompt( video + " <hr>"  +width + "<hr> " + height + " <hr>" + caption );
		$("#container").load("modules/webpage_categories.php", { create_tag : new_tag });
	}

	$.prompt(txt,{
     	 callback: send_new_tag,
     	 buttons: { Cancel: false, Create: true }}).corner(); 
	
	}
	

function create_category() {
	var txt = "<h1>Create new Category</h1><input id='new_category' style='width:100%; margin-top:10px;'><br>name<br<input id='category_color' style='width:100%; margin-top:10px;'><br>color (e.g. #CC0000)<br><br>description<br><textarea id='category_description' style='width:100%; margin-bottom:20px; height:150px'></textarea><br>";
 	function send_new_category(v,m){
	  	var new_category = m.children('#new_category').val();
		var color = m.children('#category_color').val();
		var caption = m.children("#category_description").val();
		$("#container").load("modules/webpage_categories.php", { create_category : new_category , category_color : color, category_caption : caption});
	}


	$.prompt(txt,{
     	 callback: send_new_category,
     	 buttons: { Cancel: false, Create: true }}).corner(); 
	
	}
	
function set_category_color(id) {
	
	var color = $("#color"+id).val();
	$("#confirmation").load("modules/ajax/webpage_action.php", {category_color : color , category : id});
	
	}
	
function create_new_tag(webpage_id) {
	var name = $("#quicksearch input").val();
	$("#confirmation").load("modules/ajax/webpage_action.php",{new_tag : name, webpage: webpage_id});
	
	}
	

function create_template(){
	
	var txt = "<h1>Create a new module template</h1><input id='new_template' style='width:100%; margin-top:10px;'><br>name<br><br><br>";
 	function create_new_template(v,m){
	  	
		var template = m.children('#new_template').val();
		$("#confirmation").load("modules/ajax/templates_action.php", { new_template : template });
	
		}


	$.prompt(txt,{
     	 callback: create_new_template,
     	 buttons: { Cancel: false, Create: true }}).corner(); 
	}

function edit_tag(tag_id, tag_name) {
	var txt = "<h1>Edit tag</h1><input id='edit_tag' value='"+tag_name+"' style='width:90%; margin-top:10px; margin-bottom:20px'><br><br><br>Please be aware that editing this tag will affect all webpages whith this tag attached";
 	function send_edit_tag(v,m){
	  	var edit_tag = m.children('#edit_tag').val();
		  if(v) { 
				$("#tag_"+ tag_id).html(edit_tag);
				$("#confirmation").load("modules/ajax/categories_action.php", { change_tag : edit_tag, tag : tag_id }); 
			}
	}

	$.prompt(txt,{
     	 callback: send_edit_tag,
     	 buttons: { Cancel: false, Edit: 1 }}).corner();
}

