/*******************
Menu
*******************/
function ShowMenu(oElement)
{
  var sOpenMenu = "";
  var sValue = "";
  oEle = oElement.parentNode;
  for(var i = 0; i < oEle.childNodes.length; i++)
  {
    if(oEle.childNodes[i].className)
    {
      
      if((oEle.childNodes[i].nodeName == "LI" && oEle.childNodes[i].className.replace(" ", "") == "part0" || oEle.childNodes[i].className.replace(" ", "") == "part1" || oEle.childNodes[i].className.replace(" ", "") == "part1select" || oEle.childNodes[i].className.replace(" ", "") == "part0select"))
      {
        oEle.childNodes[i].style.display = oEle.childNodes[i].style.display == "none"? "block":"none";
      }
      else if((oEle.childNodes[i].nodeName == "LI" && oEle.childNodes[i].className == "section"))
      {
        
        for(var j = 0; j < oEle.childNodes[i].childNodes.length; j++)
          if(oEle.childNodes[i].childNodes[j].nodeName == "SPAN")
          {
          
            oEle.childNodes[i].childNodes[j].className = (oEle.childNodes[i].childNodes[j].className == "open"?"close":"open");
            //sValue += oEle.childNodes[i].childNodes[j].className == "open"?"close":"open" + ";";
            
          }
      }
    }
  }  
  var sValue = "";
  var oElementLeft = document.getElementById("menu_left");
  for(var i = 0; i < oElementLeft.childNodes.length; i++)
  {
    if(oElementLeft.childNodes[i].nodeName == "UL")
    {
      if(oElementLeft.childNodes[i].childNodes[3].style.display == "none")
      {
        if(navigator.appName == 'Netscape')
          sValue += oElementLeft.childNodes[i].childNodes[1].id + ";";
        else
        sValue += oElementLeft.childNodes[i].childNodes[0].id + ";";
      }
    }
  }
  SetCookie("menu", sValue);
}

/********************
Cookie
********************/
function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + ";path=/";
}

function GetCookie(sName)
{
  oCookie = document.cookie.indexOf(sName + "=");
  if (oCookie >= 0)
  {
    oCookie += nom.length + 1;
    iEnd = document.cookie.indexOf(";",oCookie);
    if (iEnd < 0)
      iEnd = document.cookie.length;
    return unescape(document.cookie.substring(oCookie,iEnd));
  }
  return "";
}



var aMousePosition = new Array();
var bLogOpen = true;

YAHOO.util.Event.addListener(document, 'mousemove', mouseposition);

function CreateCharacter(sLang, sName, iBreedId, sSex, iColor1, iColor2)
{
  aSplit = document.location.host.split('.');
  sDomain = aSplit[aSplit.length-1]
 
  var oForm = document.createElement('form');
  oForm.method = "post";
  oForm.style.display = "none";
  switch(sLang)
  {
    case 'fr':
      if (aSplit[0]== 'www')
        oForm.action = "https://www.wakfu." + sDomain + "/fr/creer-un-compte?utm_source=Game-CreaPerso&utm_medium=Creaperso&utm_campaign=Crea-PersoEtCompte";
      else
        oForm.action = "https://www.wakfu." + sDomain + "/fr/creer-un-compte?utm_source=Serie-CreaPerso&utm_medium=CreaPerso&utm_campaign=Crea-PersoEtCompte";	 
    break;
    /*
    case 'en':
      oForm.action = "https://www.wakfu." + sDomain + "/en/account-creation";
    break;
    case 'de':
      oForm.action = "https://www.wakfu." + sDomain + "/de/account-erstellen";
    break;
    case 'es':
      oForm.action = "https://www.wakfu." + sDomain + "/es/creacion-de-cuenta";
    break;
    */
  }
 
  var oInput = document.createElement("input");
  oInput.name = "ch_name";
  oInput.type = "hidden"; 
  oInput.value = sName;
  oForm.appendChild(oInput);
 
  var oInput = document.createElement("input");
  oInput.name = "ch_breed";
  oInput.type = "hidden"; 
  oInput.value = iBreedId;  
  oForm.appendChild(oInput);

  var oInput = document.createElement("input");
  oInput.name = "ch_sex";
  oInput.type = "hidden"; 
  oInput.value = sSex;  
  oForm.appendChild(oInput);
 
  var oInput = document.createElement("input");
  oInput.name = "ch_color1";
  oInput.type = "hidden"; 
  oInput.value = iColor1;  
  oForm.appendChild(oInput);
  
  var oInput = document.createElement("input");
  oInput.name = "ch_color2";
  oInput.type = "hidden"; 
  oInput.value = iColor2;  
  oForm.appendChild(oInput);

  document.body.insertBefore(oForm, document.body.firstChild);
  
  oForm.submit();
}


function SeeNewsHome(iId, sCat)
{
  
  if (typeof(iCurrentNews) == "undefined" || iCurrentNews !== iId)
  {
    var sHeight = 0;
    var attributes =  {height: { to: 0, unit:'px' } };  
    aDiv = YAHOO.util.Dom.getElementsByClassName("content_news", 'div');
    var iSumHeight = 0;
    
	for(i = 0; i < aDiv.length; i++)
    {    
      if(aDiv[i].id != ("news_" + sCat + "_" + iId) && (aDiv[i].id.substr(0,7) == "news_" + sCat + "_") && aDiv[i].style.height != "0px")
      {
        var anim = new YAHOO.util.Anim(aDiv[i].id, attributes,  0.2, YAHOO.util.Easing.easeOut);
        anim.animate();
      }
      else if(aDiv[i].id == "news_" + sCat + "_" + iId)
      {
        var attributesWiden =  {height: { from: 0, to: aDiv[i].scrollHeight, unit:'px' } }; 
        var anim = new YAHOO.util.Anim(aDiv[i].id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
        anim.animate();
        aDiv[i].scrollHeight;
        sHeight += aDiv[i].scrollHeight;
      }	  
      if((aDiv[i].id == "title_" + sCat +"_" + iId) ) 
      {
        aDiv[i].className = "bg_white_border_grey " + aDiv[i].className ;		
        sHeight += aDiv[i].scrollHeight;
      }
      else if((aDiv[i].id != "title_" + sCat + "_" + iId) && (aDiv[i].id.substr(0,8) == "title_" + sCat + "_"))
      {
        aDiv[i].className = "news content_news content_title";
        sHeight += aDiv[i].scrollHeight;  
      }
    }
	
    ChangeHeight(sHeight);
    iCurrentNews = iId;
  }
}

function ChangeHeight(sHeight)
{
  if (YAHOO.util.Dom.get("home_right"))
  {
    
    var attributes =  {height: { to: 0, unit:'px' } };  
  
    var iHeight = (YAHOO.util.Dom.get("home_right").style.height.substring(0, YAHOO.util.Dom.get("home_right").style.height.indexOf("px", 0)));
    var attributesWiden =  {height: { from: YAHOO.util.Dom.get("home_right").offsetHeight, to: (sHeight +44), unit:'px' } }; 
    var anim = new YAHOO.util.Anim(YAHOO.util.Dom.get("home_right").id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
    anim.animate();
  }
}

function InitializeHeight(iHeightSub,iHeightIE)
{
  
  if(YAHOO.util.Dom.get("home_left").offsetHeight - YAHOO.util.Dom.get("ini_height_left").offsetHeight >= 491)
  {
    if(iHeightSub == undefined)     
	  var iHeightSub = 36;  
	if(iHeightIE == undefined)     
	  var iHeightIE = 0; 
	if(navigator.appName != 'Netscape')
		iHeightSub += iHeightIE;

	YAHOO.util.Dom.get("ini_height_left").style.height = "0px";
    YAHOO.util.Dom.get("home_right").style.height = (YAHOO.util.Dom.get("home_left").offsetHeight - iHeightSub) + "px";
  }
  else
  {
    YAHOO.util.Dom.get("home_right").style.height = "0px";
    YAHOO.util.Dom.get("ini_height_left").style.height = (YAHOO.util.Dom.get("home_right").offsetHeight) - (YAHOO.util.Dom.get("home_left").offsetHeight - YAHOO.util.Dom.get("ini_height_left").offsetHeight) + 36 + "px";
  }
}

function InitializeHeightEvent()
{
    YAHOO.util.Dom.get("home_right").style.height = (YAHOO.util.Dom.get("event_com").offsetHeight - 42) + "px";
}

function InitializeHeightCom()
{
  if(navigator.appName == 'Netscape')
    YAHOO.util.Dom.get("home_right").style.height = (YAHOO.util.Dom.get("community").offsetHeight - 46) + "px";
  else
    YAHOO.util.Dom.get("home_right").style.height = (YAHOO.util.Dom.get("community").offsetHeight - 33) + "px";
}

function BtnCheckbox(oElement)
{
  YAHOO.util.Dom.get("checkbox_wakfu").className = 'btncheckbox off'; 
  YAHOO.util.Dom.get("checkbox_ankama").className = 'btncheckbox off'; 
  YAHOO.util.Dom.get("checkbox_all").className = 'btncheckbox off';

  oElement.className = oElement.className = 'btncheckbox'; 
  var aName = oElement.id.split('_');
  
  YAHOO.util.Dom.get("news_wakfu").style.display = "none";
  YAHOO.util.Dom.get("news_ankama").style.display = "none";
  YAHOO.util.Dom.get("news_all").style.display = "none";
  YAHOO.util.Dom.get("news_" + aName[1]).style.display = "block";
  InitializeHeight();
}


function SeeNews(iId)
{
  var attributes =  {height: { to: 0, unit:'px' } };  
  aDiv = YAHOO.util.Dom.getElementsByClassName("content_news", 'div');
  var iSumHeight = 0;
  var sHeight = 0;

  for(i = 0; i < aDiv.length; i++)
  {
    if(aDiv[i].id != "news_" + iId && aDiv[i].id.substr(0,5) == "news_" && aDiv[i].style.height != "0px")
    {
      var anim = new YAHOO.util.Anim(aDiv[i].id, attributes,  0.2, YAHOO.util.Easing.easeOut);
      anim.animate();
    }
    else if(aDiv[i].id == "news_" + iId && aDiv[i].style.height == "0px")
    {
      var attributesWiden =  {height: { from: 0, to: aDiv[i].scrollHeight, unit:'px' } }; 
      var anim = new YAHOO.util.Anim(aDiv[i].id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
      anim.animate();
      sHeight = aDiv[i].scrollHeight;
      //iSumHeight += aDiv[i].scrollHeight;
    }
    if(aDiv[i].id == "title_" + iId && aDiv[i].className != "bg_white_border_grey news content_news content_title") 
    {
      aDiv[i].className = "bg_white_border_grey " + aDiv[i].className ;
    }
    else if(aDiv[i].id != "title_" + iId && aDiv[i].className == "bg_white_border_grey news content_news content_title")
    {
      aDiv[i].className = "news content_news content_title";

    }

  }

  ChangeHeightFaq(sHeight);
  //alert("g");
 //sleep(1);
 //setTimeout('ChangeHeight()', 200);
  //var iNumber = (YAHOO.util.Dom.get("home_left").scrollHeight);
  //trace(iNumber);
  //YAHOO.util.Dom.get("home_right").style.height = ((iNumber) + "px");
}

function ChangeHeightFaq(sHeight)
{
  if (YAHOO.util.Dom.get("home_right"))
  {
    if (YAHOO.util.Dom.get("event_com"))
    {
      var sHeightAdd = 193;
    }
    else
    {
      var sHeightAdd = 603;
    }
    var attributes =  {height: { to: 0, unit:'px' } };  
  
    var iHeight = (YAHOO.util.Dom.get("home_right").style.height.substring(0, YAHOO.util.Dom.get("home_right").style.height.indexOf("px", 0)));
    
    var attributesWiden =  {height: { from: parseInt(YAHOO.util.Dom.get("home_right").style.height.substring(0, YAHOO.util.Dom.get("home_right").style.height.indexOf("px", 0))), to: (sHeight + sHeightAdd), unit:'px' } }; 
    var anim = new YAHOO.util.Anim(YAHOO.util.Dom.get("home_right").id, attributesWiden,  0.2, YAHOO.util.Easing.easeOut);
    anim.animate();
  }
}


function SelectGame()
{
  YAHOO.util.Event.addListener(document, 'click', QJAction);
}

function QJAction(e)
{
  if(YAHOO.util.Dom.get('select_game').className == 'open')
  {
    YAHOO.util.Dom.get('select_game').className = 'close';
    YAHOO.util.Event.removeListener(document, 'click', QJAction);
  }
  else
  {
    YAHOO.util.Dom.get('select_game').className = 'open';
  }
}

function SelectLang()
{
  if(YAHOO.util.Dom.get('select_lang').className == 'open')
  {
    YAHOO.util.Dom.get('select_lang').className = 'open';
  }
  else
  {
    YAHOO.util.Event.addListener(document, 'click', QJActionLang);
  }
}

function QJActionLang(e)
{
  if(YAHOO.util.Dom.get('select_lang').className == 'open')
  {
    YAHOO.util.Dom.get('select_lang').className = 'close';
    YAHOO.util.Event.removeListener(document, 'click', QJActionLang);
  }
  else
  {
    YAHOO.util.Dom.get('select_lang').className = 'open';
  }
}


/*************
MODULE CONNEXION
***************/

function ShowConnect(foc, bOtherLocation, sUrl)
{
    
	if (YAHOO.util.Dom.get('connect').className == 'header_connect_open' && typeof(foc) != "string")
	{	
		YAHOO.util.Event.removeListener(document, 'click', QJConnect);
		
	}
	 if (typeof(foc) != "string" && bLogOpen)
	  {
	    YAHOO.util.Event.addListener(document, 'click', QJConnect);
	  }
	  else bLogOpen = false;
	  
	  if(bOtherLocation != undefined)
	  {
	    if(bOtherLocation)
	    {     	  
		  YAHOO.util.Event.addListener(document, 'click', QJConnect);
	      QJConnect();
		  YAHOO.util.Dom.get('quickjump').style.position = "fixed";
		  
	    }
	  }
	  
	  if (sUrl != undefined)
	  {
	    YAHOO.util.Dom.get("connect_form").f.value = sUrl;
	  }
	  
   
}

function QJConnect(e)
{
	
  if(YAHOO.util.Dom.get('connect').className == 'header_connect_open')
  {
	if(bLogOpen)
    {     
	  YAHOO.util.Dom.get('connect').className = 'header_connect_close';	
	  YAHOO.util.Event.removeListener(document, 'click', QJConnect);	  	 
    }
  }
  else
  {
	YAHOO.util.Dom.get('connect').className = 'header_connect_open';
  }
  bLogOpen = true;
}

/**********
si je veux remettre le header a sa place
************/
YAHOO.util.Event.addListener(document, 'DOMMouseScroll', QuickjumpPosition);
window.onmousewheel = document.onmousewheel = QuickjumpPosition;

var iCpt=0;
function QuickjumpPosition()
{
		iCpt++;
		
	if (iCpt == 6)
	{
		YAHOO.util.Dom.get('quickjump').style.position = "absolute";
		iCpt=0;
	}
}

/************
FIN MODULE CONNEXION
**************/


function ChangeLang(iVar)
{
  YAHOO.util.Event.removeListener(document, 'click', QJActionLang);
  aLi = YAHOO.util.Dom.getElementsByClassName("content_menu_lang", 'li');
  //trace(aLi);
  var iLangNone = 0;
  for(i = 0; i < aLi.length; i++)
  {
    if(aLi[i].style.display == "none")
      iLangNone = i;
    aLi[i].style.display = "none";
  }
  var iSomme = iLangNone + 3;
  for(i = iLangNone; i < iSomme; i++)
  {
    if(i >= aLi.length)
      aLi[i - 3].style.display = "block";
    else
      aLi[i].style.display = "block";
  }

  window.setTimeout(function()
  {
    YAHOO.util.Event.addListener(document, 'click', QJActionLang);
  }, 10);

}

function ActivateKeys(e)
{
  var asciiF5 = 116;
  var asciiT = 116;
  var asciiN = 110;
  var asciiP = 112;
  if(e.ctrlKey)
  {
    switch(e.which)
    {
      case asciiT:
        window.open();
      break;
      case asciiP:
        window.print();
      break;
    }
  }
  
  if(e.keyCode == asciiF5)
  {
    window.location.reload();
  }
}

function vote(sUrl, iPoolId, iNumber, sLang, bSigned, sDefaultMessage)
{ 
  var form = document.forms.vote;
  sResult = "?poll=" + iPoolId + "&number=" + iNumber;
  for (i=0 ; i<= form.length-1 ; i++)
  {
    if ((form[i].type == 'checkbox' || form[i].type == 'radio')  && form[i].checked)
    {
      sResult +=  "&" + form[i].name + "=" + form[i].value
    }
  }
  if(sResult != "?poll=" + iPoolId + "&number=" + iNumber)
  {
     if(bSigned)
    {
      sUrl = "/" + sLang + "/" + sResult;
      //alert(sUrl);
      form.action = sUrl;
      form.submit();
    }
    else 
    {
      sUrl = "/" + sLang + "/" + sResult;
      ShowConnect(null, true, sUrl);
    }
  }
  else alert(sDefaultMessage);

}  
function mouseposition(e)
{
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)
  {
    fCoordX = e.pageX;
    fCoordY = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    fCoordX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
    fCoordY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  }

  aMousePosition["X"] = fCoordX;
  aMousePosition["Y"] = fCoordY;
}


/********************
Download
********************/
function Track(sUrl)
{
  var sPath = sUrl.substr(26, sUrl.length - 26 -1);
  var aSplit = sPath.split('/');
  
  switch (window.location.pathname.substr(0,3))
  {
  case '/fr':
	var sPath_dl	=	'/telecharger/';
  break;
  case '/en':
	var sPath_dl	=	'/download/';
  break;
  case '/es':
	var sPath_dl	=	'/descargar/';
  break;
  case '/de':
	var sPath_dl	=	'/herunterladen/';
  break;
  }

  if (typeof(pageTracker) != "undefined")
   pageTracker._trackPageview(window.location.pathname.substr(0,3) + sPath_dl + aSplit[0] + "/" + (aSplit[1] == "win" ? "windows" : "others"));

}

function SwitchDownload(sType)
{

	aSpan = document.getElementById("image_link");
  
	sLien =	document.getElementById("lien_dl");
  
  aSpan.className = sType;
  aSpan.parentNode.href = "http://download.wakfu.com/full/" + (sType == "windows" ? "win" : sType) + "/";
	
	if (sType != "windows")
	{
	  sLien.href	=	aSpan.parentNode.href;
	}
  else if (sType == "windows")
  {
	  sLien.href	=	aSpan.parentNode.href + 'full_install.exe';		
  }

 
	
 aP = YAHOO.util.Dom.getElementsByClassName("grey", 'p');
 for (i in aP)
 {
		 if (YAHOO.util.Dom.hasClass(aP[i], sType))
     {
			 YAHOO.util.Dom.addClass(aP[i], "hide");
     }
   else
   			 YAHOO.util.Dom.removeClass(aP[i], "hide");

 }
}

function OpenContent(iId)
{
	document.getElementById(iId).style.display = "block";
}


function poll_radio_check_this(elId)
{	
  var aDiv = YAHOO.util.Dom.getElementsByClassName("checkradio", "div");
	var oDiv = YAHOO.util.Dom.get(elId);
  
	for(k = 0; k < aDiv.length; k++){
		getNextNode(aDiv[k]).checked=false;
		aDiv[k].className='uncheckradio';
	}
		
	
	if(getNextNode(oDiv).checked==true){
		getNextNode(oDiv).checked=false;
		oDiv.className='uncheckradio';
	}	
	else
	{
		getNextNode(oDiv).checked=true;
		oDiv.className='checkradio';
	}
}

/**********
Tag fr3
************/

function makeTag(tag)
{
	ftvi_portail = "france3";
	ftvi_section="programmes_ toowam";
	ftvi_rubrique=tag;
	 
	currentTime = new Date();
	refresh = currentTime.getTime();
	 
	image1 = new Image();
	rubrique = ftvi_portail + "_" + ftvi_section + "_" + ftvi_rubrique + "_" + refresh;
	image1.src = 'http://stat3.cybermonitor.com/'+ftvi_portail+'_v?R=' + rubrique + '&S=total;' + ftvi_portail + "_" + ftvi_section;
 
}

