


var lesPays = new Array("0000960000000921","0000960000000921","0000960000000924","0000960000000927","000096000000092a","000096000000092d","0000960000000930","0000960000000933","0000960000000936","0000960000000939","000096000000093c","000096000000093f","0000960000000942","0000960000000945","0000960000000948","000096000000094b","000096000000094e","0000960000000951","0000960000000954","0000960000000957","000096000000095a","000096000000095d","0000960000000960","0000960000000963","0000960000000966","0000960000000969","000096000000096c","000096000000096f","0000960000000972","0000960000000975","0000960000000978","000096000000097b","000096000000097e","0000960000000981","0000960000000984","0000960000000987","000096000000098a","000096000000098d","0000960000000990","0000960000000993","0000960000000996","0000960000000999","000096000000099c","000096000000099f","00009600000009a2","00009600000009a5","00009600000009a8","00009600000009ab","00009600000009ae","00009600000009b1","00009600000009b4","00009600000009b7","00009600000009ba","00009600000009bd","00009600000009c0","00009600000009c3","00009600000009c6","00009600000009c9","00009600000009cc","00009600000009cf","00009600000009d2","00009600000009d5","00009600000009d8","00009600000009db","00009600000009de","00009600000009e1","00009600000009e4","00009600000009e7","00009600000009ea","00009600000009ed","00009600000009f0","00009600000009f3","00009600000009f6","00009600000009f9","00009600000009fc","00009600000009ff","0000960000000a02","0000960000000a05","0000960000000a08","0000960000000a0b","0000960000000a0e","0000960000000a11","0000960000000a14","0000960000000a17","0000960000000a1a","0000960000000a1d","0000960000000a20","0000960000000a23","0000960000000a26","0000960000000a29","0000960000000a2c","0000960000000a2f","0000960000000a32","0000960000000a35","0000960000000a38","0000960000000a3b","0000960000000a3e","0000960000000a41","0000960000000a44","0000960000000a47","0000960000000a4a","0000960000000a4d","0000960000000a50","0000960000000a53","0000960000000a56","0000960000000a59","0000960000000a5c","0000960000000a5f","0000960000000a62","0000960000000a65","0000960000000a68","0000960000000a6b","0000960000000a6e","0000960000000a71","0000960000000a74","0000960000000a77","0000960000000a7a","0000960000000a7d","0000960000000a80","0000960000000a83","0000960000000a86","0000960000000a89","0000960000000a8c","0000960000000a8f","0000960000000a92","0000960000000a95","0000960000000a98","0000960000000a9b","0000960000000a9e","0000960000000aa1","0000960000000aa4","0000960000000aa7","0000960000000aaa","0000960000000aad","0000960000000ab0","0000960000000ab3","0000960000000ab6","0000960000000ab9","0000960000000abc","0000960000000abf","0000960000000ac2","0000960000000ac5","0000960000000ac8","0000960000000acb","0000960000000ace","0000960000000ad1","0000960000000ad4","0000960000000ad7","0000960000000ada","0000960000000add","0000960000000ae0","0000960000000ae3","0000960000000ae6","0000960000000ae9","0000960000000aec","0000960000000aef","0000960000000af2","0000960000000af5","0000960000000af8","0000960000000afb","0000960000000afe","0000960000000b01","0000960000000b04","0000960000000b07","0000960000000b0a","0000960000000b0d","0000960000000b10","0000960000000b13","0000960000000b16","0000960000000b19","0000960000000b1c","0000960000000b1f","0000960000000b22","0000960000000b25","0000960000000b28","0000960000000b2b","0000960000000b2e","0000960000000b31","0000960000000b34","0000960000000b37","0000960000000b3a","0000960000000b3d","0000960000000b40","0000960000000b43","0000960000000b46","0000960000000b49","0000960000000b4c","0000960000000b4f","0000960000000b52","0000960000000b55","0000960000000b58","0000960000000b5b","0000960000000b5e","0000960000000b61","0000960000000b64","0000960000000b67","0000960000000b6a","0000960000000b6d","0000960000000b70","0000960000000b73","0000960000000b76","0000960000000b79","0000960000000b7c","0000960000000b7f","0000960000000b82","0000960000000b85","0000960000000b88","0000960000000b8b","0000960000000b8e","0000960000000b91","0000960000000b94","0000960000000b97","0000960000000b9a","0000960000000b9d","0000960000000ba0","0000960000000ba3","0000960000000ba6","0000960000000ba9","0000960000000bac","0000960000000baf","0000960000000bb2","0000960000000bb5","0000960000000bb8","0000960000000bbb","0000960000000bbe","0000960000000bc1","0000960000000bc4","0000960000000bc7","0000960000000bca","0000960000000bcd","0000960000000bd0","0000960000000bd3","0000960000000bd6","0000960000000bd9","0000960000000bdc","0000960000000bdf","0000960000000be2","0000960000000be5");
var lesFormatsTel = new Array("?? ?? ?? ?? ??","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","");
var leTelOrigOuverture = '';
var lePaysOuverture = '';

function doEpurePhone(phone) {
	epure = "";
	for (i=0 ; i<phone.length ; i++) {
		if (phone.substring(i,i+1) >= "0" && phone.substring(i,i+1) <= "9") {
			epure += phone.substring(i,i+1);
		}
	}
	return epure;
}

function formatMasque(masque, entree) {
	// si pas de masque ou entree vide on rend ce qui est rentre
	if (masque == "" || entree == "") {
		return entree;
	}
	// Si conforme au masque en rend l'entree
	if (masque.length == entree.length) {
		k=i=0;
		while (k==0 && i<masque.length) {
			if ((masque.substring(i,i+1) != entree.substring(i,i+1)) && (masque.substring(i,i+1) != "?")) {
				k=1;
			} else {
				i++;
			}
		}
		if (k==0) {
			return entree;
		}
	}
	// on compte le nbr de ? dans le masque
	for (cpt=i=0 ; i<masque.length ; i++) {
		if (masque.substring(i,i+1) == "?") {
			cpt++;
		}
	}
	// on extrait les chiffres de la saisie
	epure = "";
	for (i=0 ; i<entree.length ; i++) {
		if (entree.substring(i,i+1) >= "0" && entree.substring(i,i+1) <= "9") {
			epure += entree.substring(i,i+1);
		}
	}
	
	// Si le nbr de ? different du nbr de chiffres dans l'entree en rend null
	if (epure.length != cpt) {
		res = "Erreur:" + cpt.toString();
		return res;
	}
	//on recupere le resultat
	result = "";
	j = 0;
	for (i=0 ; i<masque.length ; i++) {
		if (masque.substring(i,i+1) == "?") {
			result += epure.substring(j,j+1);
			j++;
		} else {
			result += masque.substring(i,i+1);
		}
	}
	return result;
}

function doFormatTel(leChamp , leMsg, leChampPays) {
	if (!leChampPays) {
		return;
	}
	if (leChampPays.options) {
		nomPays = leChampPays.options[leChampPays.selectedIndex].value;
	} else {
		nomPays = leChampPays.value;
	}
	if (!nomPays || nomPays == '') {
		return;
	}
	var posPays = 0;
	
	//alert('nomPays ' + nomPays);
	
	while ((posPays < lesPays.length) && (lesPays[posPays] != nomPays)) {
		posPays++;
	}
	
	if(posPays < lesPays.length) {
		masque = lesFormatsTel[posPays];
		valueDuChamp = leChamp.value;
		
		// Country code is the '+??' portion. This needs to be stripped off
		// of the field value so as to not be included in mask
		if (masque.length > 0 && masque.indexOf("+") > -1) {
			countryCode = masque.substring(0, masque.indexOf(" "));
			
			if (valueDuChamp.indexOf(countryCode) > -1) {
				valueDuChamp = valueDuChamp.substring(countryCode.length, valueDuChamp.length);
			}
		}
		
		//alert('masque ' + masque);
		//alert('leChamp.value ' + leChamp.value);
		res = formatMasque(masque , valueDuChamp);
		//alert('res ' + res);
		if (res.indexOf("Erreur:") != -1) {
			window.status = leMsg + " Vous devez entrer " + res.substring(7, res.length) + " chiffres.";
		} else {
			leChamp.value = res;
			window.status = "";
		}
	}
}

function getTelEpure(masque , entree) {
	// on extrait les chiffres de la saisie
	var epure = "";
	for (i=0 ; i<entree.length ; i++) {
		var digit = entree.substring(i, i+1);
		if (digit >= "0" && digit <= "9") {
			epure += digit;
		}
	}
	// si pas de masque on rend le tel epure
	if (masque == "") {
		return epure;
	}
	// Si non conforme au masque en rend le tel epure
	if (masque.length == entree.length) {
		k = i = 0;
		while (k == 0 && i < masque.length) {
			if ((masque.substring(i,i+1) != entree.substring(i,i+1)) && (masque.substring(i,i+1) != "?")) {
				k=1;
			} else {
				i++;
			}
		}
		if (k != 0) {
			return epure;
		}
	} else {
		return epure;
	}
	// tel conforme au masque :
	var res = "";
	for (i = 0 ; i < masque.length ; i++) {
		if (masque.substring(i,i+1) == "?") {
			res += entree.substring(i,i+1);
		}
	}
	return res;
}

function doEpureTel(leChamp , leChampOrig, leChampPays) {
	if (!leChampPays) {
		return;
	}
	if (leChampPays.options) {
		nomPays = leChampPays.options[leChampPays.selectedIndex].value;
	} else {
		nomPays = leChampPays.value;
	}
	if (!nomPays || nomPays == '') {
		return;
	}
	var posPays = 0;
	if (nomPays != "" ) {
		while ((posPays < lesPays.length) && (lesPays[posPays] != nomPays)) {
			posPays++;
		}
		masque = lesFormatsTel[posPays];
		leChampOrig.value = getTelEpure(masque , leChamp.value);
	}
}


