/*************************************************************************************************************************************
**
**   Javascript Ragnarok
**	 Drag & Drop
**   02/07/2007
**	 Version: FireFox
**
************************************************************************************************************************************/
function pageView(page){
//123	_uacct = "UA-3577333-1";
//123	urchinTracker(page);
}
/* Gestion cookie */
var nom_cookie = "ragnarok4";

/* Gestion bloc */
var nbBloc = 8;

/* Langue */
var lang = new Array;

/* Style et backgrounds */
var nbHeader = 2;
var currentHeader;
var currentPerso;
var liste_perso = new Array();
liste_perso[0] = null;
liste_perso[1] = 4;
liste_perso[2] = 2;

/* Infos perso */
var nbPerso = 0;
var cPerso = 1;
var cAjax = false;
$(document).ready(
	function () {
		$(this).floLang({file: 'include/lang/lang.fr.php'}, "timeout");
	}
);

function timeout(){
	setTimeout("chargement()", 300);
}

function majallo(date){
	$('#ladate').html(date);
}

function chargement() {
    //123pageView('/index.php');
    $('#email').focus();
	
	
	$('#bandeaubug').width('100%');
	

   /* if (document.getElementById("floslide_contener")) {
        $('#floslide_contener').floSlide({
            maxHeight: 100,
            ease: "linear"
        });
    } else {
        $('#floslide_contener2').floSlide({
            maxHeight: 60,
            ease: "linear"
        });
    } */

    $('#header_manager').Fisheye({
        maxWidth: 20,
        items: 'a',
        itemsText: 'span',
        container: '.styleManager',
        itemWidth: 22,
        proximity: 35,
        alignment: 'left'
        /*halign : 'center'*/
    });

    /* Raccourcie */
    $('.drag').Draggable({
        opacity: 0.7,
        snapDistance: 10,
        onChange: function() {
            $(this).hide();
            delRaccourciee($(this).attr('rel'));
        }
    });
    $('input.addRaccourcie').click(function() {
        addRaccourciee(this, false);
    });
    $('.sraccourci').click(function() {
        if ($(this).attr("rel") != "raccourci_vide") {
            var e = $(this).attr("rel").split("_");
            openRaccourciee(e[1]);
        }
    });

  //  placeFooter();

    show();

    loadSWF();

	rules();
	
    $('#menu1').rb_menu();

    verifCookies();
    verifModules();

    $("span.edit").each(function(i) {
        setClickable(this, i);
    })


    currentHeader = parseInt($('#bg_niveau').attr('rel'));
    currentPerso = parseInt($('#perso_niveau').attr('rel'));

	$('.table_ranking').click(function(){
		affiche_div('ranking', 950);								   
    });
	
	$('.view_ranking').click(function(){
		affiche_div('ranking', 950);								   
    });
	
	$('.table_CastleWatch').click(function(){
		affiche_div('castlewatch', 963);								   
    });
	
	$('.view_castlewatch').click(function(){
		affiche_div('castlewatch', 963);								   
    });

  $('.table_PriceWatch').click(function(){
		affiche_div('PriceWatch', 964);								   
    });
	
	$('.view_PriceWatch').click(function(){
		affiche_div('PriceWatch', 964);								   
    });
    
    
    $('#bg_prec').click(function() {
		$('#bg_preload').show();
        if (parseInt(currentHeader - 1) >= 1) {
            currentHeader = parseInt(currentHeader - 1);  
        }else{
            currentHeader = parseInt(nbHeader);
		}
		currentPerso = 1;
        style(true, currentHeader);
    });

    $('#bg_suiv').click(function() {
		$('#bg_preload').show();
        if (parseInt(currentHeader + 1) <= nbHeader) {
            currentHeader = parseInt(currentHeader + 1);
        }else{
            currentHeader = parseInt(1);
		}
        currentPerso = 1;
        style(true, currentHeader);
    });

    $('#perso_prec').click(function() {
        $('#perso_preload').show();
		if (parseInt(currentPerso - 1) >= 1) {
            currentPerso = parseInt(currentPerso - 1);   
        }else{
			currentPerso = parseInt(liste_perso[currentHeader]);   
		}
		style(false, currentPerso);
    });

    $('#perso_suiv').click(function() {
        $('#perso_preload').show();
		if (parseInt(currentPerso + 1) <= liste_perso[currentHeader]) {
            currentPerso = parseInt(currentPerso + 1);
        }else{
			currentPerso = parseInt(1);
		}
		style(false, currentPerso);
    });

    $('.styleManager').show();
	
	
	
	$('.nperso').click(function(){
		if(!cAjax){
			cAjax = true;
			nbPerso = parseInt($(this).attr('rel'));
			if(parseInt(cPerso) < parseInt(nbPerso)){
				perso(parseInt(cPerso+1));
			}else{
				perso(parseInt(1));
			}
		}
	});
	
	$('.pperso').click(function(){
		if(!cAjax){
			cAjax = true;
			nbPerso = parseInt($(this).attr('rel'));	
			if(parseInt(cPerso) > parseInt(1)){
				perso(parseInt(cPerso-1));
			}else{
				perso(parseInt(nbPerso));
			}
		}
	});
	
}

function rules(){
	timeflux = setTimeout("Flux(true)", 5000);
	
	$('#flux_prev').click(function(){
		if(!blockflux){
			blockflux = true;
			clearTimeout(timeflux);
			Flux(false);
		}
	});
	
	$('#flux_suiv').click(function(){
		if(!blockflux){
			blockflux = true;
			clearTimeout(timeflux);
			statuflux=true;
			Flux(true);	
		}
	});
	
	$('#flux_pause').click(function(){
		statuflux=false;
	});
	
    $('div.DragDrop').Sortable({
        accept: 'DragDropDiv',
        helperclass: 'DragDrophelper',
        activeclass: 'DragDropactive',
        hoverclass: 'DragDrophover',
        axis: 'horizontally',
        tolerance: 'pointer',
        //containment:	'DragDrop',
        handle: 'input.draggif',
        fx: 400,
        opacity: 0.4,
        floats: true,
        fit: false,
        onChange: serialize
    });


    $('div.DragDrop2').Sortable({
        accept: 'DragDropDiv2',
        helperclass: 'DragDrophelper2',
        activeclass: 'DragDropactive2',
        hoverclass: 'DragDrophover2',
        tolerance: 'pointer',
        //containment:	'DragDrop',
        handle: 'input.draggif',
        fx: 400,
        opacity: 0.4,
        floats: true,
        onStop: serialize2
    });

    $('#news_con').Accordion({
        headerSelector: 'dt',
        panelSelector: 'dd',
        activeClass: 'myAccordionActive',
        hoverClass: 'myAccordionHover',
        panelHeight: 150,
        speed: 300
    });

    $('input.closegif').bind('click', closeblock);	
}

var currentflux=1;
var maxflux=0;
var statuflux=true;
var timeflux=0;
var blockflux=false;
function Flux(type){
	if(statuflux){
		maxflux = parseInt($('#floslide_contener').attr('rel'));
		$('#flux-'+currentflux).fadeOut(150, function(){
			currentflux = (type) ? ((currentflux<maxflux) ? currentflux+1 : 1) : ((currentflux>1) ? currentflux-1 : maxflux);
			$('#flux-'+currentflux).fadeIn(300, function(){ 
				timeflux = setTimeout("Flux(true)", 5000);							 
				blockflux=false;
				if(!type){ statuflux=false; }else{ statuflux=true; }
			});
		});
	}else{
		timeflux = setTimeout("Flux(true)", 5000);
	}
}

function str_replace(txt){
	for(var i=0; i<40; i++){
		txt = txt.replace("&eacute;", "é");
		txt = txt.replace("&egrave;", "è");
		txt = txt.replace("&ecirc;", "ê");
		txt = txt.replace("&agrave;", "à");
		txt = txt.replace("&ocirc;", "ô");
		txt = txt.replace("&ouml;", "ö");
		txt = txt.replace("&iuml;", "ï");
		txt = txt.replace("&ucirc;", "û");
		txt = txt.replace("&lt;", "<");
		txt = txt.replace("&gt;", ">");
	}
	return txt;	
}

function login(){
	$.post('scripts/connection_compte.php', {email: $('#email').val() , password: $('#password').val() }, function(e){ if(e == "oui"){ window.location.href = './'; }else{ alert(unescape(lang['compteErreurIdentifiants'])); } });		
}

function perso(value){
	var current = cPerso;
	
	$('#perso_jpg-'+current).fadeOut(300, function(){
		$('#perso_jpg-'+parseInt(value)).fadeIn(300);
	});
	$('#perso-'+cPerso).fadeOut(300, function(){
		cPerso = parseInt(value);
		$.post("scripts/maj_gid.php", {gid: $('#perso-'+cPerso).attr("rel")}, function(){
			$('#perso-'+cPerso).fadeIn(300, function(){
				$('#stats_perso-'+current).fadeOut(200, function(){
					$('#stats_perso-'+cPerso).fadeIn(200, function(){
						cAjax = false;
					});
 				});
			});
		});
	});
}

function style(type, value){
	if(type){	
		imgPreloader = new Image();
		imgPreloader.onload = function(){				
				$('#bg_niveau').css('background-image', 'url(images/header/header'+value+'/min_ciel.jpg)');
				$('#perso_niveau').css('background-image', 'url(images/header/header'+value+'/min_perso1.jpg)');
				
				$('body').css('background-image', 'url(images/header/header'+value+'/ciel.jpg)');
				$('#personnage').css('background-image', 'url(images/header/header'+value+'/perso1.gif)');
				$('#header_bg').css('background-image', 'url(images/header/header'+value+'/header.gif)');	
				
				EcrireCookie("st[1]", value, 365, "/", "");
				EcrireCookie("st[2]", 1, 365, "/", "");
				
				$('#bg_preload').hide();
			};
		imgPreloader.width = imgPreloader.height = 1;
		imgPreloader.src = "images/header/header"+value+"/header.gif";
		$('#preloader_perso').html(imgPreloader);
	}else{
		imgPreloader = new Image();
		imgPreloader.onload = function(){
				$('#perso_niveau').css('background-image', 'url(images/header/header'+currentHeader+'/min_perso'+value+'.jpg)');
				
				$('#personnage').css('background-image', 'url(images/header/header'+currentHeader+'/perso'+value+'.gif)');
				
				EcrireCookie("st[1]", currentHeader, 365, "/", "");
				EcrireCookie("st[2]", value, 365, "/", "");
				
				$('#perso_preload').hide();
			};
		imgPreloader.width = imgPreloader.height = 1;
		imgPreloader.src = "images/header/header"+currentHeader+"/perso"+value+".gif";
		$('#preloader_perso').html(imgPreloader);
	}
}

function openRaccourciee(e){
	cache_fenetre();
	switch(e){
		case "boutique":
			affiche_div('boutique', 400);
		break;
		
		case "avantage":
			affiche_div('play', 600);
		break;
		
		case "compte":
			affiche_div('compte', 700);
		break;
		
		case "commentjouer":
			affiche_div('play', 300);
		break;
		
		case "faq":
			affiche_div('faqq', 107);
		break;
		
		case "galerie":
			affiche_div('videolarge', 8);
		break;
		
		case "guide":
			affiche_div('guide', 33);
		break;
		
		case "charte":
			affiche_div('charte', 800);
		break;
		
		case "kafra":
			affiche_div('kafra1', 687);
		break;
		
		case "allopass":
			openAllo();
		break;
		
		case "ranking":
			affiche_div('ranking', 950);
		break;
		
		case "rankingPerso":
			affiche_div('rankingPerso', 962);
		break;
		
		case "castlewatch":
			affiche_div('castlewatch', 963);
		break;
    
    case "PriceWatch":
			affiche_div('PriceWatch', 964);
		break;
	}
}

function addRaccourcie(e, type){
	addRaccourciee(e, type);
}

function addRaccourciee(e, type) {
    if (document.getElementById("header_raccourcis")) {


        /* Gestion des cookies */
        if (!type) {
            e = $(e).attr('id').split("-");
            id = e[1];
        } else {
            id = e;
        }

        var hash = "";
        var c = 0;
        var t = 0;
        for (var i = 0; i < 5; i++) {
            if (LireCookie("rac[" + i + "]") != null && LireCookie("rac[" + i + "]") != "undefined") {
                if (LireCookie("rac[" + i + "]") == id) {
                    t++;
                }
                hash += LireCookie("rac[" + i + "]") + "-";
                c++;
            }
        }
        if (c < 5) {
            if (t == 0) {
                hash += id + "-";
            } else {
                alert(unescape(str_replace(lang['raccourciErreurDeja'])));
            }
        } else {
            alert(unescape(str_replace(lang['raccourciErreurTrop'])));
        }

        newHash = hash.split("-");
        for (var i = 0; i < 5; i++) {
            EffacerCookie2("rac[" + i + "]");
        }

        for (var i = 0; i < newHash.length - 1; i++) {
            EcrireCookie("rac[" + i + "]", newHash[i], 365, "/", "");
        }

        /* Gestion des icones */
        if (t == 0) {
            var r = 0;
            for (var i = 1; i < 6; i++) {
                if (r == 0) {
                    var elem = $('#raccourci_' + i);
                    if (elem.attr('rel') == "raccourci_vide") {
                        elem.html('<img src="images/header/nav/ico/' + id + '.jpg" rel="' + id + '" class="drag" title="' + unescape(lang['titleRaccourcis']) + '" width="22" height="23" />');
                        elem.attr('rel', "raccourci_" + id);
                        r++;
                    }
                }
            }
        }

        $('.sraccourci').click(function() {
            if ($(this).attr("rel") != "raccourci_vide") {
                var e = $(this).attr("rel").split("_");
                openRaccourciee(e[1]);
            }
        });
        $('.drag').Draggable({
            opacity: 0.7,
            snapDistance: 10,
            onChange: function() {
                $(this).hide();
                delRaccourciee($(this).attr('rel'));
            }
        });

        $('#nbraccourci').html(parseInt((newHash.length - 1) + 1));

    } else {
        alert(unescape(str_replace(lang['raccourciErreurLog'])));
    }
}

function delRaccourciee(e) {
    var hash = "";
    for (var i = 0; i < 5; i++) {
        if (LireCookie("rac[" + i + "]") != null && LireCookie("rac[" + i + "]") != "undefined") {
            if (LireCookie("rac[" + i + "]") != e) {
                hash += LireCookie("rac[" + i + "]") + "-";
            }
        }
    }

    newHash = hash.split("-");
    for (var i = 0; i < 5; i++) {
        EffacerCookie2("rac[" + i + "]");
    }

    for (var i = 0; i < newHash.length - 1; i++) {
        EcrireCookie("rac[" + i + "]", newHash[i], 365, "/", "");
    }

    var racc = "";
    var ii = 0;
    var hash = "";
    for (var i = 0; i < 5; i++) {
        if (LireCookie("rac[" + i + "]") != null && LireCookie("rac[" + i + "]") != "undefined") {
            ii++;
            hash += '<div class="sraccourci" id="raccourci_' + ii + '" rel="raccourci_' + LireCookie("rac[" + i + "]") + '"><img src="images/header/nav/ico/' + LireCookie("rac[" + i + "]") + '.jpg" rel="' + LireCookie("rac[" + i + "]") + '" class="drag" title="' + unescape(lang['titleRaccourcis']) + '" width="22" height="23" /> </div>';
        }
    }

    var fk = ii;

    if (parseInt(ii + 1) < 6) {
        for (var i = parseInt(ii + 1); i < 6; i++) {
            hash += '<div class="sraccourci" id="raccourci_' + i + '" rel="raccourci_vide"><img src="images/header/nav/ico/rac_vide.jpg" width="22" height="23" /> </div>';
        }
    }

    $('#liste_racc').fadeOut(400,
    function() {
        $('#liste_racc').html('<div class="sraccourci" id="raccourci_allopass" rel="raccourci_allopass"><img src="images/header/nav/ico/allopass.jpg" rel="allopass" width="22" height="23" title="' + unescape(lang['titleAllopass']) + '" alt="' + unescape(lang['titleAllopass']) + '" /></div>' + hash);
        $('#liste_racc').fadeIn(400);
        $('#nbraccourci').html("" + parseInt(fk + 1) + "");

        $('.sraccourci').click(function() {
            if ($(this).attr("rel") != "raccourci_vide") {
                var e = $(this).attr("rel").split("_");
                openRaccourciee(e[1]);
            }
        });
        $('.drag').Draggable({
            opacity: 0.7,
            snapDistance: 10,
            onChange: function() {
                $(this).hide();
                delRaccourciee($(this).attr('rel'));
            }
        });

    });
}
function trim(aString) {
    return aString.replace(/^\s+/, "").replace(/\s+$/, "");
}

var o=0;
function setClickable(obj, i) {
	$(obj).click(function() {
	
	if(o == 0){
		o=1;
		
		if(i == 12){
			var textarea = '<div>';
			var button = '<div><input type="image" src="images/images_fond/general/Bouton_visible.jpg" style="margin-top:2px; width: 75px; height: 18px; border:none" class="saveButton" /> &nbsp;&nbsp;&nbsp;&nbsp; <input type="image" src="images/images_fond/general/Bouton_anonyme.jpg" style="margin-top:2px; width: 75px; height: 18px;border:none" class="cancelButton" /></div>';
			var revert = $(obj).html();
			$(obj).after(textarea+button).remove();
	
			$('.saveButton').click(function(){o=0; saveChangesInfos(this, "oui", i, revert);});
			$('.cancelButton').click(function(){o=0; saveChangesInfos(this, "non", i, revert);});
		}else{
			
		if(i == 11){
			var textarea = '<div>';
			var button = '<div><input type="image" src="images/images_fond/general/Bouton_inscrire.jpg" style="margin-top:2px; width: 64px; height: 19px; border:none" class="saveButton" /> &nbsp;&nbsp;&nbsp;&nbsp; <input type="image" src="images/images_fond/general/Bouton_desinscrire.jpg" style="margin-top:2px; width: 95px; height: 19px;border:none" class="cancelButton" /></div>';
			var revert = $(obj).html();
			$(obj).after(textarea+button).remove();
	
			$('.saveButton').click(function(){o=0; saveChangesNewsletter(this, "oui", i, revert);});
			$('.cancelButton').click(function(){o=0; saveChangesNewsletter(this, "non", i, revert);});
		}else{
			if(i == 1){
			/*	var textarea = '<div style="color:#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;Ancien mot de passe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nouveau mot de passe    &nbsp;&nbsp;Confirmation mot de passe<input type="password" id="nPP" style="width:30%" value="" /> <input type="password" id="nP" value="" style="width:30%" /> <input type="password" id="cP" style="width:30%" value="" />'; */
			var textarea = '<div style="color:#FFFFFF"><input type="text" id="nPP" style="width:30%" value="'+unescape(lang['profilValueAncien'])+'" onfocus="if(this.value==\''+unescape(lang['profilValueAncien'])+'\'){this.value=\'\'}"/> <input type="text" id="nP" value="'+unescape(lang['profilValueNouveau'])+'" style="width:30%" onfocus="if(this.value==\''+unescape(lang['profilValueNouveau'])+'\'){this.value=\'\'}"/> <input type="text" id="cP" style="width:30%" value="'+unescape(lang['profilValueNouveauBis'])+'" onfocus="if(this.value==\''+unescape(lang['profilValueNouveauBis'])+'\'){this.value=\'\'}"/>';
			}
			else if (i == 0){
			var textarea = '<div><input type="text" id="nPP" style="width:30%" value="'+unescape(lang['profilValueAncienEmail'])+'" onfocus="if(this.value==\''+unescape(lang['profilValueAncienEmail'])+'\'){this.value=\'\'}"/> <input type="text" id="nP" value="'+unescape(lang['profilValueNouveauEmail'])+'" style="width:30%" onfocus="if(this.value==\''+unescape(lang['profilValueNouveauEmail'])+'\'){this.value=\'\'}"/> <input type="text" id="cP" value="'+unescape(lang['profilValueNouveauBisEmail'])+'" style="width:30%" onfocus="if(this.value==\''+unescape(lang['profilValueNouveauBisEmail'])+'\'){this.value=\'\'}"/>';
			}
			else if (i == 3){
			var textarea = '<div><input type="text" id="nPP" style="width:30%" value="'+unescape(lang['profilValueJourDdn'])+'" onfocus="if(this.value==\''+unescape(lang['profilValueJourDdn'])+'\'){this.value=\'\'}"/> <input type="text" id="nP" value="'+unescape(lang['profilValueMoisDdn'])+'" style="width:30%" onfocus="if(this.value==\''+unescape(lang['profilValueMoisDdn'])+'\'){this.value=\'\'}"/> <input type="text" id="cP" style="width:30%" value="'+unescape(lang['profilValueAnneeDdn'])+'" onfocus="if(this.value==\''+unescape(lang['profilValueAnneeDdn'])+'\'){this.value=\'\'}"/><input type="hidden" id="DateNaiss" value="'+$(this).html()+'" />';
			}
			else
			{
			var textarea = '<div><input type="text" id="nPP" value="'+$(this).html()+'"/>';
			}
			var button = '<div style="margin-bottom: 5px; clear: right;"><input type="image" src="images/images_fond/general/RAGNAROK_validation_cc.jpg" style="margin-top:2px; width: 76px; height: 20px;border:none" class="saveButton" /> &nbsp;&nbsp;&nbsp;&nbsp; <input type="image" src="images/images_fond/general/RAGNAROK_annulation_cc.jpg" style="margin-top:2px; width: 76px; height: 20px;border:none" class="cancelButton" /></div>';
			
			var revert = $(obj).html();
			$(obj).after(textarea+button).remove();
	
			$('.saveButton').click(function(){o=0; saveChanges(this, false, i, revert);});
			$('.cancelButton').click(function(){o=0; saveChanges(this, revert, i, revert);});
		}
		
		}
	}
	});
}

function saveChangesNewsletter(obj, result, n, z) {
	$.post("scripts/modifInfo.php",{n:n, content:result},function(txt){});
	$(obj).parent().parent().after('<span class="edit">'+result+'</span>').remove();
	setClickable($("span.edit").get(n), n);
}

function saveChangesInfos(obj, result, n, z) {
	$.post("scripts/modifInfo.php",{n:n, content:result},function(txt){
		if(txt == "ok"){ echo = unescape(lang['profilValueVisible']); }else{ echo = unescape(lang['profilValueAnonyme']); }															  		$(obj).parent().parent().after('<span class="edit">'+echo+'</span>').remove();
		setClickable($("span.edit").get(n), n);
	});
}

function saveChanges(obj, cancel, n, z) {
		var t =  $('#nPP').val();
		var t2 = $('#nP').val();
		var t3 = $('#cP').val();
		var t4 = $('#DateNaiss').val();
	
	if(!cancel) {
			$.post("scripts/modifInfo.php",{content: t, n: n, verif: t2, newverif: t3, naissance: t4},function(txt){ if(txt == "ErrComparaisonMail"){ alert(unescape(str_replace(lang['profilErreurEmail'])));}; if(txt == "ErrSessionMail"){alert(unescape(str_replace(lang['profilErreurEmail2'])));};  if(txt == "ErrSessionPass"){alert(unescape(str_replace(lang['profilErreurMdp'])));};  if(txt == "ErrComparaisonPass"){alert(unescape(str_replace(lang['profilErreurMdp2'])));}; if(txt == "ErrPass"){alert(unescape(str_replace(lang['profilErreurMdp3'])));};  if(txt == "ErrZipCode"){alert(unescape(str_replace(lang['profilErreurZip'])));}; if(txt == "MailInvalide"){alert(unescape(str_replace(lang['profilErreurEmail3'])));}; if(txt == "ErrEmailInBase"){ alert(unescape(str_replace(lang['profilErreurEmail4'])));};     });
	} 
	else{
		var t = cancel;
	}
		
		if (n==0){
				var valn = "********"; 
				$(obj).parent().parent().after('<span class="edit">'+valn+'</span>').remove();
				setClickable($("span.edit").get(n), n);
		}
		
		if (n==1){
				var val = "********";
				$(obj).parent().parent().after('<span class="edit">'+val+'</span>').remove();
				setClickable($("span.edit").get(n), n);
		}
		if (n==3){
			if (t=='Jour'||t2=='Mois'||t3=='Année'){
				$(obj).parent().parent().after('<span class="edit">'+t4+'</span>').remove();
				setClickable($("span.edit").get(n), n);
			}
			if (t==''){
				$(obj).parent().parent().after('<span class="edit">'+t4+'</span>').remove();
				setClickable($("span.edit").get(n), n);
			}
			if (t==cancel)
			{
				$(obj).parent().parent().after('<span class="edit">'+t4+'</span>').remove();
				setClickable($("span.edit").get(n), n);
			}
			else{
				var nouvelle = t+"-"+t2+"-"+t3
				$(obj).parent().parent().after('<span class="edit">'+nouvelle+'</span>').remove();
				setClickable($("span.edit").get(n), n);
			}
		}

		if (n==2||n==4||n==5||n==6||n==7||n==8||n==9||n==10||n==11||n==12){
			if (trim(t)==''){
				$(obj).parent().parent().after('<span class="edit">'+"-"+'</span>').remove();
				setClickable($("span.edit").get(n), n);
			}
			else{
				$(obj).parent().parent().after('<span class="edit">'+t+'</span>').remove();
				setClickable($("span.edit").get(n), n);
			}
		}
}


function Resi(){
		if(confirm(unescape(str_replace(lang['profilConfirm'])))){
		if($('#vP').val() == ""){
			alert(unescape(str_replace(lang['profilConfirmErreur'])));
		}
		else if ($('#Em').val() == ""){
			alert(unescape(str_replace(lang['profilConfirmErreur2'])));
		}
		else if($('#Pq').val() == ""){
			alert(unescape(str_replace(lang['profilConfirmErreur3'])));
		}
		else{
		$('#ChampsRes').hide();
		$('#ChampsResDateNaiss').hide();
		$('#ChampsResEmail').hide();
		$('#ChampsResQuitte').hide();
		$('#msgRes').html('');
		$('#StatusRes').html('<img src="images/gif/ajax.gif" />');
		var vz = $('#vP').val();
		var dz = $('#birthday').val() +"-"+ $('#birthmonth').val() +"-"+ $('#birthyear').val();
		var ez = $('#Em').val();
		var pz = $('#Pq').val();
		$.post("scripts/resiliation.php", { secure: "ok", securee: 1, vP: vz, Dn: dz, Em: ez, Pq: pz }, function(data){ 
				if(data == "ok"){ 
					$('#tnc').hide();
						$('#StatusRes').html('<font color="#FFFFFF">'+unescape(lang['profilResiliation'])+'</font>');	
						setTimeout('window.location.replace("index.php")', 2000);																	
				}else{
					if(data == "Err"){
						alert(unescape(str_replace(lang['profilResiliationErreur4'])));
					$('#msgRes').html('<font color="#FFFFFF">'+unescape(lang['profilResiliationErreur'])+'</font><br/><br/>');
					}else if(data == "Err2"){
					$('#msgRes').html('<font color="#FFFFFF">'+unescape(lang['profilResiliationErreur2'])+'</font><br/><br/>');
					}else{
						alert(data);
					$('#msgRes').html('<font color="#FFFFFF">'+unescape(lang['profilResiliationErreur3'])+'</font><br/><br/>'+data);
					}
					$('#ChampsRes').show();
					$('#ChampsResDateNaiss').show();
					$('#ChampsResEmail').show();
					$('#ChampsResQuitte').show();
					$('#StatusRes').html('<a href="#" onClick="return Resi();"><img src="images/images_fond/general/RAGNAROK_validation_cc.jpg" title="'+unescape(lang['profilResiliationTitle'])+'" border="0" /></a>');
				}
			} 
		);	
		}
	}
}


function OubliLogin(){
	if(confirm(unescape(str_replace(lang['profilOubieLogin'])))){
		if ($('#Email_Login').val() == ""){
			alert(unescape(str_replace(lang['profilOubieLoginErreur'])));
		}
		else{
		$('#ChampsDateNaiss_Login').hide();
		$('#ChampsEmail_Login').hide();
		$('#msg_Login').html('');
		$('#Status_Login').html('<img src="images/gif/ajax.gif" />');
		var date_Login = parseInt($('#birthyear').val()) +"-"+ parseInt($('#birthmonth').val()) +"-"+ parseInt($('#birthday').val());
		var email_Login = $('#Email_Login').val();
		$.post("scripts/OubliL.php", { secure: "ok", securee: 1, d_Log: date_Login, e_Log: email_Login}, function(data){
				if(data == "ok"){
					$('#tnc').hide();
						$('#Status_Login').html('<img src="images/gif/ajax.gif" /><br/><font color="#FFFFFF">'+unescape(lang['profilOublieLoginValide'])+'</font>');
						setTimeout('window.location.replace("index.html")', 3000);
				}else{
					if(data == "Err"){
					$('#msg_Login').html('<font color="#FFFFFF">'+unescape(lang['profilOubieLoginErreur2'])+'</font><br/><br/>');	
					}else{
					$('#msg_Login').html('<font color="#FFFFFF">'+unescape(lang['profilOubieLoginErreur2'])+'</font><br/><br/>');
					}
					$('#ChampsDateNaiss_Login').show();
					$('#ChampsEmail_Login').show();
					$('#Status_Login').html('<a href="#" onClick="return OubliLogin();"><img src="images/images_fond/general/RAGNAROK_validation_cc.jpg" title="'+unescape(lang['profilOubieLoginTitle'])+'" border="0" /></a>');
				}											
			} 
		);
		}
	}
}


function OubliPass(){
		if($('#Login_Pass').val() == ""){
			alert(unescape(str_replace(lang['profilOubliePasseErreur'])));
		}
		else if ($('#Email_Pass').val() == ""){
			alert(unescape(str_replace(lang['profilOubliePasseErreur2'])));
		}
		else{
		$('#ChampsLogin_Pass').hide();
		$('#ChampsDateNaiss_Pass').hide();
		$('#ChampsEmail_Pass').hide();
		$('#msg_Pass').html('');
		$('#Status_Pass').html('<img src="images/gif/ajax.gif" />');
		var login_Pass = $('#Login_Pass').val();
		var date_Pass = parseInt($('#birthyear_Pass').val()) +"-"+ parseInt($('#birthmonth_Pass').val()) +"-"+ parseInt($('#birthday_Pass').val());
		var email_Pass = $('#Email_Pass').val();
		$.post("scripts/OubliP.php", { secure: "ok", securee: 1, l_Pass: login_Pass, d_Pass: date_Pass, e_Pass: email_Pass}, function(data){ 
				if(data == "ok"){
					$('#tnc').hide();
						$('#Status_Pass').html('<img src="images/gif/ajax.gif" /><br/><font color="#FFFFFF">'+unescape(lang['profilOubliePasseValide'])+'</font>');
						setTimeout('window.location.replace("index.html")', 3000);																	
				}else{
					if(data == "Err"){
					$('#msg_Pass').html('<font color="#FFFFFF">'+unescape(lang['profilOubliePasseErreur3'])+'</font><br/><br/>');	
					}else{
						$('#msg_Pass').html('<font color="#FFFFFF">'+unescape(lang['profilOubliePasseErreur3'])+'</font><br/><br/>');	
					}
					$('#ChampsLogin_Pass').show();
					$('#ChampsDateNaiss_Pass').show();
					$('#ChampsEmail_Pass').show();
					$('#Status_Pass').html('<a href="#" onClick="return OubliPass();"><img src="images/images_fond/general/RAGNAROK_validation_cc.jpg" title="'+unescape(lang['profilOubiePasseTitle'])+'" border="0" /></a>');
				}										
			} 
		);	
	}
}


function show(){
	$('.show').css('display', 'block');	
}

getOffsetPosition = function(inID, inTYPE)
{
 var iVal = 0;
 var oObj = document.getElementById(inID);
 var sType = 'oObj.offset' + inTYPE;
 while (oObj && oObj.tagName != 'BODY') {
  iVal += eval(sType);
  oObj = oObj.offsetParent;
 }
 return iVal;
}

function EcrireCookie(name,value,days, path, domain) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function LireCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function EffacerCookie(name,valeur,jours, path, domain) {
	createCookie(name,"",-1);
}

function EffacerCookie2(name){
	EcrireCookie(name,null,-1000, "/", "");
}

function serialize()
{
	/*chaine = $.SortSerialize('DragDrop').hash;
	chaine = chaine+"&DragDrop[]";
	valeur = new Array();
	i = 0;

	while( chaine.indexOf('&') != -1 ){
		debut = chaine.indexOf('=');
		fin = chaine.indexOf('&');
		
		valeur[i] = chaine.substr(debut+1, (fin-(debut+1)));
		chaine = chaine.substr((fin+1), (chaine.length-fin));
		i++;		
	}
	
	a = 0; b = 0;
	newValeur = new Array();
	for(z=0; z<valeur.length ;z++){
		if(valeur[z] != "null"){
			if( b == 0){
				newValeur[z] = valeur[z];
			}else{
				newValeur[z] = valeur[z+1];
			}
		}else{
			newValeur[z] = valeur[z+1];	
			b++;
		}
	}
	
	position1 = newValeur[0];
	position2 = newValeur[1];
	position3 = newValeur[2];
	
	EcrireCookie("ragna[1]", position1, 365, "/", "");
	EcrireCookie("ragna[2]", position2, 365, "/", "");
	EcrireCookie("ragna[3]", position3, 365, "/", "");
	placeFooter();*/
};


function serialize2()
{
	
	for(t=0; t<parseInt(nbBloc+1); t++){
		EffacerCookie(nom_cookie+"2["+t+"]","null",10, "/", "");
		EffacerCookie(nom_cookie+"3["+t+"]","null",10, "/", "");
	}
	
	chaine = $.SortSerialize('DragDrop21').hash;
	chaine = chaine+"&DragDrop[]";
	valeur = new Array();
	i = 0;
	//alert(chaine);
	
	while( chaine.indexOf('&') != -1 ){
		debut = chaine.indexOf('=');
		fin = chaine.indexOf('&');
		
		valeur[i] = chaine.substr(debut+1, (fin-(debut+1)));
		chaine = chaine.substr((fin+1), (chaine.length-fin));
		i++;		
	}
	
	a = 0; b = 0;
	newValeur = new Array();
	for(z=0; z<valeur.length ;z++){
		if(valeur[z] != "null"){
			if( b == 0){
				newValeur[z] = valeur[z];
			}else{
				newValeur[z] = valeur[z+1];
			}
		}else{
			newValeur[z] = valeur[z+1];	
			b++;
		}
	}
	
	for(x=0; x<newValeur.length; x++){
		if ($('#'+newValeur[x]).css('display') == "block"){	
			//alert(x+" "+newValeur[x]);
			EcrireCookie(nom_cookie+"2["+x+"]", newValeur[x], 365, "/", "");
		}else{
			EcrireCookie(nom_cookie+"2["+x+"]", newValeur[x]+'cache', 365, "/", "");
		}
	}
	
	serialize3();
};

function serialize3()
{
	chaine = $.SortSerialize('DragDrop22').hash;
	chaine = chaine+"&DragDrop[]";
	valeur = new Array();
	i = 0;
	//alert(chaine);

	while( chaine.indexOf('&') != -1 ){
		debut = chaine.indexOf('=');
		fin = chaine.indexOf('&');
		
		valeur[i] = chaine.substr(debut+1, (fin-(debut+1)));
		chaine = chaine.substr((fin+1), (chaine.length-fin));
		i++;		
	}
	
	a = 0; b = 0;
	newValeur = new Array();
	for(z=0; z<valeur.length ;z++){
		if(valeur[z] != "null"){
			if( b == 0){
				newValeur[z] = valeur[z];
			}else{
				newValeur[z] = valeur[z+1];
			}
		}else{
			newValeur[z] = valeur[z+1];	
			b++;
		}
	}
	
	for(x=0; x<newValeur.length; x++){
		if ($('#'+newValeur[x]).css('display') == "block"){		
			//alert(x+" 2 "+newValeur[x]);
			EcrireCookie(nom_cookie+"3["+x+"]", newValeur[x], 365, "/", "");
		}else{
			EcrireCookie(nom_cookie+"3["+x+"]", newValeur[x]+'cache', 365, "/", "");
		}
	}
	placeFooter();
	
};

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function verifCookies(){
	serialize();
	serialize2();
}

var fkBug = new Array();
function verifModules(){
	for(i=4; i<parseInt(nbBloc+6); i++){
			if($('#picto_z'+i).length > 0){
				temp = $('#picto_z'+i).attr("src").split(".");			
				if ($('#z'+i).css('display') == "block"){
					fkBug['z'+i] = 1;
					$('#pz'+i).toggleClass("currentt");
					
					temp = temp[0].split("_");
					
					$('#picto_z'+i).attr("src", temp[0]+'.jpg');
				}else{
					fkBug['z'+i] = 0;
					
					temp = temp[0].split("_");
					$('#picto_z'+i).attr("src", temp[0]+'_min.jpg');
				}
			
			}
	}
}

function Modules(id){
	if (fkBug[id] == 0){
		fkBug[id] = 1;
		
		if(navigator.userAgent.indexOf('MSIE 6.0') != -1 ) {
			$('#'+id).show();
			$('#'+id).html($('#b_'+id).html());
			$('#b_'+id).html('');
			$('#p'+id).toggleClass("currentt");
			$('div.DragDrop').SortableDestroy();
			$('div.DragDrop2').SortableDestroy();
			rules();
			loadSWF();
			placeFooter();
		}else{
			$('#'+id).BlindDown(500, function(){ $('#p'+id).toggleClass("currentt"); placeFooter(); });
		}
		
		temp = $('#picto_'+id).attr("src").split(".");
		temp = temp[0].split("_");
		$('#picto_'+id).attr("src", temp[0]+'.jpg');

	for(i=0; i<parseInt(nbBloc+1); i++){
		/*if(LireCookie('ragna['+i+']') == id+'cache'){
			EcrireCookie("ragna["+i+"]", id,365, "/", "");		
		}*/
		if(LireCookie(nom_cookie+'2['+i+']') == id+'cache'){
			EcrireCookie(nom_cookie+"2["+i+"]", id, 365, "/", "");
		}
		if(LireCookie(nom_cookie+'3['+i+']') == id+'cache'){
			EcrireCookie(nom_cookie+"3["+i+"]", id, 365, "/", "");
		}
	}
	
	}else{
		fkBug[id] = 0;	
		//$('#'+id).Pulsate(100,5, function(){ $('#'+id).DropOutDown(600); $('#p'+id).toggleClass("currentt"); });
		if(navigator.userAgent.indexOf('MSIE 6.0') != -1 ) { 			
			$('#b_'+id).html($('#'+id).html());
			$('#'+id).html('')
			$('#'+id).hide();
			$('#p'+id).toggleClass("currentt");
			placeFooter();
		}else{
			$('#'+id).BlindUp(500, function(){ $('#p'+id).toggleClass("currentt"); });
		}
	
		temp = $('#picto_'+id).attr("src").split(".");
		temp = temp[0].split("_");
		$('#picto_'+id).attr("src", temp[0]+'_min.jpg');
		
	for(i=0; i<parseInt(nbBloc+1); i++){
		/*if(LireCookie('ragna['+i+']') == id){
			EcrireCookie("ragna["+i+"]", id+'cache',365, "/", "");		
		}*/
		if(LireCookie(nom_cookie+'2['+i+']') == id){
			EcrireCookie(nom_cookie+"2["+i+"]", id+'cache',365, "/", "");		
		}
		if(LireCookie(nom_cookie+'3['+i+']') == id){
			EcrireCookie(nom_cookie+"3["+i+"]", id+'cache',365, "/", "");		
		}
	}	
	
	}
}

var closeblock = function(e){
	id = this.id.replace('close','');
	fkBug['z'+id] = 0;
	//$('#z'+id).Pulsate(100,5, function(){ $('#z'+id).DropOutDown(600); $('#pz'+id).toggleClass("currentt"); });
		if(navigator.userAgent.indexOf('MSIE 6.0') != -1 ) { 
			$('#b_z'+id).html($('#z'+id).html());
			$('#z'+id).html('')
			$('#z'+id).hide();
			$('#pz'+id).toggleClass("currentt");
			placeFooter();
		}else{
			$('#z'+id).BlindUp(500, function(){ $('#pz'+id).toggleClass("currentt");  placeFooter(); });
		}
	
		temp = $('#picto_z'+id).attr("src").split(".");
		temp = temp[0].split("_");
		$('#picto_z'+id).attr("src", temp[0]+'_min.jpg');
		
	for(i=0; i<parseInt(nbBloc+1); i++){
		/*if(LireCookie('ragna['+i+']') == 'z'+id){
			EcrireCookie("ragna["+i+"]",'z'+id+'cache',365, "/", "");		
		}*/
		if(LireCookie(nom_cookie+'2['+i+']') == 'z'+id){
			EcrireCookie(nom_cookie+"2["+i+"]",'z'+id+'cache',365, "/", "");		
		}
		if(LireCookie(nom_cookie+'3['+i+']') == 'z'+id){
			EcrireCookie(nom_cookie+"3["+i+"]",'z'+id+'cache',365, "/", "");		
		}
	}
	
};

function placeFooter(){
	/*var blocStatique = document.getElementById("bloc_centre_support").offsetHeight + document.getElementById("bloc_centre_support").offsetTop + document.getElementById("allContenu").offsetTop + document.getElementById("colonne3").offsetTop;
	var blocDynamique = document.getElementById("allContenu").offsetHeight + document.getElementById("allContenu").offsetTop;
	if( blocStatique > blocDynamique ) {
		document.getElementById("footer").style.top = blocStatique+"px";
		document.getElementById("personnage").style.height = (blocStatique+document.getElementById("footer").offsetHeight)+"px";
		$("#personnage").height(parseInt($('body').height()+35+25));

	}else{
		document.getElementById("footer").style.top = blocDynamique+"px";
		document.getElementById("personnage").style.height = (blocDynamique+document.getElementById("footer").offsetHeight)+"px";
		$("#personnage").height(parseInt($('body').height()+70+25));
	}
	document.getElementById("footer").style.display="block";*/
	var blocStatique = document.getElementById("bloc_centre_support").offsetHeight + 
						document.getElementById("bloc_centre_support").offsetTop + 
						document.getElementById("allContenu").offsetTop + 
						document.getElementById("colonne3").offsetTop;
	
	var blocDynamique = document.getElementById("allContenu").offsetHeight + 
						document.getElementById("allContenu").offsetTop;
	
	var plus = 0; var moins = 0;
	var colone1 = $('#DragDrop21').height();
	var colone2 = $('#DragDrop22').height();
	if(colone1 > colone2 && colone1 > 710){
		plus = parseInt(colone1-710);
		moins = colone1;
	}else if(colone2 > colone1 && colone2 > 710){
		plus = parseInt(colone2-710);
		moins = colone2;
	}else{
		moins = 710;
	}
	
	if( blocStatique > blocDynamique ) { // 697				
			var topp = document.getElementById("bloc_centre_support").offsetTop +
						document.getElementById("bloc_centre_support").offsetHeight + 
						plus;
		
			$("#footer").css({display: "block", 
							 top: topp});
			
			$("#personnage").height(parseInt(document.getElementById("footer").offsetTop+100));
	}else{
			var topp = document.getElementById("allContenu").offsetTop + 
						colone1;
			
			$("#footer").css({display: "block", 
							 top: topp});
			
			$("#personnage").height(parseInt(document.getElementById("footer").offsetTop+100));
	}
	
}
