var CheckBandeau = false;

function openLink(sUrl)
{
  window.open(sUrl);
}

function CheckUs()
{

  if(GI('us').value == "1")
  {
    if(!GI('age0').checked && !GI('age1').checked)
    {
      GI('required_us').style.display = "block";
      return false;
    }
    else if(GI('age0').checked)
    {
      GI('incorrect_us').style.display = "block";
      return false;
    }
    else if(GI('age1').checked)
    {
      return true;
    }
  }
  return true;
}

function BtnCheckbox(oElement)
{
  GI('btn_checkbox').className = GI('btn_checkbox').className == 'btncheckbox'?'btncheckbox on':'btncheckbox';  
  GI('newsl').value = GI('btn_checkbox').className == 'btncheckbox'? '0':'1';
}

function ShowToolTip(oInput)
{
  var aElementHide = YAHOO.util.Dom.getElementsByClassName( 'tooltip', 'div', oInput.parentNode);
  for(i=0; i< aElementHide.length;i++ )
    aElementHide[i].style.display = "none";
    
  var aElement = YAHOO.util.Dom.getElementsByClassName('tooltip', 'div', oInput.parentNode);
  if (aElement.length > 0)
    aElement[0].style.display  = "block";
}

function HideToolTip(oInput)
{
  var aElement = YAHOO.util.Dom.getElementsByClassName("tooltip", 'div', oInput.parentNode);
  if (aElement.length > 0)
    aElement[0].style.display  = "none";
}

function HideAllError()
{
    var aElement = YAHOO.util.Dom.getElementsByClassName( 'error', 'div');
}

function HideError(oInput)
{
  if (oInput.length > 0)
    GI('error' + oInput.name).style.display = "none";
}

function ShowToolTipPassword(oPassword)
{
  var aElement = YAHOO.util.Dom.getElementsByClassName('tooltip low', 'div', oPassword.parentNode);
  if (aElement.length > 0)
    aElement[0].style.display  = "block";
}

function HideToolTipPassword()
{
  GI('tooltip_high').style.display = 'none';
  GI('tooltip_medium').style.display = 'none';
  GI('tooltip_low').style.display = 'none';
  GI('tooltip_default').style.display = 'none';
}

function CheckPassword(oPassword)
{
  var aElementHide = YAHOO.util.Dom.getElementsByClassName( 'tooltip', 'div', oPassword.parentNode);
  for(i=0; i< aElementHide.length;i++ )
    aElementHide[i].style.display = "none";
    
  var oFormValidator = new FormValidator();
  bValid = oFormValidator.Control(GI(oPassword.name), false);

  var iLevel = -1;

  if (bValid)
  {
    iLevel = 0;

    if (oPassword.value.search("[a-z]") != -1)
      iLevel = 0;
    if (oPassword.value.search("[\x20-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]") != -1)
      iLevel++;
    if (oPassword.value.search("[0-9]") != -1)
      iLevel++;
    if (iLevel == 0)
      if (oPassword.value.search("[A-Z]") != -1)
        iLevel++;
  }
  HideToolTipPassword();
  if(iLevel < 0)
    GI('tooltip_default').style.display = 'block';
  else if(iLevel == 0)
    GI('tooltip_low').style.display = 'block';
  else if(iLevel == 1)
    GI('tooltip_medium').style.display = 'block';
  else if(iLevel == 2)
    GI('tooltip_high').style.display = 'block';
  
  //GI("tooltip_password").className = iLevel == 0 ? "tooltip high" : (iLevel == 1 ? "tooltip medium" : (iLevel == 2 ? "tooltip" : "tooltip high"));
}

function HideBandeau()
{
  for(var i=1; i<=26; i++)
  {
    if (GI('bandeau' + i) != null)
      GI('bandeau' + i).style.display = 'none';
    else if (document.getElementById('bandeau' + i) != null)
      document.getElementById('bandeau' + i).style.display = 'none';
  }
}

function ShowHelp(iNumber)
{
  if(iNumber != 17 && iNumber != 18 && CheckBandeau == false)
  {
    CheckBandeau = true;
    YAHOO.util.CrossFrame.send("http://miniclip.dofus.com/proxy.php",
                               "parent",
                               1);
  }
}

function ShowBandeau(iNumber)
{
  HideBandeau();
  GI('title_help').style.display = 'block';
  GI('bandeau' + iNumber).style.display = 'block';

/*
    YAHOO.util.CrossFrame.send("http://miniclip.dofus.com/proxy.php",
                               "parent",
                               iNumber);
                               */
}


function DoBanner(iNumber)
{
  if (GI('bandeau' + iNumber) != null)
  {
    HideBandeau();
    GI('bandeau' + iNumber).style.display = 'block';
  }
  else if(document.getElementById('bandeau' + iNumber) != null)
  {
    HideBandeau();
    document.getElementById('bandeau' + iNumber).style.display = 'block';
  }
}

function SoundPlay(sServer)
{
  if(parent.frames['music'].location.href == sServer + "/mute.html")
  {
    document.getElementById('sound').className = "sound off";
    document.getElementById('sound').href = "javascript:StopOrPlay('on')";
  }
    
  else
  {
    document.getElementById('sound').className = "sound";  
    document.getElementById('sound').href = "javascript:StopOrPlay('off')";
  }
}

function StopOrPlay(sValue)
{
  if(sValue == 'off')
  {
    document.getElementById('sound').className = "sound off";
    document.getElementById('sound').href = "javascript:StopOrPlay('on')";
    parent.frames['music'].location.href = "/mute.html";
  }
  else
  {
    document.getElementById('sound').className = "sound";
    document.getElementById('sound').href = "javascript:StopOrPlay('off')";
    parent.frames['music'].location.href = "/music.php";
  }
}

function DisplayScroll(sValue)
{
  GI('part_my_account').style.display = 'none';
  GI('part_downloading').style.display = 'none';
  GI('part_technical').style.display = 'none';
  GI('part_comment').style.display = 'none';
  GI('part_comment2').style.display = 'none'; 
  GI('part_' + (sValue)).style.display = 'block';
}

function CloseDivComment()
{
  var aElement = YAHOO.util.Dom.getElementsByClassName( 'content_description', 'div');
  for(i = 0 ; i < aElement.length ; i++)
    aElement[i].style.display = "none";
}

function OpenDivComment(sValue)
{
  GI(sValue).style.display = GI(sValue).style.display == 'block'? 'none':'block';
}

function OpenPopUpRecoverPassword()
{
  //window.location.href = "/support/recover_password.php";
  window.open('http://miniclip.dofus.com/support/recover_password.php','password','scrollbars=no,width=596 ,height=407,statusbar=no,menubar=no,toolbar=no,resizable=no,status=no,top='+((screen.height-600)/2)+',left='+((screen.width-850)/2));
}

function GoToSubscribe()
{
  parent.window.location.href = "http://miniclip.dofus.com/subscribe.php";
}

function GoToCongratulation(iValue)
{
  parent.window.location.href = "http://miniclip.dofus.com/congratulation.php?t=" + iValue;
}

function openFriends(sLang)
{
  if(sLang == 'en')
    friendWindow = window.open('http://community.dofus.com/misc/friend_popup.php', 'friendWindow', 'width=700, height=600, menubar=no,location=no,resizable=no,scrollbars=no,status=no') ;
  else if(sLang == 'de')
    friendWindow = window.open('http://spielergemeinde.dofus.de/misc/friend_popup.php', 'friendWindow', 'width=700, height=600, menubar=no,location=no,resizable=no,scrollbars=no,status=no') ;
  else if(sLang == 'es')
    friendWindow = window.open('http://comunidad.dofus.es/misc/friend_popup.php', 'friendWindow', 'width=700, height=600, menubar=no,location=no,resizable=no,scrollbars=no,status=no') ;
  
  friendWindow.focus();
}


function CreateLoading(sName)
{
  if (!GI('loading'))
  {
    var oPre = document.createElement('div');
    oPre.setAttribute('id','loading');
    document.body.insertBefore(oPre, document.body.firstChild);
  }
  else
    oPre = GI('loading');

  oPre.innerHTML = sName;
}

function CustomerStart()
{
}

function PopUp()
{
  friendWindow = window.open('http://comunidad.dofus.es/misc/friend_popup.php');
  friendWindow.focus();
}
/* -------------------------------------------------------------------------------------------------------- *\
   Mouse Loading
\* -------------------------------------------------------------------------------------------------------- */
// Simple follow the mouse script

var divName = 'loading'; // div that is to follow the mouse
                       // (must be position:absolute)
var offX = 15;          // X offset from mouse position
var offY = 15;          // Y offset from mouse position

function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

function follow(evt) {if (document.getElementById) {var obj = document.getElementById(divName).style; obj.visibility = 'visible';
obj.left = (parseInt(mouseX(evt))+offX) + 'px';
obj.top = (parseInt(mouseY(evt))+offY) + 'px';}}

/* -------------------------------------------------------------------------------------------------------- *\
   Write file log
\* -------------------------------------------------------------------------------------------------------- */
function WriteLog(sMessage, sSessionId)
{

  YAHOO.util.CrossFrame.send("http://miniclip.dofus.com/proxy.php?PHPSESSID=" + sSessionId,
                               "parent",
                               "0_" + sMessage);

}


var AsGetRating = function(o)
{
      
}

var Failure = function(o)
{
}

function DoBannerWrite(sMessage, sSessionId)
{
  var sKey = "";
  var oAjaxCall = 
  { 
    success  : AsGetRating, 
    failure  : Failure,
    argument : sKey
  };
  
  var oRequest = YAHOO.util.Connect.asyncRequest('POST', "/customer/proxy.php?PHPSESSID=" + sSessionId, oAjaxCall, "message=" + sMessage); 

}

/* -------------------------------------------------------------------------------------------------------- *\
   Check 5 seconds
\* -------------------------------------------------------------------------------------------------------- */
function startTimer()
{ 
  clearInterval(timer);
  timer = setInterval("CheckSeconds()", 5000);      
}

function stopTimer()
{
  clearInterval(timer);
}

function CheckSeconds()
{
  WriteLog('customernoanswer');
}


function ShowHeight()
{
  GI('load_swf').style.height = '0px';
  GI('load_img').style.height = '0px';
  GI('loader').style.height = '556px';
  WriteLog("customer_resize_ie");
  clearInterval(timerHeight);
}

function DownloadOs()
{
  if(navigator.appVersion.indexOf('Windows',0) > 0)
    window.document.location.href = "http://download.dofus.com/full/win/";
  else
    window.document.location.href = "http://download.dofus.com/full/zip/";
  pageTracker._trackPageview('/download.php');
}


/* -------------------------------------------------------------------------------------------------------- *\
   Help Username
\* -------------------------------------------------------------------------------------------------------- */
function UseUsername(sUsername, sSessionId)
{
  GI('login').value = sUsername;
  GI('check_login').style.display = 'none';
  DoBannerWrite('username_help;' + sUsername, sSessionId);
}