function comprovacioErrors(name)
{
    this.name = name
    this.sinerrores = true;
    this.comprovacioErrorsRadio = err_comprovacioErrorsRadio;
    this.comprovaPintatError = err_comprovaPintatError;
    this.comprovaPintatError_v2 = err_comprovaPintatError_v2;
    this.comprovaRestriccionsAmadeus = err_comprovaRestriccionsAmadeus;
    this.enviaForm = err_enviaForm;
    this.comprovacioErrorsCheckbox = err_comprovacioErrorsCheckbox;
    this.anclaName = "";
    
}

var msg = "";

function err_comprovaRestriccionsAmadeus(value, elementID, tipo,elementID2){   

    switch (tipo){
            case "A" :
                if (value > 54) {
                    try{
                        msg = "El nombre indicado excede el máximo de caracteres permitido por la compañía aérea, le aconsejamos introducir, en caso de nombre compuesto, el primer nombre y  primer apellido correctamente.\n\n";
                        document.getElementById(elementID).style.color = "white";                        
                        document.getElementById(elementID).style.backgroundColor= "red";
                        document.getElementById(elementID2).style.color = "white";                        
                        document.getElementById(elementID2).style.backgroundColor= "red";      
                        if (this.anclaName == "")
                            this.anclaName = "" + elementID + "";           
                    }catch(e){}
                        this.sinerrores = false;     
                }else{
                    try{
                        document.getElementById(elementID).style.color = "black";            
                        document.getElementById(elementID).style.backgroundColor= "white"; 
                        document.getElementById(elementID2).style.color = "black";                        
                        document.getElementById(elementID2).style.backgroundColor= "white";                  
                        }catch(e){}        
                }
                break;
                
            case "N" :
                if (value > 41) {
                    try{
                        msg = "El nombre indicado excede el máximo de caracteres permitido por la compañía aérea, le aconsejamos introducir, en caso de nombre compuesto, el primer nombre y  primer apellido correctamente.\n\n";
                        document.getElementById(elementID).style.color = "white";                        
                        document.getElementById(elementID).style.backgroundColor= "red";
                        document.getElementById(elementID2).style.color = "white";                        
                        document.getElementById(elementID2).style.backgroundColor= "red";      
                        if (this.anclaName == "")
                            this.anclaName = "" + elementID + "";           
                        }catch(e){}
                        this.sinerrores = false;  
                 }else{
                        try{
                            document.getElementById(elementID).style.color = "black";            
                            document.getElementById(elementID).style.backgroundColor= "white";
                            document.getElementById(elementID2).style.color = "black";                        
                        document.getElementById(elementID2).style.backgroundColor= "white";                   
                        }catch(e){}           
                 }
                 break;
                 
            case "B" :
                if (value > 40) {
                    try{
                        msg = "El nombre indicado excede el máximo de caracteres permitido por la compañía aérea, le aconsejamos introducir, en caso de nombre compuesto, el primer nombre y  primer apellido correctamente.\n\n";
                        document.getElementById(elementID).style.color = "white";                        
                        document.getElementById(elementID).style.backgroundColor= "red";
                        document.getElementById(elementID2).style.color = "white";                        
                        document.getElementById(elementID2).style.backgroundColor= "red";      
                        if (this.anclaName == "")
                            this.anclaName = "" + elementID + "";           
                    }catch(e){}
                    this.sinerrores = false; 
                }else{
                    try{
                        document.getElementById(elementID).style.color = "black";            
                        document.getElementById(elementID).style.backgroundColor= "white";
                        document.getElementById(elementID2).style.color = "black";                        
                        document.getElementById(elementID2).style.backgroundColor= "white";                   
                    }catch(e){}            
                }
                break;
                
            default :
                break;
     }       
}

function err_comprovaPintatError(value, elementID, errorValue){   
    //alert("formValue-->" + value);
    //alert("elementID-->" + elementID);
    //alert("errorValue-->" + errorValue);
    if (value == errorValue){      
       //alert(elementID + " entra con error (ponemos rojo)");
        try{
            document.getElementById(elementID).style.color = "white";                        
            document.getElementById(elementID).style.backgroundColor= "red";      
            if (this.anclaName == "")
                this.anclaName = "" + elementID + "";                       
        }catch(e){}
        this.sinerrores = false;             
    }else{
        try{
        //alert("entra sin error (ponemos bien...)");
        document.getElementById(elementID).style.color = "black";            
        document.getElementById(elementID).style.backgroundColor= "white";                   
        }catch(e){}
    }    
    
}
function err_comprovaPintatError_v2(formulario,value, elementID, errorValue, numPax){   
    //alert("formValue-->" + value);
    //alert("elementID-->" + elementID);
    //alert("errorValue-->" + errorValue);
    // JJC 13/05/2010 · Esto funciona en todos los navegadores
    // document.forms('reserva')['telefonoPax_0_0'].style.backgroundColor = "pink";
    if (value == errorValue){      
       //alert(elementID + " entra con error (ponemos rojo)");
        try{
            eval("document." + formulario + "." + elementID + ".style.color = 'white'");                        
            eval("document." + formulario + "." + elementID + ".style.backgroundColor = 'red'");                        
            //document.forms(formulario)[elementID].style.color = "white";                        
            //document.forms(formulario)[elementID].style.backgroundColor= "red";      
            if (this.anclaName == "")
                this.anclaName = elementID;           
            window.location.href = window.location.href + "#pax" + numPax;
        }catch(e){}
        this.sinerrores = false;             
    }else{
        try{
        //alert("entra sin error (ponemos bien...)");
        eval("document." + formulario + "." + elementID + ".style.color = 'black'");                        
        eval("document." + formulario + "." + elementID + ".style.backgroundColor = 'white'");                
        //document.forms(formulario)[elementID].style.color = "black";            
        //document.forms(formulario)[elementID].style.backgroundColor= "white";                   
        }catch(e){}
    }    
    
}

function err_comprovacioErrorsCheckbox(arra){
    for (i=0;i<arra.length;i++){
        var object = eval("document.getElementById('" + arra[i] + "')")
        if (object.checked == true)
            return true
    }
    return false
}

function err_comprovacioErrorsRadio(nomRadio){
    var object = eval(nomRadio)
    for (i=0;i<object.length;i++){
        if (object[i].checked == true)
            return true
    }
    return false
}


function err_enviaForm(nomForm){
    
    if (this.sinerrores){           
             try{
                eval("document." + nomForm + ".accion.value = '1'");
             }catch (e){};             
            eval("document." + nomForm + ".submit()")
        }
        else{            
            //alert("Hay uno o varios campos sin contestar. Por favor conteste a todo el cuestionario.")          
            alert(msg + "Se han producido errores en los campos introducidos. Por favor, revise los campos marcados en rojo. Gracias")
            window.location.href = "#" + this.anclaName + "";
        }    
}

/*function err_enviaForm_v2(nomForm, erroresSSFIBOS){
    if (erroresSSFIBOS != ""){ 
        this.sinerrores = false;
    }
    if (this.sinerrores){           
             try{
                eval("document." + nomForm + ".accion.value = '1'");
             }catch (e){};             
            eval("document." + nomForm + ".submit()")
        }
        else{            
            //alert("Hay uno o varios campos sin contestar. Por favor conteste a todo el cuestionario.")          
            alert(msg + "Se han producido errores en los campos introducidos. Por favor, revise los campos marcados en rojo. Gracias\r" + erroresSSFIBOS);
            window.location.href = "#" + this.anclaName + "";
        }    
}*/
    




