

var poppageparentwindow = window.parent

var poppageclosecode = [false,false]
var poppagemovable = [false,false]
var poppageover = [false,false]
var poppagerefreshcode = [false,false]


function popRefresh(idx){
	if (poppagerefreshcode[idx]){
		eval(poppagerefreshcode[idx])
	}
	
}

function popPageParent(code){
	
	poppageparentwindow.setTimeout(code, 10);
	
}

function popPage (popidx,url,w,h,innerHTML,pos,movable)
{
	var ww,e,sc,ds,x,y,i
	var movable_headerhtml 
	var w1,h1
	
	
	if (w.length != undefined){
		w1=w[1];w=w[0]
		h1=h[1];h=h[0]
	} else {w1=w;h1=h;}
	
	if (movable==undefined||movable==null||movable==false) 
	{
		movable=false
		movable_headerhtml=''
	}
	else{
		movable_headerhtml = movable
		movable=true
	}
	
	ww=window
	e = ww.document.getElementById ('poppage'+popidx)	;
	
	sc = getScroll();
	ds = docSize();
		
	if (pos==undefined||pos==null||pos[1]==false) pos=[0,0]
	if (!is_oldie) sc=[0,0]
	
	if (pos[0]===false){x=pos[1];y=pos[2];}
	else
	{
	x=ds[0]/2-w/2+sc[0]+pos[0]; if (x<0)x=0; //x+=popidx*30
	y=ds[1]/2-h/2+sc[1]+pos[1]; if (y<0)y=0; //y+=popidx*30
	}
	
	e.style.width = w+'px'
	e.style.height = h+'px'
	e.style.left = x+'px'
	e.style.top = y+'px'
	e.style.display = 'block';
	
	if (url == null)
	{
		
		x='' // header
		x+=movable_headerhtml
		
		x+=innerHTML
		e.innerHTML = x
		
	}
	else
	{
		
		x=''
		if (movable){
			
			x+= movable_headerhtml
			
		}
		
		x+='<iframe name="poppageiframe'+popidx+'" id="poppageiframe'+popidx+'" frameborder="0" height="'+h1+'" width="'+w1+'" marginheight="0" marginwidth="0" scrolling="auto"></iframe>';
		e.innerHTML = x
		i=ww.document.getElementById('poppageiframe'+popidx);
		i.src=url
	}
	
	popPageOn(popidx,1)
	
	poppagemovable[popidx]=movable
	
	if (!movable){
		
		fadeawayOn();
	}
	
			
}


function fadeawayOn(){
	
	var sc,ds,x
	
		sc = getScroll();
		ds = docSize();
		
		x = document.getElementById('fadeaway');
		if (is_oldie){
			x.style.left = sc[0]+'px';
			x.style.top = sc[1]+'px';
		}
		
		x.style.width=ds[0]+'px';
		x.style.height=ds[1]+'px';
		
		x.style.display='block';

}


function popPageClose(w,popidx)
{
	var win,e,was_on,xx,i,f
	
	win = w=='this'?window:poppageparentwindow;
	
	was_on = isPopPageOn(w,popidx)
	if (!was_on) return false;
		
	e = win.document.getElementById ('poppage'+popidx);
	
	e.style.display='none'
	
	
	
	if (was_on && poppageclosecode[popidx]!==false && w=='this')
	{
		eval(poppageclosecode[popidx]);
		poppageclosecode[popidx]=false
		poppagerefreshcode[popidx]=false
	}

	
	f=false
	for (i=0;i<popidx;i++) if (isPopPageOn(w,i)) {f=true;break;}
	
	if (!f){
		xx = win.document.getElementById('fadeaway');
		xx.style.display='none';
	}
	
	
	if (w=='this') popPageOn(popidx,0)
	
	
	e.innerHTML=''
	
	e = win.document.getElementById('poppageiframe'+popidx);
	if (e != null) e.src = '';

	if (w=='this') popPageOver(popidx,false)
	
	return true
	
	
}


function isPopPageOn(w,popidx)
{
	var win,e
	
	win = w=='this'?window:poppageparentwindow;
	
	e = win.document.getElementById ('poppage'+popidx);
	
	if (e.style.display=='block') return true
	return false;
}

function popPageOn(popidx,on)
{
}

function bodyMouseUp(depth)
{
	// closes child pop = opened from this window
	var c
	c=false
	if (0>=depth && isPopPageOn('this',0) && !poppageover[0] && !poppagemovable[0]) c=popPageClose('this',0);
	if (1>=depth && ((isPopPageOn('this',1) && !poppageover[1])||c)) popPageClose('this',1);
	
}


function popPageOver(popidx,on)
{
	poppageover[popidx]=on	
}


function docSize() {

	var ww
	ww=window	
  var myWidth = 0, myHeight = 0;
  if( typeof( ww.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = ww.innerWidth;
    myHeight = ww.innerHeight;
  } else if( ww.document.documentElement && ( ww.document.documentElement.clientWidth || ww.document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = ww.document.documentElement.clientWidth;
    myHeight = ww.document.documentElement.clientHeight;
  } else if( ww.document.body && ( ww.document.body.clientWidth || ww.document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = ww.document.body.clientWidth;
    myHeight = ww.document.body.clientHeight;
  }
  
  return [myWidth,myHeight]
}

function getScroll() {
	
	var ww
	ww = window
  var scrOfX = 0, scrOfY = 0;
  if( typeof( ww.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = ww.pageYOffset;
    scrOfX = ww.pageXOffset;
  } else if( ww.document.body && ( ww.document.body.scrollLeft || ww.document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = ww.document.body.scrollTop;
    scrOfX = ww.document.body.scrollLeft;
  } else if( ww.document.documentElement && ( ww.document.documentElement.scrollLeft || ww.document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = ww.document.documentElement.scrollTop;
    scrOfX = ww.document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

