//-----------------------------------------------------------------------
// lib_EG.js
//
// Javascript ISEC - France
// 
//
// Version 0.0  ---  Date: 07/05/2007
//-----------------------------------------------------------------------


//=======================================================================
//
// NB: Les variables "contenu" sont d2finies dans "data_ISEC.js" file
//
//-----------------------------------------------------------------------




//===========================================================
//
//               Definition of parameters
//
//                        ******
//
//                 Modify with care! :)
// 
//-----------------------------------------------------------



//===========================================================
// Location of the graphics:
//-----------------------------------------------------------
var graphics_path = "graphics/";


//===========================================================
// Top image definition:
//-----------------------------------------------------------
var top_image = ['top_ISEC_Fr.jpg'];

var top_image_current = 0;


//===========================================================
// Menu items definition:
//-----------------------------------------------------------

var nav_id =    ['home', 'apropos', 'actions', 'ressources', 'contact'];

var nav_src=    ['home.html', 'apropos.html', 'actions.html', 'ressources.html', 'contact.html'];

var nav_title = ['home', 'apropos', 'actions', 'ressources', 'contact']; 


 
var N_navbar = nav_id.length;

//---- NB: graphics: nav_id[i] + '_off.gif' / '_over.gif' / +'_selected.gif'  
















//===========================================================
//               Definition of subroutines
//
//                        ******
//
//                 Modify with care! :)
// 
//-----------------------------------------------------------






//-----------------------------------------------------------
// 			TOP IMAGE
//-----------------------------------------------------------
function html_for_top(){

	var t = '';
		
	t+= '<img src="'+graphics_path + top_image[ top_image_current ]+'" >';


	document.write( t );

}

//-----------------------------------------------------------
// 			MENU 
//-----------------------------------------------------------
function html_for_menu(current_page){

	var t= '<table width=814 bgcolor="#ffffff" cellspacing=0 cellpadding=0 border=0 align=left valign=top><tr>' ;

	t+= '	<td><img src="'+graphics_path+'menu_left.jpg"></td>';


	//--------------------------------------------------

	t+= '	<td ><table cellspacing=0 cellpadding=0 border=0  align=left valign=top><tr>';
	
	for(i=0;i<N_navbar;i++){
		if (current_page == nav_id[i]){
			t+= ' 	<td><img src='+graphics_path+nav_id[i]+'_over.jpg></td> ';
		}else{
			t+= ' 	<td><a href="'+nav_src[i]+'"><img src='+graphics_path+nav_id[i]+'_off.jpg onmouseout="this.src=\''+graphics_path+nav_id[i]+'_off.jpg\'"  onmouseover="this.src=\''+graphics_path+nav_id[i]+'_over.jpg\'" border=0></a></td> ';
		}
	}

	t+= '	<td><img src="'+graphics_path+'menu_right.jpg"  height=30></td>';

	t+= '	</tr></table></td>';


	t+= '	</tr><tr><td colspan=9 height=17 width=100%><img src='+graphics_path+'menu_separateur.jpg height=17 width=100%></td>';

	t+= '	</tr></table>';

	document.write( t );
}





//-----------------------------------------------------------
// 			HOME AGENDA BOX
//-----------------------------------------------------------
function html_for_home_agenda(){

	var agenda_width = '270';
	var nb_items = 3;

	if(agenda.length<3){nb_items=agenda.length}
	if(agenda.length==0){return;}

	var t= '';

			
	t+= '		<table cellspacing=0 cellpadding=0 border=0 align=left>';
	t+= '		<tr>';
	t+= '			<td><img src='+graphics_path+'agenda_tl.jpg></td>';
	t+= '			<td width=100%><img src='+graphics_path+'agenda_top.jpg width=100% height=14></td>';
	t+= '			<td><img src='+graphics_path+'agenda_tr.jpg></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td height=100%><img src='+graphics_path+'agenda_left.jpg width=15 height=100%></td>';
	t+= '			<td background="'+graphics_path+'agenda_bg.jpg" align=middle><img src='+graphics_path+'agenda_title.jpg></td>';
	t+= '			<td height=100%><img src='+graphics_path+'agenda_right.jpg width=18 height=100%></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td height=100%><img src='+graphics_path+'agenda_left.jpg width=15 height=100%></td>';
	t+= '			<td background="'+graphics_path+'agenda_bg.jpg" width='+agenda_width+' style="padding:\'8px 0px 0px 0px\';">';

	t+= '			<table width=100% background="'+graphics_path+'agenda_bg.jpg" cellspacing=0 cellpadding=0 border=0 align=left>';

	for(i=0; i<nb_items; i++){
		t+= '			<tr>';
		t+= '				<td width=100% align=left style="padding:\'0px 0px 0px 12px\';"><b>'+agenda[i][0]+':&nbsp;</b>'+agenda[i][1]+'</td>';
		t+= '			</tr>';				
		
		if(i<nb_items-1){
			t+= '			<tr>';
			t+= '				<td height=35 width=100% align=middle valign=center><img src='+graphics_path+'agenda_separator.jpg></td>';
			t+= '			</tr>';
		}
	}

	t+= '			</table>';

	t+= '			</td>';
	t+= '			<td height=100%><img src='+graphics_path+'agenda_right.jpg width=18 height=100%></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td height=100%><img src='+graphics_path+'agenda_left.jpg width=15 height=100%></td>';
	t+= '			<td background="'+graphics_path+'agenda_bg.jpg" align=right><a href="agenda.html"><img src='+graphics_path+'agenda_more_off.jpg></a></td>';
	t+= '			<td height=100%><img src='+graphics_path+'agenda_right.jpg width=18 height=100%></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td><img src='+graphics_path+'agenda_bl.jpg></td>';
	t+= '			<td  width=100%><img src='+graphics_path+'agenda_bottom.jpg width=100% height=19></td>';
	t+= '			<td><img src='+graphics_path+'agenda_br.jpg></td>';
	t+= '		</tr>';
	t+= '		</table>';



//  	for(i=0;i<nb_items;i++){  
//    		t+= ' </tr><tr>';
//   		t+= '    <td  style="padding:\' 2px 0px 0px 13px \';" >&bull;</td>';
//    		t+= '    <td  align=left><a href="'+agenda[i]+'">'+latest_add[i]+'</a></td>';
//    		t+= ' </tr><tr>'; 
//	}

	
	document.write( t );
}


//-----------------------------------------------------------
// 			JOIN THE EG BOX
//-----------------------------------------------------------
function html_for_join(){

	var join_width = '270';

	var t= '';
			
	t+= '		<table cellspacing=0 cellpadding=0 border=0 align=left>';
	t+= '		<tr>';
	t+= '			<td><img src='+graphics_path+'join_tl.jpg></td>';
	t+= '			<td width=100%><img src='+graphics_path+'join_top.jpg width=100% height=16></td>';
	t+= '			<td><img src='+graphics_path+'join_tr.jpg></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td height=100%><img src='+graphics_path+'join_left.jpg width=15 height=100%></td>';
	t+= '			<td background="'+graphics_path+'join_bg.jpg" align=middle><img src='+graphics_path+'join_title.jpg></td>';
	t+= '			<td height=100%><img src='+graphics_path+'join_right.jpg width=18 height=100%></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td height=100%><img src='+graphics_path+'join_left.jpg width=15 height=100%></td>';
	t+= '			<td background="'+graphics_path+'join_bg.jpg" width='+join_width+'>';

	t+= '			<table width=100% background="'+graphics_path+'join_bg.jpg" cellspacing=0 cellpadding=0 border=0 align=left>';
	t+= '			<tr>';
	t+= '				<td width=100% align=middle>'+join_text+'</td>';
	t+= '			</tr>';				
	t+= '			</table>';

	t+= '			</td>';
	t+= '			<td height=100%><img src='+graphics_path+'join_right.jpg width=18 height=100%></td>';
	t+= '		</tr>';

	t+= '		<tr>';
	t+= '			<td><img src='+graphics_path+'join_bl.jpg></td>';
	t+= '			<td  width=100%><img src='+graphics_path+'join_bottom.jpg width=100% height=16></td>';
	t+= '			<td><img src='+graphics_path+'join_br.jpg></td>';
	t+= '		</tr>';
	t+= '		</table>';

	
	document.write( t );
}


//-----------------------------------------------------------
// 			AGENDA 
//-----------------------------------------------------------
function html_for_agenda(){
	
	var nb_agenda = agenda.length;
	var t= '';
	
	t+= '		<table cellspacing=0 cellpadding=0 border=0 width=450 align=left>';
	
	for(iag=0; iag<nb_agenda; iag++){
		t += '		<tr><td style="padding:\'15px 0px 0px 0px\';"><b>'+agenda[iag][0]+'</b></td></tr>';
		t += '		<tr><td colspan=3 style="padding:\'0px 0px 0px 0px\';"><hr size=1></td></tr>';	
		t += '		<tr>';
		t += '		<td valign=center>'+agenda[iag][1]+'</td>';
		
		if(agenda[iag][2]!=''){
			t += '		<td style="padding:\'8px 0px 0px 20px\';" valign=center align=right>[ <a href='+agenda[iag][2]+' target="_blank">more</a> ]</td>';
		}

		t += '		</tr>';	
	}

	t+= '		</table>';

	
	document.write( t );


}


//-----------------------------------------------------------
// 			DOCUMENTS 
//-----------------------------------------------------------
function html_for_doc_categories(){

	html_for_categories( 'documents' );
}


function html_for_documents(){
	html_for_items( 'documents' , 'pdf' );
}



//-----------------------------------------------------------
// 			LINKS
//-----------------------------------------------------------


function html_for_link_categories(){

	html_for_categories( 'links' );
}


function html_for_links(){
	html_for_items( 'links' , 'site' );
}



//-----------------------------------------------------------
// 		   ECOLOGICAL HOME
//-----------------------------------------------------------


function html_for_ecological_home_categories(){

	html_for_categories( 'ecological_home' );
}


function html_for_ecological_home(){
	html_for_items( 'ecological_home' , 'pdf' );
}



//-----------------------------------------------------------
// 		   OFFICE ACTIONS
//-----------------------------------------------------------


function html_for_office_actions_categories(){

	html_for_categories( 'office_actions' );
}


function html_for_office_actions(){
	html_for_items( 'office_actions' , 'pdf' );
}



//-----------------------------------------------------------
// 			RESOURCES
//-----------------------------------------------------------


function html_for_resources_categories(){

	html_for_categories( 'resources' );
}


function html_for_resources(){
	html_for_items( 'resources' , 'pdf' );
}




//===========================================================
// 			GENERIC FUNCTIONS
//-----------------------------------------------------------

//-----------------------------------------------------------
// 			LIST CATEGORIES
//-----------------------------------------------------------
function html_for_categories( label ){

	eval('var nb_cat = '+label+'_category.length');

	var t= '';
			
	t+= '		<table style="padding-top:5px;" cellspacing=0 cellpadding=0 border=0 align=left>';

	for(i=0; i<nb_cat; i++){
		t+= '		<tr>';
		t+= '			<td ><a href="#c'+i+'">'+eval(label+'_category['+i+'][1]')+'</a></td>';
		t+= '		</tr>';
	}

	t+= '		</table>';

	
	document.write( t );

}

//-----------------------------------------------------------
// 			LIST ITEMS (per category) 
//-----------------------------------------------------------
function html_for_items( label,link_text ){

	var nb_doc = eval(label+'.length;');
	var nb_cat = eval(label+'_category.length;');
	var nb_cat_intro = eval(label+'_category_intro.length;');

	var t= '';
	
	t+= '		<table cellspacing=0 cellpadding=0 border=0 width=450 align=left>';




	for(icat=0; icat<nb_cat; icat++){
		
		this_cat_idx = eval(label+'_category['+icat+'][0]');
		t += '		<a name="c'+icat+'"></a>';
//		t += '		<tr><td style="padding:\'15px 0px 0px 0px\';"><b>'+eval(label+'_category['+icat+'][1]')+'</b></td></tr>';
t += '		<tr><td style="padding-top:15px;"><b>'+eval(label+'_category['+icat+'][1]')+'</b></td></tr>';

		t += '		<tr><td colspan=3 style="padding:0px;"><hr size=1></td></tr>';

		for(intro=0; intro<nb_cat_intro; intro++){
			if(eval(label+'_category_intro['+intro+'][0]')==this_cat_idx){		
				t += '		<tr>';
//				t += '		<td colspan=3 style="padding:\'5px 0px 18px 0px\';" valign=center><i>'+eval(label+'_category_intro['+intro+'][1]')+'</i></td>';
t += '		<td colspan=3 style="padding-top:5px;padding-bottom:18px;" valign=center><i>'+eval(label+'_category_intro['+intro+'][1]')+'</i></td>';
				t += '		</tr>';
			}
		}

		for(idoc=0; idoc<nb_doc; idoc++){

			if(eval(label+'['+idoc+'][0]')==this_cat_idx){
				t += '		<tr>';
				t += '		<td width=200 valign=center><a href='+eval(label+'['+idoc+'][2]')+' target="_blank">'+eval(label+'['+idoc+'][1]')+'</a></td>';
				t += '		<td style="padding:\'6px 0px 0px 20px\';" align=right valign=center>[ '+eval(label+'['+idoc+'][3]')+' ]</td>';
				t += '		</tr>';
			}
		}	
	}




	
	t+= '		</table>';

	
	document.write( t );

}

