// JavaScript Document
// PORTACHIAVI VOLANTE

	var index = false;
	var imgOn=false;
	var newImg;
	var timeoutID;
	function showImage(fname, mid) {
		
		if (!timeoutID) {
			newImg="http://www.scoobike.ch/images/catalogue/"+mid+"/bike-images/"+fname;
			var imgCont=$('theImgContainer');
			var imgTag=$('theImg');
			if (!imgOn) {
				Effect.SlideDown(imgCont);
				imgTag.src=newImg;
				imgOn=true;
			} else if (newImg!=imgTag.src) {
				Effect.Fade(imgTag);
				timeoutID=setTimeout("showNewImg();", 1000);
			}
		}
		
	}
	function showImageShop(fname, shop) {
		
		if (!timeoutID) {
			newImg="http://www.scoobike.ch/images/shops/"+shop+"/"+fname;
			var imgCont=$('theImgContainer');
			var imgTag=$('theImg');
			if (!imgOn) {
				Effect.SlideDown(imgCont);
				imgTag.src=newImg;
				imgOn=true;
			} else if (newImg!=imgTag.src) {
				Effect.Fade(imgTag);
				timeoutID=setTimeout("showNewImg();", 1000);
			}
		}
		
	}
	function showImageCdm(fname) {
		
		if (!timeoutID) {
			newImg="http://www.scoobike.ch/images/cdm/"+fname;
			var imgCont=$('theImgContainer');
			var imgTag=$('theImg');
			if (!imgOn) {
				Effect.SlideDown(imgCont);
				imgTag.src=newImg;
				imgOn=true;
			} else if (newImg!=imgTag.src) {
				Effect.Fade(imgTag);
				timeoutID=setTimeout("showNewImg();", 1000);
			}
		}
		
	}
	function showNewImg() {
		clearTimeout(timeoutID);
		var imgTag=$('theImg');
		imgTag.src=newImg;
		Effect.Appear(imgTag);
		timeoutID=0;
	}
	function closeImage() {
		var imgCont=$('theImgContainer');
		if (imgOn) {
			Effect.SlideUp(imgCont);
			imgOn=false;
		}
	}
	
	var liv_prix=0;
	var reg=0, lieu=0; // region et lieu choisis
	function addLiv() {
		var theReg=$('liv_reg');
		var theLieu=$('liv_lieu');
		var i=0;
		var thePrice=$('priceShow');
		var theLivPrice=$('liv_price_txt');
		var theLivLieu=$('liv_lieu_txt');
		//var a1=$('amount_pp');
		//var a2=$('amount_pf');
		
		try {
				Effect.Fade('liv_infos'+reg+lieu, { queue:'front', duration:1 });
		} catch(e) {
				Effect.Fade('liv_infos00', { queue:'end', duration:1 });
		}
		
		var thePriceNum=parseInt(thePrice.innerHTML.replace("'",""));
		
		for (i; i<theReg.options.length; i++) {
			if (theReg.options[i].selected) {
				reg=i;
				break;
			}
		}
		i=0;
		for (i; i<theLieu.options.length; i++) {
			if (theLieu.options[i].selected) {
				lieu=i;
				break;
			}
		}
		
		// tableau 2x3 des prix
		var tab_prix=new Array(new Array(0,60,120), new Array(0,0,120));
		var tab_lieu=new Array(new Array('Meyrin - CdM','Genève - ScooBike Shop','Livraison à domicile'),
								new Array('Meyrin - CdM','Lausanne - ScooBike Shop','Livraison à domicile'));
		
		if (liv_prix) {
			thePriceNum-=liv_prix;
		}
		liv_prix=tab_prix[reg][lieu];
		
		
		
		thePrice.innerHTML=parseInt(thePriceNum)+liv_prix;
		
		//a1.value=thePrice.innerHTML;
		//a2.value=parseInt(thePrice.innerHTML)*100;
		if (thePrice.innerHTML.length>3) {
			thePrice.innerHTML= thePrice.innerHTML.substr(0,thePrice.innerHTML.length-3) + "'" +
								thePrice.innerHTML.substr(thePrice.innerHTML.length-3,thePrice.innerHTML.length);
		}
		thePrice.innerHTML+='.00';
		theLivPrice.innerHTML=liv_prix;
		theLivLieu.innerHTML=tab_lieu[reg][lieu];
		try {
				Effect.Appear('liv_infos'+reg+lieu, { queue:'end', duration:1 });
		} catch(e) {
				Effect.Appear('liv_infos00', { queue:'end', duration:1 });
		}
	}
	var ssAdded=false;
	function addScSu(add) {
		var thePrice=$('priceShow');
		var ok=false;
		thePriceNum=parseInt(thePrice.innerHTML.replace("'",""));
		
		if (add) {
			if (!ssAdded) {
				thePrice.innerHTML=parseInt(thePriceNum)+200;
				ssAdded=true;
				ok=true;
				try { // solo se nella pagina compra prodotto
					Effect.SlideDown('cart_sbsupp');
				} catch(e) {}
			}
		} else {
			if (ssAdded) {
				thePrice.innerHTML=parseInt(thePriceNum)-200;
				ssAdded=false;
				ok=true;
				try { // solo se nella pagina compra prodotto
					Effect.SlideUp('cart_sbsupp');
				} catch(e) {}
			}
		}
		if (ok) {
			if (thePrice.innerHTML.length>3) {
				thePrice.innerHTML= thePrice.innerHTML.substr(0,thePrice.innerHTML.length-3) + "'" +
									thePrice.innerHTML.substr(thePrice.innerHTML.length-3,thePrice.innerHTML.length);
			}
			thePrice.innerHTML+='.00';
		}
	}
	function pay(how, img) {
		var theCards=$('cartes');
		theCards.src=img;
		theCards.style.display='block';
		
		var divPP=$('by_paypal');
		var divPoste=$('by_poste');
		if (how=='pp') {
			divPP.style.display='block';
			divPoste.style.display='none';
		} else {
			divPP.style.display='none';
			divPoste.style.display='block';
		}
		
	}
	function setPC(isIndex) {
		// deprecated
		
		/*var tb = document.all ? document.all['Table_01'] : document.getElementById('Table_01');
		var minus = 57;
		var minus_bis = 14;
		if (document.all) {
			minus=56;
			minus_bis = 13;
		}
		var tbW = parseInt(tb.offsetWidth);
		
		var edge = document.all ? document.all['edgeleft'] : document.getElementById('edgeleft');
		edge.style.left = (((tbW-800)/2)-minus_bis)+"px";
		edge.style.visibility = "visible";
		var pcLeft = tbW-((tbW-800)/2)-minus;
		if (isIndex) {
			var pc = document.all ? document.all['portecles'] : document.getElementById('portecles');
			pc.style.left= pcLeft+"px";
			pc.style.visibility = "visible";
		} else {
			var edger = document.all ? document.all['edgeright'] : document.getElementById('edgeright');
			edger.style.left = (pcLeft+50)+"px";
			edger.style.visibility = "visible";
		}*/
		
		
	}
	function setPCimg(isIndex) {
  		var platform = navigator.platform;
		if (platform.indexOf('Win')!=-1) {
			if (isIndex) {
				var pcimg = document.all ? document.all['pcimg'] : document.getElementById('pcimg');
				pcimg.src= "http://www.scoobike.ch/images/pc_win.jpg";
			}
			var edgeimg = document.all ? document.all['edgeimg'] : document.getElementById('edgeimg');
			edgeimg.src= "http://www.scoobike.ch/images/bar_left_edge_win.jpg";
		}
	}
	window.onresize = function() { setPC(index); }
	window.onload= function() { setPCimg(index); setPC(index); }
// FINE PORTACHIAVI
	function execute(submenu, ct) {
			if (submenu==1 && document.getElementById('submenu_prod').style.display!='none')
				noSubMenu(ct);
				/*
			else if (submenu==2 && document.getElementById('submenu_societe').style.display!='none')
				noSubMenu(ct);
			else if (submenu==3 && document.getElementById('submenu_techno').style.display!='none')
				noSubMenu(ct);
			*/
		}
	function retard(context) {
		if (!context) {
			if (document.getElementById('submenu_prod').style.display!='none') {
				setTimeout("execute(1, '"+context+"');", 8000);/*
				
			} else if (document.getElementById('submenu_societe').style.display!='none') {
				setTimeout("execute(2, '"+context+"');", 8000);
			} else if (document.getElementById('submenu_techno').style.display!='none') {
				setTimeout("execute(3, '"+context+"');", 8000);*/
			}
		}
	}
	
	function noSubMenu(context) {
		if (context == 'societe') {
			
			document.getElementById('submenu_prod').style.display='none';
			//document.getElementById('submenu_techno').style.display='none';
		} else if (context == 'prod') {
			document.getElementById('submenu_prod').style.display='inline';
			document.getElementById('submenu').style.display='none';
			//document.getElementById('submenu_techno').style.display='none';
		} else if (context == 'techno') {
			document.getElementById('submenu_prod').style.display='none';
			//document.getElementById('submenu_techno').style.display='inline';
		} else {
			document.getElementById('submenu').style.display='inline';
			document.getElementById('submenu_prod').style.display='none';
			//document.getElementById('submenu_techno').style.display='none';
		}
	}
	
	function replaceSubMenu(context, menu) {
		if (context == 'societe') {
			if (menu=='prod') {
				document.getElementById('submenu_prod').style.display='inline';
				//document.getElementById('submenu_techno').style.display='none';
			} else if (menu=='techno') {
				document.getElementById('submenu_prod').style.display='none';
				//document.getElementById('submenu_techno').style.display='inline';
			}
		} else if (context == 'prod') {
			document.getElementById('submenu_prod').style.display='none';
			if (menu=='societe') {
				
				//document.getElementById('submenu_techno').style.display='none';
			} else if (menu=='techno') {
				//document.getElementById('submenu_techno').style.display='inline';
			}
		} else if (context == 'techno') {
			//document.getElementById('submenu_techno').style.display='none';
			if (menu=='societe') {
				
				document.getElementById('submenu_prod').style.display='none';
			} else if (menu=='prod') {
				document.getElementById('submenu_prod').style.display='inline';
			}
		} else {
			document.getElementById('submenu').style.display='none';
			document.getElementById('submenu_prod').style.display='none';
			
			//document.getElementById('submenu_techno').style.display='none';
		}

	}
	
	function $(id) {
		return document.getElementById(id);
	}
	
	var ssOn=false;
	function shSupportInfos() {
		if (ssOn) {
			ssOn=false;
			Effect.SlideUp('ssInfos');
		} else {
			ssOn=true;
			Effect.SlideDown('ssInfos');
		}
	}
	var manuelOn=false;
	function shManuel() {
		var a=$('shManuelLink');
		if (manuelOn) {
			manuelOn=false;
			Effect.SlideUp('manuel');
			// language link inner text
			a.innerHTML=showStr;
		} else {
			manuelOn=true;
			Effect.SlideDown('manuel');
			a.innerHTML=hideStr;
		}
	}

// show temoignages
function showTem(text,aut) {
	var bb=document.getElementById('home_blackBox');
	var arrayPageSize = getPageSizeHome();
	// Element.setHeight('home_blackBox', arrayPageSize[1]);
	bb.style.height=arrayPageSize[1]+"px";
	bb.style.width=document.body.offsetWidth+"px";
	bb.style.display='block';
	
	var dialog=document.getElementById('dialog_tem');
	var top=(window.pageYOffset+200);
	top=top?top:document.documentElement.scrollTop+200; // IE6 compliant
	try { dialog.style.top=top+"px"; dialog.style.left=(document.body.offsetWidth/2-350)+"px"; } catch(e) {} // just in case
	dialog.style.display='block';
	document.getElementById('feedback').innerHTML=text;
	document.getElementById('author').innerHTML=aut;
}
function hideTem() {
	var bb=document.getElementById('home_blackBox');
	bb.style.display='none';
	var dialog=document.getElementById('dialog_tem');
	dialog.style.display='none';
	document.getElementById('feedback').innerHTML='';
	document.getElementById('author').innerHTML='';
}

function getPageSizeHome(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}