/************************************************************************************
@ Author : Nicolas Castelli
@ Mail : nicolas.castelli2@gmail.com
@ Date of creation : 2008-01-01
@ Filename : prototype.js
@ Use : Javascript pour la définition de la classe Browser, qui va contenir
toutes les infos utiles du navigateur
************************************************************************************/

//Classe de définition de Browser
function Browser() {
	//**** VARIABLES PUBLIQUES
	this.system = "";
	this.navigator = "";
	this.navVersion = 0;
	this.lang = "";
	this.screenHeight = "";
	this.screenWidth = "";
	//**** VARIABLES PRIVÉES


	//Detection du systeme
	if (navigator.appVersion.indexOf('Win') != -1 )
		this.system = 'Windows';
	if (navigator.appVersion.indexOf('Mac') != -1 )
		this.system = 'Macintosh';
	if (navigator.appVersion.indexOf('Linux') != -1 )
		this.system = 'Linux';
	//Detection du navigateur
	if (navigator.userAgent.indexOf('Opera') != -1 )
		this.navigator = 'Opera';
	if (navigator.userAgent.indexOf('Konqueror') != -1 )
		this.navigator = 'Konqueror';
	if (navigator.userAgent.indexOf('Safari') != -1 )
		this.navigator = 'Safari';
	if (navigator.userAgent.indexOf('Firefox') != -1 )
		this.navigator = 'Firefox';
	if (navigator.userAgent.indexOf('Netscape') != -1 )
		this.navigator = 'Netscape';
	if (navigator.userAgent.indexOf('MSIE 7') != -1 )
	{
		this.navigator = 'Internet Explorer';
		this.navVersion = 7;
	}
	if (navigator.userAgent.indexOf('MSIE 6') != -1 )
	{
		this.navigator = 'Internet Explorer';
		this.navVersion = 6;
	}

	if(this.navigator == 'Internet Explorer')
		ieBrowser.call(this);
	else
		ffBrowser.call(this);

	//**** FONCTIONS PRIVÉES
	//**** FONCTIONS PUBLIQUES :
	this.getSystem = function() { return this.system;	}
	this.getNavigator = function() { return this.navigator;	}
	this.getLang = function() { return this.lang;	}
	this.getVersion = function() { return this.navVersion;	}

	this.setSystem = function(value) { this.system = value;	}
	this.setNavigator = function(value) { this.navigator = value;	}
	this.setLang = function(value) { this.lang = value;	}
	this.setVersion = function(value) { this.navVersion = value;	}
//Fin de la classe Browser
}

//Classe spécifique à Internet Explorer
function ieBrowser()
{
	//**** VARIABLES PRIVÉES

	//**** VARIABLES PUBLIQUES

	//**** FONCTIONS PRIVÉES
	//Creation de l'objet pour Ajax
	var getXmlHttpObject = function () {
		var xmlHttp = null;
		try {	// Internet Explorer 7
		 xmlHttp = new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer 6
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
		  // Internet Explorer 5.5 and <
		  catch (e) {
		  	xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		  }
		}
		return xmlHttp;
	}

	//**** FONCTIONS PUBLIQUES
	this.getMouseX = function() {return event.offsetX;}
	this.getMouseY = function() {return event.offsetY;}
	this.getScreenHeight = function() { return screen.height;	}
	this.getScreenWidth = function() { return screen.width;	}

	this.getJSONData = function(fichier, async) {
		var reqAjax = "";
		var data = new Array();
		reqAjax = getXmlHttpObject();
		reqAjax.open('GET', fichier+"?nocache=" + Math.random(), async);
  	reqAjax.send(null);
  	if(localVersion == 1)
  	{
		  //VERSION LOCALE
			try { data = eval('(' + reqAjax.responseText + ')'); }
			catch (e) { alert(e.name + " : " + e.message + " ! If you see this message, please contact the admin ! "); }
		}
		else
		{
			//VERSION NORMALE
			//Si le fichier est présent, on a status = 200
	  	if(reqAjax.status == 200)
	  	{
		  	try { data = eval('(' + reqAjax.responseText + ')'); }
				catch (e) { alert(e.name + " : " + e.message + " ! If you see this message, please contact the admin ! "); }
		  }
		}
	  //On renvoie le fichier chargé
		return data;
	}


//Fin de la classe
}

//Classe spécifique à Firefox
function ffBrowser()
{
	//**** VARIABLES PRIVÉES

	//**** VARIABLES PUBLIQUES

	//**** FONCTIONS PRIVÉES

	//**** FONCTIONS PUBLIQUES
	this.getMouseX = function(event) {return event.layerX;}
	this.getMouseY = function(event) {return event.layerY;}
	this.getScreenHeight = function() { return screen.height;	}
	this.getScreenWidth = function() { return screen.width;	}

	this.getJSONData = function(fichier, async) {
		var reqAjax = "";
		var data = new Array();
		reqAjax = new XMLHttpRequest();
		//reqAjax.open('GET', fichier, async);
		reqAjax.open('GET', fichier+"?nocache=" + Math.random(), async);
  	reqAjax.send(null);
  	if(localVersion == 1)
  	{
   		// VERSION LOCALE
	  	try { data = eval('(' + reqAjax.responseText + ')'); }
			catch (e) { alert(e.name + " : " + e.message + " ! If you see this message, please contact the admin ! "); }
		}
		else
		{
			//VERSION NORMALE
	  	//Si le fichier est présent, on a status = 200
	  	if(reqAjax.status == 200)
	  	{
		  	try { data = eval('(' + reqAjax.responseText + ')'); }
				catch (e) { alert(e.name + " : " + e.message + " ! If you see this message, please contact the admin ! "); }
		  }
		}
	  //On renvoie le fichier chargé
		return data;
	}

//Fin de la classe
}