// Loading
var loading = '<img src ="/src/icons/zak/loading.gif" alt="Chargement..." />';
//var loading2 = '<img class="loading" src="/images/loading-black.gif" alt="Chargement..." />';

$(document).ready( function() 
{   
    /* Supprimer les pointillé sur btn submit */
    $("input[type=submit]").focus(function(){  $(this).blur();});
    $("input[type=button]").focus(function(){  $(this).blur();});
    $("input[type=image]").focus(function(){  $(this).blur();});
    
    /* Mon compte (HEADER) */
    $('.aCompte').click( function( e )
    {
        e.stopPropagation();
        $( '#divFormCompte' ).show();
    });
    
    /* Bookmark */
    addBookmark();
    
    /* Bookmark */
    //addHomePage();
    
    /*function()
    {
        $("input[@name='searchTerm']").change
        (
            function()
            {
                $("#form-search").attr("action",$(this).val());
            }
        );
    }*/
    
    /*var myArray = getWindowSize();
    var myWidth = myArray[0];
    var myHeight = myArray[1];
    
    //document.write('<p>'+ myWidth +'</p>');
    //document.write('<p>'+ myHeight +'</p>');
    
    $("div.body-left").attr({ 
      style: "min-height: "+myHeight+"px;"
    });
    $("div.body-bottom").attr({ 
      style: "min-height: "+myHeight+"px;"
    });
    $("div.body-center").attr({ 
      style: "min-height: "+myHeight+"px;"
    });
    
    alertSize();
    */
    
    /*$("div.body-left").attr({ 
      style: "min-height: 50px;"
    });
    $("div.body-right").attr({ 
      style: "min-height: 60px;"
    });
    $("div.body-center").attr({ 
      style: "min-height: 70px;"
    });*/
    
    /*var ul_0 = $("p:first".innerHeight();
    $("p:last").text( "innerHeight:" + p.innerHeight() );*/
    
    // Edit top of ul (via height of ul)
    var ul_0 = $("ul.ul-level-2_0").innerHeight()+1;
    $("ul.ul-level-2_0").attr({ 
      style: "top: -"+ul_0+"px;"
    });
    
    var ul_1 = $("ul.ul-level-2_1").innerHeight()+1;
    $("ul.ul-level-2_1").attr({ 
      style: "top: -"+ul_1+"px;"
    });
    
    var ul_2 = $("ul.ul-level-2_2").innerHeight()+1;
    $("ul.ul-level-2_2").attr({ 
      style: "top: -"+ul_2+"px;"
    });
    
    var ul_3 = $("ul.ul-level-2_3").innerHeight()+1;
    $("ul.ul-level-2_3").attr({ 
      style: "top: -"+ul_3+"px;"
    });
    
    var ul_4 = $("ul.ul-level-2_4").innerHeight()+1;
    $("ul.ul-level-2_4").attr({ 
      style: "top: -"+ul_4+"px;"
    });
    
    // Edit search bar (content) input width's 
    var searchBar_width = $("div.bar-search-content").innerWidth()-170; // div = (btn submit = 156, padding-left = 14 : => 170px)
    var searchBarInput_width = searchBar_width-26;                      // input = padding input = 12x2 + border = 1x2 : => 26px
    //alert(searchBar_width);
    
    $("div.field-search").attr({ 
      style: "width: "+searchBar_width+"px;"
    });
    $("div.field-search > input").attr({ 
      style: "width: "+searchBarInput_width+"px;"
    });
});

/* Mon compte (HEADER) */
$( document ).dblclick( function( e )
{
    if( !$(e.target).parent().parent().is( '#formCompteHeader' ) )
        $( '#divFormCompte' ).hide();
} )

function resolution()
{
    alert(
        "Vous etes en résolution : "+screen.width+"*"+screen.height
        
        +"\nTaille d'écran disponible : "+screen.availWidth+"*"+screen.availHeight
        
        +"\nPalette de couleurs : "+screen.colorDepth+" bits"
    );
}

function alertSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

//-----------------
//--  BOOKMARKS
//-----------------
function addBookmark()
{
    // add a "rel" attrib if Opera 7+
    if(window.opera)
    {
        if ($("a.jqbookmark").attr("rel") != "") { // don't overwrite the rel attrib if already set
            $("a.jqbookmark").attr("rel","sidebar");
        }
    }
   
    $("a.jqbookmark").click(function(event)
    {
        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
        var url = this.href;
        var title = this.title;
       
        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(title, url, "");
        } else if( window.external ) { // IE Favorite
            window.external.AddFavorite( url, title);
        } else if(window.opera) { // Opera 7+
            return false; // do nothing - the rel="sidebar" should do the trick
        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
            alert('Unfortunately, this browser does not support the requested action, please bookmark this page manually.');
        }
    });
}

//----------------------
//--  ADD to HOME PAGE
//----------------------
function addHomePage( url )
{
    this.style.behavior='url(#default#homepage)';this.setHomePage(url);
}

/**
 * http://forums.asp.net/t/1279376.aspx/1
 * 
 * Based on my experience, we cannot set the home page of Firefox, if the browser set
 * signed.applets.codebase_principal_support
 * to false, the only thing we can do is remind use to change the setting. You can try the following code, both for IE and Firefox: 
 */
function setHomepage( url )
{
     if (document.all)
     {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage( url );
     }
     else if (window.sidebar)
     {
        if(window.netscape)
        {
            try
            {  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }  
            catch(e)  
            {  
                alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
            }
        }
        
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', url);
     }
}


function getWindowSize()
{
    var myWidth = 0;
    var myHeight = 0;
    var myArray = new Array(2);
  
  //Non-IE
  if( typeof( window.innerWidth ) == 'number' )
  {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }
  //IE 6+ in 'standards compliant mode'
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  {
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }
  //IE 4 compatible
  /*else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
  {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }*/
  
    myArray[0] = myWidth; // Width
    myArray[1] = myHeight; // Height
  
    return myArray;
}

function getWindowWidth()
{
    var myArray = getWindowSize();
    
    return myArray[0];
}

function getWindowHeight()
{
    var myArray = getWindowSize();
    
    return myArray[1];
}
