// JavaScript Document
function refreshGrid(gridname){
	ColdFusion.Grid.refresh(gridname);
}

function refreshTree(treeName){
	ColdFusion.Tree.refresh(treeName);
}

function core_showWindow(windowName,title,page,wwidth,wheight,wmodal,closable){
	ColdFusion.Window.create(windowName,title,page,{height:wheight,width:wwidth,modal:wmodal,initshow:true,resizable:false,destroyOnClose:true,closable:closable,refreshonshow:true,x:50,y:50});

}

function signIn(redirect,rand1){
	var randomnumber=Math.floor(Math.random()*100)
	ColdFusion.Window.create('SignUp','Login','/signIn.cfm?redirect=' + redirect + '&rand=' + randomnumber ,{height:200,width:300,modal:true,initshow:true,resizable:false,destroyOnClose:true,closable:false,center:true});
}

function signOut(){
	window.location = '/signOut.cfm';
}
function handleLogin() {
	ColdFusion.Ajax.submitForm('loginForm','/processlogin.cfm',handleResponse);
}
function handleResponse(s) {
	var trimmed = s.replace(/^\s+|\s+$/g, '') ;
	if(trimmed != "false") {
		//first hide the window
		closeWindow('SignUp');
		window.location = s;

	} else {
		alert('Invalid Username or Password, Please try again');
	}
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function loadPage(pagename,region){
	ColdFusion.navigate(pagename,region);
}

function closeWindow(windowName) {
	windowName = windowName.replace(/^\s+|\s+$/g,"");	
    ColdFusion.Window.destroy(windowName,true);
}

function showStatus(statusObj) {
	//alert(statusObj.STATUS + ' ' + statusObj.FILENAME);
}

function showComplete(ID,pType) {
	alert('done!');
}
function showError(errorObj) {
	alert(errorObj.STATUS + ' ' + errorObj.FILENAME + ' ' + errorObj.MESSAGE);
}

function navError(){
	alert('Navigation Error');
}

function loginMyAccount(){
	document.forms["myAccountForm"].submit();
}


