/********************
COMMON FUNCTIONS
********************/

/*
Hide button on submit
*/
function hidebutton (id)
{ 
	which = document.getElementById(id); 
	if (which.className=="shownbutton")
	{ 
		which.className="hidden"; 
	} 
} 

/*
Hide/show on click
*/
function expandcollapse (id)
{ 
	which = document.getElementById(id); 
	if (which.className=="hidden")
	{ 
		which.className="shown"; 
	}
	else
	{ 
		which.className="hidden"; 
	} 
} 

/*
Strip whitespace from the beginning and end of a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value))
	{
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*
	if (textBox.value.length == 0)
	{
		textBox.value = 0;		
	}
	else
	{
		textBox.value = parseInt(textBox.value);
	}
*/
}

/*
Check if a form element is empty. If so, display an alert box and focus	on the element
*/
function isEmpty(formElement, message)
	{
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '')
	{
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++)
	{
		if (listElement.options[i].value == listValue)
		{
			listElement.selectedIndex = i;
		}
	}	
}

/*
Opening picture window
*/
function picWin(URL)
{
	aWindow = window.open(URL, "composerwindow", "toolbar=no, height=850, status=no, scrollbars=yes, resize=yes, menubar=no, left=0, top=0");
}

/* 
Live preview of text area.
Created by: Jonathan Lau; Web Site: http://lauweijie7715.excell.org
*/
function livePreviewAdd()
{
  document.getElementById("preview").innerHTML = document.frmAdd.mtxContent.value
  setTimeout("livePreviewAdd()",80);
}
function livePreviewModify()
{
  document.getElementById("preview").innerHTML = document.frmModify.mtxContent.value
  setTimeout("livePreviewModify()",80);
}

/*
Picture Rollover Code
*/
function movepic(img_name,img_src)
{
	document[img_name].src=img_src;
}

/*
Drop Down Navigation
*/
function openDir(form)
{ 
	var newIndex = form.fieldname.selectedIndex; 
	if ( newIndex == 0 )
	{
		alert( "Please select a state." );
	}
	else
	{ 
		cururl = form.fieldname.options[ newIndex ].value; 
		window.location.assign( cururl ); 
	} 
} 
function openDir(form2)
{ 
	var newIndex = form2.fieldname.selectedIndex; 
	if ( newIndex == 0 )
	{
		alert( "Please select a state." );
	}
	else
	{ 
		cururl = form2.fieldname.options[ newIndex ].value; 
		window.location.assign( cururl ); 
	} 
} 

/*
JS Quicktags
Created by: Alex King | http://alexking.org/
Copyright (c) 2002-2005 Alex King
http://www.alexking.org/
Licensed under the LGPL license
http://www.gnu.org/copyleft/lesser.html
*/

/*end quick tags*/

/********************
ADMIN FUNCTIONS
********************/
function delete(id)
{
	if (confirm('Delete this?'))
	{
		window.location.href = 'process.php?action=delete&id=' + id;
	}
}
function deleteCategory(id)
{
	if (confirm('Delete this?'))
	{
		window.location.href = 'process.php?action=deleteCategory&id=' + id;
	}
}
function deleteItem(id)
{
	if (confirm('Delete this?'))
	{
		window.location.href = 'process.php?action=deleteItem&id=' + id;
	}
}
