﻿// JScript File

var newLine = 1;

function Add(){
    document.getElementById("Reserve").style.display = "none";
    document.getElementById("Delete").style.opacity = 1;
    document.getElementById("Delete").style.filter = 'alpha\(opacity=100\)';
    maDiv = document.createElement("div");
    maDiv.id = "ligne_"+newLine;
    maDiv.className="ligne";
    maDiv.style.marginLeft = "13px"
    maDiv.style.marginTop = "5px"
    maDiv.style.width = "366px"
    maDiv.innerHTML = '<div class="item" style="width:14px;margin-top:5px;color:#9f9f9f;">'+(newLine+1)+'</div><div class="item" style="margin-left:5px;">Nom : <input type="text" name="nom_'+newLine+'" id="nom_'+newLine+'" style="width:100px;" /></div>\n<div class="item" style="margin-left:5px;">Prénom : <input type="text" name="prenom_'+newLine+'" id="prenom_'+newLine+'" style="width:100px;" /></div></div>';
    document.getElementById("CadreNom").appendChild(maDiv);
    newLine++;
    document.getElementById("nbBillet").value = newLine;
}

function Delete(){
    if(newLine > 1){
        document.getElementById("Reserve").style.display = "none";
        newLine--;
        document.getElementById("CadreNom").removeChild(document.getElementById("ligne_"+newLine));
        document.getElementById("nbBillet").value = newLine;
        if(newLine == 1){
            document.getElementById("Delete").style.opacity = 0.3;
            document.getElementById("Delete").style.filter = 'alpha\(opacity=30\)';
        }
    }
}

function AfficheTarif(val)
{
   var valid = true;

   if(document.getElementById("Tel_personne").value != ""){
   
        if(document.getElementById("Mail_personne").value == "" || document.getElementById("MailBis_personne").value == ""){
                valid = false;
                alert("Vous devez saisir votre adresse mail dans les 2 champs");
            }
            else{
                if(document.getElementById("Mail_personne").value != document.getElementById("MailBis_personne").value){
                    valid = false;
                    alert("Les 2 champs mail doivent être identiques");
                }
        }
        
        if(VerifNom() && valid){
            var total = val * newLine;
            var phraseTotal = "Total de la réservation : " + total + " €";
            document.getElementById("TotalHidden").value = total;
            document.getElementById("Reserve").style.display = "";
            document.getElementById("Total").innerHTML = phraseTotal;
        }
    }
    else
        alert("Veuillez saisir un numéro de téléphone pour la reservation");        
}

function VerifNom() {
    nb = document.getElementById("nbBillet").value;
    ok = true;
    for(i = 0 ; i < nb ; i++)
    {
        document.getElementById("nom_"+i).style.borderColor = "#000000";
        document.getElementById("prenom_"+i).style.borderColor = "#000000";
    
        if(document.getElementById("nom_"+i).value == ""){
            document.getElementById("nom_"+i).style.borderColor = "#ff0000";
            ok = false;
         }
         if(document.getElementById("prenom_"+i).value == ""){
            document.getElementById("prenom_"+i).style.borderColor = "#ff0000";
            ok = false;
         }
    }
    if(ok == false)
        alert("Veuillez remplir le nom et prénom de chaque personne");
        
    return ok;
}

function showSmooth()
{
    document.getElementById("SmootBoxMaison").style.display = "";
}

function HideSmoooth()
{
    document.getElementById("SmootBoxMaison").style.display = "none";
}

function getHorOlaizola()
{
    if(document.getElementById("lst_ville").value  == "0")
    {
        alert("Vous devez choisir un arrêt de départ");
    }
    else
    {
        SoapMethod = "POST";
        ajax.Start(AxgetHorOlaizola);
    }
}

var AxgetHorOlaizola = {
delay: 200,
prepare: function() {

   var arret = document.getElementById("lst_ville").value;
   var idExcu = "420";

   InputVar = new Array(arret, idExcu);
},
call: proxies.AjaxFunc.GetHorOlaizola,
finish: function(p) 
{   
    //alert(p);
    
    if(p == null)
    {
        alert("Cette réservation n'est plus disponible à ce jour");
    }
    
    var tab = p.split(",");
    var size = tab.length;
    size = size - 1;
    
    var tab2;
    var nomarret;
    var idarret;
    
    document.getElementById("hor_Anoeta_alle").options.length = 0;
    
    for(var i=0;i<size;i++)
    {
        tab2 = tab[i].split("|");
        nomarret = tab2[0];
        idarret = tab2[1];
        document.getElementById("hor_Anoeta_alle").options[i] = new Option(idarret, nomarret);
        document.getElementById("hor_Anoeta_alle").disabled = false;
    }
    
    
},
onException: ajax.alertException
};

