/* 
	Because the HTS pages may not explicitly define 
	uSubmit or uLoad, but will call them from the form onsubmit handler of the form 
	and the onload handler of the body , 
	they are conditionally defined here so that 
	if they are missing from this execution environment
	their use on the HTS will not produce errors.

	The Uniface form template structure requires 
	the existence of these two functions:-
	
	if ( typeof uSubmit != 'function') { window.uSubmit = function(frm){ return true; } }
	if (typeof uLoad    != 'function') { window.uLoad   = function(frm){ ; } }
*/

 
/* --- All Client Pages Need To Include This Code --- */
function wm_mmove(e) 
{ 
	if (parent.mmove)	//	if (top.application.mmove) 
	{ 
		if (document.all) 
			parent.mmove(event,2); 
		else 
			parent.mmove(e,2); 
	}
	else
	{
		/*alert( "parent.move not found - jswindowCallBack.js" );*/
		if (parent.parent.mmove)
		{
			if (document.all) 
				parent.parent.mmove(event,2); 
			else 
				parent.parent.mmove(e,2);
		} 

	}
}           

function setMouseMove(frame) 
{
//alert(window);
//alert(frame);

	if (!frame) frame = window;
	
	if (frame.frames.length == 0) 
	{
		if (frame.name.indexOf("divWindow") == 0)
		{
			if (!frame.document.onmousemove)
			{	
				frame.document.onmousemove=wm_mmove;		/* MOUSEMOVE */ 
			}
			//if (!frame.document.onclick)
			if (!frame.document.onmousedown)
			{
				var s = frame.name.substring( frame.name.indexOf("divWindow")+9  );
/*alert("jswindowCallBack:setMouseMove(frame) extracts index from Frame Name\n" + frame.name + "\nAs\n"+s);*/
				if (s.indexOf("Tab")!=-1){
					s = s.substring(0,s.indexOf("Tab"));
				}
				//frame.document.onclick=new Function("parent.SetActiveWin("+s+",1);");
//alert( parent.SetActiveWin );
//alert(s);
				frame.document.onmousedown=new Function("parent.SetActiveWin("+s+",1);");  /* MOUSEDOWN */
			}
		}
	}
	else
	{ 
alert( "recursive loop ...." );		
		for (var f = 0; f < frame.frames.length; f++)
			setMouseMove(frame.frames[f]);
	}
}

/* --- All Client Pages Need To Include This Code --- */


/* ------------------------------------------ programing notes, junk ---------------------[KILL] 
Path="http://www.montegodata.co.uk/Images/"
workspace=""; // "top.fraContentFrame.fraContent"

function SetImagePath(dir) { Path = dir		 }
function SetWorkspace(dir) { workspace = dir }

function action(u){eval(workspace+".location=u");}

var strLink = this.link
if (strLink.indexOf("?") > 0)
{	
doc.write("<a href=" + this.link + "&ActiveFolder=" + NodeNumber+ ">" + this.desc + "</a>") 
}
else
{	
if ( workspace.length == 0 )
doc.write("<a href=" + this.link + "?ActiveFolder=" + NodeNumber+ ">" + this.desc + "</a>") 
else
doc.write( "<a href='javascript:action(\"" + this.link + "\");'>" + this.desc + "</a>")
}

deeptree.htm
SetImagePath("../Images/")
SetWorkspace("top.fraContentFrame.fraContent")

opener.document

var strAlterDiv = "parent.parent.document.
getElementById('div1').innerHTML = 'New div tag text.'";   
eval(parent.window.parent.window.strAlterDiv);  
.referrer;
[KILL]------------------------------------------ programing notes, junk --------------------- */


function getJsWindowFrame(){
	var fn, current = window;

/*alert( "jswindowCallBack:getJsWindowFrame()" );*/
	if ( (!current.create_window) && (current.parent != current) && (!current.parent.getJsWindowFrame) )
	{
		try{	
		current.parent.getJsWindowFrame = new current.parent.Function('return ('+arguments.callee+');');
		current.parent.getJsWindowFrame = current.parent.getJsWindowFrame();
		}catch(exception){}
	
	}

	while (	(!current.create_window) && (current != current.parent) )
	{
		current = current.parent;   //work up until - create_window - is found, or (current == current.parent).
	}
	
	if(!current.create_window)
	{ // did not find the right frame on the way up (unlikely) so search down.
		current = ((fn = function(w){
			var c, f = w.frames, r = null;
			for(c = w.frames.length;(!r && c--);)
			{
				if(!f[c].create_window){
					r = fn(f[c]);
				}else{
					r = w;
				}
			}
			return r;
		})(current));
	}

	function getCurrent(){return current;}

	return ((getJsWindowFrame = getCurrent)());
}


function bindHandlers()
{
	setMouseMove();

	if (wm_mmove) document.onmousemove = wm_mmove;
	else alert('mouse handler not engaged');

	//InitializeMe(setSize);
}


var InitializeMe = (function(){
	var global = this,base = null,safe = false;
	var listenerType = (global.addEventListener && 2)||(global.attachEvent && 3)|| 0;
	function getStackFunc(next, funcRef, arg1,arg2,arg3,arg4)
	{
		function l(ev)
		{
			funcRef( (ev?ev:global.event), arg1,arg2,arg3,arg4 );
			if(next)
			next = next(ev);
			return (funcRef = null);
		};
		l.addItem = function(d)
		{
			if(next){next.addItem(d);}
			else{next = d;}
		};
		return l;
	};
	return (function(funcRef, arg1,arg2,arg3,arg4)
	{
	if(base){base.addItem(getStackFunc(null, funcRef, arg1,arg2,arg3,arg4));}
	else 	{base = getStackFunc(null, funcRef, arg1,arg2,arg3,arg4);}
	if(!safe)
	{
		switch(listenerType)
		{
		case 2:global.addEventListener("load", base, false);safe=true;break;
		case 3:global.attachEvent("onload", base);safe=true;break;
		default:if(global.onload != base){if(global.onload){base.addItem(getStackFunc(null, global.onload));}global.onload = base;}break;
		}
	}
	}
	);
})();


(function(){
/* Per-page code for global event interception. Currently monitoring
   window: onscroll, onresize, and document: onmousedown, onmouseup,
   onkeydown, onkeypress and onselectstart (as defined in the arrays
   globalEventListener.events.document and
   globalEventListener.events.window);
*/

/*alert( "calling getJsWindowFrame()" );*/

	var targetObj = getJsWindowFrame(); //<- The frame containing the JSWindow code (also top.application at present).
	var onName = ['on',''];
	var localFrame = this;
	
	function attachListener(obj, eventName, fnc)
	{
		if ( obj.addEventListener )
		{ 
			obj.addEventListener(eventName, fnc, false); 
		}
		else if( obj.attachEvent )
		{
			onName[1] = eventName;
			obj.attachEvent(onName.join(''), fnc);
		}
		else
		{
			onName[1] = eventName;
			obj[onName.join('')] = fnc;
		}
	}
	function addHandlers(obj, namesArray)
	{
		for(var c = namesArray.length;c--;){
			attachListener(obj, namesArray[c], getReportingListener(obj, namesArray[c]));
		}
	}
	function getReportingListener(obj, eventName)
	{
		return (function(e){
			e = e||localFrame.event
			targetObj[eventName](e, obj);
		});
	}
	
	if(targetObj && (targetObj = targetObj&&targetObj.globalEventListener)){
		addHandlers(localFrame, targetObj.events.window);
		addHandlers(localFrame.document, targetObj.events.document);
	}

})();

(function(){
	var global = this;

	var onName = ['on',''];
	var localFrame = this;
	global.attachListener = function(obj, eventName, fnc){
		if(obj.addEventListener){
			obj.addEventListener(eventName, fnc, false);
		}else if(obj.attachEvent){
			onName[1] = eventName;
			obj.attachEvent(onName.join(''), fnc);
		}
	}
	global.detachListener = function(obj, eventName, fnc){
		if(obj.removeEventListener){
			obj.removeEventListener(eventName, fnc, false);
		}else if(obj.detachEvent){
			onName[1] = eventName;
			obj.detachEvent(onName.join(''), fnc);
		}

	}

})();
	


/*	
	------------------------------------------------
	called in contentScroll For User Select Control.
	SelectWidget rather than contentScroll.htm
	------------------------------------------------ 
*/
function getWidgetRect( cObj, yourLeftX, yourTopY ) 
{
	var wrect;
	var Obj = (typeof cObj == "string")  ? document.getElementById(cObj) : cObj ;
	var	objLeftX  = Obj.offsetLeft+yourLeftX;
	var	objTopY   = Obj.offsetTop+yourTopY;
	var	ObjParent = Obj.offsetParent;

	if (ObjParent)
	{
		while (ObjParent.tagName.toUpperCase() != "BODY")
		{
			objLeftX += ObjParent.offsetLeft;
			objTopY  += ObjParent.offsetTop;
			ObjParent = ObjParent.offsetParent;
		}
		if (ObjParent.tagName.toUpperCase()=="BODY")
		{
			//objLeftX -= ObjParent.scrollLeft;
			//objTopY  -= ObjParent.scrollTop;		
		}
	}
	wrect = [objLeftX, objTopY, Obj.offsetWidth, Obj.offsetHeight];

	return wrect;
}

function setSize()
{
/*alert( "jswindowCallBack:setSize(top.application)" );*/

	if (parent.getActiveWindow() > 0)
	{
		var wide=0;
		var high=0;
		var r,f,j,fdoc,Obj;
		var wrect;

		fdoc = parent.getDocument();
		for (f=0;f<fdoc.forms.length;f++)	      
		{
			for (j=0;j<fdoc.forms[f].elements.length;j++) /* this will not find <input type="image"> buttons in the - elements - colection. */
			{
				Obj = fdoc.forms[f].elements[j];
				wrect = getWidgetRect( Obj, 2+2, 39+4 ); // l,t,w,h
				if (wrect[0]+wrect[2]>wide) wide = wrect[0]+ wrect[2];
				if (wrect[1]+wrect[3]>high) {high = wrect[1]+ wrect[3]; }
			}
		}
		if (wide && high){ //if (wide>0&&high>0){ //if (wide && high){
//alert(wide+' ' +high);//this.Resize(wide,high);
		parent.setChildSize(wide,high);
		}
	}
}

/* --- Force Mouse Code On All Frames --- */

bindHandlers();
