

// check IE
var iex = document.all;
var nav4 = document.layers;
var debug=0;

//sysProtect();
//sysActivateDebug();

// ****************** PROTECT **********************************

function ocm()
{
	sysDebug("onContextMenu");
	return false; // do not continue
}

function dno()
{
	return false;
}

function omd(e)
{
	sysDebug("onMouseDown");
	if (!document.onmousemove)
		document.onmousemove=dno;	
}

function sysProtect()
{
	document.oncontextmenu=ocm;
	document.onmousedown=omd;
}

// ****************** DEBUG **********************************

var _console=null;

function sysError(str)
{
	alert(str);
}

function sysActivateDebug()
{
	debug=1;
	document.write('<form>');
	document.write('<input type="button" value="Clear" onClick="clearConsole()">');
	document.write('</form>');
	sysDebug("debugActivated!");
}

function sysDebug(msg) {
	if (!debug)
		return ;
  if ((_console==null) || (_console.closed)) {
    _console=window.open("","console","width=300,height=600,resizable,left=0,top=0")
	_console.document.open("text/plain")
  }
  _console.document.writeln(msg)
}

function clearConsole() {
  _console.document.close()
  _console.document.open("text/plain")
  _console.document.writeln(" ")
}


/*

function sysDebug(str)
{
if (!debug)return;
window.status=str;
document.writeln(str);
}
*/

function sysShowInfo(str)
{
var pobj = sysGetObject(str);
if (!pobj)
	alert("Non existing object: "+str);
else
{	
	var temp = "";
	for (x in pobj)
	temp += x + ": " + pobj[x] + "\n";
	alert (temp);
}
}

//************ PICTURES ******************

function sysChangeBackground(str,pic) 
{
if (nav4) return;
var p = eval(pic+".src");
var obj = sysGetObject(str);
if (!obj) { sysDebug(str + "does not exist(changeBackground)"); return ; }
sysDebug("sysChangeBackground:"+str+"="+pic);
obj.style.backgroundImage = "url("+p+")"; //"url(pic/appleselected.gif)";
//obj.style.background.url.src = p;
/*
if (!document.images[cImg]) { sysDebug("pic does not exist:"+cImg); return; }
document.images[cImg].src = p;
*/
}


function sysChangeImg(cImg,pic) 
{
var p = eval(pic+".src");
if (!document.images[cImg]) { sysDebug("pic does not exist:"+cImg); return; }
document.images[cImg].src = p;
}

//************ WINDOW / DIV ***************

function sysSetVisibility(str,mode)
{
	sysDebug("setVisibility : "+str+"("+mode+")");
	var obj = sysGetObject(str);
	if (!obj) { sysDebug(str + " does not exist(setVisibility)"); return ; }
	if (!nav4)
		obj=obj.style;
	obj.visibility=mode;
}

function sysSetPosition(str,x,y)
{
//	sysDebug("sysSetPosition: "+str+" ("+x+","+y+")");
	var obj = sysGetObject(str);
	if (!obj) { sysDebug(str + " does not exist(setPosition)"); return ; }
	if (!nav4)
		obj=obj.style;
	obj.left=x;
	obj.top=y;
}

function sysSetAbsolutePosition(str,x,y)
{
//	sysDebug("sysSetPosition: "+str+" ("+x+","+y+")"+document.body.scrollLeft);
	var obj = sysGetObject(str);
	if (!obj) { sysDebug(str + " does not exist(setPosition)"); return ; }
	if (!nav4)
		obj=obj.style;
	obj.left=absx=x+document.body.scrollLeft;
	obj.top=absy=y+document.body.scrollLeft;

}

function sysSetColor(str,front,back)
{
	sysDebug("sysSetColor: "+str+" ("+front+","+back+")");
	var obj = sysGetObject(str);
	if (!obj) { sysDebug(str + " does not exist(setColor)"); return ; }
	if (!nav4)
		obj=obj.style;
	obj.color=front;
	obj.background=back;
}

function sysSetSize(str,sx,sy)
{
	var obj = sysGetObject(str);
	if (!obj) { sysDebug(str + "does not exist(setSize)"); return ; }
	if (!nav4)
		obj=obj.style;
	if (sx>0)
		obj.width = sx;
	else
	if (sx==0)
		obj.width=null;
		
	if (sy>0)
		obj.height = sy;
	else
	if (sy==0)
		obj.height=null;
}

function sysResize(str,sx,sy)
{
	var obj = sysGetObject(str);
	if (!obj) { sysDebug("cannot resize:"+str); return ; }
	if (!nav4)
		obj=obj.style;
	if (sx>0)
		obj.width = sx;
	str+="row"; // WARNING
	obj = sysGetObject(str);
	if (!obj) { sysDebug(str); return ; }
	if (sy>0)
		obj.height = sy;
}

function sysGetWindowX(str)
{
	var pobj=sysGetObject(str);
	if (!pobj) { sysDebug("cannot getwindowx:"+str); return ; }
	return parseInt(pobj.offsetLeft);
}

function sysGetWindowY(str)
{
	var pobj=sysGetObject(str);
	if (!pobj) { sysDebug("cannot getwindowy:"+str); return ; }
	return parseInt(pobj.offsetTop);
}


function sysGetWindowSizeYbis(str)
{
	var pobj=sysGetObject(str);	
	if (!pobj) { sysDebug(str); return ; }
	return parseInt(pobj.height);
}

function sysGetWindowSizeX(str)
{
	var pobj=sysGetObject(str);
	if (!pobj) { sysDebug("cannot getwindowsizey:"+str); return ; }
	return parseInt(pobj.offsetWidth);
}
	
function sysGetWindowSizeY(str)
{
	var pobj=sysGetObject(str);
	if (!pobj) { sysDebug("cannot getwindowsizex:"+str); return ; }
	return parseInt(pobj.offsetHeight);
}

//************ DOCUMENT WRITE *************

function sysGetObject(obj)
{
	if (document.getElementById)
		return document.getElementById(obj);
	else
	{
		//alert(document.layers[obj] + "///" + eval("document."+obj) );

		if (document.layers[obj])
			return document.layers[obj];
		else
			return eval("document."+obj);
		}
}



function sysWriteInnerHTML(tag,str)
{
	var pobj = sysGetObject(tag);
	if (!pobj) { sysDebug("cannot writehtml:"+tag); return ; }
	if (!nav4)
		pobj.innerHTML = str;
	else
	{
		pobj.document.open();
		pobj.document.write(str);
		pobj.document.close();
	}
	
}


//************ EVENTS *************

function sysRetrieveEvent()
{
	return e=window.event || arguments.callee.caller.arguments[0];	
}

function sysGetMouseX(e)
{
 return (!iex) ? e.pageX : event.x+document.body.scrollLeft;
}

function sysGetMouseY(e)
{
 return (!iex) ? e.pageY : event.y+document.body.scrollTop;
}

function  sysSetMouseMoveEvent(func)
{
	if (!iex) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = func;

}

function sysGetScrollLeft(e)
{
	return document.body.scrollLeft;
}

function sysGetScrollTop(e)
{
	return document.body.scrollTop;
}
/*
function  sysSetScrollEvent(func)
{
	sysDebug("setScrollEvent");
	if (!iex) document.captureEvents(Event.SCROLL);
	document.onscroll = func;
}
*/

//************ EVENTS *************

function sysGetTrigger(e)
{
if (iex)
	return window.event.srcElement;
else
	return e.target;
}

function sysGetZIndex(el)
{
	var pel = sysGetObject(el);
	if (!pel) return -1;
	return pel.style.zIndex;
}

function sysSetZIndex(el)
{
	var pel = sysGetObject(el);
	if (!pel) return ;
	pel.style.zIndex = zindex;
}

sysDebug("end processing system.js");