﻿var h1 = 10; var h2 = 10; var hh = 126; var fh = 70;

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

function xClientWidth()
{
    var v=0,d=document,w=window;
    if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth)
    {v=d.documentElement.clientWidth;}
    else if(d.body && d.body.clientWidth)
    {v=d.body.clientWidth;}
    else if(xDef(w.innerWidth,w.innerHeight,d.height)) {
    v=w.innerWidth;
    if(d.height>w.innerHeight) v-=16;
    }
    return v;
}

function xClientHeight()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight)
    {v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
    {v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
    v=w.innerHeight;
    if(d.width>w.innerWidth) v-=16;
  }
  return v;
}

function xHeight(e,h)
{
    if(!(e=xGetElementById(e))) return 0;
    if (xNum(h)) {
    if (h<0) h = 0;
    else h=Math.round(h);
    }
    else h=-1;
    var css=xDef(e.style);
    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    h = xClientHeight();
    }
    else if(css && xDef(e.offsetHeight) && xStr(e.style.height)) {
    if(h>=0) {
      var pt=0,pb=0,bt=0,bb=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pt=gcs(e,'padding-top',1);
        if (pt !== null) {
          pb=gcs(e,'padding-bottom',1);
          bt=gcs(e,'border-top-width',1);
          bb=gcs(e,'border-bottom-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetHeight,e.style.height)){
          e.style.height=h+'px';
          pt=e.offsetHeight-h;
        }
      }
      h-=(pt+pb+bt+bb);
      if(isNaN(h)||h<0) return;
      else e.style.height=h+'px';
    }
    h=e.offsetHeight;
    }
    else if(css && xDef(e.style.pixelHeight)) {
    if(h>=0) e.style.pixelHeight=h;
    h=e.style.pixelHeight;
    }
    return h;
}

function xShow(e) {return xVisibility(e,1);}

function xVisibility(e, bShow)
{
    if(!(e=xGetElementById(e))) return null;
    if(e.style && xDef(e.style.visibility)) {
    if (xDef(bShow)) e.style.visibility = bShow ? 'visible' : 'hidden';
    return e.style.visibility;
    }
    return null;
}

function xGetElementById(e)
{
    if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
    }
    return e;
}

function xDef()
{
    for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
    return true;
}

function xNum()
{
    for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
    return true;
}

function xStr(s)
{
    for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
    return true;
}

function xGetComputedStyle(e, p, i)
{
    if(!(e=xGetElementById(e))) return null;
    var s, v = 'undefined', dv = document.defaultView;
    if(dv && dv.getComputedStyle){
    s = dv.getComputedStyle(e,'');
    if (s) v = s.getPropertyValue(p);
    }
    else if(e.currentStyle) {
    v = e.currentStyle[xCamelize(p)];
    }
    else return null;
    return i ? (parseInt(v) || 0) : v;
}

function xCamelize(cssPropStr)
{
    var i, c, a = cssPropStr.split('-');
    var s = a[0];
    for (i=1; i<a.length; ++i) {
    c = a[i].charAt(0);
    s += a[i].replace(c, c.toUpperCase());
    }
    return s;
}

function xAddEventListener(e,eT,eL,cap)
{
    if(!(e=xGetElementById(e)))return;
    eT=eT.toLowerCase();
    if(e.addEventListener)e.addEventListener(eT,eL,cap||false);
    else if(e.attachEvent)e.attachEvent('on'+eT,eL);
    else {
    var o=e['on'+eT];
    e['on'+eT]=typeof o=='function' ? function(v){o(v);eL(v);} : eL;
    }
}

function adjustLayout()
{
    var cHeight = xHeight("contentcontent");
    var lHeight = xHeight("leftcontent");
    var rHeight = xHeight("rightcontent");
    var maxHeight = Math.max(cHeight, Math.max(lHeight, rHeight));
    var h = xClientHeight();
    var remain = h - (h1 + h2 + hh + fh + maxHeight) - 5;
    if (is_ie6) remain -= 30;
    if (remain > 0) maxHeight = maxHeight + remain;
    xHeight("main", maxHeight);
    xShow("home_footer");
    var maxWidth = xDocWidth();
    xWidth("header", maxWidth);
    xWidth("main", maxWidth);
    xWidth("home_footer", maxWidth);
}

window.onload = function()
{
    xAddEventListener(window, "resize", adjustLayout, false);
    adjustLayout();
}

function deleteCartItem(productid)
{
    xGetElementById(hdnProductId).value = productid;
    xGetElementById("aspnetForm").submit();
}

function xDocWidth()
{
    var b=document.body, e=document.documentElement; var esw=0, eow=0, bsw=0, bow=0, sbw=0, docWidth;
    if (e) { esw = e.scrollWidth; eow = e.offsetWidth; } if (b) { bsw = b.scrollWidth; bow = b.offsetWidth; }
    docWidth = Math.max(esw,eow,bsw,bow); if (is_ie) { sbw = getScrollBarWidth(); if (docWidth > xClientWidth()+sbw) sbw=0; } docWidth -= sbw; return docWidth;
}

function getScrollBarWidth() {
    var inner = document.createElement('p'); inner.style.width = "100%"; inner.style.height = "200px"; var outer = document.createElement('div'); outer.style.position = "absolute"; outer.style.top = "0px"; outer.style.left = "0px"; outer.style.visibility = "hidden"; outer.style.width = "200px";
    outer.style.height = "150px"; outer.style.overflow = "hidden"; outer.appendChild (inner); document.body.appendChild (outer); var w1 = inner.offsetWidth; outer.style.overflow = 'scroll'; var w2 = inner.offsetWidth; if (w1 == w2) w2 = outer.clientWidth; document.body.removeChild(outer); return (w1 - w2); }

function xWidth(e,w)
{
    if(!(e=xGetElementById(e))) return 0;
    if (xNum(w)) {
    if (w<0) w = 0;
    else w=Math.round(w);
    }
    else w=-1;
    var css=xDef(e.style);
    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = xClientWidth();
    }
    else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(w>=0) {
      var pl=0,pr=0,bl=0,br=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pl=gcs(e,'padding-left',1);
        if (pl !== null) {
          pr=gcs(e,'padding-right',1);
          bl=gcs(e,'border-left-width',1);
          br=gcs(e,'border-right-width',1);
        }
        else if(xDef(e.offsetWidth,e.style.width)){
          e.style.width=w+'px';
          pl=e.offsetWidth-w;
        }
      }
      w-=(pl+pr+bl+br);
      if(isNaN(w)||w<0) return;
      else e.style.width=w+'px';
    }
    w=e.offsetWidth;
    }
    else if(css && xDef(e.style.pixelWidth)) {
    if(w>=0) e.style.pixelWidth=w;
    w=e.style.pixelWidth;
    }
    return w;
}

function xWindow(name, w, h, x, y, loc, men, res, scr, sta, too)
{
  var e='',c=',',xf='left=',yf='top='; this.n = name;
  if (document.layers) {xf='screenX='; yf='screenY=';}
  this.f = (w?'width='+w+c:e)+(h?'height='+h+c:e)+(x>=0?xf+x+c:e)+
    (y>=0?yf+y+c:e)+'location='+loc+',menubar='+men+',resizable='+res+
    ',scrollbars='+scr+',status='+sta+',toolbar='+too;
  this.opened = function() {return this.w && !this.w.closed;};
  this.close = function() {if(this.opened()) this.w.close();};
  this.focus = function() {if(this.opened()) this.w.focus();};
  this.load = function(sUrl) {
    if (this.opened()) this.w.location.href = sUrl;
    else this.w = window.open(sUrl,this.n,this.f);
    this.focus();
    return false;
  };
}
var win =  new xWindow('', 550, 400, 210, 190, 0, 0, 0, 1, 0, 0);
var win2 =  new xWindow('', 570, 320, 210, 190, 0, 0, 0, 1, 0, 0);

var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();