var _LAY_INFO = new Array();

xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page
var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;
function hidelayer(lay) {
if (ie4) {document.all[lay].style.visibility = "hidden";}
if (ns4) {document.layers[lay].visibility = "hide";}
if (ns6) {document.getElementById([lay]).style.display = "none";}
}
function showlayer(lay) {
if (ie4) {document.all[lay].style.visibility = "visible";}
if (ns4) {document.layers[lay].visibility = "show";}
if (ns6) {document.getElementById([lay]).style.display = "block";}
}

function layerpos(lay,x,y) {
	
	if(ie4) {
		obj = document.all[lay];
	}else if(ns4) {
		obj = document.layers[lay];
	}else {
		obj = document.getElementById(lay);
	}
	if(obj) {
		obj.style.left = x;
		obj.style.top=y;
		obj.style.position="absolute";
	}
		return;
//	if (ie4) {document.all[lay].style.left = x;
//			  document.all[lay].style.top=y; }
//	if (ns4) {document.layers[lay].left = x;
//				document.layers[lay].top=y;}
//	if (ns6) {document.getElementById(lay).style.left = x;
//			  document.getElementById(lay).style.top=y;}

}
function writetolayer(lay,txt) {
if (ie4) {
document.all[lay].innerHTML = txt;
}
if (ns4) {
document[lay].document.write(txt);
document[lay].document.close();
}
if (ns6) {
over = document.getElementById([lay]);
range = document.createRange();
range.setStartBefore(over);
domfrag = range.createContextualFragment(txt);
while (over.hasChildNodes()) {
over.removeChild(over.lastChild);
}
over.appendChild(domfrag);
   }
}

var last_show = '';
function show_and_write(lay) {
//	if(last_show !='') {
//		hidelayer(last_show);
//	}
//	writetolayer(lay,_LAY_INFO[lay]);
//	showlayer(lay);
//	last_show=lay;
	show_and_write_txt('paperlayer',_LAY_INFO[lay]);
}

function show_and_write_txt(lay,txt) {
//	if(last_show !='' && last_show!=lay) {
//		hidelayer(last_show);
//	}

//	layerpos(lay,xMousePos,yMousePos);
	writetolayer(lay,txt);
	if(last_show!=lay) {
		showlayer(lay);
	}
	last_show=lay;
	//writetolayer(lay,_LAY_INFO[lay]);
	//showlayer(lay);
}
function gety(layer) {

	if(layer.style.top>0) {
		return layer.style.top;
	}

    if(layer.y>0) {	
		return layer.y;
	}

   if (document.layers) return layer.y;
   if (document.getElementById) return parseInt(layer.top)
   if (document.all) return layer.pixelTop
   }
function getx(layer) {
//document.write("left = " + layer.left +", pixelLeft=" + layer.pixelLeft + ", x=" +layer.x);
	if(layer.style.left>0) {
		return layer.style.left;
	}
   	if(layer.x>0) {	
		return layer.x;
	}
   if (document.layers) {
   		if(layer.x) {	
			return layer.x;
		}
	}
	if (document.getElementById) {
		if(parseInt(layer.left)>0)
			return parseInt(layer.left);
	}
   if (document.all) {
   	return layer.pixelLeft;
	}
}
function show_and_write_pos(lay,x,y) {
//	txt = _LAY_INFO[lay];
	
//	lay = 'paperlayer';
	var img;
	img = document.imglinks;
	if(! img) {
		img = document.getElementById('imglinks');
	}
	if(!img) {
		img = document.all['imglinks'];
	}
	//try {
	//	x = 100+x;
	if(!img) {
		x1=100+x;
		y1 = y;
		layerpos('paperlayer',x1,y1);
		show_and_write(lay);
		return;
	}

	x1 = getx(img);
	if(x1>0) {
		//document.write("getx="+x1);
		x1 +=x;
	} else{
		x1= 100+x;
	}
	y1 = gety(img);
	if(y1>0) {
		y1+=y;
	} else {
		y1 = y+100;
	}
	//} catch (e) {;}
//	_LAY_INFO[lay] = "x="+getx(img);
//	document.write("x,y="+x1,","+y1);
	layerpos('paperlayer',x1,y1);
	show_and_write(lay);
}


 function hidde_and_write(lay) {
	last_show='';
	writetolayer(lay,'');
	hidelayer(lay);
}

function hidde_all() {
	for(lay in _LAY_INFO) {
		hidelayer(lay);
	}

}

function layer_txt(paper_id, txt, layname) {
	if (layname == '' || layname == null) {
		layname = 'paperlayer';
	}
	var ret = '';
	ret += "<table border=0 cellpadding=0 cellspacing=0 style={border-width:1px;} width=440><TR><TD>";
	ret += "<table border=0 cellpadding=0 cellspacing=0 width=100% style={border-width:0px;}><TR bgcolor=#335533><TD bgcolor=\"#335533\" align=left style={color:white;background-color:#335533;} >"+txt +"</TD><TD align=right width=10 style={color:white;background-color:#335533;}><A href=\"javascript:hidde_and_write('"+layname+"')\" style={color:white;font-weight:bold;text-decoration:none;}>X</A></td></tr></table>";
	ret += "<table border=0 cellpadding=0 cellspacing=0 width=100% style={border-width:0px;}><tr>";
	//ret += "<table border=1 cellpadding=0 cellspacing=0 ><TR bgcolor=#335533><TD bgcolor=#335533 align=center style={color:white;} colspan=3>"+txt +"<div align=right><A href=\"javascript:hidde_and_write('layer"+layname+"')\" style={color:white;font-weight:bold;text-decoration:none;}>X</A></div></td></tr><tr><td>";
	
		ret += "<TD >";
	src = './quick_paper.php4?paperid=' +paper_id ;
	ret += '<IFRAME SRC="'+src+'" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 WIDTH=440 HEIGHT=200></IFRAME>';
	//ret += '<IFRAME SRC="'+src+'" MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=NO WIDTH=240 HEIGHT=100></IFRAME>';

	ret += "</td></tr></table>";
	//ret += "</td></tr><TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR></table>";
	ret += "</TD></TR></table>";
	return ret;
	}

	if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

