



function DisplayHide(idElement) {

	if (document.getElementById(idElement).style.display == 'none') {
		document.getElementById(idElement).style.display = 'block';
	}
	else {
		document.getElementById(idElement).style.display = 'none';
	}

}

//#######################################################
/* BAR ADMIN */
var SousMenuPrecedent = null;

function Montrer(Div) {

	if (SousMenuPrecedent == null) {
		SousMenuPrecedent = Div;
		document.getElementById(Div).style.display = 'block';
	}
	else {
		if (SousMenuPrecedent != Div) {
			document.getElementById(SousMenuPrecedent).style.display = 'none';
			document.getElementById(Div).style.display = 'block';
		}
		/*else
		{
		if(document.getElementById(SousMenuPrecedent).style.display == 'block')
		{
		document.getElementById(Div).style.display = 'none';
		}
		else
		{
		document.getElementById(Div).style.display = 'block';
		}
		}*/
		SousMenuPrecedent = Div;
	}

}

//Redimensionner la barre admin
try {
	$('BarreAdmin').style.width = $('container').getDimensions().width + "px";
}
catch (error) { }

//Afficher le brouillon et cacher l'original
function ShowDraftMethod(div, draft) {
	//if (Chargement == true){

	if ($(div).style.display == "")
		$(div).style.display = "block";

	if ($(div).style.display == "block") {
		$(draft).style.display = "block";
		$(div).style.display = "none";
		$("draftValueSelected").value = "1";
	}
	else {
		$(draft).style.display = "none";
		$(div).style.display = "block";
		$("draftValueSelected").value = "0";
	}
	ViewClassButton(".draftToolbar");

	/*Affichage ToolbarDraft
	if($("draftValueSelected").value == "0")
	{
	ViewClassButton(".draftToolbar");
	}
	else
	{
	ViewClassButton(".draftToolbar");
	}*/
	//}
}


//Mise en place du wysiwyg
function wysiwyg(ww, source) {

	var el = $$('rade_toolbarWrapper');
	var toolbars = el[0];


	if ($("draftValueSelected").value == "0") {
		source = source + "_content";
	}
	else {
		source = source + "_draft";
	}

	$(ww).show();
	Element.absolutize($(ww));
	Element.clonePosition($(ww), $(source));



	//Ajustement De la zone de contenue
	try {
		var dimDiv = Element.getDimensions($(source));
		//$("RadEditor1Wrapper").style.zIndex = "60";
		$("RadEditor1Wrapper").style.height = $(ww).style.height;
		$("RadEditor1Wrapper").style.width = $(ww).style.width;
		//$("RadEditor1Wrapper").style.height = "200px";
		//$("RadEditor1Wrapper").style.width = dimDiv.width;

		$(ww).style.height = dimDiv.height;
		$(ww).style.width = dimDiv.width;
		// $(ww).style.zIndex = 51;

	}
	catch (err) {

	}


	//Ajustement
	try {
		$(ww).style.top = $(ww).style.top + 10;
		$(ww).style.top = AddPixel($(ww).style.top, 10);
		$(ww).style.left = AddPixel($(ww).style.left, 10);
		$("RadEditor1Wrapper").style.height = AddPixel($("RadEditor1Wrapper").style.height, 10);
	}
	catch (err) {

	}

	var RadEditor1 = $find("RadEditor1");

	//Remplissage
	if ($("draftValueSelected").value == "0") {
		var html = $(source + '_value').innerHTML;

		RadEditor1.set_html(html);
		RadEditor1.pasteHtml($(source + "_content"));
	}
	else {
		RadEditor1.set_html($(source + "_content").innerHTML);
		RadEditor1.pasteHtml($(source + "_content"));

	}






	//Placement de la barre
	try {
		var toolbar = $('RadEditor1Top');
		Element.absolutize(toolbar);
		Element.clonePosition(toolbar, $("Tools_" + numZoneBack + "_" + numBlockBack));
		toolbar.style.width = '618px';
		toolbar.style.height = '60px';
		var l = (toolbar.style.left.replace('px', '') * 1) + 25;
		toolbar.style.left = l + 'px';
		var t = (toolbar.style.top.replace('px', '') * 1) + 60;
		toolbar.style.top = t + 'px';
	}
	catch (e) { }




	try {
		//Champ caché pour connaitre le div pour la MAJ
		$("ZoneComeIn").value = source;
		//Fond de IFrame
		$('RadEditor1_contentIframe').contentDocument.body.style.backgroundColor = "White";
	}
	catch (err) {

	}


}


//Bouton close
function HideWysiwygZone() {

	//$("ZoneComeIn").value="default";
	$("wysiwygZone").hide();
	try {
		$('RadEditor1Toolbar0').style.display = "none";
		$('RadEditor1Toolbar1').style.display = "none";
	}
	catch (e) { }
	$("Tools_" + numZoneBack + "_" + numBlockBack).style.display = "none";
	$("block_" + numZoneBack + "_" + numBlockBack).style.border = "0px";
	$("Tools_" + numZoneBack + "_" + numBlockBack).style.display = "none";

}

//Fonction d'ajout de pixel pour modifier une taille
function AddPixel(tailleOriginal, pixelSupp) {
	var temp;
	temp = tailleOriginal.substring(0, tailleOriginal.indexOf("p"));
	temp = (temp * 1) + (pixelSupp * 1);
	temp += "px";
	return temp;
}

//Fonction d'affichage d'une classe particulière
function ViewClassButton(cssClass) {
	var listbutton = $$(cssClass);
	for (i = 0; i < listbutton.length; i++) {
		var button = $(listbutton[i].id);
		if ($(button.id).style.display == "block") {
			$(button.id).style.display = "none";
		}
		else {
			$(button.id).style.display = "block";
		}
	}
}


//AFFICHAGE DE LA TOOLBAR DANS UN BLOCK
var numZoneBack = null;
var numBlockBack = null;

function ViewBlock(numZone, numBlock) {
	//Si c'est dans la zone ou on a cliqué on affiche
	if (numZone == exZone) {
		//TODO Caché le reste de la page avec 4 div
		try {

			$("Tools_" + numZoneBack + "_" + numBlockBack).style.display = "none";
			$("wysiwygZone").hide();
			$('RadEditor1Toolbar0').style.display = "none";
			$('RadEditor1Toolbar1').style.display = "none";
		}
		catch (err) { }

		if (choice == 0) {
			try {
				if ((numZoneBack != null) & (numBlockBack != null)) {
					$("block_" + numZoneBack + "_" + numBlockBack).style.border = "0px";
					$("Tools_" + numZoneBack + "_" + numBlockBack).style.display = "none";
				}
				$("block_" + numZone + "_" + numBlock).style.border = "dotted 2px red";
				$("Tools_" + numZone + "_" + numBlock).style.display = "block";

				//Placement au dessus du DIV
				Element.clonePosition($('Tools_' + numZone + '_' + numBlock), $('block_' + numZone + '_' + numBlock));
				//$("Tools_"+numZone+"_"+numBlock).style.zIndex = "40";
				$("Tools_" + numZone + "_" + numBlock).style.width = "690px";
				$("Tools_" + numZone + "_" + numBlock).style.height = "140px";
				/*MODIFI NICOLAS BERGER*/
				var nb = parseInt($("Tools_" + numZone + "_" + numBlock).style.width);
				nb = screen.width * 0.5 - nb * 0.5
				$("Tools_" + numZone + "_" + numBlock).style.left = nb + "px";
				$("Tools_" + numZone + "_" + numBlock).style.marginLeft = "0px";
				/*FIN MODIF*/

				numZoneBack = numZone;
				numBlockBack = numBlock;
			}
			catch (err) { }
		}

		//On affiche le wysiwyg directement
		wysiwyg("wysiwygZone", "block_" + numZone + "_" + numBlock);
	}
}


//-1 = AUCUN
//0 = TEXTE
var choice = -1;
var exZone = null;
//Choix d'édition
function EditChoice(choiceValue, numZone) {
	choice = choiceValue;
	try {
		if (exZone != null) {
			$("ZONE_" + exZone).style.border = "dashed 1px black";
		}
		exZone = numZone;
		$("ZONE_" + numZone).style.border = "dashed 1px yellow";
	}
	catch (err) { }
}

//Dessin le contour des zones
function DrawZone(zone) {
	try {
		$("ZONE_" + zone).style.border = "dashed 1px black";
	}
	catch (err) { }
}


//Redimensionement d'une zone
//taille pour les TD de 0% ou 0px
var minwidth = "44px";
function ChangeWidthZone(zone, admin, update) {
	try {
		var width = $("width_" + zone).value;
		$("TD_ZONE_" + zone).style.width = width;

		if ((width == "0px") || (width == "0%") || (width == "0")) {
			if (admin) {
				$("TD_ZONE_" + zone).style.display = "block";
				$("TD_ZONE_" + zone).style.width = minwidth;
			}
			else {
				$("TD_ZONE_" + zone).style.display = "none";
			}
		}

		if (update) SaveZoneWidths();
	}
	catch (err) {
		//alert(err);
	}
}
//AJAX pour le redimensionement
function SaveZoneWidths() {
	var params = 'WebpageGUID=' + escape(WebpageGUID);
	var textboxes = $$('.tbxZoneWidth');
	for (var i = 0; i < textboxes.length; i++) {
		var zoneNumb = textboxes[i].id.split('_')[1];
		var width = escape(textboxes[i].value);
		params += '&w' + zoneNumb + '=' + width;
	}
	new Ajax.Request("ajaxbridges/savezonewidth.aspx", {
		method: 'post',
		parameters: params,
		onSuccess: function (resp) {
			var result = resp.responseText;
		}
	});
}

//Changement d'image pour le mouseOver
function ChangeImageUrl(img, url) {
	$(img.id).src = url;
}


ChangeWidthZone(1, false, false);
ChangeWidthZone(2, false, false);
ChangeWidthZone(3, false, false);
ChangeWidthZone(4, false, false);
