//Provided by sir delvinj
function log(str)
{
	var out = document.getElementById("out");
	if(out == null)
	{
		out = document.createElement("textarea");
		out.wrap = "off";
		out.cols = 10;
		out.rows = 100;
		out.id = "out";
		out.style.cssText =
			"background:pink;padding:3px;font-size:80%;font-family: tahoma,verdana,sans-serif;position:absolute;bottom:0px;right:0px;z-index:100000;width:420px;height:300px;";
		document.body.appendChild(out);
	}
	out.value += str;
	out.scrollTop = out.scrollHeight;
}

//show teh login box for teh goodness login
function showLoginBox() {
	window.loginBox=Dialog.confirm($('login').innerHTML,
								{windowParameters: {className:"alphacube", width:400},
									okLabel: "login", cancelLabel: "cancel",
									ok:function(win){
										$('login_error_msg').innerHTML='Login or password inccorect';
										$('login_error_msg').show();
										Dialog.win.updateHeight();
										new Effect.Shake('modal_dialog');
										return false;
									}
								}
	);
}

//show the admin menu
function showAdminMenu() {
	if (contentWin != null) {
	Dialog.alert("Close the window 'Test' before opening it again!", {windowParameters:{ width:200, height:130}}); 
	}
	else {
		contentWin = new Window('content_win', {resizable: false, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10})
		contentWin.setContent('test_content', true, true)
		contentWin.toFront();
		contentWin.setDestroyOnClose();
		contentWin.show();	

		// Set up a windows observer, check ou debug window to get messages
		myObserver = {
			onDestroy: function(eventName, win) {
			if (win == contentWin) {
				$('container').appendChild($('test_content'));
				contentWin = null;
				Windows.removeObserver(this);
			}
			debug(eventName + " on " + win.getId())
			}
		}
		Windows.addObserver(myObserver);
	}	
}

function convert(theDate)
{
	//first search to see if any / exist in it already, if they don't, 
	//then we need to do this stuff..
	var winnar = theDate.indexOf('/');  
	if(winnar == -1) {
		if(theDate.length == 8)
		{
			var month = theDate.substring(0, 2);
			var day = theDate.substring(2, 4);
			var year = theDate.substring(4, 8);
			
			var newDate = month + '/' + day + '/' + year;
			
			return newDate;
		}
		else
		{ 
			return theDate;
		}
	} else {
		return theDate;
	}
}

//cofirm button presses
function confirmSubmit()
{
	var agree=confirm("Are you sure you wish to continue?");
	if (agree)
		return true ;
	else
		return false ;
}

function confirmSubmitExpenseCheck()
{ 
	var agree=false;
    if($('tehExpenseAmount').value.length > 0) {
		agree=confirm("You have left text in the ExpenseAmount box, indicating you may have forgotten to add this expense.  Are you sure you would like to continue?");
	} else {
		agree=true;
	}
    if (agree)
		return true;
	else
		return false;
}