var clientX;
var clientY;var X;var Y;
var bMoving = false;
var bResizing = false;
var iMAC_TOP = 70;
var iMAC_LEFT = 186;
var iPC_TOP = iMAC_TOP;
var iPC_LEFT = iMAC_LEFT;
var iMAC_DEFAULT_WIDTH = 300;
var iMAC_DEFAULT_HEIGHT = 100;
var iPC_DEFAULT_WIDTH = 300;
var iPC_DEFAULT_HEIGHT = 300;
if(document.layers){document.captureEvents(Event.mousedown | Event.mousemove | Event.mouseup);}
function initEditor(e){

	if(gBrowserType() != "NS"){
		if(gOS() == "MAC"){
			if(parseInt(document.all['elementeditor'].style.pixelTop) == 0) document.all['elementeditor'].style.pixelTop = iMAC_TOP;
	 		if(parseInt(document.all['elementeditor'].style.pixelLeft) == 0) document.all['elementeditor'].style.pixelLeft = iMAC_LEFT;	 		
		}else{
			if(parseInt(document.all['elementeditor'].style.pixelTop) == 0) document.all['elementeditor'].style.pixelTop = iPC_TOP;
			if(parseInt(document.all['elementeditor'].style.pixelLeft) == 0) document.all['elementeditor'].style.pixelLeft = iPC_LEFT;
		}
		document.all['resizewindow'].onmousedown=getResizePosition;
		document.all['toolbar'].onmousedown=getPosition;
		try{
		if(document.all['onecolform'])	document.all['onecolform'].style.visibility = "hidden";
		if(document.all['twocolform'])	document.all['twocolform'].style.visibility = "hidden";
		if(document.all['threecolform'])	document.all['threecolform'].style.visibility = "hidden";
		if(document.all['multicolform'])	document.all['multicolform'].style.visibility = "hidden";
		}catch (e){}
		document.all['elementeditor'].style.visibility = "visible";
	}
	return true;
}
						
function getResizePosition(e)
{
	bMoving = false;
	bResizing = true;
	document.onmouseup=stopResizing;
	document.onmousemove=resizeDiv;
							
	if(document.layers){
		document.layers['elementeditor'].zindex = 0;
		/*
		if(isNaN(parseInt(document.layers['elementeditor'].height))) document.layers['elementeditor'].height = 300;
		if(isNaN(parseInt(document.layers['elementeditor'].width))) document.layers['elementeditor'].width = 300;
							
		clientX = e.clientX;
		clientY = e.clientY;
		*/
	}else{
		if(gOS() == "MAC"){
			if(isNaN(parseInt(document.all['elementeditor'].style.height))) document.all['elementeditor'].style.height = iMAC_DEFAULT_HEIGHT;
			if(isNaN(parseInt(document.all['elementeditor'].style.width))) document.all['elementeditor'].style.width = iMAC_DEFAULT_WIDTH;
		}else{
			if(isNaN(parseInt(document.all['elementeditor'].style.height))) document.all['elementeditor'].style.height = iPC_DEFAULT_HEIGHT;
			if(isNaN(parseInt(document.all['elementeditor'].style.width))) document.all['elementeditor'].style.width = iPC_DEFAULT_WIDTH;
		}
		
		if(gOS() == "MAC"){
			X = event.clientX;
			Y = event.clientY;
		}else{
			X = event.x;
			Y = event.y;
		}
		document.onmousedown=null;	
	}
							
	return true;
}
						
function stopResizing(e){
	bResizing = false;
	document.onmousemove=null;
	document.onmouseup=null;
							
	return true;
}
						
function resizeDiv(e){
	if(bResizing){
		if(document.layers){
			/*
			document.layers['elementeditor'].height = parseInt(document.layers['elementeditor'].height) + eval(e.clientY - clientY);
			document.layers['elementeditor'].width = parseInt(document.layers['elementeditor'].width) + eval(e.clientX - clientX);
			clientY = e.clientY;
			clientX = e.clientX;
			*/
		}else{
			if(gOS() == "MAC"){
				document.all['elementeditor'].style.height = parseInt(document.all['elementeditor'].style.height) + eval(event.clientY - Y);
				document.all['elementeditor'].style.width = parseInt(document.all['elementeditor'].style.width) + eval(event.clientX - X);
			}else{
				document.all['elementeditor'].style.height = parseInt(document.all['elementeditor'].style.height) + eval(event.y - Y);
				document.all['elementeditor'].style.width = parseInt(document.all['elementeditor'].style.width) + eval(event.x - X);			
			}
									
			if(gOS() == "MAC"){
				X = event.clientX;
				Y = event.clientY;
			}else{
				X = event.x;
				Y = event.y;
			}
		
		}
		return true;
	}
}
						
function getPosition(e)
{
	bResizing = false;
	bMoving = true;
	document.onmouseup=stopMoving;
	document.onmousemove=moveDiv;
						
	if(document.layers){
		/*
		if(parseInt(document.layers['elementeditor'].top) == 0) document.layers['elementeditor'].top = 200;
		if(parseInt(document.layers['elementeditor'].left) == 0) document.layers['elementeditor'].left = 100;
							
		clientX = e.clientX;
		clientY = e.clientY;
		*/
	}else{
		if(gOS() == "MAC"){
			if(parseInt(document.all['elementeditor'].style.pixelTop) == 0) document.all['elementeditor'].style.pixelTop = iMAC_TOP;
			if(parseInt(document.all['elementeditor'].style.pixelLeft) == 0) document.all['elementeditor'].style.pixelLeft = iMAC_LEFT;
		}else{
			if(parseInt(document.all['elementeditor'].style.pixelTop) == 0) document.all['elementeditor'].style.pixelTop = iPC_TOP;
			if(parseInt(document.all['elementeditor'].style.pixelLeft) == 0) document.all['elementeditor'].style.pixelLeft = iPC_LEFT;		
		}
							
		if(gOS() == "MAC"){
			X = event.clientX;
			Y = event.clientY;			
		}else{
			X = event.x;
			Y = event.y;
		}

		document.onmousedown=null;	
	}
	return true;
}
						
function stopMoving(e){
	bMoving = false;
	document.onmousemove=null;
	document.onmouseup=null;
	return true;
}
						
function moveDiv(e){
	if(bMoving){
		if(document.layers){
			/*
			document.layers['elementeditor'].top = parseInt(document.layers['elementeditor'].top) + eval(e.clientY - clientY);
			document.layers['elementeditor'].left = parseInt(document.layers['elementeditor'].left) + eval(e.clientX - clientX);
			clientY = e.clientY;
			clientX = e.clientX;
			*/
		}else{
			if(gOS() == "MAC"){
				document.all['elementeditor'].style.pixelTop = parseInt(document.all['elementeditor'].style.pixelTop) + eval(event.clientY - Y);
				document.all['elementeditor'].style.pixelLeft = parseInt(document.all['elementeditor'].style.pixelLeft) + eval(event.clientX - X);
			}else{
				document.all['elementeditor'].style.pixelTop = parseInt(document.all['elementeditor'].style.pixelTop) + eval(event.y - Y);
				document.all['elementeditor'].style.pixelLeft = parseInt(document.all['elementeditor'].style.pixelLeft) + eval(event.x - X);
			}

			if(gOS() == "MAC"){
				X = event.clientX;
				Y = event.clientY;
			}else{
				X = event.x;
				Y = event.y;
			}
		}
								
	}
	return true;
}
						
