function fenetre()
{
			var viewportwidth;
			 var viewportheight;
			 
			 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
			 
			 if (typeof window.innerWidth != 'undefined')
			 {
				  viewportwidth = window.innerWidth,
				  viewportheight = window.innerHeight
			 }
			 
			// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
			
			 else if (typeof document.documentElement != 'undefined'
				 && typeof document.documentElement.clientWidth !=
				 'undefined' && document.documentElement.clientWidth != 0)
			 {
				   viewportwidth = document.documentElement.clientWidth,
				   viewportheight = document.documentElement.clientHeight
			 }
			 
			 // older versions of IE
			 
			 else
			 {
				   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
				   viewportheight = document.getElementsByTagName('body')[0].clientHeight
			 }
			 
			 this.height = viewportheight
			 this.width =  viewportwidth 
}


function demarrage()
{
	
	$$(' .controle').each(
							function (p)
							{
								Event.observe($(p.id),'change',coherence.bindAsEventListener($(p.id), p.id) );
							}
	                     );
	//cas des controles inadaptés à l'évènement change...
	$$(' .controle2').each(
							function (p)
							{
								Event.observe($(p.id),'click',coherence.bindAsEventListener($(p.id), p.id) );
							}
	                     );
	
	/*$$(' .validation').each(
						   	function(p)
							
							{
								Event.observe($(p.id),'click',find_and_show.bindAsEventListener(p, p.id) );
							}
						   );*/
	$$(' .form_off').each(
					function (p)
					{
							Event.observe( $(p.id),'submit', find_and_show, false );
					}
				);
}

function coherence(obj, id)
{
//	alert($F(id));
	
	var data = $H({'provenance':'moteur_offre','objet' : id, 'valeur':$F(id)}).toQueryString();
	if ( id== 'filiere') data = $H({'provenance':'moteur_offre','objet' : id, 'valeur':$F(id),'categorie':$F('categorie') }).toQueryString();
	if ( id== 'cadreemploi') data = $H({'provenance':'moteur_offre','objet' : id, 'valeur':$F(id),'categorie':$F('categorie'),'filiere':$F('filiere') }).toQueryString();
	if ( id== 'grade') data = $H({'provenance':'moteur_offre','objet' : id, 'valeur':$F(id),'categorie':$F('categorie'),'filiere':$F('filiere'),'cadreemploi':$F('cadreemploi') }).toQueryString();
	
	new Ajax.Updater(
					 'form_off',
					 '/Traitements/ajax.asp',
					 {
						 postBody:data,
						 insertion:Insertion.Bottom,
						 evalScripts:true
					 }
					 );
	
	
	/*
	if (id == "categorie")
	{
		var data = $H({'objet' : id, valeur:}).toQueryString()
	}
	if (id == "filiere")
	{
		var data = $H({}).toQueryString()
	}
	if (id == "cadreemploi")
	{
		var data = $H({}).toQueryString()
	}
	if (id == "grade")
	{
		var data = $H({}).toQueryString()
	}*/
}
function positionnement( id )
{
	//$(id).value="2";
	alert($F(id) + 'c\'est le positionnement');
	
}
function summup()
{
	
	var data = $H({'provenance':'moteur_offre','objet' :'summup','categorie':$F('categorie'),'filiere':$F('filiere'),'cadreemploi':$F('cadreemploi'),'grade':$F('grade'),'secteur':$F('secteur'),'typecoll':$F('typecoll'),'localisation':$F('localisation'),'motcle':$F('motcle'),'tps_complet':$F('tps_complet') }).toQueryString();
	
	new Ajax.Updater(
					 'form_off',
					 '/Traitements/ajax.asp',
					 {
						 postBody:data,
						 insertion:Insertion.Bottom,
						 evalScripts:true
					 }
					 );
}

function find_and_show(e)
{
	// On détermine l'origine de l'evt pour un paramétrage adapté : si on appelle la fonctiondepuis les éléments de navigation, il faut ajuster les index...
	source= Event.element(e);
	if (source.className =="navigation") index_aff=source.id.gsub("record_","")<0 ? 0 : source.id.gsub("record_","");
	if (source.className =="form_off")   index_aff=0;
	Event.stop(e);
	
	$$('.resultat').each
	(
		function(p)
		{
			Element.remove($(p.id) );
		}
	)
	//ainsi que la barre de navigation précédente
	//if ($('nav_bar')) Element.remove( $('nav_bar') );
	//On patiente en attendant le résultat...
	var waitstyle =" height:"+ $('general').getHeight().toString() + "; width :"+ $('general').getWidth().toString();
	new Insertion.Top('resultats','<div id="patienter"><h3>Patienter...</h3></div>');
	
	
//	Ecran
	//1 - Dimensions de la fenêtre...
	var fen= new fenetre();
	

	
	if ($('patienter'))
	  $('patienter').setStyle({
							  	height:(fen.height*1.1).toString()+'px',
	  							width:'760px',
								opacity:0.85});
	  //width:(fen.width).toString()+'px',
	 //cas spécial pour MSIE6 pour lequel les selects sont au dessus de tt!!
	masquer_controles();
	  
	
	//alert(waitstyle);
	var data = $H({'provenance':'moteur_offre','objet' :'findandshow','categorie':$F('categorie'),'filiere':$F('filiere'),'cadreemploi':$F('cadreemploi'),'grade':$F('grade'),'secteur':$F('secteur'),'typecoll':$F('typecoll'),'localisation':$F('localisation'),'motcle':$F('motcle'),'tps_complet':$F('tps_complet'),'nb_resul':nb_resul,'nb_aff':nb_aff,'index_aff':index_aff}).toQueryString();
	
	//alert(data);
	
	new Ajax.Updater(
					 'resultats',
					 '/Traitements/ajax.asp',
					 {
						 postBody:data,
						 insertion:Insertion.Bottom,
						 evalScripts:true
					 }
					 );
	
	//return false; //pour stopper la propagation de l'evt...
}

function show_me_an_offer(e)
{
	source= Event.element(e);
	
	
	id=source.id.gsub("off_","");
	
//	alert('qui je suis...? aucune idée, mais je veux bien te montrer l\'offre'+ id);
	
	// on supprime les offres anciennement affichées...
	hide_offer()
	//Cas particulier des sélects...
	masquer_controles();
	new Insertion.Top('resultats', '<div id="Sannonce_'+id+'" class="annonce" ></div>')
	
	var fen= new fenetre();
	
	$('Sannonce_'+id).setStyle({
							  	height:(fen.height*3.7).toString() +'px',
								width : '760px',
								opacity:1});
	//width : fen.width.toString()+'px',
	
	data =$H({'provenance':'moteur_offre','objet':'display_offer','offre': id,'motcle':$F('motcle')}).toQueryString();
	
	new Ajax.Updater(
					 'resultats',
					 '/Traitements/ajax.asp',
					 {
						 postBody:data,
						 insertion:Insertion.Bottom,
						 evalScripts:true
					 }
					 );
	
}

function hide_offer()
{
	var ident =null;
	//On affiche les controes masqués durant le temps d'attente...
	demasquer_controles();
	
	
	 $$('.annonce').each(
						 	function (p)
							{
								ident = p.id.gsub("Sannonce_","");
								Element.remove($(p.id));
							}
				
						 );

	// alert(ident);
	 if(ident)
		{
			//document.location=document.location + "annonce_" + ident;
			Element.scrollTo('annonce_'+ident);
			Element.removeClassName($('off_'+ident),'show_me');
			Element.addClassName($('off_'+ident),'shown_me');
			
		}
		
		
}
function masquer_controles()
{
	$('categorie', 'grade', 'filiere','secteur','typecoll','grade','localisation','cadreemploi').each(
																							function(p)
																							{
																								p.addClassName('invisible');
																							}
																						);
	if ($('menu')) $('menu').addClassName('invisible');
	if ($('pied')) $('pied').addClassName('invisible');
	/*Element.addClassName($('categorie'),'invisible');
	Element.addClassName($('filiere'),'invisible');
	Element.addClassName($('secteur'),'invisible');
	Element.addClassName($('typecoll'),'invisible');
	Element.addClassName($('typecoll'),'invisible');
	Element.addClassName($('typecoll'),'invisible');*/
}
function demasquer_controles()
{
	
	$('categorie', 'grade', 'filiere','secteur','typecoll','grade','localisation','cadreemploi').each(
																							function(p)
																							{
																								p.removeClassName('invisible');
																							}
																						);
	if ($('menu')) $('menu').removeClassName('invisible');
	if ($('pied')) $('pied').removeClassName('invisible');
}


function PSR_imprimer (e)
{
	source= Event.element(e)
	id = "corps_"+ source.id.gsub("print_","");
 	var PSR_f1 = null;
 	var PSR_content=document.getElementById(id).innerHTML;
 	var PSR_title=document.getElementsByTagName('title')[0].innerText;
 	if (PSR_f1) {if(!PSR_f1.closed) PSR_f1.close();}
 	PSR_f1 = window.open ('',"PSR_f1", "height=500,width=600,menubar=yes,scrollbars=yes,resizable=yes,,left=10,top=10"); ;
 	PSR_f1.document.open();
 	PSR_f1.document.write("<html><head><title>" + PSR_title + "</title><link type='text/css' rel='stylesheet' media='all' href='/Styles/offre_imp.css' /></head><body bgcolor='#ffffff'>"+PSR_content+"</body></html>");
 	PSR_f1.document.close();
	PSR_f1.print();
	PSR_f1.close();
	//PSR_f1.document.getElementById(id).style.visibility='hidden';
 	PSR_f1.focus();
} 

Event.observe(window,'load',demarrage, false);