// Cette fonction permet de retourner l'objet en fonction du navigateur
function findObject(n, d)
{
	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=return_object(n,d.layers[i].document);
	if(!x && document.getElementById)
		x=document.getElementById(n);
	return x;
}

function setFocus(componentID)
{
	findObject(componentID).focus();
}

function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

// afficher ou masquer un bloc alternativement
function showHide(divId)
{
	if(findObject(divId).className == "masquer")
		findObject(divId).className = "afficher";
	else
		findObject(divId).className = "masquer";
}

function vide(champ)
{
	if(champ.length == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

//radio
function getRadioVal(rbname)
{
	var rb = document.getElementsByName(rbname);
	var L=rb.length;var ret="";
	var L=rb.length;var ret="";
	for (var i = 0 ; i< L ; i++)
	{
		if(rb[i].checked)
		{
			ret=rb[i].value;break;
		}
	}
	return(ret);
}

// verifier si un numero de fixe est valide
function validerPhone(telephone)
{
  var regEx = /^0[1-5][0-9]{8}$/;
  return (regEx.test(telephone))
}

// verifier si un numero de telephone est valide
function validerPhoneContact(telephone)
{
  var regEx = /^0[1-68][0-9]{8}$/;
  return (regEx.test(telephone))
}

// verifier si un code postal est correct
function validerCodePostal(codepostal)
{
  var regEx = /^[0-9][0-9]{4}$/;
  return (regEx.test(codepostal))
}

// verifier si un email est valide
function validerEmail(email)
{
  var regEx = /^[-_\.A-Za-z0-9]*@[-_\.A-Za-z0-9]*\.((net)|(com)|(org)|(fr)|(be)|(nc)|(it)|(de)|(uk)|(es)|(nl)|(us))$/;
  return (regEx.test(email))
}


// verifier si un RIB est valide
function validerRIB()
{
  if (validerRIB.arguments.length==4)
  {
    var banque = validerRIB.arguments[0];
    var guichet = validerRIB.arguments[1];
    var compte = validerRIB.arguments[2].toUpperCase();

    // Conversion du numero de compte en chiffres
    var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    var tab1 = "123456789123456789234567890123456789".split("");

    while (compte.match(/\D/) != null)
      compte = compte.replace(/\D/, tab1[tab.indexOf(compte.match(/\D/))]);
    var cp = parseInt  (compte, 10);

    //Calcul cle RIB
    a = banque%97;
    a = a*100000+parseInt(guichet, 10);
    a = a%97;
    a = a*Math.pow(10, 11) + cp;
    a = a%97
    a = a*100;
    a = a%97
    a = 97-a;
    return validerRIB.arguments[3] == a;
  }
  return false;
}

// naviguer dans l'historique des etapes
function navigation(param)
{
  window.history.go(param);
}

