function logout(){

	$.ajax({url:"libs/ajax.Actions.php",type: "post",data:{"action":"logout"},success: function() {

			document.location.href="index.php?p=home&lang="+lang;

		}

	});
}

function fancy(){

	$("a.admin_link").fancybox({
				'autoScale'     	: false,
		        'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'easingIn'		    : 'swing',
				'easingOut'		    : 'swing',
				'autoDimensions'    : true,
				'showNavArrows'     : false,
				'titleShow'         : false,
				'onStart'			:function(){
				
					if(!confirmed_delete) { confirmed_delete=true; return false;} else return true;
					
						
				},
				'onComplete':function(){
					
					if(CKEDITOR.instances.content_text==undefined && $("#content_text").size()>0){
					
						CKEDITOR.replace( 'content_text',
							{
								width : '730',
								filebrowserBrowseUrl : 'ckeditor/filemanager/index.html',
								filebrowserImageBrowseUrl : 'ckeditor/filemanager/index.html',
								filebrowserFlashBrowseUrl : 'ckeditor/filemanager/index.html',
								filebrowserUploadUrl : 'ckeditor/filemanager/connectors/php/filemanager.php',
								filebrowserImageUploadUrl : 'ckeditor/filemanager/connectors/php/filemanager.php?command=QuickUpload&type;=Images',
								filebrowserFlashUploadUrl : 'ckeditor/filemanager/connectors/php/filemanager.php?command=QuickUpload&type;=Flash',

								
								"txtBody":{height:"350", width:"650"},
								
								/*
								 * Style sheet for the contents
								 */
								contentsCss : 'output_xhtml.css',
		
								/*
								 * Core styles.
								 */
								coreStyles_bold	: { element : 'span', attributes : {'class': 'Bold'} },
								coreStyles_italic	: { element : 'span', attributes : {'class': 'Italic'}},
								coreStyles_underline	: { element : 'span', attributes : {'class': 'Underline'}},
								coreStyles_strike	: { element : 'span', attributes : {'class': 'StrikeThrough'}, overrides : 'strike' },
		
								coreStyles_subscript : { element : 'span', attributes : {'class': 'Subscript'}, overrides : 'sub' },
								coreStyles_superscript : { element : 'span', attributes : {'class': 'Superscript'}, overrides : 'sup' },
		
								/*
								 * Font face
								 */
								// List of fonts available in the toolbar combo. Each font definition is
								// separated by a semi-colon (;). We are using class names here, so each font
								// is defined by {Combo Label}/{Class Name}.
								font_names : 'Comic Sans MS/FontComic;Courier New/FontCourier;Times New Roman/FontTimes',
		
								// Define the way font elements will be applied to the document. The "span"
								// element will be used. When a font is selected, the font name defined in the
								// above list is passed to this definition with the name "Font", being it
								// injected in the "class" attribute.
								// We must also instruct the editor to replace span elements that are used to
								// set the font (Overrides).
								font_style :
								{
										element		: 'span',
										attributes		: { 'class' : '#(family)' },
										overrides	: [ { element : 'span', attributes : { 'class' : /^Font(?:Comic|Courier|Times)$/ } } ]
								},
		
								/*
								 * Font sizes.
								 */
								fontSize_sizes : 'Smaller/FontSmaller;Larger/FontLarger;8pt/FontSmall;14pt/FontBig;Double Size/FontDouble',
								fontSize_style :
									{
										element		: 'span',
										attributes	: { 'class' : '#(size)' },
										overrides	: [ { element : 'span', attributes : { 'class' : /^Font(?:Smaller|Larger|Small|Big|Double)$/ } } ]
									} ,
		
								/*
								 * Font colors.
								 */
								colorButton_enableMore : false,
		
								colorButton_colors : 'FontColor1/FF9900,FontColor2/0066CC,FontColor3/F00',
								colorButton_foreStyle :
									{
										element : 'span',
										attributes : { 'class' : '#(color)' },
										overrides	: [ { element : 'span', attributes : { 'class' : /^FontColor(?:1|2|3)$/ } } ]
									},
		
								colorButton_backStyle :
									{
										element : 'span',
										attributes : { 'class' : '#(color)BG' },
										overrides	: [ { element : 'span', attributes : { 'class' : /^FontColor(?:1|2|3)BG$/ } } ]
									},
		
								/*
								 * Indentation.
								 */
								indentClasses : ['Indent1', 'Indent2', 'Indent3'],
		
								/*
								 * Paragraph justification.
								 */
								justifyClasses : [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull' ],
		
								/*
								 * Styles combo.
								 */
								stylesSet :
										[
											{ name : 'Strong Emphasis', element : 'strong' },
											{ name : 'Emphasis', element : 'em' },
		
											{ name : 'Computer Code', element : 'code' },
											{ name : 'Keyboard Phrase', element : 'kbd' },
											{ name : 'Sample Text', element : 'samp' },
											{ name : 'Variable', element : 'var' },
		
											{ name : 'Deleted Text', element : 'del' },
											{ name : 'Inserted Text', element : 'ins' },
		
											{ name : 'Cited Work', element : 'cite' },
											{ name : 'Inline Quotation', element : 'q' }
										]
										
							});

					}

					
				if(CKEDITOR.instances.event_text==undefined && $("#event_text").size()>0){
					
					
					CKEDITOR.replace( 'event_text',
					{
						width : '270',
						contentsCss : 'output_xhtml.css',
						toolbar:"Basic",
						coreStyles_bold	: { element : 'span', attributes : {'class': 'Bold'} },
						coreStyles_italic	: { element : 'span', attributes : {'class': 'Italic'}},
						coreStyles_underline	: { element : 'span', attributes : {'class': 'Underline'}},
						coreStyles_strike	: { element : 'span', attributes : {'class': 'StrikeThrough'}, overrides : 'strike' },

	

					});
					
				}
				
				fancy();

				},
				"onCleanup":function(){
					
					if($("#content_text").size()>0 && CKEDITOR.instances.content_text!=undefined ){
					
						CKEDITOR.instances.content_text.destroy();
						
					}
					
					
					if($("#event_text").size()>0 && CKEDITOR.instances.event_text!=undefined ){
					
						CKEDITOR.instances.event_text.destroy();
						
					}
				}
})

}

var config = {
		toolbar:[['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],['UIColor']]
};


function reload(){

	$.ajax({type:"post",url:window.location.href,data:{"type":"ajax"},success:function(response){
	
			$(".site").html(response);
			
			 init_admin();
			 
			 resize_content();
			
			$.fancybox.hideActivity();
			
			$.fancybox.close();
		
	}})
	
}

function setTinyAdvanced()
{

	tinyMCE.init({

		mode: "textareas",

		theme : "advanced",

		// Theme options
		plugins : "filemanager,safari,pagebreak,style,table,advimage,advlink,inlinepopups,preview,media,contextmenu,paste,fullscreen,visualchars,nonbreaking,xhtmlxtras",

		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontsizeselect,styleselect,moveforward,movebackward,absolute,cut,copy,paste,bullist,numlist,|,outdent,indent,|,undo,redo",

		theme_advanced_buttons2 : "link,unlink,image,code,|,forecolor,backcolor,|,tablecontrols,|,removeformat,|,sub,sup,|,media",

		theme_advanced_toolbar_align : "left",

		theme_advanced_toolbar_location : "top",

		theme_advanced_toolbar_align : "left",

		theme_advanced_resizing : false,

		auto_reset_designmode : true,

		content_css : "css/tinymce.css",

		// Example content CSS (should be your site CSS)

 		width : "750",

 		height : "300"

		// Drop lists for link/image/media/template dialogs

	});
}


function get_order(page_id,parent_id){
	
	$.fancybox.showActivity();
								
	$.ajax({type:"post",data:{"parent_id":parent_id,"page_id":page_id,"action":"get_order"},url:"libs/ajax.Actions.php",success:function(data){
								
		$("#page_order").html(data);
	
		$.fancybox.hideActivity();
									
	}});
								
}

function get_new_order(parent_id){
	
	$.fancybox.showActivity();
								
	$.ajax({type:"post",data:{"parent_id":parent_id,"action":"get_new_order"},url:"libs/ajax.Actions.php",success:function(data){
								
		$("#page_order").html(data);
	
		$.fancybox.hideActivity();
									
	}});
								
}
