 var peapodMaster;

 setLocation();

 function setLocation()
 {
  if (opener !=null)
	{    
	   if (opener.top.mainWin != null)
	   {
    	 peapodMaster = opener.top.mainWin;
	   }
	   else
	   {
	     if ((opener.top.opener != null) && (opener.top.opener.top.mainWin != null) )
	     {
   	     peapodMaster = opener.top.opener.top.mainWin;
	     }
	   }
	}
	else
	{
	  peapodMaster = top;
	}
 }
   // moved from fr4_mainl.jhtml
  function showListPrefPopup()
  {
     if (document.all)
     {
        prefPopup.style.visibility='visible';
     }
     if (document.getElementById)
     {
        var divObj = document.getElementById('prefPopup');
        divObj.style.visibility='visible';
     }

     positionit2();
     repositionPane("prefPopup");
   }

   // moved from fr4_mainl.jhtml
   function setAllItemsPref( num ) 
   {
      allItemsPref=num;
   }

   // moved from fr4_mainl.jhtml	
   function saveListPref(itemQy)
   {
      var newLoc = 'processAllItemsShelf.jhtml?';
      newLoc += 'NUM1=' + bNum;
//      newLoc += '&PREF=' + allItemsPref;
      newLoc += '&PREF=' + itemQy;
      peapodMaster.frame4.location.replace(newLoc);
   }

   // moved from fr4_mainl.jhtml	
   function positionit2()
   {
      //define universal dsoc left point
      var dsocleft=document.all? document.body.scrollLeft : pageXOffset

      //define universal dsoc top point
      var dsoctop=document.all? document.body.scrollTop : pageYOffset

      //define universal browser window width
      var window_width=document.all? document.body.clientWidth : window.innerWidth

      // if the user is using IE 4+ or NS6+
      if (document.all)
      {
         prefPopup.style.left=(parseInt(dsocleft)+
         parseInt(window_width)-475)/2
         prefPopup.style.top=dsoctop+50
      }
      else (document.getElementById)
      {
         var divobj2 = document.getElementById('prefPopup');
         divobj2.style.left=(parseInt(dsocleft)+parseInt(window_width)-475)/2
         divobj2.style.top = dsoctop+50;
      }
    }

   // moved from fr4_main.jhtml	
   function jumpPage( pageno ) 
   {
      var newLoc = 'processJumpShelf.jhtml?NUM1=' + bNum;
      newLoc += "&pageno="+pageno;
      bNum = bNow.getTime();	
      peapodMaster.frame6.location.replace(newLoc);
      bNum++;
   }
   
   // moved from fr4_main.jhtml
   function showPrevPage()
   {
      var newLoc = 'processPreviousShelf.jhtml?NUM1=' + bNum;
      bNum = bNow.getTime();	 
      peapodMaster.frame6.location.replace(newLoc);
      bNum++;
   }
   

// moved from fr4_main.jhtml
   function showNextPage()
   {
      var newLoc = 'processNextShelf.jhtml?NUM1=' + bNum;
      bNum = bNow.getTime();
      peapodMaster.frame6.location.replace(newLoc);
      bNum++;
   }

// renamed from shopSpecialProduct() and moved from fr4_main.jhtml
   function shopSpecialProductFromShelf( prodId, prodDesc, salePrice )
   {
      prodDesc=prodDesc.replace(/\%/gi, "%25");
      prodDesc=prodDesc.replace(/\&/gi, "%26");
      
      salePrice=salePrice.replace(/\%/gi, "%25");
	  salePrice=salePrice.replace(/\&/gi, "%26");

      var newLoc = 'processShowSpecialProductFromShelf.jhtml?PRODID=' + prodId;
      newLoc += "&PRODDESC=" + prodDesc;
      newLoc += "&SALEPRICE=" + salePrice;
	  newLoc += "&event=ShelfPromo";	  
	  bNum = bNow.getTime();
      newLoc += "&NUM1=" + bNum;

      var options = 'resizable=yes,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,width=750,height=490,top=1,left=1';
      var agent = navigator.userAgent;

      if ( agent.indexOf( 'Mozilla' ) != -1 )
      {
        top.specGrpWin = window.open( newLoc, 'WeeklySpecials', options);
        if ( top.specGrpWin != null )
          top.specGrpWin.focus();
      }
   }

  // moved from myPeapodOrderDef.jhtml
  function shopSpecialProdGrpMP( prodGrpId, prodDesc, salePrice )
  {

     prodDesc=prodDesc.replace(/\%/gi, "%25");
     prodDesc=prodDesc.replace(/\&/gi, "%26");

	 salePrice=salePrice.replace(/\%/gi, "%25");
     salePrice=salePrice.replace(/\&/gi, "%26");
     

     var newLoc = 'processShowSpecialProdGrpFromMyPeapod.jhtml?PRODGRP=' + prodGrpId;
     newLoc += "&PRODDESC=" + prodDesc;
     newLoc += "&SALEPRICE=" + salePrice;
     bNum = bNow.getTime();
     newLoc += "&NUM1=" + bNum;

     var options = 'resizable=yes,toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,width=750,height=550';
     var agent = navigator.userAgent;

     if ( agent.indexOf( 'Mozilla' ) != -1 )
     {
        top.specGrpWin = window.open( newLoc, 'WeeklySpecials', options);
        if ( top.specGrpWin != null )
          top.specGrpWin.focus();
     }
  }
      
   // moved from fr4_main.jhtml
   function loadShelf( value, currentShelfType )
   {
      peapodMaster.refreshCartTotals = value;
      if ( peapodMaster.refreshCartTotals == 'true' )   
      {    
         if ( peapodMaster.previousShelfType != currentShelfType )
         {
            peapodMaster.frame3.location.replace('fr3_cart.jhtml?NUM1='+bNum);
            bNum++;
         }
      }
      if( currentShelfType == 5 )
      {
         var newLoc = 'fr3_cart.jhtml?reviewOrderShelf=1&NUM1='+bNum;
         bNum++;
         peapodMaster.frame3.location.replace(newLoc);
      }
      peapodMaster.refreshCartTotals = 'false';
   }
	
   // moved from fr4_main.jhtml
   function setReviewOrderShelf ( value )
   {
      bReviewOrderShelf = value;
   }	

   function shopECI(cpnSet, cpnNo, cpnKey )
   {
      bNow = new Date();
      var bNum = bNow.getTime();

      var newLoc = 'processShowECI.jhtml?CPNSET=' + cpnSet;
      newLoc += "&CPNNO=" + cpnNo;
      newLoc += "&CPNKEY=" + cpnKey;
      bNum = bNow.getTime();
      newLoc += "&NUM1=" + bNum;

//      top.frame4.location=newLoc;

      var options = 'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,width=750,height=400';
      var agent = navigator.userAgent;

      if ( agent.indexOf( 'Mozilla' ) != -1 )
      {
        top.couponWin = window.open( newLoc, 'PromotionSavings', options);
        if (  top.couponWin != null )
          top.couponWin.focus();
      }
   }

   function shopCoupon(cpnSet, cpnNo, cpnKey )
   {  
      bNow = new Date();
      var bNum = bNow.getTime();

      var newLoc = 'processShowCouponShelf.jhtml?CPNSET=' + cpnSet;
      newLoc += "&CPNNO=" + cpnNo;
      newLoc += "&CPNKEY=" + cpnKey;
	  newLoc += "&event=AllSpecialsCoupon";
      bNum = bNow.getTime();
      newLoc += "&NUM1=" + bNum;

      var options = 'toolbar=no,directories=no,status=no,scrollbars=yes,menubar=no,width=750,height=400';
      var agent = navigator.userAgent;

      if (opener)
      {
        if ( agent.indexOf( 'Mozilla' ) != -1 )
        {
          opener.top.couponWin = window.open( newLoc, 'PromotionSavings', options);
          if (  opener.top.couponWin != null )
           opener.top.couponWin.focus();
        }
      }

      else
      {
        if ( agent.indexOf( 'Mozilla' ) != -1 )
        {
          top.couponWin = window.open( newLoc, 'PromotionSavings', options);
          if (  top.couponWin != null )
           top.couponWin.focus();
        }
      }
   }

// moved function ntn() to common_1.0.js

   function toggleThumbNailImages()
   {
     peapodMaster.refreshCartItems = 'false';
     peapodMaster.refreshCartTotals = 'false';
     newLoc = 'processThumbNailImages.jhtml';
     peapodMaster.frame4.location=newLoc;
   }

   function s( sortType )
   { 
     peapodMaster.refreshCartItems = 'false';
     peapodMaster.refreshCartTotals = 'false';
     result = sortType.replace(/\+/gi, "%2B");
     newLoc = 'processSortShelf.jhtml?sortType=' + result;
     newLoc += "&NUM1=" + bNum;
     peapodMaster.frame6.location=newLoc;
     bNum++;
   }


   function ac( prodId, mrchCatId )
   {
      alert('productId = ' + prodId + ';minCatId = ' + mrchCatId + ';');       
   }
   

function preloadShelfImages( Img_3247, Img_3248 )
{
   if (document.images)
   {
      image_grocery_cart_visible = newImage(Img_3247);
      image_grocery_cart_invisible = newImage(Img_3248);

      image_grocery_cart_visible_src = Img_3247;
      image_grocery_cart_invisible_src = Img_3248;

      preloadImagesFlag = true;
   }
   
   if ( peapodMaster.refreshSpecials == 'true' )
   {
      var newLocation = 'underCartAdvtContent.jhtml?NUM1=' + bNum;
      bNum++;
      peapodMaster.frame5.location.replace(newLocation);
   }
   else
   {
      peapodMaster.refreshSpecials = 'true';
   }
}

function preloadShopCardImages( Img_3247, Img_3248 )
{
   if (document.images) 
   {           
      image_grocery_cart_visible = newImage(Img_3247);  
      image_grocery_cart_invisible = newImage(Img_3248);       

      image_grocery_cart_visible_src = Img_3247;
      image_grocery_cart_invisible_src = Img_3248;

      preloadImagesFlag = true;     
   }
      var newLocation = 'underCartAdvtContent.jhtml?NUM1=' + bNum;
      bNum++;
      peapodMaster.frame5.location.replace(newLocation);
}

// this function is also implemented in common_1.0.js
// any changes to this function need to be made in both
// js files.
function y2k(number)
{
   return (number < 1000) ? number + 1900 : number;
}

function setDeletePref(curPref)
{
  peapodMaster.showDeleteConfim = curPref;
}


function repositionPane(divName) {
//this fixes cross browser position issues with many divs by piggy backing on existing functions.
//requires jQuery to be sourced into the page calling this function	
	
	//sets top to current top
	var scrollTop = jQuery("html,body").scrollTop() + 50;
	var divTarget = jQuery("#" + divName);

	divTarget.css("top", scrollTop + "px")
	
	//sets left to middle
	var totalWidth = jQuery("html,body").width() / 2;
	var divWidth = divTarget.width();
	totalWidth = totalWidth - (divWidth/2);
	divTarget.css("left", totalWidth + "px");
	
	
}


// shows popup pane or deletes the item.
function displayTrashCanPane(desc, prodId, shelfType)
{
   // set current prod to prodId;
   tmpProdId = prodId;
   var agent = navigator.userAgent;
   
   if ( (peapodMaster.showDeleteConfim == 'Y') )
   {
      if (document.all)
      {
      prodName.innerText = desc;
      }
      else if (document.getElementById)
      {
         document.getElementById("prodName").innerHTML = desc;
      }

      if ( agent.indexOf( 'Mozilla' ) != -1 )
      {
         positionit('trashCanPane');
	 repositionPane('trashCanPane');
      }
   }
   else
   {
      deleteItem(shelfType)
   }
}

function setPreviousShelfType( value )
{  
   peapodMaster.previousShelfType = value;
}

   function unloadShelf()
   {   
      if ( bReviewOrderShelf==1 )
      {
         peapodMaster.frame3.location.replace('fr3_cart.jhtml?NUM1='+bNum);
         peapodMaster.previousShelfType = '99';
         bReviewOrderShelf=0;
         bNum++;
         peapodMaster.refreshCartItems = 'false';
      }
      peapodMaster.refreshCartItems = 'true';
   }

  function newImage(arg)
  {
     if (document.images)
     {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
     }
  }
