// Archivo JScript.
/* Desmarcar. */
function desmarcar()
{
	var listado = document.getElementById("tx_responsables");
    var i
    for (i=0;i<listado.length;i++)
    {
    	if (listado[i].selected)
    	{
    		listado[i].selected = false;
    	}
    }
}

/* Cambiar importe. */
function cambiarImporte(medio)
{
	var i;
	var j;
	var listado = document.getElementsByName(medio);
	var formaPago = document.getElementsByName('tipo');
	for(i=0;i<listado.length;i++)
	{
		if(listado[i].checked)
		{
			break;
		}
	}
	for(j=0;j<formaPago.length;j++)
	{
		if(formaPago[j].checked)
		{
			break;
		}
	}
	var valor = listado[i].value;
	var forma = formaPago[j].value;
	window.location = "suscripciones.php?cambio=1&t="+valor+"&f="+forma;
}

/* Cambiar pago. */
function cambiarPago()
{
	var j;
	var formaPago = document.getElementsByName('tipo');
	for(j=0;j<formaPago.length;j++)
	{
		if(formaPago[j].checked)
			break;
	}
	var forma = formaPago[j].value;
	window.location = "suscripciones.php?pago=1&f="+forma;
}

/* Cambiar edicion. */
function cambiarEdicion(id_medio, c_fecha)
{
	var edicion = $('#descarga_edicion').val();
	var portada = $('#descarga_portada').val();
	var tmp_fec = $('#fecha_descarga_portada').val();
	var tmp_fec2 = $('#fecha_descarga_edicion').val();
	$('#idpde').val(id_medio);
	$('#ee').val(edicion);
	$('#pe').val(portada);
	$('#fecha_descarga_portadae').val(tmp_fec);
	$('#fecha_descarga_edicione').val(tmp_fec2);
	$('#tipo_seleccione').val("edicion");
	$('#c_fe').val(c_fecha);
	$('#cambiaEdicion').submit();
}

/* Cambiar portada. */
function cambiarPortada(id_medio, c_fecha)
{
	var edicion = $('#descarga_edicion').val();
	var portada = $('#descarga_portada').val();
	var tmp_fec = $('#fecha_descarga_portada').val();
	var tmp_fec2 = $('#fecha_descarga_edicion').val();
	$('#idpdp').val(id_medio);
	$('#ep').val(edicion);
	$('#pp').val(portada);
	$('#fecha_descarga_portadap').val(tmp_fec);
	$('#fecha_descarga_edicionp').val(tmp_fec2);
	$('#tipo_seleccionp').val("portada");
	$('#c_fp').val(c_fecha);
	$('#cambiaPortada').submit();
}

/* Cambiar edicion. */
function cambiarEdicion_2(id_medio)
{
	//var fechaPortada = document.getElementById('fecha_descarga_portada').value;
	var edicion = $('#descarga_edicion').val();
	var portada = $('#descarga_portada').val();
	window.location = "indexLocal.php?idpd="+id_medio+"&e="+edicion+"&p="+portada;
}

/* Accion portada. */
function accionPortada()
{
	var edicion = $('#descarga_edicion').val();
	var tmp_fec2 = $('#fecha_descarga_edicion').val();
	$('#fecha_descarga_edicionp_sb').val(tmp_fec2);
	$('#descarga_edicionp_sb').val(edicion);
	$('#tipo_seleccionp_sb').val("portada");
	return true;
}

/* Accion edicion. */
function accionEdicion()
{
	/*var login = estaLogado();
	if(login)
	{*/
		var portada = $('#descarga_portada').val();
		var tmp_fec = $('#fecha_descarga_portada').val();
		$('#fecha_descarga_portadae_sb').val(tmp_fec);
		$('#descarga_portadae_sb').val(portada);
		$('#tipo_seleccione_sb').val("edicion");
		/* return true; */
		return submitAction('desc_edi', 'indexLocal.php?enviado=1', false);
	/*}
	else
	{
		// Saco el alert().
	}*/
}

/* Esta Logado. */
/*function estaLogado(idDivDesc)
{
	// Edicion.
	tmp = document.getElementById('descarga_edicion');
	var edicion = tmp.value;
	index = tmp.selectedIndex;
	var tx_edicion = tmp.options[index].text;
	// Llamada.
	var parametros = {f:fecha,e:edicion};
	var data = jsonPostCall("ajax/Check.Login.ajax.php", parametros);
	var ok = false;
	if ( ( data != "" ) && ( data != undefined ) )
	{
		if(!IsEmpty(data.resultado) && (data.resultado == 'ok'))
		{
			
		}
	}
	return false;
}*/

/* Nuevo Cobro. */
function NuevoCobro()
{
    IdPedido();               
}

/* Id pedido. */
function IdPedido()
{        
    var pedido = document.getElementById('txtPedido');
    if(pedido)
    {
        var fecha=new Date();
        var diames=fecha.getDate();     
        var mes=fecha.getMonth();
        var ano=fecha.getYear();
        var hora=fecha.getHours();
        var min=fecha.getMinutes();
        var sec=fecha.getSeconds();
        var mill=fecha.getMilliseconds();
        pedido.value = diames;
        pedido.value += mes;
        //pedido.value += ano;
        pedido.value += hora;
        pedido.value += min;
        pedido.value += sec;
        //pedido.value += mill;  	
    }
}

/* Abrir formulario. */
function AbrirFrm(mylink, windowname, w, h)
{
    if (! window.focus)
    {
    	return true;
    }
    var href;
    if (typeof(mylink) == 'string')
    {
       href=mylink;
    }
    else
    {
       href=mylink.href;
    }
    window.open(href, windowname, 'width=' + w + ',height=' + h + ',scrollbars=no,directories=no,resizable=no,status=no,top=300,left=300');
}

/**
 * Funcion encargada de mostrar el div con el id pasado como parámetro a la función.
 * @param idDivImg
 * @return
 */
function showDivImg(idDivImg)
{
	if($("#" + idDivImg))
	{
		$("#" + idDivImg).show();
	}
}

/**
 * Funcion encargada de ocultar el div con el id pasado como parámetro a la función.
 * @param idDivImg
 * @return
 */
function hideDivImg(idDivImg)
{
	if($("#" + idDivImg))
	{
		$("#" + idDivImg).hide();
	}
}

/* Hago llamada por POST y JSON. */
function jsonPostCall(url, parametros)
{
	var devv = "";
	if(parametros && (parametros != "") && url && (url != ""))
	{
	    $.ajax({
			url: url,
			type: "POST",
			data: parametros,
			async: false,
			dataType: "json",
			success: function(data){
				devv = data;
			},
			error: function(data){
			}
	    }).responseText;
	}
    return devv;
}

/* Hago llamada por POST y JSON. */
function jsonPostCallForm(url, parametros, formulario)
{
	var devx = "";
	if(parametros && (parametros != "") 
		&& url && (url != "") 
		&& formulario && (formulario != ""))
	{
		var urlTmp = "" + url;
		if(parametros && (parametros != ""))
		{
			urlTmp += "?" + parametros;
		}
		var datos = serializeForm(formulario);
	    $.ajax({
			url: urlTmp,
			type: "POST",
			data: datos,
			async: false,
			dataType: "json",
			success: function(data){
				devx = data;
			},
			error: function(data){
			}
	    }).responseText;
	}
    return devx;
}

/* Serializo el formulario para pasarlo por la URL. */
function serializeForm()
{
	return $("#" + idFormulario).serialize();
}

/* Deshabilito las teclas de ESC y Enter. */
function deshabilitaTeclaESC_Enter()
{
	$(document).keyup(function(e) { 
	    if (e.which == 13) { return false; }  // enter.
	    if (e.which == 27) { return false; }  // esc.
	});
}

function submitAction(form_id, pagina, hagoSubmit)
{
	var formu = document.getElementById(form_id);
	if(formu != undefined)
	{
		formu.action = pagina;
		if(hagoSubmit)
		{
			formu.submit();
		}
		return true;
	}
	else
	{
		return false;
	}
}

/* Descarga edicion. */
function descargaEdicion(idDivDesc, idDivNoDesc, idDivIn)
{
	/* Fecha. */
	var tmp = $('#fecha_descarga_edicion');
	var fecha = tmp.val();
	var index = tmp[0].selectedIndex;
	var tx_fecha = tmp[0].options[index].text;
	/* Edicion. */
	tmp = $('#descarga_edicion');
	var edicion = tmp.val();
	index = tmp[0].selectedIndex;
	var tx_edicion = tmp[0].options[index].text;
	/* Llamada. */
	var parametros = {f:fecha,e:edicion};
	var data = jsonPostCall("ajax/Descarga.Edicion.ajax.php", parametros);
	var ok = false;
	if ( ( data != "" ) && ( data != undefined ) )
	{
		if(!IsEmpty(data.resultado) && (data.resultado == 'ok'))
		{
			if(!IsEmpty(data.numDescargas))
			{
				var numDescargas = data.numDescargas;
				if(isNumber(numDescargas) && (numDescargas > 0))
				{
					if(!IsEmpty(data.di) && (data.di == 'ok'))
					{
						if(!IsEmpty(data.numDescargas))
						{
							var accionNO = function() {
								$("#iframe_id4").hide();
								$( this ).dialog("close");
							};
							var accionSi = function() {
								$("#iframe_id4").hide();
								$( this ).dialog("close");
								$('#acDesc_e').val("1");
								submitAction('desc_edi', 'indexLocal.php?enviado=1', true);
								/*document.getElementById('desc_edi').submit();*/
							};
							var txt_d = data.txt;
							if(typeof(idDivIn_Tmp) != "undefined")
							{
								tmp = idDivIn_Tmp;
							}
							else
							{
								tmp = $("#"+idDivIn+"_p").html();
								idDivIn_Tmp = tmp;
							}
							tmp = tmp.replace("%s", numDescargas);
							tmp = tmp.replace("%s", txt_d);
							$("#"+idDivIn+"_p").html(tmp);
							$("#iframe_id4").show();
							displayConfirmDialog(idDivIn+"_div", accionNO, accionSi, "", "", 170);
							ok = true;
						}
					}
					else
					{
						var accionNO = function() {
							$("#iframe_id4").hide();
							$( this ).dialog("close");
						};
						var accionSi = function() {
							$("#iframe_id4").hide();
							$( this ).dialog("close");
							$('#acDesc_e').val("1");
							submitAction('desc_edi', 'indexLocal.php?enviado=1', true);
							/* document.getElementById('desc_edi').submit(); */
						};
						if(typeof(idDivDesc_Tmp) != "undefined")
						{
							tmp = idDivDesc_Tmp;
						}
						else
						{
							tmp = $("#"+idDivDesc+"_p").html();
							idDivDesc_Tmp = tmp;
						}
						tmp = tmp.replace("%s", numDescargas);
						tmp = tmp.replace("%s", tx_edicion);
						tmp = tmp.replace("%s", tx_fecha);
						$("#"+idDivDesc+"_p").html(tmp);
						$("#iframe_id4").show();
						displayConfirmDialog(idDivDesc+"_div", accionNO, accionSi, "", 370, 160);
						ok = true;
					}
				}
			}
		}
	}
	if(!ok)
	{
		var accionAceptar = function() {
			$("#iframe_id4").hide();
			$( this ).dialog("close");
		};
		if(typeof(idDivNoDesc_Tmp) != "undefined")
		{
			tmp = idDivNoDesc_Tmp;
		}
		else
		{
			tmp = $("#"+idDivNoDesc+"_p").html();
			idDivNoDesc_Tmp = tmp;
		}
		var txt_sop = "";
		if(!IsEmpty(data.mail_sop))
		{
			txt_sop = data.mail_sop;
			var name_sop = "";
			if(!IsEmpty(data.name_sop))
			{
				name_sop = data.name_sop;
			}
			else
			{
				name_sop = txt_sop;
			}
			txt_sop = "<a href='mailto: "+txt_sop+"'>"+name_sop+"</a>";
		}
		tmp = tmp.replace("%s", tx_edicion);
		tmp = tmp.replace("%s", tx_fecha);
		tmp = tmp.replace("%s", txt_sop);
		$("#"+idDivNoDesc+"_p").html(tmp);
		$("#iframe_id4").show();
		displayAlertDialog(idDivNoDesc+"_div", accionAceptar, "", 400, 216);
	}
	return false;
}

/* Es un numero. */
function isNumber(n)
{
	return !isNaN(parseFloat(n)) && isFinite(n);
}

/* Muestra 'LightBox' o ventana de confirmación generico. */
function displayConfirmDialogGen(idDiv, txt_accionNo, accionNo, txt_accionSi, accionSi, accionAbrir, width, height)
{
	/* Nombre de la funcion a ejecutar al cargar la ventana de confirmacion o 'LightBox'. */
	/* var accionAbrir = "funcion('param')"; */
	var widthV = 360;
	if (width)
	{
		widthV = width;
	}
	var heightV = 150;
	if (height)
	{
		heightV = height;
	}
	if($("#dialog:ui-dialog") && $("#dialog:ui-dialog").dialog)
	{
		$("#dialog:ui-dialog").dialog("destroy");
	}
	var botones = {
	};
	botones[txt_accionNo] = accionNo;
	botones[txt_accionSi] = accionSi;
	$("#"+idDiv).dialog({
		resizable: false,
		height:heightV,
		maxHeight:heightV,
		closeOnEscape: false,
		width:widthV,
		maxWidth:widthV,
		modal: true,
		buttons: botones,
		open: function(event, ui) {
			$(".ui-dialog-titlebar-close", $(this).parent()).hide();
			if (accionAbrir && (accionAbrir != ""))
			{
				eval(accionAbrir);
			}
		}
	});
}

/* Muestra 'LightBox' o ventana de alert, alerta Generico. */
function displayAlertDialogGen(idDiv, txt_accionAceptar, accionAceptar, accionAbrir, width, height)
{
	var widthV = 330;
	if (width)
	{
		widthV = width;
	}
	var heightV = 150;
	if (height)
	{
		heightV = height;
	}
	$(function() {
		if($("#dialog:ui-dialog") && $("#dialog:ui-dialog").dialog)
		{
			$("#dialog:ui-dialog").dialog("destroy");
		}
		var botones = {
		};
		botones[txt_accionAceptar] = accionAceptar;
		$("#"+idDiv+"").dialog({
			resizable: false,
			height:heightV,
			maxHeight:heightV,
			closeOnEscape: false,
			width:widthV,
			maxWidth:widthV,
			modal: true,
			buttons: botones,
			open: function(event, ui) {
				/* Oculto el boton de Cerrar. */
				$(".ui-dialog-titlebar-close", $(this).parent()).hide();
				if (accionAbrir && (accionAbrir != ""))
				{
					eval(accionAbrir);
				}
			}
		});
	});
}

/* Muestra Info. */
function muestraInfoLogin(idDiv)
{
	var accionAceptar = function() {
		$("#iframe_id3").hide();
		$( this ).dialog("close");
	};
	$("#iframe_id3").show();
	displayAlertDialog(idDiv, accionAceptar);
}

/* Muestra Info para Finalizar. */
function muestraInfoFinalizar(idDiv)
{
	var accionAceptar = function() {
		$("#iframe_id").hide();
		$(this).dialog("close");
		/* Submito el formulario */
		submitFormFinalizar();
	};
	$("#iframe_id").show();
	displayAlertDialogFinalizar(idDiv, accionAceptar);
}

/* Submite Formulario para Finalizar. */
function submitFormFinalizar()
{
	return submitAction('id_form_finalizar', 'transferencia_bancaria.php?enviado=1', true);
}

/* Muestra Info. */
function muestraConfirmCarr(idDiv)
{
	var accionSeg = function() {
		$("#iframe_id").hide();
		$( this ).dialog("close");
	};
	var accionCarr = function() {
		$("#iframe_id").hide();
		$( this ).dialog("close");
		document.getElementById('carrito').submit();
	};
	$("#iframe_id").show();
	display_CD_Carr(idDiv, accionSeg, accionCarr);
}

/* Muestra 'LightBox' o ventana de confirmación. */
function displayConfirmDialog(idDiv, accionNo, accionSi, accionAbrir, width, height)
{
	var txt_accionSi = "Si";
	var txt_accionNo = "No";
	displayConfirmDialogGen(idDiv, txt_accionNo, accionNo, txt_accionSi, accionSi, accionAbrir, width, height);
}

/* Muestra 'LightBox' o ventana de confirmación. */
function display_CD_Carr(idDiv, accionSeg, accionCarr, accionAbrir, width, height)
{
	var txt_accionSeg = "Seguir comprando";
	var txt_accionCarr = "Ir al carrito";
	displayConfirmDialogGen(idDiv, txt_accionSeg, accionSeg, txt_accionCarr, accionCarr, accionAbrir, width, height);
}

/* Muestra 'LightBox' o ventana de confirmación. */
function display_CD_Registro(idDiv, accionQui, accionCan, accionAbrir, width, height)
{
	var txt_accionQui = "Quiero registrarme";
	var txt_accionCan = "Cancelar";
	displayConfirmDialogGen(idDiv, txt_accionCan, accionCan, txt_accionQui, accionQui, accionAbrir, width, height);
}

/* Muestra 'LightBox' o ventana de alert, alerta. */
function displayAlertDialog(idDiv, accionAceptar, accionAbrir, width, height)
{
	var txt_accionAceptar = "Aceptar";
	displayAlertDialogGen(idDiv, txt_accionAceptar, accionAceptar, accionAbrir, width, height);
}

/* Muestra 'LightBox' o ventana de alert, alerta. Finalizar. */
function displayAlertDialogFinalizar(idDiv, accionAceptar, accionAbrir, width, height)
{
	var txt_accionAceptar = "Finalizar";
	displayAlertDialogGen(idDiv, txt_accionAceptar, accionAceptar, accionAbrir, width, height);
}

/* Funcion que valida que el texto pasado es vacia. */
function IsEmpty(aText)
{
	if(!aText || (aText == null) || (aText == undefined) 
			|| (aText == "") || (aText.length == 0))
	{
		return true;
	}
	else
	{
		return false;
	}
}

/* Actualiza el Importe de la Cesta. */
function actualizaImporteCesta(id, sp)
{
	/* Importe. */
	var valor = getImporte(id);
	if(!IsEmpty(valor))
	{
		document.getElementById(sp).innerHTML = valor;
	}
	/* Total. */
	var id_tmp = id.split("_");
	document.getElementById("tot_imp").innerHTML = totalImporteCesta(""+id_tmp[0]+"_");
}

/* Actualiza el Importe de la Cesta. */
function getImporte(id)
{
	var idCombo = document.getElementById(id).value;
	var idImp = "h_"+id+"_"+idCombo;
	return document.getElementById(idImp).value;
}

/* Actualiza el Importe de la Cesta. */
function totalImporteCesta(id)
{
	var total = 0;
	var eltos = $("*[id^='"+id+"']").each(function() {
		total += parseFloat(getImporte(this.id));
	});
	return total.toFixed(2);
}

/* Quitar bloqueo. */
function quitarBloqueo()
{
	/* document.getElementById("div_bloqueador_1").classname = ''; */
	/* document.getElementById("div_bloqueador_1").style.display = 'none'; */
}

/* Poner bloqueo. */
function ponerBloqueo()
{
	document.getElementById("div_bloqueador_1").style.display = 'inline';
}

/* Desc_1. */
function descLP(n)
{
	var formu = document.getElementById("form1");
	if(formu != undefined)
	{
		formu.enviar.value = 1;
		formu.num.value = n;
		formu.action = "download.php";
		/* formu.submit(); */
		
		/* Oculto el botón. */
		var botonD = document.getElementById("btnDescargar"+n);
		botonD.style.display = "none";
		
		return true;
	}
	else
	{
		return false;
	}
}

/* Desc_2. */
function descLPs(n)
{
	var formu = document.getElementById("form1");
	if(formu != undefined)
	{
		formu.enviar.value = 1;
		formu.num.value = n;
		formu.action = "downloadS.php";
		/* formu.submit(); */
		
		/* Oculto el botón. */
		var botonD = document.getElementById("btnDescargar"+n);
		botonD.style.display = "none";
		
		return true;
	}
	else
	{
		return false;
	}
}

/* Muestra Info registro en el Sistema. */
function alertInfoRegistro(idDiv, url)
{
	if($("#dialog:ui-dialog") && $("#dialog:ui-dialog").dialog)
	{
		var accionCan = function() {
			$("#iframe_id2").hide();
			$( this ).dialog("close");
		};
		var accionQui = function() {
			$("#iframe_id2").hide();
			$( this ).dialog("close");
			location.href = url;
		};
		$("#iframe_id2").show();
		display_CD_Registro(idDiv, accionQui, accionCan);
	}
}

/* Edito. */
function isEditableU(id)
{
	/* Llamada. */
	var parametros = {id:id};
	var data = jsonPostCall("../ajax/ListadoUsuarios.CheckEdit.ajax.php", parametros);
	var resultado = false;
	if ( ( data != "" ) && ( data != undefined ) )
	{
		if(!IsEmpty(data.resultado) && (data.resultado == 'ok'))
		{
			resultado = true;
		}
	}
	return resultado;
}

/* 'Devuelve' the value of the radio button that is checked
'devuelve' an empty string if none are checked, or
there are no radio buttons. */
function getCheckedValue(radioObj)
{
	if(!radioObj)
	{
		return "";
	}
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		if(radioObj.checked)
		{
			return radioObj.value;
		}
		else
		{
			return "";
		}
	}
	for(var i = 0; i < radioLength; i++)
	{
		if(radioObj[i].checked)
		{
			return radioObj[i].value;
		}
	}
	return "";
}

/* Descarga de los Pdfs en caso de que se haya producido algún error. */
function descDocE(n)
{
	var formu = document.getElementById("form"+n);
	if(formu != undefined)
	{
		formu.enviar.value = 1;
		formu.num.value = n;
		/* Compongo la Url con los parámetros. */
		var urlForm = "descargas_perfil.php";
		/* ini Params. */
			var tmp = document.getElementById("dt_ffin");
				urlForm += "?dt_ffin="+tmp.value;
			tmp = document.getElementById("dt_fini");
				urlForm += "&dt_fini="+tmp.value;
			tmp = document.getElementById("orden");
				urlForm += "&orden="+tmp.value;
			tmp = document.getElementById("pg");
				urlForm += "&pg="+tmp.value;
			var formular = document.getElementById("formulario_descarga");
			tmp = getCheckedValue(formular.radio);
				urlForm += "&radio="+tmp;
		formu.action = urlForm;
		
		/* Oculto el botón. */
		var botonD = document.getElementById("btnDescargar"+n);
		botonD.style.display = "none";
		
		/* fin Params. */
		return true;
	}
	else
	{
		return false;
	}
}

/**
 * Funcion que valida si una Fecha con el formato dd/mm/aaaa es correcta.
 * @return
 */
function fechaValidaFormato1(Cadena)
{
	/* Crea un string. */
	var Fecha = new String(Cadena);
	/* Cadena Año. */
	var Ano = new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
    /* Cadena Mes. */
    var Mes = new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
    /* Cadena Día. */
    var Dia = new String(Fecha.substring(0,Fecha.indexOf("/")));	
	   
	/* Valido el año. */
	if (isNaN(Ano) || Ano.length < 4 || parseFloat(Ano) < 1900)
	{  
		return false;
	}  
	/* Valido el Mes. */
	if (isNaN(Mes) || parseFloat(Mes) < 1 || parseFloat(Mes) > 12)
	{
		return false;
	}  
    /* Valido el Dia. */
    if (isNaN(Dia) || parseInt(Dia, 10) < 1 || parseInt(Dia, 10) > 31)
	 {
        return false;
    }  
    if (Mes == 4 || Mes == 6 || Mes == 9 || Mes == 11 || Mes == 2)
	 {
        if (Mes == 2 && Dia > 28 || Dia > 30)
		 {
            return false;
        }  
    } 
	
	return true;
}

/**
 * Funcion que devuelve la fecha en formato ISO.
 * @return
 */
function fechaFormatoIso(Cadena)
{
	/* Crea un string. */
	var Fecha = new String(Cadena);
	/* Cadena Año. */
	var Ano = new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
    /* Cadena Mes. */
    var Mes = new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
    /* Cadena Día. */
    var Dia = new String(Fecha.substring(0,Fecha.indexOf("/")));	
	   
	return Ano+"-"+Mes+"-"+Dia;
}

/**
 * Funcion que valida si una Fecha cumple con el patrón ('dd/mm/aaaa').
 * @return
 */
function checkFormatoFecha1(texto)
{
	var re1 = new RegExp("^[0-3][0-9]/[0-1][0-9]/[0-9][0-9][0-9][0-9]$");
	var res1 = texto.match(re1);
	
	if ( res1 )
	{
		if ( fechaValidaFormato1(texto) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

function compruebaFactura()
{
	var error = false;
	
	/* Oculto el mensaje de error del servidor. */
	hideDivImg("id_listado_errores");
	
	/* Comprobaciones. */
	var medio = document.getElementById("medio");
	if(!medio || (medio.value == "") || (medio.value.length < 1))
	{
		error = true;
		alert("El campo Medio es obligatorio.");
	}
	
	var fini = document.getElementById("dt_fini");
	var errfini = false;
	if(!error && (!fini || (fini.value == "") || (fini.value.length < 1)))
	{
		errfini = true;
		error = true;
		alert("La fecha inicial del Período a Facturar es un campo obligatorio.");
	}
	else
	{
		if(!error && !checkFormatoFecha1(fini.value))
		{
			error = true;
			alert("La fecha inicial del Período a Facturar no es correcta. El formato correcto es: 'dd/mm/aaaa'.");
		}
	}
	
	var ffin = document.getElementById("dt_ffin");
	var errffin = false;
	if(!error && (!ffin || (ffin.value == "") || (ffin.value.length < 1)))
	{
		errffin = true;
		error = true;
		alert("La fecha final del Período a Facturar es un campo obligatorio.");
	}
	else
	{
		if(!error && !checkFormatoFecha1(ffin.value))
		{
			error = true;
			alert("La fecha final del Período a Facturar no es correcta. El formato correcto es: 'dd/mm/aaaa'.");
		}
	}
	
	if(!error && !errfini && !errffin)
	{
		var dini = new Date(fechaFormatoIso(fini.value));
		var dfin = new Date(fechaFormatoIso(ffin.value));
		if(dini > dfin)
		{
			error = true;
			alert("La fecha final del Período a Facturar no puede ser anterior a la fecha inicial.");
		}
	}
	
	if(!error && !errffin)
	{
		var dactual = new Date();
		if(dactual < dfin)
		{
			error = true;
			alert("La fecha final del Período a Facturar no puede ser posterior a la fecha actual.");	
		}
	}
	if(!error)
	{
		return true;
	}
	else
	{
		return false;
	}
}
