//preload utility navigation
preload("uti_setup_on", "/i/utility/setup_on.gif");
preload("uti_setup_off", "/i/utility/setup_off.gif");
preload("uti_admin_on", "/i/utility/admin_on.gif");
preload("uti_admin_off", "/i/utility/admin_off.gif");
preload("uti_training_on", "/i/utility/training_on.gif");
preload("uti_training_off", "/i/utility/training_off.gif");
preload("uti_help_on", "/i/utility/help_on.gif");
preload("uti_help_off", "/i/utility/help_off.gif");
preload("uti_logout_on", "/i/utility/logout_on.gif");
preload("uti_logout_off", "/i/utility/logout_off.gif");

//preload tab navigation
preload("tab_home_on", "/i/tabs/home_on.gif");
preload("tab_home_off", "/i/tabs/home_off.gif");
preload("tab_alerts_on", "/i/tabs/alerts_on.gif");
preload("tab_alerts_off", "/i/tabs/alerts_off.gif");
preload("tab_tickets_on", "/i/tabs/tickets_on.gif");
preload("tab_tickets_off", "/i/tabs/tickets_off.gif");
preload("tab_csc_on", "/i/tabs/csc_on.gif");
preload("tab_csc_off", "/i/tabs/csc_off.gif");
preload("tab_inventory_on", "/i/tabs/inventory_on.gif");
preload("tab_inventory_off", "/i/tabs/inventory_off.gif");
preload("tab_reports_on", "/i/tabs/reports_on.gif");
preload("tab_reports_off", "/i/tabs/reports_off.gif");

function notyet() {
    o = window.location;
    alert('We are sorry, we are currently working on this functionality.  Please check back soon');
    window.location=o;
}

function MM_swapImgRestore() { 
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { 
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { 
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//functions for preloading and changing images 
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function changeImages() {
    if (document.images) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
        }
    }
}

function guideline(id) {
    var height = 600;
    var width = 800;
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "Guidelines";
    var link = "/csc/guideline.php?id=" + id;

    popup=window.open("","msg","scrollbars=yes,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }
}

function epi(ty, gr, start, end) {
    var height = 480;
    var width = 640;
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "EPI Graph";
    var link = "view.php?type=epi&print=1&img=" + gr + "&start=" + start + "&end=" + end + "&epi=" + ty;

    popup=window.open("","msg","scrollbars=no,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }
}

function alerts(id) {
    var height = 250;
    var width = 400;
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "View Alert";
    var link = "view.php?print=1&type=alert&objid=" + id;

    popup=window.open("","msg","scrollbars=yes,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }
}

function invoice(invoiceId,customerId) {
    var height = 600;
    var width = 800;
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "View Invoice " + invoiceId;
    var link = "view.php?print=1&type=invoice&objid=" + invoiceId + "&customerid=" + customerId;

    popup=window.open("","msg","scrollbars=yes,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }
}

function aprobe(objectid, application) {
    var height = 250;
    var width = 400;
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "View Alert";
    var link = "view.php?print=1&type=aprobe&objid=" + objectid + "&service=" + application;

    popup=window.open("","msg","scrollbars=vertical,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }
}

function probe(objectid, application) {
    var height = 250;
    var width = 400;
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "View Alert";
    var link = "view.php?print=1&type=probe&objid=" + objectid + "&service=" + application;

    popup=window.open("","msg","scrollbars=vertical,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }
}

function newWindow(link, height, width) {
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null; 
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "AppCare - NetLojix";

    popup=window.open("","msg","scrollbars=yes,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;     
        } 
        popup.location.href = link;
    }  
}

function moreInfo(service) {
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var h = 300;
    var w = 400;
    var left = (swidth/2) - (w/2);
    var top = (sheight/2) - (h/2);
    popup=window.open("","pop","scrollbars=yes,resizable=yes,height="+h+",width="+w+",left="+left+",top="+top);
    if (popup != null) {
        if (popup.opener == null) {
            popup.opener = self;
        }
        popup.location.href = "/serviceinfo.php#" + service;
    }
}

function dateWindow(obj) {
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null; 
    var height = 300;
    var width = 400;
    var left = (swidth/2) - (width/2);
    var top = (sheight/2) - (height/2);
    var over = "Choose Date";
    
    popup=window.open("","msg","status=yes,scrollbars=yes,height="+height+",width="+width+",left="+left+",top="+top); 
    if (popup != null) { 
        if (popup.opener == null) { 
            popup.opener = self;
        } 
        popup.location.href = "choosedate.php?formName=" + obj;
    }
}

function nsMoreInfo(info) {
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var h = 250;
    var w = 400;
    var left = (swidth/2) - (w/2);
    var top = (sheight/2) - (h/2);
    popup=window.open("","pop","scrollbars=yes,resizable=yes,height="+h+",width="+w+",left="+left+",top="+top);
    if (popup != null) {
        if (popup.opener == null) {
            popup.opener = self;
        }
        popup.location.href = "/nsmoreinfo.php?info=" + info;
    }
}

// poorly named...
function popup(id,w,h) {
    var swidth = screen.width;
    var sheight = screen.height;
    var popup = null;
    var left = (swidth/2) - (w/2);
    var top = (sheight/2) - (h/2);
    popup=window.open("","pop","scrollbars=yes,resizable=yes,height="+h+",width="+w+",left="+left+",top="+top);
    if (popup != null) {
        if (popup.opener == null) {
            popup.opener = self;
        }
        popup.location.href = "/popup.php?id="+id;
    }
}

function makeArray(len) {
    for (var i = 0; i < len; i++) this[i] = null;
    this.length = len;
}

// Array of month Names
var monthNames = new makeArray(12);
monthNames[0] = "Jan";
monthNames[1] = "Feb";
monthNames[2] = "Mar";
monthNames[3] = "Apr";
monthNames[4] = "May";
monthNames[5] = "Jun";
monthNames[6] = "Jul";
monthNames[7] = "Aug";
monthNames[8] = "Sep";
monthNames[9] = "Oct";
monthNames[10] = "Nov";
monthNames[11] = "Dec";

var now = new Date();
var day = now.getDay();
var month = now.getMonth();
var year = now.getYear();
var date = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var ampm = "AM";
if(hour == 0) {
    hour = 12;
}
if(hour > 11) {
    ampm = "PM";
}
if(hour > 12) {
    hour == 12;
}
if(minute < 10) {
    minute = "0" + minute;
}

if (year < 1000)
    year = year + 1900;

function showdate() {   
    document.write(monthNames[month] + " " + date + ", " + year + " " + hour + ":" + minute + " " + ampm);
}

function gotoPage(url) {
    window.opener.location=url;
    window.close();
}
