function setCart() { this.w=131; this.h=70; this.l=30; this.t=465;
this.p="lt"; // положение на странице с учетом b_left и b_top (lt || lc || lb || ct || cc || cb || rt || rc || rb)
return this; }
document.cookie=" check_esm=on; path=/";

cart=new setCart();
var obj, obj_ind;

if( bw.ie && !bw.ie7 ) {
   // Конструктор индикатора для IE
   html_ind='';
   html_ind+='<style type="text/css">\n#eCartDiv { left:-'+cart.w+'px;top:-'+cart.h+'px;width:'+cart.w+'px;height:'+cart.h+'px;position:absolute;visibility:hidden; }\n</style>\n';
   html_ind+='<div id="eCartDiv"><iframe id="eCart" width="'+cart.w+'" height="'+cart.h+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe></div>';
   document.write(html_ind); obj=document.all["eCartDiv"].style; obj_ind=document.all["eCartDiv"].document.all["eCart"]; 
   
} else {
   obj = document.createElement( "DIV" );
   obj.id = "eCartDiv";
   obj.style.width      = cart.w;
   obj.style.height     = cart.h;
   obj.style.left       = cart.l;
   obj.style.top        = cart.t;
   obj.style.position   = "absolute";
   obj.style.visibility = "hidden";
   
   obj_ind = document.createElement( "IFRAME" );
   obj_ind.id = "eCart";
   obj_ind.width = cart.w;
   obj_ind.height = cart.h;
   obj_ind.marginWidth="0";
   obj_ind.marginHeight="0";
   obj_ind.scrolling="no";
   obj_ind.frameBorder="0";
   obj.appendChild(obj_ind);
   document.body.appendChild(obj);
   
}

// Разрешение экрана и размер окна браузера
function bwSize() {
   this.w=document.body.offsetWidth-20;
   this.h=document.body.offsetHeight-5; 
   if (self.screen) {
      this.sw=screen.width;
      this.sh=screen.height;
   } else if (self.java) {
      jkit=java.awt.Toolkit.getDefaultToolkit();
      scrsize=jkit.getScreenSize();
      this.sw=scrsize.width;
      this.sh=scrsize.height;
   }
   return this;
}

// Позиционирование индикатора для тупого IE
function PositionIE(goods,stat) {
   page=new bwSize();
   pos_l=(cart.p=="lt"||cart.p=="lc"||cart.p=="lb"||cart.p=="")?cart.l:(cart.p=="ct"||cart.p=="cc"||cart.p=="cb")?(page.w-cart.w-cart.l)/2:(cart.p=="rt"||cart.p=="rc"||cart.p=="rb")?page.w-cart.w+cart.l:0;
   pos_t=(cart.p=="lt"||cart.p=="ct"||cart.p=="rt"||cart.p=="")?cart.t:(cart.p=="lc"||cart.p=="cc"||cart.p=="rc")?(page.h-cart.h-cart.t)/2:(cart.p=="lb"||cart.p=="cb"||cart.p=="rb")?page.h-cart.h+cart.t:0;
   obj.pixelLeft=pos_l; obj.pixelTop=pos_t;
}

// Позиционирование индикатора для нормальных пацанов
function Position(goods,stat) {
   page=new bwSize();
   pos_l=(cart.p=="lt"||cart.p=="lc"||cart.p=="lb"||cart.p=="")?cart.l:(cart.p=="ct"||cart.p=="cc"||cart.p=="cb")?(page.w-cart.w-cart.l)/2:(cart.p=="rt"||cart.p=="rc"||cart.p=="rb")?page.w-cart.w+cart.l:0;
   pos_t=(cart.p=="lt"||cart.p=="ct"||cart.p=="rt"||cart.p=="")?cart.t:(cart.p=="lc"||cart.p=="cc"||cart.p=="rc")?(page.h-cart.h-cart.t)/2:(cart.p=="lb"||cart.p=="cb"||cart.p=="rb")?page.h-cart.h+cart.t:0;
   if( bw.ie && !bw.ie7 ) {
      obj.pixelLeft=pos_l; obj.pixelTop=pos_t;
   } else {
      obj.style.left=pos_l; obj.style.top=pos_t;
   }
}

// Первая загрузка определение cookie и cid'а
function loadCart() {
   rnd=parseInt((Math.random()*1000000+1));
   cid=check_esm="";
   esm_cookie=" "+document.cookie+";";
   esm_cookie=esm_cookie.substring(esm_cookie.indexOf(" check_esm="));
   // cookie
   find1=esm_cookie.indexOf(" check_esm=");
   if (find1!=-1) {
      find1+=11;
      find2=esm_cookie.indexOf(";");
      check_esm=unescape(esm_cookie.substring(find1,find2));
   }
   // cid
   find1=esm_cookie.indexOf(" esm_cid=");
   if (find1!=-1) {
      find1+=9;
      find2=esm_cookie.lastIndexOf(";");
      cid=unescape(esm_cookie.substring(find1,find2));
   }
   if (check_esm=="on"&&cid!="") {
      goods="/cgi-bin/esm/add_to_cart.pl?"+rnd+"&cid="+cid;
      Position();
      if( bw.ie && !bw.ie7 ) {
         obj.visibility="visible";
      } else {
         obj.style.visibility="visible";
      }
      obj_ind.src=goods;
   } else if (check_esm!=""&&cid=="") {
      goods="about:blank";
      Position();
      if( bw.ie && !bw.ie7 ) {
         obj.visibility="hidden";
      } else {
         obj.style.visibility="hidden";
      }
      obj_ind.src="about:blank";
   }
}

// Добавление в корзину
function toCart(eName,eTm,eCode,eCost,eQuantity,eWeight,eImgPath,eImgWidth,eImgHeight) {
   eTm=(eTm)?eTm:"";
   eWeight=(eWeight)?eWeight:"";
   rnd=parseInt((Math.random()*1000000+1));
   cid=check_esm="";
   esm_cookie=" "+document.cookie+";";
   esm_cookie=esm_cookie.substring(esm_cookie.indexOf(" check_esm="));
   // cookie
   find1=esm_cookie.indexOf(" check_esm=");
   if (find1!=-1) {
      find1+=11;
      find2=esm_cookie.indexOf(";");
      check_esm=unescape(esm_cookie.substring(find1,find2));
   }
   // cid
   find1=esm_cookie.indexOf(" esm_cid=");
   if (find1!=-1) {
      find1+=9;
      find2=esm_cookie.lastIndexOf(";");
      cid=unescape(esm_cookie.substring(find1,find2));
   }
   if (check_esm=="on"&&eName&&eCost&&eQuantity) {
      goods="/cgi-bin/esm/add_to_cart.pl?"+rnd+"&cid="+cid+"&name="+eName+"&tm="+eTm+"&code="+eCode+"&cost="+eCost+"&quantity="+eQuantity+"&weight="+eWeight+"&img_path="+eImgPath+"&img_width="+eImgWidth+"&img_height="+eImgHeight;
      Position();
      if( bw.ie && !bw.ie7 ) {
         obj.visibility="visible";
      } else {
         obj.style.visibility="visible";
      }
      obj_ind.src=goods;
   } else  { 
      if(bw.ns4||bw.ns6) { eName=escape(eName); eTm=escape(eTm); eCode=escape(eCode); }
      page=new bwSize();
      goods="/cgi-bin/esm/cart_stat.pl?"+rnd+"&good_name="+eName+"&tm="+eTm+"&code="+eCode+"&cost="+eCost+"&quantity="+eQuantity+"&weight="+eWeight+"&img_path="+eImgPath+"&img_width="+eImgWidth+"&img_height="+eImgHeight;
      wleft=(page.sw-(page.sw-100))/2;
      wtop=(page.sh-(page.sh-50))/2;
      property="left="+wleft+",top="+wtop+",width="+(page.sw-100)+",height="+(page.sh-100)+",toolbar=0,menubar=0,scrollbars=1,resizable=0"
      esm_win=window.open(goods,"esm_order",property); 
   }
}
loadCart();
onresize=Position;
// setInterval("MoveCart()",30);