


// CURSOS SOBRE BUTACA
function butaca_over(idSeat) {
    if (estaSeleccionado(idSeat)) {
    }
    else {
        var src_img=document.getElementById(idSeat);
        src_img.src='/images/compra_online/compra_numerada/butaca_amarilla.jpg';
    }
}

// CURSOR SALE DE BUTACA
function butaca_out(idSeat) {
    if (estaSeleccionado(idSeat)) {
    }
    else {
        var src_img = document.getElementById(idSeat);
        src_img.src='/images/compra_online/compra_numerada/butaca_verde.jpg';
    }
}
//SELECCIONO BUTACA
function butaca_select(idSeat) {
    var seleleccionado = estaSeleccionado(idSeat)
    if(cantidadSeleccionada() < document.getElementById('cantidad').value ){
         var src_img=document.getElementById(idSeat);
         src_img.src='/images/compra_online/compra_numerada/butaca_azul.jpg';
         //alert("seleccionado "+seleleccionado);
         if(seleleccionado){
             quitarButacaASeleccion(idSeat);
         }
         else{
             agregarButacaASeleccion(idSeat);
         }
    }
    else{
        quitarButacaASeleccion(idSeat);	
    }
}

function quitarButacaASeleccion(idSeat){
    var seleccionados = document.getElementById("seleccionados").value;
    var seleccion = seleccionados.split('//');
    document.getElementById("seleccionados").value = "";
    var count = 0;
    
    for(var i=0;seleccion.length>i;i++){
        if(count == 0){
            if(seleccion[i] != idSeat){
                document.getElementById("seleccionados").value = seleccion[i];			
            }
        }else{
            if(seleccion[i] != idSeat){
                document.getElementById("seleccionados").value = document.getElementById("seleccionados").value +"//"+ seleccion[i];			
            }
        }
        count++;
    }
}

function agregarButacaASeleccion(idSeat){
    document.getElementById("seleccionados").value = document.getElementById("seleccionados").value +"//"+ idSeat;
}

function estaSeleccionado(idSeat){
    var seleccionados = document.getElementById("seleccionados").value;
    var seleccion = seleccionados.split('//');
    
    for(var i=0;seleccion.length>i;i++){
        //alert('seleccion['+i+']'+seleccion[i] );
        if(seleccion[i] == idSeat){
            //alert('idSeat '+idSeat+' existe');
            return true;
        }
    }
    
    //alert('idSeat '+idSeat+' no  existe');
    return false;
}

function limpiar(){
    var seleccionados = document.getElementById("seleccionados").value;
    var seleccion = seleccionados.split('//');
    
    for(var i=0;seleccion.length>i;i++){
        if(seleccion[i]!=''){
            var src_img=document.getElementById(seleccion[i]);
            src_img.src='compra_online/compra_numerada/butaca_gris.jpg';
        }
    }
    
    document.getElementById("seleccionados").value = "";
}

function cantidadSeleccionada(){
    var seleccionados = document.getElementById("seleccionados").value;
    var seleccion = seleccionados.split('//');
    return seleccion.length-1;
}

function elementoExiste(id){
    if(document.getElementById(''+id)){
            return true;
    }
    else{
            return false;
    }
}

function enviarFormSeleccionButaca(){
    var seleccionados = document.getElementById("seleccionados").value;
    var seleccion = seleccionados.split('//');
    var cantidadSeleccionada = seleccion.length-1;
    
    if( cantidadSeleccionada < document.getElementById('cantidad').value ){
        alert('Debe seleccionar '+document.getElementById('cantidad').value+' butacas');
    }
    else if( cantidadSeleccionada > document.getElementById('cantidad').value ){
        alert('Debe seleccionar todas las butacas');
    }
    else if( cantidadSeleccionada == document.getElementById('cantidad').value ){
        document.getElementById('sala_form').submit();
    }
}
