// Common Functions

function menuLinks(linkStyle){
	for(var i = 0; i < links.length; i++){
		// If we are on the page pointed to by the link, just write the name of the link so it can't be clicked
		if(document.location.pathname.indexOf(links[i].page) != -1 || (i == 0 && document.location.pathname.indexOf('index.html') != -1))
			document.write(links[i].linkName);
		// If the link points to a different page then write the whole link so it is clickable
		else
			document.write('<a href="' + links[i].page + '">' + links[i].linkName + '</a>');
		
		// If the end of the links hasn't been reached
		if(i != links.length - 1){
			// And linkStyle is horizontal 'h' write a pipe
			if(linkStyle == 'h')
				document.write(' | ');
			// Otherwise it is vertical style 'v' so write a line break
			else if(linkStyle == 'v')
				document.write('<br />');
		}
	}
}
	
var headEdited = false;
var menuEdited = false;
var noteEdited = false;

function checkForEdits()
{
	if(headEdited || menuEdited || noteEdited)
	{
		if(confirm('Changes were made in this page. Would you like to save the changes before leaving?'))
			return true;
	}
	return false;
}

function allowEdits()
{	
	var target = null;
	var firstTarget = null;
	var checkboxes = new Array();

	if(typeof(arguments[0]) != 'number')
	{
		for( var i = 0; i < arguments.length; i++ )
		{
			target = arguments[i];
			if( i == 0 ) firstTarget = target;
			target.readOnly = false;
		}
	}
	else
	{
		for(i = 0; i < numberOfMenuItems; i++)
		{
			elem = getElement('cb' + i);
			if(elem.checked)
				checkboxes.push(i);
		}

		for(i = 0; i < checkboxes.length; i++)
		{	
			if(i == 0) firstTarget = getElement('item[' + checkboxes[i] + '][0]');
			getElement('edit[' + checkboxes[i] + '][0]').style.display = 'block';
			getElement('edit[' + checkboxes[i] + '][1]').style.display = 'block';
			getElement('edit[' + checkboxes[i] + '][2]').style.display = 'block';
			getElement('edit[' + checkboxes[i] + '][3]').style.display = 'block';
			getElement('edit[' + checkboxes[i] + '][4]').style.display = 'block';
		}
	}
	firstTarget.select();
}

function getElement(id)
{
	if(document.all)
		return document.all[id];
	if(document.getElementById)
		return document.getElementById(id);
	return false;
}

function rollOver(imgObj)
{
	if(document.images)
	{
		// Retrieve image file name
		imageFile = imgObj.src;
		// Extract image extension and save to reassemble file name later
		ext = imageFile.substr(-4);
		// Drop the extension form the file name
		imageFile = imageFile.slice(0, -4);
		// Assign proper file name depending on presence or absence of '_on' appended at 
		// the end of the currernt file name. If '_on' is present, remove it, else add it
		imageFile = (imageFile.lastIndexOf('on') == -1 || imageFile.lastIndexOf('_on') < imageFile.length - 3) ? imageFile + '_on' + ext: imageFile.slice(0, -3) + ext;
		
		imgObj.src = imageFile;
	}
}

function save_edits(menu_part)
{
		menu_part.submit();
	switch(menu_part)
	{
		case 'header': break;
		case 'menu': break;
		case 'note': break;
	}
}

var images = Array();
var picInfo = '';
var picName = '';
var picExt = '';
var header = '';
function show_thumbs()
{
	for(var i = 0; i < gallery.length; i++)
	{
		picInfo = gallery[i][0].split('.');
		header = gallery[i][1];
		picName = picInfo[0];
		picName += '_';
		picExt = '.' + picInfo[1];
		
		images[i] = Array(new Image(1024, 768), new Image(800, 600));
		images[i][0].src = picName + imgType.larger + picExt;
		images[i][1].src = picName + imgType.smaller + picExt;
		
		document.write('<div class="thumb">');
		document.write('<img src="images/ac/thumbs/' + picName + imgType.thumb + picExt + '" width="140" height="105" border="0" />');
		document.write('<br /><a href="javascript:void(window.open(\'picpage.html?id=' + i + '&amp;size=' + imgType.smaller + '\'));">800 x 600</a>');
		document.write('<br /><a href="javascript:void(window.open(\'picpage.html?id=' + i + '&amp;size=' + imgType.larger + '\'));">1024 x 768</a>');
		document.write('</div>');
	}
}
