$(function(){
    // Dialog            
    $('#dialog').dialog({
        autoOpen: false,
        buttons: { 
            "Fermer": function() { 
                $(this).dialog("close"); 
            } 
        }
    });
                    
    // Dialog Link
    $('#dialog_link').click(function(){
        $('#dialog').dialog('open');
        return false;
    });
    
    $(".myDatePicker").datepicker({
        monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
        dayNamesMin:  ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
        dateFormat: 'dd/mm/yy'
    });
    
//all hover and click logic for buttons
        $(".fg-button:not(.ui-state-disabled)")
        .hover(
            function(){ 
                $(this).addClass("ui-state-hover"); 
            },
            function(){ 
                $(this).removeClass("ui-state-hover"); 
            }
        )
        .mousedown(function(){
                $(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
                if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
                else { $(this).addClass("ui-state-active"); }    
        })
        .mouseup(function(){
            if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
                $(this).removeClass("ui-state-active");
            }
        });
});


function Aide(messageHTML) {
    document.getElementById('dialog').innerHTML = messageHTML;
    $('#dialog').dialog('open');
    return false;      
}

function AideZoom(messageHTML,width,height) {
    document.getElementById('dialog').innerHTML = messageHTML;
    $('#dialog').dialog('option', 'width', width);
    $('#dialog').dialog('option', 'height', height);
    $('#dialog').dialog('option', 'title', 'Zoom'); 
    $('#dialog').dialog('open');
    return false;      
}


//2011-09-30 L'emploi de basehref pose problème avec les ancres interne.
//Il faut donc modifier l'url des ancre interne, pour rajouter l'url de la page en cours.
function repairLink2Anchor(){
	// exists tag BASE3.
	if ($("base").length)
	{
		// regular expression for anchor link
		var re1 = /#([\w-]+)/; // anchor parts
		var re2 = /^#([\w-]+)/; // only anchor
		// read current url
		var thisUrl = document.location.href;
		// remove anchor from current url
		thisUrl=thisUrl.replace(re1,"");
		// inicialization
		var href = '';
		var anchor = '';
		// loop all A tags whith attribute href
		$("a[href]").each(function(){
			href = $(this).attr("href");
		    // check - href is anchor?
		    if (re2.test(href))
		    {
		    	anchor = href.match(re2);
		        $(this).attr("href", thisUrl + '#' + anchor[1]);
		    }
		});
	}
}
$(document).ready(function() {repairLink2Anchor();});
