// JScript source code
var paginaActiva = "";
var strIdioma    = "es";
var colorAzul    = "#134791";
var colorBlanco  = "white";
var OpenWindow   = null;
// ---------------------------------------------------------------------- //
var nImgIndex=0;
var ArrayImgHotel=new Array();
ArrayImgHotel[nImgIndex]="/Imagenes/VistaExterior.jpg";
ArrayImgHotel[++nImgIndex]="/Imagenes/Habitacion.jpg";

nImgIndex=0;
var ArrayImgDescription=new Array();
ArrayImgDescription[nImgIndex]="Vista Exterior";
ArrayImgDescription[++nImgIndex]="Habitacion Doble";

var nImgCounter=ArrayImgHotel.length-1;
// ---------------------------------------------------------------------- //
function set_active_page(page,idioma)
{
    strIdioma = idioma;
    paginaActiva = page;
    if(paginaActiva=="CONOCENOS")
    {                
        menu_on("mnuConocenos");
        document.getElementById("fontConocenos").color="#134791";
        nImgIndex=0;
    }
    else if(paginaActiva=="TARIFAS")
    {
        menu_on("mnuTarifas");
        document.getElementById("fontTarifas").color="#134791";
    }
    else if(paginaActiva=="RESERVAS")
    {
        menu_on("mnuReserva");
        document.getElementById("fontReserva").color="#134791";
        nImgIndex=1;
    }
    else if(paginaActiva=="LOCALIZACION")
    {
        menu_on("mnuLocalizacion");
        document.getElementById("fontLocalizacion").color="#134791";       
    } 
    else if(paginaActiva=="FOTOS")
    {
        menu_on("mnuFotos");
        document.getElementById("fontFotos").color="#134791";
    } 
    else if(paginaActiva=="PTOINTERES")
    {
        menu_on("mnuPtoInteres");
        document.getElementById("fontPtoInteres").color="#134791";
    }    
}
// ---------------------------------------------------------------------- //
function menu_on(menuID)
{     
    document.getElementById(menuID).bgColor=colorBlanco; 
    if( menuID == "mnuTarifas")
    {
        fontTarifas.color = colorAzul;  
        showmenu("idDisplayTarifas");
    }
}
// ---------------------------------------------------------------------- //
function menu_off(menuID)
{     
    document.getElementById(menuID).bgColor=colorAzul;  
    if( menuID == "mnuTarifas")
    {
        fontTarifas.color = colorBlanco;
        hidemenu("idDisplayTarifas");        
    }
}

// ---------------------------------------------------------------------- //
function showmenu(elmnt)
{
    document.getElementById(elmnt).style.visibility="visible";
}
// ---------------------------------------------------------------------- //
function hidemenu(elmnt)
{
    document.getElementById(elmnt).style.visibility="hidden";
}
// ---------------------------------------------------------------------- //
function previous_img(ImgViewer,ImgDescription)
{
    if (nImgIndex>0)
	{
	    nImgIndex--;	
	}
    else
    {
        nImgIndex = nImgCounter;
    }
    document.getElementById(ImgViewer).src=ArrayImgHotel[nImgIndex];
    document.getElementById(ImgDescription).innerHTML=ArrayImgDescription[nImgIndex];

}
// ---------------------------------------------------------------------- //
function next_img(ImgViewer,ImgDescription)
{
    if (nImgIndex<nImgCounter)
	{
	    nImgIndex++;	
	}
    else
    {
        nImgIndex = 0;
    }
    document.getElementById(ImgViewer).src=ArrayImgHotel[nImgIndex];
    document.getElementById(ImgDescription).innerHTML=ArrayImgDescription[nImgIndex];    
}
// ---------------------------------------------------------------------- //
function clientSideInclude(idIncludeDiv,url) 
{
    var req = false;
    url= "http://www.hotelelpozo.es/Include/" + url;

    // For Safari, Firefox, and other non-MS browsers
    if (window.XMLHttpRequest) 
    {
        try 
        {
        req = new XMLHttpRequest();
        } 
        catch (e) 
        {
        req = false;
        }
    } 
    else if (window.ActiveXObject) 
    {
        // For Internet Explorer on Windows
        try 
        {
        req = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) 
            {
                req = false;
            }
        }
    }

    var element = document.getElementById(idIncludeDiv);    
    if (!element) 
    {
        alert("Bad id " + idIncludeDiv + 
                "passed to clientSideInclude." +
                "You need a div or span element " +
                "with this id in your page.");
        return;
    }

    if (req) 
    {
        // Synchronous request, wait till we have it all
        req.open('GET', url, false);
        req.send(null);
        element.innerHTML = req.responseText;                
    } 
    else 
    {
        element.innerHTML =
        "Sorry, your browser does not support " +
        "XMLHTTPRequest objects. This page requires " +
        "Internet Explorer 5 or better for Windows, " +
        "or Firefox for any system, or Safari. Other " +
        "compatible browsers may also exist.";
    }
}

function processClick(elementDate)
{
	var obj = document.getElementById(elementDate);			
	displayDatePicker(elementDate, false, 'dmy');
	return true;
}

function ValidarReserva()
{	
	var strError = "";
    var bResult  = true;

    if (document.frmReserva.Fecha_Entrada.value.length==0)
	{
        if(strIdioma == "es")
        {
		    strError+= "- Fecha de entrada\n";
        }
        else
        {
            strError+= "- Arrival Date\n";
        }
		bResult = false;
	}

    if (document.frmReserva.Fecha_Salida.value.length==0)
	{
		if(strIdioma == "es")
        {
		    strError+= "- Fecha de salida\n";
        }
        else
        {
            strError+= "- Departure Date\n";
        }
		bResult = false;
	}

	if (document.frmReserva.Nombre.value.length==0)
	{
		if(strIdioma == "es")
        {
		    strError+= "- Nombre\n";
        }
        else
        {
            strError+= "- First Name\n";
        }
		bResult = false;
	}
    
    if (document.frmReserva.Apellidos.value.length==0)
	{
		if(strIdioma == "es")
        {
		    strError+= "- Apellidos\n";
        }
        else
        {
            strError+= "- Last Name\n";
        }
		bResult = false;
	}

    var strPhone = document.frmReserva.Telefono.value
    var FilterPhone = /^(\+?\(\d+\)\s*)?\d+$/;
	if (strPhone.length==0 || !FilterPhone.test(strPhone))
	{
		if(strIdioma == "es")
        {
		    strError+= "- Teléfono.Ejemplo de formatos:\n";
            strError+= "      Nacional:   699100100\n";
            strError+= "      Extranjero: +(32)699100100\n";
        }
        else
        {
            strError+= "- Phone.Format sample:\n";
            strError+= "      National:   699100100\n";
            strError+= "      Foreign: +(32)699100100\n";
        }
		testresults=false;
	}	

    var strEmail = document.frmReserva.Email.value;
	var FilterEMail=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (strEmail.length==0 || !FilterEMail.test(strEmail))
	{
		if(strIdioma == "es")
        {
		    strError+= "- Correo Electrónico\n";
        }
        else
        {
            strError+= "- E-Mail\n";
        }
		bResult = false;
	}

    if(!bResult)
    {
        if(strIdioma == "es")
        {
		    alert( "Por favor, introduzca los siguientes datos:\n" + strError );
        }
        else
        {
            alert( "Please, enter the following data:\n" + strError );
        }
    }
    else
	{	
/*	
        var splitDate = /(\d+)\/(\d+)\/(\d+)/;

        var aFechaEntrada = splitDate.exec(document.frmReserva.Fecha_Entrada.value);		
		var dEntrada = new Date();
        dEntrada.setFullYear(FechaEntrada[3],aFechaEntrada[2],aFechaEntrada[1]);

        var aFechaSalida  = splitDate.exec(document.frmReserva.Fecha_Salida.value);
        var dSalida = new Date();
        dSalida.setFullYear(aFechaSalida[3],aFechaSalida[2],aFechaSalida[1]);

        alert(dSalida.toDateString());
        alert(dEntrada.toDateString());
		if (dSalida<=dEntrada)
		{
			strError = "La fecha de salida debe ser posterior a la fecha de entrada\n";
            alert(strError);    
            bResult = false;
		}
*/
	}
   		
	return (bResult);
}
function DisplayIdioma(csIdioma)
{
    strIdioma = csIdioma;
    var strPage = "";
    alert(csIdioma);
    if(strIdioma=="es")
    {
        if(paginaActiva=="CONOCENOS")
        {                
            strPage = "/index.htm";
        }        
        else if(paginaActiva=="RESERVAS")
        {
            strPage = "/Reservas.htm";
        }
        else if(paginaActiva=="LOCALIZACION")
        {
            strPage = "./Localizacion.htm";
        } 
        else if(paginaActiva=="FOTOS")
        {
            strPage = "/GaleriaFotos.htm";
        }         
   }
   else if(strIdioma=="en")
    {
        if(paginaActiva=="CONOCENOS")
        {                
            strPage = "/index_e.html";
        }        
        else if(paginaActiva=="RESERVAS")
        {
            strPage = "/Reservas_e.htm";
        }
        else if(paginaActiva=="LOCALIZACION")
        {
            strPage = "./Localizacion_e.htm";
        } 
        else if(paginaActiva=="FOTOS")
        {
            strPage = "/GaleriaFotos_e.htm";
        }         
   }
    else if(strIdioma=="fr")
    {
        if(paginaActiva=="CONOCENOS")
        {                
            strPage = "/index_f.html";
        }        
        else if(paginaActiva=="RESERVAS")
        {
            strPage = "/Reservas_f.htm";
        }
        else if(paginaActiva=="LOCALIZACION")
        {
            strPage = "/Localizacion_f.htm";
        } 
        else if(paginaActiva=="FOTOS")
        {
            strPage = "/GaleriaFotos_f.htm";
        }         
   }    
     
    return strPage;
}

// ---------------------------------------------------------------------- //
//                                MAPA                                    //
// ---------------------------------------------------------------------- // 
var map      = null;
var gdir     = null;
var geocoder = null;
var addressMarker;

function initialize_map() 
{
    if (GBrowserIsCompatible()) 
    {      
        map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleMapErrors);        
    }
}
    
function setMapDirections(fromAddress, toAddress, locale) 
{
    gdir.load("from: " + fromAddress + " to: " + toAddress,
             { "locale": locale });
}

function CalcRuta(csDireccion) 
{
    if(csDireccion=="")
    {
        if(strIdioma == "es")
        {
	        alert( "Por favor, introduzca la direccion origen.");
        }
        else
        {
            alert( "Please, enter the direction.");
        }
	    return; 
    }  

    if(map == null)
        initialize_map();
    
    TablaRuta.style.visibility="visible";
    setMapDirections(csDireccion, "Casablanca 4 Torremolinos Malaga España", strIdioma);
}

function handleMapErrors()
{
    if(strIdioma == "es")
    {
	    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	        alert("No podemos indicarle la ruta desde la dirección proporcionada.\n" + 
		        "Esto puede ocurrir porque la dirección sea muy reciente o quizás incorrecta.\n");
	    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	        alert("Lo sentimos pero el servidor de mapas ha devuelto un error.\n");	      
	    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	        alert("Lo sentimos pero el servidor de mapas ha devuelto un error.\n");	     
	    else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	    alert("Lo sentimos pero el servidor de mapas ha devuelto un error.\n");
	    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	        alert("No podemos indicarle la ruta desde la dirección proporcionada.\n" + 
		        "Esto puede ocurrir porque la dirección sea muy reciente o quizás incorrecta.\n");	    
	    else alert("Lo sentimos pero el servidor de mapas ha devuelto un error.\n");
    }	
    else
    {        
       if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.");	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.");
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given.");
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.");	    
	   else alert("An unknown error occurred.");
    }   
}

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...
}

