jQuery.noConflict();
var prev_con;
var help_visible = false;
var prefocustext;
var glob_cur = 0;
var glob_size = 10;
var functionHistory= "";
var edit_page = "";
var a, b, q;
var limit = 10;
var dir = "";
var activeTab = 0;

/*
 * I18n
 */
 
function _(s) {
    if (typeof(i18n)!=='undefined' && i18n[s]) {
        return i18n[s];
    }
    return s;
}

function clearInput(){
    jQuery("#s_where").val("");
    jQuery("#s_what").val("");
    jQuery("#s_branches").val("0");
}

jQuery(document).ready(function(){
    //jQuery('#basicModalContent').modal(); // jQuery object; this demo
    jQuery("#s_what").blur(function () {
        //jQuery(this).val(prefocustext);
        });
    jQuery("#s_what").focus(function () {
        if(jQuery("#s_what").val() === _('What')) {
            prefocustext = jQuery(this).val();
            jQuery(this).val("");
        }
    });

    jQuery("#s_where").blur(function () {
        //jQuery(this).val(prefocustext);
        });
    jQuery("#s_where").focus(function () {
        if(jQuery("#s_where").val() === _("Where")) {
            prefocustext = jQuery(this).val();
            jQuery(this).val("");
        }
    });
});

function logAction(action,vars) {
    //action is the click action a user performed
    //vars is an array of variables that need to be stored in the log
    var vrs = vars.toString();
    jQuery.get("/log.php?a=" + action + "&q=" + vrs);
}


function what(start, initial, q_optional) {
    if (typeof q_optional !== "undefined") {
        q = q_optional;
    }
    req_str = "";


    if(jQuery("#s_where").val() !== _('Where') && jQuery("#s_where").val() !== "") {
        a = jQuery("#s_where").val();
    } else {
        a = "";
    }
    if(jQuery("#s_what").val() !== _('What') && jQuery("#s_what").val() !== "") {
        q = jQuery("#s_what").val();
    } else {
        q = "";
    }
    if(q !== "") {
        req_str = req_str + "/find/" + q;
    }

    jQuery.get(req_str, function(data){
        //Show single detail
        location.href = req_str;
    });

}

function toggleHelp(e) {
    if (help_visible){
        help_visible = false;
        jQuery("#content_center").css('text-align', '');
        jQuery("#content_center").html(prev_con);
    } else{
        help_visible = true;
        prev_con = jQuery("#content_center").html();
        //jQuery("#content_center").empty();
        jQuery("#content_center").css('text-align', 'justify');
        jQuery("#content_center").load("/faq.php");
    }
}

function toggleTerm(e) {
    if (help_visible){
        help_visible = false;
        jQuery("#content_center").css('text-align', '');
        jQuery("#content_center").html(prev_con);
    } else{
        help_visible = true;
        prev_con = jQuery("#content_center").html();
        jQuery("#content_center").css('text-align', 'justify');
        jQuery("#content_center").load("/terms.php");
    }
}
