function addNetscapeSidebar()
{
	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
	{
		window.sidebar.addPanel ("STP (non-officiel)", "http://poitiers.transbus.org/push.html","");
	}
	else
	{
		var rv = window.confirm ("This page is enhanced for use with Netscape 6.	" + "Would you like to upgrade now?");
		if (rv) document.location.href = "http://home.netscape.com/download/index.html";
	}
}


function isMsie4orGreater()
{
	var ua=window.navigator.userAgent;
	var msie=ua.indexOf ("MSIE");
	if (msie>0)
	{
		return (parseInt (ua.substring (msie+5, ua.indexOf (".", msie))) >= 4) && (ua.indexOf ("MSIE 4.0b") <0);
	}
	else
	{
		return false;
	}
}


function imgParc()
{
	var x=-1;
	while (x<1)
	{
		x=Math.round(Math.random()*8);
	}
	document.write('<p class="pIntro"><img src="img_depot_');
	document.write(x);
	document.write('.jpg" alt="Dépôts" class="imgRub" /></p>');
}


function getAllSheets()
{
	if (navigator.__ice_version)
	{
		return document.styleSheets;
	}
	if (document.getElementsByTagName)
	{
		var lt=document.getElementsByTagName('link'),st=document.getElementsByTagName('style');
	}
	else if (document.styleSheets && document.all)
	{
		var lt=document.all.tags('link'),st=document.all.tags('style');
	}
	else
	{
		return [];
	}
	for (var x=0, os=[]; lt[x]; x++)
	{
		var rel=lt[x].rel ? lt[x].rel : lt[x].getAttribute ? lt[x].getAttribute('rel') : '';
		if (typeof(rel) == 'string' && rel.toLowerCase().indexOf('style')+1)
		{
			os[os.length]=lt[x];
		}
	}
	os.concat(st);
	return os;
}


function setActiveStyleSheet()
{
	window.userWin=true;
	for (var x=0, ss=getAllSheets(); ss[x]; x++)
	{
		if (ss[x].title)
		{
			ss[x].disabled=true;
		}
		for (var y=0; y<arguments.length; y++)
		{
			if (ss[x].title==arguments[y])
			{
				ss[x].disabled=false;
			}
		}
	}
}


function getPreferredStyleSheet(cookieName,cookieLife)
{
	for (var viewUsed=false, ss=getAllSheets(), x=0; window.SNOss && ss[x]; x++)
	{
		if(ss[x].disabled != SNOss[x])
		{
			viewUsed=true;
			break;
		}
	}
	if (!window.userWin && !viewUsed)
	{
		return;
	}
	for (var x=0, outLine=''; ss[x]; x++)
	{
		if (ss[x].title && ss[x].disabled==false)
		{
			outLine += (outLine ? ' SNO ' : '')+escape(ss[x].title);
		}
	}
	if (ss.length)
	{
		document.cookie=escape(cookieName) + '=' + escape(outLine)+(cookieLife ? ';expires=' + new Date((new Date()).getTime()+(cookieLife*24*60*60*1000)).toGMTString() : '')+'; path=/';
	}
}


function savePreferredStyleSheet(cookieName)
{
	window.SNOss=[];
	for (var ss=getAllSheets(), x=0; ss[x]; x++)
	{
		SNOss[x]=ss[x].disabled;
	}
	for (var x=0; x<document.cookie.split("; ").length; x++)
	{
		var oneCookie=document.cookie.split("; ")[x].split("=");
		if (oneCookie[0] == escape(cookieName))
		{
			var styleStrings=unescape(oneCookie[1]).split(" SNO ");
			for (var y=0, funcStr = ''; styleStrings[y]; y++)
			{
				funcStr += (y ? ',' : '') + 'unescape(styleStrings[' + y + '])';
			}
			eval('setActiveStyleSheet(' + funcStr + ');');
			break;
		}
	}
}


function getElementsByClassName(_clsName)
{
	var matches = new Array(), els = document.getElementsByTagName('*');
	for(var i = 0; i < els.length; i++)
	{
		if(els.item(i).className == _clsName) matches.push(els.item(i));
	}
	return matches;
}


function toggleRef(_clsName,_idShowHide)
{
	var btns = getElementsByClassName(_clsName);
	for(var i = 0; i < btns.length; i++)
	{
		btns[i].style.visibility = (btns[i].style.visibility != 'hidden') ? 'hidden': 'visible';
		if (btns[i].style.visibility == 'hidden')
		{
			document.getElementById(_idShowHide).childNodes[0].nodeValue = "afficher les vĂ©hicule rĂ©formĂ©s";
		} else {
			document.getElementById(_idShowHide).childNodes[0].nodeValue = "masquer les vĂ©hicule rĂ©formĂ©s";
		}
	}
	return true;
}


function viewPano(_idPano,_filePano)
{
	var isIEPano = document.getElementById('divImageObjPano');
	if (_filePano == "gare" || _filePano == "pjoubert")
	{
		isIEPano.innerHTML = '<iframe src="dossier_panorama_' + _filePano + '.html" width=400 height=300 frameborder=0 border=0 marginheight=0 marginwidth=0 vspace=0 scrolling=no></iframe><p>'+ document.getElementById(_idPano).childNodes[2].innerHTML + '</p>';
	} else {
		isIEPano.innerHTML = '<iframe src="dossier_panorama_gare.html" width=400 height=300 frameborder=0 border=0 marginheight=0 marginwidth=0 vspace=0 scrolling=no></iframe>';
		document.getElementById('divPanoGare').childNodes[0].style.border = '2px red solid';
	}
}


function selectPano(_idPano,_filePano)
{

	var btns = getElementsByClassName('divImagePano');
	for(var i = 0; i < btns.length; i++)
	{
		btns[i].childNodes[0].style.border = '2px gray solid';
	}

	document.getElementById(_idPano).childNodes[0].style.border = '2px red solid';
	viewPano(_idPano,_filePano);
}


window.onload = function(e)
{
	savePreferredStyleSheet('snostp-style');
}


window.onunload = function(e)
{
	getPreferredStyleSheet('snostp-style');
}







function sortTable(col) {

	// Get the table section to sort.
	var tblEl = document.getElementById("tbodyBus");

	// Set up an array of reverse sort flags, if not done already.
	if (tblEl.reverseSort == null)
		tblEl.reverseSort = new Array();

	// If this column was the last one sorted, reverse its sort direction.
	if (col == tblEl.lastColumn)
		tblEl.reverseSort[col] = !tblEl.reverseSort[col];

	// Remember this column as the last one sorted.
	tblEl.lastColumn = col;

	// Set the table display style to "none" - necessary for Netscape 6 browsers.
	var oldDsply = tblEl.style.display;
	tblEl.style.display = "none";

	// Sort the rows based on the content of the specified column using a selection sort.

	var tmpEl;
	var i, j;
	var minVal, minIdx;
	var testVal;
	var cmp;

	for (i = 0; i < tblEl.rows.length - 1; i++) {

		// Assume the current row has the minimum value.
		minIdx = i;
		minVal = getTextValue(tblEl.rows[i].cells[col]);

		// Search the rows that follow the current one for a smaller value.
		for (j = i + 1; j < tblEl.rows.length; j++) {
			testVal = getTextValue(tblEl.rows[j].cells[col]);
			cmp = compareValues(minVal, testVal);
			// Reverse order?
			if (tblEl.reverseSort[col])
				cmp = -cmp;
			// If this row has a smaller value than the current minimum, remember its position and update the current minimum value.
			if (cmp > 0) {
				minIdx = j;
				minVal = testVal;
			}
		}

		// By now, we have the row with the smallest value. Remove it from the table and insert it before the current row.
		if (minIdx > i) {
			tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
			tblEl.insertBefore(tmpEl, tblEl.rows[i]);
		}
	}

	// Restore the table's display style.
	tblEl.style.display = oldDsply;

	return false;
}

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants (like IE).
if (document.ELEMENT_NODE == null) {
	document.ELEMENT_NODE = 1;
	document.TEXT_NODE = 3;
}

function getTextValue(el) {

	var i;
	var s;

	// Find and concatenate the values of all text nodes contained within the element.
	s = "";
	for (i = 0; i < el.childNodes.length; i++)
		if (el.childNodes[i].nodeType == document.TEXT_NODE)
			s += el.childNodes[i].nodeValue;
		else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
						 el.childNodes[i].tagName == "BR")
			s += " ";
		else
			// Use recursion to get text within sub-elements.
			s += getTextValue(el.childNodes[i]);

	return normalizeString(s);
}

function compareValues(v1, v2) {

	var f1, f2;

	// If the values are numeric, convert them to floats.

	f1 = parseFloat(v1);
	f2 = parseFloat(v2);
	if (!isNaN(f1) && !isNaN(f2)) {
		v1 = f1;
		v2 = f2;
	}

	// Compare the two values.
	if (v1 == v2)
		return 0;
	if (v1 > v2)
		return 1
	return -1;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) {
	s = s.replace(whtSpMult, " ");
	s = s.replace(whtSpEnds, "");
	return s;
}
