// JavaScript Document

function cargaPagina(url,div,parametros)
{
	new Ajax(url,{method: 'post', postBody:parametros, update:div, evalScripts: true}).request();

	/*new Request(
	{
		method: 'post',
		url: url,
		noCache: true,
		evalScripts: true,		
		onSuccess: function(texto){
		$(div).innerHTML = texto;}
	}).send(parametros);*/
}
//------------------------------------------------------------------------------------------//
function Comprobar()
{
	var error = "";
	
	if($('txtnombre').value=="" && error == "")
	{
		error = "Es obligatorio poner el nombre.";
		$('txtnombre').focus();
	}
	if(($('txtmail').value == "" || !validateEmail($('txtmail').value)) && error == "")
	{
		error = "El e-mail de respuesta no es valido.";
		$('txtmail').focus();
	}
	if(($('txttelefono').value == "" || !validaTelefono($('txttelefono').value)) && error == "")
	{
		error = "Es obligatorio poner el telefono.";
		$('txttelefono').focus();
	}
	if($('txtcomentarios').value=="" && error == "")
	{
		error = "Es obligatorio poner el comentario.";
		$('txtcomentarios').focus();
	}
	if(!($('AceptarCondiciones').checked) && error == "")
	{
		error = "Debe aceptar las condiciones para poder continuar.";
		$('AceptarCondiciones').focus();
	}

	if(error != "")
		alert(error);
	else
	{
		//location.href="send.php?nombre=" + $('txtnombre').value + "&mail=" + $('txtmail').value + "&telefono=" + $('txttelefono').value + "&comentario=" $('txtcomentarios').value;
		document.form1.submit();
	}
}
//------------------------------------------------------------------------------------------//
function validateEmail(txtmail)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(txtmail))
    	return true;
	else
    	return false;
}
//------------------------------------------------------------------------------------------//
function validaTelefono(txttelefono)
{
	var tfno= parseInt(txttelefono);
	var error = "";
	if ( isNaN(tfno) )
		error="q";
	else
	{
		if ( !( (txttelefono >= 900000000) && (txttelefono < 1000000000) || (txttelefono >= 600000000) && (txttelefono < 700000000) ) )  
			error="q";
	}

	if(error == "")
		return true;
	return false;
}
//------------------------------------------------------------------------------------------//
function ComprobarFormGrande()
{
	var error = "";
	
	if($('txtnombre').value=="" && error == "")
	{
		error = "Es obligatorio poner el nombre.";
		$('txtnombre').focus();
	}
	if($('txtapellidos').value=="" && error == "")
	{
		error = "Es obligatorio poner los apellidos.";
		$('txtapellidos').focus();
	}
	if(($('txtmail').value == "" || !validateEmail($('txtmail').value)) && error == "")
	{
		error = "El e-mail de respuesta no es valido.";
		$('txtmail').focus();
	}
	if(($('txttelefono').value == "" || !validaTelefono($('txttelefono').value)) && error == "")
	{
		error = "Es obligatorio poner el telefono.";
		$('txttelefono').focus();
	}
	if($('txtasunto').value=="" && error == "")
	{
		error = "Es obligatorio poner el asunto.";
		$('txtasunto').focus();
	}
	if($('txtcomentarios').value=="" && error == "")
	{
		error = "Es obligatorio poner el comentario.";
		$('txtcomentarios').focus();
	}
	if(!($('AceptarCondiciones').checked) && error == "")
	{
		error = "Debe aceptar las condiciones para poder continuar.";
		$('AceptarCondiciones').focus();
	}
	if(error != "")
		alert(error);
	else
	{
		//location.href="send.php?nombre=" + $('txtnombre').value + "&mail=" + $('txtmail').value + "&telefono=" + $('txttelefono').value + "&comentario=" $('txtcomentarios').value;
		document.form1.submit();
	}
}
//------------------------------------------------------------------------------------------//
var AltoPantalla = screen.Height / 2;
var AnchoPantalla = screen.Width / 2;

function AbrePopupConScroll(Ruta, Nombre, Ancho, Alto) 
{
	var AltoMostrar = AltoPantalla - (Alto / 2);
	var AnchoMostrar = AnchoPantalla - (Ancho / 2);	
	var PopUpW = window.open(Ruta, Nombre, "width=" + Ancho + ", height=" + Alto + ", top=" + AltoMostrar + ", left=" + AnchoMostrar + ", scrollbars=yes, titlebar=no, menubar=no, location=no");
	PopUpW.focus();
	return false;
}
//------------------------------------------------------------------------------------------//
function limpiar()
{
	$('txtnombre').value = "";
	$('txtmail').value = "";
	$('txttelefono').value = "";
	$('txtcomentarios').value = "";
	$('AceptarCondiciones').checked = false;
}
//------------------------------------------------------------------------------------------//
var cambioFoto;
var fotoActual = 1;
function cargaFotos()
{
	for (var i = 2; i<=3; i++)
	{
		//$('foto' + i).fade(0);
		//$('foto' + i).style.visibility = 'hidden';
	}
	cambioFoto = setTimeout("cambiaFoto()", 5000);
}
//------------------------------------------------------------------------------------------//
function cambiaFoto()
{
	clearTimeout(cambioFoto);
	var nuevaFoto = fotoActual + 1;
	if(nuevaFoto > 3)
		nuevaFoto = 1;
	
	//var myFx1 = new Fx.Tween($('texto' + nuevaFoto), [, options]);
	//var myFx2 = new Fx.Tween($('texto' + fotoActual), [, options]);
	//myFx1.set('opacity', {duration: 2000}).start(0);
    //myFx2.set('opacity', {duration: 2000}).start(1);
	//$('foto' + nuevaFoto).style.visibility = 'visible';
	$('foto' + fotoActual).fade(0);
	$('foto' + nuevaFoto).fade(1);	
	
	fotoActual = nuevaFoto;
	cambioFoto = setTimeout("cambiaFoto()", 5000);
}
//------------------------------------------------------------------------------------------//
//------------------------------------ MENÚ LIMPIEZA ---------------------------------------//
//------------------------------------------------------------------------------------------//
var toggleActual = '';
var mySlideEmpresas;
var mySlideComunidades;
var mySlideColegios;
var mySlideRestauracion;
var mySlideIndustria;
var mySlideCentrosComerciales;

function abreSubMenu(a)
{
	var o={};
	var b=new Fx.Elements($(a),{wait:false,duration:300,transition:Fx.Transitions.Back.easeOut});

		if($(a).getStyle("height").toInt()==21)
		{
			o[0]={height:[21,21]};
			$(a).className="celda_izquierda";
		}
		else
		{
			o[0]={height:[21,21]};
			$(a).className="celda_izquierda";
		}
		
		b.start(o);
	
	$("sub"+a).setStyle("display","block");
	
	if(toggleActual!="" && toggleActual!=a)
	{
		ocultaSubMenu();
		toggleActual=a;
	}
	else if(toggleActual==a)
		toggleActual="";
	else
		toggleActual=a;
	eval("mySlide"+a+".toggle();")
}
//------------------------------------------------------------------------------------------//
function ocultaSubMenu()
{
	var o={};
	var a=new Fx.Elements($(toggleActual),{wait:false,duration:300,transition:Fx.Transitions.Back.easeOut});

		if($(toggleActual).getStyle("height").toInt()==21)
		{
			o[0]={height:[21,21]};
			$(toggleActual).className="celda_izquierda";
		}
		else
		{
			o[0]={height:[21,21]};
			$(toggleActual).className="celda_izquierda";
		}

		a.start(o);

	eval("mySlide"+toggleActual+".toggle();")
}
//------------------------------------------------------------------------------------------//
function inicializa(a)
{
	var menuAbierto = $('menuAbierto').value;

	mySlideEmpresas=new Fx.Slide('subEmpresas');
	mySlideComunidades=new Fx.Slide('subComunidades');
	mySlideColegios=new Fx.Slide('subColegios');
	mySlideRestauracion=new Fx.Slide('subRestauracion');
	mySlideIndustria=new Fx.Slide('subIndustria');
	mySlideCentrosComerciales=new Fx.Slide('subCentrosComerciales');

	if(menuAbierto != 'Empresas')
		mySlideEmpresas.hide();
	if(menuAbierto != 'Comunidades')
		mySlideComunidades.hide();
	if(menuAbierto != 'Colegios')
		mySlideColegios.hide();
	if(menuAbierto != 'Restauracion')
		mySlideRestauracion.hide();
	if(menuAbierto != 'Industria')
		mySlideIndustria.hide();
	if(menuAbierto != 'CentrosComerciales')
		mySlideCentrosComerciales.hide();

	toggleActual = menuAbierto;
}
//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//

//------------------------------------------------------------------------------------------//
//------------------------------------- MENÚ PLAGAS ----------------------------------------//
//------------------------------------------------------------------------------------------//
var toggleActual_2 = '';
var mySlideDesinsectacion;
var mySlideDesratizacion;
var mySlideDesinfeccion;
var mySlideOtrasPlagas;
var mySlideControlPlagas;


function abreSubMenu_2(a)
{
	var o={};
	var b=new Fx.Elements($(a),{wait:false,duration:300,transition:Fx.Transitions.Back.easeOut});

		if($(a).getStyle("height").toInt()==21)
		{
			o[0]={height:[21,21]};
			$(a).className="celda_izquierda2";
		}
		else
		{
			o[0]={height:[21,21]};
			$(a).className="celda_izquierda2";
		}
		
		b.start(o);
	
	$("sub"+a).setStyle("display","block");
	
	if(toggleActual_2!="" && toggleActual_2!=a)
	{
		ocultaSubMenu_2();
		toggleActual_2=a;
	}
	else if(toggleActual_2==a)
		toggleActual_2="";
	else
		toggleActual_2=a;
	eval("mySlide"+a+".toggle();")
}
//------------------------------------------------------------------------------------------//
function ocultaSubMenu_2()
{
	var o={};
	var a=new Fx.Elements($(toggleActual_2),{wait:false,duration:300,transition:Fx.Transitions.Back.easeOut});

		if($(toggleActual_2).getStyle("height").toInt()==21)
		{
			o[0]={height:[21,21]};
			$(toggleActual_2).className="celda_izquierda2";
		}
		else
		{
			o[0]={height:[21,21]};
			$(toggleActual_2).className="celda_izquierda2";
		}

		a.start(o);

	eval("mySlide"+toggleActual_2+".toggle();")

}
//------------------------------------------------------------------------------------------//
function inicializa_2(a)
{
	var menuAbierto_2 = $('menuAbierto_2').value;
	
	mySlideDesinsectacion=new Fx.Slide('subDesinsectacion');
	mySlideDesratizacion=new Fx.Slide('subDesratizacion');
	mySlideDesinfeccion=new Fx.Slide('subDesinfeccion');
	mySlideOtrasPlagas=new Fx.Slide('subOtrasPlagas');
	mySlideControlPlagas=new Fx.Slide('subControlPlagas');

	if(menuAbierto_2 != 'Desinsectacion')
		mySlideDesinsectacion.hide();
	if(menuAbierto_2 != 'Desratizacion')
		mySlideDesratizacion.hide();
	if(menuAbierto_2 != 'Desinfeccion')
		mySlideDesinfeccion.hide();
	if(menuAbierto_2 != 'OtrasPlagas')
		mySlideOtrasPlagas.hide();
	if(menuAbierto_2 != 'ControlPlagas')
		mySlideControlPlagas.hide();

	toggleActual_2 = menuAbierto_2;
}
//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//
function abreSubMenu02 (id, valor)
{
	
	$(id).style.display = 'inline';
	
	/*if(valor == 1)
	{
		$(id).style.display = 'inline';
		valor = 2;
	}
	else
		$(id).style.display = 'none';*/
	
	
	//position:absolute; position:fixed; position:inherit; position:relative; position:static;
	//$(id).get.height
}
//------------------------------------------------------------------------------------------//
function cambiaFondoPlagas (id, id2, value)
{
	if(value == 1)
	{
		$(id).style.background = 'url(/imagenes/menu_verde_textoSeleccionado.gif)';
		$(id2).style.color = '#FFFFFF';
	}
	else
	{
		$(id).style.background = 'url(/imagenes/menu_verde_texto.gif)';
		$(id2).style.color = '#000000';
	}
}
//------------------------------------------------------------------------------------------//
function cambiaFondoPlagas2 (id, value)
{
	if(value == 1)
	{
		$(id).style.background = 'url(/imagenes/menu_verde_textoSeleccionado.gif)';
		$(id).style.color = '#FFFFFF';
	}
	else
	{
		$(id).style.background = 'url(/imagenes/menu_verde_texto.gif)';
		$(id).style.color = '#000000';
	}
}
//------------------------------------------------------------------------------------------//
function cambiaFondoLimpieza (id, value)
{
	if(value == 1)
	{
		$(id).style.background = 'url(/imagenes/menu_morado_textoSeleccionado.gif)';
		$(id).style.color = '#FFFFFF';
	}
	else
	{
		$(id).style.background = 'url(/imagenes/menu_morado_texto.gif)';
		$(id).style.color = '#535353';
	}
}
//------------------------------------------------------------------------------------------//
function cambiaImagenSubseccion (tipo, subseccion)
{
	//***** onMouseOver *****
	if(tipo == 1)
	{
		$('div_menuSubSeccion_'+subseccion).className = 'div_menuSubSeccion2';
	}
	//***** onMouseOut *****
	else if(tipo == 2)
	{
		$('div_menuSubSeccion_'+subseccion).className = 'div_menuSubSeccion';
	}
	
}



