
var idioma="";
var lenguaje="";
var opcion="";
var fechasOrden,fechas,numeroNoches,nombre,telefono,preferencia,observaciones;

$(document).ready(function () {
   
	switch($("#idioma").val())
	{
	case '1': idioma="es";break;
	case '2': idioma="en";break;
	case '3': idioma="fr";break;
	case '4': idioma="de";break;
	case '5': idioma="cat";break;
	}
	switch(idioma)
        {
            case 'es':
                fechas = 'FECHAS';
                fechasOrden = "[DD/MM/AA]";
                numeroNoches = 'Nº NOCHES';
                nombre = 'NOMBRE';
                telefono = 'TELEFONO';
                preferencia = 'PREFERENCIA';
                observaciones = 'OBSERVACIONES';
                break;
            case 'en':
                fechas = 'DATES';
                fechasOrden = "[DD/MM/YY]";
                numeroNoches = 'NIGHTS';
                nombre = 'NAME';
                telefono = 'PHONE';
                preferencia = 'PREFERENCES';
                observaciones = 'COMMENTS';
                break;
            case 'de':
                fechas = 'DATUM';
                fechasOrden = "[T/M/J]";
                numeroNoches = 'NÁCHTENZAHL';
                nombre = 'NAME';
                telefono = 'TELEFON';
                preferencia = 'VORLIEBE';
                observaciones = 'BEMERKUNG';
                break;
            case 'fr':
                fechas = 'DATES';
                fechasOrden = '[J/M/A]';
                numeroNoches = 'Nº NOCHES';
                nombre = 'NOM';
                telefono = 'TÉLÉPHONE';
                preferencia = 'PRÉFÉRENCE';
                observaciones = 'OBSERVATIONS';
                break;
             case 'cat':
                fechas = 'DATES';
                fechasOrden = "[DD/MM/AA]";
                numeroNoches = 'Nº NOCHES';
                nombre = 'NOM';
                telefono = 'TELEFON';
                preferencia = 'PREFERENCIES';
                observaciones = 'REMARQUES';
                break;
        }
        $("#fechas").html(fechas);
        $("#ordenFechas").html(fechasOrden);
        $("#noches").html(numeroNoches);
        $("#nombre").html(nombre);
        $("#telefono").html(telefono);
        $("#preferencia").html(preferencia);
        $("#observaciones").html(observaciones);

	$("img").mouseover(function(){
		switch($(this).attr('id'))
		{
		case 'opt01' : $(this).attr("src","images/"+idioma+"/icoOption01o.gif");break;
		case 'opt02' : $(this).attr("src","images/"+idioma+"/icoOption02o.gif");break;
		case 'opt03' : $(this).attr("src","images/"+idioma+"/icoOption03o.gif");break;
		case 'opt04' : $(this).attr("src","images/"+idioma+"/icoOption04o.gif");break;
		case 'opt05' : $(this).attr("src","images/"+idioma+"/icoOption05o.gif");break;
		case 'opt06' : $(this).attr("src","images/"+idioma+"/icoOption06o.gif");break;
		case 'opt07' : $(this).attr("src","images/"+idioma+"/icoOption07o.gif");break;
		case 'opt08' : $(this).attr("src","images/"+idioma+"/icoOption08o.gif");break;
		}
	});
	$("img").mouseout(function(){
		switch($(this).attr('id'))
		{
		case 'opt01' : $(this).attr("src","images/"+idioma+"/icoOption01r.gif");break;
		case 'opt02' : $(this).attr("src","images/"+idioma+"/icoOption02r.gif");break;
		case 'opt03' : $(this).attr("src","images/"+idioma+"/icoOption03r.gif");break;
		case 'opt04' : $(this).attr("src","images/"+idioma+"/icoOption04r.gif");break;
		case 'opt05' : $(this).attr("src","images/"+idioma+"/icoOption05r.gif");break;
		case 'opt06' : $(this).attr("src","images/"+idioma+"/icoOption06r.gif");break;
		case 'opt07' : $(this).attr("src","images/"+idioma+"/icoOption07r.gif");break;
		case 'opt08' : $(this).attr("src","images/"+idioma+"/icoOption08r.gif");break;
		}
	});
	$("a.ES").click(function(){
		lenguaje='ES';
		idioma='es';
		cambiarLenguaje();
		return false;
	});
	$("a.EN").click(function(){
		lenguaje='EN';
		idioma='en';
		cambiarLenguaje();
		return false;
	});
	$("a.GER").click(function(){
		lenguaje='GER';
		idioma='de';
		cambiarLenguaje();
		return false;
	});
	$("a.FR").click(function(){
		lenguaje='FR';
		idioma='fr';
		cambiarLenguaje();
		return false;
	});
	$("a.CAT").click(function(){
		lenguaje='CAT';
		idioma='cat';
		cambiarLenguaje();
		return false;
	});
	function cambiarLenguaje()
	{
		$.ajax({
			type: "POST",
			url: "peticionesajax/change-language.php",
			dataType: "html",
			data: {
				idioma: lenguaje
			},
			success: function(data, stat) {
				cargarContenido();
			},
			error: function(xhr, stat, err) {
				if ($("#_firebugConsole")) {
					console.log(xhr, stat, err);
				}
			}
		});
	}
	function cargarContenido()
	{
		var tab=$("#tabla").val();
		opcion = $("#opt").val();
		var room=0;
		if($("#tabla").val()=='t_roomslanguage')
		{
			room=$("#habitacion").val();
		}
		$.ajax({
			type: "POST",
			url: "peticionesajax/cargarContenido.php",
			dataType: "json",
			data: {
				tabla: tab,
				habitacion: room,
				opt: opcion
			},
			success: function(data) {
				if(tab!='t')
				{
                                    switch(opcion)
                                    {
                                        case '1':
                                        case '2':
                                        case '3':
                                            $("#scroll").html(data[1]);
                                            if(opcion!=0)
                                            {
                                                    $(document).attr("title", data[2] + " | Hotel Cresol");
                                            }
                                            break;
                                        case '4':
                                            $("#supl").html(data[1][0]);
                                            $("#oferta").html(data[1][1]);
                                            $("#explic").html(data[1][2]);
                                            for(var i=1;i<6;i++)
                                            {
                                                $("#ht"+i+"n").html(data[1][3][i-1]);
                                                $("#ht"+i+"pd").html(data[1][4][i-1]);
                                                $("#ht"+i+"pi").html(data[1][5][i-1]);
                                            }
                                            break;
                                        case '5':
                                            $("#preform").html(data[1][0]);
                                            $("#lopd").html(data[1][1]);
                                           
                                            switch(idioma)
                                            {
                                                case 'es':
                                                    fechas = 'FECHAS';
                                                    fechasOrden = "[DD/MM/AA]";
                                                    numeroNoches = 'Nº NOCHES';
                                                    nombre = 'NOMBRE';
                                                    telefono = 'TELEFONO';
                                                    preferencia = 'PREFERENCIA';
                                                    observaciones = 'OBSERVACIONES';
                                                    break;
                                                case 'en':
                                                    fechas = 'DATES';
                                                    fechasOrden = "[DD/MM/YY]";
                                                    numeroNoches = 'NIGHTS';
                                                    nombre = 'NAME';
                                                    telefono = 'PHONE';
                                                    preferencia = 'PREFERENCES';
                                                    observaciones = 'COMMENTS';
                                                    break;
                                                case 'de':
                                                    fechas = 'DATUM';
                                                    fechasOrden = "[TT/MM/JJ]";
                                                    numeroNoches = 'NÁCHTENZAHL';
                                                    nombre = 'NAME';
                                                    telefono = 'TELEFON';
                                                    preferencia = 'VORLIEBE';
                                                    observaciones = 'BEMERKUNG';
                                                    break;
                                                case 'fr':
                                                    fechas = 'DATES';
                                                    fechasOrden = '[JJ/MM/AA]';
                                                    numeroNoches = 'Nº NOCHES';
                                                    nombre = 'NOM';
                                                    telefono = 'TÉLÉPHONE';
                                                    preferencia = 'PRÉFÉRENCE';
                                                    observaciones = 'OBSERVATIONS';
                                                    break;
                                                 case 'cat':
                                                    fechas = 'DATES';
                                                    fechasOrden = "[DD/MM/AA]";
                                                    numeroNoches = 'Nº NOCHES';
                                                    nombre = 'NOM';
                                                    telefono = 'TELEFON';
                                                    preferencia = 'PREFERENCIES';
                                                    observaciones = 'REMARQUES';
                                                    break;
                                            }
                                            $("#fechas").html(fechas);
                                            $("#ordenFechas").html(fechasOrden);
                                            $("#noches").html(numeroNoches);
                                            $("#nombre").html(nombre);
                                            $("#telefono").html(telefono);
                                            $("#preferencia").html(preferencia);
                                            $("#observaciones").html(observaciones);
                                            break;
                                    }
                                   
				}
				cargarMenu(data[0]);
                                cargarTitular();
			},
			error: function(xhr, stat, err) {
				if ($("#_firebugConsole")) {
					console.log(xhr, stat, err);
				}
			}
		});
	}
	function cargarMenu(literales)
	{
		if(opcion==1)
		{
			$("#opt01img").attr("src","images/"+idioma+"/icoOption01o.gif");
			$("#opt01img").attr("title",literales[0]);
		}
		else
		{
			$("#opt01").attr("src","images/"+idioma+"/icoOption01r.gif");
			$("#opt01").attr("title",literales[0]);
		}		
		if(opcion==2)
		{	
			$("#opt02img").attr("src","images/"+idioma+"/icoOption02o.gif");
			$("#opt02img").attr("title",literales[1]);
		}
		else
		{
			$("#opt02").attr("src","images/"+idioma+"/icoOption02r.gif");
			$("#opt02").attr("title",literales[1]);
		}
		if(opcion==3)
		{
			$("#opt03img").attr("src","images/"+idioma+"/icoOption03o.gif");
			$("#opt03img").attr("title",literales[2]);
		}
		else
		{
			$("#opt03").attr("src","images/"+idioma+"/icoOption03r.gif");
			$("#opt03").attr("title",literales[2]);
		}
		if(opcion==4)
		{
			$("#opt04img").attr("src","images/"+idioma+"/icoOption04o.gif");
			$("#opt04img").attr("title",literales[3]);
		}
		else
		{
			$("#opt04").attr("src","images/"+idioma+"/icoOption04r.gif");
			$("#opt04").attr("title",literales[3]);
		}
		if(opcion==5)
		{
			$("#opt05img").attr("src","images/"+idioma+"/icoOption05o.gif");
			$("#opt05img").attr("title",literales[4]);
		}
		else
		{
			$("#opt05").attr("src","images/"+idioma+"/icoOption05r.gif");
			$("#opt05").attr("title",literales[4]);
		}
		if(opcion==6)
		{
			$("#opt06img").attr("src","images/"+idioma+"/icoOption06o.gif");
			$("#opt06img").attr("title",literales[5]);
		}
		else
		{
			$("#opt06").attr("src","images/"+idioma+"/icoOption06r.gif");
			$("#opt06").attr("title",literales[5]);

		}
		if(opcion==7)
		{
			$("#opt07img").attr("src","images/"+idioma+"/icoOption07o.gif");
			$("#opt07img").attr("title",literales[6]);
		}
		else
		{
			$("#opt07").attr("src","images/"+idioma+"/icoOption07r.gif");
			$("#opt07").attr("title",literales[6]);
		}
		if(opcion==8)
		{
			$("#opt08img").attr("src","images/"+idioma+"/icoOption08o.gif");
			$("#opt08img").attr("title",literales[7]);
		}
		else
		{
			$("#opt08").attr("src","images/"+idioma+"/icoOption08r.gif");
			$("#opt08").attr("title",literales[7]);
		}
	}
        function cargarTitular()
        {
            if(opcion=='1')
            {
                $("#titular").attr("src","images/"+idioma+"/titHotel.gif");
            }
        }
	
	
});

