var xmlhttp
var xmlhttp2
var xmlhttp3
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp3=new ActiveXObject("Msxml2.XMLHTTP");
  tipo ='firefox';
 } catch (e) {
  try {
  	tipo = 'explorer';
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	 xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp3=new ActiveXObject("Msxml2.XMLHTTP");
  } catch (E) {
   xmlhttp=false;
    xmlhttp2=false;
  xmlhttp3=false;
  }
 }
@else
 xmlhttp=false
 xmlhttp2=false;
  xmlhttp3=false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
if (!xmlhttp2 && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp2 = new XMLHttpRequest();
 } catch (e) {
  xmlhttp2=false
 }
}
if (!xmlhttp3 && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp3 = new XMLHttpRequest();
 } catch (e) {
  xmlhttp3=false
 }
}

var map=null;
var myPano=null;
var arrowIcon = new GIcon();
      arrowIcon.iconSize = new GSize(24,24);
      arrowIcon.shadowSize = new GSize(1,1);
      arrowIcon.iconAnchor = new GPoint(12,12);
      arrowIcon.infoWindowAnchor = new GPoint(0,0);
      arrowIcon.image = "http://www.google.com/intl/en_ALL/mapfiles/dir_0.png";

function Decimales(Numero, Decimales) {
pot = Math.pow(10,Decimales);
num = parseInt(Numero * pot) / pot;
nume = num.toString().split('.');
if(nume.length==1) {
  var deci='';
  for(i=0;i<Decimales;i++)
    deci+=String.fromCharCode(48);
  num=nume+'.'+deci;
}
return num;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function calcular(){
	var cantidad= document.getElementById('cantidad');
	var resultado= document.getElementById('resultado');
	var meses= document.getElementById('meses');
	if (cantidad.value=='')
	resultado.innerHTML='';
	else
	{
	if (meses.value!=0)
	{
	
	if (IsNumeric(meses.value) || (IsNumeric(cantidad.value)))
	{
		var cuota = meses.value*cantidad.value;
		cuota = cuota.toFixed(2);
		if (cuota>18)
		resultado.innerHTML='Cuota mensual:<br /><strong>'+cuota+' &euro;/mes</strong>'
		else
		resultado.innerHTML='Cuota mensual:<br /><strong style="color:red">Lo sentimos, la cuota mínima es de 18 &euro;/mes</strong>'
	}
	}
	else
	resultado.innerHTML='';
	}
}

function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
   return (true)
  } else {
      return (false);
  }
}
		var enviar ='no';
			function trim(stringToTrim) {
			return stringToTrim.replace(/^\s+|\s+$/g,"");
		}
function comprobarcontacto(){
var msgerror='';
var telefono = trim(document.f.telefono.value);

if (document.f.nombre.value=='') 
	msgerror = '* Nombre completo\n';
	
	if (document.f.metros.value=='') 
		msgerror += '* Nº de metros a instalar\n';
if (document.f.localidad.value=='') 
	msgerror += '* Localidad\n';
	
if (document.f.provincia.value=='') 
	msgerror += '* Provincia\n';	
if (telefono=='') 
	{
	msgerror = msgerror +'* Teléfono\n';
	}
else
	{
	if (!IsNumeric(telefono)) 
		msgerror = msgerror +'* El teléfono ha de ser un número\n';
	}
	
if (document.f.email.value=='') 
	msgerror += '* Email\n';
else
	{
	if (validarEmail(document.f.email.value)==false)
		msgerror = msgerror +'* El Email parece incorrecto\n';
	}
	
if (!document.f.acepto.checked) 
	msgerror = msgerror +'* Aceptar política de privacidad\n';
	
if (msgerror==''){
 if ((telefono.length)<9)
 	msgerror = '* El teléfono ha de tener 9 cifras como mínimo\n';
	document.f.telefono.focus();
}
if (msgerror!=''){
	alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
	return false;
	}
else{

	document.f.action='enviarpresupuesto.php';
	document.f.submit();
	return false;	

}
}
function financi(){
	if (document.getElementById('cantidad'))
		{
			if (parseFloat(document.getElementById('metrosx').value))
			{
			var precio=(document.getElementById('precio').value*document.getElementById('metrosx').value);
			document.getElementById('cantidad').value=Decimales(precio,2);
			}
		}
}

function comprobarcontacto2(){
var msgerror='';
var telefono = trim(document.f.telefono.value);

if (document.f.nombre.value=='') 
	msgerror = '* Nombre completo\n';

if (document.f.localidad.value=='') 
	msgerror += '* Localidad\n';
	
if (document.f.provincia.value=='') 
	msgerror += '* Provincia\n';
	

if (telefono=='') 
	{
	msgerror += '* Teléfono\n';
	}
else
	{
	if (!IsNumeric(telefono)) 
		msgerror += '* El teléfono ha de ser un número\n';
	}
	
if (document.f.email.value=='') 
	msgerror += '* Email\n';
else
	{
	if (validarEmail(document.f.email.value)==false)
		msgerror +='* El Email parece incorrecto\n';
	}
	
if (!document.f.acepto.checked) 
	msgerror +='* Aceptar política de privacidad\n';
	
if (msgerror==''){
 if ((telefono.length)<9)
 	msgerror = '* El teléfono ha de tener 9 cifras como mínimo\n';
	document.f.telefono.focus();
}
if (msgerror!=''){
	alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
	return false;
	}
else{

	document.f.action='enviarcontacto2.php';
	document.f.submit();
	return false;	

}
}
function calcularrollos(){
	var metros=document.getElementById('metros').value;
	var capa=document.getElementById('resultado');
	if (!IsNumeric(metros)) 
		capa.innerHTML='Debe introducir un valor numérico';
	else
		{
			rollos = metros/5;
			rollos = rollos + (rollos+10)/100;
			capa.innerHTML='Para empapelar '+metros+" m<sup>2</sup> son necesarios:<br /><strong>"+rollos.toFixed(2)+" rollos</strong>";
		}
}

	function cargarmapa(capa,lat,lng,pitchx,yawx)
	{
		var fenwayPark = new GLatLng(lat,lng);
	      panoramaOptions = { latlng:fenwayPark };
		  myPOV = {yaw:yawx,pitch:pitchx,zoom:0};
	      myPano = new GStreetviewPanorama(document.getElementById(capa));
			myPano.setLocationAndPOV(fenwayPark, myPOV);
		
	}
    function initialize2() {
			var map1 = new GMap2(document.getElementById('mapa2'));
			map1.addControl(new GMapTypeControl());
	        map1.addControl(new GSmallMapControl());
			//map1.addControl(new GOverviewMapControl());
			map1.setCenter(new GLatLng(40.417003,-3.703978), 13);
	
	
      var fenwayPark = new GLatLng(40.417003,-3.703978);
      panoramaOptions = { latlng:fenwayPark };
	  myPOV = {yaw:168.6,pitch:-5.2,zoom:0};
      myPano = new GStreetviewPanorama(document.getElementById("mapa1"));
		myPano.setLocationAndPOV(fenwayPark, myPOV);

      GEvent.addListener(myPano, "error", handleNoFlash);
    }

    function handleNoFlash(errorCode) {
      if (errorCode == FLASH_UNAVAILABLE) {
        alert("Error: Flash doesn't appear to be supported by your browser");
        return;
      }
    }
	function show5(){
	if (!document.layers&&!document.all&&!document.getElementById)
	return

	 var Digital=new Date()
	 var hours=Digital.getHours()
	 var minutes=Digital.getMinutes()
	 var seconds=Digital.getSeconds()

	var dn="PM"
	if (hours<12)
	dn="AM"
	if (hours>12)
	hours=hours-12
	if (hours==0)
	hours=12

	 if (minutes<=9)
	 minutes="0"+minutes
	 if (seconds<=9)
	 seconds="0"+seconds
	//change font size here to your desire
	myclock="Hora actual: "+hours+":"+minutes+":"
	 +seconds+" "+dn;
	if (document.layers){
	document.layers.liveclock.document.write(myclock)
	document.layers.liveclock.document.close()
	}
	else if (document.all)
	liveclock.innerHTML=myclock
	else if (document.getElementById)
	document.getElementById("liveclock").innerHTML=myclock
	setTimeout("show5()",1000)
	 }


	window.onload=show5

	function mapacomercio(latx,lngx) {
	  if (GBrowserIsCompatible()) {

	    map = new GMap2(document.getElementById("mapa2"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		gdir = new GDirections(map, document.getElementById("directions"));
	    GEvent.addListener(gdir, "load", onGDirectionsLoad);
	    GEvent.addListener(gdir, "error", handleErrors);
		map.setCenter(new GLatLng(latx,lngx), 16);
		point = new GLatLng(latx,lngx);
		//initialize2(latx,lngx);
		markerx  = new GMarker(point);
		map.addOverlay(markerx);
		svOverlay = new GStreetviewOverlay();
	    map.addOverlay(svOverlay);
		geocoder = new GClientGeocoder();
		var arrow = new GMarker(new GLatLng(latx,lngx,0,0),{icon:arrowIcon});
		map.addOverlay(arrow) ;
		var lastPoint;
		var dir = Math.round(0/3) * 3;
		while (dir >= 120) {dir -= 120;}
		arrow.setImage("http://www.google.com/intl/en_ALL/mapfiles/dir_"+dir+".png");
		GEvent.addListener(map,"click", function(overlay,latlng) {
			if (!overlay) {
          		mymypano.remove();
				mymypano.setLocationAndPOV(latlng);
				arrow.setLatLng(latlng);
				lastPoint = latlng;
				map.setCenter(lastPoint);
				//mostrarcentro();
			}
			else
			{
				//alert('Wooop, google no tiene vista de calle en este punto');
			}
		});
			mymypano = new GStreetviewPanorama(document.getElementById("pano"));
		    fenwayPark = new GLatLng(latx,lngx);
		    myPOV = {yaw:0,pitch:0,zoom:0};
		    mymypano.setLocationAndPOV(fenwayPark, myPOV);
	}
	}
	function showPanoData(panoData) {
		return true;
	}
	function initialize2(lat,lng) {
	panoClient = new GStreetviewClient();  
      var fenwayPark = new GLatLng(lat,lng);
      panoramaOptions = { latlng:fenwayPark };
      myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
	  GEvent.addListener(myPano, "error", handleNoFlash);
 		panoClient.getNearestPanorama(fenwayPark, showPanoData);

	
	}
	function setDirections(fromAddress, toAddress, locale) {
	      gdir.load("from: " + fromAddress + " to: " + toAddress,
	                { "locale": locale });
	    }

	function handleErrors(){
		   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		     alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");
		   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		      alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

		   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		       alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

		   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		      alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

		   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		      alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

		   else   alert("Lo sentimos pero no conocemos la dirección especificada. Por favor pruebe con otra. Gracias.");

		}

		function onGDirectionsLoad(){ 
	      // Use this function to access information about the latest load()
	      // results.

	      // e.g.
	      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
		  // and yada yada yada...
		}
		
		
		//<![CDATA[
		var markers = [];
		var map;
		var gdir;
		var geocoder = null;
		var addressMarker;

		function cargarmapacallejero(latx,lngx) {
		  if (GBrowserIsCompatible()) {

		    map = new GMap2(document.getElementById("mapagrande"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
		    map.setCenter(new GLatLng(latx,lngx), 13);
			point = new GLatLng(latx,lngx);
			markers[0]  = new GMarker(point);
			map.addOverlay(markers[0] );
			geocoder = new GClientGeocoder();
			gdir = new GDirections(map, document.getElementById("directions"));
		    GEvent.addListener(gdir, "load", onGDirectionsLoad);
		    GEvent.addListener(gdir, "error", handleErrors);

		  }
		}
		function showAddress() {
			address=document.buscador.q.value+', Benalmádena';
		      if (geocoder) {
		        geocoder.getLatLng(
		          address,
		          function(point) {
		            if (!point) {
		              alert(address + "\nLo sentimos pero no hemos encontrado la dirección que busca");
		            } else {
		              map.setCenter(point, 19);
		              var marker = new GMarker(point);
		              map.addOverlay(marker);
						latlng=point;
						geocoder.getLocations(latlng, function(addresses) {
				          if(addresses.Status.code != 200) {
				            var okas="no";
				          }
				          else {
				            address = addresses.Placemark[0];
				            var myHtml = address.address;
				            map.openInfoWindow(latlng, myHtml);
							var url = 'guardarcalles.php?direccion='+myHtml;
							//window.open (url);
							/*xmlhttp.open("GET",url,true);
							xmlhttp.onreadystatechange=function() {
							if (xmlhttp.readyState==4) {
								var okas="yes";
							}
							}*/
							document.getElementById('marco').src=url;
				          }
				        });
		              
					
		            }
		          }
		        );
		      }
		return false;
		    }
		
			function clicked(latlng) {
			      if (latlng) {
			        geocoder.getLocations(latlng, function(addresses) {
			          if(addresses.Status.code != 200) {
			            //alert("No hemos encontrado la dirección correspondiente a las cooredenadas: " + latlng.toUrlValue());
			          }
			          else {
			            address = addresses.Placemark[0];
			            var myHtml = address.address;
						return myHtml
			          }
			        });
			      }
			    }
		//]]>
