// set the good values depending on where the script is hosted
  switch ( window.location.hostname ) {
   case "david.vmworkstation":
   case "nicolas.vmworkstation":
   case "vmdev":
   case "vmqa":
   case "localhost":
    var SITE_ROOT = '/Projects/Comite_Sectoriel_Des_Communications_Graphiques/Website/';
   break;
   default:
    var SITE_ROOT = '/';
   break;
  }


// Sets the section height 
function getSectionHeight(id, sections_total) {
	
		var total_sections_height = sections_total; // total height of other sections
		
		var windowHeight=0;
		if ( typeof( window.innerHeight )=='number' ) {
			windowHeight=window.innerHeight;
			//windowHeight=window.document.body.offsetHeight;
		}
		else {
			if ( document.documentElement && document.documentElement.clientHeight ) {
				windowHeight=document.documentElement.clientHeight;
			}
			else {
				if ( document.body&&document.body.clientHeight ) {
					windowHeight=document.body.clientHeight;
				}
			}
		}

	var section_height = windowHeight - total_sections_height;  

	

	document.getElementById(id).style.height = section_height + "px";; 

	}
	
	

// ------------------------- Opens/Closes Site Map Sections  ----------------------------- //
function Site_Map_Section_Opener( id ) {
	
	var site_map_button = document.getElementById( "site_map_" + id + "_button" );
	var site_map_arrow = document.getElementById( "site_map_" + id + "_arrow" );
	var site_map_content = document.getElementById( "site_map_" + id + "_content" );
 
	
	var	img_path = site_map_button.src.substring( 0, site_map_button.src.lastIndexOf("/") + 1  );
	var img_src = site_map_button.src.substring( site_map_button.src.lastIndexOf("/") + 1, site_map_button.src.length );
  
		if ( site_map_content.style.display == '' ){
		 
		 site_map_content.style.display = 'none';
			
			switch ( img_src ) {
				case 'minus_root.gif':
				 site_map_button.src = img_path + 'plus_root.gif';
				break;
				case 'minus_L.gif':
				 site_map_button.src = img_path + 'plus_L.gif';
				break;
				case 'minus_T_cross.gif':
				 site_map_button.src = img_path + 'plus_T_cross.gif';
				break;
			}
			
			site_map_arrow.src = img_path + 'container_arrow_right.gif';
			
						
		} else { 
		
		 site_map_content.style.display = '';
			
			switch ( img_src ) {
				case 'plus_root.gif':
				 site_map_button.src = img_path + 'minus_root.gif';
				break;
				case 'plus_L.gif':
				 site_map_button.src = img_path + 'minus_L.gif';
				break;
				case 'plus_T_cross.gif':
				 site_map_button.src = img_path + 'minus_T_cross.gif';
				break;
			}
			
			site_map_arrow.src = img_path + 'container_arrow_down.gif';
			
			
		}
	
}


//  check email format
//  str : string (email) to check 
function isEmail( str ) 
{
// are regular expressions supported?
	var supported = 0;
	
	if ( window.RegExp ) 
	{
		var tempStr = "a";
		var tempReg = new RegExp( tempStr );
		if ( tempReg.test( tempStr ) ) 
		{
			supported = 1;
		}
	}
	
	if ( !supported ) 
	{
		return ( str.indexOf(".") > 2 ) && ( str.indexOf("@") > 0 );
	}
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	
	return ( !r1.test(str) && r2.test(str) );
}




// preloads images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


		
// Shows the clicked row of a list. Example : news list
function List_Show_Hide( list_name, total_rows, current_id ) {

 var list_row;
	var i;
	
	for ( i = 1; i <= total_rows; i++ ) {		
		list_row = document.getElementById( list_name + "_" + i );
  if ( i == current_id ) {
		 list_row.style.display='';
		} else { 
		 list_row.style.display='none';
		}
	}

}





function Resize_Height( ele_id , new_height ) {

 document.getElementById( ele_id ).style.height = new_height;
	
}


function Resize_Width( ele_id , new_width ) {

 document.getElementById( ele_id ).style.width = new_width;
	
}


function Get_Window_Height() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  
		return myHeight;
}


function Get_Window_Width() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  
		return myWidth;
}

function Find_Position(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// Creates a new div as a popup, located next to the object given to this function
function Show_Calendar_Event( object, align ) {
	// Create a new div
	var popup_element = new Element('div');

	var class_str = 'calendar_popup';
	// Identify the new element by the id of the parent object so we can reach it (and hide it) later
	var popup_id = 'popup_' + object.id;
	// The id of the element that contains the text we want to display in this popup
	var source_text_id = 'title_' + object.id;
	
	// Get the position of the parent object
	pos = Find_Position(object);
	
	// Set the correct class and id of the new popup element.  className is for IE, class for the rest
	// The other browsers ignore className, no need to test for browser here
	popup_element.setAttribute('className', class_str);
	popup_element.setAttribute('class', class_str);
	popup_element.setAttribute('id', popup_id);

	// Set the text that we want this popup to display
	popup_element.innerHTML = document.getElementById(source_text_id).innerHTML;
	
	// Insert the new popup as a child of our popup container
	document.getElementById('popup_container').appendChild(popup_element);

	alignment = '';
	if ( align == "left" ) {
		// If we're being told to align this to the left, append a negative left margin
		// the width of the element
		alignment = 'margin-left: -' + $(popup_id).offsetWidth + 'px;'
	}
	
	// Set the absolute position of this element to be a little bit below the parent
	var style_str = alignment + 'top: ' + (pos[1] + 20) +  'px; left: ' + pos[0] + 'px;';
	
	if( popup_element.style.setAttribute ) {
		// IE way of setting style
		popup_element.style.setAttribute("cssText", style_str );
	} else {
		// Other browsers way of setting style
		popup_element.setAttribute("style", style_str );
	}
	
}

// Deletes (and thus hides) the popup element associated with the element given as an argument
function Hide_Calendar_Event( object ) {
	var popup_element = document.getElementById( 'popup_' + object.id );
	if (popup_element != null) {
		document.getElementById('popup_container').removeChild(popup_element);
	}
}

// Get a new calendar month by way of an ajax request
function Get_Ajax_Calendar( month, year, language, align ) {
	var url = SITE_ROOT + 'calendar.php?calendar=' + year + '-' + month + '-01' + '&lang=' + language + '&align=' + align;
	// See moo.fx documentation for this method
	var ajax = new Ajax(url, {method: 'get', update: 'calendar_container'});
	// Make the request
	ajax.request();
}


//Get a new calendar month by way of an ajax request
function Check_Code( code ) {
  var url = SITE_ROOT + 'check_code.php?code=' + code;
  var my_response = '';
  // See moo.fx documentation for this method
  var ajax = new Ajax( url, {method: 'get', async:false });

 	ajax.request();
  
 	return ajax.transport.responseText;
}



function Check_Search_Input( input )
{
	if (input.trim() == '') {
		alert( getTxt('FIELD_REQUIRED') );
		return false;
	}
	return true;
}


function DetailEntreprise(boxID) {
		var box = document.getElementById("box"+boxID);
		if(box.style.display == "none" || box.style.display=="") {
			box.style.display = "block";
		}
		else {
			box.style.display = "none";
		}
	}
	
	
	
function Hide_Status(){
	window.status = '';
	return true
}

// ------------------------- Opens a new window ----------------------------- //

function Open_Window( url, win_name, features ) {
  my_win = window.open( url, win_name, features);
		my_win.focus();
}