/*********************************************
 * Script de redimensionnement de la fen�tre *
 *********************************************/

function redimensionnement(){
	var windowHeight = getWindowHeight(); windowHeight += 75;
	var windowWidth = getWindowWidth();
//	$('banner').style.width = windowWidth - 213 -15 + "px";
	$('ZoneCentraleContenu').style.height = windowHeight - 161 + "px";
	$('zccDroite').style.height = windowHeight - 161 + "px";
	$('contenuGauche').style.height = windowHeight - 170 + "px";
	$('contenuDroite').style.height = windowHeight - 170 + "px";
	$('carte').style.height = windowHeight - 219 + "px";
	$('listeCouches').style.height = windowHeight - 201 - 22 + "px";
	$('minilisteCouches').style.height = windowHeight - 378 + "px";
	if($('cgSearchMenuCatalogue_results').style.display=='block'){
		var h=parseInt($('minilisteCouches').style.height)-24;
		$('minilisteCouches').style.height=h+ "px";
	}
//	$('searchThemapDivTable').style.height = windowHeight - 275 + "px";
	$('serverOGC').style.height = windowHeight - 277 + "px";
	$('searchCatalogue_content_results').style.height = windowHeight - 210 + "px";
	$('searchSimulatedContent').style.height = windowHeight - 210 + "px";
	$('searchHRMContent').style.height = windowHeight - 210 + "px";
	$('searchHRMGeologicalContent').style.height = windowHeight - 210 + "px";
	$('searchHRMAppliedContent').style.height = windowHeight - 210 + "px";
	$('cdDataFolderContent').style.height = windowHeight - 275 +"px";
	$('cgDataFolder').style.height = windowHeight - 174 + "px";	
	$('cdMetadataFolderContent').style.height = windowHeight - 275 +"px";	
	$('cdMetadataFolder').style.height = windowHeight - 174 +"px";	
}	
/***************************************
 * Scripts de gestion des sous-onglets *
 ***************************************/
function gotoOnglet(id){
	$(id).style.display = "block";
	changeOngletState('zcoSearch',id);
	changeOngletState('zcoMapViewer',id);
	changeOngletState('zcoMetadataFolder',id);
	changeIconeFermeture('closeMetadataFolder',id);
	changeOngletState('zcoDataFolder',id);
	changeIconeFermeture('closeDataFolder',id);
	switch(id){
	case "zcoSearch":
		$('cdSearch').style.display = "block";
		$('cgSearch').style.display = "block";
		$('cgMap').style.display = "none";
		$('cdMap').style.display = "none";
		$('cgMetadataFolder').style.display = "none";
		$('cdMetadataFolder').style.display = "none";
		$('cgDataFolder').style.display = "none";
		$('cdDataFolder').style.display = "none";
		
		//This will zoom just the first time the mapSearch is displayed
		if( firstViewMapSearch ){
			//Map for search in catalogue
			//Double zoom, needed to prevent a display bug
			mapSearch.zoomToMaxExtent();
			mapSearch.zoomToMaxExtent();
			firstViewMapSearch = false;
		}
		break;
	case "zcoMapViewer":
		$('cdSearch').style.display = "none";
		$('cgSearch').style.display = "none";
		$('cgMap').style.display = "block";
		$('cdMap').style.display = "block";
		$('cgMetadataFolder').style.display = "none";
		$('cdMetadataFolder').style.display = "none";
		$('cgDataFolder').style.display = "none";
		$('cdDataFolder').style.display = "none";
		break;
	case "zcoMetadataFolder":
		$('cdSearch').style.display = "none";
		$('cgSearch').style.display = "none";
		$('cgMap').style.display = "none";
		$('cdMap').style.display = "none";
		$('cgMetadataFolder').style.display = "block";
		$('cdMetadataFolder').style.display = "block";
		$('cgDataFolder').style.display = "none";
		$('cdDataFolder').style.display = "none";
		break;
	case "zcoDataFolder":
		$('cdSearch').style.display = "none";
		$('cgSearch').style.display = "none";
		$('cgMap').style.display = "none";
		$('cdMap').style.display = "none";
		$('cgMetadataFolder').style.display = "none";
		$('cdMetadataFolder').style.display = "none";
		$('cgDataFolder').style.display = "block";
		$('cdDataFolder').style.display = "block";
		break;
	}
}
// Changer le statut d'un onglet en regardant si l'onglet actif est lui m�me ou non
function changeOngletState(id,idactif){
	$(id).className = (id == idactif) ? "zcoActif" : "zcoPassif";
	$(id+'Droite').className = (id == idactif) ? "zcoActifDroite" : "zcoPassifDroite";
	$(id+'Gauche').className = (id == idactif) ? "zcoActifGauche" : "zcoPassifGauche";
}
function changeIconeFermeture(id,idactif){
	if( ( id == "closeMetadataFolder" && idactif == "zcoMetadataFolder" ) 
			||
		( id == "closeDataFolder" && idactif == "zcoDataFolder" )
	){
		$(id).src = "theme/img/zco_ferme_actif.png";
	} else {
		$(id).src = "theme/img/zco_ferme.gif";
	}
}

// Changer le menu dans Search (OGC ou Catalogue)
function changeSearchMenu(id){
	$('cgSearchMenuSimulated').style.background = "#90BED5";
	$('cgSearchMenuOGC').style.background = "#90BED5";
	$('cgSearchMenuHRM').style.background = "#90BED5";
	$('cgSearchMenuHRMGeological').style.background = "#90BED5";
	$('cgSearchMenuHRMApplied').style.background = "#90BED5";
	$('cgSearchMenuCatalogue').style.background = "#90BED5";
	$('cgSearchMenuCatalogue_results').style.background = "#90BED5";

	$(id).style.background = "#134E6B";
	switch(id){
		case 'cgSearchMenuOGC':
			$('cdSearchSimulated').style.display = "none";
			$('cdSearchOGC').style.display = "block";
			$('cdSearchHRM').style.display = "none";
			$('cdSearchHRMGeological').style.display = "none";
			$('cdSearchHRMApplied').style.display = "none";
			$('cdSearchCatalogue').style.display = "none";
			$('cdSearchCatalogue_results').style.display = "none";			
			break;
		case 'cgSearchMenuHRM':
			$('cdSearchSimulated').style.display = "none";
			$('cdSearchOGC').style.display = "none";
			$('cdSearchHRM').style.display = "block";
			$('cdSearchHRMGeological').style.display = "none";
			$('cdSearchHRMApplied').style.display = "none";
			$('cdSearchCatalogue').style.display = "none";
			$('cdSearchCatalogue_results').style.display = "none";			
			break;
		case 'cgSearchMenuHRMGeological':
			$('cdSearchSimulated').style.display = "none";
			$('cdSearchOGC').style.display = "none";
			$('cdSearchHRM').style.display = "none";
			$('cdSearchHRMGeological').style.display = "block";
			$('cdSearchHRMApplied').style.display = "none";
			$('cdSearchCatalogue').style.display = "none";
			$('cdSearchCatalogue_results').style.display = "none";			
			break;
		case 'cgSearchMenuHRMApplied':
			$('cdSearchSimulated').style.display = "none";
			$('cdSearchOGC').style.display = "none";
			$('cdSearchHRM').style.display = "none";
			$('cdSearchHRMGeological').style.display = "none";
			$('cdSearchHRMApplied').style.display = "block";
			$('cdSearchCatalogue').style.display = "none";
			$('cdSearchCatalogue_results').style.display = "none";			
			break;
		case 'cgSearchMenuCatalogue':
			$('cdSearchSimulated').style.display = "none";
			$('cdSearchOGC').style.display = "none";
			$('cdSearchHRM').style.display = "none";
			$('cdSearchHRMGeological').style.display = "none";
			$('cdSearchHRMApplied').style.display = "none";
			$('cdSearchCatalogue').style.display = "block";
			$('cdSearchCatalogue_results').style.display = "none";	
			//Carte recherche catalogue
			//Zoom en double utile ! pour eviter pbl d affichage
			map1GE_mapSearchForceLastExtent();
			break;
		case 'cgSearchMenuCatalogue_results':
			$('cdSearchSimulated').style.display = "none";
			$('cdSearchOGC').style.display = "none";
			$('cdSearchHRM').style.display = "none";
			$('cdSearchHRMGeological').style.display = "none";
			$('cdSearchHRMApplied').style.display = "none";
			$('cdSearchCatalogue').style.display = "none";
			$('cdSearchCatalogue_results').style.display = "block";			
			break;
		case 'cgSearchMenuSimulated':
			$('cdSearchSimulated').style.display = "block";
			$('cdSearchOGC').style.display = "none";
			$('cdSearchHRM').style.display = "none";
			$('cdSearchHRMGeological').style.display = "none";
			$('cdSearchHRMApplied').style.display = "none";
			$('cdSearchCatalogue').style.display = "none";
			$('cdSearchCatalogue_results').style.display = "none";			
			break;
	}
}

// Fermer l'onglet 'folder' Folder
function fermeFolder(folder){
	$(folder).style.display = "none";
	// Ajouter ici le traitement de reset de l'onglet 'folder' Folder
	// Quand on ferme l'onglet, si on est dessus, on retourne dans la Map
	if( $(folder).className == "zcoActif" ){
		gotoOnglet("zcoMapViewer");
	}
}
// Survole une image (ceci n'est plus utilis�)
function survoleSortImage(image,imageurl){
	$(image).src = imageurl;
}

// Affiche/Cache la fen�tre de choix d'Echelle Num�rique
function viewer_showhide_choixDEchelleNumerique(){
	var style = $('choixDEchelleNumerique').style;
	if( style.display == "block" ){
		style.display = "none";
		$('boutonDEchelleNumerique').src = "theme/img/tb_open_haut.gif";
	} else {
		style.display = "block";
		$('boutonDEchelleNumerique').src = "theme/img/tb_open_bas.gif";
		// On met un timeout pour que la fen�tre ne reste pas ouverte ad-vitam eternam (ici, elle se ferme au bout de 5 secondes)
		setTimeout("viewer_choixDEchelleNumerique_TimeOut()",5000);
	}
}
// Fonction qui d�termine si � la fin du TimeOut on doit ou non cacher la fen�tre de choix d'Echelle Num�rique
function viewer_choixDEchelleNumerique_TimeOut(){
	if( $('choixDEchelleNumerique').style.display == "block" ){
		viewer_showhide_choixDEchelleNumerique();
	}
}
// Fonction qui change l'�chelle de la carte suivant la valeur pass�e en param�tre
function viewer_changeScale(value){
	map.zoomToScale(value);
	viewer_showhide_choixDEchelleNumerique();
}

//Affiche/Cache la fen�tre de choix du SRS
function viewer_showhide_choixSRS(){
	var style = $('choixSRSTableau').style;
	if( style.display == "block" ){
		style.display = "none";
		$('boutonDeChoixSRS').src = "theme/img/tb_open_haut.gif";
	} else {
		style.display = "block";
		$('boutonDeChoixSRS').src = "theme/img/tb_open_bas.gif";
		// On met un timeout pour que la fen�tre ne reste pas ouverte ad-vitam eternam (ici, elle se ferme au bout de 5 secondes)
		setTimeout("viewer_choixSRS_TimeOut()",5000);
	}
}
// Fonction qui d�termine si � la fin du TimeOut on doit ou non cacher la fen�tre de choix du SRS
function viewer_choixSRS_TimeOut(){
	if( $('choixSRSTableau').style.display == "block" ){
		viewer_showhide_choixSRS();
	}
}
