//<![CDATA[

var posXsouris = 0;
var posYsouris = 0;

var REF_INCLUDE = "../";
function position(e) {
         posXsouris = (navigator.appName.substring(0,3) == "Net") ? e.pageX : window.event.clientX+document.body.scrollLeft;
         posYsouris = (navigator.appName.substring(0,3) == "Net") ? e.pageY : window.event.clientY+document.body.scrollTop;
         //window.status = "Souris x:"+posXsouris+" | y:"+posYsouris;
}

if (navigator.appName.substring(0,3) == "Net") document.captureEvents(Event.MOUSEMOVE);
   document.onmousemove = position;

function remoteScripting(fichier)
 {
	 if(window.XMLHttpRequest) // FIREFOX
		  xhr_object = new XMLHttpRequest(); 
	 else if(window.ActiveXObject) // IE
		  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	 else 
		  return(false); 
	 xhr_object.open("GET", fichier, false); 
	 xhr_object.send(null); 
	 if(xhr_object.readyState == 4) return(xhr_object.responseText);
	 else return(false);
 }
   
   
/*
function trim(myStr)
{ 
	var isFirst = true; 
	var fIndex = 0; 
	var lIndex = 0; 
	if (myStr.length != 0) 
	{ 
		for ( var i = 0; i < myStr.length ; i ++ ) 
		{ 
			var ch = myStr.charAt( i ); 
			if ( isFirst ) 
			{ 
				if ( ch == ' ' || ch == '\t' ) 
				{ 
					fIndex = i + 1; 
					lIndex = i + 1; 
				} 
				else 
				{ 
					isFirst = false; 
				} 
			}
			else
			{ 
				if ( ch != ' ' && ch != '\t' ) 
				{ 
					lIndex = i; 
				} 
			} 
		} 
		myStr = myStr.substring( fIndex, lIndex+1 ); 
		return(myStr); 
	} 
	else 
		return(""); 
}
*/

function trim(strVal) { return strVal.replace(/^\s+|\s+$/g, ''); }

function isset(element)
{
	/*
	Fonction permettant de tester si la variable élément est initialisée 
	et différente de la valeur null ou de la chaine vide
	*/
	var eltTest;
	if (element != "" && element != undefined && element != "undefined" && element != eltTest && element != null && element != "null" && element != "NULL")
		return(true);
	else
		return(false);
}



function ouvrirFenetre(script, largeur, hauteur, scrolling, nomFenetre)
{
	var param='top=0,left=0,location=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,';
	param+='width='+largeur+',height='+hauteur;
	if (!isset(nomFenetre))
		nomFenetre = '';
	window.open(script,nomFenetre, param);
}

function chargerDansIframe(nomIframe,script, Inparent)
{
	var elt,eltRef;
	if (Inparent)
		elt = parent.document.getElementById(nomIframe);
	else
		elt = document.getElementById(nomIframe);
	
	if (isset(elt))
		elt.src = script;
	else
		return(false);
}

function charger(source)
{
	document.location = source;
}


function chargerIframe(div, nomIframe, script, width, height, scrolling)
{
	if (isset(document.getElementById(div)))
		document.getElementById(div).innerHTML = '';
}

function chargerIframeBis(idDiv, script, nomIframe, parent, scrolling)
{
        if (!isset(nomIframe))
           nomIframe = "iframe"+idDiv;
        if (parent)
           div = parent.document.getElementById(idDiv);
        else
            div = document.getElementById(idDiv);
        if (isset(div))
           div.innerHTML = '';
}

function chargerIframeParent(div, nomIframe, script)
{
	if (isset(div))
		parent.document.getElementById(div).innerHTML = '';
}





function insererTag(idSelect, idText)
{
	if (document.getElementById(idSelect) && document.getElementById(idText))
	{
		$eltSel = document.getElementById(idSelect);
		$eltTexte = document.getElementById(idText);
		if ($eltTexte.createTextRange && $eltTexte.caretPos) 
		{ 
			var caretPos = $eltTexte.caretPos; 
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? $eltSel.value + ' ' : $eltSel.value;
		}
		else
			$eltTexte.value += ' ' + $eltSel.value + ' ';
	}
}


function storeCaret (textEl) 
{ 
	if (textEl.createTextRange) 
		textEl.caretPos = document.selection.createRange().duplicate(); 
}

function selectionnerOptions(select)
{
	var mySelect = document.getElementById(select);
	if (isset(mySelect))
	{
		for($ind = 0; $ind <mySelect.options.length;$ind++)
			mySelect[$ind].selected = true;
	}
}


function genereListe(_liste, _tabTexte, _tabValue, _tabStyle, _tailleTab) 
{
	for (var i=0; i<_tailleTab; i++)
	{
    	_liste.options[i]=new Option(_tabTexte[i], _tabValue[i]);
		_liste.options[i].style.background = _tabStyle[i].background;
	}
}

function bubbleSort(_tabText, _tabValue, _tabStyle, _tailleTab) 
{
	var i,s;

	do 
	{
		s=0;
		for (i=1; i<_tailleTab; i++)
			if (_tabText[i-1] > _tabText[i]) 
			{
				y = _tabText[i-1];
				_tabText[i-1] = _tabText[i];
				_tabText[i] = y;
				y = _tabValue[i-1];
				_tabValue[i-1] = _tabValue[i];
				_tabValue[i] = y;
				y = _tabStyle[i-1];
				_tabStyle[i-1] = _tabStyle[i];
				_tabStyle[i] = y;
				s = 1;
			}
	}while (s);
}
    
function videListe(_liste)
{

	var cpt = _liste.options.length;

	for(var i=0; i<cpt; i++) 
		_liste.options[0] = null;
}

function selectUtil(lSource, lDest)
{
	var _listeSource = document.getElementById(lSource);
	var _listeDest = document.getElementById(lDest);
	var i,j;
	var ok = false;
	var tabDestStyle = new Array();
	var tabDestTexte = new Array();
	var tabDestValue = new Array();
	var tailleTabDest = 0;

	for (i=0; i<_listeDest.options.length; i++) 
	{
		tabDestStyle[tailleTabDest]   = _listeDest.options[i].style;
		tabDestTexte[tailleTabDest]   = _listeDest.options[i].text;
		tabDestValue[tailleTabDest++] = _listeDest.options[i].value;
	}

	for (j=_listeSource.options.length-1; j>=0; j--) 
	{
		if (_listeSource.options[j].selected) 
		{
			ok = true;
			tabDestStyle[tailleTabDest]   = _listeSource.options[j].style;
			tabDestTexte[tailleTabDest]   = _listeSource.options[j].text;
			tabDestValue[tailleTabDest++] = _listeSource.options[j].value;
			_listeSource.options[j] = null;
		}
	}

	if (ok) 
	{
		//Trie du tableau
		bubbleSort(tabDestTexte, tabDestValue, tabDestStyle, tailleTabDest);
		//Vide la liste destination
		videListe(_listeDest);
		//Recrée la liste
		genereListe(_listeDest, tabDestTexte, tabDestValue, tabDestStyle, tailleTabDest);
		}
	}
 
function synchroIndex(select1, select2, sens)
{
	var selectOuv = document.getElementById(select1);
	var selectFerm = document.getElementById(select2);
	if (selectFerm.selectedIndex < selectOuv.selectedIndex)
	{
		if (sens == 1)
			selectFerm.selectedIndex = selectOuv.selectedIndex;
		else
			selectOuv.selectedIndex = selectFerm.selectedIndex;
	}
}

function is_numeric(num)
{
	var exp = new RegExp("^[0-9]*$","g");
	return exp.test(num);
}

function changeLien(idElt, nvLien, typeLien)
{
 var theElt = document.getElementById(idElt);
 if (isset(theElt))
 {
    if (typeLien == "image") theElt.src= nvLien;
    else if (typeLien == "texte") theElt.className = nvLien;

 }
}


function voir_masquer(element)
{
}


function voirElt(element)
{
	if (document.getElementById(element))
		document.getElementById(element).style.display = 'block';
}

function masquerElt(element)
{
	if (document.getElementById(element))
		document.getElementById(element).style.display = 'none';
}

var _IMG_PSG_COURANTE = "";
var _IMG_DIV_COURANTE = "";
function masquerImagePassageSouris(idDiv)
{
	masquerElt(idDiv);
	_IMG_PSG_COURANTE = "";
}

function affichageImagePassageSouris(idDiv, image)
{
	if(image == "") image = _IMG_DIV_COURANTE;
	var theDiv = document.getElementById(idDiv);
	theDiv.innerHTML="<img src='"+image+"' style='border:1px solid red'>";
	var offsetX = 640;
	var offsetY = 480;
	var availWidth = screen.width; 
	var availHeight = screen.height; 
	theDiv.style.overflow = 'visible';
	theDiv.style.top = (availHeight-offsetY)/2;
	theDiv.style.left = (availWidth-offsetX)/2;
	voirElt(idDiv);
	_IMG_PSG_COURANTE = idDiv;
	_IMG_DIV_COURANTE = image;

}

function setClass(Objet, classe)
{
	Objet.className = classe;
}

function verifierEmail(mailteste)
{
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	if(reg.test(mailteste))	return(true);
	else return(false);
}

function viderElement(theElt, chaineTest)
{
	theElt.value = trim(theElt.value);
	if(theElt.value == chaineTest) theElt.value = "";
}

function verifierTelephone(telTeste)
{
	exp=new RegExp("^0[0123456][0-9]{8}$","gi");
	if ((!exp.test(telTeste))||(telTeste.length==0)) return false;
	else return true;
}

function RemplaceChaine(str,find,rep){
  var reg = new RegExp(find,"gi")
  return(str.replace(reg,rep));
}

function verifFormSendGrossesse(theForm)
{
	theForm['EMAIL_CONTACT1'].value = trim(theForm['EMAIL_CONTACT1'].value);
	theForm['EMAIL_CONTACT2'].value = trim(theForm['EMAIL_CONTACT2'].value);
	theForm['EMAIL_CONTACT3'].value = trim(theForm['EMAIL_CONTACT3'].value);
	theForm['EMAIL_CONTACT4'].value = trim(theForm['EMAIL_CONTACT4'].value);
	theForm['EMAIL_CONTACT5'].value = trim(theForm['EMAIL_CONTACT5'].value);
	theForm['EMAIL_CONTACT6'].value = trim(theForm['EMAIL_CONTACT6'].value);
	
	if(!verifierEmail(theForm['EMAIL_CONTACT1'].value) && !verifierEmail(theForm['EMAIL_CONTACT2'].value) && !verifierEmail(theForm['EMAIL_CONTACT3'].value) && !verifierEmail(theForm['EMAIL_CONTACT4'].value) && !verifierEmail(theForm['EMAIL_CONTACT5'].value) && !verifierEmail(theForm['EMAIL_CONTACT6'].value))
	{
		document.getElementById('divMessageInfo').innerHTML = "Merci de renseigner au moins une adresse email"; 
		var offsetX = 600;
		var offsetY = 0;
		var availWidth = screen.width; 
		var availHeight = screen.height; 
		document.getElementById('divContainerMessageInfo').style.top = "300px";//((availHeight-offsetY)/2)+"px";
		document.getElementById('divContainerMessageInfo').style.left = ((availWidth-offsetX)/2)+"px";
		voirElt('divContainerMessageInfo');
		return(false);
	}
	else return(true);
}

function verifFormContact(theForm)
{
	//On nettoie un peu tous les champs :
	theForm['NOM'].value = trim(theForm['NOM'].value);
	theForm['PRENOM'].value = trim(theForm['PRENOM'].value);
	theForm['EMAIL'].value = trim(theForm['EMAIL'].value);
	theForm['TEL'].value = trim(theForm['TEL'].value);
	theForm['TEL'].value = RemplaceChaine(theForm['TEL'].value," ","");
	theForm['TEL'].value = RemplaceChaine(theForm['TEL'].value,"\\.","");
	theForm['TEL'].value = RemplaceChaine(theForm['TEL'].value,"-","");
	theForm['TEL'].value = RemplaceChaine(theForm['TEL'].value,"/","");

	theForm['MESSAGE'].value = trim(theForm['MESSAGE'].value);
	
	var bFormOk = true;
	var listeErreurs = "";
	if(theForm['NOM'].value.length == 0) {bFormOk = false;if(theForm['NOM'].className.indexOf("Warning")<0)theForm['NOM'].className=theForm['NOM'].className+"Warning";listeErreurs += " Surname ";}
	if(theForm['PRENOM'].value.length == 0) {bFormOk = false;if(theForm['PRENOM'].className.indexOf("Warning")<0)theForm['PRENOM'].className=theForm['PRENOM'].className+"Warning";listeErreurs += " First name ";}
	if(theForm['MESSAGE'].value.length == 0) {bFormOk = false;if(theForm['MESSAGE'].className.indexOf("Warning")<0)theForm['MESSAGE'].className=theForm['MESSAGE'].className+"Warning";listeErreurs += " Message ";}
	if(!verifierEmail(theForm['EMAIL'].value)) {bFormOk = false;if(theForm['EMAIL'].className.indexOf("Warning")<0)theForm['EMAIL'].className=theForm['EMAIL'].className+"Warning";listeErreurs += " Email ";}
	if(!verifierTelephone(theForm['TEL'].value)) {bFormOk = false;if(theForm['TEL'].className.indexOf("Warning")<0)theForm['TEL'].className=theForm['TEL'].className+"Warning";listeErreurs += " Telephone ";}
	
	
	if(!bFormOk)
	{
		document.getElementById('divMessageInfo').innerHTML = "Please check your application form :<br />"+listeErreurs; 
		var offsetX = 600;
		var offsetY = 0;
		var availWidth = screen.width; 
		var availHeight = screen.height; 
		document.getElementById('divContainerMessageInfo').style.top = "100px";//((availHeight-offsetY)/2)+"px";
		document.getElementById('divContainerMessageInfo').style.left = "400px";
		voirElt('divContainerMessageInfo');
		return false;
	}
	else return true;

}











//]]>


