﻿/*REGISTRO*/

//Registro de administrador
//Se crea un nuevo usuario, y se le asigna el hotel
function jsRegistro() {
    
    var email = document.getElementById("txtEmail").value;
    var pass = document.getElementById("txtPass").value;
    var conf_pass = document.getElementById("txtConfPass").value;
    
    var nombre = document.getElementById("txtNombre").value;
    var contacto = document.getElementById("txtContacto").value;
    var cargo = document.getElementById("txtCargo").value;
    var id_tipoEstablecimiento = document.getElementById("ddlTipoEstabl").value;
    var precalificacion = parseInt(document.getElementById("ddlPrecalif").value);
    var cadena = document.getElementById("rdbCadenaSiHTML").checked;//ver aca
    var nombre_cadena = document.getElementById("txtNombreCadenaHTML").value;
    var cant_aptos = parseInt(document.getElementById("txtCantApart").value);
    var cant_habits = parseInt(document.getElementById("txtCantHabit").value);
    var id_pais = document.getElementById("ddlPais").value;
    var id_provincia = document.getElementById("ddlProvincia").value;
    var ciudad = document.getElementById("txtCiudad").value;
    var direccion = document.getElementById("txtDireccion").value;
    var cod_postal = document.getElementById("txtCodPostal").value;
    var telefono = document.getElementById("txtTelefono").value;
    var web = document.getElementById("txtWeb").value;
    var id_tipoPlan = document.getElementById("ddlTipoPlan").value;
    var calif_facebook = document.getElementById("chkCalifFacebook").checked;
    var imagenAvatar = document.getElementById("idAvatar").value;

	registro.ServerSideRegistro(email, pass, conf_pass, nombre, contacto, cargo, id_tipoEstablecimiento, precalificacion,
                    cadena, nombre_cadena, cant_aptos, cant_habits, id_pais, id_provincia, ciudad, direccion, 
                    cod_postal, telefono, web, id_tipoPlan, imagenAvatar, calif_facebook, ServerSideRegistro_CallBack);
    
}
        
function ServerSideRegistro_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else
    {
        if (response.value){
            //document.getElementById("divError").innerHTML = "Gracias por registrarse.<BR>Se le ha enviado un correo de confirmación.";
            window.location = "registro_exito.aspx";
        }
    }
}

/*HOTEL.ASPX*/

//Chequea si tiene o no la opcion cadena seleccionada, en consecuencia habilita / deshabilita el textbox del nombre de la cadena
function jsChequearRadioButton() {

    var cadena = document.getElementById("rdbCadenaSiHTML").checked;
    
    if(cadena){
        //document.getElementById("txtNombreCadenaHTML").disabled = false;
        document.getElementById("txtNombreCadenaHTML").style.display = "";
    }else{
        document.getElementById("rdbCadenaNoHTML").checked = true;
        document.getElementById("txtNombreCadenaHTML").value = "";//ver aca innerHTML/value
        //document.getElementById("txtNombreCadenaHTML").disabled = true;
        document.getElementById("txtNombreCadenaHTML").style.display = "none";
    }
}

//Para Agregar / Editar un hotel
function jsEnviarDatos(){
    var nombre = document.getElementById("txtNombre").value;
    var contacto = document.getElementById("txtContacto").value;
    var cargo = document.getElementById("txtCargo").value;
    var id_tipoEstablecimiento = document.getElementById("ddlTipoEstabl").value;
    var precalificacion = parseInt(document.getElementById("ddlPrecalif").value);
    var cadena = document.getElementById("rdbCadenaSiHTML").checked;//ver aca
    var nombre_cadena = document.getElementById("txtNombreCadenaHTML").value;
    var cant_aptos = parseInt(document.getElementById("txtCantApart").value);
    var cant_habits = parseInt(document.getElementById("txtCantHabit").value);
    var id_pais = document.getElementById("ddlPais").value;
    var id_provincia = document.getElementById("ddlProvincia").value;
    var ciudad = document.getElementById("txtCiudad").value;
    var direccion = document.getElementById("txtDireccion").value;
    var cod_postal = document.getElementById("txtCodPostal").value;
    var telefono = document.getElementById("txtTelefono").value;
    var web = document.getElementById("txtWeb").value;
    var id_tipoPlan = document.getElementById("ddlTipoPlan").value;
    var calif_facebook = document.getElementById("chkCalifFacebook").checked;
    var imagenAvatar = document.getElementById("idAvatar").value;
    hotel.ServerSideEnviarDatos(nombre, contacto, cargo, id_tipoEstablecimiento, precalificacion, cadena, nombre_cadena, 
                                cant_aptos, cant_habits, id_pais, id_provincia, ciudad, direccion, cod_postal, telefono, 
                                web, id_tipoPlan, imagenAvatar, calif_facebook,ServerSideEnviarDatos_CallBack);
}

function ServerSideEnviarDatos_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        //si es 0, es un nuevo hotel
        if(response.value == 0){
            //si es un nuevo hotel, se dirige a la página donde se setea el diseño, el tipo de calificador, y "mostrar_volveria"
            window.location = "hoteldatoscalif.aspx";
        }else{
            //si esta editando uno ya existente, vuelve al menu
            window.location = "menuhotel.aspx"
        }
        
        
    }    
}


//Si el pais "Argentina" está habilitado, habilita el combo de provincias
function habilitarProvincia(){
    //codArgentina = 13
    var codArgentina = 13;
    //codProvincia = 24 No corresponde
    var noProvincia = 24;
    var pais = document.getElementById("ddlPais").value;
        if (pais == codArgentina){
            document.getElementById("ddlProvincia").disabled = false;
            document.getElementById("ddlProvincia").value = 1; //Buenos Aires
            document.getElementById("txtCiudad").disabled = false;
        }
        else{
            document.getElementById("ddlProvincia").disabled = true;
            document.getElementById("ddlProvincia").value = noProvincia;
            document.getElementById("txtCiudad").disabled = true;
        }

}

/*MENUHOTEL.ASPX*/
function nuevoHotel() {
    menuhotel.ServerSideNuevoHotel(ServerSideNuevoHotel_CallBack);
}
        
function ServerSideNuevoHotel_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        window.location = "hotel.aspx";
    }
}



//Cuando se selecciona un hotel del combo, se actualiza el tipo de plan
//y la habilitacion / deshabilitacion de calificacionies y se actualiza la sesion
function cambiarHotel() {
    
    var id_hotel = document.getElementById("ddlHoteles").value;
    if (id_hotel != ""){
        menuhotel.ServerSideCambiarHotel(id_hotel, ServerSideCambiarHotel_CallBack);
    }
    //si no hay hotel, cargo en la sesión el id_hotel: 0
    else{
        menuhotel.ServerSideEditarHotel(0);
    }
    
}
        
function ServerSideCambiarHotel_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else{
        var hotel  = response.value;
        var plan = getNombrePlan(hotel.id_tipoPlan);
        document.getElementById("tipoPlan").innerHTML = plan;
        
        document.getElementById("cantMeGusta").innerHTML = hotel.cantMeGusta;
        document.getElementById("linkCalificar").href = "http://www.rankhotel.com.ar/calificar.aspx?id=" + hotel.hash_hotel;
        document.getElementById("spanCalificar").innerHTML = "http://www.rankhotel.com.ar/calificar.aspx?id=" + hotel.hash_hotel;
        document.getElementById("txtControl").value  = "<iframe src = 'http://www.rankhotel.com.ar/control.aspx?id=" + hotel.hash_hotel + "' " + getTamaniosIframe(hotel.id_diseno) + " frameborder='0' scrolling='no' style='border: 0px solid #ffffff;'></iframe>";
                               
        if(hotel.habilitar_calificaciones){
            document.getElementById("spHabilCalif").innerHTML = "STOP!";
        }
        else{
            document.getElementById("spHabilCalif").innerHTML = "Habilitar Calificaciones";
        }
    }
    
}

function getNombrePlan(tipo_plan) 
{
    if (tipo_plan == 1) {
        return "FREE"
    }
    if (tipo_plan == 2){
        return "PRO"
    }
}

function getTamaniosIframe(id_diseno) 
{
    if ((id_diseno==1) || (id_diseno==2)) 
    {
        return "width='126' height='74'";
    }
    else 
    {
        return "width='97' height='96'";
    }
}



function jsEditarHotel() {
    var id_hotel= document.getElementById("ddlHoteles").value;
    if(id_hotel == ""){
        alert("Debe seleccionar un hotel");
    }else{
        menuhotel.ServerSideEditarHotel(id_hotel, ServerSideEditarHotel_CallBack);
    }
}
        
function ServerSideEditarHotel_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        window.location = "hotel.aspx";
    }
}


// Para editar los calificadores, el tipo de diseño y "mostrar volveria"
function jsEditarCalif(){
    
    var id_hotel = document.getElementById("ddlHoteles").value;
    if(id_hotel == ""){
        alert("Debe seleccionar un hotel");
    }else{
        menuhotel.ServerSideEditarHotel(id_hotel, ServerSideEditarCalif_CallBack);
    }
}

function ServerSideEditarCalif_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        window.location = "hoteldatoscalif.aspx";
    }
}




//habilita / deshabilita calificaciones
function habilitarCalificaciones() {
    var id_hotel = document.getElementById("ddlHoteles").value;
    
    if(id_hotel == ""){
        alert("Debe seleccionar un hotel");
    }else{
        menuhotel.ServerSideHabilitarCalificaciones(id_hotel, ServerSideHabilitarCalificaciones_CallBack);
    }
}
        
function ServerSideHabilitarCalificaciones_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        document.getElementById("spHabilCalif").innerHTML = response.value;
        //window.location = "hotel.aspx";
    }
}


function jsVerCalificacionesHotel() {
    var id_hotel= document.getElementById("ddlHoteles").value;

    if(id_hotel == ""){
        alert("Debe seleccionar un hotel");
    }else{    
        menuhotel.ServerSideEditarHotel(id_hotel, ServerSideCalifsHotel_CallBack);
    }
}
        
function ServerSideCalifsHotel_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        window.location = "vercalificaciones.aspx";
    }
}

/*HOTELDATOSCALIF.ASPX*/

//Para guardar la info: calificadores, tipo de diseño y "mostrar volveria"
function Enviar(){
    var id_calificador = document.getElementById("ddlCalificador").value;
    var id_diseno = document.getElementById("ddlDiseno").value;
    var mostrar_volveria = document.getElementById("chkVerVolveria").checked;

    hoteldatoscalif.ServerSideEnviar(id_calificador, id_diseno, mostrar_volveria,ServerSideEnviar_CallBack);
}

function ServerSideEnviar_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        window.location = "menuhotel.aspx";
    }
}




/*MENUADMIN.ASPX*/
function habilitarHotel(id_hotel){
//spHabilHotel
    listhoteles.ServerSideCalificacionesSuperAdmin(id_hotel, ServerSideCalificacionesSuperAdmin_CallBack)
    
}

function ServerSideCalificacionesSuperAdmin_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        var hotel = response.value;
        var control = "spHabilHotel" + hotel.id;
        if(hotel.habilitar_superadmin){
            document.getElementById(control).innerHTML = "STOP!";
        }else{
            document.getElementById(control).innerHTML = "Habilitar Calificaciones";
        }
    }
}


/*ADDSITIOS.ASPX*/
function addSitio(){
   
   var nom_sitio = document.getElementById("txtSitio").value;
   addsitios.ServerSideAddSitio(nom_sitio,ServerSideAddSitio_CallBack);
}

function ServerSideAddSitio_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        document.getElementById("divSitios").innerHTML = response.value;
    }
}

function delSitio(idsitio){
   
   addsitios.ServerSideDelSitio(idsitio,ServerSideDelSitio_CallBack);
}

function ServerSideDelSitio_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        document.getElementById("divSitios").innerHTML = response.value;
    }
}



/******************************************************************/
function noImplementada(){
    alert("Función no implementada");
}

/*VERCALIFADMIN*/


function seleccionarHotelCalificador(campo) {
    var id_hotel = document.getElementById("ddlHotel").value;
    var id_calificador = document.getElementById("ddlCalificador").value;
    vercalifsadmin.ServerSideSeleccionarHotelCalificador(id_hotel, id_calificador, ServerSideSeleccionarHotelCalificador_CallBack);
}
        
function ServerSideSeleccionarHotelCalificador_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }else{
        var page = 0;
        vercalifsadmin.serverSideVerPagina(page, serverSideVerCalifAdmin_Callback);
        vercalifsadmin.serverSideLlenarPaginador(serverSideVerPaginaAdmin_CallBack);
    }
    
}

function serverSideVerCalifAdmin_Callback(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        if(response.value == ""){
            document.getElementById("divCalificaciones").innerHTML = "No hay calificaciones"
        }else{
            document.getElementById("divCalificaciones").innerHTML = response.value;
        }
    }
}

function serverSideVerPaginaAdmin_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        
        document.getElementById("divPaginador").innerHTML = response.value;
        
    }
}


function verCalifEnOrden(campo){
    //var id_hotel = document.getElementById("ddlHotel").value;
    //var id_calificador = document.getElementById("ddlCalificador").value;
    var page = 0;
    //vercalifsadmin.serverSideVerPagina(page, serverSideVerCalifAdmin_Callback);
    vercalifsadmin.ServerSideMostrarEnOrden(campo, serverSideVerCalifAdmin_Callback);
    vercalifsadmin.serverSideLlenarPaginador(serverSideVerPaginaAdmin_CallBack);

}

function verCalifEnOrdenHotel(campo){
    var page = 0;
    //vercalificaciones.serverSideVerPagina(page, serverSideVerCalifAdmin_Callback);
    vercalificaciones.ServerSideMostrarEnOrden(campo, serverSideVerCalifAdmin_Callback);
    vercalificaciones.serverSideLlenarPaginador(serverSideVerPaginaAdmin_CallBack);

}


//borrar una calificación
function delCalificacion(id_calif){
if (confirm("¿Está seguro?")){
        vercalifsadmin.ServerSideBorrarCalificacion(id_calif, ServerSideBorrarCalificacion_Callback);
    }
}

function ServerSideBorrarCalificacion_Callback(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else{
        seleccionarHotelCalificador("nombre_usuario,apellido");
    }
}


/*LISTHOTELES*/
function seleccionarUsuario(){
    var campo = "nombre";
    var id_admin = document.getElementById("ddlUsuarios").value;
    listhoteles.ServerSideMostrarEnOrden(id_admin, campo, verEnOrden_CallBack);
}

function verEnOrden(campo) 
{
    var id_admin = document.getElementById("ddlUsuarios").value;
    listhoteles.ServerSideMostrarEnOrden(id_admin, campo, verEnOrden_CallBack);

}

function verEnOrden_CallBack(response){
    if (response.error != null){
        //alert(response.error.description);
        document.getElementById("divError").innerHTML = response.error.description;
        return;
    }
    else {
        
        document.getElementById("divLista").innerHTML = response.value;
        
    }
}


function borrarHotel(id_hotel){
    if(confirm("Está a punto de eliminar un hotel")){
        if (confirm("¿Desea eliminar definitivamente este hotel?")){
            listhoteles.ServerSideBorrarHotel(id_hotel, verEnOrden_CallBack);
        }
    }
}



function cambiarPlanHotel(id_hotel){
    listhoteles.ServerSideCambiarPlan(id_hotel, verEnOrden_CallBack);
}

function cambiarPlanHotelesFree(){
    var id_admin = document.getElementById("ddlUsuarios").value;
    var planFree = 1;
    if (confirm("¿Está seguro?")){
        listhoteles.ServerSideCambiarPlanVarios(id_admin, planFree, verEnOrden_CallBack);
    }
}

function cambiarPlanHotelesPro(){
    var id_admin = document.getElementById("ddlUsuarios").value;
    var planPro = 2;
    if (confirm("¿Está seguro?")){
        listhoteles.ServerSideCambiarPlanVarios(id_admin, planPro, verEnOrden_CallBack);
    }
}

