<?php

	$FLAG_NOT_SELECTED 		= true ;
	$INDEX_SITE_SELECTED 	= 0 ;
	$FLAG_FIRST_SITE 		= false ;
	$INDEX_FIRST_SITE 		= 0 ;
	
	for ($i = 0; $i < sizeof($_SESSION['list_sites']); $i++) {
		
		//echo( "i = " ); echo( $i ) ; echo("<br>") ;
		if ( $_SESSION['aqcm_PREFIXE'] == "00" ) {
			
			if ( $FLAG_NOT_SELECTED ) {
				if ( $_SESSION['SITE_ID'] == $_SESSION['list_sites'][$i] ) {
					$FLAG_NOT_SELECTED = false ;
					$INDEX_SITE_SELECTED = $i ;
				}
			}

		}
		else {
			
			if ( substr( $_SESSION['list_sites'][$i], 0, 2) == $_SESSION['aqcm_PREFIXE'] ) {
				
				if ( ! $FLAG_FIRST_SITE ) {
					$FLAG_FIRST_SITE		= true ;
					$INDEX_FIRST_SITE	= $i ;
					//echo( "INDEX_FIRST_SITE = " ); echo($INDEX_FIRST_SITE); echo("<br>");
				}
				
				if ( $FLAG_NOT_SELECTED ) {
					if ( $_SESSION['SITE_ID'] == $_SESSION['list_sites'][$i] ) {
						$FLAG_NOT_SELECTED = false ;
						$INDEX_SITE_SELECTED = $i ;
					}
				}
				
			}
			
		}
		
	}
	
	if ( $FLAG_NOT_SELECTED ) {
		$_SESSION['SITE_ID'] = $_SESSION['list_sites'][$INDEX_FIRST_SITE] ;
	}

?>