/*
*	Author:			Johnathan Gould
*	For:			Munro Consulting
*	Created:		12 April 2010
*	Description:	The common javascript functions called throughout the site.
*/

$(function() {
	//
	//	Enter to tab
	//
	if ($.browser.mozilla) {
        $(".enter").keypress(checkForEnter);
    } else {
        $(".enter").keydown(checkForEnter);
    }

	//
	//	All the button types
	//
	$(".ui-button").button();
	
	$(".ui-button-home").button({
            icons: {secondary: 'ui-icon-home'}
	});
	$(".ui-button-send").button({
            icons: {secondary: 'ui-icon-mail-closed'}
	});
	$(".ui-button-process").button({
            icons: {secondary: 'ui-icon-disk'}
	});
	$(".ui-button-login").button({
            icons: {secondary: 'ui-icon-key'}
	});
	$(".ui-button-next").button({
            icons: {secondary: 'ui-icon-circle-arrow-e'}
	});
	$(".ui-button-prev").button({
            icons: {secondary: 'ui-icon-circle-arrow-w'}
	});
	$(".ui-button-go").button({
            icons: {secondary: 'ui-icon-check'}
	});
	$(".ui-button-back").button({
            icons: {primary: 'ui-icon-arrowreturnthick-1-w'}
	});
	$(".ui-button-add").button({
            icons: {secondary: 'ui-icon-plusthick'}
	});
	$(".ui-button-minus").button({
            icons: {secondary: 'ui-icon-minusthick'}
	});
	$(".ui-button-remove").button({
            icons: {secondary: 'ui-icon-circle-close'}
	});
	$(".ui-button-retire").button({
            icons: {secondary: 'ui-icon-arrowthickstop-1-e'}
	});
	$(".ui-button-undo").button({
            icons: {secondary: 'ui-icon-arrowreturnthick-1-w'}
	});
	$(".ui-button-continue").button({
            icons: {secondary: 'ui-icon-arrowreturnthick-1-e'}
	});
	$(".ui-button-down").button({
            icons: {secondary: 'ui-icon-triangle-1-s'}
	});
	$(".ui-button-edit").button({
            icons: {secondary: 'ui-icon-pencil'}
	});
	$(".ui-button-calculate").button({
            icons: {secondary: 'ui-icon-gear'}
	});
	$(".ui-button-search").button({
            icons: {secondary: 'ui-icon-search'}
	});
});

//	Change behaviour for enter key to a tab
function checkForEnter(event) {
    var lfound = false 
    if (event.keyCode == 13) {
        var obj = this;
        $(".enter").each(function() {
            if (this == obj) {
                lfound = true
            } else {
                if (lfound) {
                    $(this).focus()
                    $(this).select();
                    event.preventDefault();
                    return false;
                }
            }
        });
    }
}

// Removing a stream from an online service
function removeStream(num)
{
	document.getElementById("str_"+num+"_deleted").value = 1;
	document.getElementById("str_"+num).style.display = 'none';
}

// Removing a once-off from an online service
function removeOnceOff(num)
{
	document.getElementById("onceOff_"+num+"_deleted").value = 1;
	document.getElementById("onceOff_"+num).style.display = 'none';
}

function showLoadOnceOff()
{
	document.getElementById("onceOffLoad").style.display = "block";
}

function toggleLoginFrame()
{
	var frame = document.getElementById("login_more");
	if (frame.style.display == "none")
		frame.style.display = "inline";
	else
		frame.style.display = "none";
}

function showLookMenu()
{
	document.getElementById("look_menu").style.display = "block";
}
function hideLookMenu()
{
	document.getElementById("look_menu").style.display = "none";
}

function showContMenu()
{
	document.getElementById("cont_menu").style.display = "block";
}
function hideContMenu()
{
	document.getElementById("cont_menu").style.display = "none";
}

function showInstrMenu()
{
	document.getElementById("instr_menu").style.display = "block";
}
function hideInstrMenu()
{
	document.getElementById("instr_menu").style.display = "none";
}

function showContactMenu()
{
	document.getElementById("contact_menu").style.display = "block";
}
function hideContactMenu()
{
	document.getElementById("contact_menu").style.display = "none";
}
