var isOpen=true;
var myFrame; //pointer to the iFrame doc
var myFlash; //pointer to flash application
var myDiv; //pointer to navigation div
var myBody; //pointer to doc body
var popupWin;

function getEditor(appServer, contentid, defaultEditor)
{
	var myDoc = top.parent.frames["contentFrame"];

	if(!myDoc.x8Editing)
	{
		window.document.location = appServer+"/editor."+appServer+"?contentid="+contentid;
	}
	else
	{
		alert("If you continue, you will lose any unsaved changes to the current document being edited");
	}
}

function doUpload(what, appServer)
{
popupWin = window.open(""+appServer+"\/"+what+"Manager\/"+what+"Upload."+appServer+"", "octane8", "left=270,top=210,width=300,height=100,location=0,toolbar=0,scrollbars=0,scrolling=no");
}

function doCanEdit()
{
	// this script merely creates an object ref to the flash frameset. We use this to show/hide the flash for layering html on top, particularly for workflow editing.
	myFlash = document.getElementById("x8receiver");
}

function doToggle(){
	// this script toggles the menu frame open/closed.
	if(document.getElementById)
	{
		if(isOpen)
		{ 
			top.parent.document.getElementById('x8main').setAttribute('cols','0,*');
			isOpen=false;
		}
		else
		{
			top.parent.document.getElementById('x8main').setAttribute('cols','250,*');
			isOpen=true;
		}
	}
	else
	{
		alert("You will need to upgrade your browser in order to use this feature. Either Mozilla 1.4+, Netscape 7+, IE 5.5+ or Opera 7+ will work fine");
	}
}

function doPreview(id,appServer,edit,task)
{
	/*
	user has clicked "preview" or "edit" button from the task/approval list. This allows the content to be previewed in the web browser
	JSB added edit attribute to allow getPreview file to execute editor or preview. edit=true/false
	*/
	myFlash.style.visibility = "hidden"; // SAFARI IS NOT ABLE TO HIDE THE FLASH MOVIE, HOWEVER
	myFrame = document.getElementById('x8iframe');
	myDiv = document.getElementById('x8navdiv');
	myBody = document.getElementById('x8body');
	myBody.style.border = "1px solid #999";
	myBody.style.borderTop = "none";
	myDiv.style.display = "block";
	myFrame.setAttribute("src", appServer+"/groupManager/getPreview."+appServer+"?itemid="+id+"&edit="+edit+"&task="+task);
	myFrame.style.width = "100%";
	myFrame.style.height = "96.2%";
	myFrame.style.visibility = "visible";
}

//Create a comments view from approvals
function x8doDetails(action, contentid)
{
	var myDialogFrame = top.parent.frames["x8toolbar"]; //pointer to the sitemenu frameset on the left side
	myDialogFrame.isOpen=false; //assume that its closed, otherwise we don't need this
	myDialogFrame.doToggle();
	myFrame = document.getElementById('x8iframe');
	myFrame.style.visibility = "visible";
	myFrame.style.width = "20px";
	myFrame.style.height = 0;
	myFrame.src = "aspx/getPageDetails.aspx?action="+action+"&contentid="+contentid;
}


function doBack()
{
	//this removes the iframe used to preview the content.
	myBody.style.border = 0;
	myFrame.style.width = 0;
	myFrame.style.height = 0;
	myFrame.src = "aspx/editor/fckblank.html";
	myFrame.style.visibility = "hidden";
	//myFrame.setAttribute("src","");  //THIS CRASHES SAFARI
	myFlash.style.visibility = "visible";
	myDiv.style.display = "none";
}

function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf(";",offset);
	if(endstr==-1)
	{
		endstr=document.cookie.length;
	}
	return unescape(document.cookie.substring(offset,endstr));
}

function getCookie(name)
{
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	
	while(i<clen)
	{
		var j=i+alen;
		
		if(document.cookie.substring(i,j)==arg)
		{
			return (getCookieVal(j));
		}
		
		i=document.cookie.indexOf(" ",i)+1;
	
		if(i==0)
		{
			break;
		}
	}
	return(null);
}

function doTipCheck(value)
{
	// this function is called from x8tips.swf to set the "Don't show again" value for the Tree menu's startup tips
	document.cookie = "x8token3="+value+"; expires=Wed, 24-Nov-66 00:00:01 GMT";
}


// this function sets the user's tokens for loading animations (x8token1), unload alert on editor (x8token2), and startup tip display (x8token3).
function doSettings(what)
{
	var myArray = what.split(',');
	for (var i = 1; i<myArray.length; i++) 
	{
		document.cookie = myArray[i]+"; expires=Wed, 24-Nov-66 00:00:01 GMT";
	}
}


