var win = null;
var themenu =null;
var theshield =null;
var theCallendar=null;
var yscroll=null
var prevX=null;
var prevY=null;

hidemenu();

function dropit(e,whichone,xoffset,yoffset,prevCoords)
{
//hide everything
	document.onclick=hidemenu;
	parent.document.onclick=hidemenu;
	if (themenu!=eval(document.getElementById(whichone))) hidemenu();


//get current menu
	themenu=eval(document.getElementById(whichone));


	if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null || navigator.appName.toUpperCase().match(/OPERA/))
	{
		themenuoffsetX=document.body.scrollLeft;
		themenuoffsetY=document.body.scrollTop;
		themenu.style.left=themenuoffsetX + e.clientX-e.offsetX-2-(xoffset?xoffset:0);
		themenu.style.top=themenuoffsetY + event.clientY-event.offsetY+14-(yoffset?yoffset:0)

		if (themenu.clientHeight+event.clientY-event.offsetY+14-(yoffset?yoffset:0)>document.body.clientHeight)
			document.body.scrollTop=document.body.scrollTop+(themenu.clientHeight+event.clientY-event.offsetY+14-(yoffset?yoffset:0))-document.body.clientHeight;

	} else
	{
		themenuoffsetX=0;
		themenuoffsetY=0;
		themenu.style.left=e.layerX-(xoffset?xoffset:0);
		themenu.style.top=e.layerY+5-(yoffset?yoffset:0);
	}

	if (prevCoords)
	{
		themenu.style.left=prevX;
		themenu.style.top=prevY;
	} else
	{
		prevX=themenu.style.left;
		prevY=themenu.style.top;
	}


	if (themenu.style.visibility=="hidden")
		themenu.style.visibility="visible";
	else
		themenu.style.visibility="hidden";

	return false;
}


function dropitTopMenu(e,whichone,left)
{
//hide everything
	document.onclick=hidemenu;
	parent.document.onclick=hidemenu;
	window.onscroll=hidemenu;


	if (themenu!=eval(parent.document.getElementById(whichone))) hidemenu();


//get current menu
	themenu=eval(parent.document.getElementById(whichone));
	theshield=eval(parent.document.getElementById('shield'));

	themenuoffsetX=document.body.scrollLeft;
	themenuoffsetY=document.body.scrollTop;
	themenu.style.left=left.offsetParent.offsetLeft-themenuoffsetX-1;
	themenu.style.top=66-themenuoffsetY;

	theshield.style.width=themenu.clientWidth+2;
	theshield.style.height=themenu.clientHeight+2;
	theshield.style.left=themenu.style.left;
	theshield.style.top=themenu.style.top;

	if (themenu.style.visibility=="hidden")
	{
		themenu.style.visibility="visible";
		theshield.style.visibility="visible";
	} else
	{
		themenu.style.visibility="hidden";
		theshield.style.visibility="hidden";
	}

	return false;
}


function dropitleftTopMenu(e,whichone,left)
{
//hide everything
	document.onclick=hidemenu;
	parent.document.onclick=hidemenu;
	window.onscroll=hidemenu;
	if (themenu!=eval(parent.document.getElementById(whichone))) hidemenu();

//get current menu
	themenu=eval(parent.document.getElementById(whichone));
	theshield=eval(parent.document.getElementById('shield'));

	themenuoffsetX=document.body.scrollLeft;
	themenuoffsetY=document.body.scrollTop;

	if (left.offsetParent.offsetLeft-themenuoffsetX-1+180>document.body.clientWidth)
		themenu.style.left=document.body.clientWidth-182;
	else
		themenu.style.left=left.offsetParent.offsetLeft-themenuoffsetX-1;

	themenu.style.top=66-themenuoffsetY;

	theshield.style.width=themenu.clientWidth+2;
	theshield.style.height=themenu.clientHeight+2;
	theshield.style.left=themenu.style.left;
	theshield.style.top=themenu.style.top;

	if (themenu.style.visibility=="hidden")
	{
		themenu.style.visibility="visible";
		theshield.style.visibility="visible";
	} else
	{
		themenu.style.visibility="hidden";
		theshield.style.visibility="hidden";
	}
	return false;
}

function dropitsub(left,e,whichone)
{
//hide everything
	document.onclick=hidemenu;
	parent.document.onclick=hidemenu;
	window.onscroll=hidemenu;
	if (themenu!=eval(parent.document.getElementById(whichone))) hidemenu();
	theshield=eval(parent.document.getElementById('shield'));

//get current menu
	themenu=eval(parent.document.getElementById(whichone));
	themenuoffsetX=document.body.scrollLeft;
	themenuoffsetY=document.body.scrollTop;
	themenu.style.left=left.offsetParent.offsetParent.offsetParent.style.left;
	themenu.style.top=66-themenuoffsetY;

	theshield.style.width=themenu.clientWidth+2;
	theshield.style.height=themenu.clientHeight+2;
	theshield.style.left=themenu.style.left;
	theshield.style.top=themenu.style.top;

	if (themenu.style.visibility=="hidden")
	{
		themenu.style.visibility="visible";
		theshield.style.visibility="visible";
	} else
	{
		themenu.style.visibility="hidden";
		theshield.style.visibility="hidden";
	}

	return false;
}

function hidemenu(e)
{
	if (!e || e.button==0)
	{
		if (themenu) themenu.style.visibility="hidden"
		if (theshield) theshield.style.visibility="hidden";
	}
}
function hidecallendar()
{
	if (theCallendar) theCallendar.style.visibility="hidden";
}


function donothing()
{
	if (themenu) themenu.style.visibility="hidden"
}


function NewWindow(mypage,myname,w,h,scroll,resize,stat)
{
	TopPosition = Math.floor(Math.random()*25);
	LeftPosition = Math.floor(Math.random()*25);
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=yes,scrollbars=yes,resizable=yes,status='+stat
	win = window.open(mypage,'_blank',settings)
	if(win.window.focus){win.window.focus();}
}

function NewWindowFix(mypage,myname,w,h,scroll,resize,stat)
{
	TopPosition = Math.floor(Math.random()*25);
	LeftPosition = Math.floor(Math.random()*25);
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=yes,scrollbars='+scroll+',resizable=yes,status='+stat
	win = window.open(mypage,myname,settings)
	if(win.window.focus){win.window.focus();}
}

function NewWindowOne(mypage,myname,w,h,scroll,resize,stat)
{
	TopPosition = Math.floor(Math.random()*25);
	LeftPosition = Math.floor(Math.random()*25);
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=yes,scrollbars='+scroll+',resizable=yes,status='+stat
	win = window.open(mypage,myname,settings)
	if(win.window.focus){win.window.focus();}
}

function NewMessenger(mypage,myname,w,h,scroll,resize,stat) 
{
	TopPosition = Math.floor(Math.random()*25);
	LeftPosition = Math.floor(Math.random()*25);
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable='+resize+',status='+stat;
	win = window.open(mypage,myname,settings)
	if(win.window.focus){win.window.focus();}
}



function openCallendar(e,type)
{
	document.onclick=hidecallendar;
	parent.document.onclick=hidecallendar;
	theCallendar=eval(document.getElementById(type));

	if (theCallendar.style.visibility=="visible")
	{
		theCallendar.style.visibility="hidden";
	} else
	{
		if (navigator.appName.toUpperCase().match(/MICROSOFT INTERNET EXPLORER/) != null || navigator.appName.toUpperCase().match(/OPERA/))
		{
			themenuoffsetX=document.body.scrollLeft;
			themenuoffsetY=document.body.scrollTop;
			theCallendar.style.left=themenuoffsetX + e.clientX-e.offsetX-2;
			theCallendar.style.top=themenuoffsetY + event.clientY-event.offsetY+14
		} else
		{
			themenuoffsetX=0;
			themenuoffsetY=0;
			theCallendar.style.left=e.layerX;
			theCallendar.style.top=e.layerY+5;
		}

		theCallendar.style.visibility="visible";
	}
	return false;
}


function setPointer(theRow, thePointerColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }
    var row_cells_cnt           = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }
    return true;
} 

function getAjaxResponse(theUrl) 
{

	var oReq;
 
	if (window.XMLHttpRequest)
	{

// IE7 or Mozilla
		oReq = new XMLHttpRequest();

	} else {

// IE6
		oReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

	}
 
	oReq.open("GET", theUrl.replace(/!URL!/, "itcubeSQL.jsp"),false);
	oReq.send(null);

	if (oReq.status&&oReq.status=='200')
		return oReq.responseText;
	else
		return "";
}

