//
// ==================================== AJAX ==========================================
//
function nuevoAjax(){
	var xmlhttp=false;
//
//		Internet Explorer
//
	if (window.ActiveXObject)
	{
		try {
 			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e) {
	 		try {
	 			xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e1) {
				xmlhttp = false;
			}
		}
//
//		Otros Navegadores
//
	} else {
 		try {
 			xmlhttp = new XMLHttpRequest();
 		} catch (e) {
			xmlhttp = false
		}
	}
	if (!xmlhttp) {
		alert ('No se puede crear objeto xmlhttp Request - Cambie de Navegador');
	}
	return xmlhttp;
}
function cargaContent (cfv,cnropag,ccontenido,ifv,inropag,icontenido,dfv,dnropag,dcontenido,grupomenu) {

	if ((cfv=='1' && cnropag!=0) || (cfv=='0' && ccontenido.length!=0)){
		cargaDiv ('cuerpo',cfv,cnropag,ccontenido);
	}

	if (grupomenu!=0){
		cargaDiv ('divmenu','0','0','cargamenu.php?nromenu='+grupomenu);
	}	

	if ((ifv=='1' && inropag!=0) || (ifv=='0' && icontenido.length!=0)){
		cargaDiv ('divpizq',ifv,inropag,icontenido);
	}

	if ((dfv=='1' && dnropag!=0) || (dfv=='0' && dcontenido.length!=0)){
		cargaDiv ('derecha',dfv,dnropag,dcontenido);
	}

}
//
function cargaDiva(div,fv,nropag,contenido) {
	if (fv=='1') {
		contenido ='cargavariable.php?id='+nropag;
	}
	var elem = document.getElementById(div);
	var vini = new nuevoAjax();
	var url = contenido;
	vini.open("GET", url ,true);
	elem.innerHTML='';
	vini.onreadystatechange=function() {
		if (vini.readyState==4 && vini.status==200) {
			elem.innerHTML = vini.responseText;
			if (elem.childNodes.length > 0) {
				elem.normalize();
			
		}
	    }
	}
	vini.send(null);	
}
//
function cambiaTab(tab,contenido){
	var el = document.getElementById("toc");
	var el1 = el.getElementsByTagName("A");
	for (var i=0;i<el1.length;i++) {
		el1[i].style.backgroundColor = '#F4C542';
		el1[i].style.color = '#000000';
	}
	el1[tab].style.backgroundColor = '#EC710C';
	el1[tab].style.color= '#ffffff';
	var elem = document.getElementById("content");
	var vcon = new nuevoAjax();
	var url = contenido;
	cargarContenido(vcon,url,elem);
	
}
function controlaForm(idioma) {

	var er_num = /^([0-9])+$/;	
	var er_mail= /^[A-Za-z][A-Za-z0-9\_\-\._]*@[A-Za-z0-9\_\-_]+\.[A-Za-z0-9_.]+[A-za-z]$/;

	var nombre = document.formulario.nombre.value;
	var empresa = document.formulario.empresa.value;
	var direccion = document.formulario.direccion.value;
	var ciudad = document.formulario.ciudad.value;
	var pais = document.formulario.pais.value;
	var contacto = document.formulario.contacto.value;
	var telefono = document.formulario.telefono.value;
	var email = document.formulario.email.value;
	var consulta = document.formulario.consulta.value;

        if (nombre.length < 1) {
                if (idioma=='es') {
                     alert ("El nombre es obligatorio");
                } else if(idioma=='en') {
                     alert ("The name is obligatory");
                } else if(idioma=='ca') {
                     alert ("El Nom l'obligatori");
                } else if(idioma=='fr') {
                     alert ("Le nom est obligatoire");
                }
		document.formulario.nombre.focus();
		return;
	}
        if (email.length < 1 ) {
                if (idioma=='es') {
                     alert ("El e-mail es obligatorio");
                } else if(idioma=='en') {
                     alert ("The e-mail is obligatory");
                } else if(idioma=='ca') {
                     alert ("El e-mail l'obligatori");
                } else if(idioma=='fr') {
                     alert ("Le e-mail est obligatoire");
                }
		document.formulario.email.focus();
		return;
	}
	if (!er_mail.test(email)) {
                if (idioma=='es') {
                     alert ("El e-mail no es valido");
                } else if(idioma=='en') {
                     alert ("The e-mail is not been worth");
                } else if(idioma=='ca') {
                     alert ("L'e-mail no és valgut ");
                } else if(idioma=='fr') {
                     alert ("Ce qui est e-mail n'est pas valu");
                }
		document.formulario.email.focus();
		return;
	}
	if (consulta.length < 1) {
                if (idioma=='es') {
                     alert ("El mensaje es obligatorio");
                } else if(idioma=='en') {
                     alert ("The message is obligatory");
                } else if(idioma=='ca') {
                     alert ("El message l'obligatori");
                } else if(idioma=='fr') {
                     alert ("Le message est obligatoire");
                }
		document.formulario.consulta.focus();
                return;
	}
//
	var url = "/enviainfo.php?nombre="+nombre+"&empresa="+empresa+"&direccion="+direccion+"&ciudad="+ciudad+"&pais="+pais;
	url = url + "&contacto="+contacto+"&telefono="+telefono+"&email="+email+"&consulta="+consulta+"&lang="+idioma;
	cargaDiv ("cuerpo",'0','',url);
}
//
function controlaSuge(idioma) {

	var er_num = /^([0-9])+$/;	
	var er_mail= /^[A-Za-z][A-Za-z0-9\_\-\._]*@[A-Za-z0-9\_\-_]+\.[A-Za-z0-9_.]+[A-za-z]$/;

	var nombre = document.formulario.nombre.value;
	var empresa = document.formulario.empresa.value;
	var direccion = document.formulario.direccion.value;
	var ciudad = document.formulario.ciudad.value;
	var pais = document.formulario.pais.value;
	var contacto = document.formulario.contacto.value;
	var telefono = document.formulario.telefono.value;
	var email = document.formulario.email.value;
	var consulta = document.formulario.consulta.value;

        if (nombre.length < 1) {
                if (idioma=='es') {
                     alert ("El nombre es obligatorio");
                } else if(idioma=='en') {
                     alert ("The name is obligatory");
                } else if(idioma=='ca') {
                     alert ("El Nom l'obligatori");
                } else if(idioma=='fr') {
                     alert ("Le nom est obligatoire");
                }
		document.formulario.nombre.focus();
		return;
	}
        if (email.length < 1 ) {
                if (idioma=='es') {
                     alert ("El e-mail es obligatorio");
                } else if(idioma=='en') {
                     alert ("The e-mail is obligatory");
                } else if(idioma=='ca') {
                     alert ("El e-mail l'obligatori");
                } else if(idioma=='fr') {
                     alert ("Le e-mail est obligatoire");
                }
		document.formulario.email.focus();
		return;
	}
	if (!er_mail.test(email)) {
                if (idioma=='es') {
                     alert ("El e-mail no es valido");
                } else if(idioma=='en') {
                     alert ("The e-mail is not been worth");
                } else if(idioma=='ca') {
                     alert ("L'e-mail no és valgut ");
                } else if(idioma=='fr') {
                     alert ("Ce qui est e-mail n'est pas valu");
                }
		document.formulario.email.focus();
		return;
	}
	if (consulta.length < 1) {
                if (idioma=='es') {
                     alert ("El mensaje es obligatorio");
                } else if(idioma=='en') {
                     alert ("The message is obligatory");
                } else if(idioma=='ca') {
                     alert ("El message l'obligatori");
                } else if(idioma=='fr') {
                     alert ("Le message est obligatoire");
                }
		document.formulario.consulta.focus();
                return;
	}

//
	var url = "/enviasuge.php?nombre="+nombre+"&empresa="+empresa+"&direccion="+direccion+"&ciudad="+ciudad+"&pais="+pais;
	url = url + "&contacto="+contacto+"&telefono="+telefono+"&email="+email+"&consulta="+consulta+"&lang="+idioma;
	cargaDiv ("cuerpo",'0','',url);
}
//
//
function resultadoAr() {
	var idorg = document.getElementById("idorg").value;
	var iddes = document.getElementById("iddes").value;
	if (idorg=='0') {
	   alert ('Debe Eljir una ciudad Origen');
	   return;
	}
	if (iddes=='0') {
	   alert ('Debe Eljir una Localidad Destino');
	   return;
	}
	cargaDiv ('resultadoar','0','','resultadoar.php?idorg='+idorg+'&iddes='+iddes);
}
//
//
function resultadoEr() {
	var loorg = document.getElementById("loorg").value;
	var lodes = document.getElementById("lodes").value;
	if (loorg=='0') {
	   alert ('Debe Eljir una Localidad Origen');
	   return;
	}
	if (lodes=='0') {
	   alert ('Debe Eljir una Localidad Destino');
	   return;
	}
	cargaDiv ('resultadoer','0','','resultadoer.php?loorg='+loorg+'&lodes='+lodes);
}
// -------------------------------------------------------------------
//		Link boton Next en Foto
//
//
	function Mas(vr,div,tot) {
		var inicio = eval(document.getElementById(vr).value);
        if ((inicio+3) < tot) {
            inicio = inicio + 1;
            var el = document.getElementById(div);
	        var dd = el.getElementsByTagName('DIV');
			for (var i=0; i<tot; i++) {
               if (i >= inicio && i <= (inicio+3)) {
                    dd[i].style.visibility= 'visible';
                    dd[i].style.display = 'block';
               } else {
                    dd[i].style.visibility = 'hidden';
                    dd[i].style.display = 'none';
               }
            }
            el = document.getElementById(div+'c');
            el.innerHTML = "Imangenes "+eval(inicio+1)+" a "+eval(inicio+3)+" de "+tot;
			document.getElementById(vr).value = inicio;
	//
	//		Normaliza el arbol DOM
	//
            el.normalize();
		}
}
// ------------------------------------------------------------------
//             Link boton Previous Foto
//
	function Menos(vr,div,tot) {
		var inicio = eval(document.getElementById(vr).value);
		if ((inicio-1) >= 0) {
            inicio = inicio - 1;
			var el = document.getElementById(div);
	        var dd = el.getElementsByTagName('DIV');
			for (var i=0; i<tot; i++) {
               if (i >= inicio && i <= (inicio+2)) {
                    dd[i].style.visibility= 'visible';
                    dd[i].style.display = 'block';
               } else {
                    dd[i].style.visibility = 'hidden';
                    dd[i].style.display = 'none';
               }
            }
            el = document.getElementById(div+'c');
            el.innerHTML = "Imangenes "+eval(inicio+1)+" a "+eval(inicio+3)+" de "+tot;
			document.getElementById(vr).value = inicio;
        //
		//	Normaliza el Arbol DOM
		//
			el.normalize();
		}
}
// ------------------------------- Prende div de capa ---------------------------------
//
	function capaoscuraon(ele,foto) {
		var fot = new Image();
		fot.src = foto;
		var myWidth = 0, myHeight = 0;
		var myTop =  document.documentElement.scrollTop;

		if( typeof( window.innerWidth ) == 'number' ) {
		  //Non-IE
		  myWidth = window.innerWidth;
		  myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myWidth = document.documentElement.clientWidth;
		  myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		  //IE 4 compatible
		  myWidth = document.body.clientWidth;
		  myHeight = document.body.clientHeight;
		}
		
		var elem = document.getElementById("pantalla");
		elem.style.zIndex = '1000';
		elem.style.visibility = "visible";
		elem.style.top = myTop+'px';
		elem.style.width = myWidth+'px';
		elem.style.height = myHeight+'px';
		var k;
		if (document.images) {
			document.images['imagenrecuadro'].src = fot.src;
			while (document.images['imagenrecuadro'].complete==false){
				retardo();
			}
			var w = document.images['imagenrecuadro'].width;
			var h = document.images['imagenrecuadro'].height;
		}
		var el = document.getElementById(ele);
		el.style.width = (w+5) + 'px';
		el.style.height = (h+20) + 'px';
		el.style.top = (myTop+((myHeight/2)-((h+20)/2)))+'px';
		el.style.left = ((myWidth/2)-((w+5)/2))+'px';
//		el.innerHTML = '';
//		el.innerHTML ="<img id=\"fotov\" src='"+foto+"' alt='' onclick=\"javascript:capaoscuraoff('"+ele+"')\" /><span>Pulse sobre la imagen para cerrar.</span>";
		el.style.visibility = "visible";
		el.style.zIndex = '15000';
    }
	function retardo(){
		setTimeout('retardo()',1000);
	}    
    //
    // ------------------------------- Apaga div de capa ---------------------------------
    //
    function capaoscuraoff(ele) {
        var el = document.getElementById(ele);
//        el.innerHTML = '';
        el.normalize();
        el.style.visibility = 'hidden';
        var elem = document.getElementById("pantalla");
        elem.style.visibility = 'hidden';
    }
    //
    // ----------------------------- Noticias de portada ---------------------------------
    //
    function cargaPortada () {
	cargaDiv ('divmenu','0','0','cargasecciones.php');
	cargaDiv ('cuerpo','0','0','notasportada.php');
    }

