//some tools
$(document).ready(
	//function used to to clean all level2 navigations with out elements
	function(){
		var className = 'level2';
		var container  = document.getElementById('mainNav');
		var elems = container.getElementsByTagName('ul');
		for(var i=0; i<elems.length; i++){
		    //console.log(elems.length);
		    if(elems[i].className == className){
		        //check if the current level has childrem
		        var test = elems[i].getElementsByTagName('li')
		        if(test.length == 0){
		             
		            //console.log($(elems[i]))
		            $(elems[i]).remove();
			    //init the counter 
			    i = 0;	
		        }
		    }
		}
	}
);



// ================================================
// -- tools for autocompletion
// ================================================
var autocompleteOptions;

// initialise plugins
jQuery(function(){
    //set the default value for the search inpu
    
    $('#search')[0].value = searchLabel; 

    //set the autocomplete options
    autocompleteOptions = { 
        serviceUrl:'./globalgolftime.php?p='+currentLanguage+',,,39.77,,,'
        ,minChars:3
        ,width:350
        ,onSelect: function(value, data){ 
            document.location = './globalgolftime.php?p='+currentLanguage+','+data+',,,,,';
        }
    };
    $('#search').autocomplete(autocompleteOptions);
    
    
    //clean the field only if it is different from the search label
	$('#search').focus(function() {
	  if($('#search')[0].value==searchLabel){
          $('#search')[0].value = '';
	  }  
	});    
    
});


