
function gonext(evt,nextField) {
    if(evt.keyCode==9){
        var field = $('#deliver_to_form').find('input[name|='+nextField+']');
        if(field.length==0) { // this means not found (strange way to say it)
            field = $('#deliver_to_form').find('textarea[name|='+nextField+']');
        }
        setTimeout(function() {
            field.focus();
        }, 0);
    }
}

function cuisine_selected (cuisine_id) {
    if (cuisine_id != window.current_cuisine) {
        createCookie("current_cuisine", cuisine_id, 1);
        $("#cuisine_div_" + window.current_cuisine).toggleClass("active");
        window.current_cuisine = cuisine_id;
        all_cuisine_deselect();
        $("#cuisine_div_" + cuisine_id).toggleClass("active");
        refresh_order_lists();
        if(window.document.title!='undefined') {
            window.document.title='Buenos Aires Delivery ' ;
        }
    }
}

function all_cuisine_selected () {
    window.current_cuisine = 'ALL';
    $("div[id^='cuisine_div_']").toggleClass("active",true);
    refresh_order_lists();
}

function all_cuisine_deselect () {
    $("div[id^='cuisine_div_']").removeClass("active");
}

function neighbourhood_selected (neighbourhood_id) {
    if (neighbourhood_id != window.current_neighbourhood) {
        createCookie("current_neighbourhood", neighbourhood_id, 1);

        //unset current neighbourhood
        $("#neighbourhood_li_" + window.current_neighbourhood).toggleClass("active", false);

        window.current_neighbourhood = neighbourhood_id;
        $("#neighbourhood_li_" + neighbourhood_id).toggleClass("active", true);

        //clears session variable for restaruant list before updating restaurant list
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "clear_rest_list"
        }, function(data) {});

        reset_map();
        
        refresh_order_lists();

    }
}

function restaurant_selected (restaurant_id) {
    clear_cart();
    createCookie("current_restaurant", restaurant_id, 1);
}

function refresh_order_lists() {
    
    var restaurants_list = 'undefined';
    if (window.geocoder_restaurants_match_list != '') restaurants_list = window.geocoder_restaurants_match_list;

    var count = 0;
    var glob_retrieved_data;
    $("#online_order_ul").slideUp(300);
    $("#phone_order_ul").slideUp(300);
    $("#specials_order_ul").slideUp(300);
    $("#closed_restaurants_order_ul").slideUp(300, function(){
        count++;
        if (count == 2) {
            if (no_error(glob_retrieved_data)) {
                $("#restaurant_lists_div").html(glob_retrieved_data);
                open_restaurant_list();
            }
        }
    });
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_home_restaurant_lists",
        cuisine_id: window.current_cuisine,
        neighbourhood_id: window.current_neighbourhood,
        restaurants_list: restaurants_list,
        current_language: window.current_language

    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            glob_retrieved_data = retrieved_data;
            count++;
            if (count == 2) {
                if (no_error(glob_retrieved_data)) {
                    $("#restaurant_lists_div").html(glob_retrieved_data);
                    open_restaurant_list();
                }
            }
        }
    });

}

function open_restaurant_list() {
    $("#online_order_ul").slideDown(300);
    $("#phone_order_ul").slideDown(300);
    $("#specials_order_ul").slideDown(300);
    $("#closed_restaurants_order_ul").slideDown(300);
}

function add_item_to_cart(menu_item_id, price_type_id, session_id) {
    $("#add_item_img_" + menu_item_id + "_" + price_type_id).hide();
    $("#add_item_ajax_" + menu_item_id + "_" + price_type_id).css("display", "inline");
    var cart_restaurant_id = readCookie("cart_restaurant_id");
    if (cart_restaurant_id != window.current_restaurant) {
        clear_cart();
    }
    createCookie("cart_restaurant_id", window.current_restaurant);
    var cart = readCookie("cart");
    if (cart == null) cart = '';
    var cart_items = new Array();
    cart_items = cart.split("::");
    var found = false;
    for ( var x = 0 ; x < cart_items.length ; x++ ) {
        var item_parts = new Array();
        item_parts = cart_items[x].split(",");
        if (menu_item_id == item_parts[0] && item_parts[1] == price_type_id) {
            item_parts[2]++;
            cart_items[x] = item_parts.join(",");
            found = true;
            break;
        }
    }
    if (found == false) cart_items[cart_items.length] = menu_item_id + "," + price_type_id + ",1";
    createCookie("cart", cart_items.join("::"), 30);
    refresh_guest_check_div(menu_item_id, price_type_id);

}

function remove_item_from_cart(menu_item_id, price_type_id) {
    var cart = readCookie("cart");
    if (cart == null) cart = '';
    var cart_items = new Array();
    cart_items = cart.split("::");
    for ( var x = 0 ; x < cart_items.length ; x++ ) {
        var item_parts = new Array();
        item_parts = cart_items[x].split(",");
        if (menu_item_id == item_parts[0] && item_parts[1] == price_type_id) {
            item_parts[2]--;
            if (item_parts[2] == 0) cart_items.splice(x, 1);
            else cart_items[x] = item_parts.join(",");
            break;
        }
    }
    createCookie("cart", cart_items.join("::"), 30);
    refresh_guest_check_div(menu_item_id, price_type_id);
}

function refresh_guest_check_div(menu_item_id, price_type_id) {
    refresh_cart(menu_item_id, price_type_id);
    refresh_cart_total();    
}

function check_action_cart() {
    var url = window.dev + '/client_info/';
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "check_action_cart"
    }, function(retrieved_data){
        if (retrieved_data == "success") {
            document.location.href = url;
            $("#button_messages").html('');
        } else if (retrieved_data == "min_not_reached") {
            $('#minimum_order_span').css('color','red').css('font-size', '18px');
        } else {
            $("#button_messages").html(retrieved_data);
        }
    });
}

function refresh_cart(menu_item_id, price_type_id) {
    $("#loading_div").show();
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_cart"
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            $("#guest_check_inner_content").html(retrieved_data);
            $("#loading_div").hide();
            if(menu_item_id!=null) {
                $("#add_item_img_" + menu_item_id + "_" + price_type_id).show();
                $("#add_item_ajax_" + menu_item_id + "_" + price_type_id).hide();
            }

        }
    });
}

function refresh_cart_total() {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_cart_total"
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            $("#total_amount_span").text("$" + retrieved_data);
            if (window.delivery_minimum != undefined) {
                if (parseFloat(retrieved_data) < parseFloat(window.delivery_minimum)) $('.delivery_charge_div').addClass('red');
                else $('.delivery_charge_div').removeClass('red');
            }
        }
    });
}

function refresh_cart_action_buttons(session_id) {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_cart_action_buttons",
        session_id: session_id
    }, function(retrieved_data){
        //alert('volvio del get_cart_action_buttons');
        $("#cart_action_buttons_div").html(retrieved_data);
        if (cart_has_stuff() == true) $("#cancel_order_button_div").slideDown(300);
        else $("#cancel_order_button_div").slideUp(300);
    });
}

function validate_coupon(){
    $('#validate_coupon_ajax').show();$('#validate_coupon_button').hide();

    var coupon_code = document.getElementById('coupon_code').value;
    if (coupon_code == '') {
        if (window.current_language == "en") alert("Coupon Code field is empty");
        if (window.current_language == "es") alert("No se ha ingresado un Código de Cupón");
        $('#validate_coupon_ajax').hide();$('#validate_coupon_button').show();
        return;
    }
    
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "validate_coupon",
        coupon_code: coupon_code
    }, function(retrieved_data){                        
        var coupon_data = eval('(' + retrieved_data + ')');
        if(coupon_data['success'] == true) {            
            createCookie("coupon_code",coupon_data['coupon_code'] , 0.3);            
            $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
                function_to_call: "get_cart_total_plus_delivery_charge"
            }, function(total_cart) {     
                $('#coupon_code_number .code').html(coupon_data['coupon_code']);
                $('#total_amount_span').html("$" + total_cart);
                $('#cart_total').val(total_cart);
                $('#coupon_code_input').val(coupon_data['coupon_code']);
                $('#coupon_div').hide();$('#coupon_code_line').show();
                $('#validate_coupon_ajax').hide();$('#validate_coupon_button').show();
                $('#coupon_code').val("");                
            });
        }else {            
            alert(coupon_data['error']);
            $('#validate_coupon_ajax').hide();$('#validate_coupon_button').show();
        }
        
        //If the coupon is valid we proceed with the discount. 
    });
}

function remove_coupon() {
    $('#coupon_code_number.remove_coupon_ajax').show();$('#coupon_code_number.remove_coupon_img').hide();
    createCookie("coupon_code",'', 0);    
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_cart_total_plus_delivery_charge"
    }, function(total_cart) {        
        $('#total_amount_span').html("$" + total_cart);
        $('#cart_total').val(total_cart);
        $('#coupon_div').show();$('#coupon_code_line').hide();
        $('#coupon_code_input').val('');
        $('#coupon_code_number.remove_coupon_ajax').hide();$('#coupon_code_number.remove_coupon_img').show();
    });
    
}

function cart_has_stuff() {
    var cart = readCookie("cart");
    if (cart == null || cart == '' || cart == '::') return false;
    else return true;
}

function cancel_order() {
    clear_cart();
    if (window.current_page != "home") go_back_to_home();
}

function clear_cart_and_refresh() {
    clear_cart();
    refresh_cart();
}

function clear_cart() {
    createCookie("cart","",1);
    createCookie("coupon_code", "", 1);
}

function finalize_order() {
    var form = document.getElementById("deliver_to_form");

    // Create client_lat and client_lng based on client address
    var address = form.address.value + " " + form.st_number.value + ", Capital Federal, Argentina";

    var geocoder = new GClientGeocoder();

    var client_lat = '';
    var client_lng = '';

    if (geocoder) {
        geocoder.getLatLng(
            address,
            function(point) {
                if (point) {
                    client_lat = point.lat();
                    client_lng = point.lng();
                    var found;
                    if (client_lat != '' && client_lng != '-58.3731613') found = 'true';
                    else found = 'false';
                    finalize_order_ajax(form, client_lat, client_lng, found);
                } else {
                    finalize_order_ajax(form, client_lat, client_lng, 'false');
            }
            });
    }

}

function finalize_order_ajax(form, client_lat, client_lng, address_found) {

    var change = $('#pay_with_input').attr('value');
    
    if (form.remember.checked) storeCookieData(form);
    else deleteCookieData(form);

    var old_year;
    if (form.old_year == undefined) old_year=false;
    else old_year = form.old_year.checked;

    var comments = form.comments.value.replace(/'/g,"");    
    

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "finalize_order",
        name: form.name.value,
        address: form.address.value,
        st_number: form.st_number.value,
        phone: form.phone.value,
        email: form.email.value,
        house_type: form.house_type.value,
        floor: form.floor.value,
        unit: form.unit.value,
        closest_cross_street: form.closest_cross_street.value,
        comments: comments,
        how_did_you_hear_about_us: form.how_did_you_hear_about_us.value,
        restaurant_id: window.current_restaurant,
        neighbourhood_id: window.current_neighbourhood,
        change: change,
        old_year: old_year,
        cuisine_id: window.current_cuisine,
        client_lat: client_lat,
        client_lng: client_lng,
        address_found: address_found,
        coupon_code: document.getElementById('coupon_code_input').value
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            if (no_error(retrieved_data) && match_md5(retrieved_data)) {
            clear_cart();
            go_forward_to_confirmation(retrieved_data);
            } else {
                $('#finalize_order_button_div').bind('click', function() {
                    $(this).unbind('click');
                    $('#loading_div').show('slow');
                    $('#cancel_order_button_div').hide('slow');
                    $('#finalize_order_button_div').hide('slow', function() {
                        finalize_order();
                    });
                });
                $("#finalize_order_button_div").show();
                $("#cancel_order_button_div").show();
                $('#loading_div').hide();
                alert(retrieved_data.substring(5,retrieved_data.length));
            }
        }
    });
}

function storeCookieData(form) {
    createCookie('name',form.name.value,1825);
    createCookie('address',form.address.value,1825);
    createCookie('st_number',form.st_number.value,1825);
    createCookie('phone',form.phone.value,1825);
    createCookie('email',form.email.value,1825);
    createCookie('house_type',form.house_type.selectedIndex,1825);
    createCookie('floor',form.floor.value,1825);
    createCookie('unit',form.unit.value,1825);
    createCookie('closest_cross_street',form.closest_cross_street.value,1825);
}

function deleteCookieData(form) {
    createCookie('name','',1825);
    createCookie('address','',1825);
    createCookie('st_number','',1825);
    createCookie('phone','',1825);
    createCookie('email','',1825);
    createCookie('house_type','',1825);
    createCookie('floor','',1825);
    createCookie('unit','',1825);
    createCookie('closest_cross_street','',1825);
}

function fillDataFromCookie() {
    var form = document.getElementById("deliver_to_form");

    var name = readCookie('name');
    var address = readCookie('address');
    var st_number = readCookie('st_number');
    var phone = readCookie('phone');
    var email = readCookie ('email');
    var house_type = readCookie('house_type');
    var floor = readCookie('floor');
    var unit = readCookie('unit');
    var closest_cross_street = readCookie('closest_cross_street');

    if(email) {
        form.name.value=name;
        form.address.value=address;
        form.st_number.value=st_number;
        form.phone.value=phone;
        form.email.value=email;
        form.house_type.options[house_type].selected=true;
        form.floor.value=floor;
        form.unit.value=unit;
        form.closest_cross_street.value=closest_cross_street;
        form.remember.checked=true;
    }
}

function match_md5(md5) {
    return /^[a-f0-9]{32,32}$/.test(md5);
}

function go_forward_to_confirmation(order_md5) {
    var is_valid_order_md5 = /^[a-f0-9]{32,32}$/.test(order_md5);
    if (is_valid_order_md5 == true) {
        $(document.body).html('<form id="hidden_post_form" action="' + window.dev + '/order_confirmation/' + order_md5 + '/" method="get" style="display: none;"></form>');
        document.getElementById("hidden_post_form").submit();
    } else {
        switch (window.current_language) {
            case 'en':
                alert('Your order has been placed successfully. There was an error loading the confirmation page. Please check your email shortly and sorry for the inconvenience. Buenos Aires Delivery Team');
                break;
            case 'es':
                alert('Su orden fue completada con éxito. Hubo un error al cargar la pagina de confirmación. Revise su correo en breve a la espera de nuestro email de confirmación y disculpe el inconveniente. El equipo de Buenos Aires Delivery');
                break;
            default:
                break;
        }
        window.location.href = '/';
    }
}

function go_back_to_home() {
    $(document.body).html('<form id="hidden_post_form" action="' + window.dev + '/" method="get" style="display: none;"></form>');
    document.getElementById("hidden_post_form").submit();
}

function get_open_time_comma_delimited_values(form) {
    var return_array = '';
    for (var x = 0 ; x <= 7 ; x++) {
        return_array +=
        form.open_time_1_hf[x].value + ',' +
        form.open_time_1_mf[x].value + ',' +
        form.open_time_1_ht[x].value + ',' +
        form.open_time_1_mt[x].value + ',' +
        form.open_time_2_hf[x].value + ',' +
        form.open_time_2_mf[x].value + ',' +
        form.open_time_2_ht[x].value + ',' +
        form.open_time_2_mt[x].value + ',' +
        form.open_time_3_hf[x].value + ',' +
        form.open_time_3_mf[x].value + ',' +
        form.open_time_3_ht[x].value + ',' +
        form.open_time_3_mt[x].value + ',';
    }
    return return_array;
}

function check_duplicate_values(array_to_check, array_lenght) {
    for (var x = 0 ; x < array_lenght ; x++) {
        for (var y = 0 ; y < array_lenght ; y++) {
            if (x != y) {
                //alert ("x:" + array_to_check[x] + ",y:" + array_to_check[y]);
                if (array_to_check[x] == array_to_check[y]) return true;
            }
        }
    }
    return false;
}

function get_new_call_center_status() {
    if (window.call_center_status == true) {
//window.call_center_status
}
}

function restaurant_confirm_order(order_md5) {

    var form = document.getElementById('form_order_confirmation');
    var delivery_delay = form.delivery_delay.value;
    var observaciones = form.observaciones.value;

    if(delivery_delay<1) {
        $('#result_confirmation').html('Por favor ingrese el tiempo de demora del pedido');
    } else {
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "restaurant_confirm_order",
            order_md5: order_md5,
            delivery_delay: delivery_delay,
            observaciones: observaciones
        }, function(retrieved_data){
            alert(retrieved_data);
            $('#result_confirmation').html(retrieved_data);
        });
    }
}

function restaurant_cancel_order(order_md5) {

    var form = document.getElementById('form_order_confirmation');
    var delivery_delay = form.delivery_delay.value;
    var observaciones = form.observaciones.value;

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "restaurant_cancel_order",
        order_md5: order_md5,
        delivery_delay: delivery_delay,
        observaciones: observaciones
    }, function(retrieved_data){
        alert(retrieved_data);
        $('#result_confirmation').html(retrieved_data);
    });
}

/**/function reset_combo_hours(_parent){
    $(_parent).children('select').attr('value', 0);
}

function filter_house_type() {

    var current_house_type = $('#deliver_to_form').find('select[name|=house_type]').val();
    if(current_house_type=='apartment' || current_house_type=='office') {
        //$('#floor_dept_div').show();
        $('#floor').attr('disabled',false);
        $('#floor').css('background','#fff');
        $('#unit').attr('disabled',false);
        $('#unit').css('background','#fff');
    } else {
        //$('#floor_dept_div').hide();
        $('#floor').val('');
        $('#floor').attr('disabled',true);
        $('#floor').css('background','#eee');
        $('#unit').val('');
        $('#unit').attr('disabled',true);
        $('#unit').css('background','#eee');
    }

}

function send_suggestion_mail() {
    var form = document.getElementById('suggest_form');
    var neighbourhood = form.neighbourhood.value;
    var restaurant_name = form.restaurant_name.value;
    var comments = form.comments.value;

    if(!restaurant_name) {
        if (window.current_language == "en") alert("Please tell us the restaurant name");
        if (window.current_language == "es") alert("Por favor dinos el nombre del restaurante");
    } else {
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "send_suggestion_mail",
            neighbourhood: neighbourhood,
            restaurant_name: restaurant_name,
            comments: comments
        }, function(retrieved_data){
            $('#content_form').hide();
            $('#message_result').show();
            if (retrieved_data == "success") {
                if (window.current_language == "en")
                    $('#message_result').html('Thanks for your suggestion.');
                if (window.current_language == "es")
                    $('#message_result').html('Gracias por su sugerencia.');
            } else {
                if (window.current_language == "en")
                    $('#message_result').html('Oops, service not available right now.<br>Try again in a few minutes.');
                if (window.current_language == "es")
                    $('#message_result').html('Oops, el servicio parece no estar disponible ahora mismo. <br>Intenta en unos minutos.');
            }
        });
    }

}


function contact_us() {
    var form = document.getElementById('deliver_to_form');
    var email = form.email.value;
    var comments = form.comments.value;

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "contact_us",
        email: email,
        comments: comments
    }, function(retrieved_data){
        if (retrieved_data == "success") {
            if (window.current_language == "en")
                alert("Thank you for send us your comments.");
            if (window.current_language == "es")
                alert("Gracias por enviarnos tus comentarios.");
            window.location.href='../';
        } else {
            alert(retrieved_data);
        }
    });
}





/* Admin functions */

/**/function add_new_menu_item_plus(form_id) {
    add_new_menu_item(form_id, true);
}

/**/function add_new_menu_item(form_id, add_another) {
    var item_category_id = form_id.split('_');
    item_category_id = item_category_id[item_category_id.length-1];

    var form = document.getElementById(form_id);
    var price_type1 = $('#' + form_id).find('input[name|=price_type1]').attr('value');
    var price_type2 = $('#' + form_id).find('input[name|=price_type2]').attr('value');
    var price_type3 = $('#' + form_id).find('input[name|=price_type3]').attr('value');
    var price_type_id1 = $('#' + form_id).find('input[name|=price_type_id1]').attr('value');
    var price_type_id2 = $('#' + form_id).find('input[name|=price_type_id2]').attr('value');
    var price_type_id3 = $('#' + form_id).find('input[name|=price_type_id3]').attr('value');
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "add_new_menu_item",
        item_category_id: item_category_id,
        description_en: form.description_en.value,
        description_es: form.description_es.value,
        price_type_value1: price_type1,
        price_type_value2: price_type2,
        price_type_value3: price_type3,
        price_type_id1: price_type_id1,
        price_type_id2: price_type_id2,
        price_type_id3: price_type_id3
    }, function(retrieved_data){
        //alert(retrieved_data);
        $('#' + form_id).find('.insert_ok_label').show().animate({
            opacity: 1
        }, 500, function() {
            if (add_another) {
                $(form).slideUp(function(){
                    form.reset();
                    $('#' + form_id).find('.insert_ok_label').hide();
                    $(form).slideDown();
                });
            } else window.location.reload();
        });
    });
}

/**/function set_status_menu_item(item_id, status) {
    if(item_id) {
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "set_status_menu_item",
            menu_item_id: item_id,
            status: status
        }, function(retrieved_data){
            if (retrieved_data != 'success') alert(retrieved_data);
            else window.location.reload();
        });
    }
}

/**/function save_menu_item(form_id) {
    var menu_item_id = form_id.split('_');
    menu_item_id = menu_item_id[menu_item_id.length-1];

    var form = document.getElementById(form_id);
    var price_type1 = $('#' + form_id).find('input[name|=price_type1]').attr('value');
    var price_type2 = $('#' + form_id).find('input[name|=price_type2]').attr('value');
    var price_type3 = $('#' + form_id).find('input[name|=price_type3]').attr('value');
    var price_type_id1 = $('#' + form_id).find('input[name|=price_type_id1]').attr('value');
    var price_type_id2 = $('#' + form_id).find('input[name|=price_type_id2]').attr('value');
    var price_type_id3 = $('#' + form_id).find('input[name|=price_type_id3]').attr('value');
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "save_menu_item",
        menu_item_id: menu_item_id,
        description_en: form.description_en.value,
        description_es: form.description_es.value,
        price_type_value1: price_type1,
        price_type_value2: price_type2,
        price_type_value3: price_type3,
        price_type_id1: price_type_id1,
        price_type_id2: price_type_id2,
        price_type_id3: price_type_id3
    }, function(retrieved_data){
        //alert(retrieved_data);
        if(retrieved_data == "success") {
            $('#' + form_id).find('.insert_ok_label').show().animate({
                opacity: 1
            }, 2000, function() {
                /*$('#menu_item_tr_' + menu_item_id).toggle();
            $('#' + form_id).find('.insert_ok_label').hide();*/
                //window.location.reload();
                $('#' + form_id).find('.insert_ok_label').hide();
            });
        }else {
            alert("There was an error trying to store the value, check your session or your internet connection.")
        }

    });
}

/**/function save_menu_category (form_id) {
    var category_id = form_id.split('_');
    category_id = category_id[category_id.length-1];
    var form = document.getElementById(form_id);
    var price_type1 = $('#' + form_id).find('input[name|=price_type1]').attr('value');
    var price_type2 = $('#' + form_id).find('input[name|=price_type2]').attr('value');
    var price_type3 = $('#' + form_id).find('input[name|=price_type3]').attr('value');
    var price_type_id1 = $('#' + form_id).find('input[name|=price_type_id1]').attr('value');
    var price_type_id2 = $('#' + form_id).find('input[name|=price_type_id2]').attr('value');
    var price_type_id3 = $('#' + form_id).find('input[name|=price_type_id3]').attr('value');
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "save_menu_category",
        category_id: category_id,
        description_en: form.description_en.value,
        description_es: form.description_es.value,
        sort_order: form.sort_order.value,
        price_type_value1: price_type1,
        price_type_value2: price_type2,
        price_type_value3: price_type3,
        price_type_id1: price_type_id1,
        price_type_id2: price_type_id2,
        price_type_id3: price_type_id3
    }, function(retrieved_data){
        //alert(retrieved_data);
        $('#' + form_id).find('.insert_ok_label').show().animate({
            opacity: 1
        }, 500, function() {
            window.location.reload();
        });
    });
}

/**/function delete_menu_item(menu_item_id) {

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "delete_menu_item",
        menu_item_id: menu_item_id
    }, function(retrieved_data){
        //alert(retrieved_data);
        window.location.reload();
    /*$('#' + form_id).find('.insert_ok_label').show().animate({
            opacity: 1
        }, 500, function() {
        });*/
    });
}

/**/function get_new_menu_item_with_new_category_form_html() {

    var form = document.getElementById('new_item_for_new_category_form');

    var str_category_name_en = form.category_names_input_en.value;
    var str_category_name_es = form.category_names_input_es.value;
    if (str_category_name_en == '' || str_category_name_es == '') {
        if (window.current_language == "en") alert("Please type in a category name in both languages");
        if (window.current_language == "es") alert("Por favor ingrese una categoría en ambos idiomas");
        return;
    }

    var price_type_strings_array = '';
    var empty_price = 0;
    if (form.price_type_id_input_en_1.value != '') {
        if (form.price_type_id_input_es_1.value != '') {
            price_type_strings_array += form.price_type_id_input_en_1.value + "__";
            price_type_strings_array += form.price_type_id_input_es_1.value + "__";
        } else {
            if (window.current_language == "en") alert("Please enter price type in both languages");
            if (window.current_language == "es") alert("Por favor ingrese tipo de precio an ambos idiomas");
            return;
        }
    } else empty_price++;
    if (form.price_type_id_input_en_2.value != '') {
        if (form.price_type_id_input_es_2.value != '') {
            price_type_strings_array += form.price_type_id_input_en_2.value + "__";
            price_type_strings_array += form.price_type_id_input_es_2.value + "__";
        } else {
            if (window.current_language == "en") alert("Please enter price type in both languages");
            if (window.current_language == "es") alert("Por favor ingrese tipo de precio an ambos idiomas");
            return;
        }
    } else empty_price++;
    if (form.price_type_id_input_en_3.value != '') {
        if (form.price_type_id_input_es_3.value != '') {
            price_type_strings_array += form.price_type_id_input_en_3.value + "__";
            price_type_strings_array += form.price_type_id_input_es_3.value + "__";
        } else {
            if (window.current_language == "en") alert("Please enter price type in both languages");
            if (window.current_language == "es") alert("Por favor ingrese tipo de precio an ambos idiomas");
            return;
        }
    } else empty_price++;
    if (empty_price == 3) {
        if (window.current_language == "en") alert("Please enter least one price type");
        if (window.current_language == "es") alert("Por favor ingrese al menos un tipo de precio");
        return;
    }
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_new_menu_item_with_new_category_form_html",
        price_type_strings_array: price_type_strings_array,
        str_category_name_en: str_category_name_en,
        str_category_name_es: str_category_name_es
    }, function(retrieved_data){
        $('#add_menu_item_to_new_category_form_content1_div').hide();
        form.reset();
        $('#add_menu_item_to_new_category_form_content2_div').html(retrieved_data);
    });
}

/**/function add_new_restaurant() {

    var form = document.getElementById('new_restaurant_form');

    var restaurant_name = form.restaurant_name.value;
    var restaurant_name_en = form.restaurant_name_en.value;
    var restaurant_type = form.restaurant_type.value;
    var restaurant_type_en = form.restaurant_type_en.value;
    var restaurant_email = form.restaurant_email.value;
    var restaurant_web_address = form.restaurant_web_address.value;
    var restaurant_url_name = form.restaurant_url_name.value;
    var restaurant_order_min = form.restaurant_order_min.value;
    var restaurant_is_unaffiliated = form.restaurant_is_unaffiliated.checked;
    var restaurant_has_online_ordering = form.restaurant_has_online_ordering.checked;
    var restaurant_has_phone_ordering = form.restaurant_has_phone_ordering.checked;
    //var restaurant_state = form.restaurant_state.options[form.restaurant_state.selectedIndex].value;
    var restaurant_admin_username = form.restaurant_admin_username.value;
    if (restaurant_admin_username == '') {
        if (window.current_language == "en") alert("Username can not be blank");
        if (window.current_language == "es") alert("El nombre de usuario no puede ser en blanco");
        return;
    }
    var restaurant_admin_password = form.restaurant_admin_password.value;
    var restaurant_admin_password_again = form.restaurant_admin_password_again.value;
    if (restaurant_admin_password == '') {
        if (window.current_language == "en") alert("Password can not be blank");
        if (window.current_language == "es") alert("La contraseña no puede ser en blanco");
        return;
    }
    if (restaurant_admin_password != restaurant_admin_password_again) {
        if (window.current_language == "en") alert("Password and Password again do not match");
        if (window.current_language == "es") alert("La contraseña y la confirmación de la contraseña no coinciden");
        return;
    }

    //Cuisines
    var separator;
    var cuisines_count = $('#new_restaurant_form').find('select[name|=restaurant_cuisine_id]').length;
    var restaurant_cuisine_id_list = '';
    var restaurant_cuisine_id_array = new Array();
    if (cuisines_count > 1) {
        for (var x = 0 ; x < cuisines_count ; x++) {
            if (x == cuisines_count-1) separator = '';
            else separator = ':::';
            restaurant_cuisine_id_array[restaurant_cuisine_id_array.length] = form.restaurant_cuisine_id[x].value;
            restaurant_cuisine_id_list += form.restaurant_cuisine_id[x].value + separator;
        }
        if (check_duplicate_values(restaurant_cuisine_id_array, cuisines_count)) {
            if (window.current_language == "en") alert("Duplicate cuisines found");
            if (window.current_language == "es") alert("Se ingresaron cocinas duplicadas");
            return;
        }
    } else {
        restaurant_cuisine_id_list = form.restaurant_cuisine_id.value;
    }

    //Neighbourhoods
    var locations_count = $('#new_restaurant_form').find('select[name|=restaurant_neighbourhood_id]').length;
    var restaurant_neighbourhood_id_list = '';
    var restaurant_phone1_list = '';
    var restaurant_phone2_list = '';
    var restaurant_address_list = '';
    var restaurant_mail_contact_list = '';
    var restaurant_map_embed_url_list = '';
    var restaurant_neighbourhood_id_array = new Array();
    if (locations_count > 1) {
        for (x = 0 ; x < locations_count ; x++) {
            if (x == locations_count-1) separator = '';
            else separator = ':::';
            restaurant_neighbourhood_id_array[restaurant_neighbourhood_id_array.length] = form.restaurant_neighbourhood_id[x].value;
            restaurant_neighbourhood_id_list += form.restaurant_neighbourhood_id[x].value + separator;
            restaurant_phone1_list += form.restaurant_phone1[x].value + separator;
            restaurant_phone2_list += form.restaurant_phone2[x].value + separator;
            restaurant_address_list += form.restaurant_address[x].value + separator;
            restaurant_mail_contact_list += form.restaurant_mail_contact[x].value + separator;
            restaurant_map_embed_url_list += form.restaurant_map_embed_url[x].value + separator;
        }
        if (check_duplicate_values(restaurant_neighbourhood_id_array, locations_count)) {
            if (window.current_language == "en") alert("Duplicate locations found. You can only register one location for each neighbourhood");
            if (window.current_language == "es") alert("Se ingresaron sucursales duplicadas. Solo puede registrar una sucursal por barrio");
            return;
        }
    } else {
        restaurant_neighbourhood_id_list += form.restaurant_neighbourhood_id[0].value;
        restaurant_phone1_list += form.restaurant_phone1.value;
        restaurant_phone2_list += form.restaurant_phone2.value;
        restaurant_address_list += form.restaurant_address.value;
        restaurant_mail_contact_list += form.restaurant_mail_contact.value;
        restaurant_map_embed_url_list += form.restaurant_map_embed_url.value;
    }

    //Open time
    var restaurant_open_time_string_en = form.restaurant_string_open_time_en_input.value;
    if (restaurant_open_time_string_en == '') {
        if (window.current_language == "en") alert("Please enter a textual description for the restaurant open time - English");
        if (window.current_language == "es") alert("Por favor ingrese una descripcion textual para el horario de apertura - Ingles");
        return;
    }
    var restaurant_open_time_string_es = form.restaurant_string_open_time_es_input.value;
    if (restaurant_open_time_string_es == '') {
        if (window.current_language == "en") alert("Please enter a textual description for the restaurant open time - Spanish");
        if (window.current_language == "es") alert("Por favor ingrese una descripcion textual para el horario de apertura - Español");
        return;
    }
    var restaurant_open_time_list = get_open_time_comma_delimited_values(form);

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "add_new_restaurant",
        restaurant_name: restaurant_name,
        restaurant_name_en: restaurant_name_en,
        restaurant_type: restaurant_type,
        restaurant_type_en: restaurant_type_en,
        restaurant_email: restaurant_email,
        restaurant_web_address: restaurant_web_address,
        restaurant_url_name: restaurant_url_name,
        restaurant_order_min: restaurant_order_min,
        restaurant_is_unaffiliated: restaurant_is_unaffiliated,
        restaurant_has_online_ordering: restaurant_has_online_ordering,
        restaurant_has_phone_ordering: restaurant_has_phone_ordering,
        //restaurant_state: restaurant_state,
        restaurant_admin_username: restaurant_admin_username,
        restaurant_admin_password: restaurant_admin_password,
        restaurant_cuisine_id_list: restaurant_cuisine_id_list,
        restaurant_neighbourhood_id_list: restaurant_neighbourhood_id_list,
        restaurant_phone1_list: restaurant_phone1_list,
        restaurant_phone2_list: restaurant_phone2_list,
        restaurant_address_list: restaurant_address_list,
        restaurant_mail_contact_list: restaurant_mail_contact_list,
        restaurant_map_embed_url_list: restaurant_map_embed_url_list,
        restaurant_open_time_string_en: restaurant_open_time_string_en,
        restaurant_open_time_string_es: restaurant_open_time_string_es,
        restaurant_open_time_list: restaurant_open_time_list
    }, function(retrieved_data){
        if (retrieved_data == "success") {
            if (window.current_language == "en") alert("Restaurant added successfully");
            if (window.current_language == "es") alert("Restaurante agregado exitosamente");
            window.location.reload();
        }
        else alert (retrieved_data);
    });
}

/**/function edit_restaurant(restaurant_id) {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_restaurant_for_edit",
        restaurant_id: restaurant_id
    }, function(retrieved_data){
        $('#edit_restaurant_div_id_' + restaurant_id).html(retrieved_data).slideDown(500);
    });
}

/**/function update_restaurant_main_info(restaurant_id) {

    var form = document.getElementById('edit_restaurant_form_' + restaurant_id);

    var restaurant_name = form.restaurant_name.value;
    var restaurant_name_en = form.restaurant_name_en.value;
    var restaurant_type = form.restaurant_type.value;
    var restaurant_type_en = form.restaurant_type_en.value;
    var restaurant_email = form.restaurant_email.value;
    var restaurant_web_address = form.restaurant_web_address.value;
    var restaurant_url_name = form.restaurant_url_name.value;
    var restaurant_order_min = form.restaurant_order_min.value;
    var restaurant_is_unaffiliated = form.restaurant_is_unaffiliated.checked;
    var restaurant_has_online_ordering = form.restaurant_has_online_ordering.checked;
    var restaurant_has_phone_ordering = form.restaurant_has_phone_ordering.checked;
    var restaurant_hide = form.restaurant_hide.checked;
    
    //var restaurant_state = form.restaurant_state.options[form.restaurant_state.selectedIndex].value;

    //Open time
    var restaurant_open_time_string_en = form.restaurant_string_open_time_en_input.value;
    if (restaurant_open_time_string_en == '') {
        if (window.current_language == "en") alert("Please enter a textual description for the restaurant open time - English");
        if (window.current_language == "es") alert("Por favor ingrese una descripcion textual para el horario de apertura - Ingles");
        return;
    }
    var restaurant_open_time_string_es = form.restaurant_string_open_time_es_input.value;
    if (restaurant_open_time_string_es == '') {
        if (window.current_language == "en") alert("Please enter a textual description for the restaurant open time - Spanish");
        if (window.current_language == "es") alert("Por favor ingrese una descripcion textual para el horario de apertura - Español");
        return;
    }
    var restaurant_open_time_list = get_open_time_comma_delimited_values(form);

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_restaurant_main_info",
        restaurant_id: restaurant_id,
        restaurant_name: restaurant_name,
        restaurant_name_en: restaurant_name_en,
        restaurant_type: restaurant_type,
        restaurant_type_en: restaurant_type_en,
        restaurant_email: restaurant_email,
        restaurant_web_address: restaurant_web_address,
        restaurant_url_name: restaurant_url_name,
        restaurant_order_min: restaurant_order_min,
        restaurant_is_unaffiliated: restaurant_is_unaffiliated,
        restaurant_has_online_ordering: restaurant_has_online_ordering,
        restaurant_has_phone_ordering: restaurant_has_phone_ordering,
        restaurant_hide: restaurant_hide,
        //restaurant_state: restaurant_state,
        restaurant_open_time_string_en: restaurant_open_time_string_en,
        restaurant_open_time_string_es: restaurant_open_time_string_es,
        restaurant_open_time_list: restaurant_open_time_list
    }, function(retrieved_data){
        if (retrieved_data == 'success'){
            if (window.current_language == "en") alert("Data updated successfully");
            if (window.current_language == "es") alert("Actualización exitosa");
        } else alert(retrieved_data);
    });
}

/**/function update_restaurant_cuisines(restaurant_id) {

    var form = document.getElementById('edit_restaurant_form_' + restaurant_id);

    var separator;
    var cuisines_count = $('#edit_restaurant_form_' + restaurant_id).find('select[name|=restaurant_cuisine_id]').length;
    var restaurant_cuisine_id_list = '';
    var restaurant_cuisine_id_array = new Array();
    if (cuisines_count > 1) {
        for (var x = 0 ; x < cuisines_count ; x++) {
            if (x == cuisines_count-1) separator = '';
            else separator = ':::';
            restaurant_cuisine_id_array[restaurant_cuisine_id_array.length] = form.restaurant_cuisine_id[x].value;
            restaurant_cuisine_id_list += form.restaurant_cuisine_id[x].value + separator;
        }
        if (check_duplicate_values(restaurant_cuisine_id_array, cuisines_count)) {
            if (window.current_language == "en") alert("Duplicate cuisines found");
            if (window.current_language == "es") alert("Se ingresaron cocinas duplicadas");
            return;
        }
    } else {
        restaurant_cuisine_id_list = form.restaurant_cuisine_id.value;
    }

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_restaurant_cuisines",
        restaurant_id: restaurant_id,
        restaurant_cuisine_id_list: restaurant_cuisine_id_list
    }, function(retrieved_data){
        if (retrieved_data == 'success'){
            if (window.current_language == "en") alert("Data updated successfully");
            if (window.current_language == "es") alert("Actualización exitosa");
        } else alert(retrieved_data);
    });
}

/**/function update_restaurant_menu_admin(restaurant_id) {

    var form = document.getElementById('edit_restaurant_form_' + restaurant_id);

    var restaurant_admin_username = form.restaurant_admin_username.value;
    if (restaurant_admin_username == '') {
        if (window.current_language == "en") alert("Username can not be blank");
        if (window.current_language == "es") alert("El nombre de usuario no puede ser en blanco");
        return;
    }
    var restaurant_admin_password = form.restaurant_admin_password.value;
    var restaurant_admin_password_again = form.restaurant_admin_password_again.value;
    if (restaurant_admin_password == '') {
        if (window.current_language == "en") alert("Password can not be blank");
        if (window.current_language == "es") alert("La contraseña no puede ser en blanco");
        return;
    }
    if (restaurant_admin_password != restaurant_admin_password_again) {
        if (window.current_language == "en") alert("Password and Password again do not match");
        if (window.current_language == "es") alert("La contraseña y la confirmación de la contraseña no coinciden");
        return;
    }

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_restaurant_menu_admin",
        restaurant_id: restaurant_id,
        restaurant_admin_username: restaurant_admin_username,
        restaurant_admin_password: restaurant_admin_password
    }, function(retrieved_data){
        if (retrieved_data == 'success'){
            if (window.current_language == "en") alert("Data updated successfully");
            if (window.current_language == "es") alert("Actualización exitosa");
        } else alert(retrieved_data);
    });
}

/**/function update_restaurant_locations(restaurant_id) {

    var form = document.getElementById('edit_restaurant_form_' + restaurant_id);

    var separator;
    var locations_count = $('#edit_restaurant_form_' + restaurant_id).find('select[name|=restaurant_neighbourhood_id]').length;
    var restaurant_neighbourhood_id_list = '';
    var restaurant_phone1_list = '';
    var restaurant_phone2_list = '';
    var restaurant_address_list = '';
    var restaurant_mail_contact_list = '';
    var restaurant_map_embed_url_list = '';
    var restaurant_neighbourhood_id_array = new Array();

    if (locations_count > 1) {
        for (x = 0 ; x < locations_count ; x++) {
            if (x == locations_count-1) separator = '';
            else separator = ':::';
            restaurant_neighbourhood_id_array[restaurant_neighbourhood_id_array.length] = form.restaurant_neighbourhood_id[x].value;
            restaurant_neighbourhood_id_list += form.restaurant_neighbourhood_id[x].value + separator;
            restaurant_phone1_list += form.restaurant_phone1[x].value + separator;
            restaurant_phone2_list += form.restaurant_phone2[x].value + separator;
            restaurant_address_list += form.restaurant_address[x].value + separator;
            restaurant_mail_contact_list += form.restaurant_mail_contact[x].value + separator;
            restaurant_map_embed_url_list += form.restaurant_map_embed_url[x].value + separator;
        }
        if (check_duplicate_values(restaurant_neighbourhood_id_array, locations_count)) {
            if (window.current_language == "en") alert("Duplicate locations found. You can only register one location for each neighbourhood");
            if (window.current_language == "es") alert("Se ingresaron sucursales duplicadas. Solo puede registrar una sucursal por barrio");
            return;
        }
    } else {
        restaurant_neighbourhood_id_list += form.restaurant_neighbourhood_id[form.restaurant_neighbourhood_id.selectedIndex].value;
        restaurant_phone1_list += form.restaurant_phone1.value;
        restaurant_phone2_list += form.restaurant_phone2.value;
        restaurant_address_list += form.restaurant_address.value;
        restaurant_mail_contact_list += form.restaurant_mail_contact.value;
        restaurant_map_embed_url_list += form.restaurant_map_embed_url.value;
    }

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_restaurant_locations",
        restaurant_id: restaurant_id,
        restaurant_neighbourhood_id_list: restaurant_neighbourhood_id_list,
        restaurant_phone1_list: restaurant_phone1_list,
        restaurant_phone2_list: restaurant_phone2_list,
        restaurant_address_list: restaurant_address_list,
        restaurant_mail_contact_list: restaurant_mail_contact_list,
        restaurant_map_embed_url_list: restaurant_map_embed_url_list
    }, function(retrieved_data){
        if (retrieved_data == 'success'){
            if (window.current_language == "en") alert("Data updated successfully");
            if (window.current_language == "es") alert("Actualización exitosa");
        } else alert(retrieved_data);
    });
}

/**/function save_admin_restaurant_special(restaurant_special_id, restaurant_id) {

    var form = document.getElementById('admin_restaurant_special_form_id_' + restaurant_special_id);
    
    var disabled;
    if (form.disabled.checked == true) disabled = 1;
    else disabled = 0;

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "save_admin_restaurant_special",
        restaurant_special_id: form.restaurant_special_id.value,
        restaurant_id: restaurant_id,
        description_en: form.description_en.value,
        description_es: form.description_es.value,
        discount_percentage: form.discount_percentage.value,
        disabled: disabled
    }, function(retrieved_data){
        if (no_error(retrieved_data)) {
            if (form.restaurant_special_id.value == '' && !isNaN(retrieved_data)) form.restaurant_special_id.value = retrieved_data;
            if (window.current_language == "en") alert("Data updated successfully");
            if (window.current_language == "es") alert("Actualización exitosa");
        } else alert(retrieved_data);
    });
}

/**/function remove_admin_restaurant_special(restaurant_special_id) {

    if (restaurant_special_id == '') return;

    if (window.current_language == "en") {
        if (!confirm("Are you sure that you want to completely remove this restaurant special?")) return;
    }
    if (window.current_language == "es") {
        if (!confirm("Está seguro que quiere remover esta promoción de restaurante?")) return;
    }

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "delete_restaurant_special",
        restaurant_special_id: restaurant_special_id
    }, function(retrieved_data){
        if (retrieved_data == 'success'){
            if (window.current_language == "en") alert("Restaurant special successfuly deleted");
            if (window.current_language == "es") alert("Promoción de restaurante eliminada exitosamente");
            window.location.reload();
        } else alert(retrieved_data);
    });
}

/**/function add_another_cuisine_html(caller) {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_empty_cuisine_combo_box"
    }, function(retrieved_data){
        $(caller).parent().parent().append(retrieved_data);
    });
}

/**/function add_another_neighbourhood_html(caller) {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_empty_neighbourhood_combo_box"
    }, function(retrieved_data){
        $(caller).parent().parent().append(retrieved_data);
    });
}

/**/function add_another_admin_restaurant_special(tag, restaurant_id) {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_empty_partial",
        partial_name: 'admin_restaurant_special',
        partial_parameters: "restaurant_id=>" + restaurant_id
    }, function(retrieved_data){
        $('#' + tag).append(retrieved_data);
    });
}

/**/function delete_restaurant(restaurant_id) {
    var confirmation = 0;
    if (window.current_language == "en") {
        if (confirm("Are you sure that you want to completely remove this restaurant and ALL its data? This includes all menues. This action is IRREVERSIBLE and can not be undone. Proceed?")) confirmation++;
        else return;
    }
    if (window.current_language == "es") {
        if (confirm("Está seguro que quiere remover este restaurante y TODA su información asociada? Esta información incluye todos los menu. Esta acción es IRREVERSIBLE y no puede ser deshecha. Desea proceder?")) confirmation++;
        else return;
    }
    if (window.current_language == "en") {
        if (confirm("WARNING: all data for restaurant will be PERMANENTLY lost. Are you sure?")) confirmation++;
        else return;
    }
    if (window.current_language == "es") {
        if (confirm("ADVERTENCIA: toda la información del restaurante va a eliminarse en forma PERMANENTE. Esta seguro?")) confirmation++;
        else return;
    }
    if (confirmation == 2) {
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "delete_restaurant",
            restaurant_id: restaurant_id
        }, function(retrieved_data){
            if (retrieved_data == 'success'){
                if (window.current_language == "en") alert("Restaurant successfuly deleted");
                if (window.current_language == "es") alert("Restaurante eliminado exitosamente");
                window.location.reload();
            } else alert(retrieved_data);
        });
    }
}

/**/function turn_on_off_call_center() {
    var on_off_value;
    if (window.call_center_status == 'ON') on_off_value = 'false';
    else on_off_value = 'true';
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "turn_on_off_call_center",
        on_off_value: on_off_value
    }, function(retrieved_data){
        if (retrieved_data == 'success') {
            if (on_off_value == 'true') {
                window.call_center_status = 'ON';
                $('#call_center_status_span').addClass('cc_on').text(window.call_center_status);
                if (window.current_language == "en") {
                    $('#call_center_on_off_switch').text('(turn off)');
                    alert("Call Center is now turned on");
                }
                else if (window.current_language == "es") {
                    $('#call_center_on_off_switch').text('(apagar)');
                    alert("El Call Center ha sido encendido");
                }
            } else {
                window.call_center_status = 'OFF';
                $('#call_center_status_span').removeClass('cc_on').text(window.call_center_status);
                if (window.current_language == "en") {
                    $('#call_center_on_off_switch').text('(turn on)');
                    alert("Call Center is now turned off");
                }
                else if (window.current_language == "es") {
                    $('#call_center_on_off_switch').text('(encender)');
                    alert("El Call Center ha sido apagado");
                }
            }
        }
    });
}

/**/function add_holiday() {
    var form = document.getElementById('form_add_holiday');
    var holiday_date = form.holiday_date.value;
    var holiday_description = form.holiday_description.value;

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "add_holiday",
        holiday_date: holiday_date,
        holiday_description: holiday_description
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else {
            $('#abm_holidays_content_div').slideToggle();
            $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
                function_to_call: "show_holidays"
            }, function(retrieved_data2) {
                $('#abm_holidays_content_div').html(retrieved_data2);
                $('#abm_holidays_content_div').slideToggle();
            });
        }
    });

}

/**/function delete_holiday(holiday_id) {
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "delete_holiday",
        holiday_id: holiday_id
    }, function(retrieved_data) {
        $('#tr_'+holiday_id).remove();
    });
}

/**/function bind_inline_updates_engine(placed_order_id, menu_item_id, price_type_id) {
    var item_id_class = 'item_id_' + menu_item_id + '_' + price_type_id;
    $('.' + item_id_class + ' .minus_sign_img').bind('click', function() {
        if (parseInt($('.' + item_id_class + ' .quantity_span').text()) > 0) {
            $('.' + item_id_class + ' .quantity_span').text(parseInt($('.' + item_id_class + ' .quantity_span').text()) - 1);
            update_order_item_quantity_on_db(placed_order_id, menu_item_id, price_type_id, item_id_class);
        }
    });
    $('.' + item_id_class + ' .plus_sign_img').bind('click', function() {
        $('.' + item_id_class + ' .quantity_span').text(parseInt($('.' + item_id_class + ' .quantity_span').text()) + 1);        
        update_order_item_quantity_on_db(placed_order_id, menu_item_id, price_type_id, item_id_class);
    });
    $('.' + item_id_class + ' .price_input').bind('change', function() {
        update_price_x_quantity(item_id_class, 'update_order_grand_total');
        eval("window.menu_" + item_id_class + " = true");
        $('.' + item_id_class + ' .button_p').animate({
            opacity: 1
        }, 250);
    });
}

/**/function bind_pay_with_input_engine(placed_order_id) {
    $('#totals_div #pay_with_input').bind('change', function() {
        update_order_change_needed();
        update_order_change_on_db(placed_order_id)
    });
}

/**/function bind_delivery_delay_engine(placed_order_id) {
    $('#confirm_order_time_div .minus_sign_img').bind('click', function() {
        if (parseInt($('#confirm_order_time_div .delivery_delay_input').attr('value')) > 4) {
            $('#confirm_order_time_div .delivery_delay_input').attr('value', parseInt($('#confirm_order_time_div .delivery_delay_input').attr('value')) - 5);
        } else $('#confirm_order_time_div .delivery_delay_input').attr('value', parseInt(0));
        update_order_delivery_delay_on_db(placed_order_id);
    });
    $('#confirm_order_time_div .plus_sign_img').bind('click', function() {
        $('#confirm_order_time_div .delivery_delay_input').attr('value', parseInt($('#confirm_order_time_div .delivery_delay_input').attr('value')) + 5);
        update_order_delivery_delay_on_db(placed_order_id);
    });
    $('#confirm_order_time_div .delivery_delay_input').bind('change', function() {
        update_order_delivery_delay_on_db(placed_order_id);
    });
}

/**/function update_price_x_quantity(item_id_class) {
    $('.' + item_id_class + ' .quantity_price_span').text((parseFloat($('.' + item_id_class + ' .quantity_span').text()) * parseFloat($('.' + item_id_class + ' .price_input').attr('value'))).toFixed(2));
    update_order_grand_total();
}

/**/function update_order_grand_total() {
    var order_grand_total = 0;
    var order_md5 = document.getElementById('order_md5').value;
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "get_updated_order_grand_total",
            order_md5: order_md5
        }, function(retrieved_data) {            
            order_grand_total = parseFloat(retrieved_data);
            order_grand_total += parseFloat($('#additional_charge_amount_input').attr('value'));
            $('#totals_div #order_grand_total_span').text(order_grand_total.toFixed(2));
            update_order_change_needed();
        });   
}

/**/function update_order_change_needed() {
    var change_needed = parseFloat($('#totals_div #pay_with_input').attr('value')) - parseFloat($('#totals_div #order_grand_total_span').text());
    if (change_needed < 0) {
        $('#totals_div #change_needed_span').text('-');
        $('#totals_div #client_will_pay_with_dt').css('color','#ED1C24');
    } else {
        $('#totals_div #change_needed_span').text(change_needed.toFixed(2));
        $('#totals_div #client_will_pay_with_dt').css('color','#ACACAC');
    }
}


/**/function update_menu_item_price_on_db_and_on_order_on_db(placed_order_id, menu_item_id, price_type_id) {

    var item_id_price_type_id = menu_item_id + '_' + price_type_id;
    var price = $('.item_id_' + item_id_price_type_id + ' .price_input').attr('value');

    if (eval("window.menu_item_id_" + item_id_price_type_id) == true) {
        $('.item_id_' + item_id_price_type_id + ' .button_p').hide();
        $('.item_id_' + item_id_price_type_id + ' .updating_loader_img').css('display', 'inline');
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "update_menu_item_price",
            menu_item_id: menu_item_id,
            price_type_id: price_type_id,
            price: price
        }, function(retrieved_data) {
            if(retrieved_data != "success") {
                alert(retrieved_data);
            } else {
                $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
                    function_to_call: "update_order_item_price_on_db",
                    placed_order_id: placed_order_id,
                    menu_item_id: menu_item_id,
                    price_type_id: price_type_id,
                    price: price
                }, function(retrieved_data) {
                    if(retrieved_data != "success") {
                        alert(retrieved_data);
                    } else {

                        eval("window.menu_item_id_" + item_id_price_type_id + " = false");
                    }
                    $('.item_id_' + item_id_price_type_id + ' .updating_loader_img').hide();
                    $('.item_id_' + item_id_price_type_id + ' .button_p').show().animate({
                        opacity: 0.5
                    }, 0);
                });
            }
        });
    }
}

/**/function update_order_item_quantity_on_db(placed_order_id, menu_item_id, price_type_id, item_id_class) {

    var item_id_price_type_id = menu_item_id + '_' + price_type_id;
    var quantity = $('.item_id_' + item_id_price_type_id + ' .quantity_span').text();

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_order_item_quantity_on_db",
        placed_order_id: placed_order_id,
        menu_item_id: menu_item_id,
        price_type_id: price_type_id,
        quantity: quantity
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        }else {
            update_price_x_quantity(item_id_class);
        }
    });
}

/**/function update_order_change_on_db(placed_order_id) {

    var change = $('#totals_div #pay_with_input').attr('value');

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_order",
        placed_order_id: placed_order_id,
        change: change
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        }
    });
}

/**/function update_order_delivery_delay_on_db(placed_order_id) {

    var delivery_delay = $('#confirm_order_time_div .delivery_delay_input').attr('value');

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_order",
        placed_order_id: placed_order_id,
        delivery_delay: delivery_delay
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        }
    });
}

/**/function process_order_for_first_time(placed_order_id, order_md5) {

    var url = window.dev + '/admin/view_order/' + order_md5;
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "process_order_for_first_time",
        placed_order_id: placed_order_id
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else {
            window.location.href = url;
        }
    });
}

/**/function show_order_problem_section(new_section) {
    $('.dynamic_section').hide();
    $('#' + new_section + '_div').show();
}

/**/function cancel_order_and_go_to_preview_customer_cancel_email(placed_order_id, comments, order_md5) {

    var url = window.dev + '/admin/preview_order_confirmation_email/' + order_md5;
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "operator_cancel_order",
        placed_order_id: placed_order_id,
        responsible_comments: comments
    }, function(retrieved_data) {
        if (retrieved_data != "success") {
            alert(retrieved_data);
        } else {
            window.location.href = url;
        }
    });
}

/**/function mark_order_as_pending_and_go_back_to_dashboard(placed_order_id, order_md5, comments) {

    var url = window.dev + '/admin/view_order/' + order_md5;
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "operator_mark_as_pending",
        placed_order_id: placed_order_id,
        responsible_comments: comments
    }, function(retrieved_data) {
        if (retrieved_data != "success") {
            alert(retrieved_data);
        } else {
            window.location.href = url;
        }
    });
}

/**/function confirm_order_if_pending_and_send_customer_order_email(placed_order_id, email_subject, email_body, order_status) {

    $('.edit_subject_summary_div').remove();
    if (order_status == 'pending') {
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "operator_confirm_order_in_db",
            placed_order_id: placed_order_id
        }, function(retrieved_data) {
            if (retrieved_data == "success") {
                send_customer_order_email(placed_order_id, email_subject, email_body);
            } else {
                alert(retrieved_data);
            }
        });
    } else if (order_status == 'confirmed') {
        if (confirm("ATTENTION: this order is already confirmed and the client might have already received a confirmation email. You want to send this email anyway?"))
            send_customer_order_email(placed_order_id, email_subject, email_body);
    } else send_customer_order_email(placed_order_id, email_subject, email_body);
}

/**/function confirm_order_in_db_without_sending_email(placed_order_id) {

    var url = window.dev + '/admin/orders_dashboard/';
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "operator_confirm_order_in_db",
        placed_order_id: placed_order_id
    }, function(retrieved_data) {
        if (retrieved_data == "success") {
            window.location.href = url;
        } else {
            alert(retrieved_data);
        }
    });
}

/**/function send_customer_order_email(placed_order_id, email_subject, email_body) {

    var url = window.dev + '/admin/orders_dashboard/';
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "send_customer_order_confirmation_email",
        placed_order_id: placed_order_id,
        email_subject: email_subject,
        email_body: email_body
    }, function(retrieved_data) {
        if (retrieved_data != "success") {
            alert(retrieved_data);
        } else {
            alert('Email sent!');
            window.location.href = url;
        }
    });
}

/**/function view_order_get_restaurant_menu(placed_order_id, restaurant_id) {

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "get_menu_html",
        placed_order_id: placed_order_id,
        restaurant_id: restaurant_id,
        add_item_mode: 'view_order'
    }, function(retrieved_data) {
        if (retrieved_data.substr(0, 5) == 'error') alert(retrieved_data);
        else $('#restaurant_menu_div').html(retrieved_data);
    });
}

/**/function view_order_show_restaurant_menu() {
    $('#add_new_item_span').hide();
    $('#hide_restaurant_menu_span').show();
    $('#restaurant_menu_div').show();
}

/**/function view_order_hide_restaurant_menu() {
    $('#add_new_item_span').show();
    $('#hide_restaurant_menu_span').hide();
    $('#restaurant_menu_div').hide();
}

/**/function view_order_add_item_to_order(placed_order_id, menu_item_id, price_type_id) {

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "add_new_item_to_order",
        placed_order_id: placed_order_id,
        menu_item_id: menu_item_id,
        price_type_id: price_type_id
    }, function(retrieved_data) {
        if (retrieved_data.substr(0, 5) == 'error') alert(retrieved_data);
        else window.location.reload();//$('#order_items_detail_table tbody').appendChild(retrieved_data);
    });
}

/**/function view_add_additional_charge_form() {
    $('#add_additional_charge_span').hide();
    $('#add_additional_charge_form_div').show();
}

/**/function hide_add_additional_charge_form() {
    $('#add_additional_charge_form_div').hide();
    $('#add_additional_charge_span').show();
    document.getElementById('add_additional_charge_form').reset();
    $('#submit_additional_charge_span').animate({
        opacity: 0.5
    }, 0);
}

/**/function view_order_save_additional_charge(placed_order_id) {
    var form = document.getElementById('add_additional_charge_form');

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_order",
        placed_order_id: placed_order_id,
        additional_charge_description: form.additional_charge_description.value,
        additional_charge_amount: form.additional_charge_amount.value
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else window.location.reload();
    });
}

/**/function additional_charge_changed() {
    $('#submit_additional_charge_span').animate({
        opacity: 1
    }, 0);
}

/**/function delete_additional_charge(placed_order_id) {

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "update_order",
        placed_order_id: placed_order_id,
        additional_charge_description: '',
        additional_charge_amount: 0
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else window.location.reload();
    });
}

/**/function users_management_save_user(user_id) {

    var username = $('.edit_user_id_' + user_id + ' .username').attr('value');
    var password = $('.edit_user_id_' + user_id + ' .password').attr('value');
    var confirm_password = $('.edit_user_id_' + user_id + ' .confirm_password').attr('value');
    var profile = $('.edit_user_id_' + user_id + ' .profile').attr('value');

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "save_user",
        user_id: user_id,
        username: username,
        password: password,
        confirm_password: confirm_password,
        profile: profile
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else window.location.reload();
    });
}

/**/function users_management_delete_user(user_id) {

    if (confirm('Are you sure you want to delete this user? This action can not be reverted!!!')) {
        $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
            function_to_call: "delete_user",
            user_id: user_id
        }, function(retrieved_data) {
            if(retrieved_data != "success") {
                alert(retrieved_data);
            } else window.location.reload();
        });
    }
}

/**/function order_confirmation_email_edit_subject_summary_p() {
    $('#subject_summary_p').after('<div class="edit_subject_summary_div"><form id="edit_subject_summary_form" action=""><textarea id="edit_subject_summary_textarea" name="edit_subject_summary_textarea" class="edit_subject_summary_textarea" cols="" rows="">' + $('#subject_summary_p').html() + '</textarea></form><p><span class="awesome button_p edit_subject_summary_done_span" onclick="javascript: update_subject_summary_p();">Done</span><span class="awesome button_p edit_subject_summary_cancel_span" onclick="javascript: $(\'.edit_subject_summary_div\').remove();">Cancel</span></p></div>');
}

/**/function update_subject_summary_p() {
    var form = document.getElementById('edit_subject_summary_form');
    $('#subject_summary_p').html(form.edit_subject_summary_textarea.value);
    $('.edit_subject_summary_div').remove();
}

/**/function loadMap() {
    // setup Google Map
	var point = new GLatLng(START_LOCATION[0],START_LOCATION[1]);
    map = new GMap2(document.getElementById(ID_MAP_DIV));
    map.setCenter(point, START_ZOOM);
    //map.addControl(new GSmallMapControl());
    map.addControl(new GSmallZoomControl());

    geocoder = new GClientGeocoder();

    // build/add marker
    marker = new GMarker(new GLatLng(START_LOCATION[0],START_LOCATION[1]), {
        icon:icon,
        draggable:false
    });
    
    set_search_addr();
    
    // set initial marker in default lat and lon
    map.setCenter(point, 15);
    marker.setLatLng(point);
    map.addOverlay(marker);
    // if no previous address, refresh the order list
    if (readCookie('address') === null) {
        open_restaurant_list();
    }
}

function showAddress(street, number) {
    if (load_street_address){
        if (street == '') {
            /*if (ignore_empty != undefined) {
            refresh_order_lists();
            return;
            }*/
            switch (window.current_language) {
                case 'en':
                    alert('Please input your address');
                    return;
                    break;
                case 'es':
                    alert('Por favor, ingrese su dirección');
                    return;
                    break;
                default:
                    return;
                    break;
            }
        } else {
            //set cookie to be used on order form or next search
            var FormObject = document.forms['address_search'];
            createCookie("address", FormObject.elements["street"].value, 365);
            createCookie("st_number", FormObject.elements["number"].value, 365);
        }
    
        var address = street + " " + number + ", Capital Federal, Argentina";
    } else {
           reset_map();
           refresh_order_lists();
           load_street_address = true;
    }
    if (geocoder) {
        geocoder.getLatLng(
            address,
            function(point) {
                if (!point) {
                    switch (window.current_language) {
                        case 'en':
                            alert(address + " not found");
                            return;
                            break;
                        case 'es':
                            alert(address + " no fue encontrada");
                            return;
                            break;
                        default:
                            return;
                            break;
                    }
                }
                else {
                    map.setCenter(point, 15);
                    marker.setLatLng(point);
                    map.addOverlay(marker);

                    // Setup a cookies with client's lat and long
                    createCookie('client_lat', point.lat(), 365);
                    createCookie('client_lng', point.lng(), 365);

                    isPointInPolygon(point);

                    //clear the current neighbourhood
                    $("#neighbourhood_li_" + window.current_neighbourhood).removeClass("active");
                    window.current_neighbourhood = "0";
                }
            });
    }
}

function isPointInPolygon(point){

    var lat = point.lat();
    var lng = point.lng();

    // Calls php function to search form amtching restaurant ids
    $.post(window.REL_PHP_CODE_FOLDER + "/map_search.php", {
        lat: lat,
        lng: lng
    }, function(data) { 

        // Set returned data as restaurants_match_list
        window.geocoder_restaurants_match_list = data;

        // Refresh restaurants list
        refresh_order_lists();

    });
}

function reset_map() {
    window.geocoder_restaurants_match_list = '';
    map.setCenter(new GLatLng(START_LOCATION[0],START_LOCATION[1]), START_ZOOM);
    map.removeOverlay(marker);
    var FormObject = document.forms['address_search'];
    FormObject.elements["street"].value = "";
    FormObject.elements["number"].value = "";
}

/**
 * This function is responsable for setting the remembered user's address, if one.
 * @return void
 */
function set_search_addr() {
    var address = '';
    var st_number = '';
    if (typeof window.new_street != 'undefined' && window.new_street != '') {
        address = window.new_street;
        st_number = window.new_street_number;
    } else {
        st_number = readCookie('st_number') != null? readCookie('st_number'): '';
        address = readCookie('address') != null? readCookie('address'):'';
    }
    if (address != '' && st_number != '') {
        var FormObject = document.forms['address_search'];
        FormObject.elements["street"].value = address;
        FormObject.elements["number"].value = st_number;
        showAddress(address, st_number);
    }
}


/**/function enable_disable_coupon(coupon_id, coupon_code, type) {
    if(coupon_id == '' || coupon_code == '') {
        alert('Invalid Coupon code/Coupon type');
    }
    
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "enable_disable_coupon",
        coupon_id: coupon_id,
        coupon_code: coupon_code,
        coupon_expired: type
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else window.location.reload();
    });
}

function generate_coupon() {
    var coupon_type = document.getElementById('coupon_type_select').value;    
    var coupon_amount = document.getElementById('coupon_amount_input').value;
    var coupon_quantity = document.getElementById('coupon_quantity_input').value;
    var coupon_expiration_date = document.getElementById('expiration_date_input').value;
    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "generate_coupon",
        coupon_type: coupon_type,
        coupon_amount: coupon_amount,
        coupon_quantity: coupon_quantity,
        coupon_expiration_date: coupon_expiration_date
    }, function(retrieved_data) {
        var coupon_data = eval('(' + retrieved_data + ')');
        if(coupon_data['success'] != true) {
            alert(coupon_data['error']);
        } else {
            createCookie('new_coupon_code', coupon_data['coupon_code'] , 1);
            window.location.reload();
        }
    });

}

/**/function delete_coupon(coupon_id) {
    if(coupon_id == '') {
        alert('Invalid Coupon id');
    }

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "delete_coupon",
        coupon_id: coupon_id
    }, function(retrieved_data) {
        if(retrieved_data != "success") {
            alert(retrieved_data);
        } else window.location.reload();
    });
}

/**/function clear_kmls_cache() {

    $.post(window.REL_PHP_CODE_FOLDER + "/run_function.php", {
        function_to_call: "clear_kmls_cache"
    }, function(retrieved_data){
        if (retrieved_data == "success") {
            alert('KMLs cache cleared');
        } else {
            alert('There was an error clearing the KMLs cache');
        }
    });
}

function search_widget_lite_submit() {
    var form = document.getElementById('search_lite_form');
    var address =  form.address.value;
    if (address == '' || address == 'Busca por tu dirección en C.F.') {
        alert('Es necesario ingresar la dirección');
        return;
    }
    var url = 'http://www.buenosairesdelivery.com/address/' + encodeURIComponent(address);
    window.open(url, '_top');

}

function search_widget_delux_submit() {
    var form = document.getElementById('search_delux_form');
    var neighborhood =  form.neighborhood_select.value;
    var food_type =  form.food_type_select.value;
    if (neighborhood == '') {
        alert('Es necesario que selecciones tu barrio.');
        return;
    }
    if (food_type == '') {
        food_type = 'all';
    }

    var url = 'http://www.buenosairesdelivery.com/' + food_type + '/' + neighborhood;
    window.open(url, '_top');

}

