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 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 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);
}

var cancel = false;


/*
 * 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 = document.getElementById('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);
  document.getElementById('infoFrameContainer').style.height = mainDivHeight+'px';
  var titleDiv = document.getElementById('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';
  document.getElementById('infoFrameButtonTrue').style.marginLeft = '15px';
  document.getElementById('infoFrameButtonFalse').style.marginLeft = '15px';
  if (defaultButton == true) {
    document.getElementById('infoFrameButtonTrue').style.backgroundColor = '#307DB7';
    document.getElementById('infoFrameButtonTrue').style.color = '#FFF';
  } else  {
    document.getElementById('infoFrameButtonFalse').style.backgroundColor = '#307DB7';
    document.getElementById('infoFrameButtonFalse').style.color = '#FFF';
  }
}

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

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

function addVideo (videoUrl, videoWidth, videoHeight) {
  var videoWidthInit = videoWidth != undefined ? videoWidth: "490";
  var videoHeightInit = videoHeight != undefined ? videoHeight : "390";
  var myVideo = $.flash.create({
    swf: "/scripts/swf/video.swf",
    width: videoWidthInit,
    height: videoHeightInit,
    flashvars:
    {
      source: videoUrl,
      autoplay:"false"
    },
    params:
    {
      scale: "noscale",
      salign: "tl",
      menu: "false",
      wmode: "opaque",
      bgcolor: "#dddddd"
    },
    attributes: {
      id: "swf"
    }
  });
  return myVideo;
}

function addYoutube (videoCode, videoWidth, videoHeight) {
  var videoWidthInit = videoWidth != undefined ? videoWidth: "490";
  var videoHeightInit = videoHeight != undefined ? videoHeight : "390";
  var myVideo = $.flash.create({
    swf: "http://www.youtube.com/v/" + videoCode + "?&enablejsapi=1&playerapiid=ytplayer&autoplay=0",
    width: videoWidthInit,
    height: videoHeightInit,
    params:
    {
      allowScriptAccess: "always"
    },
    attributes: {
      id: "swf"
    }
  });
  return myVideo;
}


function addAudio (audioFile, audioWidth, audioHeight) {
  var audioWidthInit = audioWidth != undefined ? audioWidth: "490";
  var audioHeightInit = audioHeight != undefined ? audioHeight : "80";
  var myAudio = $.flash.create({
    swf: "/scripts/swf/music.swf",
    width: audioWidthInit,
    height: audioHeightInit,
    flashvars:
    {
      url:audioFile,
      title:"Audio",
      width:audioWidthInit,
      height:audioHeightInit
    }
  });
  alert(myAudio);
  return myAudio;
}
