// JavaScript Document
function cargaAcerca()
{
	//If using image buttons as controls, Set image buttons' image preload here true
	//(use false for no preloading and for when using no image buttons as controls):
	var preload_ctrl_images=true;
	
	//And configure the image buttons' images here:
	var previmg='left.gif';
	var stopimg='stop.gif';
	var playimg='play.gif';
	var nextimg='right.gif';
	
	var slides=[]; //FIRST SLIDESHOW
	//configure the below images and descriptions to your own. 
	slides[0] = ["imagenes/acerca_plage/01.jpg", "Ambiente 1"];
	slides[1] = ["imagenes/acerca_plage/02.jpg", "Ambiente 2"];
	slides[2] = ["imagenes/acerca_plage/03.jpg", "Ambiente 3"];
	slides[3] = ["imagenes/acerca_plage/04.jpg", "Ambiente 4"];
	slides[4] = ["imagenes/acerca_plage/05.jpg", "Ambiente 5"];
	slides[5] = ["imagenes/acerca_plage/06.jpg", "Ambiente 6"];
	//above slide show uses only the defaults
	
	new inter_slide(slides);
}
function cargaPagina(url,div,parametros)
{
	new Ajax(url,{method: 'post', postBody:parametros, update:div}).request();
}



var numberslide=new Array()
/*numberslide[0]=["imagenes/productos/secciones/flor_ficha.jpg", ""]
numberslide[1]=["imagenes/productos/secciones/flor_ficha_02.jpg", ""]
numberslide[2]=["imagenes/productos/secciones/flor_ficha_03.jpg", ""]
numberslide[3]=["imagenes/productos/secciones/flor_ficha_04.jpg", ""]*/

var mylinktarget="" //specify optional link target
var mylinkcolor="navy" //specify default color of number links
var mylinkcolorSelected="red" //specify color of selected links

var imgborderwidth=0 //specify border of image slideshow

/////Stop customizing here////////////////

var preloadit=new Array()
for (i=0;i<numberslide.length;i++){
preloadit[i]=new Image()
preloadit[i].src=numberslide[i][0]
}

var currentindex=""

function changeslides(which)
{
	var imghtml=""
	if(which=="initial")
	{
		if($('activo').value == 1)
			var cadena = $('imagenes').value;
		if($('activo').value == 2)
			var cadena = $('ampliadas').value;
		if($('activo').value == 3)
			var cadena = $('ambiente').value;
		
		numberslide.length = 0;
		var imagenes = cadena.split(";");
		for(var i =0; i<= imagenes.length -1 ; i++)
			numberslide[i]=[imagenes[i], ""]
		if(($('activo').value == 3 || $('activo').value == 2) && i==1)
			$('botonSiguiente2').style.display = 'none';
	}
	currentindex=(which=="initial")? 0 : parseInt(which)
	var mode=(which=="initial")? "initial" : ""
	var which=(mode=="initial")? numberslide[0] : numberslide[which]
	if (which[1]!="")
	imghtml='<a href="'+which[1]+'" target="'+mylinktarget+'">'
	if($('activo').value == 1)
		imghtml+='<img src="'+which[0]+'" border="'+imgborderwidth+'">'
	else
	{
		imghtml+='<img src="'+which[0]+'" border="'+imgborderwidth+'" height="242">';
		$('infoFoto').innerHTML = 'foto(' + (currentindex+1) + '/' + numberslide.length + ')';
	}
	if (which[1]!="")
	imghtml+='</a>'
	
	if($('activo').value == 1)
		document.getElementById("imagecontainer").innerHTML=imghtml
	else
		document.getElementById("album").innerHTML=imghtml
	//changecolors()
}

function createnumbers(){
document.write('<a href="javascript:changeslides(0)" style="color:'+mylinkcolorSelected+'">0</a> ')
for (i=1; i< numberslide.length; i++)
document.write('<a href="javascript:changeslides(\''+i+'\')">'+i+'</a> ')
}

function changecolors(){
var numberobj=document.getElementById("numberDiv")
numberlinks=numberobj.getElementsByTagName("A")
for (i=0; i<=currentindex; i++)
numberlinks[i].style.color=mylinkcolorSelected
for (i=currentindex+1; i<numberslide.length; i++)
numberlinks[i].style.color=mylinkcolor
}

function goforward()
{
	if (currentindex <numberslide.length-1)
	{
		if($('activo').value == 1)
			$('botonAnterior').style.display = 'inline';
		else
			$('botonAnterior2').style.display = 'inline';
		changeslides(currentindex+1)
	}
	if (currentindex == numberslide.length-1)
	{
		if($('activo').value == 1)
			$('botonSiguiente').style.display = 'none';
		else
			$('botonSiguiente2').style.display = 'none';
	}
}

function goback()
{
	if (currentindex != 0)
	{
		if($('activo').value == 1)
			$('botonSiguiente').style.display = 'inline';
		else
			$('botonSiguiente2').style.display = 'inline';
		changeslides(currentindex-1)
	}
	if (currentindex == 0)
	{
		if($('activo').value == 1)
			$('botonAnterior').style.display = 'none';
		else
			$('botonAnterior2').style.display = 'none';
	}
}
function cierraFotos()
{
	$('div_fondo').effect('opacity').custom(0.9,0);
	$('div_opaco').effect('opacity').custom(1,0);	
	$('activo').value = 1;
	changeslides('initial');
}
function abreFotos(cual)
{
	var cadena = "";
	$('div_fondo').effect('opacity').custom(0,0.9);
	$('div_opaco').effect('opacity').custom(0, 1);	
	$('botonAnterior2').style.display = 'none';
	$('botonSiguiente2').style.display = 'inline';
	$('activo').value = cual;
	/*numberslide.length = 0;
	if(cual==2)
		cadena = $('ampliadas').value;
	else
		cadena = $('ambiente').value;
	var imagenes = cadena.split(";");
	for(var i =0; i<= imagenes.length -1 ; i++)
		numberslide[i]=[imagenes[i], ""]*/
	changeslides('initial');
}
function buscaProducto()
{
	if($('buscar').value=='' || $('buscar').value=='Buscar Palabras o referencia')	
	{
		alert('Introduzca la palabra o referencia a buscar');
		$('buscar').focus();
	}
	else
		location.href='resultados_busqueda.php?cad=' + $('buscar').value;
	return true;
}
function enviaContacto()
{
	var error="";
	if($('nombre').value == '')
	{
		error = "Introduzca su nombre.";	
		$('nombre').focus();
	}
	if(!validarMail($('email').value) && error == "")
	{
		error = "La direcciÃ³n de correo introducida no es vÃ¡lida.";	
		$('email').focus();
	}
	if($('CP').value != '' && !validaCodigoPostal($('CP').value) && error == "")
	{
		error = "El cÃ³digo postal introducido no es vÃ¡lido.";	
		$('CP').focus();
	}
	if($('telefono').value != '' && !telefono_valido($('telefono').value, 1) && error == "")
	{
		error = "El telÃ©fono introducido no es vÃ¡lido.";	
		$('telefono').focus();
	}
	if($('telefono2').value != '' && !telefono_valido($('telefono2').value, 2) && error == "")
	{
		error = "El telÃ©fono introducido no es vÃ¡lido.";	
		$('telefono2').focus();
	}
	if($('comentarios').value == '' && error == "")
	{
		error = "Introduzca un comentario.";	
		$('comentarios').focus();
	}
	if(error != '')
		alert(error);
	else
		if(confirm('¿Enviar consulta?'))
			cargaPagina('enviar_contacto.php', 'div_envio', 'nombre=' + $('nombre').value + '&email=' + $('email').value + '&direccion=' + $('email2').value + '&poblacion=' + $('email3').value + '&cp=' + $('CP').value + '&tlf=' + $('telefono').value + '&movil=' + $('telefono2').value + '&comentarios=' + $('comentarios').value);
	return true;
}
function validarMail(sEmail) {
  	var emailFilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	if (sEmail != '' && emailFilter.test(sEmail)) {return true;}
	return false;
}
function telefono_valido(numero, tipo)
{
	var tfno= parseInt(numero);
	var error = "";
	if ( isNaN(tfno) )
		error="q";
	else
	{
		if ( !( (tfno >= 900000000) && (tfno < 1000000000)) && tipo==1 )
			error = 'q';
		else if	(!((tfno >= 600000000) && (tfno < 700000000)) && tipo==2 )  
			error="q";
	}
	if(error == "")
		return true;
	return false;
}
function validaCodigoPostal(CP)
{
	if(CP == "" || isNaN(CP) || CP < 1000 || CP > 52999)
		return false;
	return true;
}























