﻿function ResetText(Control,TextToReset)
{
    if($(Control).val() == TextToReset)
    {
        $(Control).val("");
    }
    $(Control).focusout(function(){
        if($(Control).val() == "")
        {
            $(Control).val(TextToReset);
        }
    });
}


function TimeoutRedirect(Page,Seconds)
{
    window.setTimeout(function(){
        window.location.replace(Page);
    },Seconds  * 1000);
}

//On document ready events
$(document).ready(function(){
try{
        $('a.WordDefenition').each(function(){
            $(this).mouseenter(function(){
                ShowWordDefenitionBubble($(this).attr('ID'),$(this).html(),$(this));
            });
            $(this).click(function(){
                ShowWordDefenitionBubble($(this).attr('ID'),$(this).html(),$(this));
            });
            $(this).mouseleave(function(){
                $('#DefenitionWindow').delay(500).hide();
            });
            $(document).mouseenter(function(){
                $('#DefenitionWindow').delay(500).hide();
            });
        });
        
        //popup dialogs
        
        $('.popupDialog').popupWindow(
        {
            heigh:700,
            width:900,
            centerBrowser:1,
            scrollbars:1,
            location:1,
            menubar:0,
            toolbar:0
        });
    }catch(err)
    {
    
    }
});


function ShowWordDefenitionBubble(Word,Title,AnchorElement)
{
   if(Word != undefined)
   {
        var position = $(AnchorElement).offset();
        $('#DefenitionWindow').show();
        if(position.top < 250)
        {
            $('#DefenitionWindow').css('bottom','0');
        }
        else
        {
            $('#DefenitionWindow').css('top','0');
        }
        
        $.ajax({
          url:"/Services/WordDefenitions.aspx",
          method:"POST",
          data:"word=" + Word+"&title="+Title,
          success:function(data)
          {
            $('#DefenitionWindow').html(data);
          }  
        });
    }
}


function OpenModalWindow(Selector)
{
    var maskWidth = $(document).width();
    var maskHeight = $(document).height();
    
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    
    $('#mask').fadeTo("slow",0.8);	
    $('#mask').show();
    
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    
    $(Selector).css('position','absolute');
    $(Selector).css('z-index','4000');
    $(Selector).css('top',  '10%');
    $(Selector).css('left', '16%');
    
    $(Selector).show();
    
    $('#mask').click(function(){
        CloseModalWindow(Selector);
    });
}

function CloseModalWindow(Selector)
{
    $(Selector).hide();
    $('#mask').hide();
}

function DisableContextMenu()
{
  document.oncontextmenu = function()
    {
        if(event.button == 0)
        {
            alert('Function Disabled');
            return false;
        }
    };
}
