var hasNewsForPopupConnectedPosition=0;
function showBody(){
	if(document.getElementById("siteLoader")!=null)
		document.getElementById("siteLoader").innerHTML="";
	if(document.getElementById("siteLoader")!=null)
		document.getElementById("siteLoader").style.display="none";			
	if(document.getElementById("siteContainer")!=null)
		document.getElementById("siteContainer").style.display="block";					
}

function showSearchMenu(){
	var myMenu= document.getElementById("search-menu");
	if(myMenu.style.display=="none" || myMenu.style.display==""){
		myMenu.style.display="block";
		} else { 
		myMenu.style.display="none";
	}
}

function initSearchType(label,typeId){
	var myLabel = document.getElementById("search-type-label");
	myLabel.innerHTML=label;
	document.getElementById("searchType").value=typeId
	
}

function chooseSearchType(label,typeId){
	initSearchType(label,typeId)
	showSearchMenu();
}


function doAjaxAction(myUrl,formId,divId,decode){
	myParameters="";
	if(myUrl.indexOf("?")==-1)
		myUrl=myUrl+"?IS_AJAX_REQUEST=1";	
	else
		myUrl=myUrl+"&IS_AJAX_REQUEST=1";
	if(divId=="")
		divId="ajaxBackgroundAction";
	if(formId!=""){
		myForm=document.getElementById(formId);
		if(myForm!=null){		
			myParameters=myParameters+getParameters(myForm,"input",decode);
			myParameters=myParameters+getParameters(myForm,"textarea",decode);	
			myParameters=myParameters+getParameters(myForm,"select",decode);		
			myParameters=myParameters+getParameters(myForm,"radio",decode);
			myParameters=myParameters+getParameters(myForm,"checkbox",decode);			
			if(myUrl.indexOf("?")==-1){
				myUrl=myUrl+"?"+myParameters;
			}
			else
				myUrl=myUrl+"&"+myParameters;
		}
	}	
	ajax_loadContent(divId,myUrl,"POST");
	
}

function showModalDialog(myUrl,parameters){
	window.scrollTo(0,0);
	if(myUrl.indexOf("?")==-1)
		myUrl=myUrl+"?IS_AJAX_REQUEST=1";	
	else
		myUrl=myUrl+"&IS_AJAX_REQUEST=1";
	Modalbox.show(myUrl,parameters)
}

function getParameters(formObject,elementName,decode){
	myParameters="";	
	for(i=0;i<formObject.getElementsByTagName(elementName).length;i++){		
		myElement=formObject.getElementsByTagName(elementName)[i];
		if((myElement.type!="checkbox" && myElement.type!="radio")  || ((myElement.type=="checkbox" || myElement.type=="radio")  && myElement.checked)){
			if(decode){
				myParameters=myParameters+myElement.name+"="+(escape(myElement.value)).replace(/\+/g, '%2B')+"&";	
			}
			else
				myParameters=myParameters+myElement.name+"="+myElement.value+"&";	
	    }
		
	}
	return myParameters;
}

function getResourcePath(resource){
	url=window.location+"";
	pos=url.indexOf("html");    	
	return url.substring(0,pos)+ "html"+resource;
}

function setOpacity( value,popupId ) {
	document.getElementById(popupId).style.opacity = value / 10;
	document.getElementById(popupId).style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup(popupId) {
	for( var i = 0 ; i <= 100 ; i++ )
		setTimeout( 'setOpacity(' + (i / 10) + ',\''+popupId+'\')' , 8 * i );
}

function fadeOutMyPopup(popupId) {
	for( var i = 0 ; i <= 100 ; i++ ) {
		setTimeout( 'setOpacity(' + (10 - i / 10) + ',\''+popupId+'\')' , 8 * i );
	}

	setTimeout('closeMyPopup(\''+popupId+'\')', 800 );
}

function closeMyPopup(popupId) {
	document.getElementById(popupId).style.display = "none"
	if(popupId=="current-connected")
		doAjaxAction(getResourcePath("/connected/currentconnectedlist?activate=0"),null,"current-connected-action");
}

function fireMyPopup(popupId,myTop,left,width,height) {
	document.getElementById(popupId).style.width=width;
	document.getElementById(popupId).style.height=height;
	document.getElementById(popupId).style.top=myTop;
	document.getElementById(popupId).style.left=left;

	setOpacity( 0,popupId);
	document.getElementById(popupId).style.display = "block";
	fadeInMyPopup(popupId);
}
function fireMyPopupCurrentConnected(e){
	if(navigator.appName=="Microsoft Internet Explorer"){							
		width=160;
		height=410;		
		if(hasNewsForPopupConnectedPosition)
			myTop=342;
		else
			myTop=303;
		myLeft=screen.width/2-512;	
	}
	else{		
		width=148;
		height=400;
		if(hasNewsForPopupConnectedPosition)
			myTop=345;
		else
			myTop=313;
		if(screen.width==1024)
			myLeft=screen.width/2-510;
		else
			myLeft=screen.width/2-515;
	}
	doAjaxAction(getResourcePath("/connected/currentconnectedlist?activate=1"),null,"current-connected-action");
	fireMyPopup('current-connected',myTop,myLeft,width,height);	
}

function chgColor(rowNum,Color){
	thisRow=document.getElementById('ligne'+rowNum);
    OldColor=thisRow.bgColor;
    OldBorderColor=thisRow.borderColor;
    thisRow.bgColor= Color;
    thisRow.borderColor=Color;
}

function retColor(rowNum){
	thisRow=document.getElementById('ligne'+rowNum);
    thisRow.bgColor=OldColor;
    thisRow.borderColor=OldBorderColor;
}
