var timerID = null;
var timerOn = false;
var timecount = 200;
var timerIDC = null;
var timerOnC = false;
var timecountC = 200;

var prefix = "ctl00_cphZoneContenu_";
var detect = navigator.userAgent.toLowerCase();
var browser;
var version = 0;

/* Drimwouiveur */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/* menu marques*/
function menu(state){
	var menuItem = document.getElementById('menu-v').style;
	if (state == 1){

		menuItem.display = "none";
		obj = document.getElementById("ctl00_hdrMenu2_02");
		if(obj == null){
			obj = document.getElementById("hdrMenu2_02");
			url = obj.src.replace('-roll','');
			obj.src = url;
		}
		else{
			url = obj.src.replace('-roll','');
			obj.src = url;
		}
	} else {
		if (menuItem.display == "none") {
		menuItem.display = ""; }
	}
}

function startTime() {
	if (timerOn == false) { timerID=setTimeout("menu(1)", timecount); }
	timerOn = true;
}
 
function stopTime() { 
if (timerOn) { 
	clearTimeout(timerID); 
	timerID = null; 
	timerOn = false; } 
	menu(0);
}
/* menu compagnie */
function menuC(state){
	var menuItem = document.getElementById('menu-c').style;
	if (state == 1){
		menuItem.display = "none";
		obj = document.getElementById("ctl00_hdrMenu2_01");
		if(obj == null){
			obj = document.getElementById("hdrMenu2_01");
			url = obj.src.replace('-roll','');
			obj.src = url;
		}
		else{
			url = obj.src.replace('-roll','');
			obj.src = url;
		}

	} else {
		if (menuItem.display == "none") {
		menuItem.display = ""; }
	}
}

function startTimeC() {
	if (timerOnC == false) { timerIDC=setTimeout("menuC(1)", timecountC); }
	timerOnC = true;
}
 
function stopTimeC() { 
if (timerOnC) { 
	clearTimeout(timerIDC); 
	timerIDC = null; 
	timerOnC = false; } 
	menuC(0);
}



/* sniffer NS6 + IE/Safari mac */
function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


if (checkIt('netscape')){
	browser = "Netscape"
	version = detect.charAt(8);
} else if (checkIt('mac')){ 
	if (checkIt('msie') || checkIt('safari')){ browser = "Mac unsupported"; }
}



if (browser == "Netscape" && version <= 6){
	var style ="";
	style = "\n<style type=\"text/css\">\n";
	style += ":focus { -moz-outline-style: none; }\n";
	style += "ul.menu li { background: #981B1D !important; }\n";
	style += "ul.menu ul { left: -1px; }\n";
	style += "</style>\n"; 
	document.write(style);
}


if (browser == "Mac unsupported"){
	var style = "<style type=\"text/css\">@media Screen, Projection { ul.menu li:hover > ul { top: 0; }}</style>";
	document.write(style); 
}

/* print */
function imprimer(lang){
	if (window.print) { window.print(); } 
	else { 
		var warning = ""
		switch(lang) {
			case "/medias/fr/":
				warning = "Votre navigateur n'est pas compatible avec l'impression directe.\n\nPour imprimer, allez dans le menu Fichier de votre navigateur et choisissez \"Imprimer\".";
			break
			case "/medias/es/":
				warning = "Tu browser no apoya la impresión directa.\n\nPara imprimir, ir al menú \"Archivo\" de tu browser y seleccionar la \"impresión\".";
			break				
			default:
				warning = "Your browser does not support direct printing.\n\nTo print, go to the File menu of your browser and select \"Print\".";
		}
		alert(warning); 
	}
}

/* toggle features/options */
function toggleFeatOpt(element){
	var btnFeatures = document.getElementById('aBtnFeatures');
	var btnOptions = document.getElementById('aBtnOptions');
	var pFeatures = document.getElementById(prefix+'pFeatures');
	var pOptions = document.getElementById(prefix+'pOptions');

	if( element==0 ){
		btnFeatures.className = 'active';
		btnOptions.className = '';
		pFeatures.style.display = '';
		pOptions.style.display = 'none';
	} else {
		btnFeatures.className = '';
		btnOptions.className = 'active';
		pFeatures.style.display = 'none';
		pOptions.style.display = '';
	}
}

function populateFeatures(){
document.getElementById('txtFeatures').innerHTML = document.getElementById('innerScroll').innerHTML
}

/* show/hide contenu */
function showItem(element,map){
	hideItems();
	document.getElementById(prefix+element).style.display = "";
	if (map){
		hideItem(prefix+"pMapCan");
		hideItem(prefix+"pMapUSA");
		hideItem(prefix+"pMapMex");
		document.getElementById(prefix+map).style.display = "";
	}
	if (browser !== "Mac unsupported") { anchorItem(); }
}

function hideItems(){
	hideItem(prefix+"pTechInfos");
	hideItem(prefix+"pTechSpec");
	hideItem(prefix+"pDealers");
	hideItem(prefix+"pBenchLabs");
	hideItem(prefix+"pWarranty");
	hideItem(prefix+"pTestimonies");	
}

function anchorItem(){
	var strUrl = window.location.href;
	var scrollPos = f_scrollTop();
	if (scrollPos <= 305) { 
		var intPos = strUrl.indexOf("#");
		if (intPos !== -1) { strUrl = strUrl.slice(0,intPos) }
		strUrl = strUrl + "#main";
		window.location.href = strUrl;
	}
}

function hideItem(element){
	if (document.getElementById(element)){ 
		panel = document.getElementById(element).style;
		if (panel.display != "none"){ panel.display = "none"; }
	}
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}