

var lbsCtrl = Array();
var lbs_crtl_next_id = 0;

function getUniqueId()
{
    return lbs_crtl_next_id ++;
}

function onLoad()
{
}   //  to be override

function onKeyPress( event )
{
}   //  to be override


function get_url_parameter( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function array_find( array, item )
{
    for( i=0; i<array.length; i++ )
    {
        if( item == array[ i ] )
            return i;
    }
    
    return -1;
}


function format_resource( qt )
{
    if(!qt)
        return '-';

	if( Math.abs( qt ) < 1000 )
	{
	    if( qt == 0 )
	        return '-';
	    else
		    return "<i>"+qt+" kg</i>";
    }
	else
	{
	    if( Math.abs( qt ) < 10000 )
			return ( Math.floor(qt/100)/10 )+" T";
        else
            return  Math.floor( qt/1000 )+" T";
    }
}


var showlightbox_callback = 
{ 
  success: function(o)
    { 
        document.getElementById('lightbox_popup').innerHTML = o.responseText; 
    },
  failure: function(o){ document.getElementById('lightbox_popup').innerHTML = "Error"; }
};
	
function showlightbox( page, withiframe )
{
    // Show overall mask
    document.getElementById( "overall_mask" ).style.display = "block";
    var anim = new YAHOO.util.Anim("overall_mask",  { opacity: { from: 0, to: 0.5 } }, 0.5 ); 
    anim.animate();
 
    
    // Show lightbox
    var lightbox = document.getElementById( "lightbox" );
    var lightbox_popup = document.getElementById( "lightbox_popup" );
    var lightbox_popup_iframe = document.getElementById( "lightbox_popup_iframe" );
    lightbox.style.display = "block";

    if( withiframe )
    {
        lightbox_popup_iframe.style.display = "block";
        lightbox_popup_iframe.contentWindow.document.body.innerHTML = "<html><body><div style='width:100%;height:100%;background-color: white;'><img style='position: absolute;left: 45%;top:45%;width:40px;height:40px;' src='http://game.littlebigsociety.com/theme/img/layout/wait.gif' /></div></body></html>";
        lightbox_popup_iframe.src = page; 
    }
    else
    {
        lightbox_popup.innerHTML = "<img src='/theme/img/layout/wait.gif' alt='wait'/>";

        var request = YAHOO.util.Connect.asyncRequest("GET", page, showlightbox_callback); 
    }
}

function help( id )
{
    showlightbox( "http://fr.littlebigsociety.com/book/export/html/" + id );
}

function closehelp()
{
    // Hide overall mask
    document.getElementById( "overall_mask" ).style.display = "none";
    
    // Hide lightbox
    var lightbox = document.getElementById( "lightbox" );
    var lightbox_popup = document.getElementById( "lightbox_popup" );
    var lightbox_popup_iframe = document.getElementById( "lightbox_popup_iframe" );
    if( lightbox_popup_iframe )
    {
        lightbox_popup_iframe.src = '';
    }
    lightbox.style.display = "none";
}

var current_help = '';

function sethelp( id )
{
    var msg = getContextHelpMsg( id );
    if(typeof(msg)=='undefined'){ 
        document.getElementById( "contextual_help_msg" ).innerHTML = id;
    }
    else
    {
        document.getElementById( "contextual_help_msg" ).innerHTML = msg;
    }
}
function hh( )
{
    document.getElementById( "contextual_help_msg" ).innerHTML = "";
}

function lbstogglemenu( submenu_name, button )
{
    var submenu = document.getElementById( submenu_name );
    var submenumini = document.getElementById( submenu_name + "_mini" );
    if( submenu.style.display=='none' )
    {
        submenu.style.display = 'block';
        submenumini.style.display = 'none';
        button.innerHTML='-';
    }
    else
    {
        submenu.style.display = 'none';    
        submenumini.style.display = 'block';
        button.innerHTML='+';
    }
}


