// ===========================================================
// script: Gerard Ferrandez - Ge-1-doot - October 2005
// http://www.dhteumeuleu.com
// ===========================================================
//
window.onerror = new Function("return true");
var obj = [];
var scr;
var spa;
var img;
var W;
var Wi;
var Hi;
var wi;
var hi;
var Sx;
var Sy;
var M;
var xm;
var ym;
var xb = 0;
var yb = 0;
var ob =  - 1;
var cl = false;

/* needed in standard mode */
px = function(x)
{
	return Math.round(x) + "px";
}

/* center image  - do not resize for perf. reason */
img_center = function(o)
{
	with(img[o])
	{
		style.left = px( - (width - Wi) / 2);
		style.top = px( - (height - Hi) / 2);
	}
}

//////////////////////////////////////////////////////////
var Nx = 3; //size grid x
var Ny = 3; //size grid y
var Tx = 3; // image width
var Ty = 3; // image height
var Mg = 60; // margin
var SP = 1; // speed
//////////////////////////////////////////////////////////

function Cobj(o, x, y)
{
	this.o = o;
	this.ix = Math.min(Nx - Tx, Math.max(0, Math.round(x - (Tx / 2))));
	this.iy = Math.min(Ny - Ty, Math.max(0, Math.round(y - (Ty / 2))));
	this.li = ((this.ix * M + this.ix * Sx) - (x * M + x * Sx)) / SP;
	this.ti = ((this.iy * M + this.iy * Sy) - (y * M + y * Sy)) / SP;
	this.l = 0;
	this.t = 0;
	this.w = 0;
	this.h = 0;
	this.s = 0;
	this.mv = false;
	this.spa = spa[o].style;
	this.img = img[o];
	this.txt = img[o].alt;
	img[o].alt = "";

	/* zooming loop */
	this.zoom = function()
	{
		with(this)
		{
			l += li * s;
			t += ti * s;
			w += wi * s;
			h += hi * s;
			if ((s > 0 && w < Wi) || (s < 0 && w > Sx))
			{
				/* force window.event */
				window.focus();
				/* loop */
				setTimeout("obj[" + o + "].zoom()", 16);
			}
			else
			{
				/* finished */
				mv = false;
				/* set final position */
				if (s > 0)
				{
					l = ix * M + ix * Sx;
					t = iy * M + iy * Sy;
					w = Wi;
					h = Hi;
				}
				else
				{
					l = x * M + x * Sx;
					t = y * M + y * Sy;
					w = Sx;
					h = Sy;
				}
			}
			/* html animation */
			with(spa)
			{
				left = px(l);
				top = px(t);
				width = px(w);
				height = px(h);
				zIndex = Math.round(w);
			}
		}
	}

	this.click = function()
	{
		with(this)
		{
			img_center(o);
			/* zooming logic */
			if ( ! mv || cl)
			{
				if (s > 0)
				{
					if (cl || Math.abs(xm - xb) > Sx * .4 || Math.abs(ym - yb) > Sy * .4)
					{
						s =  - 2;
						mv = true;
						zoom();
						cap.innerHTML = txt;
					}
				}
				else
				{
					if (cl || ob != o)
					{
						if (ob >= 0)
						{
							with(obj[ob])
							{
								s =  - 2;
								mv = true;
								zoom();
							}
						}
						ob = o;
						s = 1;
						xb = xm;
						yb = ym;
						mv = true;
						zoom();
						cap.innerHTML = txt;
					}
				}
			}
		}
	}

	/* hook up events */
	//img[o].onmouseover = img[o].onmousemove = img[o].onmouseout = new Function("cl=false;obj[" + o + "].click()");
	//img[o].onclick = new Function("cl=true;obj[" + o + "].click()");
	img[o].onclick = new Function("cl=true;obj[" + o + "].click()");
	img[o].onload = new Function("img_center(" + o + ")");

	/* initial display */
	this.zoom();
}

/* mouse */
document.onmousemove = function(e)
{
	if ( ! e)
	{
		e = window.event;
	}
	xm = (e.x || e.clientX);
	ym = (e.y || e.clientY);
}

/* init */
function load()
{
	/* html elements */
	scr = document.getElementById("screen");
	spa = scr.getElementsByTagName("span");
	img = scr.getElementsByTagName("img");
	cap = document.getElementById("caption");

	/* mouseover border */
	document.getElementById("border").onmouseover = function()
	{
		cl = true;
		if(ob >= 0 && obj[ob].s > 0) obj[ob].click();
		ob = -1;
	}

	/* global variables */
	W = parseInt(scr.style.width);
	H = parseInt(scr.style.height);
	M = W / Mg;
	Sx = (W - (Nx - 1) * M) / Nx;
	Sy = (H - (Ny - 1) * M) / Ny;
	Wi = Tx * Sx + (Tx - 1) * M;
	Hi = Ty * Sy + (Ty - 1) * M;
	SP = M * Tx * SP;
	wi = (Wi - Sx) / SP;
	hi = (Hi - Sy) / SP;

	/* create objects */
	for (k = 0, i = 0; i < Nx; i ++)
	{
		for (j = 0; j < Ny; j ++)
		{
			obj[k] = new Cobj(k ++, i, j);
		}
	}
}





/* ------------------ Traitement des formulaires -------------------------------- */

/* ------------------------ Contact --------------------------------------------- */

function nettoyageContact(){
document.forms["formcontact"].elements["prenom"].focus();
document.forms["formcontact"].reset();
}


function actionEnvoyerContact() {
	var aa = document.formcontact.nom.value.indexOf("@");
	var ab = document.formcontact.adresse.value.indexOf("@");
	var ac = document.formcontact.ville.value.indexOf("@");
	var ad = document.formcontact.texte.value.indexOf("@");
	var ua = document.formcontact.nom.value.indexOf("http");
	var ub = document.formcontact.adresse.value.indexOf("http");
	var uc = document.formcontact.ville.value.indexOf("http");
	var ud = document.formcontact.texte.value.indexOf("http");
	
		
	if (document.formcontact.nom.value == "") {
    alert("Merci de saisir votre nom - Thanks to write your name");
    document.formcontact.nom.focus();
	return false;
	}
		if (aa != -1 || ua != -1) {
		alert ("Adresse email ou URL interdite dans le champ Nom - Email or URL address forbidden in the field Name");
		document.formcontact.nom.value = "";
		document.formcontact.nom.focus();
		return false;
		}

	if (document.formcontact.adresse.value == "") {
    alert("Merci de saisir votre adresse - Thanks to write your adress");
    document.formcontact.adresse.focus();
	return false;
	}
		if (ab != -1 || ub != -1) {
		alert ("Adresse email ou URL interdite dans le champ Adresse - Email or URL address forbidden in the field Adress");
		document.formcontact.adresse.value = "";
		document.formcontact.adresse.focus();
		return false;
		}
	
	if (document.formcontact.cp.value == "") {
    alert("Merci de saisir votre code postal - Thanks to write your postal code");
    document.formcontact.cp.focus();
	return false;
	}
	
		if(isNaN(document.formcontact.cp.value) == true) {
    	alert ("Code Postal incorrect - Incorrect postal code");
    	document.formcontact.cp.value = "";
    	document.formcontact.cp.focus(); 
    	return false;
    	}
	
	if (document.formcontact.ville.value == "") {
    alert("Merci de saisir votre ville - Thanks to write your city");
    document.formcontact.ville.focus();
	return false;
	}
		if (ac != -1 || uc != -1) {
		alert ("Adresse email ou URL interdite dans le champ Ville - Email or URL address forbidden in the field City");
		document.formcontact.ville.value = "";
		document.formcontact.ville.focus();
		return false;
		}
	
	if (document.formcontact.tel1.value == "") {
    alert("Merci de saisir un téléphone dans le champs Tél.1 - Thanks to write your main phone number");
    document.formcontact.tel1.focus();
	return false;
	}
		if(isNaN(document.formcontact.tel1.value) == true) {
    	alert ("Numéro de téléphone incorrect - Incorrect phone number");
    	document.formcontact.tel1.value = "";
    	document.formcontact.tel1.focus(); 
    	return false;
    	}
	
	if(isNaN(document.formcontact.nb_personne.value) == true) {
    alert ("Le nombre de personne doit être un nombre - The number of people must be a number");
    document.formcontact.nb_personne.value = "";
    document.formcontact.nb_personne.focus(); 
    return false;
    }
	
	
	if (ad != -1 || ud != -1) {
	alert ("Adresse email ou URL interdite dans le champ Votre texte - Email or URL address forbidden in the field Your message");
	document.formcontact.texte.value = "";
	document.formcontact.texte.focus();
	return false;
	}
		
else {
return true }
}  



/* ------------------------ Sondage --------------------------------------------- */

function nettoyageSondage(){
document.forms["formsondage"].elements["prenom"].focus();
document.forms["formsondage"].reset();
}



function actionEnvoyerSondage() {
   if (document.formsondage.nom.value == "") {
    alert("Merci de saisir votre nom");
    document.formsondage.nom.focus();
	return false;
	}
	
	else {
	return true }
}  

/* ------------------------ Admin --------------------------------------------- */


function nettoyageAdmin(){
document.forms["formlogin"].elements["identifiant"].focus();
document.forms["formlogin"].reset();
}

function actionEnvoyerAdmin() {
   if (document.formlogin.identifiant.value == "") {
    alert("Merci de saisir votre identifiant");
    document.formlogin.identifiant.focus();
	return false;
	}
	if (document.formlogin.motdepasse.value == "") {
    alert("Merci de saisir votre mot de passe");
    document.formlogin.motdepasse.focus();
	return false;
	}
	
	else {
	return true }
}  

/*------------------ Traitement des DIV --------------------*/


function showdiv(D) {
  if (document.all) {  document.all[D].style.display="block";  }
  else if (document.getElementById) {  document.getElementById(D).style.display="block";  }
}
  
function hiddediv(D) {
  if (document.all) { document.all[D].style.display="none"; window.location.reload();}
  else if  (document.getElementById) { document.getElementById(D).style.display="none"; window.location.reload();}
}



/*------------------ Traitement des images Aux Alentours --------------------*/



function detectimg(ID) {
	largeur = document.images[ID].offsetWidth;
	hauteur = document.images[ID].offsetHeight;
	/*alert ("largeur =" + largeur + " hauteur = " + hauteur);*/

	if (largeur < 222) {
		document.getElementById(ID).className="boiteinfoP";
		/*alert ("< 222");*/
	}
		else {
			document.getElementById(ID).className="boiteinfoL";
			/*alert ("> 222");*/
		}
}

// ===========================================================
// Les rares bidules rajoutés automatiquement par
// Dreamweaver
// ===========================================================
//


function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

