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;
}

function rebuildListItem(contentid){
	var divID;
	var sType, sTextStyle0, sTextStyle1, sTextStyle2, sTextStyle3, sText, sLevel;
	var sStartTitle, sEndTitle, sStartBold, sEndBold, sStartItalic, sEndItalic, sStartUnderline, sEndUnderline;
	var sLI, sTextHTML, sItemHTML, sHTML;
	
	divID = 'li_' + contentid;
	
	sStartTitle = '';
	sEndTitle = '';
	sStartBold = '';
	sEndBold = '';
	sStartItalic = '';
	sEndItalic = '';
	sStartUnderline = '';
	sEndUnderline = '';
	
	sType = document.forms['submitform'].type.value;
	sTextStyle0 = document.forms['submitform'].textstyle[0].checked;
	sTextStyle1 = document.forms['submitform'].textstyle[1].checked;
	sTextStyle2 = document.forms['submitform'].textstyle[2].checked;
	sTextStyle3 = document.forms['submitform'].textstyle[3].checked;
	sText = document.forms['submitform'].text.value;
	sLevel = document.forms['submitform'].level.value;
	
	//alert('type= ' + sType + ' textstyle1= ' + sTextStyle1 + ' textstyle2= ' + sTextStyle2 + ' textstyle3= ' + sTextStyle3 + 'text= ' + sText + ' level = ' + sLevel);
	
	if (sTextStyle0){sStartTitle = '<h3 style="margin-top: 0px; margin-bottom: 0px;">'; sEndTitle='</h3>';}
	if (sTextStyle1){sStartBold = '<b>'; sEndBold='</b>';}
	if (sTextStyle2){sStartItalic = '<i>'; sEndItalic='</i>';}
	if (sTextStyle3){sStartUnderline = '<u>'; sEndUnderline='</u>';}	
    
    sTextHTML = sStartTitle + sStartBold + sStartItalic + sStartUnderline + sText + sEndUnderline + sEndItalic + sEndBold + sEndTitle;
    
	sLI = '<li type="' + sType + '" style="margin-bottom: 0px;">' + sTextHTML + '</li>';
	
	//alert(sLI);
	
	switch (sType) 
	{ 
	   case 'A':	
		  sItemHTML = '<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ol>';	     
	      break;
	   case 'a':	
		  sItemHTML = '<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ol>';	     
	      break;
	   case 'I':	
		  sItemHTML = '<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ol>';	     
	      break;
	   case 'i':	
		  sItemHTML = '<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ol>';	     
	      break;
	   case '1':	
		  sItemHTML = '<ol style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ol>';	     
	      break;
	   case 'disc': 
		  sItemHTML = '<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ul>';
	      break; 
	   case 'circle': 
		  sItemHTML = '<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ul>';
	      break;
	   case 'square': 
		  sItemHTML = '<ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px;">' + sLI + '</ul>';
	      break; 
	   default : 
		  sItemHTML = sTextHTML;		 
	} 
	
	sHTML =
		'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>' +
		'<table cellpadding="0" cellspacing="0" border="0"><tr><td>' +
		'<img src="/images/spacer.gif" height="1" name="listitem_' + contentid +
		'" width="' + parseInt(sLevel) * 10 + '">' + 	
		'</td><td>' + sItemHTML + '</td>' + 
		'</tr></table></td>' +
		'<td align="right" valign="top">' +
			'<table cellpadding="0" cellspacing="0" border="0">' +
				'<tr>' +
					'<td align="center">'+
						'<img src="/core/framework/images/buttons/edit_light.gif" border="0" />' +
					'</td>' +
					'<td valign="middle"><img src="/core/framework/images/acumium/spacebar9.gif" height="9" alt="" /></td>' +
					'<td align="center">' +
						'<img src="/core/framework/images/buttons/delete.gif" border="0" />' +
					'</td>' +
				'</tr>' +
			'</table>' +
		'</td>' +		
		'</tr></table>';
			
	document.all[divID].innerHTML = sHTML;

}

function adjustLILevelDown(contentid, oForm)
{
	var curLevel, newLevel, imageID;
	
	curLevel = parseInt(oForm.level.value);
	imageID = 'listitem_' + contentid;
	
	if (curLevel > 0){
			newLevel = curLevel - 1;
			document.images[imageID].width = newLevel * 10;
			oForm.level.value = newLevel;
	}	
}

function adjustLILevelUp(contentid, oForm)
{
	var curLevel, newLevel, imageID;
	
	curLevel = parseInt(oForm.level.value);
	imageID = 'listitem_' + contentid;
	
	newLevel = curLevel + 1;
	document.images[imageID].width = newLevel * 10;
	
	oForm.level.value = newLevel;
}
						
//drag and drop global functions
function cancelEvent() {
    window.event.returnValue = false;
}

function getActionType(){
	var actionType;
							
	if (event.ctrlKey){
		actionType = 'copy';	
	}else{
		actionType = 'move';
	}
							
	return actionType;
}
					