function moveContainer(source, destination) {  
  if (source != null && destination != null) {    
    var replaceElementId = "replaceContainer";
    var replaceElement = document.createElement("div");
    replaceElement.setAttribute("id", replaceElementId);
    destination.appendChild(replaceElement);
    destination.replaceChild(source, replaceElement);
  }
}

function $(id) {
  return document.getElementById(id);
}

function confirmChangeLocation(message, url) {
  if(confirm(message)) location.href = url;
}

function confirmation(message) {
  if (confirm(message))  {
    return true;    
  } else {
    return false;   
  }
}

  
function show(id){
  if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "none"){
      obj.style.display = "block";
    } else {
      obj.style.display = "none";
    }
  }
}

function display(id) {
  if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "none") {
      obj.style.display = "block";
    }
  }
}

function hide(id) {
  if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "block") {
      obj.style.display = "none";
    }
  }
}

function loadContent() {
  if (document.getElementById) {  // DOM3 = IE5, NS6
    document.getElementById('hidepage').style.display = 'none';
    document.getElementById('main').style.display = 'block';
  }
  else {
    if (document.layers) {  // Netscape 4
      document.hidepage.display = 'none';
    }
    else {  // IE 4
      document.all.hidepage.style.display = 'none';
    }
  }
}

function loadContent2() {
    document.getElementById('hidepage').style.display = 'none';
    document.getElementById('main').style.display = 'block';
}

function initSelect(id, from, to, step, selected) {  
  var select = $(id);
  if (select != null && from != null && to != null) {
    if (step > 0) {
      var index = 0;
      for (var i = from; i <= to; i += step) {
        if (i == selected) {
          select[index] = new Option(i, i, true);
        } else {
          select[index] = new Option(i, i, false);          
        }
        index ++;
      }
    }
  }
}
  
function removeItem(childId, parentId) {
  var nElement = document.getElementById(childId);
  var nParent = document.getElementById(parentId);
  nParent.removeChild(nElement);
  if (childId == defEmail) {
    defEmail = 0;
  }
}

function removeElement(id) {
  var element = document.getElementById(id);
  if (element != null) {
    element.parentNode.removeChild(element);
  }
}

function removeChildren(id) {
  var node = document.getElementById(id);
  if (node == undefined || node == null) {
    return;
  }
  var len = node.childNodes.length;
  for(var i = 0; i < len; i++)  {
    node.removeChild(node.childNodes[i]);
  }
}

function showHideElement(id) {
  var element = $(id);
                
  if (element !== undefined && element !== null) {
    if (element.style.display != "block") {
      element.style.display = "block";
    } else {
      element.style.display = "none";
    }
  }
}

function formatPrice(price) {
  return Math.round(price * 100)/100;  
}

function getVar(name) {
  var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&";
  if (infos.indexOf("#")!=-1) {
    infos = infos.substring(0,infos.indexOf("#"))+"&";
  }
  var value=0;
  name = name + "=";
  var size = name.length;
  if (infos.indexOf(name)!=-1) {
    value = infos.substring(infos.indexOf(name)+size,infos.length).substring(0,infos.substring(infos.indexOf(name)+size,infos.length).indexOf("&"));
  }
  return unescape(value);
}

function fieldSizeController(elementId, controllerId, maxSize) {
  var element = $(elementId);
  var controller = $(controllerId);

  if (element != null && controller != null && maxSize > 0) {
    var sizeNow = element.value.length;
    if (sizeNow > maxSize) {
      element.value = element.value.substring(0, maxSize);
      controller.value = 0;
    } else {
      controller.value = maxSize - sizeNow;
    }
  }
}


/*
 * message: message in the box.
 * boxType: message, warning, error.
 * trueButtonMessage: message of button which returns true.
 * falseButtonMessage: message of button which returns false.
 * defaultButton: true or false.
 */
function msgbox(message, boxType, trueButtonMessage, falseButtonMessage, defaultButton, callback) {
  msgboxCallback = callback;
   
  var mainDiv = $('main');
  var mainDivHeight = document.getElementById('main').offsetHeight;
  var urlDiv = 'partissimo1';
  var newDiv = document.createElement('div');
  newDiv.setAttribute('id', msgboxFrame);
  newDiv.style.height = mainDivHeight+'px';
  newDiv.innerHTML = '<div id=\'infoFrameContainer\'>\n\
</div><div id=\'infoFrameBox\'>\n\
<div id=\'infoFrameTitle\'>'+boxType+'</div><div id=\'infoFrameContent\'>'+message+'\
</div><div id=\'infoFrameButtons\'>\n\
  <input id=\'infoFrameButtonTrue\' type=\'button\' value=\'' + trueButtonMessage + '\'onclick="removeMsgbox(true);return false;"/>\n\
  <input id=\'infoFrameButtonFalse\' type=\'button\' value=\'' + falseButtonMessage +  '\' onclick="removeMsgbox(false);return false;"/>\n\
</div>\n\
</div>';
  mainDiv.appendChild(newDiv);
  $('infoFrameContainer').style.height = mainDivHeight+'px';
  var titleDiv = $('infoFrameTitle');
  titleDiv.style.backgroundImage = 'url(/pages/themes/'+urlDiv+'/backend/images/'+boxType+'.gif)';
  titleDiv.style.backgroundRepeat = 'no-repeat';
  titleDiv.style.backgroundPosition = '5px center';
  titleDiv.style.paddingLeft = '25px';
  $('infoFrameButtonTrue').style.marginLeft = '15px';
  $('infoFrameButtonFalse').style.marginLeft = '15px';
  if (defaultButton == true) {
    $('infoFrameButtonTrue').style.backgroundColor = '#307DB7';
    $('infoFrameButtonTrue').style.color = '#FFF';
  }  else  {    
    $('infoFrameButtonFalse').style.backgroundColor = '#307DB7';
    $('infoFrameButtonFalse').style.color = '#FFF';
  }
}

function removeMsgbox(result) {
  removeElement(msgboxFrame);
  msgboxCallback(result);
  msgboxCallback = null;  
}

var cancel = false;
var msgboxCallback = null;
var msgboxFrame = 'msgboxFrame';

function tradeinChangeImage (elem) {
  var par = "";
  par = elem.parentNode.parentNode.className;
  var strHtm = elem.src;
  strHtm = strHtm.replace("thumbnails", "images");
  document.getElementById('tradeImage_'+ par).innerHTML = "<img src='" + strHtm + "'>";
}