function toggle_block_display(blockId)
{
  obj = document.getElementById(blockId);

  if (!obj)
    return false;

  if (obj.style['display'] == '')
    obj.style['display'] = 'none';
  else
    obj.style['display'] = '';

  return false;
}

function toggle_menu_entry(blockId)
{
  obj = document.getElementById(blockId);

  if (!obj)
    return false;

  if (obj.style['display'] == '' || obj.style['display'] == 'block')
    obj.style['display'] = 'none';
  else
    obj.style['display'] = 'block';

  return false;
}

function set_block_display(blockId, displayState)
{
  obj = document.getElementById(blockId);
  obj.style['display'] = displayState;
  return false;
}

function toggle_all_block_display(tag, re)
{
  objList = document.getElementsByTagName(tag);

  for (i = 0; i < objList.length; i++)
  {
    obj = objList[i];
    id = obj.getAttribute('id');

    if (id && id.match(re))
      toggle_block_display(id);
  }
}

function toggle_input_checked(input, re)
{
  var state = input.checked;

  objList = document.getElementsByTagName('input');
  for (i = 0; i < objList.length; i++)
  {
    obj = objList[i];
    id = obj.getAttribute('id');

    if (id && id.match(re))
      obj.checked = state;
  }
}

function hide_all_address(selectObj, re)
{
  objList = document.getElementsByTagName('ul');

  for (i = 0; i < objList.length; i++)
  {
    obj = objList[i];
    id = obj.getAttribute('id');

    if (id && id.match(re))
      set_block_display(id, 'none');
  }
}


function popup( url, width, height ) {
	top_pos=screen.height/2-height/2;
	left_pos=screen.width/2-width/2;
	window.open(url, '', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left='+left_pos+',top='+top_pos);
	return false;
}
function popup_fixe( url, width, height, name ) {
	top_pos=screen.height/2-height/2;
	left_pos=screen.width/2-width/2;
	window.open(url, 'preview'+name, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,titlebar=0,resizable=yes,width='+width+',height='+height+',left='+left_pos+',top='+top_pos);
	return false;
}


function ask_quantity_more(f, msg) {
	if (f.options[f.selectedIndex].value == '+') {
		do {
			nbr_bout=prompt(msg + ' :','');
		} while ( nbr_bout!=null && !nbr_bout.match(/^\d+$/) );
		if ( nbr_bout ) {
			f.options[f.selectedIndex].value = nbr_bout;
			f.form.submit();
		} else {
			f.selectedIndex=0;
		}
	}
}
function compare_quantite(a, b, p) {
	aa = a*2;
	if (b%a!=0 || b <= 0) {
		if (p) {
		alert("Nous vous rappelons que pour les primeurs les commandes sont envoyées par caisse de "+a+" ou de "+aa+" bouteilles.\n"+
		"Nous vous invitons donc à commander par "+a+" bouteilles et multiples de "+a+".\n"+
		"Veuillez modifier votre quantité.\n"+
		"\n"+
		"Millésimes");
		return false;
		} else {
			alert("Ce vin est disponible à l'achat uniquement par lot de "+a+" produits,\n"+
				"Nous vous invitons à modifier votre quantité\n"+
				"\n"+
				"Millésimes");
			return false;
		}
	}
	return true;
}

function register_set_input_other(selectObj)
{
  var option = selectObj.options[selectObj.selectedIndex];
  if (option.text == 'Autre') {
    textObj = document.getElementById('source_autre');
    if (textObj) {
      textObj.style['display'] = '';
    } else {
      textObj = document.createElement('input');
      textObj.id = 'source_autre';
      textObj.name = 'source_autre';
      textObj.value = "Veuillez preciser";
      textObj.size = 50;
      textObj.setAttribute('maxlength', 255);
      textObj.onfocus = function ()
      {
        if (this.value == "Veuillez preciser")
          this.value = '';
      }
      textObj.onblur = function ()
      {
        if (this.value == '')
          this.value = "Veuillez preciser";
      }

      divObj = document.createElement('div');
      divObj.appendChild(textObj);

      nextObj = selectObj.nextSibling;
      selectObj.parentNode.insertBefore(divObj, nextObj);
    }
  } else {
    divObj = document.getElementById('source_autre');
    if (divObj)
      divObj.style['display'] = 'none';
  }
}
