// Documento JavaScript
function cambiaColor(src,color,colorTexto)
{
	src.style.cursor="hand";
	src.bgColor=color;
}
function cambiaColor2(src,color,colorTexto)
{
	src.style.cursor="hand";
	src.bgColor=color;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	obj.visibility=v; }
}

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_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_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_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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//////////////////////////////
/// JAVASCRIPT EMPRESAS
//////////////////////////////

//////////////////////////////
/// VARIABLES 
//////////////////////////////
////// VARIABLES SCROLL


	var num; 

	var upH = 28; var upW = 13; var downH = 28; var downW = 13; 
	var dragH = 55; var dragW = 13; var scrollH = 265; var altocontent=200;
	

	
	var speedinicial = 5; var veloc=0;

//////////////////////////////
/// RUTINAS STANDARD
//////////////////////////////


	function init(modo){
		
		centrar();
		if (modo!=0) eventLoader(); else eventLoader(0);
	}


	var dom = document.getElementById ? true:false;
	var nn4 = document.layers ? true:false;
	var ie4 = document.all ? true:false;
	var nn = document.layers ? true:false;
	var ie = document.all ? true:false;
	
	


	function reloadPage(){
		location.reload();
	}
	
/////////////////////////////////////////////
/// SCROLL VIRTUAL			/////
/// CON BARRA DE DESPLAZAMIENTO		/////
/// Y VELOCIDAD				/////
/////////////////////////////////////////////


speed=speedinicial;

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; 
var clickDown = false; 
var clickDrag = false; 
var clickAbove = false; 
var clickBelow = false; 


var timer = setTimeout("",500); 
var upL; var upT; var downL; var downT; var dragL; var dragT; var rulerL; var rulerT; 
var contentT=0; 
var contentH; var contentClipH; var scrollLength; var startY;


function down(e){
	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; 
		getMouse(e);
		startY = (mouseY - dragT);
		if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
			clickUp = true;
			return scrollUp();
		} else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
			clickDown = true;
			return scrollDown();
		} else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
			clickDrag = true;
			return false;
		} else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
			if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		} else {
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	} else {
		return true;
	}
	
}


function move(e){
	if(clickDrag && contentH > contentClipH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT = eval('-' + contentT);
		
		moveTo();
		
		if(ie4)
			return false;
	} 
}

function getT(){
	if(ie4)
		contentT = document.all.content.style.pixelTop;
	else if(nn4)
		contentT = document.contentClip.document.content.top;
	else if(dom)
		contentT = parseInt(document.getElementById("content").style.top);
}


function up(){
	clearTimeout(timer);
	speed=3;
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}


function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	}
}


function moveTo(){

	if(ie4){
		document.all.content.style.top = contentT;
		document.all.ruler.style.top = dragT;
		document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.contentClip.document.content.top = contentT;
		document.ruler.top = dragT;
		document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("content").style.top = contentT + "px";
		document.getElementById("drag").style.top = dragT + "px";
		document.getElementById("ruler").style.top = dragT + "px";
	}
	
}

function scrollDown(){

	getT();
	
	if(clickBelow){
		if(dragT >= (mouseY-(dragH/2)))
			return up();

	}

	if(clickDown){
			if(contentT > -(contentH - contentClipH)){			
			dragT = dragT + (speed*scrollLength);
			if(dragT > (rulerT + scrollH - dragH))
				dragT = (rulerT + scrollH - dragH);
			
			contentT = contentT - speed;
			if(contentT < -(contentH - contentClipH))
				contentT = -(contentH - contentClipH);
			
			moveTo();
			if (veloc<7) { veloc++;
			} else { speed++; veloc=0;}
			
			timer = setTimeout("scrollDown()",25);
		}
	} 
	return false;
	
}

function scrollUp(){
	getT();
	
	if(clickAbove){
		if(dragT <= (mouseY-(dragH/2)))
			return up();
	}
	
	if(clickUp){
		if(contentT < 0){		
			dragT = dragT - (speed*scrollLength);
			
			if(dragT < (rulerT))
				dragT = rulerT;
				
			contentT = contentT + speed;
			if(contentT > 0)
				contentT = 0;
			
			moveTo();
			if (veloc<15) { veloc++;
			} else { speed++; veloc=0;}
			timer = setTimeout("scrollUp()",25);
		}
	}
	return false;
}

function eventLoader(modo){
	
	if(ie4){
		// Up-arrow X and Y variables
		upL = document.all.up.style.pixelLeft;
		upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		downL = document.all.down.style.pixelLeft;
		downT = document.all.down.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = document.all.drag.style.pixelLeft;
		dragT = document.all.drag.style.pixelTop;		
		// Ruler Y variable
		rulerT = document.all.ruler.style.pixelTop;		
		// Height of content layer and clip layer
		contentH = parseInt(document.all.content.scrollHeight);
		contentClipH = parseInt(document.all.contentClip.style.height);
		
		if ((contentH<altocontent) || (modo==0)) {
			document.all.down.style.visibility = "hidden";
			document.all.ruler.style.visibility = "hidden";
			document.all.drag.style.visibility = "hidden";
			document.all.up.style.visibility = "hidden";
			
		}
		

	}
	else if(nn4){
		// Up-arrow X and Y variables
		upL = document.up.left;
		upT = document.up.top;		
		// Down-arrow X and Y variables
		downL = document.down.left;
		downT = document.down.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		rulerT = document.ruler.top;
		// Height of content layer and clip layer
		contentH = document.contentClip.document.content.clip.bottom;
		contentClipH = document.contentClip.clip.bottom;
		
		if ((contentH<altocontent) || (modo==0)) {
			document.down.visibility = "hidden";
			document.ruler.visibility = "hidden";
			document.drag.visibility = "hidden";
			document.up.visibility = "hidden";
			
		}
		
	}
	else if(dom){
		// Up-arrow X and Y variables
		upL = parseInt(document.getElementById("up").style.left);
		upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		downL = parseInt(document.getElementById("down").style.left);
		downT = parseInt(document.getElementById("down").style.top);
		// Scrollbar X and Y variables
		dragL = parseInt(document.getElementById("drag").style.left);
		dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		rulerT = parseInt(document.getElementById("ruler").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("content").offsetHeight);
		contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
		document.getElementById("content").style.top = 0 + "px";
		
		if ((contentH<altocontent) || (modo==0)) {
			document.getElementById("down").style.visibility = "hidden";
			document.getElementById("ruler").style.visibility = "hidden";
			document.getElementById("drag").style.visibility = "hidden";
			document.getElementById("up").style.visibility = "hidden";
			
			
		}
		
		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	
		
	// Initializes event capturing
	
	if(nn4){
		self.document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	self.document.onmousedown = down;
	self.document.onmousemove = move;
	self.document.onmouseup = up;
}

function reset(){
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	document.onmousedown = down;
	document.onmousemove = move;
	document.onmouseup = up;
}

/////////////////////////////////////////////
/// 	   FUNCIONES DE ANCLAS DHTML  	   //
/////////////////////////////////////////////



function ancla(nombre){
	

	if (document.layers) {
	
		coor=-(eval('document.layers["contentClip"].document.layers["content"].document.layers["'+nombre+'"].top'))

	} else {
	
		coor=-(eval('document.all["'+nombre+'"].top'))
		
	}
	coorA=-(coor)
	coorB=-(parseInt(contentT))
	if (!contentT) contentT=0

	mueve(coorA,coorB);


}


function mueve(XcoorA,XcoorB){
	
	if (document.layers) XcoorA=eval(XcoorA-100)
	
	
	clickDown=true;
	if (XcoorA>XcoorB) {

	depla=eval(XcoorA-XcoorB)
	
	//alert('XcoorA='+XcoorA+';XcoorB='+XcoorB+';depla='+depla)
	
	depla=parseInt(depla/3)
	
	
	
	if (depla>contentH) depla=contentH
		
		for (i=0; i<depla;i++){

			if(contentT > -(contentH - contentClipH)){			
				dragT = dragT + (speed*scrollLength);
				if(dragT > (rulerT + scrollH - dragH))
					dragT = (rulerT + scrollH - dragH);

				contentT = contentT - speed;
				if(contentT < -(contentH - contentClipH))
					contentT = -(contentH - contentClipH);

				

			
			}
		}
		
		moveTo();
	
	} else {	
	
	depla=eval(XcoorB-XcoorA)


	depla=parseInt(depla/3)
	
	///if ((XcoorA<(-2000)) && (document.layers))  alert(depla)
			
		for (i=0; i<depla;i++){
			if(contentT < 0){		
				dragT = dragT - (speed*scrollLength);
				
				if(dragT < (rulerT))
					dragT = rulerT;
					
				contentT = contentT + speed;
				if(contentT > 0)
					contentT = 0;
			}
		}
		
		moveTo();
	}
	
	XcoorA=contentT
	
}

/////////////////////////////////////////////
/// FUNCIONES DE CENTRADO DE LAS PAGINAS   //
/////////////////////////////////////////////

function centrarcapa(nombre,val1,val2){
		if (ie) {
			totalwidth=document.body.clientWidth;
			totalheight=document.body.clientHeight;
			type1='.all.';type2='.style';
		}
		if (nn) {
			totalwidth=window.innerWidth;
			totalheight=window.innerHeight;
			type1='.layers["';type2='"]';
			val1=eval(val1+11)
			val2=eval(val2+8)
		}
		val1=eval(val1+112)
		val2=eval(val2+74)
		eval('document'+type1+nombre+type2+'.left='+val1);
		eval('document'+type1+nombre+type2+'.top='+val2);
}

function centrar(){

	if ((ie && document.body.clientWidth>800) || (nn && window.innerWidth>800)) {
posx=400;posy=160;
				
		centrarcapa('pagina',0,10);
		
		centrarcapa('up',555,140);
		centrarcapa('down',555,396);
		centrarcapa('drag',555,155);
		centrarcapa('ruler',555,155);
		centrarcapa('contentClip',220,140);
		centrarcapa('capabuscar',posx-20,posy-125);
	} else {
		
		if ((document.all) && (document.all["servnivel"])) {  MM_showHideLayers('servnivel','','show')}
		if ((nn) && (document.layers["servnivel"])) { MM_showHideLayers('servnivel','','show')}

	}
	MM_showHideLayers('fondo','','show','pagina','','show','up','','show','down','','show','drag','','show','ruler','','show','contentClip','','show','rastro','','show','capabanner','','show','opcionesabajo','','show');
}

function ValidaForm()
{
	var nombre = document.frmContacto.nombre.value;
	var direccion = document.frmContacto.direccion.value;
	var localidad = document.frmContacto.localidad.value;
	var provincia = document.frmContacto.provincia.value;
	var pais = document.frmContacto.pais.value;
	var email = document.frmContacto.email.value;
	var telefono = document.frmContacto.telefono.value;
	var motivo = document.frmContacto.motivo.value;
	var consulta = document.frmContacto.consulta.value;
	
	if (nombre.length == "" && direccion == "" && localidad == "" && provincia == "" && pais == "" && email == "" && telefono == "" && motivo == "" && consulta == "")
	{
		alert("Debe rellenar los siguientes campos:\n- Nombre\n- Dirección\n- Localidad\n- Provincia\n- País\n- E-Mail\n- Teléfono\n- Motivo de la Consulta\n- Consulta");
		document.getElementById('nombre').style.backgroundColor = '#FFFFCC';
		document.getElementById('direccion').style.backgroundColor = '#FFFFCC';
		document.getElementById('localidad').style.backgroundColor = '#FFFFCC';
		document.getElementById('provincia').style.backgroundColor = '#FFFFCC';
		document.getElementById('pais').style.backgroundColor = '#FFFFCC';
		document.getElementById('email').style.backgroundColor = '#FFFFCC';
		document.getElementById('telefono').style.backgroundColor = '#FFFFCC';
		document.getElementById('motivo').style.backgroundColor = '#FFFFCC';
		document.getElementById('consulta').style.backgroundColor = '#FFFFCC';
		document.frmContacto.nombre.focus();
		return false;
	}
	
	if (nombre.length == "")
	{
		alert("Debe rellenar el campo Nombre");
		document.getElementById('nombre').style.backgroundColor = '#FFFFCC';
		document.frmContacto.nombre.focus();
		return false;
	}
	//else if (nombre.search(/^[0-9]+$/i) == -1)
	else if (!isNaN(nombre))
	{
		alert("El campo Nombre no puede contener números");
		document.getElementById('nombre').style.backgroundColor = '#FFFFCC';
		document.frmContacto.nombre.focus();
		document.frmContacto.nombre.select();
		return false;
	}
	else
	{
		document.getElementById('nombre').style.backgroundColor = '';
	}
	
	if (direccion.length == "")
	{
		alert("Debe rellenar el campo Dirección");
		document.getElementById('direccion').style.backgroundColor = '#FFFFCC';
		document.frmContacto.direccion.focus();
		return false;
	}
	else
	{
		document.getElementById('direccion').style.backgroundColor = '';
	}
	
	if (localidad.length == "")
	{
		alert("Debe rellenar el campo Localidad");
		document.getElementById('localidad').style.backgroundColor = '#FFFFCC';
		document.frmContacto.localidad.focus();
		return false;
	}
	//else if (localidad.search(/^[0-9]+$/i) == -1)
	else if (!isNaN(localidad))
	{
		alert("El campo Localidad no puede contener números");
		document.getElementById('localidad').style.backgroundColor = '#FFFFCC';
		document.frmContacto.localidad.focus();
		document.frmContacto.localidad.select();
		return false;
	}
	else
	{
		document.getElementById('localidad').style.backgroundColor = '';
	}
	
	if (provincia.length == "")
	{
		alert("Debe rellenar el campo Provincia");
		document.getElementById('provincia').style.backgroundColor = '#FFFFCC';
		document.frmContacto.provincia.focus();
		return false;
	}
	else if (!isNaN(provincia))
	{
		alert("El campo Provincia no puede contener números");
		document.getElementById('provincia').style.backgroundColor = '#FFFFCC';
		document.frmContacto.provincia.focus();
		document.frmContacto.provincia.select();
		return false;
	}
	else
	{
		document.getElementById('provincia').style.backgroundColor = '';
	}
	
	if (pais.length == "")
	{
		alert("Debe rellenar el campo País");
		document.getElementById('pais').style.backgroundColor = '#FFFFCC';
		document.frmContacto.pais.focus();
		return false;
	}
	else if (!isNaN(pais))
	{
		alert("El campo País no puede contener números");
		document.getElementById('pais').style.backgroundColor = '#FFFFCC';
		document.frmContacto.pais.focus();
		document.frmContacto.pais.select();
		return false;
	}
	else
	{
		document.getElementById('pais').style.backgroundColor = '';
	}
	
	if (email.length == "")
	{
		alert("Debe rellenar el campo E-Mail");
		document.getElementById('email').style.backgroundColor = '#FFFFCC';
		document.frmContacto.email.focus();
		return false;
	}
	else if (!(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1))
	{
		alert("El E-Mail introducido no es válido");
		document.getElementById('email').style.backgroundColor = '#FFFFCC';
		document.frmContacto.email.focus();
		document.frmContacto.email.select();
		return false;
	}
	else
	{
		document.getElementById('email').style.backgroundColor = '';
	}
	
	if (telefono.length == "")
	{
		alert("Debe rellenar el campo Teléfono");
		document.getElementById('telefono').style.backgroundColor = '#FFFFCC';
		document.frmContacto.telefono.focus();
		return false;
	}
	else if (!/^([0-9])*$/.test(telefono))
	{
		alert("El campo Teléfono no puede contener letras");
		document.getElementById('telefono').style.backgroundColor = '#FFFFCC';
		document.frmContacto.telefono.focus();
		document.frmContacto.telefono.select();
		return false;
	}
	else
	{
		document.getElementById('telefono').style.backgroundColor = '';
	}
	
	if (motivo.length == "")
	{
		alert("Debe rellenar el campo Motivo de la Consulta");
		document.getElementById('motivo').style.backgroundColor = '#FFFFCC';
		document.frmContacto.motivo.focus();
		return false;
	}
	else
	{
		document.getElementById('motivo').style.backgroundColor = '';
	}
	
	if (consulta == "")
	{
		alert("Debe rellenar el campo Consulta");
		document.getElementById('consulta').style.backgroundColor = '#FFFFCC';
		document.frmContacto.consulta.focus();
		return false;
	}
	else
	{
		document.getElementById('consulta').style.backgroundColor = '';
	}
	
	return true;
}
