var launched = false;

var isVista = (navigator.userAgent.indexOf("windows NT 6.0")>-1)?true:false;


var browserDtct = (Prototype.Browser.IE) ? "ie" : "ff";
var isFF = !Prototype.Browser.IE;
var isIE = Prototype.Browser.IE;
var urlEXE = url_exe[browserDtct];

var isInstalled = getCookie(cookieName)==cookieExpectedVal;
var firstLaunch = getCookie(cookieName+"_first")==cookieExpectedVal;

function initMin(){
	initMaps();
	var m1b = document.getElementById("M1BUT");
	if(m1b){
		m1b.setAttribute("src",m1Url);
		m1b.setAttribute("usemap","#map1");
	}
	var m2b = document.getElementById("M2BUT");
	if(m2b){
		m2b.setAttribute("src",m2Url);
		m2b.setAttribute("usemap","#map2");
	}
	buildHelp();
	if(firstLaunch){
		launchMin();
		eraseCookie(cookieName+"_first");
	}
}

function initMaps(){
	var m1m = document.getElementsByName("map1");
	if(m1m && m1m.length>0){
		setmap(m1m[0],m1Map,"true","showInfo");
	}

	var m2m = document.getElementsByName("map2");
	if(m2m && m2m.length>0){
		setmap(m2m[0],m2Map,"false","showGo");
	}	
}

function setmap(map,coords,go,method){
	for(i in coords.action){
		var mapping = document.createElement('area');
		mapping.setAttribute('shape',"RECT");
		mapping.setAttribute('coords',coords.action[i]);
		mapping.setAttribute('href',"javascript:"+method+"("+go+");");
		map.appendChild(mapping); 
	}
	for(i in coords.help){
		var mapping = document.createElement('area');
		mapping.setAttribute('shape',"RECT");
		mapping.setAttribute('coords',coords.help[i]);
		mapping.setAttribute('href',"javascript:aideminitel();");
		map.appendChild(mapping); 
	}	
}

function aideminitel(){
	window.open(url_help,'_blank', 'width=580,height=392,top='+((screen.height-333)/2)+',left='+((screen.width-483)/2)+',scrollbars=0,location=0,status=0,resizable=0');
}

function showInfo(dl)
{
	if(isInstalled){
		launchMin();
	}else{
		$("btnMin").style.display = "none";
		$("info").style.display = "block";
		if(dl){
			window.location.href = urlEXE;
		}
	}
}
function showGo()
{
	if(launched){
		alert("Vous devez mettre à jour votre PC");
		window.location.href = urlEXE;
	} else {
		if(isFF){
			window.location.href = urlEXE;
		}else{
			launchMin();
		}
	}
	launched = true;
}

function launchMin(){
	var b = document.getElementById(divIframe) ;
	if(!b){
		return;
	}
	var MinIframe = document.createElement('iframe');
	MinIframe.setAttribute('src', url_min);
	MinIframe.setAttribute('id', "minitelifrm");
	MinIframe.setAttribute('style', "width:0;height:0");
	MinIframe.setAttribute('width', "0");
	MinIframe.setAttribute('height', "0");
	MinIframe.setAttribute('scrolling',"no");
	MinIframe.setAttribute('frameborder',"0");
	b.appendChild(MinIframe); 
}

function buildHelp(){
	eval("var hlp = Help."+browserDtct+";");
	
	var infoD = document.getElementById("info"+browserDtct.toUpperCase());
	infoD.style.display = "block";
	
	var hlpD = document.getElementById("help"+browserDtct.toUpperCase()+"Div");
	if(hlp && hlpD){
		var ol = document.createElement('ol');
		for(i in hlp){
			if(hlp[i].src && hlp[i].txt){
				var li = document.createElement('li');	
				li.appendChild(document.createTextNode(hlp[i].txt));
				li.appendChild(document.createElement('br'));
				
				var link = document.createElement('a');
				link.setAttribute("href","javascript:showInfo(true);");	
				var img=  document.createElement('img');
				if(isVista){
					var reg=new RegExp("/xp/", "g");
					img.setAttribute('src',hlp[i].src.replace(reg,"/vista/"));
				}else{
					img.setAttribute('src',hlp[i].src);
				}
				img.setAttribute('border',0);
				link.appendChild(img);
				li.appendChild(link);
				ol.appendChild(li);
			}
		}
		hlpD.appendChild(ol);
	}
}
Event.observe(window, 'load', initMin);