// JavaScript Document

// Gestion des PNG //

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])


if ((version >= 5.5) && (version < 7) )//&& (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

// PNG //


function setLyr(obj,lyr)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
	//alert('X='+newX+'Y='+newY)
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	//window.status = printstring;
	return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}



//On garde de façon globale la taille de la fenêtre en cours
var winsizew;
var winsizeh;



function ScreenSize(mode) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 winsizew = myWidth;
 winsizeh = myHeight;
 
  
 // window.alert( 'Width = ' + myWidth+' - Height = ' + myHeight );

}

ScreenSize('tWidth');
//window.onresize="ScreenSize('tWidth')"; 


// Gestion des Position Layer //

//GESTION DES ERREURS ET TOOLTIP//
var inc_id = 0;
function od_tooltip(element_target_name,ttl,titre,message,mode,format)
{
	var image_tooltip = '<img src="images/interface/icones/warn.gif" width="16" height="14" align="left" />';
	switch (mode)
	{
	  case 'warn':
		image_tooltip = '<img src="images/interface/icones/warn.gif" width="16" height="14" align="left" />';
	   break;
	  case 'wrong':
		image_tooltip = '<img src="images/interface/icones/wrong.gif" width="16" height="16" align="left" />';
		break;
		case 'idea':
		image_tooltip = '<img src="images/interface/icones/idea.gif" width="11" height="16" align="left" />';
		break;
	  default:
		image_tooltip = '<img src="images/interface/icones/warn.gif" width="16" height="14" align="left" />';
	   break;
	}
	inc_id++;
	var div_container = document.createElement('div');
	div_container.setAttribute('id','div_container_'+inc_id);
	div_container.className = 'class_tooltip';

	switch (format)
	{
	  case 'bottom':
		 var tooltip_content = '<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="images/interface/icones/tooltip-top.gif" width="200" height="6" /></td></tr><tr><td><table width="200" border="0" cellpadding="4" cellspacing="0" class="tooltip_inner"><tr><td width="17" align="left" valign="top" >'+image_tooltip+'</td><td width="165" align="left" valign="middle" style="padding:0px"><strong>'+titre+' :</strong></td></tr><tr><td align="left" valign="top" colspan="2">'+message+'</td></tr></table></td></tr></table>';
	   break;
	  case 'right':
		 var tooltip_content = '<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top" background="images/interface/icones/tooltip-left-border.gif"><img src="images/interface/icones/tooltip-left.gif"   /></td><td align="left" valign="top"><table width="200" border="0" cellpadding="4" cellspacing="0" class="tooltip_inner_left"><tr><td width="17" align="left" valign="top" >'+image_tooltip+'</td><td width="165" align="left" valign="middle" style="padding:0px"><strong>'+titre+' :</strong></td></tr><tr><td align="left" valign="top" colspan="2">'+message+'</td></tr></table></td></tr></table></td></tr></table>';
	  break;
	  default:
		 var tooltip_content = '<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="images/interface/icones/tooltip-top.gif" width="200" height="6" /></td></tr><tr><td><table width="200" border="0" cellpadding="4" cellspacing="0" class="tooltip_inner"><tr><td width="17" align="left" valign="top" >'+image_tooltip+'</td><td width="165" align="left" valign="middle" style="padding:0px"><strong>'+titre+' :</strong></td></tr><tr><td align="left" valign="top" colspan="2">'+message+'</td></tr></table></td></tr></table>';
	   break;
	}
	div_container.innerHTML = tooltip_content;	
	
	if(element_target_name != "random_posistion")
	{
		var ttarget = document.getElementById(element_target_name);
		var tparent = ttarget.parentNode;
		tparent.insertBefore(div_container,ttarget);
		div_container.className = 'class_tooltip';
		div_container.style.position = 'absolute';
		setLyr(ttarget,'div_container_'+inc_id);
		if (format == "right" && ttarget.style.width != "" )
		{
			var act_pos = parseInt(ttarget.style.width)+parseInt(document.getElementById('div_container_'+inc_id).style.left)+6;
			document.getElementById('div_container_'+inc_id).style.left = act_pos+'px';
		}
		else if(format == "bottom" && ttarget.style.height != ""  )
		{
		
			
			var act_pos = parseInt(ttarget.style.height)+parseInt(document.getElementById('div_container_'+inc_id).style.top)+6;
			document.getElementById('div_container_'+inc_id).style.top = act_pos+'px';
		}
	}
	else
	{
		var ttarget = document.getElementById(element_target_name);
		var tparent = ttarget.parentNode;
		tparent.insertBefore(div_container,ttarget);
		div_container.className = 'class_tooltip';
		div_container.style.position = 'absolute';
		setLyr(ttarget,'div_container_'+inc_id);
		//var act_pos = parseInt(ttarget.style.height)+parseInt(document.getElementById('div_container_'+inc_id).style.top)+6;
		var winsizew = ScreenSize("tWidth");
		var winsizeh = ScreenSize("tHeight");
		//alert(winsize);
		document.getElementById('div_container_'+inc_id).style.top = (Math.random()*winsizeh)+'px';
	//	alert(document.getElementById('div_container_'+inc_id).style.left);
		document.getElementById('div_container_'+inc_id).style.left = (Math.random()*winsizew)+'px';
		
	}
	
	
	
	if (window.ActiveXObject) div_container.style.filter = "alpha(opacity=0)";
	div_container.style.visibility='visible';	
	var anim_appear = new YAHOO.util.Anim('div_container_'+inc_id, { opacity: { from: 0, to: 1} }, 1, YAHOO.util.Easing.easeOut);
	anim_appear.animate();
	var tempo = ttl*1000;
	window.setTimeout("erase_tooltip('div_container_"+inc_id+"')",tempo );
}




function od_tooltip_rand(element_target_name,ttl,titre,message,mode,format)
{
	
		 
	//var image_tooltip = '';
	/*switch (mode)
	{
	  case 'warn':
		image_tooltip = '<img src="images/interface/icones/warn.gif" width="16" height="14" align="left" />';
	   break;
	  case 'wrong':
		image_tooltip = '<img src="images/interface/icones/wrong.gif" width="16" height="16" align="left" />';
		break;
		case 'idea':
		image_tooltip = '<img src="images/interface/icones/idea.gif" width="11" height="16" align="left" />';
		break;
	  default:
		image_tooltip = '<img src="images/interface/icones/warn.gif" width="16" height="14" align="left" />';
	   break;
	}*/
	
	var num_image = Math.abs(Math.round((Math.random()*10)-4));
	//alert(num_image);
	inc_id++;
	var div_container = document.createElement('div');
	div_container.setAttribute('id','div_container_'+inc_id);
	div_container.className = 'class_tooltip';
    var tooltip_content = '<img src="images/mots/'+num_image+'.png"  align="left" style=\'z-index:1;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/mots/'+num_image+'.png",sizingMethod="image")\' />';
	/*switch (format)
	{
	  case 'bottom':
		 var tooltip_content = '<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="images/interface/icones/tooltip-top.gif" width="200" height="6" /></td></tr><tr><td><table width="200" border="0" cellpadding="4" cellspacing="0" class="tooltip_inner"><tr><td width="17" align="left" valign="top" >'+image_tooltip+'</td><td width="165" align="left" valign="middle" style="padding:0px"><strong>'+titre+' :</strong></td></tr><tr><td align="left" valign="top" colspan="2">'+message+'</td></tr></table></td></tr></table>';
	   break;
	  case 'right':
		 var tooltip_content = '<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top" background="images/interface/icones/tooltip-left-border.gif"><img src="images/interface/icones/tooltip-left.gif"   /></td><td align="left" valign="top"><table width="200" border="0" cellpadding="4" cellspacing="0" class="tooltip_inner_left"><tr><td width="17" align="left" valign="top" >'+image_tooltip+'</td><td width="165" align="left" valign="middle" style="padding:0px"><strong>'+titre+' :</strong></td></tr><tr><td align="left" valign="top" colspan="2">'+message+'</td></tr></table></td></tr></table></td></tr></table>';
	  break;
	  default:
		 var tooltip_content = '<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="images/interface/icones/tooltip-top.gif" width="200" height="6" /></td></tr><tr><td><table width="200" border="0" cellpadding="4" cellspacing="0" class="tooltip_inner"><tr><td width="17" align="left" valign="top" >'+image_tooltip+'</td><td width="165" align="left" valign="middle" style="padding:0px"><strong>'+titre+' :</strong></td></tr><tr><td align="left" valign="top" colspan="2">'+message+'</td></tr></table></td></tr></table>';
	   break;
	}*/
	div_container.innerHTML = tooltip_content;	
	
	if(element_target_name != "random_posistion")
	{
		var ttarget = document.getElementById(element_target_name);
		var tparent = ttarget.parentNode;
		tparent.insertBefore(div_container,ttarget);
		div_container.className = 'class_tooltip';
		div_container.style.position = 'absolute';
		setLyr(ttarget,'div_container_'+inc_id);
		if (format == "right" && ttarget.style.width != "" )
		{
			var act_pos = parseInt(ttarget.style.width)+parseInt(document.getElementById('div_container_'+inc_id).style.left)+6;
			document.getElementById('div_container_'+inc_id).style.left = act_pos+'px';
		}
		else if(format == "bottom" && ttarget.style.height != ""  )
		{
		
			
			var act_pos = parseInt(ttarget.style.height)+parseInt(document.getElementById('div_container_'+inc_id).style.top)+6;
			document.getElementById('div_container_'+inc_id).style.top = act_pos+'px';
		}
	}
	else
	{
		var ttarget = document.getElementById(element_target_name);
		var tparent = ttarget.parentNode;
		tparent.insertBefore(div_container,ttarget);
		div_container.className = 'class_tooltip';
		div_container.style.zIndex = 1;
		div_container.style.position = 'absolute';
		setLyr(ttarget,'div_container_'+inc_id);
		//var act_pos = parseInt(ttarget.style.height)+parseInt(document.getElementById('div_container_'+inc_id).style.top)+6;
		
		posX = new Array();
		posX[0] = Math.random()*(((winsizeh-925)/2)-170);
		//posX[1] = Math.random()*(((winsizeh-925)/2)+posX[0]+925);
		posX[1] = (925+((winsizeh-925)/2))+(Math.random()*((winsizeh-925)/2))+230;

		//alert(winsizeh);
		//-45 haiteur des mots
		//-342 largeur des mots
		/*document.getElementById('div_container_'+inc_id).style.top = ((Math.random()*winsizeh)-45)+'px';
	//	alert(document.getElementById('div_container_'+inc_id).style.left);
		document.getElementById('div_container_'+inc_id).style.left = ((Math.random()*winsizew)-342)+'px';*/
		document.getElementById('div_container_'+inc_id).style.top = ((Math.random()*winsizeh)-45)+'px';
		document.getElementById('div_container_'+inc_id).style.left = posX[Math.round(Math.random())]+'px';
		
	}
	
	
	
	if (window.ActiveXObject) div_container.style.filter = "alpha(opacity=0)";
	div_container.style.visibility='visible';
	div_container.style.zIndex = 1;

	var anim_appear = new YAHOO.util.Anim('div_container_'+inc_id, { opacity: { from: 0, to: 1} }, 0.5, YAHOO.util.Easing.easeOut);
	anim_appear.animate();
	var tempo = ttl*1000;
	window.setTimeout("erase_tooltip_rand('div_container_"+inc_id+"')",tempo );
	delete anim_appear;
}



function erase_tooltip(id_tooltip)
{
	setTimeout("delete_node('"+id_tooltip+"')",1000);
	var anim_disappear = new YAHOO.util.Anim(id_tooltip, { opacity: { to: 0} }, 1, YAHOO.util.Easing.easeOut);
	anim_disappear.animate();
}

function erase_tooltip_rand(id_tooltip)
{
	setTimeout("delete_node('"+id_tooltip+"')",700);
	var anim_disappear = new YAHOO.util.Anim(id_tooltip, { opacity: { to: 0} }, 0.5, YAHOO.util.Easing.easeOut);
	anim_disappear.animate();
	delete anim_disappear;
}

function delete_node(id_tooltip)
{
	var my_obj = document.getElementById(id_tooltip);
	var tparent = my_obj.parentNode;
	tparent.removeChild(my_obj);
}

function confirmerDelete(message, url){
	if(confirm(message)){
		document.location=url;
	}
}

