//Declaración de variables
eulalia = new Image(114,150)
eulalia.src = "img/eulalia.jpg"
juan = new Image(117,150)
juan.src = "img/juan.jpg"
pablo = new Image(114,150)
pablo.src = "img/pablo.jpg"
sonia = new Image(114,150)
sonia.src = "img/sonia.jpg"

iluminada_izquierda_fin = new Image(14,16)
iluminada_izquierda_fin.src = "http://www.coaateeef.org/img/izquierda_finR.gif"
apagada_izquierda_fin = new Image(14,16)
apagada_izquierda_fin.src = "http://www.coaateeef.org/img/izquierda_fin.gif"
iluminada_izquierda_uno = new Image(14,16)
iluminada_izquierda_uno.src = "http://www.coaateeef.org/img/izquierda_unoR.gif"
apagada_izquierda_uno = new Image(14,16)
apagada_izquierda_uno.src = "http://www.coaateeef.org/img/izquierda_uno.gif"
iluminada_derecha_uno = new Image(14,16)
iluminada_derecha_uno.src = "http://www.coaateeef.org/img/derecha_unoR.gif"
apagada_derecha_uno = new Image(14,16)
apagada_derecha_uno.src = "http://www.coaateeef.org/img/derecha_uno.gif"
iluminada_derecha_fin = new Image(14,16)
iluminada_derecha_fin.src = "http://www.coaateeef.org/img/derecha_finR.gif"
apagada_derecha_fin = new Image(14,16)
apagada_derecha_fin.src = "http://www.coaateeef.org/img/derecha_fin.gif"
var nuevotexto = "";
var contador = 0;
var sentido;
var tempor = "";

// Funciones de linkaje del menú
function menu_normal(nombre)
{
document.getElementById(nombre).style.color = "#343333";
}

function menu_empresas(nombre)
{
document.getElementById(nombre).style.color = "#666666";
}

function submenu_normal(nombre)
{
document.getElementById(nombre).style.color = "#9D9C9C";
}

function encendido(nombre)
{
document.getElementById(nombre).style.color= "#A63321";
}

function seleccionado(nombre)
{
document.getElementById(nombre).style.color= "#E1E1E1";
}
function linka(nombre,orden)
{
  window.location = 'index.asp?pag=listado&buscar=' + document.getElementById(nombre).value + '&orden=' + orden + '&mostrar=' + document.getElementById('mostrando').value;
}
function linka_registro(pagina,nombre,orden,acceso)
{
  window.location = 'http://www.coaateeef.org/index.asp?pag='+pagina+'&acceso=' + acceso + '&buscar=' + document.getElementById(nombre).value + '&orden=' + orden + '&mostrar=' + document.getElementById('mostrando').value;
}

// Funciones de linkaje de la galería de fotos
function flash(cambio)
{
  matriu = cambio.split('|');
      var cadena2 = matriu[1].split("%20")
      for (var i=0; i < cadena2.length; i++) {
        nuevotexto = nuevotexto + (cadena2[i] + " ");
      }
  matriu[1] = nuevotexto;
  nuevotexto = "";
if (matriu[2].substring(matriu[2].length-1,matriu[2].length) == "'") {
  matriu[2] = matriu[2].substring(0,matriu[2].length-1); 
}
valor = matriu[2];

caracteres = matriu[0].lastIndexOf('/');
rutamax = matriu[0].substring(caracteres,matriu[0].length);
rutamax = 'img/fotos/max' + rutamax;
parent.frames["marco"].document.links("link").href = rutamax;
if (matriu[0].substring(0,1) == "'") {
 matriu[0] = matriu[0].substring(1,matriu[0].length);
}
parent.frames["marco"].document.images("foto").src = matriu[0];
parent.frames["marco"].document.all("texto").innerText = matriu[1];
parent.frames["marco"].document.all("actual").value = matriu[2];
for (a=0;a<44;a++) {
  if (a != eval(matriu[2]-1)) {
    parent.frames["negativo"].document.images(a).filters.alpha.opacity = 100;  
  } else {
    parent.frames["negativo"].document.images(a).filters.alpha.opacity = 45;    
  }
}
}
function muestra(valor)
{
if (valor > 0)  {
if (valor < 45) {
  valor = valor-1;
  frase = parent.frames["negativo"].document.links(valor).href;
  parent.frames["negativo"].scroll (valor * parent.frames["negativo"].document.images(valor).width + (valor * 12)); 
  cambio = frase.substring(17,frase.length-1);
  flash(cambio);
}
}
}
function puntero(imagen)
{
 for (a=1;a<44;a++) {
   parent.frames["negativo"].document.links(a).style.cursor = imagen ;
 }
}
function mueve()
{
if (tempor == "") {
 if (event.x < 50) {
  tempor = setTimeout("enrolla('negativo',1,5)",1);
  puntero('w-resize');
 } else if (event.x > 500) {
    tempor = setTimeout("enrolla('positivo',1,5)",1);
    puntero('w-resize');
 } else if (event.x < 100) {
  tempor = setTimeout("enrolla('negativo',1,2)",1);
  puntero('w-resize');
 } else if (event.x > 450) {
    tempor = setTimeout("enrolla('positivo',1,2)",1);
    puntero('w-resize');
 } else if (event.x < 150) {
    tempor = setTimeout("enrolla('positivo',1,1)",10);
    puntero('w-resize');
 } else if (event.x > 400) {
    tempor = setTimeout("enrolla('positivo',1,1)",10);
    puntero('w-resize');
 } 
} else {
 if (event.x < 50) {
  window.clearTimeout(tempor);
  tempor = "";
  sentido = "";
  tempor = setTimeout("enrolla('negativo',1,5)",1);
 } else if (event.x > 500) {
    window.clearTimeout(tempor);
    tempor = "";
    sentido = "";
    tempor = setTimeout("enrolla('positivo',1,5)",1);
 } else if (event.x < 100) {
  window.clearTimeout(tempor);
  tempor = "";
  sentido = "";
  tempor = setTimeout("enrolla('negativo',1,2)",1);
 } else if (event.x > 450) {
    window.clearTimeout(tempor);
    tempor = "";
    sentido = "";
    tempor = setTimeout("enrolla('positivo',1,2)",1);
 } else if (event.x < 150) {
    window.clearTimeout(tempor);
    tempor = "";
    sentido = "";
    tempor = setTimeout("enrolla('negativo',1,1)",10);
 } else if (event.x > 400) {
    window.clearTimeout(tempor);
    tempor = "";
    sentido = "";
    tempor = setTimeout("enrolla('positivo',1,1)",10);
 } else {
  if (event.x > 149) {
    if (event.x < 401) {
    puntero('hand');
    window.clearTimeout(tempor);
    tempor = "";
    sentido = "";
    }
  }
}
}
}
function enrolla(sentido,tiempo,unidad) 
{
if (sentido == 'positivo') {
  contador = contador + unidad;
  if (contador > 5300) {
     window.clearTimeout(tempor);
	 tempor = "";
	 sentido = "";
	 contador = 5300;
  } else {
    window.scroll(contador);
    tempor = setTimeout("enrolla('positivo',"+tiempo+','+unidad+")");
  }
} else if (sentido == 'negativo') {
  contador = contador - unidad;
  if (contador < 1) {
     window.clearTimeout(tempor);
	 tempor = "";
	 sentido = "";
	 contador = 0;
  } else {
    window.scroll(contador);
    tempor = setTimeout("enrolla('negativo',"+tiempo+','+unidad+")");
  }
}
} 

function para()
{
      window.clearTimeout(tempor);
      tempor = "";
      sentido = "";
}
function aparece(nombre)
{
document.getElementById(nombre).style.visibility='visible';
}
function desaparece(nombre)
{
  document.getElementById(nombre).style.visibility='hidden';
}
function mail()
{
window.clearTimeout(temporiza);
document.getElementById('entra').click();
}

function IsNumeric(valor) 
{
var punto = false;
var z = 0; 
var log=valor.length; var sw="S"; 
for (x=0; x<log; x++) 
{ v1=valor.substr(x,1); 
if (v1 != ".") {
  if (punto == false) {
    v2 = parseInt(v1); 
  } else {
    v2 = parseInt('.');
  }
} else {
    z = z + 1;
	if (z == 2) {
      punto = true;
    }
}
//Compruebo si es un valor numérico 
if (isNaN(v2)) { sw= "N";} 
} 
if (sw=="S") {return true;} else {return false; } 
} 

var primerslap=false; 
var segundoslap=false; 
function formateafecha(fecha) 
{ 
var long = fecha.length; 
var dia; 
var mes; 
var ano; 

if ((long>=2) && (primerslap==false)) { dia=fecha.substr(0,2); 
if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); primerslap=true; } 
else { fecha=""; primerslap=false;} 
} 
else 
{ dia=fecha.substr(0,1); 
if (IsNumeric(dia)==false) 
{fecha="";} 
if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; } 
} 
if ((long>=5) && (segundoslap==false)) 
{ mes=fecha.substr(3,2); 
if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; } 
else { fecha=fecha.substr(0,3);; segundoslap=false;} 
} 
else { if ((long<=5) && (segundoslap=true)) { fecha=fecha.substr(0,4); segundoslap=false; } } 
if (long>=7) 
{ ano=fecha.substr(6,4); 
if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); } 
else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } } 
} 

if (long>=10) 
{ 
fecha=fecha.substr(0,10); 
dia=fecha.substr(0,2); 
mes=fecha.substr(3,2); 
ano=fecha.substr(6,4); 
// Año no bisiesto y es febrero y el dia es mayor a 28 
if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; } 
} 
return (fecha); 
} 
function fechas(acceso,sociedad)
{
  uno = document.all('fecha1').value
  dos = document.all('fecha2').value
  if (uno.length < 10) {
    window.alert('La fecha inicial no es correcta');
  } 
  if (dos.length < 10) {
    window.alert('La fecha final no es correcta');
  }
  if (uno.length > 9) {
    if (dos.length > 9) {
	document.getElementById('tempo_resumen').style.visibility = 'visible';
  window.location ='http://www.coaateeef.org/index.asp?pag=resumen&acceso='+acceso+'&modo=entre&fecha1='+document.all('fecha1').value+'&fecha2='+document.all('fecha2').value+'&mostrar='+document.all('select').value+'&sociedad='+sociedad
    }
  }
}
function calcula(acceso)
{
if ((IsNumeric(document.all('presupuesto').value)==true)) {
  if ((IsNumeric(document.all('ciento').value)==true)) {
    if (document.all('ciento').value < 100.01) {
      if ((IsNumeric(document.all('super').value)==true)) {
        if ((IsNumeric(document.all('altura').value)==true)) {
           window.location='http://www.coaateeef.org/index.asp?pag=coste&acceso='+acceso+'&presupuesto='+document.all('presupuesto').value+'&tipo='+document.all('tipo').value+'&obra='+document.all('obraoficial').value+'&porcentaje='+document.all('ciento').value+'&superficie='+document.all('super').value+'&tipoobra='+document.all('tipoobra').value+'&altura='+document.all('altura').value+'&edificio='+document.all('edificio').value+'&calidad='+document.all('calidad').value+'&fecha='+document.all('fecha').value;
        } else {
     window.alert ('El valor introducido no es correcto (Altura).');
      }} else {
     window.alert ('El valor introducido no es correcto (Superficie).');
	}} else {
	 window.alert ('El valor de la participación no puede superar el 100%'); 
  }} else {
     window.alert ('El valor introducido no es correcto (Participación).');
  }} else {
window.alert ('El valor introducido no es correcto (Presupuesto).');
}
}
function calculapem(acceso)
{
if ((IsNumeric(document.all('presupuesto').value)==true)) {
     window.location='http://www.coaateeef.org/index.asp?pag=modulos&acceso='+acceso+'&presupuesto='+document.all('presupuesto').value+'&fecha='+document.all('txtfecha').value;
} else {
  window.alert ('El valor introducido no es correcto (Presupuesto).');
}
}
function control_texto()
{
if (event.keyCode == 39) {
  event.keyCode = 34;
}
}

function abre (pagina) {
var opciones="toolbar=no,location=no,directories=no,status=no,copyhistory=no,menubar=no,scrollbars=no,resizable=no,width=850,height=600,top=85,left=90";
  window.open(pagina,'',opciones);
}
function abre_visado (pagina) {
var opciones="toolbar=no,location=no,directories=no,status=no,copyhistory=no,menubar=no,scrollbars=no,resizable=no,width="+screen.width-100+",height="+screen.height-100+",top=0,left=0";
window.showModalDialog(pagina,"",'dialogHeight:'+screen.height-100+'px;dialogWidth:'+screen.width-100+'px;center:Yes; help:No;resizable:Yes;status:No;'); 
}

function publica(acceso) {
var variables = '';
for (a=2;a<13;a++) {
if (document.all(''+a+'').checked == true) {
variables = variables + '&' + a + '=' + '1';
} else { 
variables = variables + '&' + a + '=' + '0';
}
}
variables = variables + '&mail=' + document.getElementById('mailn').value + '&movil=' + document.getElementById('moviln').value;
window.location = 'publicar.asp?acceso='+acceso+variables;

}

function cambio_pass(acceso) {
if (document.all('pass1').value != document.all('pass2').value) {
  window.alert('Las contraseñas no coinciden');
} else {
  if (document.all('usuario').value != '') {
    abre('cambio.asp?acceso='+acceso+'&usuario='+document.all('usuario').value+'&pass='+document.all('pass1').value+'&usuario_webmail='+document.all('usuario_webmail').value+'&pass_webmail='+document.all('pass_webmail').value);
    window.location = 'colegiados.asp';
  } else {
  if (document.all('usuario_webmail').value != '') {
    abre('cambio.asp?acceso='+acceso+'&usuario_webmail='+document.all('usuario_webmail').value+'&pass_webmail='+document.all('pass_webmail').value);
  } else {  
    window.alert('Debes introducir un nombre de usuario.');
  }
  }
}
}

function cerrar(){ 
var ventana = window.self; 
ventana.opener = window.self; 
ventana.close(); 
} 

function accesos(acceso)
{
  uno = document.all('fecha1').value
  dos = document.all('fecha2').value
  if (uno.length < 10) {
    window.alert('La fecha inicial no es correcta');
  } 
  if (dos.length < 10) {
    window.alert('La fecha final no es correcta');
  }
  if (uno.length > 9) {
    if (dos.length > 9) {
  window.location ='webmaster.asp?acceso='+acceso+'&fecha1='+document.all('fecha1').value+'&fecha2='+document.all('fecha2').value;
    }
  }
}

function LTrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(j, s.length);
}
function RTrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}


function cambio_posicion(acceso) {
if (document.getElementById('imagen').value != '')  {
  imagen = LTrim(RTrim(document.getElementById('imagen').value));
  if (imagen = ' ') { imagen = ''; }
  document.frames('cajaimagen').document.location='imagen.asp?ambito=EEEEEE&posicion='+document.getElementById('posicion').value+'&borra='+imagen+'&id='+document.getElementById('id').value;
} else {
  document.frames('cajaimagen').document.location='imagen.asp?ambito=EEEEEE&posicion='+document.getElementById('posicion').value;
}
}

function actualiza_frame() {
document.frames('cajaimagen').document.location='imagen.asp?ambito=EEEEEE&posicion='+document.getElementById('posicion').value+'&imagen='+document.getElementById('imagen').value;
}

function estad(estado,acceso,ambito) {
  document.location = 'general_webmaster.asp?acceso='+acceso+'&estadistica='+estado+'&portada='+ambito;
}
function refresca(acceso) {
  if (document.getElementById('publica').selected==false) {
    document.location = 'general_webmaster.asp?acceso='+acceso+'&portada=privada';
  } else {
    document.location = 'general_webmaster.asp?acceso='+acceso+'&portada=publica';  
  }
}
function guarda_listado(acceso) {
window.location = "sql.asp?acceso="+acceso+"&guarda="+document.all('txtmensaje').value+"&nombre="+window.prompt('Introduce un nombre para la consulta.','Listado...');
}
