function paginadoListado(mipagina,tmpform) {
	var ff=eval("window.document.bava_"+tmpform);
	ff.pagina.value=mipagina;
	ff.submit();
}

function mostrarOferta(Id,Tabla) {
	window.location.href="oferta.html?tipo="+Tabla+"&id="+Id;
}

function zoomOficina(n) {
	var zoom = window.open("zoom_Oficina.html?Id="+n,"","width=800,height=600,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function zoomFotos(n) {
	var zoom = window.open("zoom.html?Id="+n,"","width=800,height=600,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function on_zoom(n) {
	var zoom = window.open("zoom_2.html?Thumb="+n,"","width=800,height=600,left=0,top=0,status=no,resizable=yes,scrollbars=no"); 
}

function validarFichaVenta() {

	var ok=0;

	var ff=window.document.FVenta;
	
	validacion = /[^a-z-.@0-9A-Z]/g;
	validacionTelefono = /[^+ 0-9]/g;
	validacionNumerica = /[^0-9]/g;

	if (ff.Nombre.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
	} else {
		if(ff.Nombre.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
		}
	}


	if (ff.Direccion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
	} else {
		if(ff.Direccion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
		}
	}

	if (ff.Codigo_Postal.value.length != 5 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
	} else {
		if (validacionNumerica.test(ff.Codigo_Postal.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
		}
	}

	if (ff.Poblacion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
	} else {
		if(ff.Poblacion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
		}
	}

	if (ff.Provincia.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
	} else {
		if(ff.Provincia.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
		}
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}


	if (ff.Fax.value.length>0){
		if (validacionTelefono.test(ff.Fax.value) || (ff.Fax.value.length<6)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Fax'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
		}
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'eMail'.\nEl formato válido es usuario@dominio.tld\n\n");
	}

	if (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Tipo de Inmueble'.\n\n");
	}

	if (ff.Direccion_Inmueble.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
	} else {
		if(ff.Direccion_Inmueble.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
		}
	}

	if (ff.Codigo_Postal_Inmueble.value.length != 5 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
	} else {
		if (validacionNumerica.test(ff.Codigo_Postal_Inmueble.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
		}
	}


	if (ff.Zona.options[ff.Zona.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Zona'.\n\n");
	}


	if (ff.Observaciones.value.length < 1 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Observaciones'.\n\n");
	}

	if (ff.politica.checked == false){
		ok=1;
		alert("Debe aceptar nuestra política de privacidad y protección de datos.");
	}

	if (ok==0) {
		ff.submit();
	} else {
		return false;	
	}
}




function validarFichaBusca() {

	var ok=0;

	var ff=window.document.FCompra;

	validacion = /[^a-z-.@0-9A-Z]/g;
	validacionTelefono = /[^+ 0-9]/g;
	validacionNumerica = /[^0-9]/g;

	if (ff.Nombre.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
	} else {
		if(ff.Nombre.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nombre'.\n\n");
		}
	}


	if (ff.Direccion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
	} else {
		if(ff.Direccion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Dirección'.\n\n");
		}
	}

	if (ff.Codigo_Postal.value.length != 5 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
	} else {
		if (validacionNumerica.test(ff.Codigo_Postal.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\n\n");
		}
	}

	if (ff.Poblacion.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
	} else {
		if(ff.Poblacion.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Población'.\n\n");
		}
	}

	if (ff.Provincia.value.length < 3 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
	} else {
		if(ff.Provincia.value.length > 128){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Provincia'.\n\n");
		}
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}


	if (ff.Fax.value.length>0){
		if (validacionTelefono.test(ff.Fax.value) || (ff.Fax.value.length<6)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Fax'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
		}
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'eMail'.\nEl formato válido es usuario@dominio.tld\n\n");
	}

	if (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Tipo de Inmueble'.\n\n");
	}

	if ((ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Garaje") && (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Trastero")) {


		if ((ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Bajo") && (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Local Comercial") && (ff.Tipo_de_Inmueble.options[ff.Tipo_de_Inmueble.selectedIndex].text != "Oficina")) {
			if (ff.nHabitaciones.options[ff.nHabitaciones.selectedIndex].text == ""){
				ok=1;
				alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Nº de Habitaciones'.\n");
			}
		}

		if (ff.Superficie_Minima.options[ff.Superficie_Minima.selectedIndex].text == ""){
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Superficie Mínima'.\n");
		}

	}

	if (ff.Precio_Maximo.options[ff.Precio_Maximo.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Precio Máximo'.\n\n");
	}

	if (ff.Zona_Preferida.options[ff.Zona_Preferida.selectedIndex].text == "") {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Zona Preferida'.\n\n");
	}

	if (ff.Observaciones.value.length < 1 ){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Observaciones'.\n\n");
	}

	if (ff.politica.checked == false){
		ok=1;
		alert("Debe aceptar nuestra política de privacidad y protección de datos.");
	}

	if (ok==0) {
		ff.submit();
	} else {
		return false;	
	}
}

function DC_Print() {
	disipa('imprimir','imagenes/bot_imprimir');
	window.print();
	disipa('imprimir','imagenes/bot_imprimir');
}

function disipa(imagen,base_imagen) {
	if ((document.images[imagen].src.indexOf("_t.gif")) > -1) {
		MM_swapImage(imagen,'',base_imagen+'.gif',1);
	} else {
		MM_swapImage(imagen,'',base_imagen+'_t.gif',1);
	}
}

function mapa_localizacion() {
	var zoom = window.open("mapa.html","","width=548,height=538,left=0,top=0,status=no,resizable=yes,scrollbars=no");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function MM_showHideLayers() { //v2.0
   var i, visStr, args, theObj;
   args = MM_showHideLayers.arguments;
   for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
     visStr   = args[i+2];
     if (navigator.appName == 'Netscape' && document.layers != null) {
       theObj = eval(args[i]);
       if (theObj) theObj.visibility = visStr;
     } else if (document.all != null) { //IE
       if (visStr == 'show') visStr = 'visible'; //convert vals
       if (visStr == 'hide') visStr = 'hidden';
       theObj = eval(args[i+1]);
       if (theObj){
		pageWidth=(ie)?document.body.offsetWidth:innerWidth;
		theObj.style.left=(pageWidth - 780)/2;
		theObj.style.visibility = visStr;
		}
  } }
}

function ilumina(imagen,base_imagen) {
	if ((document.images[imagen].src.indexOf("_i.gif")) > -1) {
		MM_swapImage(imagen,'',base_imagen+'.gif',1);
	} else {
		MM_swapImage(imagen,'',base_imagen+'_i.gif',1);
	}
}


function borraPresupuesto() {
	var ff=window.document.presupuesto;
	ff.Empresa.value="";
	ff.Persona_de_Contacto.value="";
	ff.Direccion.value="";
	ff.Localidad.value="";
	ff.Provincia.value="";
	ff.Codigo_Postal.value="";
	ff.Telefono.value="";
	ff.eMail.value="";
	if (ff.Fiscal.checked==true) {
	 ff.Fiscal.click();
	}
	if (ff.Laboral.checked==true) {
	 ff.Laboral.click();
	}
	if (ff.Contabilidad.checked==true) {
	 ff.Contabilidad.click();
	}
	if (ff.Gestion_Completa.checked==true) {
	 ff.Gestion_Completa.click();
	}	
	ff.Tipo_de_Empresa.value="";
	ff.Numero_de_Trabajadores.value="";
	ff.Numero_de_Asientos.value="";
	ff.Informacion_Complementaria.value="";
}

function borraConsulta() {
	var ff=window.document.contacto;
	ff.Contacto.value="";
	ff.Telefono.value="";
	ff.eMail.value="";
	ff.Informacion_Complementaria.value="";
}


function validaConsulta() {
	var ff=window.document.contacto;
	var ok=0;
	var campo_actual="";

	validacion = /[^a-z-.@0-9A-Z áéíóúÁÉÓÚ,.\/]/g;
	validacionTelefono = /[^+ 0-9]/g;
	validacionNumerica = /[^0-9]/g;

	if (ff.Contacto.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Empresa o Persona de Contacto'.\n");
	} else {
		if (validacion.test(ff.Contacto.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Empresa o Persona de Contacto'.\n");
		}
	}


	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'eMail'.\n");
	}


	if (ff.Informacion_Complementaria.value.length < 5){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Consulta'.\n");
	} else {
		if (validacion.test(ff.Informacion_Complementaria.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Consulta'.\n");
		}
	}
	
	if (ff.politica.checked == false){
		ok=1;
		alert("Debe aceptar nuestra política de privacidad y protección de datos.");
	}

	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;
	}


}
	
function validaPresupuesto() {
	var ff=window.document.presupuesto;
	var ok=0;
	var campo_actual="";

	validacion = /[^a-z-.@0-9A-Z áéíóúÁÉÓÚ,.\/]/g;
	validacionTelefono = /[^+ 0-9]/g;
	validacionNumerica = /[^0-9]/g;

	if (ff.Empresa.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Nombre de la empresa'.\n");
	} else {
		if (validacion.test(ff.Empresa.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Nombre de la empresa'.\n");
		}
	}


	if (ff.Persona_de_Contacto.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Nombre del solicitante'.\n");
	} else {
		if (validacion.test(ff.Persona_de_Contacto.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Nombre del solicitante'.\n");
		}
	}

	if (ff.Direccion.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Dirección'.\n");
	} else {
		if (validacion.test(ff.Direccion.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Dirección'.\n");
		}
	}

	if (ff.Localidad.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Localidad'.\n");
	} else {
		if (validacion.test(ff.Localidad.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Localidad'.\n");
		}
	}

	if (ff.Provincia.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Provincia'.\n");
	} else {
		if (validacion.test(ff.Provincia.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Provincia'.\n");
		}
	}

	if (validacionNumerica.test(ff.Codigo_Postal.value) || (ff.Codigo_Postal.value.length!=5)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Código Postal'.\nLos únicos caracteres válidos para este campo son números del 0 al 9\n\n");
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}

	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'eMail'.\n");
	}

	if ((ff.Fiscal.checked==false) && (ff.Laboral.checked==false) && (ff.Contabilidad.checked==false) && (ff.Gestion_Completa.checked==false)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nDeberá seleccionar al menos una de las opciones del campo 'Desea recibir su presupuesto sobre'.\n");
	}

	if (ff.Tipo_de_Empresa.options[ff.Tipo_de_Empresa.selectedIndex].text == ""){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Tipo de Empresa'.\n");
	}

	if (validacionNumerica.test(ff.Numero_de_Trabajadores.value) || (ff.Numero_de_Trabajadores.value.length<1) || (ff.Numero_de_Trabajadores.value.length>4)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nº de Trabajadores'.\nLos únicos caracteres válidos para este campo son números del 0 al 9\n\n");
	}

	if (validacionNumerica.test(ff.Numero_de_Asientos.value) || (ff.Numero_de_Asientos.value.length<1) || (ff.Numero_de_Asientos.value.length>8)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Nº de Asientos por año'.\nLos únicos caracteres válidos para este campo son números del 0 al 9\n\n");
	}

	if (ff.politica.checked == false){
		ok=1;
		alert("Debe aceptar nuestra política de privacidad y protección de datos.");
	}

	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;
	}


}


function checkEmail(emailStr) {
   if (emailStr.length == 0)
     return true;
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="()<>@,;:\".[]";
   var validChars="[^s" + specialChars + "]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(d{1,3})[.](d{1,3})[.](d{1,3})[.](d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);

   if (matchArray == null)
      return false;

   var user=matchArray[1];
   var domain=matchArray[2];

   if (user.match(userPat) == null)
      return false;

   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
      for (var i = 1; i <= 4; i++) {
         if (IPArray[i] > 255)
         	return false;
   		}

   return true;
	 }

   var domainArray=domain.match(domainPat);
   if (domainArray == null)
      return false;

   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;

   if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 3)
      return false;

   if (len < 2)
      return false;

   return true;
}


function CalculaNifCif(nif) {
	nif = replaceSubstring(nif, " ", "");
	nif = replaceSubstring(nif, "-", "");
	nif = replaceSubstring(nif, ".", "");
	if ( !(CalculaNif(nif) || CalculaCif(nif) || CalculaNie(nif)) ) {
		alert("El NIF / CIF / NIE insertado no es válido.\n");
	} else {
		window.document.FClientes.NIF.value = nif.toUpperCase();
	}
}

function CalculaNie(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';

	var letraNie    = nif.substring(0,1);
	var dni    = nif.substring(1,8);
	var letraNif = nif.substring(8,9);
	var letraAux;
	var letraInicio="X";

	var numero = dni%23;

	letraAux = letras.substring(numero,numero+1);

	if ( (letraAux == letraNif.toUpperCase()) && (letraInicio==letraNie.toUpperCase()) ) {
		return true;
	}else{
		return false;
	}
}
function CalculaNif(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';

	var dni    = nif.substring(0,8);
	var letraNif = nif.substring(8,9);
	var letraAux;

	var numero = dni%23;

	letraAux = letras.substring(numero,numero+1);

	if(letraAux == letraNif.toUpperCase()){
		return true;
	}else{
		return false;
	}
}


function CalculaCif(elCIF)
  {
    var resul = false;
    var temp = elCIF.toUpperCase();

    if (!/^[A-Za-z0-9]{9}$/.test(temp)) {
      resul = false;
    } else {
    	if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) {
    	  resul = false;
		} else {
		  resul = ValidaCIF(temp);
    	}
    }
    return resul;
}


function ValidaCIF(elCIF)
  {
  	var resul = false;
    var v1 = new Array(0,2,4,6,8,1,3,5,7,9);

    var temp = 0;
    var temp1;

    for( i = 2; i <= 6; i += 2 )
    {
      temp = temp + v1[ parseInt(elCIF.substr(i-1,1)) ];
      temp = temp + parseInt(elCIF.substr(i,1));
    }

    temp = temp + v1[ parseInt(elCIF.substr(7,1)) ];
    temp = (10 - ( temp % 10));

    if( temp == 10 ) {
      if ((elCIF.substring(8,9)=="J") || (elCIF.substring(8,9)=="0")) {
      	resul = true;
      } else {
      	resul = false;
      }
    } else {
      if (elCIF.substring(8,9)==temp) {
      	resul = true;
      } else {
      	resul = false;
      }
	}
	return resul;
  }

var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function