var modalTitle=''
var totWidth=0;
var op=10,op2=40,theRootFrame,dlayyer 
var scrollBars
var pageHeight;

var backCol='#999999';
//backCol='#000000'
var IsSingleWindow=false;
var mN1,mN2
var op2;
var  backgroundIm='top3.gif'
var bottomIm='bottom.gif'
var customWidth=414; var customHeight=100; var offsetTop_=100

function closeModal(IsSingleWindow) {

	if (IsSingleWindow!=null)
		this.IsSingleWindow=IsSingleWindow;
	closeModal2(self);
}

function closeModal2(targetFrame,IsSingleWindow){

	if (IsSingleWindow!=null)
		this.IsSingleWindow=IsSingleWindow;
	clearFrame(targetFrame) 	// was .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): 
	 return;
	 nam=F.name
	 if (nam==undefined) nam=''
	 if (IsSingleWindow || (nam && nam.length>0)){
		var fB=F.window.document.body;
		if (this.scrollBars.indexOf(nam.toLowerCase())>=0){
			if(fB) fB.style.overflowY='auto'; //ff 'dark order' fix
		}
	 }
}

function changeOp(F){

	op+=2;op2+=10
	if (op>=50){clearInterval(xxx); } 
	changeOpacityFrame(F)
}

function changeOpacityFrame(F){
    if (F.window.frames.length>1 && IsSingleWindow==false){
		for(f=0;f<F.window.frames.length;f++)
			changeOpacityFrame(F.window.frames[f])
    }
	mod=F.document.getElementById('opakelayer');
	if (mod){
		if ('abc'.substr(-1)!='c'){   //is this ie?
			mod.style.filter='alpha(opacity='+op+')';
			if(!IsSingleWindow)dlayer.style.filter='alpha(opacity='+op2+')';
		}
		else{  //standards compliant!
  			mod.style.MozOpacity=op/100;
  			mod.style.Opacity=op/100;
  			if(!IsSingleWindow)dlayer.style.opacity=op2/100;
  			
  		}
	}
}

/*
 Recursive function to darken a frame and all subframes
*/
function darken(obj){

 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)
  if(!IsSingleWindow)
	obj.window.document.body.style.overflow='hidden'

  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.style.zindex=100      
	
	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.  
  
  }

width=getBodyWidth(obj)  // obj.document.body.clientWidth;


  // no calculations: this is simple & very effective.
 var pageWidth=width // screen.width;       
 var pageHeight=screen.height; 
 //alert(window.innerHeight);

 if (mod){
   totWidth+=width;
   

   mod.style.backgroundColor=backCol; 
   mod.style.width= pageWidth; 
    
  
   
   if ('abc'.substr(-1)!='c')  { //is this ie?
	mod.style.filter='alpha(opacity=50)';
	pageHeight=obj.document.body.clientHeight;
	pageWidth=obj.document.body.clientWidth;
	mod.style.top=getScrollTop(obj) //   obj.document.body.scrollTop; //for scrolled down menu.
   } else { //standards compliant!
  	mod.style.opacity=0.5;
	mod.style.position='fixed'; //for scrolled down menu.
   }
   
 mod.style.visibility='visible';
 mod.style.height=pageHeight+'px';

  }
 }
}

// entry point
function displayModal(modalmsg,withOK,theCol){
    targetFrame=window.parent.parent;
	displayModal2(targetFrame,targetFrame,modalmsg,withOK,theCol);
}

function getScrollTop(obj) {

    var ScrollTop = obj.document.body.scrollTop;
    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = obj.window.pageYOffset;
        else
            ScrollTop = (obj.document.body.parentElement) ? obj.document.body.parentElement.scrollTop : 0;
    }
    return ScrollTop;
}

function displayModal3(rootFrame,targetFrame,rootRef,modalmsg,withOK,theCol,topMargin,IsSingleWindow,scrollbars,backImg,bottomIm,modalTitle,customWidth,customHeight,offsetTop_){

	if (modalTitle!=undefined && modalTitle!='xxx')this.modalTitle=modalTitle;
	this.customWidth=(customWidth!=undefined && customWidth!=-1)?customWidth:414;
	this.customHeight=(customHeight!=undefined && customHeight!=-1)?customHeight:100;	
	this.offsetTop_=(offsetTop_!=undefined)?offsetTop_:100;
	
	IsSingleWindow=true; // temporary
		
	backgroundIm=backImg
	this.bottomIm=bottomIm;
	displayModal2(rootFrame,targetFrame,rootRef,modalmsg,withOK,theCol,topMargin,IsSingleWindow,scrollbars)

}

// updated entry point with more parameters
function displayModal2(rootFrame,targetFrame,rootRef,modalmsg,withOK,theCol,topMargin,IsSingleWindow,scrollbars){
//backgroundIm='top5.gif'
//this.bottomIm='bottom5.gif'

totWidth=0
if (scrollbars==undefined)scrollbars='xxxxxx'
this.scrollBars=scrollbars;
theCol=backCol

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+getScrollTop(targetFrame) // .document.body.scrollTop;
 useableWidth=totWidth
 if(noOfFrames>0)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. 
  }

 // these are the standard values
 dlay.style.width=customWidth+'px' // '414px'
 dlay.style.height=customHeight+'px' // '100px'



 msgContent='<div id="closeModal"><a href="javascript:'+rootRef+'closeModal('+IsSingleWindow+')"><img border="0" class="btnCloseModal" src="/lmimages/trans.gif" height=20 width=20></a></div>'
 msgContent+='<table class="modalMsg" width="100%" height="100%" border="0" cellpadding="10" cellspacing="5" background="/LMimages/modal/'+backgroundIm+'">' 
 msgContent+='<tr><td class="colorHeader" style="text-align:left" 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+'"/>';

 modalTitle=''
 dlay.innerHTML= msgContent;

 dlayer=dlay
 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=getScrollTop(targetFrame)+offsetTop_; //    targetFrame.document.body.scrollTop)+offsetTop_; //  /2 - 250
 //alert(targetFrame.document.body.scrollTop+'\n'+dlay.style.height)
 //alert(targetFrame.document.body.clientHeight + '\n'+dlay.style.height)
 if (Y<50) Y=50;
 if (topMargin!=null)
	Y-=topMargin;
	
 dlay.style.left=L+'px'
 dlay.style.top =Y+'px'
 op=10
 theRootFrame=rootFrame
 //xxx=setInterval('changeOp(theRootFrame)',2)
 backgroundIm='top3.gif'
 
}



function getBodyWidth(targetFrame){

	//create a div positioned at the right hand side of the screen
	
	if(document.getElementById('toprightlay')==null){
		var tbody = targetFrame.document.body;   
		var tnode = targetFrame.document.createElement('div');          // Create the layer.        
		tnode.style.position='absolute';								// Position absolutely        
		tnode.style.bottom='0px';											// In the top        
		tnode.style.right='0px';										// right corner of the page        
		tnode.style.width='1px';
		tnode.id='toprightlay';										// Name it so we can find it later    
		tbody.appendChild(tnode);										// Add it to the web page    
	}
	dlay=targetFrame.document.getElementById('toprightlay');		// Get the object. 

	pageWidth=dlay.offsetLeft;
	//alert(dlay.offsetTop)
	return pageWidth
}

function displayNotification(obj,txt,typ){

    //alert(txt)
    displayModal3(this,this,'',txt,true,'#FF0000',20,true,true,'top5.gif','bottom5.gif')
return;
    if (obj.document.getElementById('notelayer'+typ)==null){
		var tbody = obj.document.body;    
		var tnode = obj.document.createElement('div');              // Create the layer.        
		tnode.style.position='absolute';							// Position absolutely              
		tnode.style.overflow='hidden';								// Try to avoid making scroll bars                    
		tnode.style.display='block';								// Start out Hidden       
		tnode.id='notelayer'+typ;									// Name it so we can find it later    
		tbody.appendChild(tnode);									// Add it to the web page    
	}
		//clearTimeout(mN1);
		mo=obj.document.getElementById('notelayer'+typ);				// Get the object.  

		if(mo.style.visibility=='visible')return;
		
		mo.style.width='200px';
		mo.style.height='180px';
		
			
		pageHeight=obj.document.body.offsetHeight;
		pageWidth=obj.document.body.offsetWidth;
		if ('abc'.substr(-1)!='c')  { //is this ie?
			mo.style.top=getScrollTop(obj) //   obj.document.body.scrollTop;
			mo.style.filter='alpha(opacity=0)';
		} else { //standards compliant!
			pageHeight=obj.window.innerHeight;
			pageWidth=obj.window.innerWidth;
			mo.style.position='fixed'; //for scrolled down menu.
			mo.style.MozOpacity=0.0;
		}
    wi=pageWidth-210 // (210*typ)
    if (wi<0) wi=30;
    mo.style.left=(wi-50)+'px';
   	mo.style.visibility='visible';
	inner='<table width="200" height="180" background="/LMimages/notificationBack.gif?rand=k98111" border="0" align="middle" cellpadding=1>'
	inner+='<tr><td width="10">&nbsp;</td><td width="180" height="10">&nbsp;</td><td width="20" style="CURSOR: pointer;" onclick="closeNotification(\'\','+typ+')"></td></tr>'
	inner+='<tr><td></td><td height="150" colspan="2" valign="top" class="notificationText">'+txt+'</td></tr></table>';
	
	mo.innerHTML=inner;

    
    mo.style.top=(pageHeight)+'px';
	op2=0
	moveNotification(mo,typ);
}

function moveNotification(mo){
try{
    op2+=2
    top_=dim(mo.style.top);
    if(top_>pageHeight-190)top_-=10;
    if(op2>=100){ // (top_<pageHeight-128){
    
		mN1=setTimeout('closeNotification(mo)',10000);
		return;
	}
	
	if ('abc'.substr(-1)!='c'){   //is this ie?
		//alert(mo.style.filter)
		mo.style.filter='alpha(opacity='+op2+')';
	}else  //standards compliant!
  		mo.style.MozOpacity=op2/100;
  	
	
    mo.style.top=top_+'px';
    mN1=setTimeout('moveNotification(mo)',10);	
}
catch(err){
	mN1=0;
	closeNotification(mo);
	//return;
}   

}
function closeNotification(mo,typ){

	try{
		if(mo==null || mo==''){
			mo=document.getElementById('notelayer'+typ)
		}
		mo.style.visibility='hidden';
		
		
	}
	catch(err)
	{
		return;
	}
}

function dim(v){
	// removes the px
	vs=v.split('px')
	return parseInt(vs[0]);
}
