// 1k DHTML API - standards version
// http://dithered.chadlindstrom.ca/javascript/1kdhtml/index.html
d=document;l=d.layers;op=navigator.userAgent.indexOf('Opera')!=-1;px='px';
function gE(e,f){if(l){f=(f)?f:self;var V=f.document.layers;if(V[e])return V[e];for(var W=0;W<V.length;)t=gE(e,V[W++]);return t;}if(d.all)return d.all[e];return d.getElementById(e);}
function sE(e){l?e.visibility='show':e.style.visibility='visible';}
function hE(e){l?e.visibility='hide':e.style.visibility='hidden';}
function dB(e){l?e.display='block':e.style.display='block';}
function dN(e){l?e.display='none':e.style.display='none';}
function sZ(e,z){l?e.zIndex=z:e.style.zIndex=z;}
function sX(e,x){l?e.left=x:op?e.style.pixelLeft=x:e.style.left=x+px;}
function sY(e,y){l?e.top=y:op?e.style.pixelTop=y:e.style.top=y+px;}
function sW(e,w){l?e.clip.width=w:op?e.style.pixelWidth=w:e.style.width=w+px;}
function sH(e,h){l?e.clip.height=h:op?e.style.pixelHeight=h:e.style.height=h+px;}
function sC(e,t,r,b,x){l?(X=e.clip,X.top=t,X.right=r,X.bottom=b,X.left=x):e.style.clip='rect('+t+px+' '+r+px+' '+b+px+' '+x+px+')';}
function wH(e,h){if(l){Y=e.document;Y.open();Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}

// Remedial JavaScript 
// http://www.crockford.com/javascript/remedial.html
function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

// Fonctions SYTADIN

/*
* ouvre une fenetre centree
*
* @param string l'url de la page a ouvrir
* @param string le nom associ? a cette page (en un seul mot!)
* @param int la largeur de la page
* @param int la hauteur de la page
*/
function openCenterUrl(htmlurl,nom,width,height) {
  if (width == 'max') {
  	width = screen.width - 60;
	leftf = 0;
  }
  else 
  	leftf =(screen.width-width)/2;
  
  if (height == 'max') {
  	height = screen.height - 60; 
	topf  = 0;
  } 
  else
 	topf  = (screen.height-height)/2;

  nom = nom.replace(/\s/g,"");
  var popup = window.open(htmlurl,nom,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width='+width+',height='+height+',left='+leftf+',top='+topf);
  
  if (popup)
  	popup.focus();
};


/*
 * S?lection des poles dans la recherche d'itineraire par la carte
 */
var fieldFocus = 'depart';
function updateFieldFocus(aName)
{
	fieldFocus = aName;
}
function fillFocusedFormField(value)
{
    var form = document.routeSearch;
    form.item(fieldFocus).value = value;
    // On recherche l'element suivant
    for( var i = 0; i<form.length ; i++){
	    if(form.item(i) == form.item(fieldFocus)){
           if(i == (form.length-1)){
	           i = 0;
           }
           else{
               i++;
           }
           fieldFocus = form.item(i).name;
           break;
	    }
    }
}

// Pour aider le SVG a ouvrir des popups
function openWindow(fileName){
	window.open(fileName);
};

// Gestion des cookies
function setCookie(name, value) {
	document.cookie = name + "=" + value + ";";
}
function getCookieVal(offset){
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen){
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}
