﻿function setRadio()
{
  if (document.getElementById("EcomCartShippingmethodID_SHIP2"))
  {
    mydiv = document.getElementById("ShipText");
    var elem = document.getElementById("ZipIncluded");
    if (elem.value == "0")
    {
      document.submitMethodData.EcomCartShippingmethodID_SHIP1.checked = true;
      document.submitMethodData.EcomCartShippingmethodID_SHIP2.disabled = true;
      mydiv.style.visibility = 'visible'; //to show it
    }

    else if (elem.value == "1")
    {
      document.submitMethodData.EcomCartShippingmethodID_SHIP1.disabled = false;
      document.submitMethodData.EcomCartShippingmethodID_SHIP2.checked = true;
      mydiv.style.visibility = 'hidden'; //to hide it
    }

  }
}

function setSize(elem, size)
{
  var img = new Image();
  img.src = elem.src;
  var ratio = 1;
  var w = size;
  var h = size;
  if (img.height > 0 && img.width > 0)
  {
    if (img.height > img.width)
    {
      ratio = img.width / img.height;
      w = size * ratio;
    }
    else
    {
      ratio = img.height / img.width;
      h = size * ratio;
    }
    elem.width = w;
    elem.height = h;
    elem.style.position = 'relative';
    elem.style.top = ((size - h) / 4) + 'px';
  }
}

function setSizeEx(elem, width, height)
{
  var img = new Image();
  img.src = elem.src;
  var ratio = 1;
  var w = width;
  var h = height;
  if (img.height > 0 && img.width > 0)
  {
    if (img.height > img.width)
    {
      ratio = img.width / img.height;
      w = h * ratio;
    }
    else
    {
      ratio = img.height / img.width;
      h = w * ratio;
    }
    elem.width = w;
    elem.height = h;
    elem.style.position = 'relative';
    elem.style.top = ((height - h) / 2) + 'px';
  }
}

function hideMoreElements()
{
  var tab = document.getElementById("bastekProducts");
  if (tab != null)
  {
    if (tab.rows.length > 3)
    {
      var rowsToHide = tab.rows.length - 3;
      for (i = 3; i < tab.rows.length; i++)
      {
        tab.rows[i].style.display = 'none';
      }
      var last = tab.rows.length;
      tab.insertRow(last);
      tab.rows[last].insertCell(0);
      tab.rows[last].cells[0].colSpan = 4;
      tab.rows[last].cells[0].align = "center";
      var anchorTag = document.createElement('a');
      var anchortext = document.createTextNode('klik for at se mere');
      anchorTag.appendChild(anchortext);
      anchorTag.href = "javascript:showMoreElements()";
      tab.rows[last].cells[0].appendChild(anchorTag);
    }
  }
}

function showMoreElements()
{
  var tab = document.getElementById("bastekProducts");
  if (tab.rows.length > 3)
  {
    var rowsToHide = tab.rows.length - 3;
    var hide = false;
    for (i = 3; i < tab.rows.length - 1; i++)
    {
      if (tab.rows[i].style.display == '')
      {
        tab.rows[i].style.display = 'none';
        hide = true;
      }
      else
        tab.rows[i].style.display = '';
    }
    var last = tab.rows.length - 1;
    var anchorTag = tab.rows[last].cells[0].childNodes[0].childNodes[0];

    anchorTag.nodeValue = "klik for at skjule";
    if (hide)
      anchorTag.nodeValue = "klik for at se mere";
  }
}

function clearElem(elem) { 
   if(elem.value=='Søg efter:'){ 
      elem.value = '';
   }
}

function fillElem(elem) {
  if(elem.value==''){ 
      elem.value = 'Søg efter:'; 
   }
}


