﻿function doClick(buttonName, e) {
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        //if (btn != null) { //If we find the button click it
            switch (buttonName) {
                case "hplSearch":
                    fSearch();
                    //window.location.href = "javascript:fControlSearch('all', '')";
                    fControlSearch("all", "", $("#hidSearchEstType").val(), $("#hidSearchEstService").val());
                    break;
                case "hplSearchQuick":
                    fSearchQuick();
                    //window.location.href = "javascript:fControlSearch('all', '')";
                    fControlSearch("all", "", $("#hidSearchEstType").val(), $("#hidSearchEstService").val());
                    break;
                case "btnLogin":
                    btn.click();
                    break;
                case "btnSearch":
                    fSearchAll($("#search").val());
                    //window.location.href = "javascript:fControlSearch('all', '')";
                    fControlSearch("all", "", $("#hidSearchEstType").val(), $("#hidSearchEstService").val());
                    break;
            }

            if (window.event)
                window.event.keyCode = 0;
            else
                e.which = 0;
        //}
    }
}

function viewEstablishment(id, visitType) {
    $("#hidEstablishments").val(id);
    $('#hidVisitType').val(visitType);
    /*var iIndex = location.href.lastIndexOf("/");
    if (location.href.substring(iIndex + 1) == "ResultSearchContainer.aspx") {  //Si estoy en ResultSearchContainer
        location.href = g_establishment_detail_path + "?id_establishment=" + id + "&id_visit_type=" + visitType;
    }
    else
    {
        $("#frmIndex").attr("action", g_establishment_detail_path);
        $("#frmIndex").submit();
    }*/
    location.href = g_establishment_detail_path + "?id_establishment=" + id + "&id_visit_type=" + visitType;
}

function viewEstablishmentReviewForm(id) {
    $("#frmIndex").attr("action", g_establishment_review_path);
    $("#hidEstablishments").val(id);
    $("#frmIndex").submit();
}

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

function LoginModal() {
    $("#pnlDialog").dialog({
        autoOpen: false,
        modal: true,
        width: 490,
        height: 150,
        buttons: {
            "Cerrar": function () {
                $(this).dialog("close");
            }
        }
    });

    $("#pnlDialog").dialog('option', 'title', 'Error!');
    $("#pnlDialog").dialog('open');

    $("#pnlLoading").show();
    $("#pnlDialogContent").html($("#pnlLoading").html());

    $('#pnlDialogContent').html('Para poder acceder debe iniciar sesion!<br>Muchas Gracias!');
    $("#pnlLoading").hide();

    //return false;
}


function fFocusEvent(textbox) {
    if ($("#" + textbox).val() == "Ingrese su búsqueda") {
        $("#" + textbox).val('');
    }

    /*if (textbox == "txtPass") {
        $("#" + textbox).attr("Type", "Password");
    }*/
}
