// JavaScript Document

function affich_recherche(){
//	alert ("ss");
	Element.setStyle("cherche_met", {background: 'white'});
	$("cherche_met_cont").innerHTML = "";
	
	if($("cherche_site").style.display=="")Effect.SlideUp('cherche_site',{duration:0.5});
	else if($("cherche_met").style.display=="")Effect.SlideUp('cherche_met',{duration:0.5});
	else Effect.toggle('cherche_form_menu','slide',{duration:0.4});
	
	if ( cherche_navigateur() == "IE" ) {
	$("Id_secteur").style.display = "inline";
		if ( $("Form_Catalogue_home") ) {
			$("Form_Catalogue_home").style.display = "inline";
		}	
	}
	/*if ( $("pub_partner") ) {
		$("pub_partner").style.display = "inline";
	}	*/
	//Effect.toggle('cherche_form_menu','appear',{duration:0.15});
	//
	//Effect.SlideDown('cherche_form_menu',{ duration: 0.5 });
	
}

function affich_recherche_index(num){
	
	Effect.toggle("cherche_form_indx_"+num,'blind',{duration:0.3});
}


function affiche_rech_site(){	

	if ( cherche_navigateur() == "IE" ) {
		$("Id_secteur").style.display = "none";
		if ( $("Form_Catalogue_home") ) {
			$("Form_Catalogue_home").style.display = "none";
		}
	}
	/*if ( $("pub_partner") ) { 
		if ( $("pub_partner").style.display == "" || $("pub_partner").style.display == "inline" ) {
			$("pub_partner").style.display = "none";
		}	
		else if ( $("pub_partner").style.display == "none" ) {
			$("pub_partner").style.display = "inline";
		}
	}*/

	if($("cherche_form_menu").style.display!="")Effect.SlideUp('cherche_form_menu',{duration:0.5});
	Effect.toggle('cherche_site','slide',{duration:0.5});
	if($("cherche_form_catal").style.display!="none")Effect.SlideUp('cherche_form_catal',{duration:0.5});
	setTimeout("Google_Search_API()",500);
}

function affiche_rech_site_home(){
	if ( cherche_navigateur() == "IE" ) {	
		if ( $("Form_Catalogue_home").style.display == "" || $("Form_Catalogue_home").style.display == "inline" ) {
			$("Id_secteur").style.display = "none";
			$("Form_Catalogue_home").style.display = "none";
		}	
		else if ( $("Form_Catalogue_home").style.display == "none" ) {
			$("Form_Catalogue_home").style.display = "inline";		
		}
	}
	
	/*if ( $("pub_partner") ) { 
		if ( $("pub_partner").style.display == "" || $("pub_partner").style.display == "inline" ) {
			$("pub_partner").style.display = "none";
		}	
		else if ( $("pub_partner").style.display == "none" ) {
			$("pub_partner").style.display = "inline";
		}
	}*/
	
	Effect.toggle('cherche_site','slide',{duration:0.5});
	if($("cherche_form_catal").style.display!="none")Effect.SlideUp('cherche_form_catal',{duration:0.5});
	setTimeout("Google_Search_API()",500);;
	
	if($("cherche_form_catal_home").style.display!="none")Effect.SlideUp('cherche_form_catal_home',{duration:0.5});
	
}

function affiche_rech_catal(){
	if($("cherche_form_catal").style.display!="")Effect.SlideDown('cherche_form_catal',{duration:0.5});
	
}

function affiche_rech_catal_home(){
	if($("cherche_site").style.display!="none")Effect.SlideUp('cherche_site',{duration:0.5});
	if($("cherche_form_catal_home").style.display!="")Effect.SlideDown('cherche_form_catal_home',{duration:0.5});
	if ( cherche_navigateur() == "IE" ) {
		$("Id_secteur").style.display = "inline";
		if ( $("Form_Catalogue_home") ) {
			$("Form_Catalogue_home").style.display = "inline";
		}	
	}
/*	if ( $("pub_partner") ) {
		$("pub_partner").style.display = "inline";
	}*/

}

function affiche_rech_met(){
	
	if($("cherche_form_menu").style.display!="")Effect.SlideUp('cherche_form_menu',{duration:0.5});
	Effect.toggle('cherche_met','slide',{duration:0.5});
	init_cherche_met_cont();
	setTimeout("affiche_swf_met()",500);
	
}

function init_cherche_met_cont(){

	Element.setStyle('cherche_met', {background: '50% 50% url(/images/waiting.gif) no-repeat white' });
	//alert($('cherche_met_cont').style.background);
	
}

function affiche_swf_met(){

	var div_flash = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"800\" height=\"529\" title=\"Metier\">";
		div_flash += "<param id=\"param_swf_met\" name=\"param_swf_met\" value=\"/appli/metier_01.swf?typePresentation=intra\" />";
		div_flash += "<param name=\"quality\" value=\"high\" />";
		div_flash += "<embed id=\"embed_swf_met\" src=\"/appli/metier_01.swf?typePresentation=intra\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"800\" height=\"529\"></embed>";
		div_flash += "</object>";

	$("cherche_met_cont").innerHTML = div_flash;

}

var siteSearch;
var searchControl;
function Google_Search_API() {
	
	// Create a search control
	searchControl = new GSearchControl();
	options = new GsearcherOptions();
	
	siteSearch = new GwebSearch();
	siteSearch.setUserDefinedLabel("nextformation.com");
	siteSearch.setUserDefinedClassSuffix("siteSearch");
	siteSearch.setSiteRestriction("nextformation.com");
	options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
	searchControl.addSearcher(siteSearch, options);
	
	// setting the draw mode for the Google search
	var drawOptions = new GdrawOptions();

	// set the input field (instead of the default one)
	drawOptions.setInput(document.getElementById('query'));
	// actually write the needed markup to the page
	searchControl.draw(document.getElementById("searchcontrol"), drawOptions);


	/**/
	// set the google logo container
	 GSearch.getBranding(document.getElementById("branding"));
	
	// Tell the searcher to draw itself and tell it where to attach
//	searchControl.draw(document.getElementById("searchcontrol"));
	searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
	

	
	siteSearch.setSearchCompleteCallback(null, OnWebSearch);
	// Execute an inital search
	searchControl.execute("");

}

function OnWebSearch() {
  if (!siteSearch.results) return;
  var searchresults = document.getElementById("searchresults");
  searchresults.innerHTML = "";
	
  if ( siteSearch.results.length == 0) 
	{ 	var results = "Les termes de recherche sp&eacute;cifi&eacute;s ne correspondent &agrave; aucun document."; }
  else if  ( siteSearch.results.length == 1) 
	{	var results = "R&eacute;sultat de la recherche:<br>"; }
  else 	
	{ var results = "R&eacute;sultats de la recherche:<br>"; }
  
  for (var i = 0; i < siteSearch.results.length; i++) {
	var thisResult = siteSearch.results[i];
	results += "<p>";
	results += "<a href=\"" + thisResult.unescapedUrl  + "\" target=\"_blank\">" + thisResult.title + "<\/a><br \/>";
	results += thisResult.content + "<br \/>";
  /*    results += "<span class=\"url\">" + thisResult.url + "<\/span>";
  if (thisResult.cacheUrl) {
		results += " - <a class=\"cached\" href=\"" + thisResult.cacheUrl + "\">Cached <\/a>";
	}*/
	
	results += "<\/p>";
  }
 var query = document.getElementById('query').value;
 /*document.gsc-search-box.search.value);*/
 
  if ( siteSearch.results.length == 8) {
	  results += "<div class='gsc-trailing-more-results'><a target='_blank' class='gsc-trailing-more-results' href='http://www.google.com/search?hl=fr&source=uds&q="+query+"+site%3Anextformation.com&start=9&filter=0'>Autres r&eacute;sultats&nbsp;&gt;&gt;</a></div>";
  }		  
  searchresults.innerHTML = results;
}