var cheminSite = 'https://www.crt.asso.fr/votre-compte/';
var cheminConnexion = cheminSite + "vous-connecter/index.html";
var cheminDemandeActivation = cheminSite + "activer-votre-compte/index.html";
var cheminRecupMdp = cheminSite + "retrouver-votre-mot-de-passe/index.html";
var cheminDossier = cheminSite + "votre-dossier/index.html";
var cheminModification = cheminSite + "modifier-votre-dossier/index.html";
var cheminPremiereConnexion = cheminSite + "votre-premiere-connexion/index.html";
var cheminCommandes = cheminSite + "vos-commandes/index.html";
var cheminSouscriptionColisur = cheminSite + "souscrire-colisur/index.html";
var cheminModificationColisur = cheminSite + "changer-formule-colisur/index.html";
var cheminColisur = cheminSite + "colisur/index.html";
var cheminRemises = cheminSite + "vos-remises/index.html";
var cheminListeAffilies = cheminSite + "vos-affilies-rattaches/index.html";
var cheminReglement = cheminSite + "vos-reglements/index.html";
var cheminVerifTitre = cheminSite + "verifier-validite-titre/index.html";
var cheminRechercheTitreVoles = cheminSite + "rechercher-titres-voles/index.html";
var cheminListeAffiliesSuivis = cheminSite + "vos-affilies-suivis/index.html";
var cheminSuiviQualite = cheminSite + "votre-suivi-qualite/index.html";
var cheminDeconnexion = cheminSite + "deconnexion/index.html";
var cheminStatut ="https://www.crt.asso.fr/votreCompte/jsp/statut.jsp";
var cheminCGU ="http://www.crt.asso.fr/rubriques-transverses/cgu/index.html";


function returnObjById(id)
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function controleTel(idChamp) {
var champAControler = returnObjById(idChamp);
var numTel = champAControler.value;
if(numTel.length > 0) {
	var re = /^([0-9]{10})$/;
	if(!re.test(numTel)) {
 		alert("Numéro de téléphone invalide");
		champAControler.focus();
		return false;
		}
	}
}

function controleSaisieNum(e) {
e = e || window.event;
var codeTouche;
if(document.all) {
	codeTouche = e.keyCode;
}
else {
	codeTouche = e.which;
}

if( codeTouche < 31 )  {
            return true; // netscape
	}
if( codeTouche < 48 || codeTouche > 57) {
            e.returnValue = false; // IE
            e.preventDefault(); // dom 2 (also tried without this here)
            return false; // netscape
	}
}

function controleSaisieTel(e) {
controleSaisieNum(e);
}

function controleSaisieNom(e) {
e = e || window.event;
var codeTouche;
if(document.all) {
	codeTouche = e.keyCode;
}
else {
	codeTouche = e.which;
}
if( codeTouche < 31 )  {
            return true; // netscape
	}
if( (codeTouche >= 48 && codeTouche <= 57) 
|| (codeTouche >= 65 && codeTouche <= 96) 
|| codeTouche == 32 
|| codeTouche == 45 
|| codeTouche == 46 )
{
// do nothing
}
else {
            if( codeTouche >= 97 && codeTouche <= 122 ){
                        //var char = String.fromCharCode(codeTouche);
                        //char = char.toUpperCase();
                        //var champOrigine = e.target || e.srcElement ;
                        //champOrigine.value = champOrigine.value + char ;
                        codeTouche = String.fromCharCode(codeTouche).toUpperCase().charCodeAt(0);   
                        if(document.all) {
				e.keyCode = codeTouche;
				}
			else {
				e.which = codeTouche;
}
                        }
                else{
            e.returnValue = false; // IE
            e.preventDefault(); // dom 2 (also tried without this here)
            return false; // netscape
       		}
            }
}

function controleSaisieDecimal(e,objet) 
{
	//blop(e);
	e = e || window.event;
	flagIE = false;
	if(document.all) {
		flagIE = true;
		if(e.keyCode < 31) 
			return true;
	}
	else {
		if(e.which < 31 || e.ctrlKey)
			return true;
	}
	var reType = /[0-9\.,]/ 
	var rePoint = /\./
	var lettreEntree = flagIE ? String.fromCharCode(e.keyCode) : String.fromCharCode(e.which);
	if(!reType.test(lettreEntree)) {
		e.returnValue = false; // IE
		 if (e.preventDefault)          
			e.preventDefault();
		return false; // netscape
	}
	else if(rePoint.test(lettreEntree)) {
		if(flagIE) {
			window.event.keyCode = ",".charCodeAt(0);
		}
		else {
		     if (e.preventDefault)          
	         	e.preventDefault();
			 var oldSelectionStart = objet.selectionStart;
			 var oldSelectionEnd = objet.selectionEnd;
			 var selectedText = objet.value.substring(oldSelectionStart, oldSelectionEnd);
			 var newText =  ',';  
			 objet.value = objet.value.substring(0, oldSelectionStart) + newText +
				objet.value.substring(oldSelectionEnd);
			 objet.setSelectionRange(oldSelectionStart + newText.length, oldSelectionStart + newText.length);
			 return false;
		}
	}
}

function reloadStatut() {
//parent.frames["statut"].location.href = parent.frames["statut"].location.href;
parent.frames["statut"].location.href = cheminStatut;
}

function loadParent(page) {
if(page=="DEMANDE_ACTIVATION") {
	if(parent.location.href != cheminDemandeActivation) {
		parent.location.href = cheminDemandeActivation;
		}
	}
else if(page=="RECUP_MDP") {
	if(parent.location.href != cheminRecupMdp) {
		parent.location.href = cheminRecupMdp;
		}
	}
else if(page=="DOSSIER") {
	if(parent.location.href != cheminDossier) {
		parent.location.href = cheminDossier;
		}
	}
else if(page=="ACTIVATION") {
	if(parent.location.href != cheminPremiereConnexion) {
		parent.location.href = cheminPremiereConnexion;
		}
	}
else if(page=="MODIFICATION") {
	if(parent.location.href != cheminModification) {
		parent.location.href = cheminModification;
		}
	}
else if(page=="COMMANDE") {
	if(parent.location.href != cheminCommandes) {
		parent.location.href = cheminCommandes;
		}
	}
else if(page=="COLISUR_S") {
	if(parent.location.href != cheminSouscriptionColisur) {
		parent.location.href = cheminSouscriptionColisur;
		}
	}
else if(page=="COLISUR_M") {
	if(parent.location.href != cheminModificationColisur) {
		parent.location.href = cheminModificationColisur;
		}
	}
else if(page=="COLISUR") {
	if(parent.location.href != cheminColisur) {
		parent.location.href = cheminColisur;
		}
	}
else if(page=="REMISE") {
	if(parent.location.href != cheminRemises) {
		parent.location.href = cheminRemises;
		}
	}
else if(page=="AFFILIES_RATTACHES") {
	if(parent.location.href != cheminListeAffilies) {
		parent.location.href = cheminListeAffilies;
		}
	}
else if(page=="REGLEMENT") {
	if(parent.location.href != cheminReglement) {
		parent.location.href = cheminReglement;
		}
	}	
else if(page=="VERIF_TITRE") {
	if(parent.location.href != cheminVerifTitre) {
		parent.location.href = cheminVerifTitre;
		}
	}
else if(page=="RECHERCHE_TITRE_VOLE") {
	if(parent.location.href != cheminRechercheTitreVoles) {
		parent.location.href = cheminRechercheTitreVoles;
		}
	}
else if(page=="AFFILIES_SUIVIS") {
	if(parent.location.href != cheminListeAffiliesSuivis) {
		parent.location.href = cheminListeAffiliesSuivis;
		}
	}
else if(page=="SUIVI_QUALITE") {
	if(parent.location.href != cheminSuiviQualite) {
		parent.location.href = cheminSuiviQualite;
		}
	}
else if(page=="DECONNEXION") {
	if(parent.location.href != cheminDeconnexion) {
		parent.location.href = cheminDeconnexion;
		}
	}
else if(page=="CGU") {
	if(parent.location.href != cheminCGU) {
		parent.location.href = cheminCGU;
		}
	}
else if(parent.location.href != cheminConnexion) {
	parent.location.href = cheminConnexion;
	}
}

function controleCle(champAControler,code,cle) {
var codeAffilie = champAControler.value;
if(codeAffilie.length > 0) {
	var re = /^([0-9]{1,7})\*([0-9])$/;
	if(!re.test(codeAffilie)) {
		alert("Le code client est de la forme 1234567*0\n(7 chiffres * 1 chiffre)");
		champAControler.focus();
		return false;
		}
	else {
		re.exec(codeAffilie);
		code.value = RegExp.$1;
		cle.value = RegExp.$2;
		return true;
		}
	}
else {
	return false;
	}
}
