
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popupWindow2(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=0,resizable=no,copyhistory=no,width=360,height=600,screenX=150,screenY=150,top=150,left=150');
}

function popupWindow3(url) {
  window.open(url,'SealVerfication','location=yes,status=yes,resizable=yes,scrollbars=no,width=560,height=322');
}

function popupWindow4(url) {
  return window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=350,height=350,screenX=150,screenY=150,top=150,left=150');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*******************************
  NEW ITEMS BELOW - 2008-05-15
*******************************/

  function pop_product_image(id,img_path) {
    img_window = window.open('','img_'+id,'height=550,width=550,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no'); img_window.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd"><html xmlns="http:\/\/www.w3.org\/1999\/xhtml">');
    img_window.document.write('<head><title>Image for Product #'+id+'<\/title><\/head><body style="overflow:hidden; margin: 25px;" bgcolor="#ffffff"><img src="'+img_path+'" style="border: 1px solid #666666;">');
    img_window.document.write('<\/body><\/html>');
  }

  function changeImage(id) {
    var i  = document.getElementById('image-main');
    var b  = document.getElementById('images-big-'+id);
    var m  = document.getElementById('images-main-'+id);
    var mw = document.getElementById('image-main-'+id+'-width');
    var mh = document.getElementById('image-main-'+id+'-height');
    var bn = document.getElementById('image-big-now');
    var bw = document.getElementById('image-big-width-now');
    var bh = document.getElementById('image-big-height-now');
    var a  = document.getElementById('image-main-link');
    var w  = document.getElementById('images-big-'+id+'-width');
    var h  = document.getElementById('images-big-'+id+'-height');

    MM_swapImage('image-main','',m.innerHTML,1);

    bn.innerHTML = b.innerHTML;
    bw.innerHTML = w.innerHTML;
    bh.innerHTML = h.innerHTML;

    document.getElementById('image-main').width  = mw.innerHTML;
    document.getElementById('image-main').height = mh.innerHTML;
    $('image-main').parentNode.href = bn.innerHTML;
  }

/* Cookie management, borrowed from quirksmode.org */

function createCookie(name, value, days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}

/* Starting point:
 *
 * http://www.safalra.com/web-design/javascript/collapsible-lists/
 *
 * $Id$
 */

var CLOSED_IMAGE = 'catalog/view/theme/riecktron/image/category_arrow_right.gif';
var OPEN_IMAGE =  'catalog/view/theme/riecktron/image/category_arrow_down.gif';
var EMPTY_IMAGE = 'catalog/view/theme/riecktron/image/category_arrow_none.gif';

/* makeCollapsible - makes a list have collapsible sublists
 *
 * listElement - the element representing the list to make collapsible
 */
function makeCategoryTree(listElement)
{
  // loop over all child elements of the list
  var child = listElement.firstChild;

  while (child != null) {

    // only process li elements (and not text elements)
    if (child.nodeType == 1) {

      // Handle cookies:
      if (child.id) {
        var storedState = readCookie(child.id);
        if (storedState /* && ( child.className != 'open' )*/ )
          child.className = storedState;
      }

      var imageSrc;
      switch (child.className) {
        case 'open'   : imageSrc = OPEN_IMAGE;   break;
        case 'closed' : imageSrc = CLOSED_IMAGE; break;
        default       : imageSrc = EMPTY_IMAGE;
      }

      // add buttons
      var image = document.createElement('img');
      image.setAttribute('src', imageSrc);
      image.id = child.id + '_toggle';

      if (child.className == 'closed' || child.className == 'open') {
        image.onclick = treeToggleFunction(image, child);
        child.firstChild.onclick = treeOpenFunction(image, child);
        image.className = 'cattree';
      } else {
        image.className = 'cattree_empty';
      }

      child.insertBefore(image, child.firstChild);
    }

    child = child.nextSibling;
  }

}

/* createToggleFunction
 * returns a function that toggles sublist display
 * and stores state in a cookie
 *
 * toggleElement - the element representing the toggle gadget
 * listElement - the collapsible <li>
 */
function treeToggleFunction(toggleElement, listElement)
{
  return function(cookie)
  {
    var cookie = (cookie == null) ? true : cookie;

    // toggle status of toggle gadget
    if (listElement.className == 'closed') {
      toggleElement.setAttribute('src', OPEN_IMAGE);
      if (cookie) createCookie(listElement.id, 'open', 360);
      newClass = 'open';
    } else {
      toggleElement.setAttribute('src', CLOSED_IMAGE);
      if (cookie) createCookie(listElement.id, 'closed', 360);
      newClass = 'closed';
    }

    // toggle display of sublists
    listElement.className = newClass;
  }
}
function treeOpenFunction(toggleElement, listElement)
{
  return function(cookie)
  {
    var cookie = (cookie == null) ? true : cookie;

    // toggle status of toggle gadget
    if (listElement.className == 'closed') {
      toggleElement.setAttribute('src', OPEN_IMAGE);
      if (cookie) createCookie(listElement.id, 'open', 360);
      newClass = 'open';
    }

    // toggle display of sublists
    listElement.className = newClass;
  }
}

