

// common scripts

// Ajax useful functions

function makeHttpRequest() {		
		if(window.XMLHttpRequest) { // Firefox et autres
	  	httpRequest = new XMLHttpRequest();
	  }else if(window.ActiveXObject){ // Internet Explorer
	    try {
	      httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	      try {
	        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (e1) {
	        httpRequest = null;
	      }
	    }
	  }else { // XMLHttpRequest non support?ar le navigateur
	    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	  }  			  		  
		return httpRequest;			
}	

function ajax_action(path, variable, fct_act, elem, wait_msg, finally_msg) {
		httpRequest = null;
		fct_act(elem, wait_msg, httpRequest);
		httpRequest = makeHttpRequest(); // Make the HttpRequest														
        httpRequest.onreadystatechange = function() { fct_act(elem, wait_msg, httpRequest, finally_msg); };
  	    httpRequest.open('POST', path, true);
  	    httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		httpRequest.send(variable);
}


function updateElement(elem, wait_msg, httpRequest, finally_msg) {
		if(httpRequest!=null) {
			if (httpRequest.readyState == 4) {
	        if (httpRequest.status == 200) {
	            document.getElementById(elem).innerHTML=httpRequest.responseText;
	        } else {	        		
	            document.getElementById(elem).innerHTML='/!\ An Error has occured';
	        }
	    }
    }else {
    	document.getElementById(elem).innerHTML=wait_msg;	
    }	
}

//

//Get element by Id on every browsers
function ElementByID(id) {
     if(document.layers) return document.layersid;
     if(document.all && !document.getElementById) return document.allid;
     if(document.all && document.getElementById) return document.getElementById(id); 
     if(!document.all && document.getElementById) return document.getElementById(id); 
}

//Add site to favorites
nav = navigator.appName.substring(0,3);
ver = navigator.appVersion.substring(0,1)
function addFav() {
  if (nav == "Mic" && ver >= 4) {
    url_site="http://www.royal-horse.fr";
    titre_site = "Royal Horse";
    //document.write('<a href="javascript:window.external.AddFavorite(url_site, titre_site);return(false)">Site en favori</a>');
    document.write('<a href="javascript:window.external.AddFavorite(url_site, titre_site);void(0)">Site en favori</a>');
}
  else {
    document.write('<a href="javascript:alert(\'Appuyez sur les touches Ctrl+D pour ajouter le site à vos favoris.\');">Site en favori</a>');
  }
}


// ---------------------------
function OpenCenterPopUp(url, w, h) {
if(w == undefined) w = 760;
if(h == undefined) h = 420;
var Left=window.screen.width/2-(w/2);
var Top=window.screen.height/2-(h/2);
var Configuration='scrollbars=yes, resizable=yes, width='+w+', height='+h+', top='+Top+', left='+Left;
var f = window.open(url,'print',Configuration);
f.focus();
}

// Window open code

// Better window code


function openWin( winURL, winName, winWidth, winHeight, winX, winY, scrollBars, statusBar, menuBar, resizable ) {
	winName = window.open( winURL, winName, 'width='  + winWidth + ',height='  + winHeight + ',top=' + winX + ',left=' + winY + ',screenX=' + winX + ',screenY=' + winY + ',location=no,scrollbars=' + scrollBars + ',directories=no,status=' + statusBar + ',menubar=' + menuBar + ',personalbar=no,resizable=' + resizable );
	// winName.scrollTo( 0, 0 );
}

// Better window code lite
function openWinLite( winURL, winName ) {
	winName = window.open( winURL, winName, 'width=400,height=300,top=100,left=100,screenX=100,screenY=100,location=no,scrollbars=no,directories=no,status=no,menubar=no,personalbar=no,resizable=no' );
	// winName.scrollTo( 0, 0 );
}

function printerFriendlyWin(winURL) {
	winName = window.open( winURL, 'printerWin', 'width=570,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,personalbar=no,resizable=yes');
}

function openHelpWin( winURL, winName, winWidth, winHeight ) {
	winName = window.open( winURL, winName, 'width='  + winWidth + ',height='  + winHeight + ',top=100,left=100,screenX=100,screenY=100,location=no,scrollbars=yes,directories=no,status=yes,menubar=no,personalbar=no,resizable=yes' );
	// winName.scrollTo( 0, 0 );
}


// Calendar window opener
function calendarWin( winURL, winWidth, winHeight ) {
	calendarWinRef = window.open( winURL, 'calendarWinSysName', 'width='  + winWidth + ',height='  + winHeight + ',top=50,left=50,screenX=50,screenY=50,location=no,scrollbars=yes,directories=no,status=yes,menubar=no,personalbar=no,resizable=yes' );
	// calendarWinRef.scrollTo( 0, 0 );
}

function printerBCardWin(winURL) {
	winName = window.open( winURL, 'printerWin', 'width=400,height=350,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,personalbar=no,resizable=yes');
}

// Generally, it's safe to amalgamate all Dreamweaver code down here

function createObject( n, d ) {
	// Object creation code
	var p, i, x;
	if( !d ) {
		d = document;
	}
	if( ( p = n.indexOf( "?" ) ) > 0 && parent.frames.length ) {
		d = parent.frames[n.substring( p + 1 )].document;
		n = n.substring( 0, p );
	}
	if( !( x = d[n] ) && d.all ){
		x = d.all[n];
		for( i = 0; !x && i < d.forms.length; i++ ) {
			x = d.forms[i][n];
		}
		for( i = 0; !x && d.layers && i < d.layers.length; i++ ) {
			x = createObject( n, d.layers[i].document );
		}
	}
	return x;
}

function preloadImages() {
	var d = document;
	if( d.images ){
		if( !d.preloadArr ) {
			d.preloadArr = new Array();
			var i, j = d.preloadArr.length, a = preloadImages.arguments;
			for( i = 0; i < a.length; i++ ) {
				if ( a[i].indexOf( "#" ) != 0 ){
					d.preloadArr[j] = new Image; d.preloadArr[j++].src = a[i];
				}
			}
		}
	}
}

function swapImage() {
	var i, j = 0, x, a = swapImage.arguments;
	document.imageRestoreArr = new Array;
	for( i = 0; i < ( a.length - 2 ); i += 3 )
		if( ( x = createObject( a[i] ) ) != null ) {
			document.imageRestoreArr[j++] = x;
			if( !x.oSrc )
				x.oSrc = x.src;
				x.src = a[i + 2];
				}
}

function swapImageRestore() {
	var i, x, a = document.imageRestoreArr;
	for( i = 0; a && i < a.length && ( x = a[i] ) && x.oSrc; i++ ) {
		x.src = x.oSrc;
	}
}


// Function utiles au scroll
var t = "";
function scrollToTop(){
	var div = document.getElementById('scrollable_container');
	if (div.scrollTop>0)
	{
		div.scrollTop = div.scrollTop-2; 
		t = setTimeout('scrollToTop()', 10);
	}
	else clearTimeout(t);
}

function scrollToBottom(){
	var div = document.getElementById('scrollable_container');
	if (div.scrollTop >= 0)
	{
		div.scrollTop = div.scrollTop+2; 
		t = setTimeout('scrollToBottom()', 10);
	}
	else clearTimeout(t);
}
// retour en haut du div
function scrollToTop2() {
	var div = document.getElementById('scrollable_container');
	if (div.scrollTop>0)
	{
		div.scrollTop = div.scrollTop-2; 
		t = setTimeout('scrollToTop2()');
	}
	else clearTimeout(t);
}

function stopScroll(){
	clearTimeout(t);
}

function showVideo(file, elem) {
  var flashvars = {};
  flashvars.file = "/customers/video/" + file;
  var params = {};
  params.allowfullscreen = "true";
  var attributes = {};
  swfobject.embedSWF("/charte/www.evialis.fr/fre/prod/flash/player.swf", elem, "540", "350", "9", "/charte/www.evialis.fr/fre/prod/flash/expressInstall.swf", flashvars, params, attributes);
}

/* onLoad="preloadImages('images/navigation/home_over.gif')" */

/* onMouseOver="swapImage('aboutus','','image_over.file',1)" onfocus="swapImage('aboutus','','image_over.file',1)" onMouseOut="swapImageRestore()" onblur="swapImageRestore()" */