// Version
var VERSION="20090629.182357";
// Commonly referenced elements
var elemDateTime;
var elemLegend;
var elemTimer;
var elemDebug;
var elemLoading;
var imgLoading;
// Window
var elemOffset=10;
var bodyHeight;
var topHeight;
var bottomHeight;
var windowWidth;
var windowHeight;
var lastScroll;
var whileScroll;
var procScroll=0;
// Printing
var screenYears=3;
var printYears=5;
// Current cursor stuff
var defCursor='default';
var emHeight=0;
// Timers
var clockTimer;
var scrollTimer;
var startTime;
var loadTimer;
var floatTimer;
var longTime=30;
var longAsk=1;
// Timezone
var curTZ='UTC';
var offsetTZ=0;
getTZ();
// Browser info
var isIE=document.all?true:false;
var isSafari=(navigator.userAgent.indexOf('Safari') > -1);
var isNetscape=(navigator.userAgent.indexOf('Netscape') > -1);
var isFirefox=(navigator.userAgent.indexOf('Firefox') > -1);
var isMac=(navigator.userAgent.indexOf('Mac') > -1);
// Floating window
var floaterVisible=0;
var floaterLoading=0;
var doHideFloater=0;
////////////////////////////////////////////////////////////////////////////////
// Body functions
function bodyLoaded() {
// Initialize body stuff
elemDateTime=document.getElementById('menu_datetime');
elemLegend=document.getElementById('menu_legend');
elemTimer=document.getElementById('menu_timer');
elemDebug=document.getElementById('menu_debug');
elemLoading=document.getElementById('menu_loading');
imgLoading=new Image();
imgLoading.src='inc/loading.gif';
// Figure out how big 1em of text is
var sizediv=document.createElement("div");
sizediv.id = 'sizediv';
sizediv.style.top = '-100px';
sizediv.style.position = 'fixed';
sizediv.innerHTML = 'M';
document.body.appendChild(sizediv);
emHeight=getHeight(sizediv);
document.body.removeChild(sizediv);
// Try to fix scrolling issues
topHeight=Math.ceil(emHeight*5);
bottomHeight=Math.ceil(emHeight*6.5);
bodyHeight=0;
if (self.innerHeight)
bodyHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientWidth)
bodyHeight = document.documentElement.clientHeight;
else if (document.body)
bodyHeight = document.body.clientHeight;
bodyHeight=bodyHeight - topHeight - bottomHeight;
lastScroll=0;
whileScroll=lastScroll;
// Initialize window sizes
if (window.innerWidth) {
windowWidth = window.innerWidth;
windowHeight = window.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
}
else if (document.body) {
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// Discourage use of the Back button
window.onbeforeunload = function () {
return "The Satellite Inventory uses AJAX to transfer data and does not keep a browser history. Navigating away from this page will cause you to lose your search state."
}
// Initialize others
clearTimer();
drawClock();
initAll();
showSearch();
getAllCoverages();
getAllSchedules();
getAllKeyedComments();
// # This is done with the
tag now
// getAllBandInfo();
}
// Placeholder for drag stuff that was moved out of the way
var isDrag=false;
function isDraggable() { return(isDrag); }
function fixScroll() {
if (!procScroll) return;
clearTimeout(scrollTimer);
scrollTimer = setTimeout('doFixScroll()',100);
}
function doFixScroll() {
var thisScroll=getScrollTop();
var diffScroll=lastScroll - thisScroll;
lastScroll=thisScroll;
// Scrolled up
if (diffScroll>0) {
if (diffScroll > bodyHeight) {
toScroll=(thisScroll+(diffScroll-bodyHeight))*-1;
procScroll=0;
window.scroll(0,toScroll);
}
}
// Scrolled down
else if (diffScroll<0) {
diffScroll=diffScroll * -1;
if (diffScroll > bodyHeight) {
toScroll=(thisScroll-(diffScroll-bodyHeight))*-1;
procScroll=0;
window.scroll(0,toScroll);
}
}
procScroll=0;
}
function initAll() {
if (!isDraggable()) hideAll();
initSearch();
initPrefs();
initOrder();
initHelp();
if (!isDraggable()) showPrefs();
}
function hideAll() {
hideSearch();
hidePrefs();
hideOrder();
hideHelp();
}
function toggleAdmin() {
if (isAdmin()) {
adminOff();
}
else {
testFile('../admin/ok.html','setAdmin();');
}
}
function setAdmin(xmlhttpstatus) {
if (xmlhttpstatus==200) {
adminOn();
}
else {
adminOff();
}
}
function drawClock() {
var now = new Date();
if (curTZ=='UTC') {
var UTC = now.toUTCString();
UTC = UTC.replace(' GMT','');
UTC = UTC.replace(' UTC','');
now = new Date(UTC);
}
var humanDate = now.format('d')+' '+now.format('M')+' '+now.format('Y');
humanDate+='.'+pad_zeroes(3,now.format('z')*1+1);
// var humanTime = now.format('H')+':'+now.format('i')+':'+now.format('s');
var humanTime = now.format('H')+':'+now.format('i');
var theDateTime = humanDate + ' @ ' + humanTime;
elemDateTime.innerHTML=theDateTime+' ('+curTZ+')';
// clockTimer = setTimeout('drawClock()',1000);
clockTimer = setTimeout('drawClock()',5000);
}
function pad_zeroes (digits, n) { // n is a string or number
if(n.constructor == Number) n = n.toString();
while(n.length < digits) n = '0' + n;
return n;
}
function getTZ() {
if (getCookie('showtz')==2) {
curTZ='Local';
var tmpDate = new Date();
offsetTZ = tmpDate.format('Z');
}
else {
curTZ='UTC';
offsetTZ=0;
}
}
function doLoading() {
defCursor='progress';
setCursor('progress');
elemLoading.innerHTML='Loading...';
startTimer();
}
function doneLoading() {
defCursor='default';
unsetCursor();
elemLoading.innerHTML='';
stopTimer();
}
function startTimer() {
// if (loadTimer) { return(false); }
var d = new Date();
startTime=d.getTime();
clearTimeout(loadTimer);
elemTimer.innerHTML='0.0 sec';
loadTimer=setTimeout('countTimer()',100);
longAsk=1;
}
function stopTimer() {
clearTimeout(loadTimer);
elemTimer.innerHTML='Done: '+elemTimer.innerHTML;
isSearching=0;
}
function countTimer() {
var d = new Date();
var thisTime=d.getTime();
theTime=(Math.round((thisTime-startTime)/100))/10;
checkTimer(theTime);
if (theTime>=1) { elemTimer.innerHTML=theTime.toFixed(1)+' sec'; }
else { elemTimer.innerHTML=theTime+' sec'; }
if (!runningAJAX) stopTimer();
else loadTimer=setTimeout('countTimer()',100);
}
function checkTimer(theTime) {
if (theTime<=longTime) return;
if (longAsk && !isSearching && runningAJAX) {
var msg='Page update is taking longer than expected.\nStop process?';
if (confirm(msg)) {
runningAJAX=0;
doneLoading();
}
else {
longAsk=0;
}
}
}
function clearTimer() {
elemTimer.innerHTML='';
}
function doDebug(string) {
elemDebug.innerHTML=string;
}
////////////////////////////////////////////////////////////////////////////////
// Manipulate elements
function hideElem(id) {
document.getElementById(id).style.visibility = 'hidden';
document.getElementById(id).style.display = 'none';
}
function showElem(id) {
document.getElementById(id).style.visibility = 'inherit';
document.getElementById(id).style.display = 'block';
}
function toggleElem(id) {
if (document.getElementById(id).style.display=='block' ||
document.getElementById(id).style.display=='') {
hideElem(id);
}
else { showElem(id); }
}
function getScrollTop(theElem) {
if (theElem==null) theElem=document.body;
if (theElem.id.match(/^menu_/) ||
theElem.id.match(/^search_/) ||
theElem.id.match(/^prefs_/) ||
theElem.id.match(/^help_/) ||
theElem.id.match(/^td_month/) ||
theElem.id.match(/^IMG_manual/)
) {
if (document.body.offsetTop)
return getTop(theElem)-document.body.offsetTop;
else
return getTop(theElem);
}
var fromTop = document.body.scrollTop;
if (!fromTop) {
var scroller=document.body.parentNode;
if (scroller) fromTop=scroller.scrollTop;
}
return(getTop(theElem) - fromTop);
}
function getScrollLeft(theElem) {
if (!theElem.id.match(/^td_month/)) return(getLeft(theElem));
var scrollElem=document.getElementById('div_calendar');
return(getLeft(theElem)-scrollElem.scrollLeft);
}
function getHeight(theElem) {
if (theElem==null) return;
if (typeof(theElem)=='string') theElem=document.getElementById(theElem);
var theVal=0;
if (theElem.offsetHeight)
theVal=theElem.offsetHeight;
else if (document.defaultView && document.defaultView.getComputedStyle)
if (document.defaultView.getComputedStyle(theElem,'')!=null)
theVal=document.defaultView.getComputedStyle(theElem,'').height;
return(stringToInt(theVal));
}
function getWidth(theElem) {
if (theElem==null) return;
if (typeof(theElem)=='string') theElem=document.getElementById(theElem);
var theVal=0;
if (theElem.offsetWidth)
theVal=theElem.offsetWidth;
else if (document.defaultView && document.defaultView.getComputedStyle)
if (document.defaultView.getComputedStyle(theElem,'')!=null)
theVal=document.defaultView.getComputedStyle(theElem,'').width;
return(stringToInt(theVal));
}
function getTop(theElem) {
if (theElem==null) return;
if (typeof(theElem)=='string') theElem=document.getElementById(theElem);
var theVal=0;
while (theElem!=null) {
if (isSafari && theElem.id=='body') break;
theVal+=theElem.offsetTop;
theElem=theElem.offsetParent;
}
return(theVal);
}
function getLeft(theElem) {
if (theElem==null) return;
if (typeof(theElem)=='string') theElem=document.getElementById(theElem);
var theVal=0;
while (theElem!=null) {
if (isSafari && theElem.id=='body') break;
theVal+=theElem.offsetLeft;
theElem=theElem.offsetParent;
}
return(theVal);
}
function getStyle(theElem, property) {
if (theElem==null) return;
if (typeof(theElem)=='string') theElem=document.getElementById(theElem);
var theVal='';
if (theElem.currentStyle)
theVal=theElem.currentStyle(property);
else if (window.getComputedStyle)
theVal=document.defaultView.getComputedStyle(theElem,null).getPropertyValue(property);
return theVal;
}
function stringToInt(string) {
var stringInt=parseInt(string);
if (isNaN(stringInt)) { stringInt=0; }
return(stringInt);
}
function placeElem(theId) {
var theElem=document.getElementById(theId);
if (isDraggable()) {
theElem.style.left=elemOffset+'px';
theElem.style.top=(getHeight('menu_top')+elemOffset)+'px';
theElem.style.position='absolute';
elemOffset+=10;
}
else {
var theLeft=getLeft(document.getElementById('menu_'+theId))-1;
// var theWidth=getWidth(theElem);
// if (theWidth<=0)
// theWidth=900;
// theElem.style.width=theWidth-theLeft+'px';
theElem.style.left=theLeft+'px';
theElem.style.top='1.5em';
theElem.style.position='fixed';
}
}
function showFloater(theElem) {
if (theElem==null) return;
if (typeof(theElem)=='string') theElem=document.getElementById(theElem);
floaterLoading=1;
var html ='';
document.getElementById('floater_body').innerHTML = html;
var top=getScrollTop(theElem);
var left=getScrollLeft(theElem);
var width=getWidth(theElem);
var height=getHeight(theElem);
var anchorRight=0;
// Place the floater on screen
var floater=document.getElementById('floater');
var fwidth=getWidth(floater);
if (left + fwidth > windowWidth) anchorRight=1;
if (anchorRight) left = left - fwidth + width;
floater.style.top = top + height + 'px';
floater.style.left = left + 'px';
// Adjust the focus box as necessary
var focus=document.getElementById('floater_focus');
focus.style.top = -1*height - 1 + 'px';
focus.style.width = width - 1 + 'px';
focus.style.height = height - 1 + 'px';
if (anchorRight) focus.style.left = fwidth - width + 'px';
showElem('floater');
floaterVisible=1;
}
function hideFloater() {
if (!floaterVisible) return;
doHideFloater++;
clearTimeout(floatTimer);
if (floaterLoading)
floatTimer=setTimeout('hideFloaterNow()',10000);
else
floatTimer=setTimeout('hideFloaterNow()',1000);
}
function hideFloaterNow() {
if (doHideFloater<=0) return;
doHideFloater=1;
hideElem('floater');
floaterVisible=0;
}
////////////////////////////////////////////////////////////////////////////////
// Cookies
function setCookie(name,value) {
var expDate=new Date('Jan 1, 2012 12:34:56');
var theVal=name+'='+value+';expires='+expDate.toGMTString();
document.cookie=theVal;
return(false);
}
function getCookie(name) {
var theCookie=document.cookie;
var theCookies=theCookie.split(';');
var retVal='';
for (i=0; i