var v=null;
var d=null;
var variab=null;
function startList()
{
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					this.className+=" over";
  				}
  				node.onmouseout=function()
				{
  					this.className=this.className.replace(" over", "");
   				}
   			}
  		}
	}
}
function mostrarDatos(ventana,prov)
{
	if (ventana != null)
	{
		ventana.close();
	}
	ventana = window.open('datosContacto.php?provincia='+prov, 'window', 'top=100,left=100,width=800,height=600');
}
function validar(a)
{
/*
	codigo: XXX + M + nnnn
	XXX: codigo de tipo
	M: A -> no nulo // B -> nulo
*/
	fin=true;
	val=true;
	mensaje="";
	for(i=0;fin==true && a.elements[i];i++)
	{
		if(a.elements[i].type != undefined)
		{
			nom=a.elements[i].name;
			clave=nom.substr(0,3);
			valor=a.elements[i].value;
			modo=nom.substr(3,1);
			switch(clave)
		  	{
				case 'cod':
				{
					var reg=new RegExp(/^[0-9]{5}$/);
					if(!reg.test(valor))
					{
			    		val=false;
			    		mensaje="Codigo postal Incorrecto";
					}
					else
					{
			    		val=true;
					}
					break;
				}
				case 'fec':
				{
					var reg = new RegExp(/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/);
		    		if(!reg.test(valor))
					{
			    		val=false;
			    		mensaje="Formato de fecha incorrecto";
					}
					else
					{
			    		j= valor.split("/");
			    		correcta = ValidarF(j[0],j[1],j[2]);
			    		if(!correcta)
			    		{
							val=false;
			    			mensaje="Fecha incorrecta";
			    		}
			   			else
			    		{
			        		val=true;
			    		}
					}
					break;
		    	}
				case 'tel':
				{
					var reg=new RegExp(/^[689][0-9]{8}$/);
					if(!reg.test(valor))
					{
			    		val=false;
			    		mensaje="Telefono incorrecto";
					}
					else
					{
			    		val=true;
					}
					break;
				}
				case 'txt':
				{
					if(valor[0]==' ' || valor.length==0)
					{
						mensaje="Nombre incorrecto";
						val=false;
					}
					else
					{
						val=true;
					}
					break;
				}
				case 'int':
				{
					var reg=new RegExp(/^[0-9]{1,10}$/);
					if(!reg.test(valor))
					{
			    		val=false;
			    		mensaje="cantidad incorrecta";
					}
					else
					{
			    		val=true;
					}
					break;
				}
				case 'flo':
				{
					var flo=new RegExp(/^[0-9]{1,10}[.]{1}[0-9]{1,2}$/);
					var rea=new RegExp(/^[0-9]{1,10}$/);
					if(!flo.test(valor) && !rea.test(valor))
					{
			    		val=false;
			    		mensaje="cantidad incorrecta";
					}
					else
					{
			    		val=true;
					}
					break;
				}
				case 'ema':
				{
					var reg=new RegExp(/^[\w._-]{1,22}@[\w-.]{1,22}[.][\w-.]{2,11}$/);
					if(!reg.test(valor))
					{
			   			mensaje="e-mail incorrecto";
			    		val = false;
					}
					else
					{
			   		 	val =true;
					}
					break;
				}
				case 'dni':
				{
					var reNIF = new RegExp(/^[0-9]{8}[A-Z]{1}$/);
	  				var reNIE = new RegExp(/^[X][0-9]{8}[A-Z]{1}$/);
	  				var reCIF = new RegExp(/^[A-Z]{1}[0-9]{8}$/);
	  				var rePAS = new RegExp(/^[P][0-9]{8}$/);
	  				if (valor.match(reNIF))
	  				{
			   		 	val =true;
	  				}
	  				else
	  				{
						if(valor.match(reNIE))
						{
			   		 		val =true;
						}
						else
						{
							if(valor.match(reCIF))
							{
			   		 			val =true;
							}
							else
							{
								if(valor.match(rePAS))
								{
			   		 				val =true;
								}
								else
								{
			   						mensaje="DNI incorrecto";
			    					val = false;
								}
							}
						}
					}
					break;
				}
				default:
				{
					val=true;
				}
		  	}
			if(val==false)
			{
				if(modo=='B' && valor.length==0)
				{
					fin=true;
				}
				else
				{
					fin=false;
					alert(mensaje);
					a.elements[i].focus();
				}
			}
		}
	}
	return fin;
}
function ValidarF(a,b,c)
{
    if(b<1 || b>12)
    {
		return false;
    }
    if((b<8 && b%2==1)||(b>7 && b%2==0))
	{
	    if(a<1 || a>31)
		{
			return false;
		}
	}
	else
	{
	    if(b!=2 &&(a<1 || a>30))
		{
			return false;
		}
		if(b==2)
		{
		    if(c%4==0 && (a<1 ||a>29))
			{
				return false;
			}
			if(c%4!=0 &&(a<1||a>28))
			{
				return false;
			}
		}
	}
	return true;
}
function cambInte(a)
{
	v=a.value;
	window.location="modPlaz.php?val="+v;
}
function abrirPDF(id,ruta)
{
	pdf=window.open("abrirPDF.php?id="+id+"&ruta="+ruta,"nueva",'scrollbars=NO,resizable=NO,Directories=NO')
}
function completarVal(a)
{
	numero=a.numElementos.value;
	for(i=1,ruta="";i<=numero;i++)
	{
		arc="archivo"+i;
		base=a.archivo1.value;
		if(base.length>0)
		{
			i=numero+1;
		}
	}
	a.archivo2.value=base;
	var partes = new Array();
	partes= base.split("/");
	for(i=0,ruta="";i<numero;i++)
	{
		if(i>0)
		{
			ruta+="/";
		}
		ruta+=partes[i];
	}
	ruta+="/";
	return false;
}
function moverExp(yo)
{
    mov=yo.value;
	window.location="modId.php?id="+mov
}
function moverValor(nom,yo)
{
    mov=yo.value;
	window.location="establecerValor.php?nom="+nom+"&val="+mov
}
function moverValorL(nom,yo)
{
    mov=yo.value;
	window.location="establecerValorL.php?nom="+nom+"&val="+mov
}
/*Movimiento de capas*/
placas= new Array();
placas[0]=new Array('marcOrigen','marcDatos','marcOper','marcFinan','marcViv');
placas[1]=new Array('','Comer','Colab');
function mostrarTipo(tip,val)
{
	vec=placas[tip];
	for(i=0;i<vec.length;i++)
	{
		if(vec[i].length>0)
		{
			document.getElementById(vec[i]).style.display="none";
		}
	}
	if(val> -1 && vec[val].length>0)
	{
		document.getElementById(vec[val]).style.display="block";
	}
}
function subir(a,id)
{
	window.location= "expediente/moverCli.php?id="+id+"&orden="+a+"&tipo=1";
}
function bajar(a,id)
{
	window.location= "expediente/moverCli.php?id="+id+"&orden="+a+"&tipo=2";
}
function borrar(a,id)
{
    if(confirm("żEsta seguro que desea eliminar este solicitante?"))
	{
	    window.location= "expediente/moverCli.php?id="+id+"&orden="+a+"&tipo=3";
	}
}
function mostCli(a)
{
    if(document.getElementById(a).style.display=="block")
	{
	    visionarCapa(a,false);
	}
	else
	{
	    visionarCapa(a,true);
	}
}
function visionarCapa(nom,val)
{
	if(val==true)
	{
		document.getElementById(nom).style.display="block";
	}
	else
	{
		document.getElementById(nom).style.display="none";
	}
}
function cambiarVision(nom)
{
	ver=document.getElementById(nom).style.display;
	if(ver=="none")
	{
		visionarCapa(nom,true);
	}
	else
	{
		visionarCapa(nom,false);
	}
}
function reunif(a,b,c)
{
    window.location="expediente/modReuni.php?cli="+a+"&val="+b+"&id="+c
}
function expOper(id,a)
{
    val=a.value;
    cadena="expediente/modTipoOper.php?id="+id+"&tipo="+val;
    window.location=cadena;
}
function mostrarBan(id,tipo)
{
	cadena="expediente/modTipoBan.php?id="+id+"&tipo="+tipo;
	window.location=cadena;
}
function guardarCookie(nom,val)
{
	document.cookie= nom +" = "+ val;
}
function leerCookie(nom)
{
	a = document.cookie.substring(document.cookie.indexOf(nom + '=') + nom.length + 1,document.cookie.length);
	if(a.indexOf(';') != -1)
	{
		a = a.substring(0,a.indexOf(';'));
		return a;
	}
	else
	{
		return -1;
	}
}
//cok:nombre de la cookie para guardar
//nom:nombre raiz del campo
//tot:numero total de elementos
//val:elemento a mostrar
function ocultarGrupDiv(cok,nom,tot,val)
{
	guardarCookie(cok,val);
	for(i=0;i<=tot;i++)
	{
		if(i==val)
		{
			capa=nom+i;
			visionarCapa(capa,true);
		}
		else
		{
			capa=nom+i;
			visionarCapa(capa,false);
		}
	}
}
function ocultarCambDiv(cok,nom,nom2,tot,val,acv,ina)
{
	guardarCookie(cok,val);
	for(i=0;i<=tot;i++)
	{
		if(i==val)
		{
			capa=nom+i;
			document.getElementById(capa).className=acv;
			document.getElementById(capa).blur();
			capa=nom2+i;
			visionarCapa(capa,true);
		}
		else
		{
			capa=nom+i;
			document.getElementById(capa).className=ina;
			capa=nom2+i;
			visionarCapa(capa,false);
		}
	}
}
function cambioValor(a,nom)
{
	document.location="establecerValor.php?nom="+nom+"&val="+a.value;
}
var i;
var lista_imagenes = new Array();

function cargarimagenes(imagenes)
{
	for(i in imagenes)
	{
		lista_imagenes[i] = new Image();
		lista_imagenes[i].src = imagenes[i];
	}
}
function formular(id,tipo,banco,prod)
{
    if(confirm("żEsta seguro que desea enviar el expediente?"))
    {
		destino="expediente/peticionForm.php?id="+id+"&ope="+tipo+"&ban="+banco+"&pro='"+prod+"'";
		window.open(destino,"window","top=400,left=150,width=600,scrollbars=1,height=700,status=1");
    }
}
function abrirCalculadora()
{
	calculadora=window.open('calculos/viabilidad.php','calculadora','top=150,left=150,width=690,height=300');
}
function mostSol(id)
{
	solicitud=window.open('expediente/solExc.php?id='+id,'Solicitud','top=150,left=150,width=550,height=650');
}
function abrirAgenda(id)
{
	agenda=window.open('agenda/agenda.php?id='+id,'agenda','top=50,left=50,width=950,height=600');
}
function abrirDocum(id)
{
	docum=window.open('expediente/indexftp.php?id='+id,'documentacion','top=50,left=50,width=950,height=600,scrollbars=1');
}
function abrirDocumEnv(id)
{
	docum=window.open('expediente/docEnv.php?id='+id,'documentacion','top=50,left=50,width=500,height=600,scrollbars=1');
}
function docDisp(ban,oper,prod)
{
	if(d!=null)
	{
		d.close();
	}
	ruta="bases/docBan.php?ban="+ban+"&oper="+oper+"&prod='"+prod+"'";
	valores='top=50,left=50,width=750,height=600,scrollbars=1';
	d=window.open(ruta,'Producto: '+prod,valores);
}
function subirProd(ban,ope,pro,ord)
{
	if(d!=null)
	{
		d.close();
	}
	ruta="bases/ordProd.php?tipo=1&ban="+ban+"&oper="+ope+"&prod='"+pro+"'&ord="+ord;
	window.location=ruta;
}
function bajarProd(ban,ope,pro,ord)
{
	if(d!=null)
	{
		d.close();
	}
	ord++;
	ruta="bases/ordProd.php?tipo=2&ban="+ban+"&oper="+ope+"&prod='"+pro+"'&ord="+ord;
	window.location=ruta;
}
function abrirSeguimiento(id)
{
	segui=window.open('expediente/segDiario.php','Seguimiento','top=50,left=50,width=950,height=600');
}
function abrirPrivada()
{
	privada=window.open('privada/index.php','privada','top=50,left=50,width=950,height=600,status=1,scrollbars=1');
}
function abrirFactura(fec,dir,afe)
{
	factura=window.open('facturacion/mostFac.php?fec='+fec+'&dir='+dir+'&afe='+afe,'factura','top=50,left=50,width=950,height=600,status=0,scrollbars=1');
}
function pagarFactura(fec,dir,afe)
{
	factura=window.open('facturacion/pagarFac.php?dat='+fec+'&dir='+dir+'&afe='+afe,'factura','top=50,left=50,width=500,height=650,status=0,scrollbars=1');
}
function editarFactura(valor)
{
	window.location='establecerValor.php?nom=id&val='+valor;
}
function visInfBan(valor)
{
	bancarios=window.open('informes/visInfBan.php?id='+valor,'informe','top=50,left=50,width=800,height=650,status=0,scrollbars=1');
}
function realizar(id)
{
	if(confirm("żLa tarea esta realizada?"))
	{
	    window.location="realizarAg.php?id="+id;
	}
}
function validSitBan(frm,i,id)
{
    a=frm.banco.value;
    if(frm.estBanF.value==4)
    {
		if(confirm("Si varia el estado del expediente a firmado no podra modificarlo.\nżDesea continuar?"))
		{
		    destino="expediente/nFactura.php?a="+a+"&id="+id;
		    window.open(destino,"window","top=400,left=150,width=300,height=90");
		    return true;
		}
		else
		{
		    return false
		}
    }
    return true;
}
function finan(id,form)
{

	if(validar(form)==true)
	{
		importe=form.floBimp.value;
		inte=form.floBint.value;
    	pla=form.intBpla.value;
    	ingre=form.floBing.value;
    	if(id==1)
    	{
	    	pla*=12;
			tasacion=form.floBtas.value;
	    	if(tasacion>0)
	    	{
	    		tasa=importe/tasacion;
	    	}
	    	else
	    	{
	    		tasa=0;
	    	}
		    tasa*=10000;
			tasa=Math.round(tasa);
			tasa/=100;
			tasa+=" % de financiacion"
		    document.getElementById("finan"+id).firstChild.firstChild.nodeValue=tasa
    	}
	    if(inte>0)
	    {
	    	inte/=1200;
			nuc=Math.pow(1+inte,pla);
			arriba=inte*nuc;
			abajo=nuc-1;
			frac=arriba/abajo;
			calc=importe*frac;
			calc*=100;
			calc=Math.round(calc);
			calc/=100;
		    document.getElementById("cuota"+id).firstChild.firstChild.nodeValue=calc+" Cuota Aproximada";
	    }
	    else
	    {
	    	calc=0;
	    }
	    if(calc>0 && ingre>0)
	    {
	    	esfuerzo=calc/ingre;
			esfuerzo*=10000;
			esfuerzo=Math.round(esfuerzo);
			esfuerzo/=100;
	        document.getElementById("esfu"+id).firstChild.firstChild.nodeValue="Tasa de esfuerzo "+esfuerzo+" %";
	    }

	}
    return false;
}
function mensajear()
{
    document.getElementById('obser').txtAobserv.value=document.getElementById('obser').obsAut.value;
}
function abrirSolicitud(id,tipo,ban,prod)
{
	agenda=window.open('expediente/visualizar.php?id='+id+"&tipo="+tipo+"&ban="+ban+"&prod='"+prod+"",'pdf','top=50,left=50,width=950,height=600,status=1,scrollbars=1');
}
function mostrarSolic(id)
{
	solicitud=window.open('expediente/solExc.php?id='+id,'solicitud','top=50,left=50,width=950,height=600,status=0,scrollbars=1');
}
function mostrarSolicInf(id)
{
	solicitud=window.open('../expediente/solExc.php?id='+id,'solicitud','top=50,left=50,width=950,height=600,status=0,scrollbars=1');
}
function estListaFac(a)
{
	document.getElementById("modalidad").value=a;
}
function listaFac(a)
{
	cont=a.valor;
	if(cont.length == null)
	{
		salida=cont.value;
		v=1;
	}
	else
	{
		for(i=0,salida="",v=0;i<cont.length;i++)
		{
			if(cont[i].checked==true)
			{
				v++;
				valor=cont[i].value;
				if(salida=="")
				{

					salida=valor;
				}
				else
				{
					salida+=";"+valor
				}
			}
		}
	}
	if(document.getElementById("modalidad").value==1)
	{
		accion="validar";
	}
	if(document.getElementById("modalidad").value==2)
	{
		accion="anular";
	}
	preg="żDesea " + accion + " estos " + v + " registros?";
	if(confirm(preg))
	{
		document.getElementById("listaVal").value=salida;
		return true;
	}
	else
	{
		return false;
	}
}
function visualColab(i)
{
	nom="origenDespColab";
	switch(i)
	{
		case 1:
		{
			if(a=confirm("żEsta seguro de que el expediente\n no es de un colaborador?"))
			{
				visionarCapa(nom,false);
			}
			else
			{
				visionarCapa(nom,true);
				document.origen.tipoOrigen[1].checked=true;
			}
			break;
		}
		case 2:
		{
			visionarCapa(nom,true);
			break;
		}
	}
}
function chkTodas(a)
{
	i=0;
	if(a.checked)
	{
		nueVal=1;
	}
	else
	{
		nueVal=0;
	}
	while(a.tagName!="form" && a.tagName!="FORM")
	{
		a=a.parentNode;
	}
	total=a.elements.length;
	for(i=0;i<total;i++)
	{
		if(a.elements[i].type=="checkbox")
		{
			a.elements[i].checked=nueVal;
		}
	}
}
function modVar(tipo,id)
{
	ruta="bases/fichaVar.php?id="+id+"&tipo="+tipo;
	opc="top=50,left=50,width=800,height=600,status=1,scrollbars=1";
	if(variab!=null)
	{
		variab.close();
	}
	variab=window.open(ruta,"variable",opc);
}
function cambiarEstadoListado(idCat,idUs,idOrd,a)
{
	mov=a.value;
	ruta="../privada/listados/establecerEstado.php?cat="+idCat+"&usu="+idUs+"&regis="+idOrd+"&val="+mov;
	if(a=confirm("żEsta seguro de que desea modificar el estado de la ficha?\nGuarde todos los cambios antes de Aceptar."))
	{
		window.location=ruta;
	}
}
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
var vecCad;
var vecVar;
var totCad;
var valorAct;
function iniciar()
{
	vecCad=new Array();
	vecVar=new Array();
	totCad=0;
	valorAct=0;
}
function addVar(a,b)
{
	valor=a;
	valor2=b;
	if(totCad==0)
	{
		pintarCad();
	}
    if(totCad>valorAct)
    {
		for(i=totCad;i>valorAct;i--)
		{
		    vecCad[i]=vecCad[i-1];
		    vecVar[i]=vecVar[i-1];
		}
		vecCad[valorAct]=valor;
		vecVar[valorAct]=valor2;
	}
	else
	{
		vecCad[valorAct]=valor;
		vecVar[valorAct]=valor2;
	   	valorAct++;
	}
	totCad++;
	pintarCad();
}
function delVar()
{
	totCad--;
	for(i=valorAct;i<totCad;i++)
	{
	    vecCad[i]=vecCad[i+1];
	    vecVar[i]=vecVar[i+1];
	}
	vecCad[totCad+1]="";
	vecVar[totCad+1]="";
	pintarCad();
}
function pintarCad()
{
	cuerpo=document.getElementById("texto");
	for(i=0,cadena="",cadenaN="";i<totCad;i++)
	{
	    if(i==valorAct)
	    {
			cadena=cadena+"<b>"+vecCad[i]+"</b>";
	    }
	    else
	    {
			cadena=cadena+vecCad[i];
	    }
		cadenaN=cadenaN+vecVar[i];
	}
	cuerpo.firstChild.nodeValue=cadena;
	document.getElementById("valorVariable").value=cadenaN;
}
function vaciar()
{
	iniciar();
	pintarCad();
}
function retroc()
{
	if(valorAct>0)
	{
	    valorAct--;
	}
	pintarCad();
}
function avanc()
{
	if(valorAct<totCad)
	{
	    valorAct++;
	    pintarCad();
	}
}
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/