// choix du DOM (Document Object Model)
var dyna_w3=0;	// DOM-1 du W3C : Mozilla, Netscape 6/7, IE 5/6, Opera 7, Safari
var dyna_ie=0;	// IE 4
var dyna_nn=0;	// Netscape Navigator 4
var dyna_op=0;	// Opera 4/5/6

// determine le DOM utilise par le navigateur
if (document.getElementById && document.getElementsByTagName)
	dyna_w3=1;
else if (document.all && navigator.userAgent.toLowerCase().indexOf('opera')!=-1)
	dyna_op=1;
else if (document.all)
	dyna_ie=1;
else if (document.layers)
	dyna_nn=1;
	
function init_ASTEC()
{		
	var laWindow = obtenirDivision('AfficheReponseWindow');
	CreationResponseWindow('AfficheReponseWindow');
	disableSelection(laWindow);
	
	document.onmouseup=mouseUP;
	document.onmousedown = ddInit;
	document.onmousemove=dd;	
}

function radCheck()
{ 
	var ranNum= Math.round(Math.random()*4); 
	var smessage= getPage(URL_RAD_CHECK + '&coordX='+tempX+'&coordY='+tempY+'&'+ranNum);
	if (smessage.length > 0)
		{
		modifierCodeDivision("AfficheReponse", doPop(smessage));
		}
	else
	{
		modifierCodeDivision("AfficheReponse", '');
		cacherDivision("AfficheReponseWindow");
	}
}

function CreationResponseWindow(idWindowParent)
{
	var	langue = getParameter("langue").toUpperCase();
	
	var	html = '<table border="0" cellspacing="0" cellpadding="0" class="tableppal">';
			html+= '	<tr>';
			if (langue == "EN")
				html+= '		<td class="top_en"  colspan="3" >';
			else
				html+= '		<td class="top"  colspan="3" >';
			html+= '		<table border="0" cellspacing="0" cellpadding="0" height="20px"><tr><td style="width:190px;cursor:move" onmouseup="mouseUP();"  id="titleBar">&nbsp;</td><td style="width:30px;cursor:default">&nbsp;</td><td><a onclick="cacherPopup();"><img src="/astec_acai/publication/cnir/referentiel_icone/bloc_blanc_haut_close.gif"></a></td></tr></table>';
			html+= '		</td>';
			html+= '	</tr>';
			html+= '	<tr class="center">';
			html+= '		<td class="center" colspan="3" align="center" valign="bottom">';
			html+= '			<div height="2px" style="background-color:#f8f8ff"><img src="/astec_acai/publication/cnir/referentiel_icone/separ.gif" width="1" height="2px" border="0"></div>';
			html+= '			<div id="AfficheReponse" onmouseover="fover();"></div>';
			html+= '		</td>';
			html+= '	</tr>';
			html+= '	<tr >';
			html+= '		<td class="bottom" colspan="3">&nbsp;</td>';
			html+= '	</tr>';
			html+= '</table>';
	
	modifierCodeDivision(idWindowParent, html);
}

/* Fonction sur DIV generales, plus facile d'ajouter des try/catch et de gerer les compatibilites*/
function obtenirDivision(id)
{
	if (dyna_w3)
		return document.getElementById(id);
	else if (dyna_ie || dyna_op)
		return document.all[id];
	else if (dyna_nn)
		return dyna_obtenirDivNN4(document, id);
	return "";
} // fin obtenirDivision(id)

// parcoure les divisions du DOM Netscape 4 pour trouver celle souhaitée
function dyna_obtenirDivNN4(objet, nom) {
	var divs=objet.layers;
	var divTrouvee;
	for (var i=0; i<divs.length; i++) {
		if (divs[i].id==nom)
		 	divTrouvee=divs[i];
		else if (divs[i].layers.length > 0)
			var tmp=dyna_obtenirDivNN4(divs[i], nom);
		if (tmp)
			divTrouvee=tmp;
	}
	return divTrouvee;
} // fin dyna_obtenirDivNN4(objet, nom)

// modifie le code HTML contenu dans la division specifiee
function modifierCodeDivision(id, code) {
	var ldiv=obtenirDivision(id);
	if (!ldiv)
		return false;
	if (!code)
		code="";
	if (navigator.userAgent.toLowerCase().indexOf("mac")!=-1)
		code+="\n";
	if (dyna_w3) {
		ldiv.innerHTML="";
		ldiv.innerHTML=code;
	} else if (dyna_ie || dyna_op) {
		ldiv.innerHTML=code;
	} else if (dyna_nn) {
		ldiv.document.open();
		ldiv.document.write(code);
		ldiv.document.close();
	}
	return true;
} // fin modifierCodeDivision(id, code)

// modifie le code HTML contenu dans la division specifiee
function modifierImgSrc(id, newsrc) {
	var ldiv=obtenirDivision(id);
	if (!ldiv)
		return false;
	if (!newsrc)
		newsrc="";
	ldiv.src=newsrc;
	return true;
} // fin modifierCodeDivision(id, code)

// recupere le code HTML contenu dans la division specifiee
function obtenirCodeDivision(id) {
	var ldiv=obtenirDivision(id);
	if (!ldiv)
		return "";
	if (dyna_w3 || dyna_ie || dyna_op) {
		return ldiv.innerHTML;
	} else if (dyna_nn) {
		return "";
	}
	return true;
} // fin modifierCodeDivision(id, code)

// rend visible la division specifiee
function montrerDivision(id) {
	var ldiv=obtenirDivision(id);
	if (!ldiv)
		return false;
	if (dyna_w3 || dyna_ie || dyna_op)
		ldiv.style.visibility="visible";
	else if (dyna_nn)
		ldiv.visibility="show";
	return true;
} // fin montrerDivision(id)

// rend invisible la division specifiee
function cacherDivision(id) {
	var ldiv=obtenirDivision(id);
	if (!ldiv)
		return false;
	if (dyna_w3 || dyna_ie || dyna_op)
		ldiv.style.visibility="hidden";
	else if (dyna_nn)
		ldiv.visibility="hide";
	return true;
} // fin cacherDivision(id)

// rend invisible la division specifiee
function modifierAffichageDivision(id, aff) {
	var ldiv=obtenirDivision(id);
	if (!ldiv)
		return false;
	if (!aff)
		aff = "";
	ldiv.style.display=aff;
	return true;
} // fin cacherDivision(id)

function getParameter( parameterName ) {
	var queryString = window.location.search.substring(1);
	queryString=unescape(queryString);
	//if (queryString.length==0) {return "null";}
	var parameters = new Array();
	parameters = queryString.split('&');
	for(var i = 0; i < parameters.length; i++) {
		if (parameters[i].indexOf(parameterName)>=0) {
			var parameterValue = new Array();
			parameterValue = parameters[i].split('=');
			return parameterValue[1];
		}
	}
	return "null";
}

// TRADUCTION
function TraductionEvt(unEvt, langue)
{
	if (langue == "EN")
	{
		//On cherche la traduction
		if (unEvt[0]!=undefined)
			unEvt[0] = getTraductionTEXTE(unEvt[0], langue);
		if (unEvt[1]!=undefined)
			unEvt[1] = getTraductionTEXTE(unEvt[1], langue);
		if (unEvt[2]!=undefined)
			unEvt[2] = getTraductionTEXTE(unEvt[2], langue);
		if (unEvt[3]!=undefined)
			unEvt[3] = getTraductionTEXTE(unEvt[3], langue);
		if (unEvt[4]!=undefined)
			unEvt[4] = getTraductionTEXTE(unEvt[4], langue);
		if (unEvt[5]!=undefined)
			unEvt[5] = getTraductionTEXTE(unEvt[5], langue);
	}
}

function getTraductionTYPE(unMOT_FR, langue)
{
	var unMOT = unMOT_FR;
	var unMOT_FR_UP = unMOT_FR.toUpperCase();

	var dico = new Array();
	// Except RES_RCD
	if (unMOT_FR_UP.substr(0, 18) == "INTERDICTION PL DE")
	{
		if (langue == "EN")
		{
			unMOT = unMOT_FR_UP;
			unMOT = unMOT.replace("INTERDICTION PL DE", "NO HGV ACCESS");
			unMOT = unMOT.replace(" KM", " km");
		}
		return unMOT;
	}
	//Exception pour le type "Bouchon de x Km"
	if ((unMOT_FR_UP.substr(0, 10) == "BOUCHON DE") || (unMOT_FR_UP.substr(0, 17) == "RALENTISSEMENT DE"))
	{
		if (langue == "EN")
		{
			unMOT = unMOT_FR_UP;
			unMOT = unMOT.replace("BOUCHON DE", "TRAFFIC JAM Queue length");
			unMOT = unMOT.replace("RALENTISSEMENT DE", "HEAVY TRAFFIC Queue length");
			unMOT = unMOT.replace(" KM", " km");
		}
		return unMOT;
	}

	dico[0]=["INTERDICTION PL","COUPURE D'AXE",'AXE COUPE','ACCIDENT','BOUCHON','RALENTISSEMENT','DEVIATION','CHANTIER','INCIDENT','REDUCTION DE CAPACITE','BASCULEMENT DE CHAUSSEE','ALTERNAT','OBSTACLE','LIMITATION DE VITESSE','RESTRICTION',
				'MANISFESTATION','ITINERAIRE BIS', 'ITINERAIRE CONSEILLE', 'CHANTIER LONGUE DUREE', 'CHANTIER JOURNALIER', 'CHANTIER NOCTURNE', 'OBSTACLE DIVERS', 'OBSTACLE INONDATION', 'OBSTACLE FEU', 'OBSTACLE EFFONDREMENT',
				'OBSTACLE EBOULEMENT', 'OBSTACLE AVALANCHE', 'OBSTACLE S\xC9ISME', 'OBSTACLE OURAGAN', 'OBSTACLE RAZ DE MAR\xC9E',
				'MANIFESTATION SOCIALE', 'MANIFESTATION SPORTIVE', 'MANIFESTATION COMMERCIALE', 'MANIFESTATION RELIGIEUSE', 'MANIFESTATION DIVERS',
				'CONDITIONS DE CIRCULATION DIFFICILES', 'RESTRICTION DE CIRCULATION'];
	dico[1]=["NO HGV ACCESS","CLOSED ROAD",'CLOSED ROAD','ACCIDENT','TRAFFIC JAM','HEAVY TRAFFIC','REROUTING','ROADWORKS','INCIDENT','LANE CLOSURE','CONTRAFLOW','ALTERNATE LANE SYSTEM','OBSTACLE','TEMPORARY SPEED LIMIT','RESTRICTION',
				'EVENT','SECONDARY WAY', 'ADVICED ROUTE', 'MAJOR ROADWORKS', 'DAY TIME ROADWORKS', 'NIGHT TIME ROADWORKS', 'OBSTRUCTION HAZARD', 'FLOODING', 'FIRE', 'SUBSIDENCE',
				 'ROCKSFALLS', 'AVALANCHES', 'EARTHQUAKE DAMAGE', 'STORM DAMAGE', 'FLASH FLOOD',
				 'DEMONSTRATION', 'SPORTS EVENT', 'FAIR', 'CEREMONIAL EVENT', 'DEMONSTRATION',
				 'DISRUPT TRAFFIC', 'RESTRICTION'];

	if (langue == "EN")
	{
		for (var j=0;j<dico[0].length;j=j+1)
		{
			if (dico[0][j] == unMOT_FR_UP)
			{
				unMOT = dico[1][j];
				break;
			}
		}	
	}
	
	return unMOT;
}

function getTraductionTEXTE(unMOT_FR, langue)
{
	var unMOT = unMOT_FR;
	var unMOT_FR_UP = unMOT_FR.toUpperCase();

	//Exception pour le type "Bouchon de x Km"
	if ((unMOT_FR_UP.substr(0, 10) == "BOUCHON DE") || (unMOT_FR_UP.substr(0, 17) == "RALENTISSEMENT DE"))
	{
		if (langue == "EN")
		{
			unMOT = unMOT_FR_UP;
			unMOT = unMOT.replace("BOUCHON DE", "TRAFFIC JAM Queue length");
			unMOT = unMOT.replace("RALENTISSEMENT DE", "Heavy traffic queue length");
			unMOT = unMOT.replace(" KM", " km");
		}
		return unMOT;
	}

	var dico = new Array();
	dico[0]=['INTERDICTION PL','AXE COUP\xC9', 'D\xC9VIATION', 'TRAVAUX', 'ACCIDENT', 'ALTERNAT', 'BASCULEMENT DE CHAUSS\xC9E', 'INONDATION', 'INCENDIE', 'OBSTACLE SUR CHAUSS\xC9E', 'EFFONDREMENT', '\xC9BOULEMENT', 'AVALANCHE', 'S\xC9ISME', 'OURAGAN', 'RAZ DE MAR\xC9E', 'INCIDENT', 'V\xC9HICULE EN PANNE', 'MANIFESTATION SOCIALE', 'MANIFESTATION SPORTIVE', 
				'MANIFESTATION COMMERCIALE', 'MANIFESTATION RELIGIEUSE', 'R\xC9DUCTION DE CAPACIT\xC9', 'LIMITATION DE VITESSE', 'RESTRICTION CAT\xC9GORIELLE', 'ITIN\xC9RAIRE BIS', 'ITIN\xC9RAIRE CONSEILL\xC9',
				'AXE COUP\xC9 POUR LES PL', 'AXE COUP\xC9 POUR LES VL', 'CONDITIONS DE CIRCULATION DIFFICILES', 'RESTRICTION DE CIRCULATION', 'MANIFESTATION'];
	dico[1]=['NO HGV ACCESS','Closed Road', 'Rerouting', 'Roadworks', 'Accident', 'Alternate lane system', 'Contraflow', 'Flooding', 'Fire', 'Obstruction hazards', 'Subsidence', 'Rocksfalls', 'Avalanches', 'Earthquake damage', 'Storm damage', 'Flash flood', 'Incident', 'Breakdown', 'Demonstration', 'Sports event', 
				'Fair', 'Ceremonial event', 'Lane closure', 'Temporary speed limit', 'Restriction', 'Secondary way', 'Adviced route', 
				'Road closed for truck', 'Road closed for light vehicle', 'Disrupt traffic', 'Restriction', 'Demonstration'];

	var trouve = 0;
	if (langue == "EN")
	{
		for (var j=0;j<dico[0].length;j=j+1)
		{
			if (dico[0][j] == unMOT_FR_UP)
			{
				unMOT = dico[1][j];
				trouve = 1;
				break;
			}
		}	
	}
	if (trouve == 0)
	{
		//On essaie de traduire un sens
		unMOT = getTraductionSENS(unMOT_FR, langue);
		if (unMOT != unMOT_FR)
			trouve = 1;
	}
	if (trouve == 0)
	{
		//Tentative de traduction de la localisation
		unMOT = getTraductionLOCALISATION(unMOT_FR, langue);
		if (unMOT != unMOT_FR)
			trouve = 1;
	}
	if (trouve == 0)
	{
		unMOT = getTraductionFIN(unMOT_FR, langue);
		if (unMOT != unMOT_FR)
			trouve = 1;
	}
	if (langue == "EN" && trouve == 0)
		unMOT = "";

	return unMOT;
}

function getTraductionSENS(unMOT_FR, langue)
{
	var unMOT = unMOT_FR;
	var unMOT_FR_UP = unMOT_FR.toUpperCase();

	var dico = new Array();
	
	if (langue == "EN")
	{
		if (unMOT_FR_UP.indexOf("DANS LES DEUX SENS") >= 0)
		{
			unMOT_FR_UP = unMOT_FR_UP.replace("DANS LES DEUX SENS", "Both ways");
			unMOT = unMOT_FR_UP;
		}
		else
		{
			if (unMOT_FR_UP.indexOf("DANS LE SENS") >= 0)
			{
				unMOT_FR_UP = unMOT_FR_UP.replace("DANS LE SENS", "");		
				unMOT_FR_UP = unMOT_FR_UP.replace("NORD-SUD", "South Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("NORD SUD", "South Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("SUD-NORD", "North Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("SUD NORD", "North Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("OUEST-EST", "East Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("OUEST EST", "East Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("EST-OUEST", "West Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("EST OUEST", "West Bound");
				unMOT_FR_UP = unMOT_FR_UP.replace("INT\xC9RIEUR", "Inside ring road");
				unMOT_FR_UP = unMOT_FR_UP.replace("EXT\xC9RIEUR", "Outside ring road");
				unMOT_FR_UP = unMOT_FR_UP.replace("INTERIEUR", "Inside ring road");
				unMOT_FR_UP = unMOT_FR_UP.replace("EXTERIEUR", "Outside ring road");
				unMOT = unMOT_FR_UP;
			}
		}
	}
	
	return unMOT;
}

function getTraductionLOCALISATION(unMOT_FR, langue)
{
	var unMOT = unMOT_FR;

	var dico = new Array();

	if (langue == "EN")
	{
		if ((unMOT.substr(0, 1) == "\xE0") && (unMOT.indexOf(" sur ") >= 0))
		{
			unMOT = unMOT.replace("\xE0 ", "at ");
			unMOT = unMOT.replace(" sur la ", " on ");
			unMOT = unMOT.replace(" sur le ", " on ");
			unMOT = unMOT.replace(" sur ", " on ");
		}
	}
	
	return unMOT;
}


function getTraductionFIN(unMOT_FR, langue)
{
	var unMOT = unMOT_FR;
	var unMOT_FR_UP = unMOT_FR.toUpperCase();
	var trouv = 0;

	var dico = new Array();

	if (langue == "EN")
	{
		if (unMOT_FR_UP.indexOf("FIN PR\xC9VUE") >= 0)
		{
			unMOT_FR_UP = unMOT_FR_UP.replace("FIN PR\xC9VUE LE", "Expected finish time");
			unMOT_FR_UP = unMOT_FR_UP.replace(" \xC0 ", " at ");
			trouv = 1;
		}
		if ((trouv == 1) || (unMOT_FR_UP.indexOf("SOURCE :") >= 0) || (unMOT_FR_UP.indexOf("SOURCE:") >= 0))
		{
			unMOT_FR_UP = unMOT_FR_UP.replace("SOURCE :", "Informations supplier :");
			unMOT_FR_UP = unMOT_FR_UP.replace("SOURCE:", "Informations supplier :");
			unMOT = unMOT_FR_UP;
		}
	}
	
	return unMOT;
}

//


