
// ****************************************************
// *** sergio@disgol.com 5/06/09                     ***
// ****************************************************


var TiendaSeleccionada="";

var lengua = new CrearIdioma("es");

function CrearIdioma(lng) 
{
	this.idioma = lng;	
}

function fStart()
{	
	if (navigator.appName.indexOf("Explorer") != -1)
	{	
		oAjax.requestSyncro();		
	}	
		
	setTimeout("useAjax('Menu.php?idioma=es','Menu',CargandoLinea);",100);
	setTimeout("useAjax('Directorio-Franquicias-de-Golosinas.php?vacio=0&idioma=es','Contenido',CargandoLinea);",1000);
					
	if (navigator.appName.indexOf("Explorer") != -1)
	{		
		oAjax.requestAsyncro();
	}
	
}

function fCargar(url,div)
{	
	if (navigator.appName.indexOf("Explorer") != -1)
	{	
		oAjax.requestSyncro();
	}	
		
	useAjax(url+".php?vacio=0&VentanaNueva=0&idioma="+lengua.idioma,div,CargandoLinea);
		
	if(url=="Tiendas-de-Golosinas-Franquicia")
	{
		fCargarFotos('Fotos-Franquicias','DivTienda','gandia');
	}
		
	if (navigator.appName.indexOf("Explorer") != -1)
	{		
		oAjax.requestAsyncro();
	}
}

function fCargarMapa()
{	

	//document.getElementById("select_tienda").style.visibility="hidden";
	useAjax("Fotos-Franquicias.php?tienda=mapa_google","divTienda",CargandoLinea);
}

function fCargarFotos(url,div,tienda)
{	
	TiendaSeleccionada=tienda;
		
	if (navigator.appName.indexOf("Explorer") != -1)
	{		
		oAjax.requestSyncro();
	}
		
	url=url + ".php?tienda=" + tienda + "&idioma=" + lengua.idioma;	
	useAjax(url,div,CargandoLinea);
	
	if (navigator.appName.indexOf("Explorer") != -1)
	{
		oAjax.requestAsyncro();
	}	
	
}

function fAmpliarImagen(img,maxfoto,foto_suelta,tienda_noticia)
{
	
	var divshadow = document.getElementById("divShadow");	
	divshadow.style.visibility="visible";
	
	var divFotos  = document.getElementById("divFotos");
	
	if (navigator.appName.indexOf("Explorer") == -1)
	{
			divFotos.style.width="600";
	}

	divFotos.style.visibility="visible";

	var imgsig=parseInt(img)+1;
	var imgant=parseInt(img)-1;

	if (navigator.appName.indexOf("Explorer") != -1)
	{	
		oAjax.requestSyncro();
	}
	
	useAjax("../Fotos-Grande-Franquicias.php?img="+img+"&imgsig="+imgsig+"&imgant="+imgant+"&tienda="+TiendaSeleccionada+"&maxfoto="+maxfoto+"&foto_suelta="+foto_suelta+"&tienda_noticia="+tienda_noticia,"divFotos",CargandoBall);
		
	if (navigator.appName.indexOf("Explorer") != -1)
	{		
		oAjax.requestAsyncro();
	}	
}

function fOcultarImagen()
{
	document.getElementById("divFotos").style.visibility="hidden";
	document.getElementById("divShadow").style.visibility="hidden";
	//document.getElementById("divFotosFondo").style.visibility="hidden";
}

function fMaximizarVentana()
{
	window.moveTo(0,0);
	if (document.all) 
	{
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) 
		{
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

function fComprobarNavegador()
{
	if (navigator.appName.indexOf("Explorer") == -1)
	{	
		alert("Recomendamos utilizar Internet Explorer 7 o superior.");
	}
}

//Cambiamos el idioma
function fCambiarIdioma(lng)
{		
	lengua.idioma = lng;		
		
	if (navigator.appName.indexOf("Explorer") != -1)
	{	
		oAjax.requestSyncro();
	}
	
	//useAjax('Menu.php?idioma='+lng,'Menu',CargandoLinea);
	setTimeout("",100);
	
	this.location.href = this.location.href + "?a=a&idioma="+lng;
			
	if (navigator.appName.indexOf("Explorer") != -1)
	{		
		oAjax.requestAsyncro();
	}
}

function fMostrarFormulario()
{	
	document.getElementById("divFormulario").style.visibility = "visible";
	document.getElementById("divShadowFormulario").style.visibility = "visible";

	useAjax("Formulario-Franquicias.php?vacio=0&VentanaNueva=0&idioma="+lengua.idioma,"divFormulario",CargandoLinea);
}

function fOcultarFormulario()
{
	document.getElementById("divFormulario").style.visibility = "hidden";
	document.getElementById("divShadowFormulario").style.visibility = "hidden";
}

function fMostrarAlquiler(value)
{	
	if(value==0)
	{
		document.getElementById("tipo_local_pro").disabled=true;
		document.getElementById("tipo_local_alq").disabled=true;
		document.getElementById("metros").disabled=true;
		document.getElementById("ubicacion").disabled=true;
	}
	else if(value==1)
	{
		document.getElementById("tipo_local_pro").disabled=false;
		document.getElementById("tipo_local_alq").disabled=false;
		document.getElementById("metros").disabled=false;
		document.getElementById("ubicacion").disabled=false;
	}
}

function fValidarFormulario(form)
{		
	var texto_email;
	
	if(form.nombre.value == ''){
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir su nombre y apellidos</span>';		
		form.nombre.focus();
		return false;
	}
	if(trim(form.telefono.value) == ''){	
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir el numero de telefono</span>';		
		form.telefono.focus();
		return false;
	}
	if ((form.email.value.indexOf ('@', 0) == -1)||(form.email.value.length < 5) || (form.email.value.indexOf ('.', 0) == -1)) {
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir un email</span>';		
		form.email.focus();
		return false;
	}
	
	var local = document.getElementById("local").checked;
	var tipo_alquilado = document.getElementById("tipo_local_alq").checked;				
	var tipo_propiedad = document.getElementById("tipo_local_pro").checked;				
	
	if(local == true){
			if(tipo_propiedad==true)
			{
				var tipo_local = document.getElementById("tipo_local_pro").checked;				
			}
			else
			{
				var tipo_local = document.getElementById("tipo_local_alq").checked;				
			}
			var indice = document.getElementById("ubicacion").selectedIndex;
			var ubicacion = document.getElementById("ubicacion").options[indice].value;			
	}
	
	fEnviarFormulario(form.nombre.value,form.telefono.value,form.movil.value,form.email.value,form.apertura.value,local,tipo_local,ubicacion,form.metros.value,form.mensaje.value);
}

function trim(cad)   
{   
	return cad.replace(/^\s+|\s+$/g,"");   
}

function fEnviarFormulario(nombre,telefono,movil,email,apertura,local,tipo,ubicacion,metros,mensaje)
{	
	
	if(local==true)
	{		
		if(tipo==true)
		{
			tipo="Alquilado";
		}
		else
		{			
			tipo="Propiedad";
		}
		local="SI";
	}
	else
	{
		local="NO";
	}
	//this.location.href="Nuevas-Franquicias-de-Golosinas-Presupuesto.php?enviar=1&vacio=0&VentanaNueva=0&idioma="+lengua.idioma+"&nom="+nombre+"&tel="+telefono+"&mov="+movil+"&email="+email+"&apertura="+apertura+"&local="+local+"&tipo="+tipo+"&ubi="+ubicacion+"&metros="+metros+"&mens="+mensaje;
	useAjax("Nuevas-Franquicias-de-Golosinas-Presupuesto.php?enviar=1&vacio=0&VentanaNueva=0&idioma="+lengua.idioma+"&nom="+nombre+"&tel="+telefono+"&mov="+movil+"&email="+email+"&apertura="+apertura+"&local="+local+"&tipo="+tipo+"&ubi="+ubicacion+"&metros="+metros+"&mens="+mensaje,"cargar",CargandoLinea);	
	//setTimeout("fComprobarEnvio();",2000);		
	alert("Formulario enviado correctamente. Nos pondremos en contacto con Usted lo antes posible. Gracias");
	this.location.href="http://www.duldi.com/Franquicias-Tiendas-de-Golosinas.php";

}

function fComprobarEnvio()
{
	
	var valor_envio_formulario = document.getElementById("valor_envio_formulario").value;
	if(valor_envio_formulario==1)
	{
		setTimeout("fOcultarFormulario();",3000);	
	}	
}
function fCargarNoticia(url)
{
	document.getElementById("divNoticia").style.visibility = "visible";
	document.getElementById("divShadowFormulario").style.visibility = "visible";

	useAjax(url+".php?idioma="+lengua.idioma,"divNoticia",CargandoLinea);	
}

function fOcultarNoticas()
{	
	document.getElementById("divNoticia").style.visibility = "hidden";
	document.getElementById("divShadowFormulario").style.visibility = "hidden";
}

function fBola()
{
	var target = $('target');
	var fx = new Fx.Styles(target, {duration: 1500, wait: false});
	var box = $('box');

	target.setStyles({			
		/*'top': box.getTop(),
		'left': box.getLeft()*/
		'left': '66%',
		'top': '83%'		
	});	 

	var selectTransition = $('fxTransition');	
	var selectEase = $('fxEase');
	var durationInput = $('duration');

	var result = $('result');

	$$(selectEase, selectTransition).addEvent('change', function(){
		var transition = selectTransition.getValue();

		var ease = selectEase.getValue();
		fx.options.transition = Fx.Transitions[transition][ease];
		transition = 'Fx.Transitions.' + transition + '.' + ease;

		result.setHTML(transition);
	});

	selectEase.fireEvent('change');

	durationInput.addEvent('blur', function(){
		fx.options.duration = parseFloat(durationInput.getValue());	
	});

	/*box.addEvent('mousedown', function(event){
		event = new Event(event);
		fx.start({
			'top': [event.page.y - 25],
			'left': [event.page.x - 25]
		});
		event.stop();
	});*/
	 
	new Drag.Base(target, {
	 
		onComplete: function(){			
			fx.start(this.s);
			
		},		
		
		onStart: function(){					
			
			this.s = {			
				'left': this.element.getLeft(),
				'top': this.element.getTop()
				/*'left': '62%',
				'top': '77%'*/
			};			
		}
	});
}
