
// ****************************************************
// *** 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)
{		

	if(formulario.nombre_comercial.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir el nombre comercial</span>';
		// seleccionamos el campo incorrecto
		formulario.nombre_comercial.focus();
		return false;
	}

	if(formulario.actividad_comercial.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir el actividad comercial</span>';
		// seleccionamos el campo incorrecto
		formulario.actividad_comercial.focus();
		return false;
	}
	
	if(formulario.persona_contacto.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir la persona de contacto</span>';
		// seleccionamos el campo incorrecto
		formulario.persona_contacto.focus();
		return false;
	}
	
	if(formulario.direccion.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir la direcci&oacute;n</span>';
		// seleccionamos el campo incorrecto
		formulario.direccion.focus();
		return false;
	}	
	
	if(formulario.provincia.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir una provincia</span>';
		// seleccionamos el campo incorrecto
		formulario.provincia.focus();
		return false;
	}
	
	if(formulario.poblacion.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir una poblacion</span>';
		// seleccionamos el campo incorrecto
		formulario.poblacion.focus();
		return false;
	}
	
	if(formulario.codigo_postal.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir el codigo postal</span>';
		// seleccionamos el campo incorrecto
		formulario.codigo_postal.focus();
		return false;
	}
	
	if(formulario.num_telefono.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir el numero de telefono</span>';
		// seleccionamos el campo incorrecto
		formulario.num_telefono.focus();
		return false;
	}
	
	if(formulario.email.value == 0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir un email</span>';
		// seleccionamos el campo incorrecto
		formulario.email.focus();
		return false;
	}
	
	if(formulario.mensaje.value ==0)
	{
		document.getElementById("ferror").innerHTML = '<span style="color:#FF0000">Tiene que escribir un mensaje</span>';
		// seleccionamos el campo incorrecto
		formulario.mensaje.focus();
		return false;
	}	
			
	useAjax("formulario.php?enviar=1&nombre_comercial="+form.nombre_comercial.value+"&nif_cif="+form.nif_cif.value+"&actividad_comercial="+form.actividad_comercial.value+"&persona_contacto="+form.persona_contacto.value+"&direccion="+form.direccion.value+"&provincia="+form.provincia.value+"&poblacion="+form.poblacion.value+"&codigo_postal="+form.codigo_postal.value+"&num_telefono="+form.num_telefono.value+"&email="+form.email.value+"&mensaje="+form.mensaje.value+"&sitio_web="+form.sitio_web.value,"cargar","");	
	//setTimeout("fComprobarEnvio();",2000);	
	
	alert("Formulario enviado correctamente. Nos pondremos en contacto con Usted lo antes posible. Gracias");
	this.location.href="http://www.qcollection.es";
}

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

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%'*/
			};			
		}
	});
}

