function makeRequest(url,pais,prov,div)
{
	if(div=="provincias")
		document.getElementById('control').value=1;
	if(div=="provincias_2")
		document.getElementById('control').value=2;
	if(div=="poblaciones")
		document.getElementById('control').value=3;

	var n_url=url + "?idPai=" + pais + "&idPro=" + prov;

	document.getElementById(div).innerHTML="Cargando...";
        http_request = false;

        if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType)
			{
                http_request.overrideMimeType('text/xml');
            }
        }
		else if (window.ActiveXObject)
		{ // IE
            try
			{
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e)
			{
                try
				{
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request)
		{
            alert('Falla :( No es posible crear una instancia XMLHTTP');
            return false;
        }
        http_request.onreadystatechange = alertContents;
        http_request.open('GET', n_url, true);
        http_request.send(null);
}

function alertContents()
{
	var div;
	if(document.getElementById('control').value==1)
		div="provincias";
	if(document.getElementById('control').value==2)
		div="provincias_2";
	if(document.getElementById('control').value==3)
		div="poblaciones";
	if (http_request.readyState == 4)
	{
   		if (http_request.status == 200)
		{
			document.getElementById(div).innerHTML=http_request.responseText;
    	}
		else
		{
        alert('Hubo problemas con la petición.');
    	}
	}
}

function actualizar(){
var v=document.getElementById('prov').value;
document.getElementById('pcia').value=v;
if(document.getElementById('pcia').value==0){
	document.getElementById('poblacion').options[0].selected=true;
	document.getElementById('poblacion').options.length=1;}

}

function mostrar(div)
{
	document.getElementById(div).style.display="";
}


function openWindow(url, name, width, height) {

     w = width
     h = height
     x = Math.round((screen.availWidth-w)/2); //center the top edge
     y = Math.round((screen.availHeight-h)/2); //center the left edge
     if(url=="includes/condiciones_legales.php")
     {
     popupWin = window.open(url, name, "width="+w+",height="+h+",scrollbars=yes,history=no,toolbar=no,resizable=1,statusbar=yes,top="+y+",left="+x+",screeenY="+y+",screenX="+x);
    }else{
			popupWin = window.open(url, name, "width="+w+",height="+h+",scrollbars=no,history=no,toolbar=no,resizable=1,statusbar=yes,top="+y+",left="+x+",screeenY="+y+",screenX="+x);
  		 }


	 popupWin.creator=self;
	 popupWin.window.focus();
}


function ver_foto(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {  // v4.01

	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);

	newWindow.document.open();

	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');

	if (imageType == "swf"){

	newWindow.document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');

	newWindow.document.write('<param name=movie value=\"'+imageName+'\"><param name=quality value=high>');

	newWindow.document.write('<embed src=\"'+imageName+'\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"'+imageWidth+'\" height=\"'+imageHeight+'\">');

	newWindow.document.write('</embed></object>');	}else{

	newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 	}

	newWindow.document.write('</body></html>');

	newWindow.document.close();

	newWindow.focus();



}



//**********FUNCION VALIDAR*************

function validar(url,email,nombre,telefono)
{


var correo=document.getElementById(email).value;
//Comprobamos telefono

if(telefono!="")
{
//******************
//Controlamos si se ponen letras en vez de numeros
var valor=document.getElementById(telefono).value;

	cad = valor.toString();
	for (var i=0; i<cad.length; i++)
	{
		var caracter = cad.charAt(i);
		if (caracter<"0" || caracter>"9")
		{
			alert("Por favor, introduzca números en lugar de letras en el campo teléfono");
			return false;
		}
	}

//*****************
	if(document.getElementById(telefono).value=="")
	{
		alert("Por favor, complete el telefono");
		document.getElementById(telefono).focus();
		return(false);
	}
	else
	{
		if(document.getElementById(telefono).value.length < 8)
		{
			alert("Por favor, introduzca al menos 9 dígitos");
			document.getElementById(telefono).focus();
			return(false);
		}
	}

}

//Comprobamos URL
if(url!=""){
	var reUrlPattern = new RegExp("^(ht|f)tp(s?)\:\/\/[a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+){2,}(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$");

	if (!reUrlPattern.test(document.getElementById(url).value) && document.getElementById(url).value != "")
    {
 	  alert("Por favor, escribe una URL correcta");
	  document.getElementById(url).focus();
 	  return(false);
    }
}

//Comprobamos email
if(email!="" ){
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(correo)==false)
	{
		alert("La dirección de email es incorrecta.");
		document.getElementById(email).focus();

		return (false);
	}

}

//Comprobamos nombre
if(nombre!=""){
			if(document.getElementById(nombre).value=="")
			{
				alert("No puedes dejar el nombre en blanco");
				return(false);
			}
}
	return (true);
}

//**********************************************************************

function Favoritos(titulo,url) {
		if (window.sidebar)
			{ window.sidebar.addPanel(titulo, url,""); }
	 else if( document.all ) {window.external.AddFavorite( url, titulo);}
	 	else if( window.opera && window.print )
		{return true;}
									}
/******************galeria de fotos****************/

function GaleriaFotos(url,imagen_actual,sentido,id_oferta,tabla)
{
	var n_url=url + "?img="+ imagen_actual+"&idOfer="+id_oferta+"&tabla="+tabla+"&sentido="+sentido;
	document.getElementById('foto').innerHTML="Cargando...";
        http_request = false;

        if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType)
			{
                http_request.overrideMimeType('text/xml');
            }
        }
		else if (window.ActiveXObject)
		{ // IE
            try
			{
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e)
			{
                try
				{
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request)
		{
            alert('Falla :( No es posible crear una instancia XMLHTTP');
            return false;
        }
        http_request.onreadystatechange = muestraContenidos;
        http_request.open('GET', n_url, true);
        http_request.send(null);
}

function muestraContenidos()
{

	if (http_request.readyState == 4)
	{
   		if (http_request.status == 200)
		{
			document.getElementById('foto').innerHTML=http_request.responseText;
    	}
		else
		{
        alert('Hubo problemas con la petición.');
    	}
	}
}

/**********ir a pag*********/
function ir_a(paginas,dire){

var pg=parseInt(document.getElementById('pag').value);
	if(paginas>=pg && pg>0)
	{	var ir=dire+"&pagina="+document.getElementById('pag').value;
		location.href=ir;
		}
	else
		alert("Hay un máximo de "+paginas+ " páginas");

}

/***************GoogleMaps********************/
  var map = null;
    var geocoder = null;

    function load(city) {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());


        geocoder = new GClientGeocoder();
		showAddress(city)


      }
    }

    function showAddress(address) {
	//alert(address);
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
             // marker.openInfoWindowHtml(address);
            }
          }
        );
      }
    }
