//var rutaWeb = 'http://ferroli.clickcode.es';
var rutaWeb = 'http://www.ferroli.devsite.es';

function escribeflash(url,anchoswf,altoswf){
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+anchoswf+'" height="'+altoswf+'"  align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="'+url+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed wmode="transparent" src="'+url+'" quality="high" width="'+anchoswf+'" height="'+altoswf+'"  align="middle"  type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');}
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 getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
	  var ua = navigator.userAgent;
	  var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	  if (re.exec(ua) != null)
		 rv = parseFloat( RegExp.$1 );
   }
   return rv;
}

function pintarEnGrowl (pagina, alto, ancho, parametros)
{
	var topIE = 0;
	if (getInternetExplorerVersion() == "8")
		topIE = 50;
	else if (getInternetExplorerVersion() == "7")	
		topIE = 100;
		
	
	var alto = alto / 2;
	var ancho = ancho / 2;
	var top = window.getScrollTop();
	var left = window.getScrollLeft();
	var h = window.getHeight()/2;
	var w = window.getWidth()/2;
	var he = top+h-alto;		

	if (he < 0) he = 20;			
	
	var we = left+w-ancho;
	$('growlfondo').setStyles({'height':window.getScrollHeight()+'px','width':window.getWidth()+'px',	'top':'0px','left':'0px','display':'block'});
	$('growlfondo').style.opacity = "0.6";
	document.getElementById('growlfondo').setAttribute('onclick', 'cierraGrowl()');
	//alert(window.getHeight()+ " - " + window.getScrollTop())
	var imgCargando = "<div style='text-align:center; font-size: 12px; font-weight:bold; color: #FFF; font-family:verdana;'><img src='/images/loading.gif' align='middle' border='0' /><br/>Cargando...";
	$('growlmsg').setStyles({'top':he + (55+parseInt(topIE)) +'px','left':we +'px','width':(ancho * 2)+'px','height':'650px','display':'block'});
	$('growlmsg').innerHTML = imgCargando;
	$('growlmsg').style.opacity = "1";
	
	if (pagina != "") //usado para poder imprimir un growl con el loading mientras se hace otra cosa. si la 'pagina' no se ha pasado no se hace el cargapagina, este es el caso del loading solo.
		cargaPagina(pagina, "growlmsg", parametros);
}

function cierraGrowl ()
{
	$('growlfondo').innerHTML = '';
	$('growlmsg').innerHTM = '';
	$('growlfondo').style.display = 'none';
	$('growlmsg').style.display = 'none';
}

function cambiaFondoMenu(tipo, id)
{
	if(tipo == 1) $('boton_'+id).src = 'http://www.ferroli.es/images/menu0'+id+'_on.gif';
	else if(tipo == 2) $('boton_'+id).src = 'http://www.ferroli.es/images/menu0'+id+'_off.gif';
}

function cambiaFondoMenuSup(tipo, id)
{
	if(tipo == 1)
	{
		$('div_menuSuperior_'+id).style.backgroundColor = '#f06e13';
		$('div_menuSuperior_'+id).style.color = '#FFFFFF';
		$('img_menuSuperior_'+id).style.display = 'none';
	}
	else
	{
		$('div_menuSuperior_'+id).style.backgroundColor = '#FFFFFF';
		$('div_menuSuperior_'+id).style.color = '#000000';
		$('img_menuSuperior_'+id).style.display = 'inline';
	}
}



function comprobarPeticionInformacion()
{
	if ($('nombre').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if ($('apellidos').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if ($('mail').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if (!comprueba_mail($('mail').value))	
	{
		return;
	}
	else if ($('tlf').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if(comprueba_tfno(document.getElementById('tlf').value,0)==false)
	{
		return;
	}
	else if ($('cp').value == "")
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if(isNaN($('cp').value) || $('cp').value.length != 5)
	{
		alert("El formato del c\xF3digo postal no es v\xE1lido.");
		return;
	}
	else if ($('observaciones').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if (document.getElementById('captcha') && document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
	{		
		alert("Introduzca el texto de la imagen correctamente.");
		error="n";
		return false;				
	}
	else if ($('acepto').checked == false)
	{
		alert ('Debe aceptar las Condiciones Generales y la Politica de Privacidad');
		return;
	}
	
	$('form_presupuesto').submit();
}

function comprobarPresupuestoCondensacion()
{
	if ($('nombre').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if ($('apellidos').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if ($('mail').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if (!comprueba_mail($('mail').value))	
	{
		return;
	}
	else if ($('direccion').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if ($('tlf').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if(comprueba_tfno(document.getElementById('tlf').value,0)==false)
	{
		return;
	}
	else if ($('cp').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if(isNaN($('cp').value) || $('cp').value.length != 5)
	{
		alert("El formato del c\xF3digo postal no es v\xE1lido.");
		return;			
	}
	else if ($('observaciones').value == "")	
	{
		alert ('Todos los campos son necesarios.');
		return;
	}
	else if (document.getElementById('captcha') && document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
	{		
		alert("Introduzca el texto de la imagen correctamente.");
		error="n";
		return false;				
	}
	else if ($('acepto').checked == false)
	{
		alert ('Debe aceptar las Condiciones Generales y la Politica de Privacidad');
		return;
	}
	
	$('form_presupuesto_condensacion').submit();
}

function cargaFamilias(check)
{
	cadenaSql = $('cadena_sql').value;
			
	if (check.checked == true)	
		cadenaSql += ' AND '+check.id+' = 1';
	else
		cadenaSql = cadenaSql.replace( "AND "+check.id+" = 1", "");
		
	$('cadena_sql').value = cadenaSql;		
	
	cargaPagina('/productos/listado_familias.php', 'div_listado_familias', 'tipo='+$('tipo').value+'&cad='+cadenaSql);
}


function cargaFamilias2(check)
{
	if(check.checked == true)
	{
		cadenaSql = "";
				
		if (check.id != "todos")	
		{
			cadenaSql += ' AND '+check.id+' = 1';			
			$('div_checks').style.display = "none";
			$('div_checks_2').style.display = "none";
			$('div_checks_3').style.display = "inline";
			$('div_nivel_2').innerHTML = "+ Nivel 2: &nbsp;" + check.parentNode.id.replace(/_/gi," ");
		}
		else
			$('div_nivel_2').innerHTML = "+ Nivel 2: &nbsp;Todos";
		$('div_nivel_3').innerHTML = "+ Nivel 3: &nbsp;Todos";
		$('cadena_sql2').value = cadenaSql;	
		cadenaSql = $('cadena_sql').value + cadenaSql; 
		cargaPagina('/productos/listado_familias.php', 'div_listado_familias', 'tipo='+$('tipo').value+'&cad='+cadenaSql+'&d1='+$('sec1').value+'&d2='+$('sec2').value+'&n2='+$('n2').value);
		if($('div_checks_3'))
			cargaPagina('/productos/listado_checks.php', 'div_checks_3', 'tipo='+$('tipo').value+'&n2='+$('n2').value+'&n3='+$('n3').value+'&n4='+$('n4').value+'&cad='+check.id+'&nivel=_3');
	}
}

function radioFamilias(radio)
{
	if(radio.checked == true)
	{
		var cadenaSql = '';
		if (radio.id != "todos")	
		{
			cadenaSql = ' AND '+radio.id+' = 1';					
			$('div_checks').style.display = "none";
			$('div_checks_2').style.display = "inline";
			$('div_checks_3').style.display = "none";
			$('div_nivel_1').innerHTML = "+ Nivel 1: &nbsp;" + radio.parentNode.id.replace(/_/gi," ");
		}
		else
			$('div_nivel_1').innerHTML = "+ Nivel 1";
			
		$('div_nivel_2').innerHTML = "+ Nivel 2: &nbsp;Todos";
		$('div_nivel_3').innerHTML = "+ Nivel 3: &nbsp;Todos";
		$('cadena_sql').value = cadenaSql;
		cargaPagina('/productos/listado_familias.php', 'div_listado_familias', 'tipo='+$('tipo').value+'&cad='+cadenaSql+'&d1='+$('sec1').value+'&d2='+$('sec2').value+'&n2='+$('n2').value);
		$('n4').value = radio.id;
		if($('div_checks_2'))
			cargaPagina('/productos/listado_checks.php','div_checks_2','cad='+radio.id+'&n2='+$('n2').value+'&n3='+$('n3').value+'&tipo='+ $('tipo').value+'&nivel=_2');
	}
}
function radioFamilias2(radio)
{
	if(radio.checked == true)
	{
		var cadenaSql = $('cadena_sql').value + $('cadena_sql2').value;
		/*$('div_checks').style.display = "none";
		$('div_checks_2').style.display = "none";
		$('div_checks_3').style.display = "none";//*/
		if (radio.id != "todos")
		{
			cadenaSql += ' AND '+radio.id+' = 1';
			$('div_nivel_3').innerHTML = "+ Nivel 3: &nbsp;" + radio.parentNode.id.replace(/_/gi," ");
		}else
			$('div_nivel_3').innerHTML = "+ Nivel 3: &nbsp;Todos";
		cargaPagina('/productos/listado_familias.php', 'div_listado_familias', 'tipo='+$('tipo').value+'&cad='+cadenaSql+'&d1='+$('sec1').value+'&d2='+$('sec2').value+'&n2='+$('n2').value);
	}
	
}

function despliegaNivel(nivel)
{
	$('div_checks').style.display = "none";
	$('div_checks_2').style.display = "none";
	$('div_checks_3').style.display = "none";
	
	$('div_checks'+nivel).style.display = "inline";
}

function login_area_privada_sat()
{
	if ( ($('nombre').value != '') && ($('pass').value != '') )
		$('formLoginSat').submit();
	/*else
		alert('Datos incorrectos.');*/
}

function descargarPDF(cod,path)
{
	window.ifr_oculto.location.href='http://crmferroli.clickcode.es/gestor_catalogo/descargarPDF.php?cod='+cod;
}




//------------------------------------------------------------------------------------------//
//-------------------------------- CARGAS DE MAPA GOOGLE ----------------------------------//
//------------------------------------------------------------------------------------------//




function cargaMapa(direccion, nombre, telefono, fax)
{
	alert ('oe');
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
		var address = direccion;
		
		var LatLng = new GLatLng(geocoder.getLatLng(address, function(point) {
				map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
				var myHtml = "<font style='font-size: 14px;'><b>"+nombre+"</b></font><br/><font style='font-size: 11px;'>"+direccion;
				myHtml += "<br/><b>Teléfono:</b> "+telefono+"  | <b>FAX:</b> "+fax+"</font>";
				map.openInfoWindowHtml(point, myHtml);			  
			}
		  )
		);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(LatLng);
	}
}

function cargaMapaNew2()
{
	//if (GBrowserIsCompatible()) {
		var map = new google.maps.Map2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
		var address = "Orense, 58 (Madrid)";
		
		var LatLng = new GLatLng(geocoder.getLatLng(address, function(point) {
				map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
				var myHtml = "<font style='font-size: 14px;'><b>Portal WATCH</b></font><br/><font style='font-size: 11px;'>Orense, 58<br/>28020 Madrid (España)";
				myHtml += "<br/><b>Teléfono:</b> 915567698  | <b>FAX:</b> 915567589</font>";
				map.openInfoWindowHtml(point, myHtml);			  
			}
		  )
		);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(LatLng);
	//}
}

function cargaMapaNew()
{
	//if (GBrowserIsCompatible()) {
		var map = new google.maps.Map2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
		var address = "Orense, 58 (Madrid)";				
		
		var LatLng = new GLatLng(geocoder.getLatLng(address, function(point) {
				map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
				var myHtml = "<font style='font-size: 14px;'><b>Portal WATCH</b></font><br/><font style='font-size: 11px;'>Orense, 58<br/>28020 Madrid (España)";
				myHtml += "<br/><b>Teléfono:</b> 915567698  | <b>FAX:</b> 915567589</font>";
				map.openInfoWindowHtml(point, myHtml);			  
			}
		  )
		);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(LatLng);

		panorama = new GStreetviewPanorama(document.getElementById("pano"));
		panorama.setLocationAndPOV(new GLatLng(40.459324,-3.694625), {yaw: 50, pitch: -10, zoom: 0});
	//}
}




//------------------------------------------------------------------------------------------//
//-------------------------------- MENÚ LATERAL IZQUIERDO ----------------------------------//
//------------------------------------------------------------------------------------------//

//----- cambiaFondoMenuIzq(tipo = onmouseover-1 onmouseout-2, id = id del div, ruta = ruta variable ferroli) -----
function cambiaFondoMenuIzq(tipo, id, ruta)
{
	if(tipo == 1)
	{
		$('menuIzq_'+id).style.backgroundColor = '#f07f13';
		$('menuIzq_'+id).style.color = '#FFFFFF';
		/*$('img_menuIzq_'+id).src = ruta+'/images/triangulo_diagonal_blanco.png';*/
	}
	else
	{
		$('menuIzq_'+id).style.backgroundColor = '#FFFFFF';
		$('menuIzq_'+id).style.color = '#999999';
		/*$('img_menuIzq_'+id).src = ruta+'/images/triangulo_diagonal.gif';*/
	}
}
function cambiaFondoMenuIzq2(tipo, id, ruta)
{
	if(tipo == 1)
	{
		$('menuIzq_'+id).style.backgroundColor = '#f07f13';
		$('menuIzq_'+id).style.color = '#FFFFFF';
	}
	else
	{
		$('menuIzq_'+id).style.backgroundColor = '#FFFFFF';
		$('menuIzq_'+id).style.color = '#000000';
	}
}

function abreSubMenu(id)
{
	/*var n = 0;
	for(n=1; n<=5; n++)
	{
		$('menuIzqTOTAL_'+n).style.display = 'none';
	}*/

	if($('menuIzqTODO_estado').value == id)
	{
		$(id).style.display = 'none';
		$('menuIzqTODO_estado').value = 0;
	}
	else
	{
		$(id).style.display = 'inline';
		$('menuIzqTODO_estado').value = id;
	}
}

function menuPrincipalLateralIzq(tipo)
{
	//$('menu1_iz1').style.display = 'none';
	//$('menu1_iz2').style.display = 'none';
	var otro = 2;
	
	if (tipo == 2)
		otro = 1;
	
	if ($('menu1_iz'+tipo).style.display == 'inline')
	{
		$('menu1_iz'+tipo).style.display = 'none';
		cargaPagina('/guardaMenu.php','div_carga_izq','m=0');
	}
	else
	{		
		$('menu1_iz'+tipo).style.display = 'inline';
		$('menu1_iz'+otro).style.display = 'none';
		cargaPagina('/guardaMenu.php','div_carga_izq','m='+tipo);
	}
	
	
	/*if(tipo == $('menu1_iz_estado').value)
	{
		$('menu1_iz'+tipo).style.display = 'none';
		$('menu1_iz_estado').value = tipo;
		//ocultaSubMenu();
	}
	else
	{
		$('menu1_iz'+tipo).style.display = 'inline';
		$('menu1_iz'+otroMenu).style.display = 'none';
		$('menu1_iz_estado').value = tipo;
		//ocultaSubMenu();
	}*/
}

//------------------------------------------------------------------------------------------//

var toggleActual = '';
var mySlideProductosUser;
var mySlideServiciosUser;
//var mySlideDescargasUser;
var mySlideProductosProf;
var mySlideServiciosProf;
var mySlideInstaladorAcredProf;
var mySlideHerramientasProf;
var mySlideFormacionProf;

function inicializa(a)
{
	var menuAbierto = $('menuAbierto').value;

	mySlideProductosUser=new Fx.Slide('ProductosUser');
	mySlideServiciosUser=new Fx.Slide('ServiciosUser');
	//mySlideDescargasUser=new Fx.Slide('DescargasUser');
	mySlideProductosProf=new Fx.Slide('ProductosProf');
	mySlideServiciosProf=new Fx.Slide('ServiciosProf');
	mySlideInstaladorAcredProf=new Fx.Slide('InstaladorAcredProf');
	mySlideHerramientasProf=new Fx.Slide('HerramientasProf');
	mySlideFormacionProf=new Fx.Slide('FormacionProf');

	if(menuAbierto != 'ProductosUser')
		mySlideProductosUser.hide();
	if(menuAbierto != 'ServiciosUser')
		mySlideServiciosUser.hide();
	//if(menuAbierto != 'DescargasUser')
		//mySlideDescargasUser.hide();
	if(menuAbierto != 'ProductosProf')
		mySlideProductosProf.hide();
	if(menuAbierto != 'ServiciosProf')
		mySlideServiciosProf.hide();
	if(menuAbierto != 'InstaladorAcredProf')
		mySlideInstaladorAcredProf.hide();
	if(menuAbierto != 'HerramientasProf')
		mySlideHerramientasProf.hide();
	if(menuAbierto != 'FormacionProf')
		mySlideFormacionProf.hide();

	toggleActual = menuAbierto;
}

function abreSubMenu(a)
{
	var o={};
	var b=new Fx.Elements($(a),{wait:false,duration:300,transition:Fx.Transitions.Back.easeOut});
	
	b.start(o);
	
	$(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});

	a.start(o);

	eval("mySlide"+toggleActual+".toggle();");
}

//------------------------------------------------------------------------------------------//

var menuActual = '';

var altura_menuProductosUser = 60;
var altura_menuServiciosUser = 80;
var altura_menuPRODUCTOS1 = 60;
var altura_menuSERVICIOS2 = 80;
var altura_menuProductosProf = 60;
var altura_menuServiciosProf = 60;
var altura_menuInstaladorAcredProf = 40;
var altura_menuHerramientasProf = 20;
var altura_menuFormacionProf = 40;
var altura_menuPromocionProf = 20;

function clickMenuIzq(menu)
{
	if (menuActual == '')
	{
		despliegaMenuIzq(menu);
		menuActual = menu;
	}
	else 
	{
		if (menuActual != menu)
		{
			pliegaMenuIzq(menuActual);
			despliegaMenuIzq(menu);
			menuActual = menu;	
		}
		else
		{
			pliegaMenuIzq(menu);
			menuActual = '';
		}
	}
}
function clickMenuIzqBis(menu,altura)
{
	if (menuActual == '')
	{
		despliegaMenuIzqBis(menu,altura);
		menuActual = menu;
	}
	else 
	{
		if (menuActual != menu)
		{
			pliegaMenuIzq(menuActual);
			despliegaMenuIzqBis(menu,altura);
			menuActual = menu;	
		}
		else
		{
			pliegaMenuIzq(menu);
			menuActual = '';
		}
	}
}

function despliegaMenuIzqBis(menu,altura)
{
	if (parseInt($(menu).style.height) < parseInt(altura))
	{
		$(menu).style.height = (parseInt($(menu).style.height) + 5 ) + 'px';
		setTimeout('despliegaMenuIzqBis("'+menu+'",'+altura+')',5);
	}
}

function pliegaMenuIzq(menu)
{
	if (parseInt($(menu).style.height) > 0)
	{
		if (parseInt($(menu).style.height) - 5 < 0)
			$(menu).style.height = '0px';
		else
			$(menu).style.height = (parseInt($(menu).style.height) - 5 ) + 'px';
		
		setTimeout('pliegaMenuIzq("'+menu+'")',5);
	}
}

function despliegaMenuIzq(menu)
{
	if (parseInt($(menu).style.height) < parseInt(eval('altura_'+menu)))
	{
		$(menu).style.height = (parseInt($(menu).style.height) + 5 ) + 'px';
		setTimeout('despliegaMenuIzq("'+menu+'")',5);
	}
}

function pliegaMenuIzq(menu)
{
	if (parseInt($(menu).style.height) > 0)
	{
		if (parseInt($(menu).style.height) - 5 < 0)
			$(menu).style.height = '0px';
		else
			$(menu).style.height = (parseInt($(menu).style.height) - 5 ) + 'px';
		
		setTimeout('pliegaMenuIzq("'+menu+'")',5);
	}
}


//------------------------------------------------------------------------------------------//
//-------------------------- CARRUSEL IMAGENES ES CABECERA ---------------------------------//
//------------------------------------------------------------------------------------------//
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);
}

//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------//

function buscarSAT ()
{
	var tipo= '';
	if(document.form1.opcionClima[0].checked)
		tipo = "&tipo=1";
	if(document.form1.opcionClima[1].checked)
		tipo = "&tipo=2";
		
	
	if ($('CP').value.indexOf(' ') != -1)
	{
		alert('No se permiten espacios en blanco en la búsqueda por CP.');
		return false;
	}
	else if (isNaN($('CP').value) && ( $('CP').value.substring(0,2) != 'AD'  &&  $('CP').value.substring(0,2) != 'ad'))
	{
		alert('Los únicos CP con letras comienzan por AD para Andorra.');
		return false;
	}
	else if ($('CP').value != "")
	{		
		cargaPagina('/content/listado_sat.php','div_resultados','cp='+$('CP').value + tipo);
		$('listado_deleg').style.display = 'inline';
	}
}


function cargaNiveles(codigo,orden)
{
	if($('div_nivel'+orden).style.display == 'inline')
		$('div_nivel'+orden).style.display = 'none';
	else
		$('div_nivel'+orden).style.display = 'inline';
	if($('div_nivel'+orden).innerHTML == "")
	{
		/*$('div_nivel'+orden).innerHTML = '<div id="div_cargando" style="float:left; display:inline; width:100%; text-align:center; margin-top:40px; font-size:12px; font-weight:bold;"><img src="/imagenes/cargando.gif"  /><br /><br /> Cargando datos...</div>';*/
		cargaPagina('/content/cargaNivel.php','div_nivel'+orden,'cod='+ codigo +"&orden="+orden);
		
	}
}

//----- Tipo (1 - onmouseover, 2 - onmouseout), id (id de la imagen), ruta (ruta variable de la carpeta imagenes) -----
function cambiaFondo(tipo, id, ruta)
{
	if(tipo == 1)
	{
		//document.getElementById('boton_'+id).src = ruta+'menu0'+id+'_on.gif';
		document.getElementById('boton_'+id).style.background = 'url('+ruta+'menu_0'+id+'_on.gif)';
		
		for(i = 1; i <= 3; i++)
		{
			if(i!= id)
			{
				//document.getElementById('boton_'+i).src = ruta+'menu0'+i+'_off.gif';
				document.getElementById('boton_'+i).style.background = 'url('+ruta+'menu_0'+i+'_off.gif)';
				document.getElementById('menu_sup_'+i).style.display = 'none';
				document.getElementById('menuSupAbierto').value = 0;
			}
		}
	}
	else if(tipo == 2 && menuDesplegado != id)
		//document.getElementById('boton_'+id).src = ruta+'menu0'+id+'_off.gif';
		document.getElementById('boton_'+id).style.background = 'url('+ruta+'menu_0'+id+'_off.gif)';
}

function limpiaMenu(menu, tipo, ruta)
{
	if(tipo == 1)
	{
		menu.style.display = 'inline';
		sec = menu.id.replace('menu_sup_', '');
		document.getElementById('boton_'+sec).src = ruta+'menu0'+sec+'_on.gif';
		document.getElementById('menuSupAbierto').value = sec;
		menuDesplegado = sec;
	}
	else
	{
		menu.style.display = 'none';
		sec = menu.id.replace('menu_sup_', '');
		document.getElementById('boton_'+sec).src = ruta+'menu0'+sec+'_off.gif';
		document.getElementById('menuSupAbierto').value = 0;
		menuDesplegado = 0;
	}
}

function abreMenuSuperior(num)
{
	for(s=1; s<=30; s++)
	{
		if(document.getElementById('div_menuSup_producto_'+s))
		document.getElementById('div_menuSup_producto_'+s).style.display = 'none';
		if(s == num)
		{
			if('div_menuSup_producto_'+num == document.getElementById('menuSup_2_Abierto').value)
			{
				document.getElementById('div_menuSup_producto_'+num).style.display = 'none';
				document.getElementById('menuSup_2_Abierto').value = 0;
			}
			else
			{
				document.getElementById('div_menuSup_producto_'+num).style.display = 'inline';
				document.getElementById('menuSup_2_Abierto').value = 'div_menuSup_producto_'+num;
			}
		}
	}
}

var menuDesplegado = 0;

function abreMenuSup(num)
{
	for(p=1; p<=3; p++)
	{
		document.getElementById('menu_sup_'+p).style.display = 'none';
		if(p == num)
		{
			if('menu_sup_'+num == document.getElementById('menuSupAbierto').value)
			{
				document.getElementById('menu_sup_'+num).style.display = 'none';
				document.getElementById('menuSupAbierto').value = 0;
				menuDesplegado = 0;
			}
			else
			{
				document.getElementById('menu_sup_'+num).style.display = 'inline';
				document.getElementById('menuSupAbierto').value = 'menu_sup_'+p;
				menuDesplegado = num;
			}
		}
	}
}

function escribeflash(url,anchoswf,altoswf){
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+anchoswf+'" height="'+altoswf+'"  align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="'+url+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed wmode="transparent" src="'+url+'" quality="high" width="'+anchoswf+'" height="'+altoswf+'"  align="middle"  type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');}

function envia()
	{
	var error = "";
	if (document.getElementById('nif').value == "")
		{
		alert("Por favor, introduzca el NIF.");
		error="n";
		return false;
		}	
	else if(comprueba_NIF(document.getElementById('nif').value)==false)
		error = "n";
	else if (document.getElementById('nombre').value == "")
		{
		alert("Por favor, introduzca el nombre.");
		error="n";
		return false;
		}
	else if (document.getElementById('direccion').value == "")
		{
		alert("Por favor, introduzca la direcci\xF3n.");
		error="n";
		return false;
		}	
	else if (document.getElementById('poblacion').value == "")
		{
		alert("Por favor, introduzca la poblaci\xF3n.");
		error="n";
		return false;
		}	
	else if (document.getElementById('provincia').value == "")
		{
		alert("Por favor, introduzca la provincia.");
		error="n";
		return false;
		}	
	else if (document.getElementById('cp').value == "")
		{
		alert("Por favor, introduzca el c\xF3digo postal.");
		error="n";
		return false;

		}
	else if(isNaN(document.getElementById('cp').value) || document.getElementById('cp').value.length != 5)
		{
		alert("El formato del c\xF3digo postal no es v\xE1lido.");
		error="n";
		return false;			
		}
	else if (document.getElementById('tlfn1').value=="")
		{
		alert("Por favor, introduzca el tel\xE9fono 1.");
		error="n";
		return false;
		}
	else if(comprueba_tfno(document.getElementById('tlfn1').value,1)==false || comprueba_tfno(document.getElementById('tlfn2').value,2)==false)
		error = "n";
	else if (document.getElementById('mail').value=="")
		{
		alert("Por favor, introduzca el correo electr\xF3nico.");
		error="n";
		return false;
		}
	else if(comprueba_mail(document.getElementById('mail').value) == false)
		error="n";
	else
		{
		if (document.getElementById('captcha'))
		{
			if (document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
			{
				
				alert("Introduzca el texto de la imagen correctamente.");
				error="n";
				return false;	
			}
		}
		if (!(document.getElementById('AceptarCondiciones').checked))
			{
			alert("Es obligatorio aceptar las condiciones y el aviso legal.");
			error="n";
			return false;
			}			
		}			
	
	if (error == "")
		{
		document.formVentajas.submit();
		}			
	}

function envia2(){
	var error = "";
	if (document.getElementById('nombre').value == "")
		{
		alert("Por favor, introduzca el nombre.");
		error="n";
		return false;
		}	
	if (document.getElementById('apellido').value == "")
		{
		alert("Por favor, introduzca los apellidos.");
		error="n";
		return false;
		}
	if (document.getElementById('direccion').value == "")
		{
		alert("Por favor, introduzca la direcci\xF3n.");
		error="n";
		return false;
		}	
	if (document.getElementById('mail').value=="")
		{
		alert("Por favor, introduzca el correo electr\xF3nico.");
		error="n";
		return false;
		}		
		
	if (!comprueba_mail(document.getElementById('mail').value))
		{
		error="n";
		return false;
		}		
		
	if (document.getElementById('tlfn').value=="")
		{
		alert("Por favor, introduzca el tel\xE9fono.");
		error="n";
		return false;
		}		
		
	if (document.getElementById('cp').value == "")
		{
		alert("Por favor, introduzca el c\xF3digo postal.");
		error="n";
		return false;
		}
	if( (isNaN(document.getElementById('cp').value) || document.getElementById('cp').value.length != 5) )
		{
		alert("El formato del c\xF3digo postal no es v\xE1lido.");
		error="n";
		return false;			
		}	
		
	if(comprueba_tfno(document.getElementById('tlfn').value,0)==false)	
		error="n";
	else
		{
		if (document.getElementById('captcha'))
		{
			if (document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
			{
				
				alert("Introduzca el texto de la imagen correctamente.");
				error="n";
				return false;	
			}
		}	
		if (!(document.getElementById('AceptarCondiciones').checked))
			{
			alert("Es obligatorio aceptar las condiciones y el aviso legal.");
			error="n";
			return false;
			}			
		}	
		
	if (document.getElementById('observaciones').value=="")
		{
		alert("Por favor, introduzca las observaciones.");
		error="n";
		return false;
		}	
	
	if (error == "")
		{
		document.formMant.submit();
		}			
}

function envia3(){
	var error = "";
	if (document.getElementById('nombre').value == "")
		{
		alert("Por favor, introduzca el nombre.");
		error="n";
		return false;
		}	
	if (document.getElementById('apellidos').value == "")
		{
		alert("Por favor, introduzca los apellidos.");
		error="n";
		return false;
		}
		
		
	if (document.getElementById('mail').value=="")
		{
		alert("Por favor, introduzca el correo electr\xF3nico.");
		error="n";
		return false;
		}	
		
	if (!comprueba_mail(document.getElementById('mail').value))
		{
		error="n";
		return false;
		}		
	if (document.getElementById('direccion').value == "")
		{
		alert("Por favor, introduzca la direcci\xF3n.");
		error="n";
		return false;
		}	
		
		
	if (document.getElementById('tlf').value=="")
		{
		alert("Por favor, introduzca el tel\xE9fono.");
		error="n";
		return false;
		}	
			
	if(comprueba_tfno(document.getElementById('tlf').value,0)==false)	
		{
		error="n";
		return false;
		}
		
	if (document.getElementById('cp').value == "")
		{
		alert("Por favor, introduzca el c\xF3digo postal.");
		error="n";
		return false;
		}
	if( (isNaN(document.getElementById('cp').value) || document.getElementById('cp').value.length != 5) )
		{
		alert("El formato del c\xF3digo postal no es v\xE1lido.");
		error="n";
		return false;			
		}	
	
	if (document.getElementById('observaciones').value=="")
		{
		alert("Por favor, introduzca unas observaciones.");
		error="n";
		return false;
		}		
	if (document.getElementById('captcha'))
	{
		if (document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
		{
			
			alert("Introduzca el texto de la imagen correctamente.");
			error="n";
			return false;	
		}
	}
		
	if (!(document.getElementById('AceptarCondiciones').checked))
		{
		alert("Es obligatorio aceptar las condiciones y el aviso legal.");
		error="n";
		return false;
		}			
		
		
	if (error == "")
		{
		document.formCambiaCaldera.submit();
		}		
}

function envia4()
	{
	var error = "";	
	if (document.getElementById('nombre').value == "")
		{
		alert("Por favor, introduzca el nombre.");
		error="n";
		return false;
		}
	if (document.getElementById('nif').value == "")
		{
		alert("Por favor, introduzca el NIF.");
		error="n";
		return false;
		}		
	if ( (comprueba_NIF(document.getElementById('nif').value)==false && validaCIF(document.getElementById('nif').value)==false) )
		{
		alert("El NIF no es v\xE1lido.");
		error="n";
		return false;
		}	
	if (document.getElementById('direccion').value == "")
		{
		alert("Por favor, introduzca la direcci\xF3n.");
		error="n";
		return false;
		}	
	if (document.getElementById('poblacion').value == "")
		{
		alert("Por favor, introduzca la poblaci\xF3n.");
		error="n";
		return false;
		}	
	if (document.getElementById('provincia').value == "")
		{
		alert("Por favor, introduzca la provincia.");
		error="n";
		return false;
		}	
	if (document.getElementById('cp').value=="")
		{
		alert("Por favor, introduzca el CP.");
		error="n";
		return false;
		}	
	if (isNaN(document.getElementById('cp').value))
		{
		alert("El CP no es v\xE1lido.");
		error="n";
		return false;
		}	
	if (document.getElementById('tlfn1').value=="")
		{
		alert("Por favor, introduzca el tel\xE9fono 1.");
		error="n";
		return false;
		}
	if (comprueba_tfno(document.getElementById('tlfn1').value,1)==false)
		{
		error="n";
		return false;
		}
	/*else if (document.getElementById('fax').value == "")
		{
		alert("Por favor, introduzca el fax.");
		error="n";
		return false;
		}
	else if(isNaN(document.getElementById('fax').value))
		{
		alert("El formato del fax no es v\xE1lido.");
		error="n";
		return false;			
		}	*/	
	if (document.getElementById('mail').value=="")
		{
		alert("Por favor, introduzca el correo electr\xF3nico.");
		error="n";
		return false;
		}
	if (comprueba_mail(document.getElementById('mail').value) == false)
		{
		error="n";
		return false;
		}
		
	/*else if( (comprueba_NIF(document.getElementById('nif').value)==false && validaCIF(document.getElementById('nif').value)==false) || comprueba_tfno(document.getElementById('tlfn1').value,1)==false || /*comprueba_tfno(document.getElementById('tlfn2').value,2)==false ||* comprueba_mail(document.getElementById('mail').value) == false)
	{
			
		error="n";
	}*/
	else
		{
		if (document.getElementById('captcha'))
		{
			if (document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
			{
				
				alert("Introduzca el texto de la imagen correctamente.");
				error="n";
				return false;	
			}
		}
		if (!(document.getElementById('AceptarCondiciones').checked))
			{
			alert("Es obligatorio aceptar las condiciones y el aviso legal.");
			error="n";
			return false;
			}			
		}			
	
	if (error == "")
		{
		document.formVentajas.submit();
		}			
	}
	
function comprueba_NIF(abc)
{
	dni=abc.substring(0,abc.length-1);
	let=abc.charAt(abc.length-1);
	if (!isNaN(let)) {
		//alert("El NIF no es v\xE1lido");		
		return false;
	}else{
		cadena = "TRWAGMYFPDXBNJZSQVHLCKET";
		posicion = dni % 23;
		letra = cadena.substring(posicion,posicion+1);
		if (letra!=let.toUpperCase()){
			//alert("El NIF no es v\xE1lido");
			return false;
		}
	}
	return true;
}	

function validaCIF(CIF)
{
	var pares = 0;
	var impares = 0;
	var suma, ultima, numero;
	var letra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
	var cad;
	
	CIF = CIF.toUpperCase();
	
	var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
	if (!regular.exec(CIF)) return false;
		 
	ultima = CIF.substr(8,1);
	
	for (var cont = 1 ; cont < 7 ; cont ++){
		cad = (2 * parseInt(CIF.substr(cont++,1))).toString() + "0";
		impares += parseInt(cad.substr(0,1)) + parseInt(cad.substr(1,1));
		pares += parseInt(CIF.substr(cont,1));
	}
	cad = (2 * parseInt(CIF.substr(cont,1))).toString() + "0";
	impares += parseInt(cad.substr(0,1)) + parseInt(cad.substr(1,1));
	
	suma = (pares + impares).toString();
	numero = parseInt(suma.substr(suma.length - 1, 1));
	numero = (10 - numero).toString();
	if(numero == 10) numero = 0;
	
	if ((ultima == numero) || (ultima == letra[numero]))
		return true;
	return false; 
}	
	
function comprueba_tfno(telefono,num)
{
	if((num==2 && telefono!='') || num==1 || num==0)
		{
			if ( isNaN(telefono) || telefono.length != 9)
			{	
				if(num==0)
					alert("El formato del tel\xE9fono no es v\xE1lido");	
				else if(num==1)
					alert("El formato del tel\xE9fono 1 no es v\xE1lido");
				else
					alert("El formato del tel\xE9fono 2 no es v\xE1lido");
				return false;
			}
			else
			{
				if ( !( (telefono >= 900000000) && (telefono < 1000000000) || (telefono >= 600000000) && (telefono < 700000000) ) )  
				{	
					if(num==0)
						alert("El formato del tel\xE9fono no es v\xE1lido");	
					else if(num==1)
						alert("El formato del tel\xE9fono 1 no es v\xE1lido");
					else
						alert("El formato del tel\xE9fono 2 no es v\xE1lido");			
					return false;
				}
			}	
		}
}

function comprueba_mail(email)
{
	var b=/^\w+([\.-ñ]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
	if ( b.test(email) == false )
	{
		alert("El formato del e-mail no es v\xE1lido");
		return false;
	}
	return true;
}	

function validaFormularioFormacion(){
	var check = false;
	var i = 0;
	for (i = 0; i < document.formacionForm.curso_solicitado.length; i++)
		check = document.formacionForm.curso_solicitado[i].checked || check;
	if (!check){
		alert("Debe solicitar al menos un curso");
		return false;
	}
	check = false;
	for (i = 0; i < document.formacionForm.nombre_asistente.length; i++)
		check = (document.formacionForm.nombre_asistente[i].value!='') || check ;
	if (!check){
		alert("Debe incribir al menos a un asistente ");
		return false;
	}
	check = false;
	for (i = 0; i < document.formacionForm.cualificacion.length; i++)
		check = document.formacionForm.cualificacion[i].checked || check ;
	if (!check){
		alert("Al menos 1 una cualificacion es necesaria");
		return false;
	}
	
	if (document.getElementById('tel_contacto').value == ""){
		alert("Por favor, introduzca el tel\xE9fono de contacto.");
		error="n";
		return false;
	}
	
	if (comprueba_tfno(document.getElementById('tel_contacto').value,0)==false)
		{
		error="n";
		return false;
		}

	//if (document.getElementById('datos_empresa').value == ""){
	//	alert("Por favor, introduzca datos Empresa.");
	//	error="n";
	//	return false;
	//}

	if (document.getElementById('nombre_empresa').value == ""){
		alert("Por favor, introduzca el Nombre de Empresa.");
		error="n";
		return false;
	}

	//if (document.getElementById('actividad_principal').value == ""){
	//	alert("Por favor, introduzca la Actividad Principal.");
	//	error="n";
	//	return false;
	//}

	if (document.getElementById('direccion').value == ""){
		alert("Por favor, introduzca la Direcci\xF3n.");
		error="n";
		return false;
	}
		
	if ( document.getElementById('cp').value == ""){
		alert("Por favor, introduzca el c\xF3digo postal.");
		error="n";
		return false;
	}
	
	if ( document.getElementById('cp').value.length != 5 ){
		alert("El c\xF3digo postal introducido no es v\xE1lido. (longitud) ");
		error="n";
		return false;
	}
	
	if ( isNaN(document.getElementById('cp').value) ) {
		alert("El c\xF3digo postal introducido no es v\xE1lido. (no es numl\xE9rico)");
		error="n";
		return false;
	}
	
	//if (document.getElementById('poblacion').value == ""){
	//	alert("Por favor, introduzca la Poblacion.");
	//	error="n";
	//	return false;
	//}
	
	//if (document.getElementById('provincia').value == ""){
	//	alert("Por favor, introduzca la Provincia.");
	//	error="n";
	//	return false;
	//}
	
	if (document.getElementById('telefono').value == ""){
		alert("Por favor, introduzca el tel\xE9fono.");
		error="n";
		return false;
	}

	if (comprueba_tfno(document.getElementById('telefono').value,0)==false){
		//alert("Por favor, introduzca el tel\xE9fono correctamente.");
		error="n";
		return false;
	}

	//if (document.getElementById('fax').value == ""){
	//	alert("Por favor, introduzca el c\xF3digo postal.");
	//	error="n";
	//	return false;
	//}*/

	//if (isNaN(document.getElementById('fax').value)){

	//	alert("Por favor, introduzca el telefono correctamente.");
	//	error="n";
	//	return false;
	//}
	
	if (document.getElementById('email').value==""){
		alert("Por favor, introduzca el email.");
		error="n";
		return false;
	}
	
    if(comprueba_mail(document.getElementById('email').value)==false){
		return false;
	}
	if (document.getElementById('captcha'))
	{
		if (document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
		{
			
			alert("Introduzca el texto de la imagen correctamente.");
			error="n";
			return false;	
		}
	}
	if (!document.formacionForm.condiciones.checked){
		alert("Debe aceptar las condiciones.");
		return false;		
	}
	
	document.formacionForm.submit();
}

function cargaBusquedaSAT()
{
	var cadenaLimpia;
		
	if ( $('cp_lateral').value != 'Código Postal' )
	{
		if ($('cp_lateral').value.indexOf(' ') != -1)
			alert('No se permiten espacios en blanco en la búsqueda por CP.');
		else 
			if (isNaN($('cp_lateral').value) && ( $('cp_lateral').value.substring(0,2) != 'AD'  &&  $('cp_lateral').value.substring(0,2) != 'ad'))
				alert('Los únicos CP con letras comienzan por AD para Andorra.');
		else 
			if ($('cp_lateral').value != "")
				$('form_busca_sat_lateral').submit();
	}
}

function longitudCP(input)
{
	if ($(input).value.length > 5)
		$(input).value = $(input).value.substring(0,5);
}

function checkSat(chk)
{
	if(chk.checked == true && chk.id== "aireAcondicionado")
		$('calefaccion').checked = false;
	if(chk.checked == true && chk.id== "calefaccion")
		$('aireAcondicionado').checked = false;
}
function cerrarCuadro()
{
	$('div_cuadroInfo').style.display = 'none';
	$('div_cuadroInfo_cerrar').style.display = 'none';
}

function abrirCuadro()
{
	$('div_cuadroInfo').style.display = 'inline';
	$('div_cuadroInfo_cerrar').style.display = 'inline';
}

function cambiaImagenCabecera_3Tipos(tipo, ruta)
{
	if(tipo == 1)
		$('img_carruselCabecera').src = ruta+'/images/carrusel_cabecera1.gif';
	if(tipo == 2)
		$('img_carruselCabecera').src = ruta+'/images/carrusel_cabecera2.gif';
	if(tipo == 3)
		$('img_carruselCabecera').src = ruta+'/images/carrusel_cabecera3.gif';
}

//--------- MAPA GOOGLEEEEEEEEEEEEEEEE !!!!!!!!!!!!!!!! ------------------------------------//

function cargaMapa()
{
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		var geocoder = new GClientGeocoder();
		var address = "Orense, 58 (Madrid)";
		
		var LatLng = new GLatLng(geocoder.getLatLng(address, function(point) {
				map.setCenter(point, 15);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
				var myHtml = "<font style='font-size: 14px;'><b>Portal WATCH</b></font><br/><font style='font-size: 11px;'>Orense, 58<br/>28020 Madrid (España)";
				myHtml += "<br/><b>Teléfono:</b> 915567698  | <b>FAX:</b> 915567589</font>";
				map.openInfoWindowHtml(point, myHtml);			  
			}
		  )
		);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(LatLng);
	}
}

function enviaAviso()
{
	if($('Apellidos').value == '')
	{
		alert("Introduzca los apellidos");
		return false;
	}
	if($('Apellidos').value.length > 60)
	{
		alert("Introduzca los apellidos");
		return false;
	}
	if($('Nombre').value == '')
	{
		alert("Introduzca el nombre");
		return false;
	}
	if($('Nombre').value.length > 60)
	{
		alert("Nombre demasiado grande");
		return false;
	}
	if($('codigo_postal').value == '' || $('codigo_postal').value.replace(/^\s+|\s+$/g, "") == "")
	{
		alert("Introduzca el cp.");
		return false;
	}
	if($('codigo_postal').value != '' && isNaN($('codigo_postal').value))
	{
		alert("Introduzca el cp, debe se numérico.");
		return false;
	}
	if($('codigo_postal').value.length > 5)
	{
		alert("CP demasiado grande");
		return false;
	}
	if($('Poblacion').value.length > 50)
	{
		alert("Población demasiado grande");
		return false;
	}
	if($('Telefono').value == '' || isNaN($('Telefono').value))
	{
		alert("Introduzca el teléfono, \n\n Debe se numérico de hasta 15 caracteres.");
		return false;
	}
	if($('Telefono').value.length > 15)
	{
		alert("El telefono es muy largo");
		return false;
	}
	if($('Provincia').value == 0)
	{
		alert("Debe seleccionar una provincia");
		return false;
	}
	if($('movil').value.length > 15)
	{

		alert("El telefono movil es muy largo");
		return false;
	}
	if($('motivo').value == "")
	{
		alert("Introduzca el motivo de la consulta.");
		return false;
	}
	if($('motivo').value.length > 10000)
	{
		alert("El motivo es demasiado grande");
		return false;
	}
	if (document.getElementById('captcha'))
	{
		if (document.getElementById('captcha').value.toUpperCase() != document.getElementById('ImgnCptch').value)	
		{
			
			alert("Introduzca el texto de la imagen correctamente.");
			error="n";
			return false;	
		}
	}
	if($('AceptarCondiciones').checked == false)
	{
		alert("Debe aceptar las condiciones para completar el formulario");
		return false;
	}
	
	$('div_cuadro_formulario').style.display = 'none';
	$('div_cuadro_exito').style.display = 'inline';
	document.formCambiaCaldera.submit();
}

function overSello(imagen, event)
{
	var cadenaImagenSello = '<img src="/images/sellos/'+imagen+'" style="max-width:400px; max-height:400px; border:1px #F06E13 solid;" />';	
	
	var x = event.clientX;
	var y = event.clientY;

	$('div_carga_sello').style.left = x + 'px';
	$('div_carga_sello').style.top = (y - 400) + 'px';
	
	$('div_carga_sello').innerHTML = cadenaImagenSello;
	$('div_carga_sello').style.display = 'block';
}


function recargarCaptcha()
{
	cargaPagina('/recarga_captcha.php','div_captcha','');
	
}

var geocoder;
var map;
var marker;
function cargaMapa2()
{
	if (GBrowserIsCompatible()) {
		map = new GMap2($("mapa"));
		geocoder = new GClientGeocoder();		
		var posicion;
		var address = document.getElementById('direccion').value;	
		//if(address == "") address = "johan carballeira 8 bajo vigo";
		if(document.getElementById('lat').value != "" && document.getElementById('lon').value != "")
		{
			var LatLng = new GLatLng(document.getElementById('lat').value, document.getElementById('lon').value);
			map.setCenter(LatLng, 16);
			marker = new GMarker(LatLng);
			map.addOverlay(marker);
		}
		else
		{
			var LatLng = new GLatLng(geocoder.getLatLng(address, function(point) {
					posicion = point;
					map.setCenter(point, 16);
					marker = new GMarker(point);
					map.addOverlay(marker);
					posicion = posicion.toString();
					posicion = posicion.replace('(', '');
					posicion = posicion.replace(")", '');
					corte = posicion.split(", ");
					document.getElementById('lat').value = corte[0];
					document.getElementById('lon').value = corte[1];
				}
				)
			);
		}
		GEvent.addListener(map, "click", function (overlay,point){
			if (point){
				marker.setPoint(point); 
			}
			//marker.openInfoWindowHtml("Latitud: " + point.lat() + "<br>Longitud: " + point.lng());
			document.getElementById('lat').value = point.lat();
			document.getElementById('lon').value = point.lng();
		});
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		//map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
		map.setCenter(LatLng);
	}
}




