// ########## CRYPT MAIL ##########
function crypt(User){
 window.location.href="mailto:" + User + "@terra-octet.fr";
}

// ########## SHOW LOGIN ##########
function showLogin(){
  document.getElementById('form_login').style.display='block';
  document.getElementById('storage_li').setAttribute('class','active');
  document.getElementById('storage_li').setAttribute('class','active');
  var a = document.getElementById('storage_li').firstChild;
  if(a.nodeType == 3)
    a = a.nextSibling;
  
  a.setAttribute('class','active');
  
}

// ########## SHOW INFO ##########
function showInfo(id){
  document.getElementById(id).style.display = 'inline';
}

// ########## HIDE INFO ##########
function hideInfo(id){
  document.getElementById(id).style.display = 'none';
}

// ########## LISTEN SIGN IN ##########
function listenSignIn(){
  var email = document.getElementById('email');
  var login = document.getElementById('login');
  var password = document.getElementById('password');
  var confirm_password = document.getElementById('confirm_password');
  
  if(window.addEventListener) {
    email.addEventListener('keyup', function(){fillLogin(email.value)}, false);
    /*email.addEventListener('blur', function(){removeEvent(email,'keyup')}, true);*/
  }
  else if(window.attachEvent) {
    email.attachEvent('onkeyup', function(){fillLogin(email.value)});
    /*email.attachEvent('onblur', function(){removeEvent(email,'keyup')});*/
  }
  /*
  if(window.addEventListener) {
    login.addEventListener('keyup', function(){checkLogin(login)}, false);
  }
  else if(window.attachEvent) {
    login.attachEvent('onkeyup', function(){checkLogin(login)});
  }*/
  
  /*if(window.addEventListener) {
    login.addEventListener('keyup', function(){removeEvent(email,'keyup')}, false);
  }
  else if(window.attachEvent) {
    login.attachEvent('onkeyup', function(){removeEvent(email,'keyup')});
  }*/
  
  if(window.addEventListener) {
    password.addEventListener('keyup', function(){checkPasslength(password)}, false);
  }
  else if(window.attachEvent) {
    password.attachEvent('onkeyup', function(){checkPasslength(password)});
  }
  
  if(window.addEventListener) {
    confirm_password.addEventListener('keyup', function(){checkConfPass()}, false);
  }
  else if(window.attachEvent) {
    confirm_password.attachEvent('onkeyup', function(){checkConfPass()});
  }
}

// ########## CHECK LOGIN ##########
function checkLogin(input){
  var reg = new RegExp(/^\w+([\.\-_]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/);
  var res = reg.exec(input.value);
  if(!res){
    // String not ok
    input.setAttribute('class','warning');
    input.setAttribute('className','warning');
  }else{
    input.setAttribute('class','');
    input.setAttribute('className','');
  }
}

// ########## CHECK PASS LENGTH ##########
function checkPasslength(input){
  document.getElementById('balloon_confirm_pass').style.display = 'none';
  if(input.value.length < 6){
    document.getElementById('balloon_pass').style.display = 'block';
    document.getElementById('check_pass').style.display = 'none';
  }
  else{
    document.getElementById('balloon_pass').style.display = 'none';
    document.getElementById('check_pass').style.display = 'block';
    input.setAttribute('class','');
    input.setAttribute('className','');
    checkConfPass()
  }
}

// ########## CHECK CONF PASS ##########
function checkConfPass(){
  var password = document.getElementById('password');
  var conf_password = document.getElementById('confirm_password');
  if(password.value.length >= 6){
    password.setAttribute('class','');
    password.setAttribute('className','');
    if(conf_password.value != password.value || password.value == ''){
      document.getElementById('balloon_confirm_pass').style.display = 'block';
      document.getElementById('check_confirm_pass').style.display = 'none';
    }else{
      document.getElementById('balloon_confirm_pass').style.display = 'none';
      document.getElementById('check_confirm_pass').style.display = 'block';
    }
  }
  else{
    password.setAttribute('class','warning');
    password.setAttribute('className','warning');
  }
}

// ########## CONFIRM PASSWORD ##########
function confirmPassword(){
  var password = document.getElementById('password');
  if(password.value.length < 6){
    showInfo('balloon_pass');
    password.setAttribute('class','warning');
    password.setAttribute('className','warning');
  }
  if(document.getElementById('balloon_confirm_pass').value != password.value && password.value.length > 6){
    showInfo('balloon_confirm_pass');
    hideInfo('balloon_pass');
  }
}

// ########## FILL LOGIN ##########
function fillLogin(value){
  document.getElementById('login').value = value;
}
/*
function removeEvent(el, event, fct) {
  if(window.removeEventListener) {
    document.getElementById('company').removeEventListener('keyup', fillLogin, false);
  }
  else if(window.detachEvent) {
    el.detachEvent("on"+event, fillLogin);
  }
}
*/

// ########## NEXT TIP ##########
function nextTip(n){
  var next = n+1;
  var currentTip = document.getElementById('tip'+n);
  var nextTip = document.getElementById('tip'+next);
  
  var prevLink = document.getElementById('prev_tip');
  var nextLink = document.getElementById('next_tip');
  
  currentTip.style.display = 'none';
  nextTip.style.display = 'block';
  
  prevLink.setAttribute('onclick','return prevTip('+next+');');
  nextLink.setAttribute('onclick','return nextTip('+next+');');
  
  if(next == 2)
    prevLink.style.display = 'block';
  
  if(next == 8)
    nextLink.style.display = 'none';
  return false;
}

// ########## PREV TIP ##########
function prevTip(n){
  var prev = n-1;
  var currentTip = document.getElementById('tip'+n);
  var prevTip = document.getElementById('tip'+prev);
  
  var prevLink = document.getElementById('prev_tip');
  var nextLink = document.getElementById('next_tip');
  
  currentTip.style.display = 'none';
  prevTip.style.display = 'block';
  
  prevLink.setAttribute('onclick','return prevTip('+prev+');');
  nextLink.setAttribute('onclick','return nextTip('+prev+');');
  
  if(prev == 1)
    prevLink.style.display = 'none';
  
  if(prev == 7)
    nextLink.style.display = 'block';
  return false;
}

// ########## SHOW INTRA ##########
function showVat(item){
  if(item !== 0){
    document.getElementById('p_vat_number').style.display = 'block';
  }
  else{
    document.getElementById('p_vat_number').style.display = 'none';
  }
}

// ########## SHOW OS CHOICE VIDEO ##########
function showOsChoiceVideo(){
  if(document.getElementById('webdav_images').style.display == 'block'){
    document.getElementById('webdav_images').setAttribute('class','os_choice os_choice_screenshot');
    document.getElementById('webdav_images').setAttribute('className','os_choice os_choice_screenshot');
  }
  document.getElementById('webdav_video').style.display = 'block';
  document.getElementById('os_choice_video').onclick = function() {
    return hideOsChoiceVideo();
  }
  return false;
}

// ########## HIDE OS CHOICE VIDEO ##########
function hideOsChoiceVideo(){
  if(document.getElementById('webdav_images').style.display == 'block'){
    document.getElementById('webdav_images').setAttribute('class','os_choice os_choice_screenshot only_image');
    document.getElementById('webdav_images').setAttribute('className','os_choice os_choice_screenshot only_image');
  }
  document.getElementById('webdav_video').style.display = 'none';
  document.getElementById('os_choice_video').onclick = function() {
    return showOsChoiceVideo();
  }
  return false;
}

// ########## SHOW OS CHOICE IMAGE ##########
function showOsChoiceImage(){
  if(document.getElementById('webdav_video').style.display == 'none'){
    document.getElementById('webdav_images').setAttribute('class','os_choice os_choice_screenshot only_image');
    document.getElementById('webdav_images').setAttribute('className','os_choice os_choice_screenshot only_image');
  }
  document.getElementById('webdav_images').style.display = 'block';
  document.getElementById('os_choice_image').onclick = function() {
    return hideOsChoiceImage();
  }
  return false;
}

// ########## HIDE OS CHOICE IMAGE ##########
function hideOsChoiceImage(){
  document.getElementById('webdav_images').setAttribute('class','os_choice os_choice_screenshot');
  document.getElementById('webdav_images').setAttribute('className','os_choice os_choice_screenshot');
  document.getElementById('webdav_images').style.display = 'none';
  document.getElementById('os_choice_image').onclick = function() {
    return showOsChoiceImage();
  }
  return false;
}

if (typeof jQuery != 'undefined') {
  function nextMovie(newVideo){
    var activeBlock = $("#trailer li.active div");
    var activeVideoId = $(activeBlock).attr('id');
    
    $(activeBlock).parent().removeClass('active');
    $("#"+newVideo).parent().addClass('active');
    
    swfobject.removeSWF(activeVideoId);
    swfobject.embedSWF("/videos/"+newVideo+".swf", "swfMovie", "710", "210", "9.0.0",false,{allowScriptAccess:"sameDomain"},{wmode:"window",bgcolor:"#434343"});
  }
  $(document).ready(function(){
    $("#trailer li div").click(function(e){
      var activeBlock = $("#trailer li.active div");
      var activeVideoId = $(activeBlock).attr('id');
      var newVideo = $(this).attr("id");
      
      $(activeBlock).parent().removeClass('active');
      $(this).parent().addClass('active');
      
      swfobject.removeSWF(activeVideoId);
      swfobject.embedSWF("/videos/"+newVideo+".swf", "swfMovie", "710", "210", "9.0.0",false,{allowScriptAccess:"sameDomain"},{wmode:"window",bgcolor:"#434343"});
    });
  });
}
