//<script>
// Code javascript pour le cirque du soleil - Versalys.com

////////////////////////////////////////////////////////////////////////////////////////////
//These variables are used by the speed detection functions
//
var SLOW_MODEM		= 60;
var connectionSpeed = 0;	// The variable where connection speed information
var startTime		= '';	// will be stored when it is available.	
var fileSize		= 19529;
var fileLocation	= '/NR/ContentConnector/CS2000/SiteInterface/commonLSA/js/cds.jpg';
//
////////////////////////////////////////////////////////////////////////////////////////////

var newWindow = null;

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_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_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];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
 }
MM_reloadPage(true);


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function openNewWinFriends(back, PreviousURL)
{
   window.open("/CirqueDuSoleil/en/tellafriend?background=" + back + "&PreviousURL=" + PreviousURL,null,"resizable=no,scrollbars=yes,titlebar=no,toolbar=no,height=490,width=420,status=no,toolbar=no,menubar=no,location=nom,left=200,top=30");
}

function openNewWinFriends_FR(back, PreviousURL)
{
   window.open("/CirqueDuSoleil/fr/tellafriend?background=" + back + "&PreviousURL=" + PreviousURL,null,"resizable=no,scrollbars=yes,titlebar=no,toolbar=no,height=490,width=420,status=no,toolbar=no,menubar=no,location=nom,left=200,top=30");
}

function openNewWinFriends2(url)
{
	window.open(url,null,"resizable=no,scrollbars=yes,titlebar=no,toolbar=no,height=490,width=420,status=no,toolbar=no,menubar=no,location=nom,left=200,top=30");
}	
	
function popupPreLancement()
{
	if (GetCookie('cds_pre_club') == null) {
		window.open("/CirqueDuSoleil/images/popup_cds.htm",null,"resizable=no,scrollbars=no,titlebar=no,toolbar=yes,status=no,toolbar=no,menubar=no,location=nom,width=550,height=200,left=140,top=170");
	}	
	var expiration = new Date(); 
	SetCookie('cds_pre_club', 'OK', null); 				
}
function popupPreLancement_FR()
{
	if (GetCookie('cds_pre_club') == null) {
		window.open("/CirqueDuSoleil/images/popup_cds_fr.htm",null,"resizable=no,scrollbars=no,titlebar=no,toolbar=yes,status=no,toolbar=no,menubar=no,location=nom,width=550,height=200,left=140,top=170");
	}	
	var expiration = new Date(); 
	SetCookie('cds_pre_club', 'OK', null); 				
}

function langue(siteLang)
{
	if (siteLang == null)
	{
		siteLang = '';
	}
	
	var len = siteLang.length;
	var the_url = document.URL;
	var strFind = "cirquedusoleil.com/CirqueDuSoleil/" + siteLang + "/";
	var strReplace = "cirquedusoleil.com/CirqueDuSoleil/en/";
	
	//Le indexOf et le replace gère mal le case Sensitive alors on met tout en lowercase
	the_url = the_url.toLowerCase();
	strFind = strFind.toLowerCase();
	strReplace = strReplace.toLowerCase();
	
	if (len > 0)
	{
		if (the_url.indexOf(strFind, 0)!=-1)
		{
			document.location = the_url.replace(strFind,strReplace);
		}
	}
	else
	{
		if (the_url.indexOf("/en/", 0)!=-1){
			document.location = the_url.replace(/((?:\/)|(?:%2F))en\1/gi, "$1fr$1");	
		}	
		else if (the_url.indexOf("/fr/", 0)!=-1){
			document.location = the_url.replace(/((?:\/)|(?:%2F))fr\1/gi, "$1en$1");
		}
		else {
		}	
	}
}


// Quand on sort d'un layer
function out(obj) {
	var nom = document.getElementById(obj);		
	nom.style.visibility = "hidden";	

}

// Quand ont entre sur un layer
function over(nav) {
	var nom = document.getElementById(nav);		
	nom.style.visibility = "visible";	
}

// Menu du bas

// Vérifie la position de la navigation dans la page

		
function page() {
	var hauteur = document.navigation.offsetTop;
	var largeur = document.navigation.offsetLeft;
				
	if (hauteur<=388){
		hauteur_page =0;
	}
	else {
		hauteur_page = hauteur-(388);
	}
		
	var nom = document.getElementById("menubas");		
	nom.style.top=hauteur-(92);
	nom.style.left=largeur;
	nom.style.visibility = "visible";

	if (document.getElementById("titre")!=null){
		var nom_titre = document.getElementById("titre");	
		nom_titre.style.visibility = "visible";
	}			
		
	nav_bas_page()
}


//lien menu du bas over
function  lien_over(section,nav) {
	
	if (nav=="bnav"){
		the_color="#FFFFFF";	
	}
	else if (nav=="snav"){
		the_color="#FFE461";
	}
	else {
		the_color="#F3c200";	
	}
		
	the_roll = eval (section);
	the_roll.style.color= the_color;
}

//lien menu du bas out
function  lien_out(section,nav) {
		if (nav=="bnav"){
			the_color="#CCCCCC";
		}
		else if (nav=="snav"){
			the_color="#FFFFCC";		
		}
		else {
			the_color="#999999";	
		}
		the_roll = eval (section);
		the_roll.style.color= the_color;
	
}


var count=0;
var the_scroll=0;
var past_scroll=0;
var page_scrool=0;
	
// Retour a la navigation
		
function nav_bas_page() {

	var espace = document.body.clientHeight;
	var hauteur = document.navigation.offsetTop;
	var page_scroll = document.body.scrollTop;
	var position =espace+page_scroll;
	var objbas = document.getElementById("bas")
		
	if (position<(hauteur-30)){
		if (page_scroll==0&&count==0){
			objbas.style.visibility = "visible";
			objbas.style.top=position-34;
			var x_nav = document.navigation.offsetLeft;
			objbas.style.left=x_nav+658;
		}
		else{
			objbas.style.visibility = "hidden";
			count=1;
		}
	}
	else {
		objbas.style.visibility = "hidden";
		count=1;
	}
	setTimeout("page()", 100);
}


// Aller au bas de page
function navigation_page() 
{
	bas.style.visibility = "hidden";	
	var hauteur = document.navigation.offsetTop;
	window.scroll(0,hauteur);
}

// Masquer le flash
function  flash() {
		if (document.getElementById("lucioles")!=null){		
			var obj_lucioles = document.getElementById("lucioles");
			obj_lucioles.style.visibility = "hidden";
		}		
}

/*VerifCookieMusic()-----------------------------------------------------
-  Descript : Verifie si la fenetre musique est ouverte grace a un cookie.
-    La fenetre sera fermee si elle est presente.	
-  Date de creation : 9 avril 2002
-  Date de modification : --
--------------------------------------------------------------------------*/
function VerifCookieMusic()
{
	if (GetCookie('musique') > 0) 
	{
		//sinon, on creer a nouveau une reference a la fenetre et on la ferme
		window2 = window.open('/CirqueDuSoleil/flash/musique.asp','musique','width=115,height=115');	
		if (window.window2) 
		{
        	window2.close();
     		SetCookie('musique_fichier', '');	
            window2 = null;
   		}
	}
}
/*
function  musique() {

	if (GetCookie('musique') == null) {	
		window2 = null;	
	}
	else {
		var ismusique =  GetCookie('musique');
	
		if (ismusique == 0) {	
			window2 = null;				
		}	
		else {
			window2 = window.open('/CirqueDuSoleil/flash/musique.asp','musique','width=115,height=115');	
		}
	}

    if (!window.window2) {
        // has not yet been defined
        window2 = window.open('/CirqueDuSoleil/flash/musique.asp','musique','width=115,height=115');
        if (document.son!=null){	
        document.son.src="/CirqueDuSoleil/images/son_on.gif";
        }
        SetCookie('musique', '1');
        self.focus();
    }
    else {
        // has been defined
        if (!window2.closed) {
           // still open
           if (document.son!=null){
           document.son.src="/CirqueDuSoleil/Images/navigation/etoile.gif";
            }
            SetCookie('musique', '0');
            window2.close();
            window2 = null;
        }
        else {
        	if (document.son!=null){
        	document.son.src="/CirqueDuSoleil/images/son_on.gif";
        	}
                window2 = window.open('/CirqueDuSoleil/flash/musique.asp','musique','width=115,height=115');
        	SetCookie('musique', '1');
        	self.focus();
        }
    }
}
*/
function SetCookie(name, value, path, domain) {

		//var expiration = new Date(); 
		//expiration.setTime(expiration.getTime() + (100000*1000000));  // 1 day	

  document.cookie = name + "=" + escape(value)+   
  //"; expires=" + expiration.toGMTString() + 
 "; path=/"; 
  //((domain == null)  ? "" : "; domain=" + domain); 
}


function GetCookie(name) {
	var cname = name + "=";                
  var dc = document.cookie;              
  
  if (dc.length > 0) {
    begin = dc.indexOf(cname);        
    if (begin != -1) {
      begin += cname.length;        
      end = dc.indexOf(";", begin); 
      if (end == -1) end = dc.length; 
     	return unescape(dc.substring(begin, end)); 
    }  
  } 
  return null; 
}


/*-----------------------------------------------------
détection de la plate-forme
utilisée pour rediriger l'utilisateur PC ou MAC
-------------------------------------------------------*/
function platformDetect() {

  if(navigator.appVersion.indexOf("Mac") != -1) 
    {
	    return "Mac";
    }       
  else 
		return "win";
    } 


/*-----------------------------------------------------
RedirectPcMac(url) et LoadRedirectPcMac(url) servent
?rediriger l'utilisateur vers PC ou MAC sans tenir compte
de la vitesse de connection
-------------------------------------------------------*/
function RedirectPcMac(url,page) {
	//window.location =  url + platformDetect() + page ;
	location.replace(url + platformDetect() + page);
}


function LoadRedirectPcMac(url,page) {
        document.write('<body onload=RedirectPcMac(' + "'" + url + "'," + "'" + page + "'" +');>')
    return;
} 


/*-----------------------------------------------------
drawCSImageTag(), Redirect(), computeConnectionSpeed() et connectionType()
servent ?rediriger l'utilisateur PC ou MAC en tenant compte
de la vitesse de connection
-------------------------------------------------------*/			
connectionSpeed = 0;
	// The variable where connection speed information
	// will be stored when it is available.
		
function drawCSImageTag( path, pagename, fileLocation, fileSize, imgTagProperties ) {
	// This function draws the image tag required to run this process.
	// It needs to be passed:
	//     1.  (String)   The location of the file to be loaded
	//     2.  (Integer)  The size of the image file in bytes
	//     3.  (String)   The tag properties to be included in the <img> tag
	// Place a call to this function inside the <body> of your file
	// in place of a static <img> tag.
			
	start = (new Date()).getTime();
		// Record Start time of <img> load.
				
	loc = fileLocation + '?t=' + escape(start);
		// Append the Start time to the image url
		// to ensure the image is not in disk cache.
	
				
	document.write('<img src="' + loc + '" ' + imgTagProperties + ' onload="Redirect( '+ "'" + path + "'" + ' , '+ "'" + pagename + "'" + ' , ' + start + ',' + fileSize + ');">');
		// Write out the <img> tag.
			
	return;
}
		
function connectionType(speed) {
	// This function returns a string describing the connection type
	// being used by the user-agent hitting the page.
			
	SLOW_MODEM = 60;
	//FAST_MODEM = 57;
	//ISDN_MODEM = 200;
	// These are constants which define the base speeds
	// for a number of different connections.  They are
	// measured in units of kbps.
			
	if (speed) {
		if (speed < SLOW_MODEM) {
					
			return "Low";
					
		} else {
				
			return "Hi";
					
		}
	} else {
	
		return "Hi";
		
	}
}
		
function computeConnectionSpeed( start, fileSize ) {
	// This function returns the speed in kbps of the user's connection,
	// based upon the loading of a single image.  It is called via onload 
	// by the image drawn by drawCSImageTag() and is not meant to be called
	// in any other way.  You shouldn't ever need to call it explicitly.
			
	end = (new Date()).getTime();
	connectSpeed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
	return connectSpeed;
}
		

function Redirect(path, pagename, start, fileSize) {
	connectionSpeed=computeConnectionSpeed(start ,fileSize );
	//window.location = path + pagename +  platformDetect() + connectionType(connectionSpeed) + ".htm" ;
	location.replace(path + pagename +  platformDetect() + connectionType(connectionSpeed) + ".htm");
}

function RenderSpeedDetectionImageTag() {
	// This function draws the image tag required to run this process.
	
	// Record Start time of <img> load.		
	startTime = (new Date()).getTime();
		
	// Append the Start time to the image url
	// to ensure the image is not in disk cache.
	var strSrc = fileLocation + '?t=' + escape(startTime);

	// Write out the <img> tag.			
	document.write("<img style=\'visibility:hidden\' src=\'" + strSrc + "\' width=\"1\" height=\"1\" border=\"0\" onload=\"RenderKAFlash();\">");
	
	return;
}

function GetConnectionSpeed () {
	// This function returns the speed in kbps of the user's connection,
	// based upon the loading of a single image.  It is called via onload 
	// by the image drawn by drawCSImageTag() and is not meant to be called
	// in any other way.  You shouldn't ever need to call it explicitly.

	var returnValue;
	var endTime = (new Date()).getTime();
	
	connectionSpeed =  (Math.floor((((fileSize * 8) / ((endTime - startTime) / 1000)) / 1024) * 10) / 10);
	returnValue = (connectionSpeed && (connectionSpeed < SLOW_MODEM)) ? 'Low' : 'Hi';

	return returnValue;
}

/*******************************************
 Author : Eric De Carufel
 Description : Open a URL from a dropdown Menu
 Date : 2005-06-07
*******************************************/ 
function openUrl( o ) { 

	var newIndex = o.selectedIndex; 

	if ( newIndex != 0 ) { 
		url = o.options[ newIndex ].value; 
		window.location.assign( url ); 
	} 

}

/*******************************************
 Author : Francois Simard
 Description : Open a URL from a given string
 Date : 2005/08/03
*******************************************/ 
function openMenuUrl( o ) { 
	window.location.assign( o ); 
}  


/*******************************************
 Author : Yan Cordeau
 Description : Pop a window at a given percentage related to the screen resolution of the user
 Date : 2005/10/05
*******************************************/ 
function openWindowPercent(percent,theURL,winName,features) {
    var w = 800, h = 600; // default sizes
    if (window.screen) {
        w = window.screen.availWidth * percent / 100;
        h = window.screen.availHeight * percent / 100;
    }

    window.open(theURL,winName,features+',width='+w+',height='+h);

}	

function GetXmlHttpRequest()
{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			try {
			xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.4.0");
		} catch (E) {
			xmlhttp = false;
		}
	}
	/*@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function GetRequestHtml(url)
{
	var req = GetXmlHttpRequest();
	req.open("GET", url, false);
	req.send(null);
	return req.responseText
}

function GetRequestBody(url)
{
	var req = GetXmlHttpRequest();
	req.open("GET", url, false);
	req.send(null);
	re = new RegExp(".*<body[^>]*>(.*)</body>.*");
	var str = req.responseText;
	return str.replace(re, "$1");
}



/*****
* Fonction servant ?faire le log dans la table mk_logs
*****/
function LogInfo(p_strId, p_strLangue){

	//Nous créons la requete
	var req = GetXmlHttpRequest();
	//Pointeur vers la page qui va faire le traitement sur le serveur
	var url = '/CirqueDuSoleil/commonLsa/asp/LogInfo.asp' + '?' + 'p=' + p_strId + '&l=' + p_strLangue
	var LogInfoResult = null;
	//Ouverture de la requete
	req.open("GET", url, false);
	//Ajout des header
	req.setRequestHeader('Accept','message/x-jl-formresult');
	//Envoit de la requete
	req.send(null);
	//Si le traitement ?bien fonctionn?
	if (req.responseText == 'true')
	{
		LogInfoResult = true;
	} else {
		LogInfoResult = false;
	}
	return LogInfoResult;
}

function checkFocus(){
	if (newWindow != null) {
		try{newWindow.focus();}
		catch(er){newWindow=null;}
	}
}

function openWindow(p_path, p_width, p_height){
	
	var winWidth		= p_width;  
	var winHeight		= p_height;	
	
	if (winWidth>screen.width) winWidth = screen.width;

	if (winHeight>screen.height) winHeight = screen.height;
		
	if (winWidth <= 0) winWidth = screen.width;
		
	if (winHeight <= 0) winHeight = screen.height;
		
	var leftPos = 0; leftPos = screen.width/2 - winWidth/2; // centres window
	var topPos	= 0; topPos = screen.height/2 - winHeight/2;  // centres window			

	newWindow = window.open(p_path,'newWin','toolbar=no,location=no,scrollbars=yes,resizable=no,width='+winWidth+',height='+winHeight+',left='+leftPos+',top='+topPos+'');

}

function submitFormThumbnail(imgName, folderName, cardType){

	if(!document.forms[0].show)
		CreateHiddenElement('show');
	if(!document.forms[0].ecard_folderName)
		CreateHiddenElement('ecard_folderName');
	if(!document.forms[0].cardType)
		CreateHiddenElement('cardType');
	
	document.forms[0].show.value = imgName;
	document.forms[0].ecard_folderName.value = folderName;
	document.forms[0].cardType.value = cardType;
	var loc = window.location.toString();
	var composePath = "/CirqueDuSoleil/{lang}/ecard/gen/compose";
	if(loc.match(/\/CirqueDuSoleil\/en/))
		composePath = composePath.replace('{lang}', 'en');
	else
		composePath = composePath.replace('{lang}', 'fr');
	document.forms[0].action = composePath;//"compose.htm"
	document.forms[0].submit();
	return true;
}

function CreateHiddenElement(strName)
{
	var newinput = document.createElement('INPUT');
	newinput.type = 'hidden';
	newinput.name = strName;
	newinput.id = strName;
	document.forms[0].appendChild(newinput);
}


//Fonction servant a inclure du flash dans une page pour bypasser le Activate de WinXP SP2
function WriteFlashInPage(flashId, width, height){
	document.write("<obj" + "ect classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"homepage_top\" align=\"middle\">\n" +
		"<pa" + "ram name=\"allowScriptAccess\" value=\"sameDomain\"/>\n" +
		"<pa" + "ram name=\"movie\" value=\"" + flashId + "\" /" + ">\n" +
		"<pa" + "ram name=\"quality\" value=\"high\" /" + ">\n" +
		"<pa" + "ram name=\"bgcolor\" value=\"#ffffff\" /" + ">\n" +
		"<em" + "bed src=\"" + flashId + "\" quality=\"high\" bgcolor=\"#1a1c20\" width=\"" + width + "\" height=\"" + height + "\" name=\"homepage_top\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n" +
		"<" + "/obj" + "ect" + ">");
}
