NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
var W3C = (document.getElementById) ? 1 : 0;	
var strActiveToolbar = ''
var strLastActiveToolbar = ''

/* hide/show layer */
function findPosX(evt)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (evt.offsetParent)
		{
			curleft += evt.offsetLeft
			evt = evt.offsetParent;
		}
	}
	else if (document.layers)
		curleft += evt.x;
	return curleft;
}

function findPosY(evt)
{
	var curtop = 0;
	var printstring = '';
	if (document.getElementById || document.all)
	{
		while (evt.offsetParent)
		{
			curtop += evt.offsetTop
			evt = evt.offsetParent;
		}
	}
	else if (document.layers)
		curtop += (evt.y - 100);
	return curtop;
}

function show ( evtname, name, blnShowHide) 
{
	if (W3C) 
	{
    	evt = document.getElementById(evtname)
  	}
	else if (NS4)
	{
    	evt = document.layers[evtname]
  	}
	else
	{
    	evt = document.all[evtname]
  	}
	var newX = findPosX(evt);
	var newY = findPosY(evt);

  	var ele;		//points to the popup element
  	if (W3C) 
  	{
  		ele = document.getElementById(name).style;
		visible = "visible"
		hidden  = "hidden"
  	} 
	else if (NS4) 
	{
		ele = document.layers[name];
		visible = "show"
		hidden  = "hide"
  	} else {
   		ele = document.all[name].style;
		visible = "visible"
		hidden  = "hidden"
  	}

	strLastToolbar = strLastActiveToolbar.toString();
	intLastIndex = strLastToolbar.substr(strLastToolbar.indexOf('_') + 1, strLastToolbar.length)
	strCurrentToolbar = evtname.toString();
	intCurrentIndex = strCurrentToolbar.substr(strCurrentToolbar.indexOf('_') + 1, strCurrentToolbar.length)
	if ((intLastIndex == intCurrentIndex) && (blnShowHide == 'true'))
	{
		if (ele.visibility == "visible") 
		{
			ele.visibility = "hidden";
		} 
		else if (ele.visibility == "hidden") 
		{
			ele.visibility = "visible";
		} 
	}
	else
	{	
		ele.left = newX + 14;
		ele.top = newY - 56;
		ele.visibility = "visible";
	}
}

function hide ( name ) {
	if (W3C) 
	{
    	document.getElementById(name).style.visibility = "hidden";
  	}
	else if (NS4)
	{
    	document.layers[name].visibility = "hide";
  	}
	else
	{
    	document.all[name].style.visibility = "hidden";
  	}
}
			
function change_class_name(strId, strClassName, strType)
{
	if (W3C) {
		objEleIcon = document.getElementById(strId);
	} else if (NS4) {
		objEleIcon = document.layers[strId];
	} else {
		objEleIcon = document.all[strId];
  	}
	if (strType != '')
	{
		objEleIcon.className = strClassName;
	}
	else
	{
		objEleIcon.className = strClassName;
	}
}

function initialize_editor(intNumContent)
{
    for (i = 0; i < document.all.length; i++)
	{
		document.all(i).unselectable = "on"
	}
    for (i = 0; i < intNumContent; i++)
	{
		j = i + 1
		objEle = eval('content_' + j)
		objEle.unselectable = 'off'
	}
}

function format_content(strType, strValue) 
{ 
	if (W3C) {
		objEle = document.getElementById(strActiveToolbar);
	} else if (NS4) {
		objEle = document.layers[strActiveToolbar];
	} else {
		objEle = document.all[strActiveToolbar];
  	}
	eval(strActiveToolbar + ".focus()")
	if (strType != '') 
	{
		switch(strType) 
		{ 
			case 'heading':
				if(strValue != '') 
				{
					strValue = '<' + strValue + '>';
					document.execCommand("FormatBlock", false, strValue); 
				}
				break;
			default:
				if (strValue != '') 
				{
					document.execCommand(strType, false, strValue);
				}
				else
				{
					document.execCommand(strType);
				}
				break;
		}
		eval(strActiveToolbar+".focus()")
	}
}

function create_bookmark(strValue)
{
	//alert(window.opener.content_1.focus())
	//eval("window.opener." + strActiveToolbar + ".focus()")
	window.opener.document.execCommand("CreateLink", false, strValue);
//	eval("window.opener." + strActiveToolbar+".focus()")
}

function set_active_toolbar(strToolbarName)
{
	strLastActiveToolbar = strActiveToolbar
	strActiveToolbar = strToolbarName
	eval(strActiveToolbar+".focus()") 
}

function open_window_image() 
{
	objEditorWindow = window.open('editor/editor_command_image.php?edtr='+strActiveToolbar, 'editor_command_image', 'toolbars=no,scrollbars=no,width=347,height=90,top=300,y=400')
	objEditorWindow.focus();
}

function open_window_file() 
{
	objEditorWindow = window.open('../editor/edit_file.php?edtr='+strActiveToolbar, 'editor_command_file', 'toolbars=no,scrollbars=no,width=347,height=100,top=300,y=400')
	objEditorWindow.focus();
}

function check_textfield(objField, strId)
{
	if (W3C) {
		objElement = document.getElementById(strId);
	} else if (NS4) {
		objElement = document.layers[strId];
	} else {
		objElement = document.all[strId];
  	}
	if (objField.value != '')
	{
		objElement.disabled = false;
		objElement.className = 'button';
	}
	else if (objField.value == '')
	{
		objElement.disabled = true;
		objElement.className = 'buttondisabled';
	}
}
function open_window_anchor(intNumContent) 
{
	objEditorWindow = window.open('../editor/editor_command_anchor.php?num='+intNumContent, 'editor_command_anchor', 'toolbars=no,scrollbars=no,width=320,height=100,top=300,y=400')
	objEditorWindow.focus();
}



 
 
//icall mo lang to 
//movePage('top')
//movePage('up')
//movePage('down')
//movePage('bottom')
