// Gestion des onglets
$(document).ready(function() {
	$('#onglets').tabs({selected:0, fx:{opacity:"toggle"}});
  $('a.lightbox').lightBox();
});

// cf www.acces-pour-tous.net
var newWin = null;
function closeWin(){
  if (newWin != null){
    if(!newWin.closed)
      newWin.close();
  }
}

function popUp(strURL,strType,strWidth,strHeight) {
  closeWin();
  var strOptions="";
  if (strType=="console")
    strOptions="resizable,height="+strHeight+",width="+strWidth;
  if (strType=="fixed")
    strOptions="status,height="+strHeight+",width="+strWidth;
  if (strType=="elastic")
    strOptions="scrollbars,resizable,height="+strHeight+",width="+strWidth;
  if (strType=="elastic2")
    strOptions="location,scrollbars,resizable,height="+strHeight+",width="+strWidth;   
  newWin = window.open(strURL, 'newWin', strOptions);
  newWin.focus();
}

function popupcentree(page,largeur,hauteur,options)

{

var top=(screen.height-hauteur)/2;

var left=(screen.width-largeur)/2;

window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);

}

function redirect(formulaire)
{
//alert(URL);
popUp(formulaire.url.options[formulaire.url.selectedIndex].value,'elastic',670,600)
}

// Autosuggest 

$().ready(function() {
	
	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	
	$("#collectivite").autocomplete("/cdg33/suggest/", {
			width: 350,
			selectFirst: false
		});
	$("#collectivite").result(function(event, data, formatted) {
		if (data)
			$(this).parent().next().find("input").val(data[1]);
						var obj = document.getElementById( 'collectivite' );;
            while (obj.tagName != "FORM" && obj.tagName != "body") {
							obj = obj.parentNode;
						}
						if(obj.tagName != "body")
						{
							obj.submit();
						} 
	});
	
});

//function lookup(inputString) {
//    if(inputString.length == 0) {
//        // Hide the suggestion box.
//        $('#suggestions').hide();
//    } else {
//        $.post("/cdg33/suggest/", {queryString: ""+inputString+""}, function(data){
//            if(data.length >0) {
//                $('#suggestions').show();
//                $('#autoSuggestionsList').html(data);
//            }
//        });
//    }
//} // lookup
//
//function fill(thisValue) {
//    $('#inputString').val(thisValue);
//   $('#suggestions').hide();
//}
