
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_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_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 addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            func();
            if (oldonload) {
                oldonload();
            }
        }
    }
}

function $(id)
{
    return document.getElementById(id);
}

function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}

function getWidth(obj)
{
    var width = obj.offsetWidth;
    if (width > 0)
        return width;
    if (!obj.firstChild)
        return 0;
    //return obj.parentNode.parentNode.offsetWidth;

    // use the left and right child instead
    return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + getWidth (obj.lastChild);
}

function getHeight(obj)
{
    var height = obj.offsetHeight;
    if (height > 0)
        return height;
    if (!obj.firstChild)
        return 0;
    // use the first child's height
    return obj.firstChild.offsetHeight;
}

function getXY(el)
{
    
    if (el.offsetParent == null) {
       return false;
    }
    
    var parentNode = null;
    var pos = [];
    var box;
    
    if (el.getBoundingClientRect) { // IE
       box = el.getBoundingClientRect();
       var doc = document;
       /*if ( !this.inDocument(el) && parent.document != document) {// might be in a frame, need to get its scroll
          doc = parent.document;
    
          if ( !this.isAncestor(doc.documentElement, el) ) {
             return false;
          }
    
       }*/
    
       var scrollTop = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
       var scrollLeft = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
    
       return [box.left + scrollLeft, box.top + scrollTop];
    }
    else { // safari, opera, & gecko
       pos = [el.offsetLeft, el.offsetTop];
       parentNode = el.offsetParent;
       if (parentNode != el) {
          while (parentNode) {
             pos[0] += parentNode.offsetLeft;
             pos[1] += parentNode.offsetTop;
             parentNode = parentNode.offsetParent;
          }
       }
       /*if (isSafari && el.style.position == 'absolute' ) { // safari doubles in some cases
          pos[0] -= document.body.offsetLeft;
          pos[1] -= document.body.offsetTop;
       }*/
    }
    
    if (el.parentNode) { parentNode = el.parentNode; }
    else { parentNode = null; }
    
    while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML')
    { // account for any scrolled ancestors
       if (parentNode.style.display != 'inline') { // work around opera inline scrollLeft/Top bug
          pos[0] -= parentNode.scrollLeft;
          pos[1] -= parentNode.scrollTop;
       }
    
       if (parentNode.parentNode) { parentNode = parentNode.parentNode; }
       else { parentNode = null; }
    }
    
    
    return pos;
}

function getDocHeight()
{

     var scrollHeight=-1, windowHeight=-1, bodyHeight=-1;

     var marginTop = 0;//parseInt(util.Dom.getStyle(document.body, 'marginTop'), 10);

     var marginBottom = 0;//parseInt(util.Dom.getStyle(document.body, 'marginBottom'), 10);



     var mode = document.compatMode;



     if ( (mode || getBrowser() == 'IE' || getBrowser() == 'IE7') && getBrowser() != 'opera' ) { // (IE, Gecko)

        switch (mode) {

           case 'CSS1Compat': // Standards mode

              scrollHeight = ((window.innerHeight && window.scrollMaxY) ?  window.innerHeight+window.scrollMaxY : - 1);

              windowHeight = [document.documentElement.clientHeight,self.innerHeight||-1].sort(function(a, b){return(a-b);})[1];

              bodyHeight = document.body.offsetHeight + marginTop + marginBottom;

              break;



           default: // Quirks

              scrollHeight = document.body.scrollHeight;

              bodyHeight = document.body.clientHeight;

        }

     } else { // Safari & Opera

        scrollHeight = document.documentElement.scrollHeight;

        windowHeight = self.innerHeight;

        bodyHeight = document.documentElement.clientHeight;

     }



     var h = [scrollHeight,windowHeight,bodyHeight].sort(function(a, b){return(a-b);});

     return h[2];

}

function getViewHeight()
{
    var height = -1;
    var mode = document.compatMode;

    if ( (mode || getBrowser() == 'IE' || getBrowser() == 'IE7') && getBrowser() != 'opera' ) 
    {
        switch (mode) 
        { // (IE, Gecko)
        case 'CSS1Compat': // Standards mode
            height = document.documentElement.clientHeight;
            break;
        default: // Quirks
            height = document.body.clientHeight;
        }
    } 
    else 
    { // Safari, Opera
        height = self.innerHeight;
    }

    return height;
}

function getViewWidth()
{
     var width = -1;
     var mode = document.compatMode;

     if (mode || getBrowser() == 'IE') { // (IE, Gecko, Opera)
        switch (mode) {
        case 'CSS1Compat': // Standards mode
           width = document.documentElement.clientWidth;
           break;

        default: // Quirks
           width = document.body.clientWidth;
        }
     } else { // Safari
        width = self.innerWidth;
     }
     return width;
  }

function getBrowser()
{
    var ua = navigator.userAgent.toLowerCase();
    
    if (ua.indexOf('msie 7')>-1)
    {
        return 'IE7';
    }
    
    if (ua.indexOf('opera')>-1)
    {
        return 'opera';
    }
    
    if (ua.indexOf('webkit')>-1)
    {
        return 'safari';
    }
    
    if (window.ActiveXObject)
    {
        return 'IE';
    }
    
    if (ua.indexOf('firefox')>-1)
    {
        return 'Firefox';
    }
    return false;
}

function changeItemProduct(name, price, image, update, quantity) {

	name = name.replace(/####/g, '"');
	price = price.replace(/####/g, '"');
	image = image.replace(/####/g, '"');
	update = update.replace(/####/g, '"');
	quantity = quantity.replace(/####/g, '"');

	document.getElementById('addItemName').innerHTML = name;
	document.getElementById('addItemPrice').innerHTML = price;
	document.getElementById('addMainItem').innerHTML = image;
	document.getElementById('addItemAction').innerHTML = update;
	document.getElementById('addItemQuantity').innerHTML = quantity;
}
