/*
  This function shows the different delivery address
  fields on the register page via checkout
*/
function displayDifferentDeliveryAddress(type, element)
{
  if(type == 'show')
  {
    if(document.getElementById(element)) document.getElementById(element).style.display = '';
    if(document.getElementById(element+'_header')) document.getElementById(element+'_header').style.display = '';
  }
  else
  {
    if(document.getElementById(element)) document.getElementById(element).style.display = 'none';
    if(document.getElementById(element+'_header')) document.getElementById(element+'_header').style.display = 'none';
  }
}

/*
  This function shows the different messages
  when changing quantity via basket
*/
function changeQuantity(iKey,strDirection)
{
  if (strDirection == 'plus')
  {
    if(((arrBasket[iKey]['quantity']+1) > arrBasket[iKey]['stock']) && arrBasket[iKey]['stock'] != -1)
    {
      alert(arrBasket[iKey]['title']+'\n\nSorry, we currently only have '+arrBasket[iKey]['stock']+' of this item in stock');
      return false;
    }
    else
    {
      return true;
    }
  }
  else if (strDirection == 'minus')
  {
    if((arrBasket[iKey]['quantity'] == 1))
    {
      if (confirm("Are you sure you want to remove this item from your basket?\n\nClick \"OK\" for Yes or \"Cancel\" for No"))
      {
        return true;
      }
      else
      {
        return false;
      }
      return false;
    }
    else
    {
      return true;
    }
  }

  //Should never get here
  return true;
}

/*
  This function shows the different messages
  when remove items via basket
*/
function removeItem(iKey)
{
  if (confirm("Are you sure you want to remove this item from your basket?\n\nClick \"OK\" for Yes or \"Cancel\" for No"))
  {
    return true;
  }
  else
  {
    return false;
  }
}

function popupWindow(url,width,height)
{
  LeftPosition = (screen.width) ? (screen.width-500)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-500)/2 : 0;

  settings = 'height='+height+',width='+width+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1';
  win = window.open(url,null,settings);

  return false;
}

function switch_promo(promo)
{
  document.getElementById('promo_unit_1').style.display = 'none';
  document.getElementById('promo_unit_2').style.display = 'none';
  document.getElementById('promo_unit_3').style.display = 'none';
  document.getElementById('promo_unit_4').style.display = 'none';
  document.getElementById('promo_unit_'+promo).style.display = '';
  
  for(i = 1; i < 5; i++)
  {
    document.getElementById('promo_tab_'+i).src='/images/img_tab_'+i+'_off.gif';
  }
  document.getElementById('promo_tab_'+promo).src='/images/img_tab_'+promo+'_on.gif';
}


function addToFavorites(url,name)
{
  if(window.sidebar && window.sidebar.addPanel) 
  {
    window.sidebar.addPanel(name,url,'');
  } 
  else if(window.opera && window.print) 
  { 
    var e=document.createElement('a');
    e.setAttribute('href',url);
    e.setAttribute('title',name);
    e.setAttribute('rel','sidebar');
    e.click();
  } 
  else if(window.external) 
  {
    try 
    {
      window.external.AddFavorite(url,name);
    }
    catch(e)
    {
    }
  }
  else
  {
    alert("To add our website to your bookmarks use CTRL+D on Windows and Linux and Command+D on the Mac.");
  }
}
