var scrolldelay = 25;
var scroll_dist = 10;
var scroll_count = 21;

var count = 0;

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function closeAll(){
	hidediv('sub_nav_orange');
	hidediv('sub_nav_rouge');
	hidediv('sub_nav_gris');
	//clearInterval(timeOut);
}

function showAll(){
	showdiv('sub_nav_orange');
	showdiv('sub_nav_rouge');
	showdiv('sub_nav_gris');
	//clearInterval(timeOut);
}

function replaceIt(string,str_find,str_replace) {
	begin = "";
	end = "" + string;
	while (end.indexOf(str_find)>-1) {
		pos = end.indexOf(str_find);
		begin = "" + begin + end.substring(0, pos) + str_replace;
		end = ""+ end.substring((pos + str_find.length), end.length);
	}
	return begin+end;
}

function getLeft(objectId) {
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	//oParent = o.offsetParent    // Get parent object reference
	//oLeft += oParent.offsetLeft // Add parent left position
	//o = oParent
	return oLeft
}

function getTop(objectId) {
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get top position from the parent object
	//oParent = o.offsetParent    // Get parent object reference
	//oTop += oParent.offsetTop // Add parent top position
	//o = oParent
	return oTop
}

function getWidth(objectId) {
	o = document.getElementById(objectId);
	oParent = o.parentNode;
	oWidth = replaceIt(oParent.style.width,'px','');
	return oWidth
}

function getHeight(objectId) {
	o = document.getElementById(objectId);
	oParent = o.parentNode;
	oHeight = replaceIt(oParent.style.height,'px','');
	return oHeight
}

function scroll_right(element,stop_element){
	count++;
	var left = parseInt(replaceIt(document.getElementById(element).style.left,'px',''));
	gauche = getLeft(stop_element);
	largeur = getWidth(element);
	//alert("L:"+left+" G:"+gauche+" La:"+largeur);
	if ((gauche+left > largeur) && (count<scroll_count)){
		left = left-scroll_dist;
		document.getElementById(element).style.left = left+"px";
		var func = "scroll_right('"+element+"','"+stop_element+"')";
		window.setTimeout(func, scrolldelay);
	}
	else{
		count=0;
	}
}

function scroll_left(element,stop_element){
	count++;
	var left = parseInt(replaceIt(document.getElementById(element).style.left,'px',''));
	gauche = getLeft(stop_element);
	largeur = getWidth(element);
	//alert("L:"+left+" G:"+gauche+" La:"+largeur);
	if ((left < 0) && (count<scroll_count)){
		left = left+scroll_dist;
		document.getElementById(element).style.left = left+"px";
		var func = "scroll_left('"+element+"','"+stop_element+"')";
		window.setTimeout(func, scrolldelay);
	}
	else{
		count=0;
	}
}

function scroll_bottom(element,stop_element){
	//alert(element+" "+stop_element);
	count++;
	var top = parseInt(replaceIt(document.getElementById(element).style.top,'px',''));
	haut = getTop(stop_element);
	hauteur = getHeight(element);
	//alert("H:"+haut+" T:"+top+" Ha:"+hauteur+"\n"+haut+"+"+top+">"+hauteur+" && "+count+"<"+scroll_count);
	if ((haut+top > hauteur) && (count<scroll_count)){
		top = top-scroll_dist;
		//alert(top);
		document.getElementById(element).style.top = top+"px";
		var func = "scroll_bottom('"+element+"','"+stop_element+"')";
		window.setTimeout(func, scrolldelay);
	}
	else{
		count=0;
	}
}

function scroll_top(element,stop_element){
	count++;
	var top = parseInt(replaceIt(document.getElementById(element).style.top,'px',''));
	haut = getTop(stop_element);
	hauteur = getHeight(element);
	//alert("L:"+left+" G:"+gauche+" La:"+largeur);
	if ((top < 0) && (count<scroll_count)){
		top = top+scroll_dist;
		document.getElementById(element).style.top = top+"px";
		var func = "scroll_top('"+element+"','"+stop_element+"')";
		window.setTimeout(func, scrolldelay);
	}
	else{
		count=0;
	}
}

function scroll_horizontal(element,stop_element,button_left,button_right){
	var left = parseInt(replaceIt(document.getElementById(element).style.left,'px',''));
	gauche = getLeft(stop_element);
	largeur = getWidth(element);
	if (gauche+left <= largeur){
		hidediv(button_left);
		hidediv(button_right);
	}
}

function scroll_vertical(element,stop_element,button_top,button_bottom){
	var top = parseInt(replaceIt(document.getElementById(element).style.top,'px',''));
	haut = getTop(stop_element)-5;
	hauteur = getHeight(element);
	//alert(element+" H:"+hauteur);
	//alert(element+" H:"+haut+" T:"+top+" Ha:"+hauteur);
	if (haut+top <= hauteur){ // +5px = hauteur de l'image spacer
		hidediv(button_top);
		hidediv(button_bottom);
	}
}

/* PRINT */

var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printPage(content,page,sat,id1,id2){
	if (document.getElementById != null){
		var printWin = window.open("print.php?page="+page+"&sat="+sat+"&id1="+id1+"&id2="+id2,"print","width=652, height=650, menubar=1, toolbar=0, directories=0, scrollbars=1, resizable=0");
		
		/*if (gAutoPrint)
			printWin.print();*/
		//if (!window.opera)
			//printWin.close();
	}
	else{
		alert("Désolé, cette fonctionnalité ne fonctionne qu'avec les navigateurs modernes.");
	}
}