var editorStarted = false ;

function editor_place_on_middle()
{
	var sH = $(window).height() ;
	var sW = $(window).width() ;
	var oH = $("#div_content_editor").height() / 2 ;
	var oW = $("#div_content_editor").width() / 2 ;
	$("#div_content_editor").css('left', (sW / 2) - oW) ;
	$("#div_content_editor").css('top', (sH / 2) - oH) ;
	$("#div_content_editor").slideDown('slow') ;
}

function editor_toogle_content(lng)
{
	var divId = "content_" + lng ;
	$(".div_content_lng").hide() ;
	$("#"+divId).show() ;
}

function editor_close()
{
	$("#div_content_editor").slideUp('slow', function(){
		$("#div_content_editor").html('') ;
	}) ;
}

function editor_check_subscribe_pilote()
{
	var pFName = $("#pil_firstname").val() ;
	var pLName = $("#pil_lastname").val() ;
	var pEmail = $("#pil_email").val() ;
	var pPwd1 = $("#pil_pwd1").val() ;
	var pPwd2 = $("#pil_pwd2").val() ;

	$(".error_msg").hide() ;
	if(pFName == '' || pLName == '' || pEmail == '' || pPwd1 == '' || pPwd2 == '') {
		$("#error_empty").show() ;
	} else {
		if(pPwd1 != pPwd2) {
			$("#error_pwd_equal").show() ;
		} else {
			if(pPwd1.length < 5) {
				$("#error_pwd_short").show() ;
			} else {
				if(!validate_email(pEmail)) {
					$("#error_mail_valid").show() ;
				} else {
					$.ajax({
						url: "/scripts/user_get_email_free.php",
						data: ({email: pEmail}),
						dataType: "json",
						cache: false,
						type: "POST",
						success: function(data) {
							if(data.result == 0) {
								$("#error_mail_exist").show() ;
							} else {
								/* Subscribe de pilote */
								$.ajax({
									url: "/scripts/pilote_subscribe.php",
									data: ({pil_lastname: pLName, pil_firstname: pFName, pil_email: pEmail, pil_pwd1: pPwd1}),
									cache: false,
									type: "POST",
									dataType: "html",
									success: function(data) {
										$("#content_subscribe").hide() ;
										$("#content_subscribed").show() ;	
									}
								}) ;
							}
						}
					}) ;

				}
			}
		}
	}
}


function editor_subscribe_pilote(elem)
{
	$.ajax({
		url: "/editor/pilote_subscribe.php",
		type: "POST",
		dataType: "html",
		cache: false,
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true
			});
		}
	}) ;
}

function editor_edit_pilote(elem, pId)
{
	$.ajax({
		url: "/editor/pilote.php",
		type: "POST",
		data: ({pid: pId}),
		dataType: "html",
		cache: false,
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true
			});
		}
	}) ;
}

function editor_edit_page(p)
{
	$.ajax({
		url: "/editor/content.php",
		type: "POST",
		data: ({page:p}),
		dataType: "html",
		success: function(html) {
			$("#edit_page").overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
	
}

function editor_edit_page_old(p)
{
	$.ajax({
		url: "/editor/content.php",
		type: "POST",
		data: ({page:p}),
		dataType: "html",
		success: function(html) {
			$("#div_content_editor").html(html) ;	
		}
	}) ;		
}

function editor_add_gofly(elem)
{
	$.ajax({
		url: "/editor/gofly.php",
		type: "POST",
		dataType: "html",
		cache: false,
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_edit_gal(g)
{
	$.ajax({
		url: "/editor/gallery.php",
		type: "POST",
		data: ({gal_id:g}),
		dataType: "html",
		success: function(html) {
			$("#div_content_editor").html(html) ;	
		}
	}) ;		
}

function editor_add_gal(elem)
{
	$.ajax({
		url: "/editor/gallery.php",
		type: "POST",
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_add_gal_videos(gId, elem)
{
	$.ajax({
		url: "/editor/gallery_videos.php",
		type: "POST",
		data: ({gal_id : gId}),
		dataType: "html",
		cache: false,
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_add_gal_photos(gId, elem)
{
	$.ajax({
		url: "/editor/gallery_photos.php",
		type: "POST",
		data: ({gal_id : gId}),
		dataType: "html",
		cache: false,
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_edit_gal(gId,elem)
{
	$.ajax({
		url: "/editor/gallery.php",
		type: "POST",
		data: ({gal_id : gId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}


function editor_add_new(elem)
{
	$.ajax({
		url: "/editor/new.php",
		type: "POST",
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_del_gallery(gId,elem)
{
	$.ajax({
		url: "/editor/gallery_del.php",
		type: "POST",
		data: ({gid : gId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_del_gofly(fId,elem)
{
	$.ajax({
		url: "/editor/gofly_del.php",
		type: "POST",
		data: ({fid : fId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_del_event(eId,elem)
{
	$.ajax({
		url: "/editor/event_del.php",
		type: "POST",
		data: ({eid : eId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_edit_event(eId,elem)
{
	$.ajax({
		url: "/editor/event.php",
		type: "POST",
		data: ({event_id : eId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_add_event(elem)
{
	$.ajax({
		url: "/editor/event.php",
		type: "POST",
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_del_pilote(pId,elem)
{
	$.ajax({
		url: "/editor/pilote_del.php",
		type: "POST",
		data: ({pid : pId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_del_new(nId,elem)
{
	$.ajax({
		url: "/editor/new_del.php",
		type: "POST",
		data: ({nid : nId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

function editor_edit_new(nId,elem)
{
	$.ajax({
		url: "/editor/new.php",
		type: "POST",
		data: ({new_id : nId}),
		dataType: "html",
		success: function(html) {
			$(elem).overlay({
				expose: '#1f1f1f',
				effect: 'apple',
				onBeforeLoad: function() {
					var wrap = this.getOverlay().find(".contentWrap");
					wrap.html(html) ;
				},
				load: true

			});
		}
	}) ;		
}

