var Popup = 
{
	_PopupInit: false,
	_xOffset: 0,
	_yOffset: 0,
	_isIE: false,
	_isNav6: false,
	_isNav: false,
	_divId: '',
	//_divProperty: null,
	//_visible: '',
	//_invisible: '',
	
	Popup: function(xOffset, yOffset, divId) {
		Popup._divId = divId;
	    if (document.all) {	// Internet Explorer
	        Popup._isIE = true;
	        document.all[Popup._divId].className = 'visibleWindow';
	        //alert('Popup:all:Popup._divId=' + Popup._divId);
	        
	        
	        
			document.getElementById(Popup._divId).className = 'visibleWindow';
			//document.getElementById(Popup._divId).style.display = "";
			
			
			document.all[Popup._divId].style.left = (document.body.clientWidth/2) - (document.all[Popup._divId].offsetWidth/2);
			document.all[Popup._divId].style.top = document.body.scrollTop+(document.body.clientHeight/2) - (document.all[Popup._divId].offsetHeight/2);
	        /*
	        ViewOrderDetails.className = 'visibleWindow';
			ViewOrderDetails.style.left = (document.body.clientWidth/2) - (ViewOrderDetails.offsetWidth/2);
			ViewOrderDetails.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (ViewOrderDetails.offsetHeight/2);
			*/
		} 
	    else if (document.layers) {	// Netscape
	        Popup._isNav = true;
	        document.layers[Popup._divId].visibility = true;
	        //alert('Popup:lay:Popup._divId=' + Popup._divId);
			document.layers[Popup._divId].left = (window.innerWidth/2) - 100;
			document.layers[Popup._divId].top = pageYOffset+(window.innerHeight/2) - 40;
		} 
	    else if (document.getElementById) {	// Netscape 6+
			Popup._isNav6=true;
			document.getElementById(Popup._divId).className = 'visibleWindow';
			document.getElementById(Popup._divId).style.display = "";
	        //alert('Popup:id:Popup._divId=' + Popup._divId);
	        document.getElementById(Popup._divId).style.left = (window.innerWidth/2)- 100;
			document.getElementById(Popup._divId).style.top = pageYOffset+(window.innerHeight/2) - 40;
		}
	},
	
	//sets the initial parameters xOffset, yOffset and interval 
	PopupInitFunc: function(xOffset, yOffset){
	//alert('xOffset=' + xOffset + '|yOffset=' + yOffset);
	 //alert('in PopupInitFunc');
	  if(xOffset){
	      Popup._xOffset = xOffset;
	      
	      if(Popup._isIE){
	      	//alert('in init: isIE');
	      	document.all[Popup._divId].style.left= Popup._xOffset;	
	        //document.getElementById('ViewOrderIframe').style.left = document.all[Popup._divId].style.left;
	        //document.getElementById('ViewOrderIframe').style.display = "inline";
	        //document.getElementById('ViewOrderIframe').style.visibility = "visible";
	      }
	      else if(Popup._isNav) {
	      	//alert('in init: isNav');
	      	document.layers[Popup._divId].left= Popup._xOffset;	
	      	//document.getElementById(Popup._divId).style.display = "";
	        //document.getElementById('ViewOrderIframe').style.left = document.layers[Popup._divId].style.left;
	        //document.getElementById('ViewOrderIframe').style.display = "inline";
	        //document.getElementById('ViewOrderIframe').style.visibility = "visible";
	      }
	      else{
	      	//_divProperty.
	      	//alert('in init: isNav');
	      	document.getElementById(Popup._divId).style.left = xOffset;
	      }
	   }
	   if(yOffset){
	      Popup._yOffset = yOffset;
	      
	      if(Popup._isIE){
	        document.all[Popup._divId].style.top = Popup._yOffset;
	         
	        //document.getElementById('ViewOrderIframe').style.top = document.all[Popup._divId].style.top;
	        //document.getElementById('ViewOrderIframe').style.display = "inline";
	        //document.getElementById('ViewOrderIframe').style.visibility = "visible";
	      }
	      else{
	        document.getElementById(Popup._divId).style.top = yOffset; 
	      }
	
	   }
	   
	   Popup._PopupInit = true;
	   return Popup._PopupInit;
	},
	                           
	//  Hide it there is no garantee that we already initialized so need to 
	// make the full call to get the browser type.
	PopupDestroy: function() {
		//alert('in destroy');
	    if (document.all) {	// Internet Explorer
	    	//alert('in document.all');
			document.all[Popup._divId].className = 'hiddenWindow';
			//document.all[Popup._divId].style.display = 'none';
	    	//alert('out document.all');
		} 
	    else if (document.layers) {	// Netscape
	    	//alert('in document.layers');
			document.layers[Popup._divId].visibility = false;
	    	//alert('out document.layers');
		} 
	    else if (document.getElementById) {	// Netscape 6+
	    	//alert('in document.getElementById');
			document.getElementById(Popup._divId).className = 'hiddenWindow';
			//document.getElementById[Popup._divId].style.display = 'none';
	    	//alert('out document.getElementById');
		}
		
		//document.getElementById(Popup._divId).style.visibility = "hidden";
		//alert('return destroy');
	},

	showPopup: function(xOffset, yOffset, divId) {
	//alert('111');
	      Popup.Popup(xOffset, yOffset, divId);
	      Popup.PopupInitFunc(xOffset, yOffset); 
	},
	
	show: function(evt, divId)
	{		
		//alert('in show');
		var viewElem = document.getElementById(divId);
		//alert('viewElem=' + viewElem);
		var posObj = Popup.getMouseCoordinates(evt, viewElem);
		//alert('after getMouseCoordinates');
		posx = posObj.x;
		posy = posObj.y;
		Popup.showPopup(posx, posy, divId);
	},
	
	ietruebody: function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},
	

	getMouseCoordinates: function(evt, popupElem)
	{
		var ie=document.all;
		var ns6=document.getElementById && !document.all;
		
		//alert('in getMouseCoordinates');
			
		var offsetxpoint=0; //-60; //Customize x offset of tooltip
		var offsetypoint=0; //20; //Customize y offset of tooltip
		
		var e = (window.event) ? window.event:evt;
		
		//alert('in getMouseCoordinates:popupElem' + popupElem);
		
		var posx = 0;
		var posy = 0;
		if (e.pageY)
		{
			posy = e.pageY;
		}
		else if (e.clientY)
		{
			posy = e.clientY + document.body.scrollTop;
		}
		
	
		var promptWidth = popupElem.offsetWidth;
		var promptHeight = popupElem.offsetHeight;
		
		//alert('in getMouseCoordinates1111');
	
		var curX=(ns6)?e.pageX : event.clientX+Popup.ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+Popup.ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? Popup.ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? Popup.ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<promptWidth)
			//move the horizontal position of the menu to the left by it's width
			posx=ie? Popup.ietruebody().scrollLeft+event.clientX-promptWidth+"px" : window.pageXOffset+e.clientX-promptWidth+"px";
		else if (curX<leftedge)
		  	posx = "5px";
		else
			//position the horizontal position of the menu where the mouse is positioned
		  	posx=curX+offsetxpoint+"px";
		  	
		//alert('in getMouseCoordinates222222');
	
		//same concept with the vertical position
		if (bottomedge<promptHeight)
			posy=ie? Popup.ietruebody().scrollTop+event.clientY-promptHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-promptHeight-offsetypoint+"px"
		else
			posy=curY+offsetypoint+"px"
			
		var returnObj = new Object();
		returnObj.x = posx;
		returnObj.y = posy;
		
		return returnObj;
	}
	
} // end Popup