String.prototype.StartsWith = function(str) 
{
    return (this.match("^"+str)==str)
}


//SECTION 1//

/*Handlers for on off state images*/

//Replaces an off image with an on image e.g. button_off.gif -> button_on.gif
$.fn.onImage = function ()
{
    $(this).each(function ()
    {
        $(this).attr('src', $(this).attr('src').replace('_off.', '_on.'));
        return $(this);
    });
}

//Replaces an on image with an off image e.g. button_on.gif -> button_off.gif
$.fn.offImage = function ()
{
    $(this).each(function ()
    {
        $(this).attr('src', $(this).attr('src').replace('_on.', '_off.'));
        return $(this);
    });
    
}

//Handles on/off states in a radio button style -> Only one out of a list of selectors will be on at a time
$.fn.radioStateClick = function ()
{
    
    var allbuttons = $(this);
    
    $(this).each(function()
    {
        $(this).click(function()
        {
            $(allbuttons).offImage();
           $(this).onImage();
        });
    })
    
    
    return $(this);
}

//Handles on/off states for mouse hover instead of click as above
$.fn.radioStateHover = function ()
{
    var allbuttons = $(this);
    
    $(this).each(function()
    {
        $(this).hover(function()
        {
           $(this).onImage();
        },
        function()
        {
            $(this).offImage();
        });
    })
    return $(this);
}

//END SECTION 1//


$.fn.centerVertical = function ()
{
    
    var topMargin = ((($(this).parent().height()) - ($(this).height()))) / 2;
    
    $(this).css('margin-top', topMargin + "px");
}
$.fn.centerHorizontal = function ()
{
    
    var leftMargin = ((($(this).parent().width()) - ($(this).width()))) / 2
    $(this).css('margin-left', leftMargin + "px");
}
//Get screen viewport width and height
function viewPortHeight()
{
     if (typeof window.innerHeight != 'undefined')
     {
          return window.innerHeight;
     }
     else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0)
     {
           return document.documentElement.clientHeight;
     }
     else
     {
           return document.getElementsByTagName('body')[0].clientHeight;
     }
     return 0;
}
function viewPortWidth()
{
     if (typeof window.innerWidth != 'undefined')
     {
          return window.innerWidth;
     }
     else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
     {
           return document.documentElement.clientWidth;
     }
     else
     {
           return document.getElementsByTagName('body')[0].clientWidth;
     }
     return 0;
}


