
/* function to return full text from a url */
function GetURL(url) {
	var fulltext, paratext;
 	if ('undefined' == typeof(url)) return false;
 	var p,rnd;
 	if (document.all){
	   // For IE, create an ActiveX Object instance
   		p = new ActiveXObject("Microsoft.XMLHTTP");
 	}
 	else {
   		// For mozilla, create an instance of XMLHttpRequest.
   		p = new XMLHttpRequest();
 	}
 	// Prevent browsers from caching the included page by appending a random  number
 	rnd = Math.random().toString().substring(2);
 	url = url.indexOf('?')>-1 ? url+'&rnd='+rnd : url+'?rnd='+rnd;
 	// Open the url and get the response
 	p.open("GET",url,false);
 	p.send(null);
	fulltext = p.responseText ;
	return fulltext;
}

// new prototype defintion include another file
document.include = function (url) {
	if ('undefined' == typeof(url)) return false;
	var ftext;
	document.write(GetURL(url));
}

document.inclBody = function (url) {
	if ('undefined' == typeof(url)) return false;
	document.write(GetURL(url));
}

function GetPara2(url) {
	url = CheckInclude(url);
    return GetPara(url);
}

function GetPara(url) {
	var fulltext, paratext;
	var start, end;
	var prefix, targ, anch, expr;
	var hashpos;
	var expr2 = new RegExp("<p>","i");
	if ('undefined' == typeof(url)) return false;
//		return url;
	hashpos = url.indexOf("#");
	if (hashpos > -1) {
		targ =  'name="' + url.substr(hashpos+1);
		expr = new RegExp(targ,"i");
		url = url.substr(0,hashpos);
	}
	else {
//		return "Target not found";
		expr = new RegExp("<body","i");
		targ = "";
	}
	fulltext = GetURL(url);
	start = fulltext.search(expr);
	paratext = fulltext.substr(start+ targ.length);
	end = paratext.search(expr2);
	paratext =  paratext.substr(0, end);
	start = paratext.indexOf(">");
	if (start > -1) {
		paratext = paratext.substr(start+1);
	}
	return paratext;
}

function CheckInclude(url) {
	var targpos;
	var hashstr;
	targpos = url.indexOf("#");
	if (targpos == -1) {
		hashstr = "";
		}
	else {
		hashstr = url.substr(targpos);
	}
	targpos = url.lastIndexOf("/");
	var pathstr = url.substring(0,targpos+1);
	//get the text
	var fulltext = GetURL(url);
	//look for inclBody
	targpos = fulltext.indexOf('<div class="mainBodyDiv">');
	if (targpos == -1) return url; 
	fulltext = fulltext.substr(targpos);
	targpos = fulltext.indexOf("document.inclBody('");
	if (targpos == -1) return url; 
	//if found build newurl
	fulltext = fulltext.substr(targpos);
	targpos = fulltext.indexOf("('")+2;	
	fulltext = fulltext.substr(targpos);
	targpos = fulltext.indexOf("')");
	return pathstr + fulltext.substr(0,targpos) + hashstr;
}

function ShowTarg() {
	var targstr, prefix, fstr;
	var xypos = findPos(document.getElementById("whereto"));
	targstr = document.getElementById("whereto").value;
	prefix = targstr.substr(0,targstr.length-3).toLowerCase();
//	fstr = "mfss" + prefix + ".html#" + targstr.toUpperCase();
	fstr = "m" + prefix + ".html#" + targstr.toUpperCase();
	if (prefix == "ts") {
		targstr = fstr;
		}
	else {
		targstr = "../mfss/" + fstr;
	}	
	Tip(GetPara(targstr),CLOSEBTN,true,FOLLOWMOUSE,false,WIDTH,160,FIX,xypos,TITLE,fstr,BGCOLOR,'#c0ffc0',BORDERCOLOR,'#084D13')
//	Tip(GetPara2(targstr),CLOSEBTN,true,FOLLOWMOUSE,false,WIDTH,160,FIX,xypos,TITLE,fstr,BGCOLOR,'#c0ffc0',BORDERCOLOR,'#084D13')
	//document.getElementById("showtime").value = prefix + " - " + targstr;
	
}

 function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
} 

function JumpTo() {
	var targstr, prefix, fstr;
	targstr = document.getElementById("whereto").value;
	prefix = targstr.substr(0,targstr.length-3).toLowerCase();
	fstr = "mfss" + prefix + ".html#" + targstr.toUpperCase();
	if (prefix == "ts") {
		targstr =  fstr;
		}
	else {
		targstr = "../mfss/" + fstr;	
	}

	window.open(targstr,"_top");
}

/* This section works with behaviour.js to define mouseover and mouseout behaviours for all span tags
The format for the span must be <span><a href="mfssag.html#AG206">AG206</a></span>
It will use href to define the url and para that it will find. If no has string it looks for start of body tag
Tooltip popups use <script type="text/javascript" src="wz_tooltip.js"></script> as first line in body of file

*/

var myrules = {
	'span' : function(el){
		el.onmouseover = function(){
//			Tip(this.firstChild.href,WIDTH,450);
			Tip(GetPara2(this.firstChild.href),WIDTH,350,JUMPHORZ,true);
//			Tip(GetInclude(this.firstChild.href),WIDTH,550);
		}
		el.onmouseout = function(){
			UnTip();
		}
	}
};

Behaviour.register(myrules);

/* ================================================= */