//Variables used for Drop Down Menu
var DropDownEventTimer = 0;
var DropDownEventTimerLevelTwo = 0;
var DropDownEventClicked = 0;
var DropDownEventLevelTwoClicked = 0;
var StatusEventTimer = 0;

var NewsArticleCount = 1;
var NewsArticleEventTimer = 0;
var PreviousArticleSet = 0;
var CurrentArticle = 0;

//AJAX HTTP REQUEST MAIN FUNCTION
function GetXmlHttpObject()
{	
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
  	}
  	
	return xmlHttp;
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	if(document.getElementById(id)){	
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function LoadContent(contentId, isCustom, params)
{	
	UpdateStatus("Chargement...");
	if(isCustom == null){
		isCustom = false;	
	}
	
	if(params == null){
		params = '';	
	}
	
	var xmlLoadContentHttp=GetXmlHttpObject();
	if(xmlLoadContentHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	//document.getElementById("content").innerHTML = "";
	//document.getElementById("content").innerHTML = "<table width='100%' ><tr><td align='center'><img src='images/loading.gif'></td></tr></table>";	
	
	var url="content.php?cId=" + contentId + "&isCustom=" + isCustom + "" + params;
	
	xmlLoadContentHttp.onreadystatechange=function()
	{
		
		if(xmlLoadContentHttp.readyState==4)
		{	
			document.getElementById("content").innerHTML = "";
			document.getElementById("content").innerHTML = xmlLoadContentHttp.responseText;	
			ClearStatus();			
			
		}
	}
	xmlLoadContentHttp.open("GET",url,true);
	xmlLoadContentHttp.send(null);	
}

function UpdateNavigationHistory(menuId, historyAction, orderId){

	if(orderId == null){
		orderId =0;	
	}
	
	var xmlNavUpdateHttp=GetXmlHttpObject();
	if(xmlNavUpdateHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	var url="include/navigationHistory.php?menuId=" + menuId + "&action=" + historyAction + "&orderId=" + orderId + " ";	
	
	xmlNavUpdateHttp.onreadystatechange=function()
	{
		
		if(xmlNavUpdateHttp.readyState==4)
		{	
			document.getElementById("navigationBar").innerHTML = "";
			document.getElementById("navigationBar").innerHTML = xmlNavUpdateHttp.responseText;	
			
		}
	}
	xmlNavUpdateHttp.open("GET",url,true);
	xmlNavUpdateHttp.send(null);	
	
	
}

//Get Y position of Element
function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

//Get X position of Element
function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function DisplayDropDownMenu(menuId, menuLocation, menu)
{		
	clearTimeout(DropDownEventTimer);	
	
	if(DropDownEventClicked != menuId) 
	{
		DropDownEventClicked = menuId;			
		
		var dropDownMenuBox = document.getElementById('DropDown');	
		var windowWidth = 0;
		var eventHTML = "";	
		var offsetTop = 0;
		var offsetLeft = 0;	
		var AlternatTopLeft = "";
		var url="include/dropDownDisplay.php?menuId=" + menuId + "&menu=" + menu + " ";	
		var browser;
						
		dropDownMenuBox.innerHTML='';
		dropDownMenuBox.style.width = "0px";
		dropDownMenuBox.style.height = "0px";
	  	
	  	if(menu == 'main'){
		  	offsetTop = getY(document.getElementById(menuLocation))-1;		  
			offsetLeft = (getX(document.getElementById(menuLocation)) + 149);			  			
	  	}else{		  			  
			offsetTop = getY(document.getElementById(menuLocation))-2;
			offsetLeft = (getX(document.getElementById(menuLocation)) - 202);			  		
	  	}
	  	
		//Determine width of window		
		if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE		   	
			windowWidth = (window.innerWidth - 2) - 15;	
			browser = "firefox";	   
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'		    
			windowWidth = (document.documentElement.clientWidth - 2);
			browser = "IE6";					
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    windowWidth = (document.body.clientWidth - 2);	
		    browser = "IE4";	
		}
		
		xmlDropDownDisplayHttp=GetXmlHttpObject();
		if(xmlDropDownDisplayHttp==null)
		{
				alert ("Your browser does not support AJAX!");
				return;
		}
		
		xmlDropDownDisplayHttp.onreadystatechange=function()
		{
			
			if(xmlDropDownDisplayHttp.readyState==4)
			{	
				
				dropDownMenuBox.style.width = "200px";		
			  	dropDownMenuBox.style.left = offsetLeft + "px";
			  	dropDownMenuBox.style.top = offsetTop + "px";			  	
				dropDownMenuBox.innerHTML = xmlDropDownDisplayHttp.responseText;
				
				if(browser == "firefox"){
					dropDownMenuBox.style.height = document.getElementById('dropDownHeight').value - 1 + "px";						
				}else{					
					if(document.getElementById('dropDownHeight')!=null){
						dropDownMenuBox.style.height = document.getElementById('dropDownHeight').value + "px";	
					}
				}
				
				changeOpac(90,"DropDown");					
			}
		}
		xmlDropDownDisplayHttp.open("GET",url,true);
		xmlDropDownDisplayHttp.send(null);	
		
	}	
}

function DisplayDropDownMenuLevelTwo(menuId, menuLocation, menu)
{	
	clearTimeout(DropDownEventTimerLevelTwo);
	
	if(DropDownEventLevelTwoClicked != menuId) 
	{
		DropDownEventLevelTwoClicked = menuId;			
		
		var dropDownMenuBox = document.getElementById('DropDownLevelTwo');		
		
		var windowWidth = 0;
		var eventHTML = "";	
		var offsetTop = 0;
		var offsetLeft = 0;	
		var AlternatTopLeft = "";
		var url="include/dropDownDisplay.php?menuId=" + menuId + "&menu=" + menu + "&level=2" + " ";	
		var browser;
						
		dropDownMenuBox.innerHTML='';
		dropDownMenuBox.style.width = "0px";
		dropDownMenuBox.style.height = "0px";
	  	
	  	if(menu == 'main'){
		  	offsetTop = getY(document.getElementById(menuLocation))-1;		  	
			offsetLeft = (getX(document.getElementById(menuLocation)) + 198);	
		  		
	  	}else{		
		  	offsetTop = getY(document.getElementById(menuLocation)) - 1;
		  	offsetLeft = (getX(document.getElementById(menuLocation)) - 200);
	  	}
	  	
		//Determine width of window		
		if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE		   	
			windowWidth = (window.innerWidth - 2) - 15;	
			browser = "firefox";	   
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'		    
			windowWidth = (document.documentElement.clientWidth - 2);
			browser = "IE6";					
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    windowWidth = (document.body.clientWidth - 2);	
		    browser = "IE4";	
		}
		
		xmlDropDownDisplayHttp=GetXmlHttpObject();
		if(xmlDropDownDisplayHttp==null)
		{
				alert ("Your browser does not support AJAX!");
				return;
		}
		
		xmlDropDownDisplayHttp.onreadystatechange=function()
		{
			
			if(xmlDropDownDisplayHttp.readyState==4)
			{	
				
				dropDownMenuBox.style.width = "200px";		
			  	dropDownMenuBox.style.left = offsetLeft + "px";
			  	dropDownMenuBox.style.top = offsetTop + "px";			  	
				dropDownMenuBox.innerHTML = xmlDropDownDisplayHttp.responseText;
				
				if(browser == "firefox"){
					dropDownMenuBox.style.height = document.getElementById('dropDownLevelTwoHeight').value - 1 + "px";						
				}else{					
					if(document.getElementById('dropDownHeight')!=null){
						dropDownMenuBox.style.height = document.getElementById('dropDownLevelTwoHeight').value + "px";	
					}
				}
												
				changeOpac(90,"DropDownLevelTwo");
			}
		}
		xmlDropDownDisplayHttp.open("GET",url,true);
		xmlDropDownDisplayHttp.send(null);			
	}	
}

//start hiding the eventdetails
function StartHideDropDown(level)
{
	if(level == 2){
		DropDownEventTimerLevelTwo = setTimeout("HideDropDown(" + level + ")",100);
	}else{
		DropDownEventTimer = setTimeout("HideDropDown(" + level + ")",100);		
	}	
}

//hideEventDetails
function HideDropDown(level)
{
	
	if(level==2){
		DropDownEventLevelTwoClicked = 0;
		var eventBox = document.getElementById('DropDownLevelTwo');	
	}else{
		DropDownEventClicked = 0;
		var eventBox = document.getElementById('DropDown');	
	}
	
	eventBox.innerHTML='';
	eventBox.style.width = "0px";
	eventBox.style.height = "0px";
	eventBox.style.left = "0px";
	eventBox.style.top = "0px";	
	eventBox.style.border = "none";	
}

function StopHideDropDown(level)
{
	if(level == 2){
		clearTimeout(DropDownEventTimerLevelTwo);	//Clear Timer to hide Dropdown	
	}else{
		clearTimeout(DropDownEventTimer);	//Clear Timer to hide Dropdown	
	}	
}

function LogIn()
{
	var xmlLoginHttp=GetXmlHttpObject();
	
	var params, url="login.php?a=l";
	
	if(xmlLoginHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	UpdateStatus("Authentification...");
	
	for(i=0; i<document.userLogin.elements.length; i++){
		if(document.userLogin.elements[i].name == "password"){
			params +=  "&" + document.userLogin.elements[i].name + "=" + hex_md5(document.userLogin.elements[i].value);			
		}else{
			params += "&" + document.userLogin.elements[i].name + "=" + document.userLogin.elements[i].value ;
		}		
	}
		
	xmlLoginHttp.onreadystatechange=function()
	{		
		if(xmlLoginHttp.readyState==4)
		{	
			if(xmlLoginHttp.responseText =="Success"){
				window.location = window.location;
			}else{							
				UpdateStatus("Authentification: Erreur!");
			}
		}
	}
	
	xmlLoginHttp.open("POST",url,true);
	xmlLoginHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlLoginHttp.send(params);
	
	
}

function LogInRedirect(pageType,id){
	var xmlLoginHttp=GetXmlHttpObject();
	
	var params, url="login.php?a=l";
	
	if(xmlLoginHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	UpdateStatus("Authentification...");
	
	for(i=0; i<document.userLoginForced.elements.length; i++){
		if(document.userLoginForced.elements[i].name == "password"){
			params +=  "&" + document.userLoginForced.elements[i].name + "=" + hex_md5(document.userLoginForced.elements[i].value);			
		}else{
			params += "&" + document.userLoginForced.elements[i].name + "=" + document.userLoginForced.elements[i].value ;
		}		
	}
		
	xmlLoginHttp.onreadystatechange=function()
	{		
		if(xmlLoginHttp.readyState==4)
		{	
			if(xmlLoginHttp.responseText =="Success"){
				switch(pageType)
				{
				case "archive":
				  UpdateNavigationHistory(id,'resetadd');
				  LoadContent(id, false, '&isArchive=true&id=' + id);
				  break;
				case "search":
				  UpdateNavigationHistory(id,'resetadd');
				  LoadContent(id, false, '&isArchive=true&id=' + id);
				  break;
				case "content":
				  UpdateNavigationHistory(id,'resetadd');
				  LoadContent(id);
				  break;
				default:
				  window.location = window.location;
				}
				
				ClearStatus();
			}else{							
				UpdateStatus("Authentification: Erreur!");
			}
		}
	}
	
	xmlLoginHttp.open("POST",url,true);
	xmlLoginHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlLoginHttp.send(params);
	
}

function ToggleObjectDisable(object){
		
	if(document.getElementById(object)){	
		if(document.getElementById(object).disabled ==true) {
			document.getElementById(object).disabled = false;
		}else {
			document.getElementById(object).disabled = true;
		}	
	}
}


function LogOut()
{
	var xmlLogoutHttp=GetXmlHttpObject();
	
	var params, url="login.php?a=e";
	params="";
	
	if(xmlLogoutHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	UpdateStatus("Deconnexion...");
		
	xmlLogoutHttp.onreadystatechange=function()
	{		
		if(xmlLogoutHttp.readyState==4)
		{				
			window.location = window.location;			
		}
	}
	
	xmlLogoutHttp.open("POST",url,true);
	xmlLogoutHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlLogoutHttp.send(params);
	
}

function UpdateStatus(statusMessage, parentLevel)
{
	clearTimeout(StatusEventTimer);
	changeOpac(100,"status", parentLevel);
	var HTML ="";
	HTML +="<div align='center' style='background-color:white;line-height:1px;height:1px;font-size: 0px;width:98.5%'>&nbsp;</div>";
	HTML +="<div align='center' style='background-color:white;line-height:1px;height:1px;font-size: 0px;width:99.5%'>&nbsp;</div>";
	HTML +="<div align='center'style='background-color:white;line-height:12px;height:12px;font-size:12px;'><b>" + statusMessage + "</b></div>";
	HTML +="<div align='center' style='background-color:white;line-height:1px;height:1px;font-size: 0px;width:99.5%'>&nbsp;</div>";
	HTML +="<div align='center' style='background-color:white;line-height:1px;height:1px;font-size: 0px;width:98.5%'>&nbsp;</div>";
		
	if(parentLevel){
		parent.document.getElementById('status').innerHTML = HTML;
		parent.document.getElementById('status').style.width = '100%';
	}else{
		document.getElementById('status').innerHTML = HTML;
		document.getElementById('status').style.width = '100%';
	}		
}

function ClearStatus(fadeEnabled, parentLevel)
{
	clearTimeout(StatusEventTimer);
	if(fadeEnabled)
	{
		StatusEventTimer = setTimeout("opacity(\'status\',100,0,6000, " + parentLevel + "),6000");
	}
	else
	{
		if(parentLevel){
			parent.document.getElementById('status').innerHTML = "";
		}else{
			document.getElementById('status').innerHTML = "";
		}		
	}
}

function SendData(dataLink, formName, parameters, returnLocation, button, closeWindow, layer, dataMethod, statusMessage){
	
	if(button !=null){ToggleObjectDisable(button);}	
	if(dataMethod ==null){dataMethod = 'GET';}
	
	if(statusMessage == null){UpdateStatus("Updating...")}else{UpdateStatus(statusMessage)};	
	var xmlHttpSendData=GetXmlHttpObject();
		
	var params, url;
	if(dataMethod == 'POST' && formName!=null){
		for(i=0; i<document.getElementById(formName).elements.length; i++){
			params += document.getElementById(formName).elements[i].name + "=" + document.getElementById(formName).elements[i].value +"&";
		}
		params = params.substring(9);
	}
	
	if(dataMethod == 'GET'){
		url = dataLink +"?" + parameters;	 
	}else{
		url = dataLink;
		params += "&" + parameters;	
	}	

	if(xmlHttpSendData==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}			

	xmlHttpSendData.onreadystatechange=function()
	{
		if(xmlHttpSendData.readyState==4)
		{		
			if(returnLocation != null){document.getElementById(returnLocation).innerHTML = xmlHttpSendData.responseText;}
			//alert(xmlHttpSendData.responseText);				
			ClearStatus();				
			if(button !=null){ToggleObjectDisable(button);}				
			if(closeWindow){ClearOverlay(layer);}	
		}
	}
	
	if(dataMethod == 'GET'){
		xmlHttpSendData.open("GET",url,true);
		xmlHttpSendData.send(null);
	}else{
		xmlHttpSendData.open("POST",url,true);
		xmlHttpSendData.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpSendData.send(params);	
	}
}

//Route user to the Admin System
function AccessAdminSystem()
{	
	UpdateStatus("Chargement Admin...");
	window.location = window.location + "backEnd/"
	
}

//Route user to the Forum
function AccessForum()
{
	UpdateStatus("Chargement Forum...");
	window.location = window.location + "phpBB3/"
}

//Route user to the Bulletin Board
function AccessBulletinBoard()
{
	UpdateStatus("Chargement Babillard...");
	LoadContent(null,false,'&bb=true');	
	
}

//Route user to the Bulletin Board
function LoadMyBillboard()
{
	UpdateStatus("Mes Babillards...");
	LoadContent(null,false,'&bb=true&a=my');
	SendData('mybillboardList.php', null, null, 'myBillboards', null, false, null, 'GET', "Mes Babillards...");
	//UpdateNavigationHistory(" . $menuItems[$iCount][MenuId] . ",'resetadd');
	
}

function ChangeLanguage(language){
	var xmlChangeLanguageHttp=GetXmlHttpObject();
	
	var params,response,url="language.php";
	params = "&ln=" + language;
	if(xmlChangeLanguageHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	UpdateStatus("Chargement...");
	
	xmlChangeLanguageHttp.onreadystatechange=function()
	{		
		if(xmlChangeLanguageHttp.readyState==4)
		{	
			response = xmlChangeLanguageHttp.responseText;
			
			if(response == "1"){
				window.location = window.location;		
			}else{
				alert(response);
			}
		}
	}
	
	xmlChangeLanguageHttp.open("POST",url,true);
	xmlChangeLanguageHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlChangeLanguageHttp.send(params);	
}

function ClearMyBillBoardList(){
	
	document.getElementById("myBillboards").innerHTML = "";
}

function DisplayGreyOut(enabled, loading, parentLevel)
{
	var divObject;	
	if(parentLevel){
		divObject = parent.document.getElementById("greyOut");			
	}else{
		divObject = document.getElementById("greyOut");
	}		
		
	if(enabled)
	{
		divObject.className = "greyOut";	
		
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    if(document.height >window.innerHeight)
			{
				divObject.style.height= (document.height) + "px";
			}
			else
			{
				divObject.style.height= (window.innerHeight - 2) + "px";
			}		
			divObject.style.width= (window.innerWidth - 2) + "px";		   
		} else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    if(document.height > document.documentElement.clientHeight)
			{
				divObject.style.height= (document.height) + "px";
			}
			else
			{
				divObject.style.height= (document.documentElement.clientHeight - 2) + "px";
			}		
			divObject.style.width= (document.documentElement.clientWidth - 2) + "px";	
			
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    if(document.height > document.body.clientHeight)
			{
				divObject.style.height= (document.height) + "px";
			}
			else
			{
				divObject.style.height= (document.body.clientHeight - 2) + "px";
			}		
			divObject.style.width= (document.body.clientWidth - 2) + "px";	
		   
		}
		
		opacity("greyOut",0,50,200,parentLevel);
		
	}
	else
	{
		//alert('hi2');
		opacity("greyOut",50,0,200,parentLevel);
		setTimeout("ClearGreyOut(" +parentLevel + ")", 200);
	}	
}

function ClearGreyOut(parentLevel)
{
	if(parentLevel){
		parent.document.getElementById("greyOut").innerHTML="";
		parent.document.getElementById("greyOut").className = "defaultCenter";
		parent.document.getElementById("greyOut").style.height= 0 + "px";
		parent.document.getElementById("greyOut").style.width= 0 + "px";
	}else{
		document.getElementById("greyOut").innerHTML="";
		document.getElementById("greyOut").className = "defaultCenter";
		document.getElementById("greyOut").style.height= 0 + "px";
		document.getElementById("greyOut").style.width= 0 + "px";
	}
}

function OverlayBox(message, actionGoFunction, actionCancelFunction, enableGreyOut, actionOkFunction){
	if(actionOkFunction == null){actionOkFunction = "";}
	UpdateStatus("Chargement...");	
	var xmlHttpOverLayBox=GetXmlHttpObject();
	if(enableGreyOut){DisplayGreyOut(true);}	
	var url;

	if(xmlHttpOverLayBox==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}		
	
	url = "/backEnd/overlayBox.php?message=" + message + "&goFunction=" + actionGoFunction + "&cancelFunction=" + actionCancelFunction + "&okFunction=" + actionOkFunction + "";	

	xmlHttpOverLayBox.onreadystatechange=function()
	{
		if(xmlHttpOverLayBox.readyState==4)
		{	
			if(actionOkFunction.length > 0){
				parent.document.getElementById("overlayBox").className = "overlayBoxBig";
			}else{
				parent.document.getElementById("overlayBox").className = "overlayBox";
			}
			
			document.getElementById("overlayBox").innerHTML = xmlHttpOverLayBox.responseText;
			opacity("overlayBox",0,100,100);		
			ClearStatus();			
		}
	}
	
	xmlHttpOverLayBox.open("GET",url,true);
	xmlHttpOverLayBox.send(null);
	
}

function ClearOverlayBox(disableGreyOut){	
	document.getElementById("overlayBox").className = "defaultCenter";	
	document.getElementById("overlayBox").innerHTML= "";
	if(disableGreyOut){ClearGreyOut();}
}

function ClearOverlay(layer){	
	if(layer == 3){
		document.getElementById("overlayLayerThree").className = "defaultCenter";	
		document.getElementById("overlayLayerThree").innerHTML= "";
	}else if(layer == 2){
		document.getElementById("overlayLayerTwo").className = "defaultCenter";	
		document.getElementById("overlayLayerTwo").innerHTML= "";
	}else{
		document.getElementById("overlay").className = "defaultCenter";	
		document.getElementById("overlay").innerHTML= "";
		ClearGreyOut();
	}	
}

function DisplayOverLay(HTML, className, fadeEnabled, layer){	
	if(layer == 3){
		document.getElementById('overlayLayerThree').innerHTML=HTML;
		document.getElementById('overlayLayerThree').className = className;
	}else if(layer == 2){
		document.getElementById('overlayLayerTwo').innerHTML=HTML;
		document.getElementById('overlayLayerTwo').className = className;
	}else{
		document.getElementById('overlay').innerHTML=HTML;
		document.getElementById('overlay').className = className;
	}	
}

function DisplayOverLayWindow(moduleLink, className, parameters, windowWidth, windowHeight, headerText, layer){	
	
	if(layer ==null){layer = 1;}
	UpdateStatus("Chargement...");	
	var xmlHttpLoadPage=GetXmlHttpObject();
	if(layer == 1){DisplayGreyOut(true);}
	var url;
	
	if(xmlHttpLoadPage==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}		
	
	url = "include/overlayWindow.php?location=" + moduleLink + "&layer=" + layer + "&width=" + windowWidth + "&height=" + windowHeight + "&" + parameters + "&headerText=" + headerText;	

	xmlHttpLoadPage.onreadystatechange=function()
	{
		if(xmlHttpLoadPage.readyState==4)
		{		
			DisplayOverLay(xmlHttpLoadPage.responseText, className, false, layer);			
			ClearStatus();			
		}
	}
	
	xmlHttpLoadPage.open("GET",url,true);
	xmlHttpLoadPage.send(null);
	
}

function UpdateBillboard(){
	
	parent.UpdateStatus("Economie...");	
	parent.frames[0].DisplayGreyOut(true);
	parent.frames[0].HasEditorBeenEdited = false;
	
	var params, response, ed = parent.frames[0].tinyMCE.get('content');
	//ed.setProgressState(1);
	var content = ed.getContent();

	var xmlHttpUpdateContent=GetXmlHttpObject();
	if(xmlHttpUpdateContent==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	params += "&billboardId=" + parent.document.getElementById('billboardId').value + "&subject=" + parent.frames[0].document.getElementById('subject').value + "&content=" + escape(content) + " ";
	var url="updateBillboard.php";
	xmlHttpUpdateContent.onreadystatechange=function()
	{
		if(xmlHttpUpdateContent.readyState==4)
		{	
			response = xmlHttpUpdateContent.responseText;
			
			if(response.substring(0,3) !="Suc"){
				alert(response);
			}else{			
						
				parent.LoadContent(null,false,'&bb=true&a=my&billboardId=' + parent.document.getElementById('billboardId').value);						
				parent.LoadMyBillboard();	
			}
					
			parent.UpdateStatus(xmlHttpUpdateContent.responseText,true);			
			parent.frames[0].DisplayGreyOut(false);
			
		}
	}
	xmlHttpUpdateContent.open("POST",url,true);
	xmlHttpUpdateContent.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpUpdateContent.send(params);	
}

function CreateBillboard(message){
	parent.UpdateStatus("Creation...");	
	parent.frames[0].DisplayGreyOut(true);
	parent.frames[0].HasEditorBeenEdited = false;
	alert(message);
	var params, message, response, newId, ed = parent.frames[0].tinyMCE.get('content');
	
	//ed.setProgressState(1);
	var content = ed.getContent();

	var xmlHttpUpdateContent=GetXmlHttpObject();
	if(xmlHttpUpdateContent==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	params += "&billboardId=" + parent.document.getElementById('billboardId').value + "&subject=" + parent.frames[0].document.getElementById('subject').value + "&content=" + escape(content) + " ";
	var url="insertBillboard.php";
	xmlHttpUpdateContent.onreadystatechange=function()
	{
		if(xmlHttpUpdateContent.readyState==4)
		{	
			response = xmlHttpUpdateContent.responseText;
			
			if(response.substring(0,3) !="ID:"){
				alert(response);
			}else{				
				newId = response.substring(3,response.indexOf("|"));				
				parent.LoadContent(null,false,'&bb=true&a=my&billboardId=' + newId);
				parent.LoadMyBillboard();	
			}
							
			parent.UpdateStatus(xmlHttpUpdateContent.responseText,true);	
			parent.frames[0].DisplayGreyOut(false);			
			parent.OverlayBox(message, "ClearOverlayBox(true);", "ClearOverlayBox(true)",true, "ClearOverlayBox(true)");
			
		}
	}
	xmlHttpUpdateContent.open("POST",url,true);
	xmlHttpUpdateContent.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpUpdateContent.send(params);	
	
}

function DeleteBillboard(billboardId){
	parent.UpdateStatus("Suppression...");	
	parent.frames[0].DisplayGreyOut(true);
	parent.frames[0].HasEditorBeenEdited = false;
	
	var params, response, newId, ed = parent.frames[0].tinyMCE.get('content');
	//ed.setProgressState(1);
	var content = ed.getContent();

	var xmlHttpUpdateContent=GetXmlHttpObject();
	if(xmlHttpUpdateContent==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	params += "&billboardId=" + billboardId +  " ";
	var url="deleteBillboard.php";
	xmlHttpUpdateContent.onreadystatechange=function()
	{
		if(xmlHttpUpdateContent.readyState==4)
		{	
			response = xmlHttpUpdateContent.responseText;
			
			if(response.substring(0,3) !="Sup"){
				alert(response);
			}else{				
				newId = response.substring(3,response.indexOf("|"));				
				parent.LoadContent(null,false,'&bb=true&a=my');
				parent.LoadMyBillboard();	
			}
							
			parent.UpdateStatus(xmlHttpUpdateContent.responseText,true);	
			parent.frames[0].DisplayGreyOut(false);
			parent.ClearOverlayBox();
		}
	}
	xmlHttpUpdateContent.open("POST",url,true);
	xmlHttpUpdateContent.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpUpdateContent.send(params);	
	
}


function InsertImage(rte, command, option) {   	
	try {
			parent.frames[0].tinyMCE.execCommand(command, false, option);
	} catch (e) {
			alert(e);
	}
} 

function DeleteImage(fileName, id)
{
	
	var params, url;
	var xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null)
	{
			alert ("Your browser does not support AJAX!");
			return;
	}
	
	params += "&fileName=" + fileName +"&id="+id;
	url="deleteBillboardImage.php";
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			parent.frames[1].document.getElementById("Images").innerHTML="";
			parent.frames[1].document.getElementById("Images").style.width='100%';
			//changeOpac(0, "Images");					
			parent.frames[1].document.getElementById("Images").innerHTML=xmlHttp.responseText;
			//opacity("Images",50,100,500);					
			parent.DisplayGreyOut(false);
			var responce = parent.frames[1].document.getElementById('Images').innerHTML;
			parent.ClearOverlayBox();
			if(responce.indexOf('id="good"') != -1)
			{
				parent.UpdateStatus(fileName + ' Deleted!');
			}else
			{
				parent.UpdateStatus('Delete Failed!');
			}
		}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(params);	
}

function AddNewBillboard(){
	
	LoadContent(null,false,'&bb=true&a=new&id=0');
	UpdateStatus('Chargement..');
	
}

function OnResizeAdjustGreyOut(){

	if(document.getElementById("greyOut").style.height.length > 3){
		
		var screenWidth=null;
		var screenHeight=null;
		var scale = null;
		
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    if(document.height >window.innerHeight)
			{
				screenHeight = (document.height) + "px";
			}
			else
			{
				screenHeight = (window.innerHeight - 2) + "px";
			}		
			screenWidth = (window.innerWidth - 2) + "px";		   
		} else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    if(document.height > document.documentElement.clientHeight)
			{
				screenHeight = (document.height) + "px";
			}
			else
			{
				screenHeight = (document.documentElement.clientHeight - 2) + "px";
			}		
			screenWidth = (document.documentElement.clientWidth - 2) + "px";	
			
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    if(document.height > document.body.clientHeight)
			{
				screenHeight = (document.height) + "px";
			}
			else
			{
				screenHeight = (document.body.clientHeight - 2) + "px";
			}		
			screenWidth = (document.body.clientWidth - 2) + "px";	
		   
		}
		
		//if(netscape 4+ OR firefox or any DOM compliant post-1998 browser other than Explorer 4+)
		if(document.layers||(document.getElementById&&!document.all))
		{
			//document.body.style.fontSize = scale + "em";
			window.onresize = OnResizeAdjustGreyOut;
		}
		//else if(IE 4+)
		else if(document.all||(document.getElementById&&!document.all))
		{
			//document.body.style.fontSize = scale + "em";
			window.onresize = OnResizeAdjustGreyOut;
		} 
		
		document.getElementById('greyOut').style.width = screenWidth;
		document.getElementById('greyOut').style.height = screenHeight;		
	}
}

function ChangeNewsArticle(lastId)
{	
	if(document.getElementById('lastNewsId') != null){
		if (lastId == null){ lastId = 0; }
		var ReturnedData = "";	
		changeOpac(0, "newsArticle")
		
		xmlHttpMessageBord = GetXmlHttpObject();
		if(xmlHttpMessageBord==null)
		{
				alert ("Your browser does not support AJAX!");
				return;
		}
		
		var url="include/getNewsArticle.php?lastId=" + lastId + "&currentCount=" + NewsArticleCount;	
		
		xmlHttpMessageBord.onreadystatechange=function()
		{		
			if(xmlHttpMessageBord.readyState==4)
			{				
				setTimeout("opacity('newsArticle',0,100,500)",500);
				document.getElementById("newsArticle").innerHTML = xmlHttpMessageBord.responseText;					
				NewsArticleEventTimer = setTimeout("ChangeNewsArticle(document.getElementById('lastNewsId').value);",12000);
				ResetNewsArticlesList();
				SelectNewsArticleInList(document.getElementById('lastNewsId').value);	
				if ( NewsArticleCount == 5 ) { NewsArticleCount = 1; } else { NewsArticleCount++; }
				
			}
		}
		xmlHttpMessageBord.open("GET",url,true);
		xmlHttpMessageBord.send(null);		
	}

}


function ChangeNewsArticle(lastId, id)
{
	clearTimeout(NewsArticleEventTimer);
	if (id == null) { id = 0; }
	if (lastId == null){ lastId = 0; }
		
	if(( CurrentArticle != id ) || CurrentArticle == 0 || NewsArticleEventTimer == 0){
				
		var ReturnedData = "";
		var totalNewsArticles = document.getElementById('totalArticles').value;	
		changeOpac(0, "newsArticle")
		
		xmlHttpMessageBord = GetXmlHttpObject();
		if(xmlHttpMessageBord==null)
		{
				alert ("Your browser does not support AJAX!");
				return;
		}
		
		if( id == 0){
			var url="include/getNewsArticle.php?lastId=" + lastId + "&currentCount=" + NewsArticleCount;	
		}else{		
			var url="include/getNewsArticle.php?id=" + id + "&currentCount=" + NewsArticleCount;		
		}	
		
		xmlHttpMessageBord.onreadystatechange=function()
		{		
			if(xmlHttpMessageBord.readyState==4)
			{
				if( id == 0){
					changeOpac(0,'newsArticle');
					setTimeout("opacity('newsArticle',0,100,500)",500); 
				}else{
					changeOpac(0,'newsArticle');
					opacity('newsArticle',0,100,200); 
				}
				
				document.getElementById("newsArticle").innerHTML = xmlHttpMessageBord.responseText;	
				
				if( id == 0){
					NewsArticleEventTimer = setTimeout("ChangeNewsArticle(document.getElementById('lastNewsId').value);",12000);
					SelectBoxInList(document.getElementById('lastNewsId').value);
					//ResetBoxList();
					CurrentArticle = lastId;
					//ResetNewsArticlesList();
					//SelectNewsArticleInList(document.getElementById('lastNewsId').value);
					if( totalNewsArticles > 5 ){ totalNewsArticles = 5; }
					if ( NewsArticleCount == totalNewsArticles ) { NewsArticleCount = 1; } else { NewsArticleCount++; }	
				}else{
					SelectBoxInList(id);
					//ResetBoxList();
					CurrentArticle = id;
					//ResetNewsArticlesList();
					//SelectNewsArticleInList(id);
					//NewsArticleEventTimer = setTimeout("ChangeNewsArticle(" + id + ");",12000);
					//ResetNewsArticlesList();
					//SelectNewsArticleInList(id);
					NewsArticleCount = 1;
				}
				
				PreviousArticleSet = document.getElementById('lastNewsId').value;
			}
		}
		xmlHttpMessageBord.open("GET",url,true);
		xmlHttpMessageBord.send(null);		
	}

}

function SelectBoxInList(newsId){		
	
	if(newsId > 0){
		if(PreviousArticleSet > 0 ){ document.getElementById('listItem_' + PreviousArticleSet).style.background = "gray"; }
		document.getElementById('listItem_' + newsId).style.background = "white";	
	}	
}

function ResetBoxList(){
	var rows=document.getElementById('newsArticlesList').getElementsByTagName("TR");
   	for (var j=0; j<rows.length; j++)  {    	
		cells=rows[j].getElementsByTagName("DIV");
		for (var i=0; i<cells.length; i++)  {
  			cells[i].style.background = "white";
		}   		
  }
}

function SelectNewsArticleInList(newsId){		
	document.getElementById('listItem_' + newsId).style.color = "#8B9785";	
	document.getElementById('listItem_' + newsId).style.fontWeight = 'bold';
}

function ResetNewsArticlesList(){	
   var rows=document.getElementById('newsArticlesList').getElementsByTagName("TR");
   for (var j=0; j<rows.length; j++)  {    	
		cells=rows[j].getElementsByTagName("TD");
		for (var i=0; i<cells.length; i++)  {
  			cells[i].style.color = "white";      	
  			cells[i].style.fontWeight = '';		
		}   		
  }
}

function ClearNewsArticleTimer(){	
	clearTimeout(NewsArticleEventTimer);	
}

function ResumeNewsArticleTimer(){	
	try
	{			
		clearTimeout(NewsArticleEventTimer);
	  	NewsArticleEventTimer = setTimeout("ChangeNewsArticle(document.getElementById('lastNewsId').value);",6000);
	}
	catch (e)
	{	 
	   clearTimeout(NewsArticleEventTimer);
	}
}