// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
/*if (!IE) document.captureEvents(Event.MOUSEMOVE)*/

// Temporary variables to hold mouse x-y pos.s
var mouseX = 0
var mouseY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}
  return true
}

function setLyr(obj,lyr)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	var x = new getObj(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

function setLyr2(obj,X,Y)
{
	obj.style.top = Y + 'px';
	obj.style.left = X + 'px';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			//printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	window.status = '';
	return curtop;
}	 
function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		if (document.layers[name])
		{
		this.obj = document.layers[name];
		this.style = document.layers[name];
		}
		else
		{
		this.obj = document.layers.testP.layers[name];
		this.style = document.layers.testP.layers[name];
		}
	}
}		

var objdiv, objdivName, objdivStyle, over = false;
var thisBrowser = "";
var X, Y;
function startDrag(e) 
{
	if (over)
	{
		objdiv = document.getElementById(objdivName);
		objdivStyle = objdiv.style;
		if (thisBrowser=="ie")
		{
			X = event.clientX-objdivStyle.pixelLeft;
			Y = event.clientY-objdivStyle.pixelTop;			
		}
		else		
		{
			X = e.clientX-parseInt(objdivStyle.left);
			Y = e.clientY-parseInt(objdivStyle.top);
		}
	}	
}

// keypad'in mouse ile sürüklenirken mouse'un yeni koumu için keypad'i konumlandırır
function drag(e) 
{
	getMouseXY(e);
	if (objdiv) 
	{
		if (thisBrowser=="ie")
		{
			objdivStyle.pixelTop = event.clientY-Y;
			objdivStyle.pixelLeft = event.clientX-X;
		}
		else
		{
			objdivStyle.left = parseInt(e.clientX)-X;
			objdivStyle.top = parseInt(e.clientY)-Y;
		}
		return false;
	}
}

function browserDetect() 
{
	if(document.layers)
	{
		thisBrowser="NN4";
		keypadClose=true;
	}
	else
	{
		if(document.all)
			thisBrowser="ie";
		else
		{
			if(!document.all && document.getElementById)
				thisBrowser="NN6+";
			else
				keypadClose=true;
		}
	}
}

// keypad'in mouse ile sürüklenmesi bittiğinde keypad referans objesini siler
function endDrag() 
{
	objdiv = null;
}

//aşağıdakiler sayfa yüklemesinde çalıştırmak gerek
browserDetect();

document.onmousedown = startDrag; 
document.onmousemove = drag;
document.onmouseup = endDrag;


