//Title: Global javascript functions
//       for essay type activity
//Author: Tom Hudson
//Date: 10/01/03


//Define the images to be used in the activity
var imageList = new Array(); /****/

for(imgInd=0; imgInd < intImageTotal; imgInd++) 
{
	if(imgInd < 9)
	{
		imageList[imgInd] = strImagePath + strImageNameRoot + "0" + (imgInd+1) + ".jpg";
	} 
	else
	{
		imageList[imgInd] = strImagePath + strImageNameRoot + (imgInd+1) + ".jpg";
	}
}

//--------------Preloads nav frame pics so they roll over faster
function preLoad() 
{
	preloadImages();
}

//--------------Defines process for preload
function preloadImages()
{
	for(loop = 0; loop < imageList.length; loop++)
	{
		var image = new Image();
		
		image.src = imageList[loop];
	}
}

function change(select)
{
	//Set the image on the page to the new selected title.
	strImageAndPath = imageList[select.selectedIndex];
	strCurrentImage = strImageAndPath;
	document.bioimage.src = strImageAndPath;
	
	//Set the value to be passed to the perl script for displaying the image.
	intStartIndex = 0;
	for(i=strImageAndPath.length; i>=0; --i) 
	{
		lChar = strImageAndPath.charAt(i);
		if(lChar == "/") 
		{
			intStartIndex = i + 1;
			i = -1;
		}
	}
	//intStartIndex = strImageAndPath.indexOf('bio/') + 4;
	strImage = strImageAndPath.substring(intStartIndex,strImageAndPath.length)
	document.bioForm.imageName.value = strImage;
}

function validate() 
{
	//insertLineBreaks();
	bioForm.submit();
}

function checkSize(strAreaName) 
{
	switch (strAreaName) 
	{
		case 'overview':
			intMaxSize = 150;
			fieldObj = document.bioForm.overview;
			break;
		case 'whychose':
			intMaxSize = 150;
			fieldObj = document.bioForm.whychose;
			break;
		case 'education':
			intMaxSize = 500;
			fieldObj = document.bioForm.education;
			break;
		case 'career':
			intMaxSize = 500;
			fieldObj = document.bioForm.career;
			break;
		case 'achievement':
			intMaxSize = 500;
			fieldObj = document.bioForm.achievement;
			break;
		case 'fact1':
			intMaxSize = 150;
			fieldObj = document.bioForm.fact1;
			break;
		case 'fact2':
			intMaxSize = 150;
			fieldObj = document.bioForm.fact2;
			break;
		case 'fact3':
			intMaxSize = 150;
			fieldObj = document.bioForm.fact3;
			break;
		case 'fact4':
			intMaxSize = 150;
			fieldObj = document.bioForm.fact4;
			break;
		case 'fact5':
			intMaxSize = 150;
			fieldObj = document.bioForm.fact5;
			break;
	}
	strTextArea = fieldObj.value;
	intAreaLength = strTextArea.length;
	if (intAreaLength > intMaxSize) 
	{
		strAlertText = "The " + strAreaName + " field cannot contain more than\n" + intMaxSize + " characters. You currently have " + intAreaLength + "\ncharacters in this field. Please edit this field\ndown to the appropriate length."
		alert(strAlertText);
		fieldObj.focus();
	}
}

function setImageOnReturn() 
{

	strImageAndPath = imageList[document.bioForm.mainTitle.selectedIndex];
	strCurrentImage = strImageAndPath;
	document.bioimage.src = strImageAndPath;
	
	//Set the value to be passed to the perl script for displaying the image.
	intStartIndex = 0;
	for(i=strImageAndPath.length; i>=0; --i) 
	{
		lChar = strImageAndPath.charAt(i);
		if(lChar == "/") 
		{
			intStartIndex = i + 1;
			i = -1;
		}
	}
	strImage = strImageAndPath.substring(intStartIndex,strImageAndPath.length)
	document.bioForm.imageName.value = strImage;

}


