var cheminSite = "";
var cheminWebApp = "/votreCompte";

var cheminCompte = parent.location.protocol + "//" + parent.location.host + cheminSite + "/votre-compte/";

var cheminConnexion = cheminCompte + "vous-connecter/index.html";
var cheminDemandeActivation = cheminCompte + "activer-votre-compte/index.html";
var cheminRecupMdp = cheminCompte + "retrouver-votre-mot-de-passe/index.html";
var cheminDossier = cheminCompte + "votre-dossier/index.html";
var cheminModification = cheminCompte + "modifier-votre-dossier/index.html";
var cheminPremiereConnexion = cheminCompte + "votre-premiere-connexion/index.html";
var cheminCommandes = cheminCompte + "vos-commandes/index.html";
var cheminSouscriptionColisur = cheminCompte + "souscrire-colisur/index.html";
var cheminModificationColisur = cheminCompte + "changer-formule-colisur/index.html";
var cheminColisur = cheminCompte + "colisur/index.html";
var cheminRemises = cheminCompte + "vos-remises/index.html";
var cheminListeAffilies = cheminCompte + "vos-affilies-rattaches/index.html";
var cheminReglement = cheminCompte + "vos-reglements/index.html";
var cheminVerifTitre = cheminCompte + "verifier-validite-titre/index.html";
var cheminRechercheTitreVoles = cheminCompte + "rechercher-titres-voles/index.html";
var cheminListeAffiliesSuivis = cheminCompte + "vos-affilies-suivis/index.html";
var cheminSuiviQualite = cheminCompte + "votre-suivi-qualite/index.html";
var cheminCGU = cheminCompte + "validation-des-cgu/index.html"
var cheminPackExpress = cheminCompte + "pack-express/index.html"
var cheminPackGestionPro = cheminCompte + "pack-gestion-pro/index.html"
var cheminFichiers = cheminCompte + "vos-fichiers/index.html"
var cheminDeconnexion = cheminCompte + "deconnexion/index.html";

var cheminStatut = parent.location.protocol + "//" + parent.location.host + cheminWebApp + "/jsp/statut.jsp";

var cheminCguSite = "http://" + parent.location.host + cheminSite + "/rubriques-transverses/cgu/index.html"
var cheminTarifTR = "http://" + parent.location.host + cheminSite + "/le-titre-restaurant/tarifs-de-lannee-en-cours/index.html"
var cheminTarifCAP = "http://" + parent.location.host + cheminSite + "/cap-titre-de-services/contrat-et-tarifs/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 controleSaisie(e,objet,type) 
{
	//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;
	if(type == 'nom') 
		reType = /[A-Za-z ]/
	else if(type == 'majchiffre') 
		reType = /[0-9A-Za-z]/
	else if(type == 'chiffre') 
		reType = /[0-9]/
	else if(type == 'libelle') 
		reType = /[0-9A-Za-z \-\.]/
	var reLettreMin = /[a-z]/
	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(reLettreMin.test(lettreEntree)) {
		if(flagIE) {
			window.event.keyCode = String.fromCharCode(window.event.keyCode).toUpperCase().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 = String.fromCharCode(e.which).toUpperCase();  
			 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 = 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=="PACK_EXPRESS") {
	if(parent.location.href != cheminPackExpress) {
		parent.location.href = cheminPackExpress;
		}
	}
else if(page=="CGU") {
	if(parent.location.href != cheminCGU) {
		parent.location.href = cheminCGU;
		}
	}
else if(page=="PACK_GESTION_PRO") {
	if(parent.location.href != cheminPackGestionPro) {
		parent.location.href = cheminPackGestionPro;
		}
	}
else if(page=="FICHIERS") {
	if(parent.location.href != cheminFichiers) {
		parent.location.href = cheminFichiers;
		}
	}
else if(page=="CguSite") {
	if(parent.location.href != cheminCguSite) {
		parent.location.href = cheminCguSite;
		}
	}
else if(page=="TarifsCap") {
	if(parent.location.href != cheminTarifCAP) {
		parent.location.href = cheminTarifCAP;
		}
	}
else if(page=="TarifsTR") {
	if(parent.location.href != cheminTarifTR) {
		parent.location.href = cheminTarifTR;
		}
	}
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;
	}
}

