﻿// JScript File


var myTimer;
var prodId;
var docId;
var emptyImage;
var tipOn = false;
function GetProductThumbNail(productId,documentId,spacerImg)    
{ 
    prodId = productId;   
    docId = documentId;
    emptyImage=spacerImg; 
     tipOn = true;   
    if(document.getElementById("prodImg")!=null)
    document.getElementById("prodImg").src=spacerImg
    resetPriceLabels();
    var parameters = "?prodId="+prodId+"&docId="+docId;
    var url = "../Services/ThumbNailHoverWebService.asmx/GetProductThumbNail"+parameters;
    var responseObject = ExecuteWebserviceCall(url,"text",CallBack);
}

function resetPriceLabels()
{
    document.getElementById("lblhovertitle").innerHTML="";
    document.getElementById("lblhoverSellingprice").innerHTML="";	    
    document.getElementById("descHolder").innerHTML ="";  
    document.getElementById("lblhoverSavingsText").innerHTML ="";
    document.getElementById("lblhoverOriginalPrice").innerHTML ="";
    document.getElementById("lblhoverOriginalPriceText").innerHTML ="";     
}

function HidePopUp()
{
    tipOn=false;
    clearTimeout(myTimer);
    var getDivId = document.getElementById('PopOvr');        
    getDivId.style.display = 'none';   
     var iframe = document.getElementById('iframetop');
        iframe.style.display = 'none';   
    resetPriceLabels();
    
}
 
 function CallBack(details)
 {
   
    document.getElementById("prodImg").src=details.HoverImage;
    document.getElementById("lblhovertitle").innerHTML=htmlDecode(details.Title);
    document.getElementById("lblhoverSellingprice").innerHTML=htmlDecode(details.SellingPriceLabel)+" "+details.SellingPrice;	    
    document.getElementById("descHolder").innerHTML =htmlDecode(details.Description);  
    if(details.Saving!=0 && details.OriginalPrice!="")
    {
    document.getElementById("lblhoverSavingsText").innerHTML =htmlDecode(details.Saving)+"%";
    document.getElementById("lblhoverOriginalPrice").innerHTML =htmlDecode(details.OriginalPrice);
    document.getElementById("lblhoverOriginalPriceText").innerHTML =htmlDecode(details.OriginalPriceLabel);
    }
    else
    {
        document.getElementById("lblhoverSavingsText").visible=false;
        document.getElementById("lblhoverOriginalPrice").visible=false;
        document.getElementById("lblhoverOriginalPrice").visible=false;
    }
    myTimer=setTimeout('DelayDisplay()', 1000);
//   var img = details.HoverImage;      
//   var sp = details.SellingPrice;
//   var desc = details.Description;
//   var title = details.Title;
//   showPop(img,title,sp,desc);    
 } 
   
  
function showPop(img,title,sp,desc) {     
   
    document.getElementById("prodImg").src=img;
    document.getElementById("lblhovertitle").innerHTML=htmlDecode(title);
    document.getElementById("lblhoverSellingprice").innerHTML=sp;	    
    document.getElementById("descHolder").innerHTML =htmlDecode(desc);  
    myTimer=setTimeout('DelayDisplay()', 1000);
     
}
function DelayDisplay()
{
    if(tipOn)
    {
       var getDivId = document.getElementById('PopOvr');       
       getDivId.style.display = 'block';	   
        var tpWd =(ie)? getDivId.clientWidth: getDivId.offsetWidth;
	    var tpHt = (ie)? getDivId.clientHeight: getDivId.offsetHeight;
	    if ((mouseX+offX+tpWd)>winWd) 
		    getDivId.style.left = mouseX-(tpWd+offX)+"px";
	    else getDivId.style.left = mouseX+offX+"px";
	    if ((mouseY+offY+tpHt)>winHt) 
		    getDivId.style.top = winHt-(tpHt+offY)+"px";
	    else getDivId.style.top = mouseY+offY+"px";		  
	    var iframe = document.getElementById('iframetop');
        iframe.style.display = 'block';
        iframe.style.width = getDivId.offsetWidth-10;
        iframe.style.height = getDivId.offsetHeight-5;
        iframe.style.left = getDivId.offsetLeft;
        iframe.style.top = getDivId.offsetTop;  
      
    }
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);
// Set-up to use getMouseXY function onMouseMove
   document.onmousemove = getMouseXY;  
// Temporary variables to hold mouse x-y pos.s

var tempX = 0+'px'
var tempY = 0+'px'

var offX= 20;	// how far from mouse to show tip
var offY= 12;
var ie=document.all
var ns5=document.getElementById && !document.all


var mouseX;
var mouseY;
var winWd;
var winHt;
function getMouseXY(evt) {
var tooltip = document.getElementById('PopOvr');
  standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
    mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
    mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
// document area in view (subtract scrollbar width for ns)
	 winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	 winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;

}




