$(document).ready(function() {
    $('#inspired-errors').click(function(){
        $('#inspired-errors').hide();
    });

    var websiteUrl = $('#website_url').val();
    if(websiteUrl=="")
    {
        websiteUrl =  $('#hid-main-wsurl');
    }

    $('#inspired').click(function()
    {
        $('.editor').hide();
        var tmp = $('.inspired').html();
        if(tmp=="")
        {
            $('.inspired').load(websiteUrl+'sys/backend_inspired/index/pageId/'+$('#pageId').val());
        }
        $(".inspired").show();
    });
       
});


$(document).ajaxStart(function () {
    $('#ajaxBusy').show();
});
$(document).ajaxStop(function (){
    $('#ajaxBusy').hide();
});

function checkEnter(e)
{
    $("#h1find").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            findTeasareous();
            return false;
        } 
    });
}

function backToPage()
{
    $(".inspired").hide();
    $('.editor').show();
   
}

function processThesaurus()
{
    var websiteUrl = $('#website_url').val();
    if(websiteUrl=="")
    {
        websiteUrl =  $('#hid-main-wsurl');
    }
    $.ajax({
        type : 'POST',
        url:''+websiteUrl+'sys/backend_ajax/processthesaurus/',
            
        success: function(response){
            if(response==1)
            {
                parent.tb_remove();
            }
        }
    });
}

function findTeasareous()
{
    var websiteUrl = $('#website_url').val();
    var str = trim($('#h1find').val());
    
    if(str!=""){
        $.ajax({
            type : 'POST',
            url:''+websiteUrl+'sys/backend_ajax/findteasareous/',
            data: ({
                str : str
            } ),
            success: function(response){
                $(".words-list").empty();
                $(".words-list").html(response);
            }
        });
    }
    else
    {
        $('#inspired-errors').show();
        $('#search-empty').show();
        $('#inspired-errors').click(function(){
        $('#inspired-errors').hide();
        });
    }

}

function trim(str)
{
    var ltrim = /^\s+/g;
    var rtrim = /\s+$/g;

    str = str.replace(ltrim,'');
    str = str.replace(rtrim,'');
    return str;
}
