// Funciones a ejecutar en el submit
var funciones_someter_form = new Array();

//Variables Globales
var objG = null;

function someter_form(form, action) {
    var objForm = document.getElementById(form);
    var res = true;
    var len = funciones_someter_form.length;
    for (someter_form_i=0; someter_form_i<len; someter_form_i++) {
        eval("res = " + funciones_someter_form[someter_form_i] + "('" + form + "')");
        if (!res) {
            break;
        }
    }
    return res;
}

// Control de validacion de campos por JS
var obligatorios  = new Array();
var validaciones  = new Array();
var camposValidar = new Array();
var idForm        = null;

// Valida que los campos recibidos hayan sido rellenados
function validar_obligatorios(prefijo) {
    _prefijo = prefijo ? prefijo : 'campo';
    _prefijo = (_prefijo == 'null') ? '' : _prefijo;
    var i;
    var len = obligatorios.length;
    var res = true;
    var comprobar = false;      

    if (idForm != null){
    	var elementos = Array();
    	var f = document.getElementById(idForm);    	
    	for (i = 0; i < document.getElementById(idForm).elements.length; i++){
            elementos[i] = document.getElementById(idForm).elements[i].name;    		    		
        }
    }      

    for (i = 0; i < len; i++) {
        if(idForm != null && elementos != null){
            if (array_search(obligatorios[i], elementos) !== false) {
                comprobar = true;
            } else {
                comprobar = false;
            }
        } else {
            comprobar = true;
        }
    	if (comprobar) {
            objCampo = document.getElementById(_prefijo + obligatorios[i]);
            if (objCampo && !objCampo.value) {
                focoAlertObligatorio(obligatorios[i], prefijo);
                res = false;
                break;
            }
        }
    }
    return res;
}

// Valida que los campos recibidos hayan sido rellenados con los datos correctos
function validar_campos() {
    var res = true;

    if (camposValidar && camposValidar.length) {
        for (i in camposValidar) {
            res = valida(camposValidar[i][0], camposValidar[i][1], camposValidar[i][2]);
            if (!res) {
                break;
            }
        }
    }

    if (res && validaciones && validaciones.length) {
        for (i in validaciones) {
            eval('res = ' + validaciones[i] + '()');
            if (!res) {
                break;
            }
        }
    }
    return res;
}

function focoAlert(id, prefijo) {
    _prefijo = prefijo ? prefijo : 'campo';
    _prefijo = (_prefijo == 'null') ? '' : _prefijo;
    objCampo = document.getElementById(_prefijo + id);
    objLabel = document.getElementById('label' + id);
    var title = '';
    if (objLabel) {
        title = objLabel.title;
        if (!title) title = objLabel.innerHTML;
    } else {
        title = id;
    }
    alert(CAMPO + '"' + title + '"'+ ERRONEO);
    objCampo.focus();
}

function focoAlertObligatorio(id, prefijo) {
    _prefijo = prefijo ? prefijo : 'campo';
    _prefijo = (_prefijo == 'null') ? '' : _prefijo;
    objCampo = document.getElementById(_prefijo + id);
    objLabel = document.getElementById('label' + id);
    var title = '';
    if (objLabel) {
        title = objLabel.title;
        if (!title) title = objLabel.innerHTML;
    } else {
        title = id;
    }
    alert(CAMPO + '"' + title + '"'+ OBLIGATORIO);
    if (!objCampo.readOnly && (objCampo.type != 'select')) {
        objCampo.focus();
    }
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isDigit (c) {
    return ((c >= "0") && (c <= "9"))
}

function valida(id, checkOption, prefijo) {
    var myRe;
    var myArray = new Array();
    var security = true;
    _prefijo = prefijo ? prefijo : 'campo';
    _prefijo = (_prefijo == 'null') ? '' : _prefijo;
    var objCampo = document.getElementById(_prefijo + id);
    if (objCampo) {
        var value = objCampo.value;
        if (value != "") {
            switch(checkOption) {
                case 'INTEGER':
                    myRe = /^\-?[0-9]+$/g;
                    myArray = value.match(myRe);
                    if (myArray == null) {
                        security = false;
                    }
                break;
                case 'NUMERIC':
                    myRe = /^\-?[0-9]+[\.,]{0,1}[0-9]+$/g;
                    myArray = value.match(myRe);
                    if (myArray == null) {
                        security = false;
                    }
                break;
                case 'PRIMARYKEY':
                    myRe = /^\-?[0-9]+$/g;
                    myArray = value.match(myRe);
                    if (myArray == null || (value.length > 11) || (value.length <= 0)) {
                        security = false;
                    }
                break;
                case 'KEYWORD':
                    myRe = /^[_0-9a-zA-Z-]{2,}$/g;
                    myArray = value.match(myRe);
                    if (myArray == null) {
                        security = false;
                    }
                break;
                case 'TELEFONO':
                    myRe = /^[\+]?[0-9 \.\-]{9,}$/g;
                    if (value.match(myRe) == null) {
                        security = false;
                    }
                break;
                case 'CP':
                    myRe = /^[0-9]{2}[ \t\.\-]?[0-9]{3}$/g;
                    if (value.match(myRe) == null) {
                        security = false;
                    }
                break;
                case 'FECHA':
                    myRe = /^[0-9]{2,4}[/-][0-9]{2,4}[/-][0-9]{2,4}$/g;
                    if (value.match(myRe) == null) {
                        security = false;
                    }
                    if (!isFechaValida(value))  {
                        security = false;
                    }
                break;
                case 'EMAIL':
                    if (value.length > 255) {
                        security = false;
                    } else {
                        myRe = /^[_\-\.0-9a-zA-Z-]+@([\-0-9a-zA-Z]{1,}\.)+[\-a-zA-Z]{2,6}$/g;
                        if (value.match(myRe) == null) {
                            security = false;
                        }
                    }
                break;
                case 'CIF':
                    var v1 = Array(0, 2, 4, 6, 8, 1, 3, 5, 7, 9);
                    var temp = 0;
                    var i;
                    var control;
                    for (i = 2; i <= 6; i = i + 2) {
                        temp = temp + parseInt(v1[value.substr(i-1, 1)]);
                        temp = temp + parseInt(value.substr(i, 1));
                    }
                    temp    = temp + v1[value.substr(7, 1)];
                    temp    = (10 - (temp % 10));
                    temp    = String(temp);
                    temp    = temp.substr(temp.length - 1);
                    control = value.substr(value.length - 1);
                    control = control.toLowerCase();
                    control = (control == 'j') ? 0 : control;
                    if ((control != temp) || (value.length < 9)) {
                        security = false;
                    }
                break;
                case 'NIF':
                    if (value.length >= 8) {
                    	var letraControl;
                        var letras = new Array('T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E', 'T');
                        var dni = value.substr(0, value.length - 1);
                        //Protegemos para NIEs
                        dni = dni.replace(/X/g, "0");
                        dni = dni.replace(/Y/g, "1");
                        dni = dni.replace(/Z/g, "2");
                        dni = dni.replace(/K/g, "0");
                        dni = dni.replace(/L/g, "0");
                        dni = dni.replace(/M/g, "0");                        

                        dni = parseInt(dni);
                        var tmp = parseInt(dni) - parseInt(dni/23) * 23;
                        var res = letras[tmp];
                        letraControl = value.substr(value.length - 1);
                        if (letraControl){
                        	letraControl = letraControl.toUpperCase();
                        }
                        if (res != letraControl) {
                            security = false;
                        }
                    } else {
                        security = false;
                    }
                    // NIFs no legales
                    myRe = /^((00000001R)|(11111111H)|(22222222J)|(33333333P)|(44444444A)|(55555555K)|(66666666Q)|(77777777B)|(88888888Y)|(99999999R)|(01234567L)|(98765432M)|(12345678Z))$/g;
                    myArray = value.match(myRe);
                    if (myArray != null) {
                        security = false;
                    }
                break;
                case 'URL':
                    value = value.toLowerCase();
                    myRe = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/g;
                    if (value.match(myRe) == null) {
                        security = false;
                    }
                break;
                case 'TEXTAREA':
                case 'STRING':
                    if (typeof(value) != 'string') {
                        security = false;
                    }
                break;
                case 'HTML':
                break;
                default:
                    security = false;
                break;
            }

            if (!security) {
                focoAlert(id, prefijo);
            }
        }
    }
    return security;
}

function validaTfno(tfno) {
    var n
    var total = 0
    var ini = 0
    var min = 9

    if (tfno.charAt(0) == '+') {
        ini = 1
    }

    for (n = ini; n < tfno.length; n++) {
        car = tfno.charAt(n)
        if (es_digito(car)) {
            total++
        } else if ((car != ' ') && (car != '-')) {
            return false
        }
    }
    return (total >= min)
}

//Devuelve TRUE si el caracter es un digito
function es_digito(c) {
    if ((c.charCodeAt(0) >= "0".charCodeAt(0)) &&
        (c.charCodeAt(0) <= "9".charCodeAt(0))) {
        return true;
    } else {
        return false;
    }
}

function isFechaValida(value) {
    var ndia  = parseInt(value.substr(0,2), 10);
    var nmes  = parseInt(value.substr(3,2), 10);
    var nanyo = parseInt(value.substr(6,4), 10);
    var dias  = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    if (nanyo % 4 == 0 && nanyo % 400 != 0) {
        dias[1] = 29;
    }
    if (nmes >= 1 && nmes <= 12 && ndia >= 1 && ndia <= dias[nmes-1] ) {
        return true;
    }
    return false;
}

function validarFechayEstilo(campo) {
    var vFecha = campo.value;
	var nombreOK = campo.name + "OK";		
	var nombreKO = campo.name + "KO";
	
	var fechaValida = isFechaValida(vFecha);

	if(fechaValida){
		document.getElementById(nombreOK).style.display = "block";
		document.getElementById(nombreKO).style.display = "none";
		YAHOO.util.Dom.removeClass(campo,"error");
		return true;
	}else{
		document.getElementById(nombreKO).style.display = "block";
		document.getElementById(nombreOK).style.display = "none";
		YAHOO.util.Dom.addClass(campo,"error");
		return false;
	}		
}

function inputValueDefecto (idcampo,texto){
    var campo = document.getElementById(idcampo);
    if (campo && campo.value == "") {
    	campo.style.color = '#aaa';
    	campo.value = texto;
        campo.onfocus = function() {
        	if (campo.value == texto) {
        		campo.style.color = '#000';
                campo.value = '';
        	}
        }
    	campo.onblur = function() {
    		if (campo.value == "" && !campo.readOnly) {
    			campo.style.color = '#aaa';
    			campo.value = texto;
    		}
    	}
    	campo.form.onsubmit = function() {
        	if (campo.value == texto) {
                campo.value = '';
        	}
    	}
    }
}

function vaciarCampoDefecto (idcampo,texto){
    var campo = document.getElementById(idcampo);
	if (campo.value == texto) {
	    campo.value = '';
	}
}

function activaayuda(campo){
	id = campo.name + "ayuda";
	nomOK = campo.name + "OK";
	nomKO = campo.name + "KO";
	document.getElementById(nomOK).style.display = "none";
	document.getElementById(nomKO).style.display = "none";
	document.getElementById(id).style.display = "block";
}

function desactivaayuda(campo){
	id = campo.name + "ayuda";
    document.getElementById(id).style.display = "none";
}


//Comprueba que el campo no esté vacío y que no se haga otra comprovación a posteriori
function compruebacampovacio(campo,validar){
	if(campo){
		var val = campo.value;
		var nomOK = campo.name + "OK";
		var nomKO = campo.name + "KO";
		
		if((val!=null) && (val!="")){
			if(!validar){
				document.getElementById(nomOK).style.display = "block";
				document.getElementById(nomKO).style.display = "none";
				YAHOO.util.Dom.removeClass(campo,"error");
				if(document.getElementById(campo.name + "_checkOK")){
					document.getElementById(campo.name + "_checkOK").value=1;
				}
			}
		}else{
			document.getElementById(nomKO).style.display = "block";
			document.getElementById(nomOK).style.display = "none";				
			YAHOO.util.Dom.addClass(campo,"error");
		}
	}
}

//Define el estilo OK o KO del campo. Tipo se usa para campos especiales, p.e. tipo='radio'
//También es una especialización de la función compruebacampovacio para mostrar el 
//estilo en los campos rellenados por ajax
function compruebacampoform(nombrecampo, tipo) {
	campo = document.getElementById(nombrecampo);
	if (campo) {
		if (tipo=='radio'){
			if (campo.checked){
				mostrarestilocampo(campo, 'OK');
			} else {
				mostrarestilocampo(campo, 'KO');
			}
		} else {
			if (campo.value!=''){
				mostrarestilocampo(campo, 'OK');
			} else {
				mostrarestilocampo(campo, 'KO');
			}
		}
	}
}

//Muestra el estilo OK o KO del campo
function mostrarestilocampo(campo, estado) {
	var nombreOK = campo.name + "OK";
	var nombreKO = campo.name + "KO";
	if (estado=='OK') {
		document.getElementById(nombreOK).style.display = "block";
		document.getElementById(nombreKO).style.display = "none";
		YAHOO.util.Dom.removeClass(campo,"error");
	} else {
		document.getElementById(nombreKO).style.display = "block";
		document.getElementById(nombreOK).style.display = "none";				
		YAHOO.util.Dom.addClass(campo,"error");
	}
}

//Comprueba que el campo tiene la longitud mostrada
function compruebalongitud(campo,numero){
	if(campo){
		var longitud = campo.value.length;
		var nomOK = campo.name + "OK";
		var nomKO = campo.name + "KO";
		
		if(longitud==numero){
			document.getElementById(nomOK).style.display = "block";
			document.getElementById(nomKO).style.display = "none";
			YAHOO.util.Dom.removeClass(campo,"error");
		}else if(longitud>0){
			document.getElementById(nomKO).style.display = "block";
			document.getElementById(nomOK).style.display = "none";
			YAHOO.util.Dom.addClass(campo,"error");
		}
	}
}

//Control de Código postal genérico

function cpcomprobacion(e, campo) {
	var cp = document.getElementById(campo).name;
	var valorcp = document.getElementById(campo).value;
	var nomOK = cp + "OK";		
	var nomKO = cp + "KO";	
	var longitud = valorcp.length;
	objG = cp;
	if(cp && valorcp){		
        var url = urlCpCambiado + '&cp=' + valorcp;
        YAHOO.util.Connect.asyncRequest('GET', url, {success:_controlCP, failure:_muestraError});
	}else{
		document.getElementById(nomKO).style.display = "block";
		document.getElementById(nomOK).style.display = "none";
		YAHOO.util.Dom.addClass(campo,"error");
	}	
}

function _controlCP(o) {
    var nombre = objG;
    var nomKO = nombre + "KO";
	var nomOK = nombre + "OK";
    if (o.responseText !== undefined) {
        var resp = eval('(' + o.responseText + ')');
        if (resp == 'error') {
    		document.getElementById(nomKO).style.display = "block";
    		document.getElementById(nomOK).style.display = "none";
    		YAHOO.util.Dom.addClass(nombre,"error");
    		YAHOO.util.Dom.removeClass(nombre,"ok");
        } else {
    		document.getElementById(nomOK).style.display = "block";
    		document.getElementById(nomKO).style.display = "none";
    		YAHOO.util.Dom.addClass(nombre,"ok");
    		YAHOO.util.Dom.removeClass(nombre,"error");
    		if(document.getElementById(nombre + "_checkOK")){
    			document.getElementById(nombre + "_checkOK").value=1;
    		}
    		//YAHOO.util.Dom.removeClass(o,"error");
    		if(nombre=='cp'){
                setPoblaciones(resp['poblaciones'], resp['provincia']);
        		document.getElementById('poblacionOK').style.display = "block";
        		document.getElementById('poblacionKO').style.display = "none";
        		YAHOO.util.Dom.addClass(nombre,"ok");
        		YAHOO.util.Dom.removeClass(nombre,"error");
        		if(document.getElementById("poblacion_checkOK")){
        			document.getElementById("poblacion_checkOK").value=1;
        		}
    		}
        }
    }
}

function _muestraError() {
  alert(LBL_ERROR_CAMPO_ACTUAL);
}

function f_p_ventacomprobacion(e, camp) {
	var campo = YAHOO.util.Dom.get(camp);	
    var val = campo.value;
	var nomOK = campo.name + "OK";		
	var nomKO = campo.name + "KO";

    if (val.length == 10) {
        var dia = val.substr(0,2);
        var mes = val.substr(3,2);
        var anyo  = val.substr(6,4);
        var ndia  = parseInt(dia, 10);
        var nmes  = parseInt(mes, 10);
        var nanyo = parseInt(anyo, 10);
        var dias  = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
        if (nanyo % 4 == 0 && nanyo % 400 != 0) {
            dias[1] = 29;
        }

        if (nmes >= 1 && nmes <= 12 && ndia >= 1 && ndia <= dias[nmes-1] ) {
        	val = dia + "/" + mes + "/" + anyo;
        	
        	var hoy = compara_fecha_hoy(val);
        	var hoy_mas_ano = compara_fecha_hoy_mas_ano(val);
        	
        	if(hoy && hoy_mas_ano){
          		document.getElementById(nomOK).style.display = "block";
        		document.getElementById(nomKO).style.display = "none";
        		YAHOO.util.Dom.addClass(camp,"ok");
        		YAHOO.util.Dom.removeClass(camp,"error");
        		if(document.getElementById(campo.name + "_checkOK")){
        			document.getElementById(campo.name + "_checkOK").value=1;
        		}
        	}else{
          		document.getElementById(nomOK).style.display = "none";
        		document.getElementById(nomKO).style.display = "block";
        		YAHOO.util.Dom.addClass(camp,"error");
        		YAHOO.util.Dom.removeClass(camp,"ok");
        		if(document.getElementById(campo.name + "_checkOK")){
        			document.getElementById(campo.name + "_checkOK").value='';
        		}        		
        	}	
        } else {
    		document.getElementById(nomKO).style.display = "block";
    		document.getElementById(nomOK).style.display = "none"; 		
    		YAHOO.util.Dom.addClass(camp,"error");
    		YAHOO.util.Dom.removeClass(camp,"ok");
    		if(document.getElementById(campo.name + "_checkOK")){
    			document.getElementById(campo.name + "_checkOK").value='';
    		}      		
        }
    } else if (val) {
		document.getElementById(nomKO).style.display = "block";
		document.getElementById(nomOK).style.display = "none"; 		
		YAHOO.util.Dom.addClass(camp,"error");
		YAHOO.util.Dom.removeClass(camp,"ok");
		val = "";	
		if(document.getElementById(campo.name + "_checkOK")){
			document.getElementById(campo.name + "_checkOK").value='';
		}  		
    }
    return false;
}

//Función para controlar que solo se puedan insertar números en las cajas de texto.
function controlNoLetras(evento){
	var key;
	var keychar;
	
	if(window.event)
		key = window.event.keyCode;
	else if(evento)
		key = evento.which;
	else
		return true;
	
	keychar = String.fromCharCode(key);
	
	//control key
	if((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
		return true;
	//numbers
	else if((("0123456789").indexOf(keychar) > -1))
		return true;
	else
		return false;
}

function completar_nif(campo){
    var nif = campo.value;
	if (nif.length == 8) campo.value = '0' + nif; 
	return 1;
}

function validar_nif_nie_general(campo){
    var nif = campo.value;
    var retorno = false;
	var nomOK = campo.name + "OK";		
	var nomKO = campo.name + "KO";    
    
    retorno = validar_nif_nie(nif);

    if(retorno==1){
		document.getElementById(nomOK).style.display = "block";
		document.getElementById(nomKO).style.display = "none";
		YAHOO.util.Dom.removeClass(campo,"error");
		if(document.getElementById('nif_checkOK')){
			document.getElementById('nif_checkOK').value=1;
		}
    }else{
		document.getElementById(nomKO).style.display = "block";
		document.getElementById(nomOK).style.display = "none";
		YAHOO.util.Dom.addClass(campo,"error");
    }	
    	
}

function validamail_general(campo){
    var strEmail = campo.value;
    var retorno = false;
	var nomOK = campo.name + "OK";		
	var nomKO = campo.name + "KO";
	
	retorno = validamail(strEmail);
	
    if(retorno==1){
		document.getElementById(nomOK).style.display = "block";
		document.getElementById(nomKO).style.display = "none";
		YAHOO.util.Dom.removeClass(campo,"error");
		if(document.getElementById('email_checkOK')){
			document.getElementById('email_checkOK').value=1;
		}
		return 1;
    }else{
		document.getElementById(nomKO).style.display = "block";
		document.getElementById(nomOK).style.display = "none";
		YAHOO.util.Dom.addClass(campo,"error");
		if(document.getElementById('email_checkOK')){
			document.getElementById('email_checkOK').value='';
		}		
		return 0;
    }		
}

//Valida que los campos recibidos hayan sido rellenados
function validar_campos_obligatorios(formulario, campos_obligatorios) {
	var n;
	for (n = 0; n < campos_obligatorios.length; n++) {
		campo = campos_obligatorios[n]
		if (!obtenerValorCampos(formulario, campo)) {
			focoCampo(formulario, campo)
			return false
		}
	}
	return true
}

//Devuelve el "value" de un "input" en funcion de su tipo
//NOTA:	faltan tipos por definir
function obtenerValorCampos(formulario, campo) {
	var s
	if (input = formulario.elements[campo]) {
		if (input.type == undefined)
			tipo = formulario.elements[campo][0].type
		else
			tipo = input.type
		switch(tipo) {
			case "text":
			case "password":
			case "textarea":
			case "hidden":			return input.value
										break
			case "checkbox":		if (input.checked)
											return input.value
										break
			case "radio":			if (input.length) {
											for (s = 0; s < input.length; s++) {
												if (input[s].checked) {
													return input[s].value
												}
											}
										} else {
											return input.value
										}
										break
			case "select-one":	return input.options[input.selectedIndex].value
										break
			default: 			return false
		}
	} else {
		return false
	}
}

//Asigna el foco a un "input" teniendo en cuenta su tipo
//NOTA:	faltan casos por definir
function focoCampo(formulario, campo) {
	if (input = formulario.elements[campo]) {
		if (input.type == undefined)
			tipo = formulario.elements[campo][0].type
		else
			tipo = input.type
		switch (tipo) {
			case "radio":	if (input[0])
									input[0].focus()
								break;
			case "hidden": break;
			default:			input.focus()
		}
	} else {
		return false
	}
}

//Comprobar check de condiciones
function validar_acepto_condiciones() {
    var res = true;
    objAceptoCondiciones = YAHOO.util.Dom.get('acepto_condiciones');
    if (objAceptoCondiciones && !objAceptoCondiciones.checked){
        alert(LBL_ERROR_ACEPTO_CONDICIONES);
        res = false;
    }
    return res;
}

function mostrar(obj1, obj2){
	  if(obj1 != ""){
	    var el1 = document.getElementById(obj1);
	    if(el1){
	      el1.style.display = "block";
	    }
	  }
	  if(obj2 != ""){
	    var el2 = document.getElementById(obj2);
	    if(el2){
	      el2.style.display = "none";
	    }
	  }
	}

function compruebaExtensionFicheroImagen(form, campo){
    var valorFichero = campo.value;
    var retorno = false;
	var nomOK = campo.name + "OK";		
	var nomKO = campo.name + "KO";
	
	retorno = comprueba_extension_fichero_imagen(form, valorFichero);
	
    if(retorno==1){
		document.getElementById(nomOK).style.display = "block";
		document.getElementById(nomKO).style.display = "none";	
		YAHOO.util.Dom.removeClass(campo,"error");
		if(document.getElementById('fichero_oculto')){
			document.getElementById('fichero_oculto').value=1;
		}
    }else if(retorno==0){
		document.getElementById(nomKO).style.display = "block";
		document.getElementById(nomOK).style.display = "none";
		YAHOO.util.Dom.addClass(campo,"error");
    }else{
    	//Nada
    }			
}

function compruebaExtensionFicheroReclamacion(form, campo){
	var valorFichero = campo.value;
    var retorno = 0;
	var nomOK = campo.name + "OK";		
	var nomKO = campo.name + "KO";
	
	retorno = comprueba_extension_fichero_reclamacion(form, valorFichero);
	
    if(retorno==1){
		document.getElementById(nomOK).style.display = "block";
		document.getElementById(nomKO).style.display = "none";	
		YAHOO.util.Dom.removeClass(campo,"error");
		if(document.getElementById('fichero_oculto_rec')){
			document.getElementById('fichero_oculto_rec').value=1;
		}
    }else{
		document.getElementById(nomKO).style.display = "block";
		document.getElementById(nomOK).style.display = "none";
		YAHOO.util.Dom.addClass(campo,"error");
    }
    return retorno;
}

function comprueba_extension_fichero(formulario, archivo, extensiones) {
	   mierror = "";
	   if (!archivo) {
	       //Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario
		   //mierror = "No has seleccionado ningún archivo";
		   //Nada porque no es obligatorio
	   }else{
	      //recupero la extensión de este nombre de archivo
	      extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
	      //compruebo si la extensión está entre las permitidas
	      permitida = false;
	      for (var i = 0; i < extensiones.length; i++) {
	    	  if (extensiones[i] == extension) {
	        	 permitida = true;
	        	 break;
	    	  }
	      }
	      if (!permitida) {
	    	 //Extensión errónea
	    	  return 0;
	       }else{
	          //Correcto!
	    	   return 1;
	       }
	   }
	   //si estoy aqui es que no se ha podido submitir
	   //alert (mierror);
	}


function comprueba_extension_fichero_imagen(formulario, archivo) {
	extensiones_permitidas = new Array(".gif", ".jpg", ".png", ".bmp");
	return comprueba_extension_fichero(formulario, archivo, extensiones_permitidas);
}

function comprueba_extension_fichero_reclamacion(formulario, archivo) {
	extensiones_permitidas = new Array(".pdf", ".doc", ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".bmp", ".zip", ".rar");
	return comprueba_extension_fichero(formulario, archivo, extensiones_permitidas);
}

//Comparamos una fecha con la fecha de hoy
function compara_fecha_hoy(fpventa){
	var f = new Date();
	var hoy = f.getDate() + "/" + (f.getMonth() +1) + "/" + f.getFullYear();
		fpv=fpventa.split("/");
		now=hoy.split("/");
		if (parseInt(fpv[2],10) > parseInt(now[2],10)){
			    return true;
		}else{
		    if (parseInt(fpv[2],10) == parseInt(now[2],10)){
		    	if (parseInt(fpv[1],10) > parseInt(now[1],10)){
			    	return true;
		    	}
		    	else if (parseInt(fpv[1],10) == parseInt(now[1],10)){
		    		if (parseInt(fpv[0],10) >= parseInt(now[0],10)){
		    			return true;
		    		}else{
		    			return false;
		    		}
		    	}else{
			    	return false;
		    	}
			}else{
				return false;
			}
		}
}

//Comparamos una fecha con la fecha de hoy + 1 año
function compara_fecha_hoy_mas_ano(fpventa){
	var f = new Date();
	var hoy_mas_ano = f.getDate() + "/" + (f.getMonth() +1) + "/" + (f.getFullYear() +1);
		fpv=fpventa.split("/");
		now=hoy_mas_ano.split("/");
		if (parseInt(fpv[2],10) > parseInt(now[2],10)){
			    return false;
		}else{
		    if (parseInt(fpv[2],10) == parseInt(now[2],10)){
		    	if (parseInt(fpv[1],10) > parseInt(now[1],10)){
			    	return false;
		    	}
		    	else if (parseInt(fpv[1],10) == parseInt(now[1],10)){
		    		if (parseInt(fpv[0],10) > parseInt(now[0],10)){
		    			return false;
		    		}else{
		    			return true;
		    		}
		    	}else{
			    	return true;
		    	}
			}else{
				return true;
			}
		}
}

