var movent=false;
var numf='';
var act=1;

window.onload=function() {
	if($('galIni')){
		protoFlash=new ProtoFlash('galIni', {
			interval:2.5,
			width: 140,
			height: 140,
			animSpeed: 1.5
		});
	}
	
	if($('galFin')){
		protoFlash=new ProtoFlash('galFin', {
			interval:2.5,
			width: 140,
			height: 140,
			animSpeed: 1.5
		});
	}
	
	if($('map')){
		map();
	}
}

function map(){
	if (GBrowserIsCompatible()) { 
			
			map = new GMap2(document.getElementById("map")); 
			map.setCenter(new GLatLng(39.59804057525722, 2.6703107357025146), 17); 
			map.addControl(new GSmallMapControl()); 
			map.addControl(new GMapTypeControl()); 
			map.setMapType(G_HYBRID_MAP); 
			map.openInfoWindow(map.getCenter(), 
				"<div id='menmapa' style=height:100px;><div id='iconomapa' style='float: left; margin-right: 23px;'><img src='../img/mayfe.jpg' style='width:196px;'></div></div>"); 
			 
			
			/*GEvent.addListener(map,"click", function(overlay,latlng) {      
		      if (latlng) {    
		        //var myHtml = "The GLatLng value is: " + map.fromLatLngToDivPixel(latlng) + " at zoom level " + map.getZoom(); 
		        var myHtml = "The GLatLng value is: " + latlng + " at zoom level " + map.getZoom(); 
		        map.openInfoWindow(latlng, myHtml); 
		      } 
	    });*/
			
	    
		}
}



function nuevoMail() {
	if($('impmail').value==""){
		alert("Debe introducir un Mail");
		return
	}else{
		var res=validarEmail($('impmail').value);
		if(res==1){
			insertarMail($('impmail').value);
		}else {
			alert('Debe escribir un Mail correcto');
		}
	}
	
}


function validarEmail(valor) {
		if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(valor)){
		return 1
		} else {
		return -1;
		}
}

function insertarMail(mail) {
	var url="../xml/insertarmail.php";
	var params="mail="+mail;
	var ajax=new Ajax.Request ( url, {
		method: 'post',
		postBody: params,
		onComplete:function(reply) {
			if(reply.responseText=="ok"){
				alert('Mail correcto, gracias por inscribirse a nuestro NewsLetter');
			}else{
				alert('Ya existe un usuario con este Mail');
			}
		}
		});	
}


function itemon(x) {
	$('it'+x).style.color="#C90000";
}

function itemoff(x) {
	$('it'+x).style.color="black";
}

function notmenos() {
	if(movent==false){
			if(numf>act){
				movent=true;
				new Effect.Move("movil", { mode: 'relative', x:-409, afterFinish: function(){
					movent=false;
				} });
				act++;
			}
	}
}
function notmas() {
	//new Effect.Move("movil", { mode: 'relative', x:409, duration: 0.9 });
	if(movent==false){
		if(act>1){
			movent=true;
			new Effect.Move("movil", { mode: 'relative', x:409, afterFinish: function(){
				movent=false;
			} });
			act--;
		}
	}
}

function animaoff() {
	new Effect.Opacity('des', { from: 0.0, to: 1.0, duration: 0.9 });
	new Effect.Move("des", { mode: 'relative', x:-616, duration: 0.9 });
	//
	//new Effect.Opacity('imgArr', { from: 0.0, to: 1.0, duration: 0.9 });
	//new Effect.Move("imgArr", { mode: 'relative', x:-616, duration: 0.9 });
	//
	
}

function anima(x) {
	var men=$('des');
	new Effect.Opacity('des', { from: 1.0, to: 0.0, duration: 0.9 });
	new Effect.Move("des", { mode: 'relative', x:616, duration: 0.9 });
	//imgArr
	//new Effect.Opacity('imgArr', { from: 1.0, to: 0.0, duration: 0.9 });
	//new Effect.Move("imgArr", { mode: 'relative', x:616, duration: 0.9 });
	//textArr
	//new Effect.Opacity('textArr', { from: 1.0, to: 0.0, duration: 0.9 });
	//new Effect.Move("textArr", { mode: 'relative', x:616, duration: 0.9 });	
	
	setTimeout ( "linkmenu("+x+")", 1000 );
	//linkmenu(x);
}

function abrirgal(url){
	var men=$('des');
	new Effect.Opacity('des', { from: 1.0, to: 0.0, duration: 0.9 });
	new Effect.Move("des", { mode: 'relative', x:616, duration: 0.9 });
	setTimeout ( "abrirgal2('"+url+"')", 1000 );
}
function abrirgal2(url) {
	window.location=url+"?cab=3";
}

function abrirobra(cod) {
	var men=$('des');
	new Effect.Opacity('des', { from: 1.0, to: 0.0, duration: 0.9 });
	new Effect.Move("des", { mode: 'relative', x:616, duration: 0.9 });
	setTimeout ( "abrirobra2("+cod+")", 1000 );
}
function abrirobra2(cod) {
	window.location="obras.php?cod="+cod+"&cab=3";
}
function linkmenu(x) {
	if(x==1){
		link('index');
	}
	if(x==2){
		window.location="empresa.php?cab=2";
	}
	if(x==3){
		window.location="obras.php?cab=3";
	}
	if(x==4){
		window.location="productos.php?cab=4";
	}
	if(x==5){
		window.location="atencion.php?cab=5";
	}
	if(x==6){
		window.location="novedades.php?cab=6";
	}
	if(x==7){
		window.location="donde.php?cab=7";
	}
	if(x==8){
		window.location="contacto.php?cab=8";
	}
}

//function itemon(x){
//	$('item'+x).style.backgroundImage="url('../img/item2.jpg')";
//}
//function itemoff(x){
//	$('item'+x).style.backgroundImage="url('../img/item.jpg')";
//}



function enviar() {
	
	if (($('nombre').value=="") || ($('apellidos').value=="") || ($('telefono').value=="") || ($('impmail').value=="") || ($('mensaje').value=="")) {
		alert('tiene que rellenar todos los campos');
		return;
	}
	
	var url="../xml/mailForm.php";
	
	var params="nombre="+encodeURI($('nombre').value)+"&apellidos="+encodeURI($('apellidos').value)+"&tel="+encodeURI($('telefono').value)+"&mailA="+encodeURI($('impmail').value)+"&mensaje="+encodeURI($('mensaje').value);
	var ajax=new Ajax.Request ( url, {
		method: 'post',
		postBody: params,
		onLoading: function() {
					buida($('msg'));
					var t=document.createTextNode(unescape(iditextos[1]));
					$('msg').style.visibility='visible';
					$('msg').appendChild(t);
				},
		onComplete:function(reply) {
					if (reply.responseText=="Err") {
						var txt="Ha ocurrido un error.";
					} else {
						var txt="Mensaje enviado satisfactoriamente";
					}
					
					alert(txt);
					
					if (reply.responseText=="Ok") {
						
						
						$('nombre').value="";
						$('apellidos').value="";
						$('telefono').value="";
						$('mail').value="";
						$('mensaje').value="";
					}
				}
		});	
}



function enviarMail() {
	
	if (($('nombre').value=="") || ($('apellidos').value=="") || ($('mail').value=="") || ($('tel').value=="")) {
		alert('tiene que rellenar todos los campos obligatorios *');
		return;
	}
	var url="../xml/mail.php";
	var params="nombre="+encodeURI($('nombre').value)+"&apellidos="+encodeURI($('apellidos').value)+"&mailA="+encodeURI($('mail').value)+"&tel="+encodeURI($('tel').value)+"&dir="+encodeURI($('dir').value)+"&cp="+encodeURI($('cp').value)+"&ciudad="+encodeURI($('ciudad').value)+"&pais="+encodeURI($('pais').value)+"&noches="+encodeURI($('noches').value)+"&numhab="+encodeURI($('numhab').value)+"&dia="+encodeURI($('dia').value)+"&mes="+encodeURI($('mes').value)+"&ano="+encodeURI($('ano').value)+"&dias="+encodeURI($('dias').value)+"&mess="+encodeURI($('mess').value)+"&anos="+encodeURI($('anos').value)+"&com="+encodeURI($('com').value);
	var ajax=new Ajax.Request ( url, {
		method: 'post',
		postBody: params,
		onLoading: function() {
					//buida($('msg'));
					//var t=document.createTextNode(unescape(iditextos[1]));
					//$('msg').style.visibility='visible';
					//$('msg').appendChild(t);
				},
		onComplete:function(reply) {
					if (reply.responseText=="Err") {
						var txt="Ha ocurrido un error.";
					} else {
						var txt="Mensaje enviado satisfactoriamente";
					}
					
					alert(txt);
					
					if (reply.responseText=="Ok") {
						
						
						
					}
			}
		});	
}




function menuon(x){
	if(x==1){
		$('item1').style.backgroundImage="url('../img/nueva/item1.jpg')";
	}
	if(x==2){
		$('item2').style.backgroundImage="url('../img/nueva/item2.jpg')";
	}
	if(x==3){
		$('item3').style.backgroundImage="url('../img/nueva/item3.jpg')";
	}
	if(x==4){
		$('item4').style.backgroundImage="url('../img/nueva/item4.jpg')";
	}
	if(x==5){
		$('item5').style.backgroundImage="url('../img/nueva/item5.jpg')";
	}
	
}
function menuoff(x){
	if(x==1){
		$('item1').style.backgroundImage="";
	}
	if(x==2){
		$('item2').style.backgroundImage="";
	}
	if(x==3){
		$('item3').style.backgroundImage="";
	}
	if(x==4){
		$('item4').style.backgroundImage="";
	}
	if(x==5){
		$('item5').style.backgroundImage="";
	}
	
}


function mostraGal(){
	new Effect.Opacity('blanco', { from: 1.0, to: 0.0, duration: 0.2, afterFinish: function(){
		$('blanco').style.display="none";
	} });
	
}

function abrirTrabajo(url){
	alert(url);
}

function posaGaleria(d) {
	var dd=$(d);
	
	if (dd) {
		var protoCarousel=new ProtoCarousel(dd, {
			   itemWidth: 150,
			   itemHeight: 150, 
			   buttonLeftWidth: 26,
			   buttonRightWidth: 26,
			   buttonLeft: '../img/btn_izq.png',
			   buttonRight: '../img/btn_dcha.png'
			  
			  });
	}
}



function link(url){
	
	window.location=url+".php";
}

function over(x){
	$('item'+x).style.backgroundImage="url('../img/fondoitem.jpg')";
	$('item'+x).style.backgroundRepeat="repeat-x";
	$('item'+x).style.color="#4A6C20";
	//$('fl'+x).src="http://www.rominstec.com/web/img/flecha.png"
}
function out(x){
	$('item'+x).style.backgroundImage="";
	$('item'+x).style.backgroundRepeat="";
	$('item'+x).style.color="white";
	//$('fl'+x).src="http://www.rominstec.com/web/img/flecha2.png"
}


