

function getDirBin()
{
	
	// SI LA PAGE D'APPEL EST DANS HTTP DOC (Niveau 0)
	var dir_bin = "./";

	var path = (document.location).toString() ;
	// SI LA PAGE D'APPEL EST AU NIVEAU 1 
	if ( path.indexOf("/moteur") > -1 ) { dir_bin = "./../"; }	
	
	return dir_bin;
}
function mainfunc (func, par1, par2){
    window[func](par1, par2);
}

function calledfunc(par1, par2){
    alert("par1="+par1+" par2="+par2);
}

function popSource(target,idSource,src,idBD,searchLan,closeVisible)
{
  if (closeVisible==undefined) 
  {
      closeVisible = 1;
  }
  
	// HIDE VIRTUAL WORLD !!!!!!
	elCMV = document.getElementById('gamecontent');
	elCMV.style.visibility="hidden";
	
	
	// GET DIR BIN FROM PATH
	var dir_bin = getDirBin();
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var paramList = ajaxRequest.responseText;
			//alert(paramList);
			var paramArray  = paramList.split("$;$");
			
			window["open_divpop"](  target,
									searchLan,
									paramArray[0],//urlSource,
									paramArray[1],//widthSource,
									paramArray[2],//heightSource,
									paramArray[3],//analyticSource,
									paramArray[4],//urlPart,
									paramArray[5],//analyticPart,
									paramArray[6],//tooltipPart,
									paramArray[7],//logoPart
									idSource,
									src,
									idBD,
									paramArray[8], // isRated
									paramArray[9], // rating
									closeVisible // is close visible ?
								);

		}
	}
	var d = new Date();
	var time=d.getTime();
	ajaxRequest.open("GET", dir_bin + "services/getSourceInfo.php?id="+idSource+"&src="+src+"&idBD="+idBD+"&lan="+searchLan+"&rand=" + time , true);
	ajaxRequest.send(null); 
	
}

function popSourceCom(target,idSource,src,idBD,searchLan,keyUser,keyTrans,noExercise,closeVisible)
{

  if (closeVisible==undefined) 
  {
      closeVisible = 1;
  }
   
	// HIDE VIRTUAL WORLD !!!!!!
	elCMV = document.getElementById('gamecontent');
	elCMV.style.visibility="hidden";
	
	
	// GET DIR BIN FROM PATH
	var dir_bin = getDirBin();
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var paramList = ajaxRequest.responseText;
			//alert(paramList);
			var paramArray  = paramList.split("$;$");
            
            keyUser,keyTrans,noExercise
            
            if( keyTrans != "" && idBD != 0 )
            {
                if( paramArray[0].indexOf( "?" ) == -1 )
                {
                    paramArray[0] += "?"
                }
                else
                {
                    paramArray[0] += "&"
                }
                
                paramArray[0] += "sj_trans=" + keyTrans + "&sj_user=" + keyUser;
                
                if( noExercise != "" )
                {
                    paramArray[0] += "&no_exercise=" + noExercise;
                }
                
                
            }
            
            
            
			window["open_divpop"](  target,
									searchLan,
									paramArray[0],//urlSource,
									paramArray[1],//widthSource,
									paramArray[2],//heightSource,
									paramArray[3],//analyticSource,
									paramArray[4],//urlPart,
									paramArray[5],//analyticPart,
									paramArray[6],//tooltipPart,
									paramArray[7],//logoPart
									idSource,
									src,
									idBD,
									paramArray[8], // isRated
									paramArray[9], // rating
									closeVisible // is close visible ?
								);

		}
	}
	var d = new Date();
	var time=d.getTime();
	ajaxRequest.open("GET", dir_bin + "services/getSourceInfo.php?id="+idSource+"&src="+src+"&idBD="+idBD+"&lan="+searchLan+"&rand=" + time , true);
	ajaxRequest.send(null); 
	
}

function rate_source(idSource,src,idBD,rate,search_lan)
{
	// GET DIR BIN FROM PATH
	var dir_bin = getDirBin();
	
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				//alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ret = ajaxRequest.responseText;
			
			//alert(ret);

			// une fois le vote effectue, les fleches de vote disparaissent
			var iFrame = document.getElementById("iframegame");
			
			urlIframe = iFrame.src;
			urlIframe = urlIframe.replace("israt=0", "israt=1");
			
			// LOAD THE IFRAME WITH THE PARAMETER isRatet = 1
			iFrame.src = urlIframe;
			
		}
	}
	ajaxRequest.open("GET", dir_bin + "services/rateSource.php?id="+idSource+"&src="+src+"&idBD="+idBD+"&rt="+rate+"&lan="+search_lan, true);
	ajaxRequest.send(null); 
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function open_divpop(target,
					 searchLan,
					 urlSource,
					 widthSource,
					 heightSource,
					 analyticSource,
					 urlPart,
					 analyticPart,
					 tooltipPart,
					 logoPart,
					 idSource,
					 src,
					 idBD,
					 isRated,
					 rating,
					 closeVisible
					 )
{
	var ieVersion = getInternetExplorerVersion();
	
	// PAGES HTML DU BIN
	var dir_bin = getDirBin();	
	
	var widFLASH = 966;

	
	var titlePart    = "";
	var heiBan = 83;

	var widthFrame  =  widthSource;
	var heightFrame = heightSource;
	// 800 = taille minimum pour afficher les logos et les fleches de vote
	if (widthFrame < widFLASH) { widthFrame = widFLASH; }


	
	/*
	var analyticSource = "hits/jeu/toto";
	
	var urlPart      = "http://www.pc.gc.ca";
	var titlePart    = "toto";
	var tooltipPart  = "allez voir mon site";
	var analyticPart = "hits/partenaire/toto";
	var logoPart     = "entete_logo_parc_canada.jpg";
	*/
	
	var elbody;
	var elback;
	var elsource;
	
	
	
	
	elbody = document.getElementsByTagName("body")[0];
	
	
	// Taille de la fenetre
	var bodyH ;
	var bodyW ;
	
	//if(elbody.offsetHeight)          {bodyH=elbody.offsetHeight;}
	//else if(elbody.style.pixelHeight){bodyH=elbody.style.pixelHeight;}
	
	if(elbody.offsetWidth)          {bodyW=elbody.offsetWidth;}
	else if(elbody.style.pixelWidth){bodyW=elbody.style.pixelWidth;}
	
	bodyH = 1500;
	
	elback = document.getElementById('divpop');
	 
	elback.style.width = bodyW + "px";
	elback.style.height = bodyH + "px";
	elback.style.left = "0px"; 
	elback.style.top = "0px";
	
	elback.style.visibility = "visible";
	
	elsource = document.getElementById('divpop_source');
	var sourceT = 0;
	var sourceL = 50;
	
	if ( widthFrame < (bodyW-100) )
	{
		sourceL = parseInt( (bodyW-widthFrame)/2 );
	}
	

	if (target == "null") 
	{
		sourceT = 86;
		sourceL = parseInt( (bodyW-widthFrame)/2 );
	}
	else
	{
		var pos = findPos(target);
		sourceT = pos[1] - parseInt(heightFrame*2/3) ;
	}

	
	if (sourceT < 50) { sourceT = 50; }
	if (sourceL < 20) { sourceL = 20; }

	if ( (sourceT + parseInt(heightFrame) + heiBan ) > bodyH ) { sourceT = bodyH - parseInt(heightFrame) - heiBan - 20; }
	

	elsource.style.top = sourceT + "px";
	elsource.style.left = sourceL + "px"; 
	elsource.style.width = widthSource + "px";
	elsource.style.height = heightSource + "px";
	
  var d = new Date();
  var time=d.getTime();
  
	// POUR LES VIDEOS ON DOIT SAVOIR SI L'URL EST EXTERNE OU INTERNE
	if ( src == 'VIDEO' )
	{
		// SI LA VIDEO EST HEBERGEE CHEZ NOUS
		if ( urlSource.substring(0,4) != "http" )
		{
			urlSource = dir_bin + "services/video/videoplayer.php?url=" + urlSource + "&wid=" + widthSource + "&hei=" + heightSource ;
			heightFrame = parseInt(heightFrame) + 20 ;
		}
	}
	if ( src == 'JEU' )
	{
		// SI LE JEU EST HEBERGE CHEZ NOUS
		if ( urlSource.substring(0,4) != "http" )
		{
			urlSource = dir_bin + "jeux/" + urlSource;
			heightFrame = parseInt(heightFrame) + 20 ;
		}
	}
	if ( src == 'FICHE' )
	{           
    
		// SI LA FICHE EST HEBERGE CHEZ NOUS
		if ( urlSource.substring(0,4) != "http" )
		{
		  var pos = urlSource.indexOf(".",0)+1 ;
		  var ext = urlSource.substring(pos,pos+3);
		  ext = ext.toLowerCase();
		  var phpUrl = "";
		  if ( ext=="jpg" || ext=="png" || ext=="gif" || ext=="bmp") 
      {
        phpUrl = "openimage.php" + "?url=" + urlSource ;
      }
			urlSource = dir_bin + "fiches/" + phpUrl 
			heightFrame = parseInt(heightFrame) + 20 ;
		}
	}
	
	var heightBack = parseInt(heightFrame) + 83 ;
	
	var url_header = dir_bin + "pop_header?dbin=" + dir_bin;
	url_header    += "&lan=" + searchLan ;
	url_header    += "&upar=" + urlPart ;
	url_header    += "&lpar=" + logoPart ;
	url_header    += "&tlpar=" + tooltipPart ;
	url_header    += "&tpar=" + titlePart ;
	url_header    += "&apar=" + analyticPart ;
	url_header    += "&israt=" + isRated ;
	url_header    += "&rate=" + rating ;
	url_header    += "&isrc=" + idSource ;
	url_header    += "&tsrc=" + src ;
	url_header    += "&ibd=" + idBD ;
	url_header    += "&wid=" + parseInt(widthFrame-5) ;
	url_header    += "&close=" + closeVisible   ;
	
	var contentHTML = '';
	contentHTML += '<table border="0" cellpadding="0" cellspacing="0" width="'+widthFrame+'px" height="100%" >';
	contentHTML += '  <tr><td>';
	contentHTML += '	<iframe id="header" name="header"  src="'+ url_header + '" width='+ widthFrame +'px height="83px" scrolling=no frameborder=0 marginheight="0px" marginwidth="0px" hspace="0px" vspace="0px"></iframe>';
	contentHTML += '    </td></tr>';
	contentHTML += '  <tr bgcolor="#000000">';
	contentHTML += '  <td colspan=6 height='+heightSource+'px>';
	contentHTML += '	<iframe id="frameSource" name="frameSource" type="text/html" src="'+urlSource+'" width='+widthFrame+'px height='+heightFrame+'px scrolling=auto frameborder=0></iframe>';
	contentHTML += '  </td>';
	contentHTML += '  </tr>';
	contentHTML += '</table>';
	contentHTML += '<script type="text/javascript">try { var pageTracker = _gat._getTracker("UA-8960669-1"); pageTracker._trackPageview("' + analyticSource + '");} catch(err) {}</script>';
	
	//alert(contentHTML);
	elsource.innerHTML = contentHTML;
	
	elsource.style.visibility = "visible";
	
	removeStickyElement();
}
function removeStickyElement() 
{
	/*
	var d = document.getElementById("searchResult");
	var olddiv = document.getElementById(divId);
	d.removeChild(olddiv);
	*/
	el = document.getElementById("divSticky");
	el.style.visibility = "hidden";
	el.innerHTML = "";
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		
		return [curleft,curtop];
	}
}
function imprimerSource()
{

  frames["frameSource"].focus();  
  frames["frameSource"].print();  
}
function close_popup() 
{

	var elback = document.getElementById('divpop');
	var elsource = document.getElementById('divpop_source');
	
	elback.innerHTML = null;
	elsource.innerHTML = null;
	
	elback.style.visibility = "hidden";
	elsource.style.visibility = "hidden";
	
	
	// UN HIDE VIRTUAL WORLD !!!!!!
	elCMV = document.getElementById('gamecontent');
	elCMV.style.visibility="visible";
    
    var swf = document.getElementById('swf_cmv');
    
    if( swf != null )
    {
        swf.onPopupClose();
	}
  //location.reload(true);
  
}