
modalWindow =
{
  ifrm                  : "0",
  matteBoxId    		: "dialogueMatteBox", 	
  contentBoxId  		: "dialogueContentBox",
  matteBoxClassName     : "matteOverlay", 	
  contentBoxClassName   : "contentBox", 
  gyzorkDialogIframe	: "gyzorkDialogIframe",
  oldHash               : "0",	
  showingDetailModal    : false,
  width  : null,
  height : null,
  refreshPage : false,
  
  show : function (content, color,width,height)
  {
  	  //alert("show");
	  this.width = width ;   
	  this.height= height;   
	  
	  
	  var matteBox = document.getElementById(this.matteBoxId);
	  var contentBox = document.getElementById(this.contentBoxId);
		
	  if(typeof matteBox == 'undefined' || matteBox==null)
	  {	
		 matteBox = document.createElement("div"); 
		 matteBox.id = this.matteBoxId;	
		 document.body.appendChild(matteBox);	  
	  }
	  if(typeof contentBox == 'undefined' || contentBox==null)
	  {
		 contentBox  = document.createElement("div"); 
		 contentBox.id = this.contentBoxId;
		 document.body.appendChild(contentBox);	  
	  }
	  if(typeof contentBox.childNodes !='undefined')
	  {	
			for (var x=contentBox.childNodes.length;x>0;x--)
			{
               var child = contentBox.childNodes[x-1];
               child.id = new Date().getTime();
               contentBox.removeChild(child);
               delete child;
		  	}
	  }
	  matteBox.className=this.matteBoxClassName;
	  contentBox.appendChild(content);
	  contentBox.className=this.contentBoxClassName;
	  
	  window.setTimeout("modalWindow.paint()",100);		   

	  // IE doesn't support fixed position so, redraw when the scroll bar moves.	
	  window.onscroll = modalWindow.paint;
    },
    
	paint : function()
	{
		if(!modalWindow.isActive()){
			return;
		}
		var dims = modalWindow.getHeightAndWidth();	
		var scrollDims = modalWindow.getScrollHeightAndWidth();
	    var leftOffset = scrollDims.width + (dims.width - modalWindow.width) / 2;
 	    var topOffset = scrollDims.height + (dims.height - modalWindow.height) / 2;
 	    
 	    // If detail modalWindow is being displayed than set leftOffset and topOffset
 	    // ignoring the current size of the modalWindow.
        if ( window.parent.modalWindow.showingDetailModal ) {
  	    	leftOffset = (gyzork.modalWidthIndent / 2) + scrollDims.width;
 	    	topOffset = (gyzork.modalHeightIndent / 2) + scrollDims.height;
 	    }
 	    
 	    leftOffset = parseInt(leftOffset);
 	    topOffset = parseInt(topOffset);
 	    
	    var matte = modalWindow.getMatteHandle();
	    matte.style.top= scrollDims.height+"px" ;
	    matte.style.left= scrollDims.width+"px";
	    
	    var content = modalWindow.getContentHandle();
	    content.style.top =topOffset+"px";
	    content.style.left =leftOffset+"px";
	},
	
	getHeightAndWidth : function()
	{
	 	if( self.innerHeight ) {
		   centerX = self.innerWidth;
		   centerY = self.innerHeight;
		   //alert("innerheight: " + centerX + "," + centerY);
 		} 
 		else if( document.documentElement && document.documentElement.clientHeight ) 
		{
 		  centerX = document.documentElement.clientWidth;
   		  centerY = document.documentElement.clientHeight;
   		  //alert("documentElement.clientHeight: " + centerX + "," + centerY);
 		} 
 		else if( document.body ) 
 		{
   			centerX = document.body.clientWidth;
   			centerY = document.body.clientHeight;
   			//alert("document.body.clientHeight: " + centerX + "," + centerY);
 		}
		return {width : centerX, height :centerY};
	},


	getScrollHeightAndWidth : function(){
	
		 var scrolledX =0, scrolledY =0;
		 if( self.pageYOffset ) 
		 {
   			scrolledX = self.pageXOffset;
 		    scrolledY = self.pageYOffset;
 		 } 
  		 else if( document.documentElement && document.documentElement.scrollTop ) 
 		 {
   			scrolledX = document.documentElement.scrollLeft;
   			scrolledY = document.documentElement.scrollTop;
 		 } 
 		 else if( document.body ) 
 		 {
   			scrolledX = document.body.scrollLeft;
   			scrolledY = document.body.scrollTop;
 		 }
 		 return {width : scrolledX, height :scrolledY}; 	
	},



	isActive : function() 
	{
		var matteBox = document.getElementById(this.matteBoxId);
		var contentBox = document.getElementById(this.contentBoxId);
		if(matteBox!=null && contentBox!=null)
			return (matteBox.className==this.matteBoxClassName 
						&& contentBox.className==this.contentBoxClassName);
		return false;
	},

	getMatteHandle : function(){
		return document.getElementById(this.matteBoxId);
	},
	getContentHandle : function(){
		return document.getElementById(this.contentBoxId);
	},
	
	
    close : function()
    {
		var handle = this.getMatteHandle();
		if(handle!=null) handle.className='noDisplay';
		var handle = this.getContentHandle ();
		if(handle!=null) handle.className='noDisplay';

		document.body.onscroll = null;		
	        
	    if (modalWindow.refreshPage)  window.parent.location.reload( false );
    },
    
	sizeIFrameToContent : function (height,width)
	{  
  		var theFrame = document.getElementById(modalWindow.gyzorkDialogIframe);
  		if (theFrame) {
			theFrame.style.height = height;
			theFrame.style.width  = width;
			theFrame.height = height;
			theFrame.width  = width;
		}
	},
	
	buildIFrame: function (width,height,src)
	{
		ifrm = document.createElement("iframe");
		ifrm.frameborder="0"
		ifrm.scrolling = "no";  
		ifrm.className='gyzorkDialogIframe';
		ifrm.width = width; 
		ifrm.height = height;   
		
		document.body.appendChild(ifrm);
		document.body.removeChild(ifrm);
		
		ifrm.id = modalWindow.gyzorkDialogIframe;
		ifrm.name = new Date().getTime();
		
		var sep = (src.indexOf("?")==-1) ? "?" : "&";
		ifrm.src = src + sep + Math.random();
		
		return ifrm;
	}
}   





