
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var topelement = ns6? "HTML" : "BODY";
var moving=false;
var resizing=false;
var moveobj,coordsobj, x, y,x0,y0; 

function showcoords() {
	if (coordsobj==null)
	 return;
	var s=moveobj.style.left+','+moveobj.style.top;
//	if (parseInt(moveobj.style.width>0))
		s=s+' ('+moveobj.style.width+','+moveobj.style.height+')';
	coordsobj.innerHTML=s;
	}
	

function move(e) {
  if (moving) {
    moveobj.style.left=(ns6? x0+e.clientX-x: x0+event.clientX-x)+'px';
    moveobj.style.top=(ns6? y0+e.clientY-y : y0+event.clientY-y)+'px';
    if (parseInt(moveobj.style.top)<0)
    	moveobj.style.top=0+'px';
    if (parseInt(moveobj.style.left)<0)
    	moveobj.style.left=0;

	showcoords();
    return false;
  }
}

function resize(e) {
  if (resizing) {
//    moveobj.style.pixelLeft=ns6? x0+e.clientX-x: x0+event.clientX-x;
//    moveobj.style.pixelTop=ns6? y0+e.clientY-y : y0+event.clientY-y;

    moveobj.style.width=(ns6? x0+e.clientX-x: x0+event.clientX-x)+'px';
    moveobj.style.height=(ns6? y0+e.clientY-y : y0+event.clientY-y)+'px';

//    if (moveobj.style.top<0)
//    	moveobj.style.top=0+'px';
//    if (moveobj.style.left<0)
//    	moveobj.style.left=0;

	showcoords();
    return false;
  }
}

function findmoveobj(firedobj)
	{
  	moveobj=firedobj;
  	// find moveobj = main window to move
  	while (moveobj.tagName != topelement && moveobj.className.indexOf("draggable") == -1) {
    	moveobj = ns6? moveobj.parentNode : moveobj.parentElement;	
		}	
	// find coordsobj= coordinates window
	var r= moveobj.className.indexOf("draggable")!=-1;
	if (r) {
		coordsobj=moveobj.firstChild;
		while (coordsobj!=null && coordsobj.className.indexOf("coords")==-1) {
			coordsobj = coordsobj.nextSibling;
			}
		}
	// Return true if main window found
	return r;
	}

function mousedown(e) {
  if (!ie&&!ns6)
  return;
  var firedobj = ns6? e.target : event.srcElement;
  if (firedobj.className.indexOf("windragger")!=-1)
  	{
  	if (findmoveobj(firedobj)) {
    	moving = true;
	    x0 = moveobj.offsetLeft;
	    y0 = moveobj.offsetTop;
	    x = ns6? e.clientX: event.clientX;
	    y = ns6? e.clientY: event.clientY;
	    document.onmousemove=move;
	    return false;
		}
	}
  else if (firedobj.className.indexOf("winsizer")!=-1)
  	{
  	
  	if (findmoveobj(firedobj)) {
    	resizing = true;
	    x0 = moveobj.offsetWidth;
	    y0 = moveobj.offsetHeight;
	    x = ns6? e.clientX: event.clientX;
	    y = ns6? e.clientY: event.clientY;
	    document.onmousemove=resize;
	    return false;
		}
	}
  }

function mouseup()
	{
	moving=false;
	resizing=false;		
	}


document.onmousedown=mousedown;
document.onmouseup=mouseup;

function getData(dataSource,divId)
	{
	var XMLHttpRequestObject = false;
	if (window.XMLHttpRequest) 
		{XMLHttpRequestObject = new XMLHttpRequest();} 
	else if (window.ActiveXObject) 
		{XMLHttpRequestObject = new ActiveXObject('Microsoft.XMLHttp');}
	if(XMLHttpRequestObject) 
		{
		XMLHttpRequestObject.open('GET', dataSource);
		XMLHttpRequestObject.onreadystatechange = function()
			{
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
				{
				document.getElementById(divId).innerHTML = XMLHttpRequestObject.responseText;
				delete XMLHttpRequestObject;
				XMLHttpRequestObject = null;
				}
			}
	XMLHttpRequestObject.send(null);
		}
	}

function formfocus()
 {if (document.forms!=null) {if (document.forms[0].elements!=null) 
	{if (document.forms[0].elements[0]!=null) 	{document.forms[0].elements[0].focus();}}}}
