//
// Show confirmation box when deleting
//
function confirmdelete(type) {
    switch (type) {
        case 'image':
            return confirm('This image will be permanently removed from the server.\n\n\nAre you sure you want to delete this image?');
        case 'attribute':
            return confirm('This product variant will be permanently removed from the server.\n\n\nAre you sure you want to delete this variant?');
        default:
            return confirm('All product data will be lost. You can change the status to "hidden" and achieve the same result without losing data.\n\n\nAre you sure you still want to delete this product permanently?');
    }
}

//
// Toggle the visibility of a span element
//
function toggleDisplay(spanid,show) {
  var object = document.getElementById(spanid);

	switch (show) {
    case 'show':
      object.style.display = 'inline';
      break;
    case 'hide':
      object.style.display = 'none';
      break;
    default:
    	if (object.style.display == 'none') {
    		object.style.display = 'inline';
    	} else {
    		object.style.display = 'none';
    	}
    	break;
	}
}

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;

    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

function switchImage(imgName, imgSrc)
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

//
// find object
//
function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}