function changeCurrency(c) { document.location.href='quixpo.php?d=USER/SETCURRENCY&r='+encodeURIComponent(referer)+'&cur='+c; }
function changeLanguage(l) { document.location.href='quixpo.php?d=USER/SETLANGUAGE&r='+encodeURIComponent(referer)+'&lang='+l; }
function setGridSize(val) { document.location.href='quixpo.php?d=GRID/SETGRIDSIZE&r='+encodeURIComponent(referer)+'&horizontal=1&vertical='+val; }
function pleaseLogin() { alert(lcl_login); }

// WISHLISTS

function create_wishlist()
{
  var w_name = prompt(lcl_new_wishlist);
  if (w_name)
    document.location.href='/quixpo.php?d=WISHLIST/ADD&destination=wishlist&name=' + encodeURIComponent(w_name);
}

function change_wishlist(id)
{
  if (!isNaN(id))
    document.location.href='/wishlist.php?wishlist=' + id
}

function rename_wishlist(id)
{
  if (!isNaN(id))
  {
    var w_name = prompt(lcl_rename_wishlist);
    if (w_name)
      document.location.href='/quixpo.php?d=WISHLIST/RENAME&destination=wishlist&wishlist='+id+'&name=' + encodeURIComponent(w_name);
  }
}

function remove_wishlist(id)
{
  if (!isNaN(id))
  {
    var confirmation = confirm(lcl_remove_wishlist);
    if (confirmation)
      document.location.href='/quixpo.php?d=WISHLIST/REMOVE&destination=wishlist&wishlist='+id;
  }
}

function wishlist_selection(action)
{
  var elements = document.getElementsByTagName('input');
  for (x=0 ; x<elements.length ; x++)
  {
    var el = elements[x];
    if (el.type == 'checkbox' && el.name.substring(0,6) == 'asset-')
      el.checked = action;
  }
}

function wishlist_get_selection()
{
  var assets = new Array();
  var elements = document.getElementsByTagName('input');
  for (x=0 ; x<elements.length ; x++)
  {
    var el = elements[x];
    if (el.type == 'checkbox' && el.checked && el.name.substring(0,6) == 'asset-')
    {
       assets[assets.length] = el.name.substring(6);
    }
  }
  return assets;
}

function wishlist_remove_selection(id)
{
  if (!isNaN(id))
  {
    var selection = wishlist_get_selection();
    if (selection.length > 0)
    {
      var confirmation = confirm(lcl_remove_assets.replace(/%s/g, selection.length));
      if (confirmation)
        document.location.href='/quixpo.php?d=WISHLIST/REMOVEASSETS&destination=wishlist&wishlist='+id+'&assets=' + selection.join(',');
    }
  }
}

function wishlist_action(id)
{
  if (!isNaN(id))
  {
    var selection = wishlist_get_selection();
    if (selection.length > 0)
    {
      var dst = document.forms.actionform.destination_wishlist.value;
      var action = '';
      if (document.forms.actionform.the_action[0].checked)
        action = 'COPY';
      if (document.forms.actionform.the_action[1].checked)
        action = 'MOVE';
      if (action != '')
        document.location.href='/quixpo.php?d=WISHLIST/ACTONASSETS&r='+encodeURIComponent(referer)+'&source_wishlist='+id+'&destination_wishlist='+dst+'&assets=' +selection.join(',') + '&action=' + action;
    }    
  }
}

var wishlist_slideshow_current = 0;
var wishlist_timeout_id;
var wishlist_slideshow_navbartext = '';
function wishlist_slideshow()
{
    var selection = wishlist_get_selection();
    if (selection.length > 0)
    {
      if (document.getElementById('subnav').style.display != 'none') { document.getElementById('subnav').style.display = 'none'; }
      if (document.getElementById('wishlist-grid').style.display != 'none') { document.getElementById('wishlist-grid').style.display = 'none'; }
      if (document.getElementById('block-edit').style.display != 'none') { document.getElementById('block-edit').style.display = 'none'; }
      if (document.getElementById('wishlist-slideshow').style.display != 'block') { document.getElementById('wishlist-slideshow').style.display = 'block'; }
      if (document.getElementById('block-slideshow').style.display != 'block') { document.getElementById('block-slideshow').style.display = 'block'; }
      if (wishlist_slideshow_navbartext == '') { wishlist_slideshow_navbartext = document.getElementById('slideshow-showing').innerHTML; }
      document.getElementById('wishlist-slideshow-img').src = '/assets/' + slideshow_size + '/' + selection[wishlist_slideshow_current] + '.jpg';
      var str = lcl_wishlist_showing.replace(/%current/g, (wishlist_slideshow_current+1)).replace(/%total/g, selection.length);
      document.getElementById('slideshow-showing').innerHTML = str;
      wishlist_slideshow_current++;
      if (wishlist_slideshow_current >= selection.length)
        wishlist_slideshow_current = 0
      wishlist_timeout_id = window.setTimeout(wishlist_slideshow, slideshow_interval*1000);
    }
}

function wishlist_slideshow_interval(s)
{
  window.clearTimeout(wishlist_timeout_id);
  if (s != 0)
  {
    slideshow_interval = s;
    wishlist_slideshow();
  }
}

function wishlist_slideshow_close()
{
  window.clearTimeout(wishlist_timeout_id);
  document.getElementById('slideshow-showing').innerHTML = wishlist_slideshow_navbartext;
  wishlist_slideshow_navbartext = '';
  wishlist_slideshow_current = 0;
  document.getElementById('block-edit').style.display = 'block';
  document.getElementById('block-slideshow').style.display = 'none';
  document.getElementById('wishlist-grid').style.display = 'block';
  document.getElementById('wishlist-slideshow').style.display = 'none';
  document.getElementById('subnav').style.display = 'block';
}

function wishlist_buy_selection(id)
{
  if (!isNaN(id))
  {
    var selection = wishlist_get_selection();
    if (selection.length > 0)
      document.location.href='/quixpo.php?d=SHOP/PUTINBASKET&destination=wishlist&wishlist='+id+'&id=' + selection.join(',') + '&dd=0';
  }
}

// SEARCH

function toggleSearch(mode)
{
  if (mode == 'text')
  {
    document.getElementById('search-assets').style.display='none';
    document.getElementById('search-site').style.display='block';
    document.getElementById('search-input-text').focus();
  }
  else if (mode == 'assets')
  {
    document.getElementById('search-site').style.display='none';
    document.getElementById('search-assets').style.display='block';
    document.getElementById('search-input-assets').focus();
  }
}

var search_catselectors_shown = 0;
function appendCatselector()
{
  var div = document.getElementById('catselection');
  if (div)
  {
    var p = document.createElement('p');
    var select = document.createElement('select');
    select.id = 'cat-'+search_catselectors_shown;
    select.onchange = doCatSelection;
    for (x in cats)
    {
      var opt = document.createElement('option');
      opt.value = x
      opt.appendChild(document.createTextNode(cats[x]));
      select.appendChild(opt);
    }
    p.appendChild(select);

    if (search_catselectors_shown == 0)
    {
      var plusbtn = document.createElement('input');
      plusbtn.type='button';
      plusbtn.value='+';
      plusbtn.onclick=appendCatselector;
      p.appendChild(document.createTextNode('   '));
      p.appendChild(plusbtn);
    }
    div.appendChild(p);
    search_catselectors_shown++;
  }
}

function doCatSelection()
{
  var cats = document.getElementById('search-cats');
  if (cats)
  {
    var tmp = new Array();
    var selects = document.getElementsByTagName('select');
    for (var x=0 ; x<selects.length ; x++)
    {
      var s = selects[x];
      if (s.id.substring(0,4) == 'cat-' && s.value != '')
        tmp[tmp.length] = s.value;
    }
    cats.value = tmp.join(',');
  }
}

// PROFILE

function profileEmail()
{
  toggleDiv('profilePass', 'none');
  toggleDiv('profilePrefs', 'none');
  toggleDiv('profileEmail', 'block');
}

function profilePass()
{
  toggleDiv('profilePrefs', 'none');
  toggleDiv('profileEmail', 'none');
  toggleDiv('profilePass', 'block');
}

function profilePrefs()
{
  toggleDiv('profileEmail', 'none');
  toggleDiv('profilePass', 'none');
  toggleDiv('profilePrefs', 'block');
}

function profileForgotPassword()
{
  toggleDiv('forgot', 'block');
}

function toggleDiv(id, state)
{
    var d = document.getElementById(id);
    if (d)
      d.style.display = state;
}

function validateRegistration()
{
   if (document.forms.regform.firstname.value == "" ||
	   document.forms.regform.lastname.value == "" ||
	   document.forms.regform.email.value == "" ||
	   document.forms.regform.password.value == "" ||
	   document.forms.regform.password_repeat.value == "")
   {
	 alert(lcl_allfields);
	 return;
   }
   if (document.forms.regform.password.value != document.forms.regform.password_repeat.value)
   {
	 alert(lcl_repeatpassword);
	 return;
   }
   document.forms.regform.submit();
}

// RATINGS

function validateRating()
{
  if (document.getElementById('StarRatingValue').value == 0)
  {
    alert(lcl_set_rating);
    return;
  }
  document.forms.ratingform.submit();
}

// ORDER

function paypalDummy()
{
  alert(lclPayPalDemosite);
  document.getElementById('offlinepayment').checked = true;
}

function validateStep3()
{
  var delivery_checked = false;
  var delivery = document.forms.orderform.delivery;
  if (delivery)
  {
    for (var x=0 ; x<delivery.length ; x++)
    {
      if (delivery[x].checked) { delivery_checked = true; break; }
    }
  }
  if (!delivery_checked)
    alert(lcl_select_delivery);
  else
    document.forms.orderform.submit();
}
