﻿// JScript File

function MiniMRVList(){
    this.contentDiv = $("contentMRV");
    this.msgDiv = $("contentMsg");
    this.mainDiv = $("MRVtable");
    this.imageDiv = $("eventImageMRV");
    this.messageDiv = $("contentMsg");    
    this.imageSourceUp = '/orvis_assets/images/MiniMRVup.jpg'; 
    this.imageSourceDown = '/orvis_assets/images/MiniMRVdn.jpg';
};

MiniMRVList.prototype.Toggle = function(){
    var imageSrc;
    
     if (this.contentDiv.style.display == "none") 
     { 
     if (MRVpositionFlag == "True") {
           posArray = this.mainDiv.positionedOffset();
          this.contentDiv.style.top = posArray[1]+this.mainDiv.offsetHeight ;
          this.contentDiv.style.left = posArray[0];
          this.contentDiv.style.position = "absolute";
          this.contentDiv.style.zIndex = 1000;
          }
          Effect.BlindDown(this.contentDiv, { duration: .5}); 
          imageSrc = this.imageSourceUp;
     }
     else 
     { 
          Effect.BlindUp(this.contentDiv, { duration: .5}); 
          imageSrc = this.imageSourceDown;
     }
 
      this.imageDiv.src = imageSrc;
};
MiniMRVList.prototype.MouseOver = function(){
    this.messageDiv.style.cursor = "pointer";
    this.imageDiv.style.cursor = "pointer";
};

function initMiniMRV() {
 
 aMiniMRVList = new MiniMRVList();
 aMiniMRVList.imageDiv.onclick = function(){aMiniMRVList.Toggle();};  //this will attach the click event handler for you outside
 aMiniMRVList.messageDiv.onclick = function(){aMiniMRVList.Toggle();};  //this will attach the click event handler for you outside
 aMiniMRVList.messageDiv.onmouseover = function(){aMiniMRVList.MouseOver();};  //this will attach the click event handler for you outside
 aMiniMRVList.imageDiv.onmouseover = function(){aMiniMRVList.MouseOver();};  //this will attach the click event handler for you outside

};


function clearMRVCookie(page)
{

    // When clearing MRV and on a product page we want to preserve the first rec in the MRV cookie
    // because this is the current product we are viewing and should remain in the MRV list
    if (page == "product") {
    	
	var cookie = unescape(document.cookie.match (new RegExp('(^|;)\\s*' + escape("MRV") + '=([^;\\s]*)'))[2]);
    	var frIndex = (cookie.indexOf("|", 0)) + 1;
    	var firstRec = cookie.substring(0, frIndex);
    }
    
    
    //Expire MRV Cookie	
    var cookie_date = new Date();
    cookie_date.setTime(cookie_date.getTime() -1);
    //cookie_date.setUTCFullYear(cookie_date.getUTCFullYear() -1);
    document.cookie = "MRV=; expires=" + cookie_date.toGMTString() + ";path=/";
    
    
    //If product page (see above) create new MRV cookie
    if (page == "product") {
	
	var cookie = "MRV=" + firstRec;
	//var cookie_date = new Date();
	//set to expire in 7 days
        //cookie_date.setTime(cookie_date.getTime()+(604800000));
	//var expires = "; expires="+cookie_date.toGMTString();
 	//document.cookie = cookie+expires+"; path=/";
	document.cookie = cookie+"; path=/";
	
    }
    
    //Re-set MRV display
    this.contentDiv = $("contentMRV");
    this.msgDiv = $("contentMsg");
    this.imageDiv = $("eventImageMRV");
    this.imageSourceDown = '/orvis_assets/images/MiniMRVdn.jpg';
    Effect.BlindUp(this.contentDiv);
    imageSrc = this.imageSourceDown;
    this.imageDiv.src = imageSrc;
    this.contentDiv.innerHTML = "<table width='162px' class='noqtycellMRV'><tr><td>No Recently Viewed Items</td></tr><tr><td class='noqtycellMRV'></td></tr></table>";
    this.msgDiv.innerHTML = "0 Recently Viewed Items"
} 