﻿function swfNav(sectionTgt){
	var tempDate = new Date();
	document.getElementById("pageContent").src = "cfm/" + sectionTgt + "/index.cfm?cacheKiller=" + tempDate.getTime();
}
function loadPageContent(action){
	var tempDate = new Date();
	var url;
	switch(action){
		case "switch":
			url = "cfm/login/index.cfm?fuseaction=SwitchRest";
			break;
		case "users":
			url = "cfm/settings/index.cfm?thisaction=users";
			break;
		case "logout":
			url = "cfm/general/index.cfm?fuseaction=logout";
			break;
		}
	document.getElementById("pageContent").src = url + "&cacheKiller=" + tempDate.getTime();
}
var style;

function reStyle(){
	location.href = location.href;
}
//login test scripts
var xmlHttp;
var _restLocationUID = "";
function getUnusedMins(restLocationUID){
	//alert(restLocationUID);
	_restLocationUID = restLocationUID;
	xmlHttp = intiateAjaxHttp();
	xmlHttp.onreadystatechange = keepSessionAlive;
	xmlHttp.open("GET","/restconsole/cfm/general/pollsession.cfm?restLocationUID="+_restLocationUID+"&purge="+Math.random(),true);
  	xmlHttp.send(null);
}
var trTimer;
function keepSessionAlive(){
	if(xmlHttp.readyState==4){
		try{
			//alert(xmlHttp.responseText);
			var xmlDoc=xmlHttp.responseXML;
			var unusedMins = parseInt(xmlDoc.getElementsByTagName("RESPONSE")[0].getAttribute("UNUSEDMINS"));
			var reload = parseInt(xmlDoc.getElementsByTagName("RESPONSE")[0].getAttribute("RELOAD"));
			if(unusedMins >= 300){//if the app is unused for > 5 hours then logout
				logout();
			}
			else if(reload != 0 && _restLocationUID != ""){
				//alert(_restLocationUID);
				_reloadConsole();
			}
			else{
				//try again every 5 minutes. This will renew the sesson which is 15 mins server side
				trTimer = setTimeout("getUnusedMins('"+_restLocationUID+"')",(60*1000)*	5);
			}
		}
		catch(e){
			//alert(xmlHttp.responseText);
		}
    }
}
function clickFlag(){
	hideContent();
	showFlags();
}
function hideContent(){
	document.getElementById("pageContent").style.display = "none";
}
function showFlags(){
	document.getElementById("flags").style.display = "block";
}
function srchMouseDown(){
	var txtGlobalSearch = document.getElementById("txtGlobalSearch");
	showFloatingHelp("helpGlobalSearch");
	txtGlobalSearch.style.color="#aaa";
}
function detect(event_keyCode){
	var txtGlobalSearch = document.getElementById("txtGlobalSearch");
	if(event_keyCode==13){
		var searchStr = new String(txtGlobalSearch.value);
		if(searchStr.length >= 3){
			var url = "/restconsole/cfm/general/index.cfm?fuseaction=search&str="+escape(searchStr).replace(new RegExp( "\\+", "g" ),"%2B");
			//alert(url);
			pageContent.location.href = url;
			txtGlobalSearch.style.color="#aa0";
			setTimeout("document.getElementById('txtGlobalSearch').value='';",60000);
		}
		else{
			showFloatingHelp("helpTooShort");
		}
	}
	else{
		hideAllFloatingHelp();
	}
}