function initForm(){
	initChangeCriteria();
	initReduire();
	initReduireItin();
//	smallMap="sw-sGmap";
	bigMap="sw-bGmap";
	printMap="sw-pGmap";
//	if (document.getElementById(smallMap)){
//		init_smallMap(smallMap);
//	}
	if (document.getElementById(bigMap)){
		init_smallMap(bigMap);
	}
	if (document.getElementById(printMap)){
		init_smallMap(printMap);
	}
	addEvent(window, 'unload', GUnload);
	// Preload Images
	addClassName(document.getElementsByTagName("body"),'imageLoader' );
}

function initChangeCriteria(){

  var oDiv = document.getElementById('sw-results-display');
  var oLink = document.getElementById('sw-btn-changeCriteria');
  var odivToShow = document.getElementById('sw-searchForm');
  if (!oLink) return false;
  oLink.onclick = function() {
  	removeClassName(oDiv,'sw-visible');	
  	addClassName(oDiv,'sw-hidden');
  	removeClassName(odivToShow,'sw-hidden');
  	addClassName(odivToShow,'sw-visible');
  };

}

function initReduire(){
  var oDiv = document.getElementById('sw-searchForm');
  var oLink = document.getElementById('sw-form-navig-link');
  var odivToShow = document.getElementById('sw-results-display');
  if (!oLink) return false;
  	oLink.onclick = function() {
  	removeClassName(oDiv,'sw-visible');
  	addClassName(oDiv,'sw-hidden');
  	removeClassName(odivToShow,'sw-hidden');
  	addClassName(odivToShow,'sw-visible');
	 };
}
function initReduireItin(){
  var oDiv = document.getElementById('sw-itineraire');
  var oLink = document.getElementById('sw-itin-navig-link');
  var odivToShow = document.getElementById('sw-results-display');
  if (!oLink) return false;
  	oLink.onclick = function() {
  	removeClassName(oDiv,'sw-visible');
  	addClassName(oDiv,'sw-hidden');
  	removeClassName(odivToShow,'sw-hidden');
  	addClassName(odivToShow,'sw-visible');
	 };
}

/*--------------------------------------------------------------------------*/

//http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}

//http://www.bigbold.com/snippets/posts/show/2630
function addClassName(objElement, strClass, blnMayAlreadyExist){
   
	if (objElement != null)
	{
	   if ( objElement.className ){
	   	
	      var arrList = objElement.className.split(' ');
	      if ( blnMayAlreadyExist ){
	         var strClassUpper = strClass.toUpperCase();
	         for ( var i = 0; i < arrList.length; i++ ){
	            if ( arrList[i].toUpperCase() == strClassUpper ){
	               arrList.splice(i, 1);
	               i--;
	             }
	           }
	      }
	      arrList[arrList.length] = strClass;
	      objElement.className = arrList.join(' ');
	   }
	   else{  
	      objElement.className = strClass;
	      }
	}
}

//http://www.bigbold.com/snippets/posts/show/2630
function removeClassName(objElement, strClass){
	if (objElement != null)
	{
	   if ( objElement.className ){
	      var arrList = objElement.className.split(' ');
	      var strClassUpper = strClass.toUpperCase();
	      for ( var i = 0; i < arrList.length; i++ ){
	         if ( arrList[i].toUpperCase() == strClassUpper ){
	            arrList.splice(i, 1);
	            i--;
	         }
	      }
	      objElement.className = arrList.join(' ');
	   }
	}
}


//http://ejohn.org/projects/flexible-javascript-events/
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
    obj.attachEvent( "on"+type, obj[type+fn] );
  } 
  else{
    obj.addEventListener( type, fn, false );	
  }
}

OverlayMessage = function ( container )    {    // +-----------------+    // |wrapper          |    // |+---------------+|    // ||container      ||    // ||   +-------+   ||    // ||   |overlay|   ||    // ||   +-------+   ||    // |+---------------+|    // +-----------------+    // Get the parent.    var parent = container.parentNode;    // Make the wrapper div.    var wrapper = document.createElement( 'div' );
    var xheight = container.offsetHeight;
    wrapper.style.cssText = "padding:10px;margin:10px;clearfix;position:relative;float:none!important;height:"+ xheight+";";    parent.insertBefore( wrapper, container );    // Move the container into the wrapper.    parent.removeChild( container );    wrapper.appendChild( container );    container.style.cssText = 'clearfix';    // Add the overlay div.    this.overlay = document.createElement( 'div' );    container.appendChild( this.overlay );
    this.overlay.setAttribute('id','cust-overtlay'); 
    this.visibleStyle = 'display:block;font-size:1.25em;color:#294aab;position:absolute;top:40%;left:210px; background-color: #c5dcfd; width: 40%; text-align: center; padding: 2em; border: 0.08in solid #294aab; z-index: 100;';    this.invisibleStyle = 'display: none;';    this.overlay.style.cssText = this.invisibleStyle;    };OverlayMessage.prototype.Set = function ( message )    {    this.overlay.innerHTML = message;    this.overlay.style.cssText = this.visibleStyle;    };OverlayMessage.prototype.Clear = function ()    {    this.overlay.style.cssText = this.invisibleStyle;    };OverlayMessage.SetBackgroundColor = function ( color )    {    OverlayMessage.backgroundColor = color;    };OverlayMessage.SetBorderColor = function ( color )    {    OverlayMessage.borderColor = color;    };
    
   
    // insert msg in Dom
    function shwmsg(msg,div,closeable)
	{
		if(closeable == null)
			closeable = true ;
			
		var divs=document.getElementById(div);
		var closebtn = "" ;
		
		if (closeable == true)
			closebtn = "<span class=\"closelink\"><a href=\"javascript:clearme('"+div+"');\">Fermer</a></span>";
		
		divs.innerHTML = msg + closebtn;
		removeClassName(divs,'sw-hidden');	
  		addClassName(divs,'sw-visible');
  	
	}
	// Clear msg in Dom
    function clearme(div)
	{   
		var divs=document.getElementById(div);
		removeClassName(divs,'sw-visible');	
  		addClassName(divs,'sw-hidden');
	}
	
	
	
	
	
addEvent(window, 'load', initForm);


