var ns, ie;
var Vmajor = parseInt(navigator.appVersion);
if(navigator.appName == "Netscape") { ns = true; ie = false; }
else if(navigator.appName == "Microsoft Internet Explorer") { ie = true; ns = false; }
else { ns = false; ie = false; }

function fenetre(theURL,Targ,Opts) {
	fen = window.open(theURL, Targ, Opts);
	if (!fen.opener) fen.opener = self;
}

function checkKey(){
	if(ns) val = event.which;
	else val = event.keyCode;
	if(window.event.shiftKey) event.returnValue=true;
	if( val == 8 || val == 9 || val == 39 ) return;
	if( val == 38 || val == 40 || val == 190 || val == 110 || val == 46){
		event.returnValue=false;
		return ;
	}
	document.selection.clear() ;
	if( val < 48 || val > 57 ){
		event.returnValue=false;
		return ;
	}

	num = parseInt( window.event.srcElement.value + (window.event.keyCode-48) , 10 ) ;
	
	if( num > 9999 ){
		event.returnValue=false;
	}else if( window.event.srcElement.value.length>0 && num < 10){
		//window.event.srcElement.value = num ;
		window.event.srcElement.value += (window.event.keyCode-48); 
		event.returnValue=false;
	}
	return ;
}

function checkLength(){
	if(ns) val = event.which;
	else val = event.keyCode;
	if( val == 9 || val == 37 || val== 39 ) return;

	// pour sauter au champ suivant (48 a 57 pour les chiffres) 
	if( ( val >= 48 && val <= 57 ) || ( val >=96 && val <= 105) || val==190 || val ==40 || val==110 || val==38 || val==109){
		event.returnValue=true;
	}else{
		event.returnValue=false;
		return ;		
	}		
	if( val == 190 || val == 40 || val == 110 || val == 109){
		nextInput( parseInt( window.event.srcElement.order ) ) ;
	}
	else if( val == 38 ){
		prevInput( parseInt( window.event.srcElement.order ) ) ;
	}		
	else if( window.event.srcElement.value.length == 4 ){
		nextInput( parseInt( window.event.srcElement.order ) ) ;
	}

}
function nextInput(index){
	if( index < 2 ){
		window.event.srcElement.parentElement.children.item(index+1).focus() ;
		window.event.srcElement.parentElement.children.item(index+1).select() ;
	}
}
function prevInput(index){
	if( index > 0 ){
		window.event.srcElement.parentElement.children.item(index-1).focus() ;
		window.event.srcElement.parentElement.children.item(index-1).select() ;
	}
}
function ctrl_saisie()
{
var ctrl = document.saisie;
if( ctrl.fcivil.checked )
	{
	alert("Saisissez la civilité, svp.");
	return false;
	}
if( ctrl.fnom1.value == "" )
	{
	alert("Saisissez le nom, svp.");
	ctrl.fnom1.focus();
	return false;
	}
if( ctrl.fnom2.value == "" )
	{
	alert("Saisissez le prénom, svp.");
	ctrl.fnom2.focus();
	return false;
	}
if( ctrl.j_anniv.value < 1 )
	{
	alert("Saisissez le jour de naissance, svp.");
	ctrl.j_anniv.focus();
	return false;
	}
if( ctrl.m_anniv.value < 1 )
	{
	alert("Saisissez le mois de naissance, svp.");
	ctrl.m_anniv.focus();
	return false;
	}
if( ctrl.a_anniv.value < 1 )
	{
	alert("Saisissez l'année de naissance, svp.");
	ctrl.a_anniv.focus();
	return false;
	}
if( ctrl.fadr1.value == "" )
	{
	alert("Saisissez l'adresse, svp.");
	ctrl.fadr1.focus();
	return false;
	}
if( ctrl.fcp.value == "" )
	{
	alert("Saisissez le code postal au format numérique, svp.");
	ctrl.fcp.focus();
	return false;
	}
if( ctrl.fville.value == "" )
	{
	alert("Saisissez la ville, svp.");
	ctrl.fville.focus();
	return false;
	}
if( ctrl.fpays.value < 1 )
	{
	alert("Saisissez le pays, svp.");
	ctrl.fpays.focus();
	return false;
	}
if( ctrl.ftel.value == "" && ctrl.fmob.value == "" )
	{
	alert("Saissez un téléphone, svp.");
	ctrl.ftel.focus();
	return false;
	}
if( ctrl.ftel.value<0100000000 && ctrl.fmob.value<0100000000 )
	{
	alert("Le numéro de téléphone est incomplet.");
	ctrl.ftel.focus();
	return false;
	}
if( ctrl.femail1.value == "" )
	{
	alert("Saisissez une adresse email, svp.");
	ctrl.femail1.focus();
	return false;
	}
return true;
}
// ******************** Fonctions AJAX ***************************
function getHObjet() {
        var xmlhttp = false;
 
        /* Compilation conditionnelle d'IE */
        /*@cc_on
        @if (@_jscript_version >= 5)
                try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
                catch (e) {
                        try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
                        catch (E) { xmlhttp = false; }
                }
        @else
                xmlhttp = false;
        @end @*/
 
        /* on essaie de creer l'objet si ce n'est pas deja fait */
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                try { xmlhttp = new XMLHttpRequest();xmlhttp.overrideMimeType('text/xml'); }
                catch (e) { xmlhttp = false; }
        }
 
        return xmlhttp;
}
function getHObjetById(id,url) {
        var xmlhttp = getHObjet();
        if (xmlhttp) {
                /* on definit ce qui doit se passer quand la page repondra */
                xmlhttp.onreadystatechange=function() {
                        if (xmlhttp.readyState == 4) {  /* Donnees charges */
                                if (xmlhttp.status == 200) {    /* 200 : code HTTP pour OK */
                                        var obj = document.getElementById(id);
                                        if (obj) { obj.innerHTML = xmlhttp.responseText; }
                                }
                        }
                }
        }
        xmlhttp.open("GET", url,true);
        xmlhttp.send(null);
}

