// This is a wrapper around alttxt functions
function displayPopup(popupText)
{

	//alert("onMouseOver: " + window.loaded);

	if(window.loaded == true)
	{
		writetxt(popupText);
		return true;
	}
	else
	{
		return false;
	}
	
}

function removePopup()
{
	//alert("onMouseOut: " + window.loaded);

	if (window.loaded == true)
	{
		writetxt(0);
		return true;
	}
	else
	{
		return false;
	}


}


function changeSelectedScope(theForm)
{
	var action = theForm.formAction.value;
	var scopeToken = theForm.studentList.options[theForm.studentList.selectedIndex].value
	var destination = action + "&scopeToken=" + scopeToken + "#discussion";
	
	location = destination;
}





function validateMsgLength(theForm)
{
	var msgLength = theForm.messageBody.value.length;

	if ( msgLength == 0)
	{
		alert("You must type a message before posting.")
		return false;
	
	}
	else if (msgLength >= 100000)
	{
		alert("Messages must be shorter than 100000 characters.\nThis message contains " + msgLength + " characters.\n\nYou should save your message in a text editor\nbefore continuing.");
		return false;
	}
	else
	{
		return true;
	}

}

function validateCommentLength(theForm)
{
	var msgLength = theForm.comment.value.length;

	if ( msgLength == 0)
	{
		alert("You must type a comment before posting.")
		return false;
	
	}
	else if (msgLength >= 100000)
	{
		alert("Comments must be shorter than 100000 characters.\nThis comment contains " + msgLength + " characters.\n\nYou should save your comment in a text editor\nbefore continuing.");
		return false;
	}
	else
	{
		return true;
	}

}



function openAttachmentWindow(url)
{

	var w = window.open(url, "attachment");
	w.focus();

}




function popupHelp(url)
{

	var screenHeight = screen.availHeight;
	var screenWidth = screen.availWidth;
	
	// Put the popup center the popup
	var windowLeft = (screenWidth - 400) / 2;
	windowLeft = parseInt(windowLeft);
	
	
	// Put the popup 1/5 from the top of the page
	var windowTop = screenHeight / 5;
	windowTop = parseInt(windowTop);
	
	
	// Window height is 1/2 the screen height
	
	var windowHeight = screen.availHeight/2;
	windowHeight = parseInt(windowHeight);
	
	var windowFeatures;
	
	windowFeatures = "width=400, toolbar=false, scrollbars=yes, resizable=yes" + ", height=" + windowHeight + ", top=" + windowTop + ", left=" + windowLeft;
	

	var w = window.open(url, "popupHelp", windowFeatures);
	w.focus();

}


function notImplemented()
{

	alert("This feature is not implemented.");
}


function checkFiles(myForm,numfile)
{
	var noattachment = 0;
	var index = 0;
	var v;
	//determine number of files attached 	
	
	for (var i = 1; i <= numfile; i++)
	{	
	
		index = i - 1;		
		v = eval(myForm + '.fileitem_' + index);
		
		if ((v.value == "") || (v.value == null)) 
		{	
			noattachment = noattachment + 1; 
		}
	}
	
	//if no files are attached 
	
	if (noattachment == numfile)
	{
		//separate error messages for one file upload field vs. many
		
		if (numfile == 1)
			alert("Please specify a file in the upload area before clicking the Send Work button");
		else
			alert("Please specify files in the upload areas before clicking the Send Work button");
	
	}
	else if (noattachment > 0) //if one of more files are not attached 
	{
		var result = confirm("You have one or more empty upload areas.\n\n  Do you want to send only the specified file(s)?")
		if (result == 1)
		{
			eval(myForm + '.submit()'); 
			return true;
		}
	}
	else
	{
		eval(myForm + '.submit()');
		return true;			
	}
	return false;
}


//mood begin

function MtoDiscussion() {
	var contentHeight = this.document.getElementById('coreContent').scrollHeight;
	ManimateScroll(contentHeight);
}

function ManimateScroll(y) {
	var contentHeightLoops = 60;
	var interval = y/contentHeightLoops;
	for (var loop=0; loop < contentHeightLoops; loop++)
	{
	    scrollBy(0, interval);
	}
	
	// After slow scrolling, be sure to scroll to the exact position requested
	scrollTo(0,y);

	//make sure we are still at the top on the parent window 
	//(safari-related bug combined with bogus top document height larger than browser window height)
	window.parent.scrollTo(0,0);
}

function drawDiscBarMood(tagname, newMsgCount, totalMsgCount, showActivityDiscString)
{

	var sHTML = "";

	// Nonsense data -- do nothing
	if (newMsgCount > totalMsgCount)
	{
		return;
	}
	

	// No messages at all
	if (totalMsgCount == 0)
	{
		if(showActivityDiscString == true )
			//sHTML += '<span class="smallText">No discussion has been started on this page.</span>'
			sHTML +=	'<div class="messageFlagCont"><table class="messageFlag"><tr><td style="vertical-align:top; padding:5px 0 0 0"><span class="msgSpan">Messages</span></td><td><a class="commentsIcon" href="javascript:MtoDiscussion()">0</a></td></tr></table></div>';
	
			//sHTML += '<a href="javascript: self.focus();self.print()" style="text-align: right; font-size: 80%; float: right; margin-top: -18px; margin-right: 12px;">Print this page</a>';
		document.getElementById(tagname).innerHTML = sHTML;	
		return;
	}

	var plural = '';
	if(totalMsgCount != 1)
		plural = 's';
		
	
	
	var existingMsgCount = totalMsgCount - newMsgCount;
	//var helpFile = "/help/discussion_indicator.htm";

	// The longest possible bar will be 100%
	var maxWidth = 300;
	var totalWidth;
	var existingWidth = 0;
	
	if (totalMsgCount <= 100)
		totalWidth= parseInt(totalMsgCount/maxWidth * 1000);
	else
		totalWidth = maxWidth;  // If there are more than 100 posts, the bar width is the max width

	if (existingMsgCount < 100)
	{
		//existingWidth = parseInt(existingMsgCount/maxWidth * 1000);
		existingWidth = existingMsgCount * 3;
		newMsgWidth = newMsgCount * 3;
	}
	else
	{
		existingWidht = existingMsgCount * 2;
		newMsgWidth = newMsgCount * 2;
	}		
	if (newMsgCount == 0) newMsgWidth = 10;

	// All messages are new
	if (newMsgCount > 0) 
	{

sHTML +=	'<div class="messageFlagCont"><table class="messageFlag"><tr><td style="vertical-align:top; padding:5px 0 0 0"><span class="msgSpan">Messages</span><div style="padding:0; margin:0; position:relative; top:-5px; height:auto"><span class="messageFlagNew">New!:</span>&nbsp;<a class="messageFlagNewHyper" href="javascript:MtoDiscussion()">'+ newMsgCount + '</a></div></td><td><a class="commentsIcon" href="javascript:MtoDiscussion()">' + totalMsgCount + '</a></td></tr></table></div>';
	
	
	

		//sHTML += '<a href="javascript: self.focus();self.print()" style="text-align: right; font-size: 80%; float: right; margin-top: -18px; margin-right: 12px;">Print this page</a>';
	
		//sHTML += '<span class="barGraph">' + '<span class="barNew" style="width: ' + totalWidth + 'px;">' + totalMsgCount + '</span>' +  '</span>' + '<span class="barTotal">&nbsp;' + totalMsgCount + '&nbsp;total</span>';
		//sHTML += '<span class="smallText" style="position: relative; left: 12px;"><a href="javascript: popupHelp(\'' + helpFile + '\');">What\'s this</a>?</span>';
		document.getElementById(tagname).innerHTML = sHTML;
		return;
	}	


	
	
	// This is a special case where the proportional width is too small to
	// display the count without wrapping.
	if (newMsgCount == 1 && totalMsgCount == 2)
		totalWidth = parseInt(3/maxWidth *1000);

	// No new messages
	if (newMsgCount == 0)
	{
	
		  //	<td class="barZeroNew" style="width: 10px"; text-align:center;>0</td>
		//<td class="barGraph" style="width: 60px;">&nbsp;</td>
        //<td class="barTotal">&nbsp;7 messages posted about this page (7 new)</td>
	
	//newMsgWidth = 10;
	//existingWidth = 60;
	
	
sHTML +=	'<div class="messageFlagCont"><table class="messageFlag"><tr><td style="vertical-align:top; padding:5px 0 0 0"><span class="msgSpan">Messages</span></td><td><a class="commentsIcon" href="javascript:MtoDiscussion()">' + totalMsgCount + '</a></td></tr></table></div>';
	
	

		document.getElementById(tagname).innerHTML = sHTML;
		//alert(sHTML);
		return;
	}	


	
	document.getElementById(tagname).innerHTML = sHTML;
	return;
}


function disableSubmitButton( elementName )
{
	document.getElementById(elementName).style.visibility = "hidden";
	showPleaseWaitArea();
}

function showPleaseWaitArea() {
	document.getElementById("pleaseWaitArea").style.visibility = "visible";
}

function hideSubmitButton( elementName )
{
	document.getElementById(elementName).style.visibility = "hidden";
}
  	
function showProgressBar(progressBar)
{		
	var oIframe = document.getElementById(progressBar);
	oIframe.src = "/jsp/fileUploadProgress.jsp";
	oIframe.style.width = 290 + "px";
	oIframe.style.height = 70 + "px";
	oIframe.style.display = "block";
}

//mood - end
