function changeChoice(id) {
	checkEnCours = id;
}

/*
* Fonction pour afficher le tableau comparatif en fonction de la duree d'engagement
*/
function ChangeEngagementComparatif(engagement)	 {
	var sEngVisible 		= engagement;
	var sEngInvisible 		= engagement == 12 ? 24 : 12;
	GetId("tableau_comp_"+sEngInvisible).style.display= "none";
	GetId("tableau_comp_"+sEngVisible).style.display= "inline";
}

function updatePrix(iIdSousGamme, iDuree){
    
    // Tbody pour IE
    var tbodyPta = document.createElement('tbody');
    
    for (var index = 0, len = oAllMontantNeo[iIdSousGamme][iDuree].length; index < len; index++) {
    
        if (oAllMontantNeo[iIdSousGamme][iDuree][index].fPrix != null) {
			var indexId = index + 1;
            var trPta = document.createElement('tr');
            
            if (oAllMontantNeo[iIdSousGamme][iDuree][index].bHasPta == true) {
                
                var tdDuree = document.createElement('td');
                tdDuree.className = 'temps';
                tdDuree.innerHTML = oAllMontantNeo[iIdSousGamme][iDuree][index].DUREE;
                
                var tdPrix = document.createElement('td');
                tdPrix.className = 'prix';
                var divPrix = document.createElement('div');
                var sInput = "";
                var inputPrix = CreateElementAndName('input', 'choix');
                inputPrix.setAttribute('type', 'radio');
                inputPrix.setAttribute('id', 'choix_' + iDuree + '_' + indexId);
				
                // Modification Prix sur la Box Prix du Mobiile
				inputPrix.index = indexId;
				if (!bPanier) {
					inputPrix.onclick = function(){
						changeChoice(this.index);
						affiche_prix_tel_panier(pMobile[oAllMontantNeo[iIdSousGamme][iDuree][this.index - 1].PTA_ID]);
					};
				} else {
					inputPrix.onclick = function(){
						changeChoice(this.index);
					};
				}
                inputPrix.setAttribute('title', oAllMontantNeo[iIdSousGamme][iDuree][index].DUREE + ' / ' + iDuree + 'mois');

                inputPrix.setAttribute('value', oAllMontantNeo[iIdSousGamme][iDuree][index].PTA_ID);
                
                var pPrix = document.createElement('p');
                pPrix.innerHTML = oAllMontantNeo[iIdSousGamme][iDuree][index].sPrix_v2;
                
                divPrix.appendChild(inputPrix);
                divPrix.appendChild(pPrix);
                tdPrix.appendChild(divPrix);
                
                trPta.appendChild(tdDuree);
                trPta.appendChild(tdPrix);
            }
            else {
                var tdDuree = document.createElement('td');
                tdDuree.className = 'temps_gris';
                
                tdDuree.innerHTML = oAllMontantNeo[iIdSousGamme][iDuree][index].DUREE;
                
                var tdPrix = document.createElement('td');
                tdPrix.className = 'prix_gris';
                
                var divPrix = document.createElement('div');
                divPrix.setAttribute("onmouseover", "showInfoBulle(this, 'Offre Non disponible avec ce téléphone', {'align': 'right', 'width':220});");
                
                var inputPrix = CreateElementAndName('input', 'choix');
                inputPrix.setAttribute('id', 'choix_' + iDuree + '_' + indexId);
                inputPrix.setAttribute('type', 'radio');
                inputPrix.setAttribute('disabled', 'disabled');
                inputPrix.setAttribute('value', '');
                
                var pPrix = document.createElement('p');
                pPrix.innerHTML = oAllMontantNeo[iIdSousGamme][iDuree][index].sPrix_v2;
                
                divPrix.appendChild(inputPrix);
                divPrix.appendChild(pPrix);
                tdPrix.appendChild(divPrix);
                
                trPta.appendChild(tdDuree);
                trPta.appendChild(tdPrix);
            }
            
            tbodyPta.appendChild(trPta);
        }
    }
    
    document.getElementById('prix_pta_' + iDuree).appendChild(tbodyPta);
}

function changePrix(iIdOnglet, iIdSousGamme){
    iCurrentSousGamme = iIdSousGamme;
    
    var iDuree = iCurrentDuree;
    var iDureeComplementaire = (iDuree == 12) ? 24 : 12;
    
    $('prix_pta_' + iDuree).update();
    $('prix_pta_' + iDureeComplementaire).update();
    
    updatePrix(iIdSousGamme, iDuree);
    updatePrix(iIdSousGamme, iDureeComplementaire);
    
    $('onglets_forfait' + iIdOnglet).addClassName('onglets_forfait_on');
    
    for (var index = 1; index <= 4; index++) {
        if (index != iIdOnglet) {
            $('onglets_forfait' + index).removeClassName('onglets_forfait_on');
        }
    }
    
    libelleGammeMisePanier = oAllSousGammeLibellePanier[iIdSousGamme];
    
    changeDescription('essentiel');
	checkRadio();
}

function changeDuree(iDuree){
    iCurrentDuree = iDuree;
    
    var iDureeComplementaire = (iDuree == 12) ? 24 : 12;
    $('tableau_pta_' + iDuree).show();
    $('tableau_pta_' + iDureeComplementaire).hide();
    
    // Modification de la classe
    $('onglet_' + iDuree + 'mois_on').show();
    $('onglet_' + iDuree + 'mois_off').hide();
    
    $('onglet_' + iDureeComplementaire + 'mois_off').show();
    $('onglet_' + iDureeComplementaire + 'mois_on').hide();
    
    checkRadio();
}

function changeDescription(sTypeDescription){
    $('titre_description').update();
    
    if (sTypeDescription == 'essentiel') {
        var pTitre_description = document.createElement('p');
        pTitre_description.innerHTML = 'L\'essentiel';
        
        $('titre_description').insert(pTitre_description);
        $('contenu_description').update(oAllTexteCentralNeo3[iCurrentSousGamme]['TEXTE_ESSENTIEL']);
        
        $('btn_essentiel').addClassName('actif');
        $('btn_avantages').removeClassName('actif');
    }
    else 
        if (sTypeDescription == 'avantages') {
            var pTitre_description = document.createElement('p');
            pTitre_description.innerHTML = 'Les avantages';
            
            $('titre_description').insert(pTitre_description);
            $('contenu_description').update(oAllTexteCentralNeo3[iCurrentSousGamme]['TEXTE_AVANTAGES']);
            
            $('btn_avantages').addClassName('actif');
            $('btn_essentiel').removeClassName('actif');
        }
}

function checkBoutonAjouter(){
    var clickAjouter = true;
    
    for (var index = 0, len = oAllMontantNeo[iCurrentSousGamme][iCurrentDuree].length; index < len; index++) {
        if ((oAllMontantNeo[iCurrentSousGamme][iCurrentDuree][index].bHasPta == false) &&
        (oAllMontantNeo[iCurrentSousGamme][iCurrentDuree][index].fPrix != null)) {
            clickAjouter = false;
        }
    }
    
    if (clickAjouter) {
        if ($('bouton_ajouter').hasClassName('inactif')) {
            $('bouton_ajouter').removeClassName('inactif');
        }
        
        if (!btAjouterObserver) {
            btAjouterObserver = getCheckedForm;
            Event.observe("bouton_ajouter", "click", btAjouterObserver);
        }
        
        $('bouton_ajouter').setStyle({
            cursor: "pointer"
        });
    }
    else {
        if (!$('bouton_ajouter').hasClassName('inactif')) {
            $('bouton_ajouter').addClassName('inactif');
        }
        
        if (btAjouterObserver) {
            Event.stopObserving("bouton_ajouter", "click", btAjouterObserver);
            btAjouterObserver = null;
        }
        
    }
    
    return clickAjouter;
}

function checkRadio(){
    var bPtaDispo = checkBoutonAjouter();
	
    if (bPtaDispo == true) {
        if ($('choix_' + iCurrentDuree + '_' + checkEnCours)) {
            $('choix_' + iCurrentDuree + '_' + checkEnCours).checked = true;
        }
    }
}

function CreateElementAndName(sType, sName){
    var element = null;
    
    try {
        element = document.createElement('<' + sType + ' name="' + sName + '">');
    } 
    catch (e) {
    }
    
    if (!element || element.name.toLowerCase() != sName.toLowerCase()) {
        element = document.createElement(sType);
        element.setAttribute('name', sName);
    }
    
    return element;
}
