//////////////////////////////////////////////
//
//	Fonctions communes du site www.rte-france.com/FondationRTE/
//
//	Acte Média Applications Copyright (c) 2004 
//	www.actemedia.com
//
//	----------------------------------
//	fonctions.js
//
//  						
//////////////////////////////////////////////


/************************ MACROMEDIA *********************************/


function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
	
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_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];
   		
   }
}

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;
}

/************************ ACTEMEDIA *********************************/

function openWindow(popUrl, popNom, positionX, positionY, tailleX, tailleY){
		
		if(tailleX == "") {
			tailleX = "676";
		}
		
		if(tailleY == "") {
			tailleY = "658";
		}
		
        var winOpts = "width="+tailleX+",height="+tailleY+",resizable=no,scrollbars=yes,menubar=no,toolbar=no,innerwidth=0,alwaysRaised=yes,top="+positionY+",left="+positionX+",screenX="+positionX+",screenY="+positionY;
        fenetre = window.open(popUrl,popNom,winOpts); 
		fenetre.focus();            
}

function goSWI(link) {
	
	if(window.opener) {
		window.opener.document.location.href = link;	
		window.close();
	}
	else {
		window.document.location.href = link;	
	}
}

function submitSWI(nameForm) {

	if(window.opener) {
		window.opener.nameForm.q.value = window.document.nameForm.q.value;
		window.opener.nameForm.submit();	
		window.close();
	}
	else {
		window.document.nameForm.submit();	
	}
}

function getXhr(){
        
        var xhr = null; 
	
	if(window.XMLHttpRequest) {
	   xhr = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject){
	    try {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
	else {
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
	
        return xhr;
}

function loadVideo(param){

	var div = "divReportage";
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
	
		document.getElementById(div).style.cursor="wait";
		document.getElementById(div).innerHTML = "<p align='center'>Chargement (loading)...</p>";
	
		if(xhr.readyState == 4 && xhr.status == 200){
			document.getElementById(div).style.cursor="default";		
			document.getElementById(div).innerHTML = xhr.responseText;
		}

	}
	
	xhr.open("POST", "pop/loadVideo.jsp", true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	xhr.send(param);
}



function getVideo(param){
	
	var div = "divVideo";
	var divAlpha = "divAlpha";
	
	if(!document.getElementById(div)) {
		nodeBody = document.getElementsByTagName("body");
		
		nodeDiv = document.createElement("div");
		attribute = document.createAttribute("id");
	     	attribute.nodeValue = div;
		nodeDiv.setAttributeNode(attribute);
		nodeBody[0].appendChild(nodeDiv);
		
		nodeDivAlpha = document.createElement("div");
		attribute = document.createAttribute("id");
	     	attribute.nodeValue = divAlpha;
		nodeDivAlpha.setAttributeNode(attribute);
		nodeBody[0].appendChild(nodeDivAlpha);
	
		resize = "setSizeAndPosition('" + div + "','" + divAlpha + "');";
		attribute = document.createAttribute("onresize");
	     	attribute.nodeValue = resize;     	
		nodeBody[0].setAttributeNode(attribute);
	}
	else {
		document.getElementById(div).style.display = "block";		
		document.getElementById(divAlpha).style.display = "block";		
	}
	
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
	
		document.getElementById(div).style.cursor="wait";
		document.getElementById(div).innerHTML = "<p align='center'>Chargement (loading)...</p>";
	
		if(xhr.readyState == 4 && xhr.status == 200){
			
			document.getElementById(div).style.cursor="default";		
			document.getElementById(div).innerHTML = xhr.responseText;
			setSizeAndPosition(div,divAlpha);
		}

	}
	
	xhr.open("POST", "pop/getVideo.jsp", true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
	xhr.send(param);
}


function hideVideo() {
	var div = "divVideo";	
	var divAlpha = "divAlpha";
	document.getElementById(div).style.display="none";	
	document.getElementById(divAlpha).style.display="none";	
}

function setSizeAndPosition(div,divAlpha) {
	
	var hauteur = 0;
	var largeur = 0;
	
	// zone de contenu visible 
	
	if(window.innerHeight || window.innerWidth) { // Mozilla
		hauteur = window.innerHeight;
		largeur = window.innerWidth-17;	
	}
	else if(document.body.clientHeight || document.body.clientWidth) { // IE
		hauteur = document.body.clientHeight;
		largeur = document.body.clientWidth;	
	}
	else if (document.documentElement.clientHeight || document.documentElement.clientWidth) { // IE 6+ Strict
		hauteur = document.body.clientHeight;
		largeur = document.body.clientWidth;	
	}
	
	// position de la zone de contenu
	
	if(window.pageYOffset || window.pageXOffset) { // Mozilla
		hauteur += window.pageYOffset;
		largeur += window.pageXOffset;
	}
	else if(document.body.scrollTop || document.body.scrollLeft) { // IE (sans DTD)
		hauteur += document.body.scrollTop;
		largeur += document.body.scrollLeft;
	}
	else if (document.documentElement.scrollTop || document.documentElement.scrollLeft) { // IE
		hauteur += document.documentElement.scrollTop;
		largeur += document.documentElement.scrollLeft;	
	}
		
	document.getElementById(divAlpha).style.height = hauteur + 'px';
	document.getElementById(divAlpha).style.width = largeur + 'px';
	document.getElementById(div).style.left = ((largeur - document.getElementById(div).offsetWidth)/2) + 'px';
	document.getElementById(div).style.top = ((hauteur - document.getElementById(div).offsetHeight)/2) + 'px';
}

function getProjectLink(idpub) {
	document.location.href='projets_theme.jsp?publication=' + idpub;
}