﻿/*******************************************************************************
 * Execution de script
 ******************************************************************************/

/*******************************************************************************
 * Fonction qui va recharger le javascript
 ******************************************************************************/
var jsfiles = new Array();
var cssfiles = new Array();

function load_js(file) {

	var keylist = ['fundations','Sward'];
	
	for(var i=0;i<keylist.length;i++){
		if(file.indexOf(keylist[i])>-1)
		{
			alert("remplace "+keylist[i]+" PAR " +keylist[i]+"/"+document.getElementById("V_"+keylist[i].toUpperCase()+"_JS").value)
			file = file.replace(keylist[i],keylist[i]+"/"+document.getElementById("V_"+keylist[i].toUpperCase()+"_JS").value);
			break;
		}
	}

	if (jsfiles[file] != 1) {
		jsfiles[file] = 1;
		var oScript = document.createElement('script');
		oScript.type = 'text/javascript';
		oScript.src = file;
		document.getElementsByTagName('head')[0].appendChild(oScript);
	}
}

function load_css(file){

	if (cssfiles[file] != 1) {
		cssfiles[file] = 1;
		var oScript = document.createElement('link');
		oScript.type = 'text/css';
		oScript.rel = 'stylesheet';
		oScript.href = file;
		document.getElementsByTagName('head')[0].appendChild(oScript);
	}
}

function load_ingame_css(game,file){

  var href = 'css/'+game+'/'+document.getElementById("V_"+game.toUpperCase()+"_CSS").value+'/'+file;
	if (cssfiles[href] != 1) {
		cssfiles[href] = 1;
		var oScript = document.createElement('link');
		oScript.type = 'text/css';
		oScript.rel = 'stylesheet';
		oScript.href = href;
		document.getElementsByTagName('head')[0].appendChild(oScript);
	}
}

function trim (myString)
{
  return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}

var currenttitle=''
var currentgame='';

function setActiveStyleSheet(title){
        
	if(title==currenttitle && currentgame==dysplayinterface.name)
		return;

	currenttitle = title;
	currentgame = dysplayinterface.name;

	var i, a, main;

	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("stylesheet")!=-1)
			a.disabled = false;
	}
	
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("stylesheet") != -1 && (a.getAttribute("title")==null || a.getAttribute("title")=='')){
			a.disabled = true;
			if(a.getAttribute("href").indexOf(title)!=-1 && a.getAttribute("href").indexOf(dysplayinterface.name+"/")!=-1){
                       		a.disabled = false;
			}
			else if(a.getAttribute("href").indexOf("applicative")!=-1 && a.getAttribute("href").indexOf(dysplayinterface.name+"/")!=-1){
                       		a.disabled = false;
			}
		}
	}

	/*for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.disabled==true)
			alert(a.getAttribute("href")+" : "+a.getAttribute("title"));
	}*/
}

var norecurcive=false;

function resolution2css(){
   
    if(norecurcive)
		return;
   
	var height=0;
	var width=0;
	if (document.all)
	{
		height=document.documentElement.clientHeight;
		width=document.documentElement.clientWidth;
	}
	else
	{
		width=window.innerWidth;
		height=window.innerHeight;
	}
	
	norecurcive=true;
	
	if(width>1672 && height>850)
		setActiveStyleSheet('large');
	else if(width>1272 && height>714)
		setActiveStyleSheet('medium2');
	else if(width>1272 && height>582)
		setActiveStyleSheet('medium1');
	else
		setActiveStyleSheet('small');
		
	norecurcive=false;
}

function Begin(){
  getNews().display();
  resolution2css();
}

