﻿
var jsUrl 				= "http://webstatic-prod.masternaut.com/webstatic/gwt/scripts/";
// TODO pour test en dev, commenter avant commit
//jsUrl 				= "http://webstatic.dev/webstatic/gwt/scripts/";
var resourcesDir 		= "geonaut-resources";

/*   VARIABLES    POUR   LES    CLIENTS  FR */
var title_FR 			= "www.masternaut.com";
var text_FR 			= "Suivez l’actualité de Masternaut, obtenez des documentations, contactez-nous ...&nbsp;";
var linkText_FR 		= "Cliquez-ici";
var linkUrl_FR 			= "http://www.masternaut.com";
var width_FR 			= 240;

/*   VARIABLES    POUR   LES    CLIENTS  NL */
var title_NL 			= "www.eurecamobile.com";
var text_NL 			= "Volg de actualiteit van Masternaut, voor documentatie, contacteer ons ...&nbsp;";
var linkText_NL 		= "Klik hier";
var linkUrl_NL 			= "http://www.eurecamobile.com";
var width_NL 			= 220;

/*   VARIABLES    POUR   LES    CLIENTS  ES */
var title_ES 			= "www.masternaut.es";
var text_ES 			= "Vea las últimas noticias, novedades y soluciones en la web de Masternaut,&nbsp;";
var linkText_ES 		= "click aqui";
var linkUrl_ES 			= "http://www.masternaut.es";
var width_ES 			= 225;

/*   VARIABLES    POUR   LES    CLIENTS  IT */
var title_IT 			= "WWW.TRKITALIA.IT";
var text_IT 			= "Seguite le ultime novità e soluzioni sul nostro sito...&nbsp;";
var linkText_IT 		= "Clicca_qui";
var linkUrl_IT 			= "http://www.trkitalia.it";
var width_IT 			= 180;

var height = 80;

function getLanguage(){
    if (navigator.language) {   
		lct = navigator.language.toLowerCase().substring(0, 2);    
    } else if (navigator.userLanguage) {
		lct= navigator.userLanguage.toLowerCase().substring(0, 2);
    } else if (navigator.userAgent.indexOf("[")!=-1) {
	    var debut=navigator.userAgent.indexOf("[");
	    var fin=navigator.userAgent.indexOf("]");
	    lct= navigator.userAgent.substring(debut+1, fin).toLowerCase();
    }
    return lct;
}

LoginLink = function (){
	
	var thisObject			= this;
	var language 			= getLanguage();
	this.container 			= null;	
	this.currentLeft		= 0;	
	this.width;
	constructor();
	
	function constructor(){	
		LoadCSS(jsUrl+ resourcesDir +"/geonaut-login-script.css");		
		//on ne fait quelque chose s'il n'y a pas d'idsession et que pour les browser FR, NL, ES et IT
		
		if(	getVar("idsession")== 0 &&
			(language.toLowerCase() == 'fr' || 
			language.toLowerCase() == 'nl' ||
			// commenté pour ES le 21/06/2011 demande par S.Carlier
			//language.toLowerCase() == 'es' ||
			language.toLowerCase() == 'it')  ){
			
			createHTML();
			initPosition();
			showContainer();
		}
	}
	
	function createHTML(){
		
		thisObject.container = document.createElement("div");
		
		thisObject.container.style.position = "absolute";

		var title, text, linkUrl, linkText;
		if (language.toLowerCase() == 'fr'){
			title = title_FR;
			text = text_FR;
			linkText = linkText_FR;
			linkUrl = linkUrl_FR;
			this.width = width_FR;
		}else if (language.toLowerCase() == 'nl'){
			title = title_NL;
			text = text_NL;
			linkText = linkText_NL;
			linkUrl = linkUrl_NL;
			this.width = width_NL;
		}else if (language.toLowerCase() == 'es'){
			title = title_ES;
			text = text_ES;
			linkText = linkText_ES;
			linkUrl = linkUrl_ES;
			this.width = width_ES;
		}else if (language.toLowerCase() == 'it'){
			title = title_IT;
			text = text_IT;
			linkText = linkText_IT;
			linkUrl = linkUrl_IT;
			this.width = width_IT;
		}
		thisObject.container.style.width = this.width + "px";
		
		
		var html = "";

		html += "	<table cellspacing='0' cellpadding='0' style='width: 100%;'><tbody>";
		html += "		<tr><td>";
		html += "				<table cellspacing='0' cellpadding='0' style='width: 100%;'>";
		html += "				<tbody>";
		html += "					<tr>";
		html += "						<td class=' ExpandableTopLeft '>&nbsp;</td>";
		html += "						<td class=' ExpandableTopMiddle '>";
		html += "							<div style='width: 100%;' >";
		html += "								<div style='display: inline;'>" + title + "</div>";
		html += "							</div>";
		html += "						</td>";
		html += "						<td width='1px' class=' ExpandableTopMiddle '>&nbsp;</td>";
		html += "						<td width='20px' align='right' style='vertical-align: middle;' class=' ExpandableTopExpand '>";
		html += "							<img id='ImgClose'   src='"+jsUrl+ resourcesDir + "/windowTopClose_on.png'/></td>";
		html += "						<td class=' ExpandableTopRight '>&nbsp;</td>";
		html += "					</tr>";
		html += "				</tbody>";
		html += "				</table>";
		html += "		</td></tr>		";
		html += "	</tbody></table>";
		html += "	<table cellspacing='0' cellpadding='0' style='width: 100%;'><tbody>";
		html += "		<tr>";
		html += "			<td class=' ExpandableBorderLeft '>&nbsp;</td>";
		html += "			<td class='ExpandableCenter'>";
		html += "				<div style=' position: relative; width: 100%; height: 100%;text-align: justify' class=' Common_Font_Std Common_Default_Font_Color '>";
		html +=  				text + "<a href='" + linkUrl+ "' target=blanc>" + linkText + "</a>";
		html += "				</div>";
		html += "			</td>";
		html += "			<td class=' ExpandableBorderRight '>&nbsp;</td></tr><tr><td class=' ExpandableBottomLeft '>&nbsp;</td><td class=' ExpandableBottomMiddle '>&nbsp;</td><td class=' ExpandableBottomRight '>&nbsp;</td>";
		html += "		</tr>";
		html += "	</tbody></table>";	
	
		thisObject.container.innerHTML = html;
		
	}
	
	function initPosition(){
		thisObject.currentLeft = -this.width;
		thisObject.container.style.left = thisObject.currentLeft + "px";
		document.body.appendChild(thisObject.container);
		//alert(thisObject.container.offsetHeight);
		
		thisObject.container.style.top = getWindowHeight() - height + "px";	//thisObject.container.offsetHeight
		document.getElementById("ImgClose").onclick = hideContainer;
	}
	
	function showContainer(){
		thisObject.currentLeft += 10;
		thisObject.container.style.left = thisObject.currentLeft + "px";
		if(thisObject.currentLeft < 10){
			setTimeout(function(){showContainer()},60);
		}
	}
	
	function hideContainer(){
		thisObject.currentLeft -= 10;
		thisObject.container.style.left = thisObject.currentLeft + "px";
		if(thisObject.currentLeft > - this.width){
			setTimeout(function(){hideContainer()},60);
		}
	}
}

function LoadCSS(path){
	
    var link  = document.createElement("link");
    link.type = "text/css";
    link.rel  = "stylesheet";
    link.href = path;
	try{
		document.getElementsByTagName("head")[0].appendChild(link);
	}catch(e){
		alert(e.message);
	}
    
}

function getWindowHeight(){
	if (document.body){	
		return document.body.clientHeight;
	} else{
		return window.innerHeight;
	}
}

 function getVar (nomVariable) {
	var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
	if (infos.indexOf("#")!=-1)
		infos = infos.substring(0,infos.indexOf("#"))+"&"
	var variable=0
	{
	nomVariable = nomVariable + "="
	var taille = nomVariable.length
	if (infos.indexOf(nomVariable)!=-1)
		variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
	}
	return variable
} 

setTimeout(function(){
						new LoginLink();
					}, 2000);	

