/**
 * @version $Id: reservation.js,v 1.49.2.15 2011-12-23 10:36:26 vle Exp $
 * @package gaumont-pathe
 * @copyright Copyright (C) 2008 BROCELIA. All rights reserved.
 */

var setDisable = true;

function formatCurrency(floatvalue){
	var stringvalue = floatvalue.toFixed(2).toString();
	return stringvalue.replace(".",",");
}

var dernier_nb_places;
var prix_lunettes;

function calcul() {
	var prix_total = 0;
	var nb_total_places = 0;
	var nb_tmp, prix_tmp;
	$$('select.tarif').each(function (e, i) {
		nb_tmp = e.value.toInt();
		prix_tmp = prix[i]*nb_tmp;
		$('total_tarif_'+i).set('html', formatCurrency(prix_tmp)+'&euro;');
		prix_total += prix_tmp;
		nb_total_places += nb_tmp;
	});

	if(nb_total_places > max_places) {
		alert (max_places + " places maximum par réservation, tous tarifs confondus");
		$$('select.tarif').each(function (e, i) {
			e.value = 0;
			$('total_tarif_'+i).set('html', '0,00&euro;');
		});
		nb_total_places = 0;
		prix_total = 0;
	} else {
		$$('select.tarif').each(function (s, i) {
			s.getElements('option').each(function (o, i) {
				o.disabled = i > s.value.toInt() + max_places - nb_total_places;
			});
		});
	}
	$('nb_total_places').set('html', nb_total_places);

	/* lunettes */
	var lunettesNode = $('lunettes_nb');

	if(nb_total_places != dernier_nb_places){
		majLunettes(nb_total_places);
	}

	if(lunettesNode){
		var total_lunettes = lunettesNode.value * prix_lunettes;
		prix_total += total_lunettes;
		$('lunettes_total').set('html',formatCurrency(total_lunettes) +'&euro;');
	}
	dernier_nb_places = nb_total_places;

	/* fin lunettes */

	$('prix_total').set('html', formatCurrency(prix_total)+'&euro;');


}

window.addEvent('load', function() {
	$$('select.tarif').each(function (e) {
		e.addEvent('change', calcul);
	});
});

window.addEvent('domready', function()
{
	if($('modes_reservation'))
	{
		var paiementTypeList = $$('#modes_reservation input[name="code_paiement"]');
		// Select paiement if there is only one available
		if (paiementTypeList.length == 1)
			$$('#modes_reservation input[name="code_paiement"]').each(function(paiementType) {
				paiementType.setProperty('checked', 'checked');
			});
	}
});

/* PARAGON */
function checkCinedayParagon()
{
	var nbparagons = 0;
	for(var i=1; i<=5; i++){
		fieldname = 'numero_carte_' + i;
		fieldnode = $(fieldname);
		if(!fieldnode)
			break;
		if(!fieldnode.value)
			break;
		nbparagons++;
	}

	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		var nbCineday = nb_cineday;
		var tarifArray = new Array();
	}
	nbCinedayMax = Math.floor(Math.min(nbCineday,nbparagons))

	$('cineday_nbPlaceTotal').set("html",nbCinedayMax + nbparagons);

	$('cineday_nbPlaceCineday').set("html",nbCinedayMax);
	if (nbCinedayMax>1){
		$('cineday_s1').set("html","s");
		$('cineday_s2').set("html","s");
	}else{
		$('cineday_s1').set("html","");
		$('cineday_s2').set("html","");
	}
}

function checkSurchargeParagon(){
	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		var nbCineday = nb_cineday;
		var tarifArray = new Array();
	}

	var fieldname, fieldnode;
	var nbparagons = 0;
	for(var i=1; i<=5; i++){
		fieldname = 'numero_carte_' + i;
		fieldnode = $(fieldname);
		if(!fieldnode)
			break;
		if(!fieldnode.value)
			break;
		nbparagons++;
	}
	var montant_total = surcharge * (nbparagons + nbCineday);

	var surchargeNegTot = 0;
	for(var i=0;i<=surchargeNeg.length;i++){
		if( surchargeNeg[i]){
			surchargeNegTot += surchargeNeg[i];
		}
	}
	if (surchargeNegTot > 0){
		montant_total -= surchargeNegTot;
	}
	
	/* lunettes */
	if(nbparagons != dernier_nb_places){
		majLunettes(nbparagons + nbCineday);
	}
	dernier_nb_places = nbparagons;

	lunettesNode = $('lunettes_nb');
	if(lunettesNode){
		var total_lunettes = lunettesNode.value * prix_lunettes;
		montant_total += total_lunettes;
		$('lunettes_total').set('html',formatCurrency(total_lunettes) +'&euro;');
	}

	/* fin lunettes */

	$('montant_total').innerHTML = "<strong>"+formatCurrency(montant_total)+" &euro;</strong>";
	$('form_montant_total').value = montant_total;

}

function checkNbplaceParagon()
{
	var fieldname, fieldnode;
	var nbparagons = 0;
	for(var i=1; i<=5; i++){
		fieldname = 'numero_carte_' + i;
		fieldnode = $(fieldname);
		if(!fieldnode)
			break;
		if(!fieldnode.value)
			break;
		nbparagons++;
	}
	dernier_nb_places = nbparagons;
}

var paragonvalides = new Array();
paragonvalides[1] = false;
paragonvalides[2] = false;
paragonvalides[3] = false;
paragonvalides[4] = false;
paragonvalides[5] = false;
var paragonvalues = new Array();
paragonvalues[1] = 0;
paragonvalues[2] = 0;
paragonvalues[3] = 0;
paragonvalues[4] = 0;
paragonvalues[5] = 0;
var comid;
var num;


function checkParagon(nr,name){
	var value = $('numero_carte_'+nr).value;
	if (value != paragonvalues[nr] && (value.length >3 || paragonvalides[nr] )){
		paragonvalues[nr]=value;
		$('paragon_feedback_'+nr).innerHTML = '';
		if(value.length == 9 || value.length == 12){
			if(/^([0-9])+$/.test(value)){

				$('ajax_loading_'+nr).style.visibility = 'visible';
				num = nr;

				var ajax = new Request({
						url: 'index.php?do=ajax_paragon&com_id='+ comid +'&sub='+ name +'&numero=' + value
					, method: 'get'
					, async: true
					, onSuccess: function(responsetext)
					{
						var text = responsetext.split('|');
						actualiserFormParagon(text[0], num);
						if (text[1]){
							if (surcharge != text[1]){
								surchargeNeg[num] = surcharge - text[1];
							}else{
								surchargeNeg[num] = 0;
							}
						}
					}
				}).send();
			}
		}
		else if((value.length == 4 || value.length == 6) && name == 'invitation' )
		{
			if(/^([0-9])+$/.test(value)){

				$('ajax_loading_'+nr).style.visibility = 'visible';
				num = nr;

				var ajax = new Request({
						url: 'index.php?do=ajax_paragon&com_id='+ comid +'&sub=vip&numero=' + value
					, method: 'get'
					, async: true
					, onSuccess: actualiserFormParagon
				}).send();
			}
		}
	}
}

function actualiserFormParagon(responsetext,responsexml){
	$('ajax_loading_'+num).style.visibility = 'hidden';
	var message = "Merci de vérifier votre numéro de carte";

	if (responsetext && !(responsetext.toInt() < 0) )
	{
		if (responsetext.toInt() == 1)
		{
			message = '<img title="valide" alt="valide" src="img/interface/pictos/valide.png">';
			$('bouton_valider').src= "img/interface/boutons/valider.gif";
			$('bouton_valider').disabled= "";
		}
		else
		{
			message = responsetext;
			if (setDisable){
				$('bouton_valider').src= "img/interface/boutons/valider-disabled.gif";
				$('bouton_valider').disabled= "disabled";
			}
		}
	}

	$('paragon_feedback_'+num).innerHTML = message;
}

	/* LE PASS */

var passvalides = new Array();
passvalides[1] = false;
passvalides[2] = false;
var passvalues = new Array();
passvalues[1] = 0;
passvalues[2] = 0;
var cg_a_valider = new Array();
cg_a_valider[0] = false;
cg_a_valider[1] = false;

var nb_places_total;

function checkPass(nr){
	var value = $('numero_carte_'+nr).value;
	var invalide_txt = $('texte_invalide').innerHTML;
	if(value != passvalues[nr] && (value.length > 4 || passvalides[nr])){
		passvalues[nr] = value;
		var valide = false;
		var cg_valider = false;
		if(value.length == 11){
			if(/^([0-9])+$/.test(value)){
				/* lancer requete ajax */
				/*var ajax = new Ajax('index.php?do=ajax&sub=pass_valide&pass=' + value,
					{
						method: 'get',
						async: false
					}
				).request();
				if(ajax.transport && ajax.transport.responseText.substr(0,1) == "1"){
					valide = true;
				}
				*/
				var ajax = new Request({
						url: 'index.php?do=ajax&sub=pass_valide&pass=' + value
					, method: 'get'
					, async: false
				}).send();
				if(ajax.response && ajax.response.text.substr(0,1) == "1"){
					valide = true;
				}
				else if(ajax.response && ajax.response.text.substr(0,1) == "2"){
					valide = true;
					// nouveaux CG à valider
					cg_valider = true;
				}else if (ajax.response && ajax.response.text.substr(0,2) == "-2"){
					invalide_txt = $('texte_invalide_x_mins').innerHTML;
				}
			}
		}
		if(valide){
			$('pass_'+nr+'_feedback').innerHTML = $('texte_valide').innerHTML;
			// nouveaux CG à valider ?
			if(cg_valider){
				$('pass_cg_'+nr).style.display = 'block';
				cg_a_valider[nr] = true;
			}
			$('bouton_valider').src= "img/interface/boutons/valider.gif";
			$('bouton_valider').disabled= "";

		} else {
			$('pass_'+nr+'_feedback').innerHTML = invalide_txt;
			// nouveaux CG OK
			$('pass_cg_'+nr).style.display = 'none';
			cg_a_valider[nr] = false;

			if (setDisable){
				$('bouton_valider').src= "img/interface/boutons/valider-disabled.gif";
				$('bouton_valider').disabled= "disabled";
			}
		}
		passvalides[nr] = valide;

		actualiserFormPass();
	}

}

var montant_accompagnant = 0.0;
var montant_surcharge = 0.0;

function actualiserFormPass(){

	if(passvalides[1] && $('av_accompagnant'))
		$('av_accompagnant').style.visibility = 'hidden';


	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		if (nb_cineday > 0 && passvalides[1] && $('nb_ac_0').checked){
			$('nb_ac_1').checked =true;
			actualiserFormAccompagnant();
		}
		if (nb_cineday ==2 && passvalides[2]){
			$('nb_ac_2').checked=true;
			actualiserFormAccompagnant();
		}
	}


	if($('nb_ac_1')) {

		$('nb_ac_1').disabled = !passvalides[1];
		$('nb_ac_2').disabled = !passvalides[1] || !passvalides[2];


		if($('nb_ac_2').disabled && $('nb_ac_2').checked)
			$('nb_ac_1').checked = true;

		if($('nb_ac_1').disabled && $('nb_ac_1').checked)
			$('nb_ac_0').checked = true;

	}

	montant_surcharge = 0.0;

	if(seance3d){

		if(passvalides[1])
			montant_surcharge += surcharge;
		if(passvalides[2])
			montant_surcharge += surcharge;

		$('montant_surcharge').innerHTML = "<strong>"+formatCurrency(montant_surcharge)+" &euro;</strong>";

	}

	actualiserMontantTotal();

	// deselectionner si selectionné et desactivé




}

function actualiserFormAccompagnant(){
	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		var nbCineday = nb_cineday;
		var tarifArray = new Array();
	}

	var nb = 0;



	montant_accompagnant = 0.00;
	if($('nb_ac_2').checked){
		if (nbCineday == 0){
			montant_accompagnant = tarif_ac * 2;
			nb = 2;
		}

		if (nbCineday == 1){
			montant_accompagnant = tarif_ac;
			nb = 1;
		}

	} else if($('nb_ac_1').checked && nbCineday == 0 ){
		montant_accompagnant = tarif_ac;
		nb = 1;
	}

	montant_accompagnant += surcharge_cineday * nbCineday;

	if( (seance3d && surcharge) || montant_accompagnant>0 ){
		$('griser_accompagnant').style.display = 'block';
	} else {
		$('griser_accompagnant').style.display = 'none';
	}

	var txt = "";
	if ( montant_accompagnant )
	{
		if (nbCineday >0){
			txt = formatCurrency(montant_accompagnant) + " &euro; + "+ nbCineday +" place(s) offerte(s) avec Orange Cinéday";
		}else{
			txt = formatCurrency(montant_accompagnant)+"  &euro;";
		}
	}else {
		if (nbCineday>0){
			txt = "Offert avec Orange Cinéday";
		}else{
			txt = formatCurrency(montant_accompagnant)+"  &euro;";
		}
	}

	$('montant_accompagnants').innerHTML = "<strong>"+txt+"</strong>";

	actualiserMontantTotal();

}

function checkVoucherPass(){

	actualiserMontantTotal();

}

function actualiserMontantTotal(){

	/* vouchers */

	var montant_total = 0;

	lunettesNode = $('lunettes_nb');
	if(lunettesNode){

		nb_places_total = 0;
		if(passvalides[1])
			nb_places_total++;
		if(passvalides[2])
			nb_places_total++;
		if($('nb_ac_1')){
			if($('nb_ac_2').checked){
				nb_places_total += 2
			} else if($('nb_ac_1').checked){
				nb_places_total++;
			}
		}

		if(typeof(dernier_nb_places) == 'undefined')
		{
			dernier_nb_places = nb_places_total;
			majLunettes(nb_places_total)
		}
		if(nb_places_total != dernier_nb_places){
			majLunettes(nb_places_total)
		}
		dernier_nb_places = nb_places_total;

		var total_lunettes = lunettesNode.value * prix_lunettes;
		montant_total += total_lunettes;

		$('lunettes_total').set('html',formatCurrency(total_lunettes) +'&euro;');
		if (total_lunettes > 0){
			$('griser_accompagnant').style.display = 'block';
		}
	}

	if($('montant_total')){
		montant_total += montant_accompagnant + montant_surcharge;
		$('montant_total').innerHTML = "<strong>"+formatCurrency(montant_total)+" &euro;</strong>";
		$('form_montant_total').value = montant_total;
	}

}


var cartenvalue = '';
var cartenvalide = false;
var progid;
var quota;

function checkNPlaces(){

	var value = $('numero_carte').value;
	if(value != cartenvalue){

		//alert("Verifier..");

		cartenvalue = value;
		var valide = false;

		if(value.length == 9 || value.length == 12){

			if(/^([0-9])+$/.test(value)){

				//alert("Afficher icone");

				$('ajax_loading').style.visibility = 'visible';

				//alert("Visibility icone : " + $('ajax_loading').style.visibility);

				var ajax = new Request({
						url: 'index.php?do=ajax_nplaces&prog_id=' + progid + '&numero=' + value
					, method: 'get'
					, async: true
					, onSuccess: treatNPlaces
				}).send();

			}
		}

	}

}

function treatNPlaces(responsetext,responsexml){

	//alert("treatNPlaces");

	$('ajax_loading').style.visibility = 'hidden';

	var valide = false;

	if(responsetext){

		//alert("Parser response");

		var responsearray = new Array();
		responsearray = responsetext.split(';');

		if(responsearray[0].toInt() > 0){
			valide = true;
		}
	}

	//alert("Resultat: valide = " + valide);

	$('nplaces_nb_places').options.length = 1;

	if(valide){

		//alert("Valide => Actualiser textes");

		$('solde').innerHTML = responsearray[2] == 1 ? "1 place utilisable" : responsearray[2].toInt() + " places utilisables";
		$('solde').innerHTML += " jusqu'au " + responsearray[1];

		$('section_nombre_places').style.visibility = 'visible';
		//$('bouton_valider').style.display = 'block';
		var maxnum = Math.min(quota,responsearray[0].toInt());
		for(var i=1; i<=maxnum; i++){
			var texte = i == 1 ? "1 place" : i + " places";
			$('nplaces_nb_places').options[i] = new Option(texte,i);
		}

		cartenvalide = true;

		$('bouton_valider').src= "img/interface/boutons/valider.gif";
		$('bouton_valider').disabled= "";

	} else {

		//alert("Invalide => Actualiser textes");

		if ( responsearray[0].toInt() < 1 || !responsetext )
		{
			$('solde').innerHTML = 'Merci de vérifier votre numéro de carte';
		}
		else
		{
			$('solde').innerHTML = responsetext;
		}
		$('section_nombre_places').style.visibility = 'hidden';
		//$('bouton_valider').style.display = 'none';

		cartenvalide = false;

		if (setDisable){
			$('bouton_valider').src= "img/interface/boutons/valider-disabled.gif";
			$('bouton_valider').disabled= "disabled";
		}
	}

	//alert("Actualiser textes fini");

}

function checkSurchargeNplaces(){

	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		var nbCineday = nb_cineday;
		var tarifArray = new Array();
	}

	var nb_places_carte = $('nplaces_nb_places').value.toInt();
	var montant_total = surcharge * (nb_places_carte + nbCineday);

	if (nbCineday>0){

		if (nbCineday>nb_places_carte ){
			nbCineday = nb_places_carte;
		}

		var s = "";
		if (nbCineday>1)
			s="s";
		$('nplaces_information').set('html',"+ "+nbCineday+" place"+s+" offerte"+s+" avec Orange Cinéday");
	}

	lunettesNode = $('lunettes_nb');
	if(lunettesNode) {
		var total_lunettes = lunettesNode.value * prix_lunettes;
		montant_total += total_lunettes;

		$('lunettes_total').set('html',formatCurrency(total_lunettes) +'&euro;');
	}

	if(nb_places_carte != dernier_nb_places){
		majLunettes(nb_places_carte);
	}
	dernier_nb_places = nb_places_carte;

	if($('montant_total')){
		$('montant_total').innerHTML = "<strong>"+formatCurrency(montant_total)+" &euro;</strong>";
		$('form_montant_total').value = montant_total;
	}
}

function verif_cartenplaces(){
	//TODO
	return true;
}

function majLunettes(nb_places){

	lunettesNode = $('lunettes_nb');
	if(lunettesNode){
		lunettesNode.getChildren().each(function (e, i) {
			if(e.value > nb_places){
				lunettesNode.removeChild(e);
			}
		});
		i = lunettesNode.options.length;
		while (i <= nb_places){
			var pairestexte = i > 1 ? ' paires' : ' paire';
			lunettesNode.appendChild(new Element('option', {value : i, html : i + pairestexte}));
			i++;
		}
	}

}


// ajout des fonctions pour limiter la réservation.
function checkCarteFidelite(){
		var value = $('num_cartefid').value;
		var valide = 0;


		if (value.length != 8 )
		{
			$('poursuivre_fid').setStyle('display', 'none');
				$('carte_fid_ok').checked="";
				$('poursuivre_fid_ko').style.visibility = 'hidden';
		}
		else if(value != oldCarteFid){

		$('ajax_loading_fid').style.visibility = 'visible';

			if(/^([0-9])+$/.test(value)){

				var ajax = new Request({
						url: 'index.php?do=ajax&sub=carte_fidelite_valide&numero=' + value
					, method: 'get'
					, async: false
				}).send();
				if(ajax.response && ajax.response.text.substr(0,1) == "1"){
					valide = true;
				}
			}

		$('ajax_loading_fid').style.visibility = 'hidden';
			if(valide)
			{
				$('poursuivre_fid_ko').style.visibility = 'hidden';
				$('poursuivre_fid').setStyle('display', 'inline');
				$('carte_fid_ok').checked="checked";
			}
			else
			{
				$('poursuivre_fid_ko').style.visibility = 'visible';
			$('poursuivre_fid').setStyle('display', 'none');
				$('carte_fid_ok').checked="";
			}
		}

		oldCarteFid = value;
	}

function checkCartePass(){


		var value = $('num_cartepass').value;
		var valide = 0;

		if (value.length != 11 )
		{
			$('poursuivre_pass').setStyle('display', 'none');
				$('carte_pass_ok').checked="";
				$('poursuivre_pass_ko').style.visibility = 'hidden';
		}
		else if(value != oldCartePass){

		$('ajax_loading_pass').style.visibility = 'visible';

			if(/^([0-9])+$/.test(value)){

				var ajax = new Request({
						url: 'index.php?do=ajax&sub=carte_pass_valide&numero=' + value
					, method: 'get'
					, async: false
				}).send();
				if(ajax.response && ajax.response.text.substr(0,1) == "1"){
					valide = true;
				}
			}

			$('ajax_loading_pass').style.visibility = 'hidden';
			if(valide)
			{
				$('poursuivre_pass_ko').style.visibility = 'hidden';
				$('poursuivre_pass').setStyle('display', 'inline');
				$('carte_pass_ok').checked="checked";
			}
			else
			{
				$('poursuivre_pass_ko').style.visibility = 'visible';
			$('poursuivre_pass').setStyle('display', 'none');
				$('carte_pass_ok').checked="";
			}
		}

		oldCartePass = value;
	}

function checkCodePromo(orangePromo,otherPromo,type,id)
{
	if (orangePromo){
		var result = checkCodeOrange($('code_promo_value').value,type,id);
		if( result === true){
			$("promo_cineday").setStyle("display","block");
			$("resa_promo").setStyle("display","none");
			return ;
		}else if(result){
			alert(result);
		}
	}

	if (otherPromo)
	{
		if ($('code_promo_value').value)
		{
			$('paiement_carte_bancaire').checked = "checked";
			if (verif_choixmode()){
				$('form_choix_mode').submit();
			}
		}
	}
}

function checkCodeOrange(numero,type,id){

	if (numero.length != 8 )
	{
		return false;
	}

	if(/^([0-9])+$/.test(numero)){

		var name="orange"
		if (type == "prog"){
			var req = '&prog_id='+ id
		}else{
			var req = '&com_id='+ id
		}

		var ajax = new Request({
			url: 'index.php?do=ajax_paragon&sub='+ name +'&numero=' + numero + req
				, method: 'get'
				, async: false
			}).send();

		if(ajax.response){
			if (ajax.response.text.substr(0,1) == "1"){
				return true;
			}else
			{
				return ajax.response.text;
			}
		}
	}

	return false;

}


var oldCarteFid = Array();
var nbFidFeeld = 0;
var nbFidValide = 0;
function checkLucky(nr){

	if ($('numero_carte__fid'+nr)==null)
		return;

	var value = $('numero_carte__fid'+nr).value;
	var valide = 0;

	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		var nbCineday = nb_cineday;
		var tarifArray = new Array();
	}

	var nb_places = dernier_nb_places + nbCineday ;

	if(typeof(has_not_lucky) !== 'undefined')
	{
		for(var i = 0, l = has_not_lucky.length; i < l; i++) {
			nb_places -= $('nb_places').getElements('select[name^=nb_places['+ has_not_lucky[i] +']]').getSelected()[0][0].value;
			}
	}

	if ($('pass_1_feedback')){
		nb=0;
		if($('nb_ac_2') && $('nb_ac_2').checked){
			nb = 2;
		} else if($('nb_ac_1') && $('nb_ac_1').checked){
			nb = 1;
		}
		if (nb == 0)
		{
			$('carte_lucky').style.display = 'none';
		}
		else
		{
			$('carte_lucky').style.display = '';
		}
		nb_places = nb;
	}


	if (nb_places > nbFidFeeld && nbFidFeeld != nbFidValide+1 )
	{
				nbFidFeeld ++;
				$('ligne_carte_'+nbFidFeeld).style.display = 'block';
	}

	if (nb_places < nbFidFeeld )
	{
		if ( $('numero_carte_fid'+nbFidFeeld)){
			$('numero_carte_fid'+nbFidFeeld).value = '';
			$('ligne_carte_'+nbFidFeeld).style.display = 'none';
			nbFidFeeld --;
		}


	}

		if (value.length != 8 )
		{
				$('poursuivre_fid_ko_'+nr).style.visibility = 'hidden';
				$('poursuivre_fid_ok_'+nr).style.visibility = 'hidden';
				$('poursuivre_fid_same_'+nr).style.visibility = 'hidden';
		}
		else if (in_array(oldCarteFid,value,nr))
		{
				$('poursuivre_fid_same_'+nr).style.visibility = 'visible';
			$('poursuivre_fid_ko_'+nr).style.visibility = 'hidden';
				$('poursuivre_fid_ok_'+nr).style.visibility = 'hidden';
			return;
		}
		else if(value != oldCarteFid[nr]){

		$('ajax_loading_'+nr).style.visibility = 'visible';

			if(/^([0-9])+$/.test(value)){

				var ajax = new Request({
						url: 'index.php?do=ajax&sub=carte_fidelite_valide&numero=' + value
					, method: 'get'
					, async: false
				}).send();
				if(ajax.response && ajax.response.text.substr(0,1) == "1"){
					valide = true;
				}
			}

		$('ajax_loading_'+nr).style.visibility = 'hidden';
			if(valide)
			{
				$('poursuivre_fid_ko_'+nr).style.visibility = 'hidden';
				$('poursuivre_fid_same_'+nr).style.visibility = 'hidden';
				$('poursuivre_fid_ok_'+nr).style.visibility = 'visible';
			nbFidValide ++;

				if (nr < oldCarteFid.length-1 && nr < nb_places)
				{
					var nr1 = nr+1;
					nbFidFeeld ++;
					$('ligne_carte_'+nr1).style.display = 'block';
				}
			}
			else
			{
				$('poursuivre_fid_ko_'+nr).style.visibility = 'visible';
				$('poursuivre_fid_same_'+nr).style.visibility = 'hidden';
				$('poursuivre_fid_ok_'+nr).style.visibility = 'hidden';
			}
		}

		oldCarteFid[nr] = value;
}

function in_array(array, p_val, notest) {
		for(var i = 0, l = array.length; i < l; i++) {
				if(i!= notest && array[i] == p_val) {
						rowid = i;
						return true;
				}
		}
		return false;
}

function haveATel(){
	var ret = false;

	$$('.telToSel').each(
			function(item){
			if(item.checked){
					ret = true;
			}
	});

	return ret;
}

function verif_choixTel(){
	if (haveATel()){
		return true;
	}else{
		alert ("Veuillez sélectionnez le type de mobile avant de poursuivre.");
		return false;
	}
	return false;
}

function vip_nb_place(){
	var nbCineday = 0;
	if(typeof(nb_cineday) !== 'undefined')
	{
		var nbCineday = nb_cineday;
		var tarifArray = new Array();
	}
	if (nbCineday == 0)
			return;

	if ($("une_place").checked){
		var nb_place = 1 + Math.min(1,nbCineday);
	}else if ($("deux_places").checked){
		var nb_place = 2 + nbCineday;
	}

	if (nbCineday==2 && $("deux_places").checked ){
		$("vip_information").set("html","Nombre de places : "+ nb_place  +" dont "+nbCineday+" place offerte avec Orange Cinéday");
	}else{
		$("vip_information").set("html","Nombre de places :  "+ nb_place  +" dont 1 place offerte avec Orange Cinéday");
	}
}

