var totWidth=0;
var backCol='#000000';
var IsSingleWindow=false;
var theWidth=414;
var theHeight=100;
var theTop=50;

function closeModal(IsSingleWindow){
	if (IsSingleWindow!=null)
		this.IsSingleWindow=IsSingleWindow;
	closeModal2(self);
}

function closeModal2(targetFrame,IsSingleWindow){
	if (IsSingleWindow!=null)
		this.IsSingleWindow=IsSingelWindow;
	clearFrame(targetFrame)//.parent) 	
}

function clearFrame(F){


    if (F.window.frames.length>1 && IsSingleWindow==false){
		for(f=0;f<F.window.frames.length;f++)
			clearFrame(F.window.frames[f])
    }
	mod=F.document.getElementById('opakelayer');
	if (mod)
		mod.style.visibility='hidden';
	dlay=F.document.getElementById('displaylayer')
	if (dlay)
		dlay.style.visibility='hidden';
	
	 // when we put the dark layer, we removed all scrollbars from the page!	
	 // add the scrollbars (except to the the top frames): 
	 
		var fB=F.window.document.body;
		if(fB) fB.style.overflowY='auto'; //ff 'dark order' fix
/*
  overflow: -moz-scrollbars-vertical;
  overflow-x: none;
  overflow-y: auto;


*/
	
}

/*
 Recursive function to darken a frame and all subframes
*/
function darken(obj){
 //alert(IsSingleWindow);

 noOfFrames=obj.window.frames.length;
 if (IsSingleWindow)   // this is a special condition for a page with an Iframe
	noOfFrames=1;
 if (noOfFrames>1){
	for (ff=0;ff<obj.window.frames.length;ff++){
		darken(obj.window.frames[ff]);
	}
 }else{
 
  //Remove scrollbars: (scrollbars are ugly)
  obj.window.document.body.style.overflow='hidden'

  //alert (obj.name + '\nscrollheight='+document.body.scrollHeight+'\nclientHeight='+obj.document.body.clientHeight)
  mod=obj.document.getElementById('opakelayer'); 
  if (!mod){
	var tbody = obj.document.body;    
	var tnode = obj.document.createElement('div');            // Create the layer.        
	tnode.style.position='absolute';                 // Position absolutely        
	tnode.style.top='0px';                           // In the top        
	tnode.style.left='0px';                          // Left corner of the page        
	tnode.style.overflow='hidden';                   // Try to avoid making scroll bars                    
	tnode.style.display='block';                      // Start out Hidden  
	tnode.style.visibility='hidden';      
	tnode.id='opakelayer';							 // Name it so we can find it later    
	tbody.appendChild(tnode);                        // Add it to the web page    
	mod=obj.document.getElementById('opakelayer');			 // Get the object.  
  }
  // no calculations: this is simple & very effective.
 var pageWidth=screen.width;       
 var pageHeight=screen.height; 
  
  if (mod){
   width=obj.document.body.clientWidth;
   totWidth+=width;

   mod.style.backgroundColor=backCol;
   mod.style.width= pageWidth; 
   mod.style.height=pageHeight;

   if ('abc'.substr(-1)!='c')  { //is this ie?
	mod.style.filter='alpha(opacity=60)'; 
	mod.style.top=obj.document.body.scrollTop; //for scrolled down menu.
   } else { //standards compliant!
  	mod.style.opacity=.6;
	mod.style.position='fixed'; //for scrolled down menu.
	//if(obj.name=='Right'||obj.name=='topRight') {alert(obj.document.body.innerHTML);} //testing on safari
   }
   mod.style.visibility='visible';
  }
 }
}

// entry point
function displayModal(modalmsg,withOK,theCol){
	
    targetFrame=window.parent.parent;
	displayModal2(targetFrame,targetFrame,modalmsg,withOK,theCol);
}

function displayModal3(rootFrame,targetFrame,rootRef,modalmsg,withOK,theCol,topMargin,IsSingleWindow,theWidth,theHeight,theTop){
	this.theWidth=theWidth;
	this.theHeight=theHeight;
	this.theTop=theTop;
	displayModal2(rootFrame,targetFrame,rootRef,modalmsg,withOK,theCol,topMargin,IsSingleWindow);
}

// updated entry point with more parameters
function displayModal2(rootFrame,targetFrame,rootRef,modalmsg,withOK,theCol,topMargin,IsSingleWindow){
totWidth=0
if (IsSingleWindow!=null)
	this.IsSingleWindow=IsSingleWindow;
	


 if (theCol!=null)backCol=theCol;
 
 // start with darkening the target frame, then proceed recursively
 darken(rootFrame);
 width=targetFrame.document.body.clientWidth;
 height=targetFrame.document.body.clientHeight+targetFrame.document.body.scrollTop;
 useableWidth=totWidth/noOfFrames;
 if (noOfFrames==4) useableWidth=useableWidth*2;

 // now put the central display layer
 dlay=targetFrame.document.getElementById('displaylayer')
 if (dlay==null){
    var tbody = targetFrame.document.body;    
	var tnode = targetFrame.document.createElement('div');           // Create the layer.        
	tnode.style.position='absolute';                 // Position absolutely        
	tnode.style.top='0px';                           // In the top        
	tnode.style.left='0px';                          // Left corner of the page        
	tnode.id='displaylayer';						 // Name it so we can find it later    
	tbody.appendChild(tnode);                        // Add it to the web page    
	dlay=targetFrame.document.getElementById('displaylayer');  // Get the object. 
  }
 
 //alert(dlay)
 dlay.style.width=theWidth+'px' // '414px'
 dlay.style.height=theHeight+'px' // '100px'
 backgroundIm='top31.gif'

 msgContent='<div id="closeModal"><a href="javascript:'+rootRef+'closeModal('+IsSingleWindow+')"><img border="0" class="btnCloseModal" src="/images/closeModal.gif"></a></div>'
 msgContent+=modalmsg;
 
 //msgContent+='<table class="modalMsg2" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" background="/modal/'+backgroundIm+'"><tr><td width="15" height="20">&nbsp;</td><td>&nbsp;</td><td width="25" STYLE="cursor: hand" onclick="'+rootRef+'closeModal('+IsSingleWindow+')"><a href=\"javascript:closeModal('+IsSingleWindow+')\">&nbsp;</a></td><tr><td>&nbsp;</td><td valign="top">'+modalmsg+' </td><td>&nbsp;</td></tr>';
 //msgContent+='</table>';//<img src="modal/bottom.gif" width="414" />';
 
 /*
 msgContent+='<table class="modalMsg" width="100%" height="100%" border="0" cellpadding="10" cellspacing="5" background="/LMimages/modal/'+backgroundIm+'">' 
 msgContent+='<tr><td class="colorHeader" height="10">'+modalTitle+'</td></tr>'
 msgContent+='<tr><td align="left" valign="top">'+modalmsg+'</td></tr>'
 if (withOK)msgContent+='<tr><td align="center" valign="bottom"><img src="/LMimages/modal/OK.gif" border="0" onclick="'+rootRef+'closeModal()"></td></tr>';
 msgContent+='</table><img src="/LMimages/modal/'+bottomIm+'"/>';
*/
 
 dlay.innerHTML= msgContent;
 dlay.style.visibility='visible'; 

 L=(useableWidth/2)- dim(dlay.style.width)/2;

 if ((L+dim(dlay.style.width))>width)
    L=width-dim(dlay.style.width)-30;

 Y=(targetFrame.document.body.scrollTop)+theTop; //  /2 - 250
 //alert(targetFrame.document.body.clientHeight + '\n'+dlay.style.height)
 if (Y<50) Y=theTop;
 if (topMargin!=null)
	Y-=topMargin;
 dlay.style.left=L;
 dlay.style.top =Y+'px';// dim(dlay.style.height)*2 
}

function dim(v){
	// removes the px
	vs=v.split('px')
	return parseInt(vs[0]);
}