/*********************************************************************************
*    This file is part of Mountyzilla.                                           *
*                                                                                *
*    Mountyzilla is free software; you can redistribute it and/or modify         *
*    it under the terms of the GNU General Public License as published by        *
*    the Free Software Foundation; either version 2 of the License, or           *
*    (at your option) any later version.                                         *
*                                                                                *
*    Mountyzilla is distributed in the hope that it will be useful,                   *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of              *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
*    GNU General Public License for more details.                                *
*                                                                                *
*    You should have received a copy of the GNU General Public License           *
*    along with Mountyzilla; if not, write to the Free Software                  *
*    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
*********************************************************************************/


// Configuration
var pageVueURL = '/mountyhall/MH_Play/Play_vue.php';
var pageProfilURL = '/mountyhall/MH_Play/Play_profil.php';
var pageOptionURL = '/mountyhall/MH_Play/Options/Play_o_Interface.php';
var pageCdmURL = '/mountyhall/MH_Play/Actions/Competences/Play_a_Competence16b.php';
var pageMessageBot = '/mountyhall/Messagerie/ViewMessageBot.php';
var pageNews = '/mountyhall/MH_Play/Play_news.php';
var pagePackURL = '/mountyhall/installPack.php';
var attaqueURL = '/mountyhall/MH_Play/Actions/Play_a_Attack.php';
var combatURL = '/mountyhall/MH_Play/Actions/Play_a_Combat.php';
var diploURL ='/mountyhall/MH_Guildes/Guilde_o_AmiEnnemi.php';
var lieuURL = '/mountyhall/MH_Lieux/Lieu_Description.php';
var menuURL= '/mountyhall/MH_Play/Play_menu.php';
var autresURL = '/mountyhall/MH_Play/Actions';
var pageTanEquip = '/mountyhall/MH_Taniere/TanierePJ_o_Stock.php';
var pageComEquip = '/mountyhall/MH_Comptoirs/Comptoir_o_Stock.php';
var pageSacEquip = '/mountyhall/MH_Play/Play_e_ChampComp.php';
var pageEquip = '/mountyhall/MH_Play/Play_equipement.php';

var BricolURL = 'http://trolls.ratibus.net/mountyhall/mountyzilla/script.php?type=';

// Variables globales
var bodyVue;
var documentVue;
var totaltab;
var x_monstres;
var x_trolls;
var x_tresors;
var x_lieux;

// Détection de la page de vue
var currentURL = window.self.location.toString();
if( currentURL.indexOf(pageVueURL)!=-1 ) {
	traitementVue(window.self);
} else if( currentURL.indexOf(pageProfilURL) != -1) {
	traitementProfil(window.self);
} else if( currentURL.indexOf(pageOptionURL) != -1 ||  currentURL.indexOf(pagePackURL) != -1) {
	traitementOption(window.self);
} else if( currentURL.indexOf(pageCdmURL)!=-1 ) {
	traitementPageCdm(window.self);
} else if( currentURL.indexOf(pageMessageBot)!=-1 ) {
	traitementPageMessageBot(window.self);
} else if( currentURL.indexOf(pageNews)!=-1 ) {
        traitementNews(window.self);
} else if( currentURL.indexOf(pageEquip)!=-1 ) {
        traitementEquip(window.self);
} else if( currentURL.indexOf(attaqueURL)!=-1 ) {
        traitementAttaque(window.self);
} else if( currentURL.indexOf(diploURL)!=-1 ) {
        traitementDiplo(window.self);
} else if( currentURL.indexOf(lieuURL)!=-1 ) {
        traitementLieu(window.self);
} else if( currentURL.indexOf(combatURL)!=-1 ) {
        traitementCombat(window.self);
} else if( currentURL.indexOf(menuURL)!=-1 ) {
        traitementMenu(window.self);
} else if( currentURL.indexOf(pageTanEquip)!=-1 || currentURL.indexOf(pageComEquip)!=-1) {
        traitementPageTanEquip(window.self);
} else if( currentURL.indexOf(pageSacEquip)!=-1 ) {
	traitementPageSacEquip(window.self);
} else if( currentURL.indexOf(autresURL)!=-1 ) {
        traitementRM(window.self);
}

function pausecomp(Amount)
{
	d = new Date() //today's date
	while (1)
	{
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > Amount ) {break;}
	}
}

function chargerScript( win, script ) {
        var aList = win.document.getElementsByTagName( 'A' );

        if( !win.document.getElementById( 'monScript' ) ) {
                var newScript = win.document.createElement( 'script' );
                newScript.setAttribute( 'language', 'JavaScript' );
                newScript.setAttribute( 'id', 'monScript' );
                newScript.setAttribute( 'src', BricolURL+script );

                (aList[aList.length-1]).parentNode.appendChild( newScript );
        }
}

function traitementRM(win){
	chargerScript(win,"RM");
	return true;
}

function traitementNews(win) {
	chargerScript(win,"NEWS");
	return true;
}

function traitementAttaque(win) {
	chargerScript(win,"ATTAQUE");
	return true;
}

function traitementMenu(win) {
	chargerScript(win,"MENU");
	return true;
}

function traitementEquip(win) {
	chargerScript(win,"EQUIPEMENT");
	return true;
}

function traitementCombat(win) {
	chargerScript(win,"COMBAT");
	return true;
}

function traitementPageTanEquip(win) {
	chargerScript(win,"TANIERE_EQUIPEMENT");
        return true;
}

function traitementPageSacEquip(win) {
        chargerScript(win,"SAC_EQUIPEMENT");
        return true;
}

function traitementProfil(win) {
	chargerScript(win,'PROFIL');
}

function traitementVue(win) {
	chargerScript(win,'VUE');
	return true;
}

function traitementOption(win) {
	chargerScript(win,'OPTION');
	return true;
}

function traitementPageMessageBot(win) {
	chargerScript(win,'MSG_BOT');
	return true;
}

function traitementPageCdm(win) {
	chargerScript(win,'CDM');
	return true;
}

function traitementLieu(win) {
	chargerScript(win,"LIEU");
	return true;
}

function traitementDiplo(win) {
	chargerScript(win,'DIPLO');
	return true;
}



function trim( string ) {
   return string.replace(/(^\s*)|(\s*$)/g,'');
}

function str_woa( str ) {
        str = str.replace( /[éèêë]/g, 'e');
        str = str.replace( /[àâä]/g, 'a' );
        str = str.replace( /[ùûü]/g, 'u' );
        str = str.replace( /[ïî]/g, 'i' );
        str = str.replace( /[öô]/g, 'o' );

        return str;
}

