

//******************************************************
//****        COMMON JAVASCRIPT FUNCTIONS         ******
//******************************************************

//parameterizable opening a page in a popup (centered)
//The popup will always be open to the forefront
var popup = null;
window.onfocus = function(){
	if(popup){
		if(popup.closed == false){
			popup.focus();
		}else{
			popup = null;
		}
	}
};
function AffichePopup(page,largeur,hauteur,scrollbar){
		var PosY;
		var PosX;
		//delta de hauteur (car les fenetre ne sont pas correctement centrées sur la verticale)
		var deltah = 15;
		//pour centrer la popup
		PosY = ((screen.height-hauteur)/2)-deltah ;
		PosX = (screen.width-largeur)/2;
		if(scrollbar) 
			IsScroll = 1;
		else 
			IsScroll = 0;
		popup = window.open(page,'_blank','toolbar=0, location=0, directories=0, status=0, scrollbars='+IsScroll+', resizable=0, copyhistory=0, menuBar=0, width='+largeur+', height='+hauteur+', left='+PosX+', top='+PosY); 
		popup.focus();
}

//opening profile of a member in a popup
//this popup will not be blocked at the forefront
function AfficheProfil(page,largeur,hauteur,scrollbar){
		var winProfil;
		if(scrollbar) 
			IsScroll = 1;
		else 
			IsScroll = 0;
        location.href =  page;
		//winProfil = window.open(page,'_blank','toolbar=0, location=0, directories=0, status=0, scrollbars='+IsScroll+', resizable=0, copyhistory=0, menuBar=0, width='+largeur+', height='+hauteur); 
		//winProfil.focus();
}

//used in the registration form for choosing the mode of communication (Skype or MSN)
function selectModeCom(){
	if (document.getElementById("selModeCom").value == "1") {
		document.getElementById("tableskype").style.display = "block";
		document.getElementById("tablemsn").style.display = "block";
		document.getElementById("tableyahoo").style.display = "none";
	}
	else if(document.getElementById("selModeCom").value == "2"){
		document.getElementById("tableskype").style.display = "block";
		document.getElementById("tablemsn").style.display = "none";
		document.getElementById("txtAdrMsn").value = "";
		document.getElementById("tableyahoo").style.display = "none";
		document.getElementById("txtAdrYahoo").value = "";
	}
	else if(document.getElementById("selModeCom").value == "3"){
		document.getElementById("tableskype").style.display = "none";
		document.getElementById("txtIdSkype").value = "";
		document.getElementById("tablemsn").style.display = "block";
		document.getElementById("tableyahoo").style.display = "none";
		document.getElementById("txtAdrYahoo").value = "";
	}
	else if(document.getElementById("selModeCom").value == "4"){
		document.getElementById("tableskype").style.display = "block";
		document.getElementById("tablemsn").style.display = "none";
		document.getElementById("txtAdrMsn").value = "";
		document.getElementById("tableyahoo").style.display = "block";
	}
	else if(document.getElementById("selModeCom").value == "5"){
		document.getElementById("tableskype").style.display = "none";
		document.getElementById("txtIdSkype").value = "";
		document.getElementById("tablemsn").style.display = "none";
		document.getElementById("txtAdrMsn").value = "";
		document.getElementById("tableyahoo").style.display = "block";
	}
}

//used for MSN and skype actions
function actionMsnSkype(act,adrMsnSkype){
	//Si l'action est relative à Skype et que ce dernier n'est pas installé
	//on ouvre une popup d'invitation à télécharger skype et on arrête là !
	if((act.indexOf("skype")!= -1)&& (!skypeCheck())){
		return;
	}
	
	//If the action is a MSN action and that is not installed, we open a popup because the browser does not support MSN action
	var browserInfo = navigator.userAgent.toLowerCase();
	if((browserInfo.indexOf("msie")== -1)&&(act.indexOf("msn")!= -1))
	{
		AffichePopup("actionmsn_notie.php?adr="+adrMsnSkype,400,190,false);
	}else{
		var command;
		switch(act){
			case "skypeaddcontact" :
				command = "skype:"+adrMsnSkype+"?add";
				break;
			case "skypecall" :
				command = "skype:"+adrMsnSkype+"?call";
				break;
			case "skypemessage" :
				command = "skype:"+adrMsnSkype+"?voicemail";
				break;
			case "skypetchat" :
				command = "skype:"+adrMsnSkype+"?chat";
				break;
			case "msnaddcontact" :
				command = "msnim:add?contact="+adrMsnSkype;
				break;
			case "msncall" :
				command = "msnim:voice?contact="+adrMsnSkype;
				break;
			case "msnwebcam" :
				command = "msnim:video?contact="+adrMsnSkype;
				break;
			case "msntchat" :
				command = "msnim:chat?contact="+adrMsnSkype;
				break;
            case "yahoochat" :
                command = "ymsgr:sendIM?"+adrMsnSkype;
                break;
		}
		if(command){
			window.location.replace(command);
		}else{
			alert("Impossible to execute this action");
		}
	}
}

//Used to change the opacity of certain pictures in a onMouseOver or a onMouseOut
function changeOpacite(img,opaque){
	var IE=(document.getElementById && document.all)? true : false;
	if (opaque) {
		if (IE) img.filters.alpha.opacity=40;
		else img.style.MozOpacity=.4;
	} else {
		if (IE) img.filters.alpha.opacity=100;
		else img.style.MozOpacity=1;
	}
}

//Used in the comments page to request the removal of a comment
function deleteCommentaire(commentaireId){
	document.getElementById("commentaireSupp").value = commentaireId;
	document.getElementById("commentairesForm").submit();
}

//Used in the comments page to request the removal of a comment
function SpamCommentaire(commentaireId){
	document.getElementById("commentaireSpam").value = commentaireId;
	document.getElementById("commentairesForm").submit();
}
//Used in the comments page to request the removal of a comment
function BlockCommentaire(commentaireId){
	document.getElementById("commentaireBlock").value = commentaireId;
	document.getElementById("commentairesForm").submit();
}

//Used in the private messages page to request the removal of a message
function deleteMessagePrive(messageId){
	document.getElementById("messageSupp").value = messageId;
	document.getElementById("messagesprivesForm").submit();
}


//Used in the private messages page to request the removal of a message
function sendSpam(messageId){
	document.getElementById("messageSpam").value = messageId;
	document.getElementById("messagesprivesForm").submit();
}

//Used in the private messages page to request the removal of a message
function blockuser(messageId){
	document.getElementById("messageBlock").value = messageId;
	document.getElementById("messagesprivesForm").submit();
}

//Allow to go to the search page by specifying
//what type/gender of members which want to display (from the members list pages). 
//This function uses the search form in the menu "I SEARCH"
function lancerRechercheSexe(sexe){
	document.getElementById("selSexeSearchMenu").options.selectedIndex = sexe;
	document.getElementById("searchFormMenu").submit();
}

//###############################################
//	     USED FOR MULTIPAGE
//###############################################

//used in the member search form
function affichePageSearch(numPage){
	document.getElementById("page").value = numPage;
	document.getElementById("searchForm").submit();
}

//used in the member list page (by gender)
function affichePageSexeMembre(numPage){
	document.getElementById("page").value = numPage;
	document.getElementById("sexeMembreForm").submit();
}

function affichePageSexeMembre2(numPage){
	document.getElementById("page2").value = numPage;
	document.getElementById("sexeMembreForm2").submit();
}

//used in the "who have voted for me ?" page
function affichePageVotes(numPage){
	document.getElementById("page").value = numPage;
	document.getElementById("voteForm").submit();
}

//used in the profile page (for the comments list)
function affichePageCommentairesProfil(numPage){
	document.getElementById("page").value = numPage;
	document.getElementById("commentairesProfilForm").submit();
}

//used in the comments page
function affichePageCommentaires(numPage){
	document.getElementById("page").value = numPage;
	document.getElementById("commentairesForm").submit();
}

//used in the private messages page
function affichePageMessagesPrives(numPage){
	document.getElementById("page").value = numPage;
	document.getElementById("messagesprivesForm").submit();
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

