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

var strChUserAgent = navigator.userAgent;
var intSplitStart = strChUserAgent.indexOf("(",0);
var intSplitEnd = strChUserAgent.indexOf(")",0);
var strChStart = strChUserAgent.substring(0,intSplitStart);
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
var strChEnd = strChUserAgent.substring(strChEnd); 

var isFF = (strChEnd.indexOf("Firefox") != -1)?true:false;

var browserDtct = (isFF) ? "ff" : "ie";

var isIE = !isFF;

var urlEXE = url_exe[browserDtct];

var isInstalled = getCookie(cookieName)==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((isInstalled) && (consultDirect)){
		launchMin();
	}
}

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){
		if(!isNaN(i)){
		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){
		if(!isNaN(i)){
		var mapping = document.createElement('area');
		mapping.setAttribute('shape',"RECT");
		mapping.setAttribute('coords',coords.help[i]);
		mapping.setAttribute('href',"javascript:aideminitel();");
		map.appendChild(mapping); 
		}
	}	
}
function launchFextel()
    {
        if (initial)
        {
            document.getElementById("M1BUT").innerHTML = '<a href="javascript:launchFextel();"><img src="/image/BtnConsultation2.gif" alt="bouton" style="border: none;"/></a>';
            document.getElementById("button_tarif").style.display = "block";
            document.getElementById("button_mentions").style.display = "none";
            initial = false;

        }
        else
        {
            FlextelMgr.launchFlextel('TOPTEL*O');
            document.getElementById("M1BUT").innerHTML = '<a href="javascript:launchFextel();"><img src="/image/BtnConsultation.gif" alt="bouton" style="border: none;"/></a>';
            document.getElementById("button_tarif").style.display = "none";
            document.getElementById("button_mentions").style.display = "block";
            initial = true;
            createCookie( '_flx_inst', '1',365 );
            
        }
    }



    function aideminitel(){

            if(FlextelMgr.isFlextelEnabled()){
                window.open('cgu.html','_blank', 'width=595,height=695,top='+((screen.height-695)/2)+',left='+((screen.width-595)/2)+',scrollbars=0,location=0,status=0,resizable=0');
            } else {
                window.open(url_help,'_blank', 'width=557,height=392,top='+((screen.height-333)/2)+',left='+((screen.width-483)/2)+',scrollbars=0,location=0,status=0,resizable=0');
            }

    }

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

    function eraseCookie(name) {
        createCookie(name,"",-1);
    }



function showInfo(dl)
{
	if(isInstalled){
		launchMin();
	}else{
		
		document.getElementById("btnMin").style.display = "none";
		document.getElementById("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 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);
	}
}

if (!window.addEventListener) {

    window.addEventListener = function (type, listener, useCapture) {

        attachEvent('on' + type, function() { listener(event) });

    }

}


window.addEventListener('load', initMin, false);


