document.onmousemove=displaycoordNS;
var day;
var MyObj  = null;
var calDiv = document.createElement("div");

function openCalendar(obj, x_l, x_t, kod, text, w, h)
{
	MyObj = obj;
	html = '<div id="img_body" style="position:absolute; width:'+w+'px;" onClick="closeCal()"><img src="'+kod+'" alt=""><p>'+text+'</p><div class="closediv"></div></div>'
	if (!x_l)
		x_l = 0;
	if (!x_t)
		x_t = -50;
	if(!document.all)
	{
		x_t = 0;
	}

	calDiv.innerHTML = html;
	
	calDiv.style.position = 'absolute';
	calDiv.style.zIndex = 301;
	var x_left = calcLeft(obj) - 3 + x_l;
	var y_top = calcTop(obj) + obj.offsetHeight - 3 + x_t;
	
	
	//document.testform.test1.value=y_top;
	//document.testform.test2.value=top_panel+y_bottom;
	//document.testform.test3.value=y_bottom;
	//document.testform.test4.value=h;
	
	y_bottom += h;
	if (y_bottom > screen.height-100)
		y_top = y_top - y_bottom + screen.height-100;

	//document.testform.test5.value=y_top;
	calDiv.style.left = x_left + 'px';
	calDiv.style.top = y_top + 'px';
	document.body.appendChild(calDiv);
}

function openFoto(obj, x_l, x_t, kod, text, w, h)
{
	MyObj = obj;
	html = '<div id="img_body" style="position:absolute; width:'+w+'px;" onClick="closeCal()"><img src="'+kod+'" alt=""><p>'+text+'</p><div class="closediv"></div></div>'
	if (!x_l)
		x_l = 0;
	if (!x_t)
		x_t = -50;
	if(!document.all)
	{
		//x_t = 0;
	}

	calDiv.innerHTML = html;
	
	calDiv.style.position = 'absolute';
	calDiv.style.zIndex = 301;
	var x_left = calcLeft(obj) - 3 + x_l;
	var y_top = calcTop(obj) + obj.offsetHeight - 13 + x_t;
	
	
	//document.testform.test1.value=x_left;
	//document.testform.test2.value=x_bottom;
	//document.testform.test3.value=h;
	
	y_bottom += h;
	if (y_bottom > screen.height-100)
		y_top = y_top - y_bottom + screen.height-100;
	x_bottom = x_left + w;
	if (x_bottom > screen.width-100)
		x_left = x_left - x_l - w - 10;
	//x_left=500;
	//document.testform.test4.value=x_bottom;
	//document.testform.test5.value=screen.width;
	calDiv.style.left = x_left + 'px';
	calDiv.style.top = y_top + 'px';
	document.body.appendChild(calDiv);
}

function displaycoordNS(e){
		if(document.all)
	{
		y_bottom=event.screenY;
		x_bottom=event.screenX;
		//top_panel=event.screenY - event.clientY;
	}
	else
	{
		y_bottom=e.screenY;
		x_bottom=e.screenX;
		//top_panel=e.screenY - e.clientY;
	}
}

function closeCal()
{
	document.body.removeChild(calDiv);
}

function calcTop(ele)
{
	var oParent = ele.offsetParent;
	if (oParent == null)
		return 0;
	return ele.offsetTop + (!isNaN(oParent.clientTop) ? oParent.clientTop : 0) + calcTop(oParent);
}                       


function calcLeft(ele)
{
    var curleft = 0;
    if (ele.offsetParent)
      {
       while (ele.offsetParent)
         {
          curleft += ele.offsetLeft;
          ele = ele.offsetParent;
         }
      }
    else if (ele.x)
      curleft += ele.x;
    return curleft;
}

