// This is the "Database" for now

// The following statements create a JS "namespace" of State, in which define the global data
var State;
if (!State) State = {};
// end creating the namespace

State.CodeActive = false;

State.DemoUserNumbers = [0, 1, 2, 3, 4];
// DemoUser: role, name
State.DemoUserRoleInd = 0;
State.DemoUserNameInd = 1;

State.DemoUser = [
            ["Nurse", "L.Night"], 
            ["Porter", "D.Raffey"],
            ["Food Service", "B.Samuel"],
            ["Housekeeper", "R.Moore"],
            ["Physio", "J.Goodall"]
            ];
State.DemoPasswd = ["0001", "0002", "0003", "0004", "0005"];
State.DemoUserMainPage = [
                    "FullMainPage.aspx", 
                    "TaskListPage.aspx", 
                    "TaskListPage.aspx", 
                    "TaskListPage.aspx", 
                    "TaskListPage.aspx"
                    ];
State.CurrUser = 0;
State.CurrBed = 0;
State.ListType = 0;
State.TaskList = State.TranspoTasks;
State.CurrentStaffDisplay = 0;

// Just contains occupant names at the moment..
State.Beds = [
            ["Alan Guest"],
            ["Mary Rowand"]
            ];

State.Statuses = ["icon-box-empty.gif","box_greyb.gif","icon-box-check.gif"];
State.CodeStatus = ["icon-box-empty.gif","icon-box-check.gif"];
//var ServReqStates = ["icon-box-empty.gif", "icon-box-request.gif"];


			   
// name, duty status, presence_status("unknown", "busy", "away", "online", "offline"), extension
State.CardiologyStaff =   [
				["Dr. Henri Tang", "on-call", "on-call", "555-9002"],
				["Dr. James Bucanan", "on-duty", "on-duty", "1102"],
				["Dr. Patrick Renard", "on-duty", "on-duty", "1102"],
				["Dr. Henry Lei", "on-duty", "on-duty", "555-9003"],
				["Dr. Jim Duncan", "on-duty", "on-duty", "1102"],
				["Dr. Patrick Hughes", "on-duty", "on-duty", "1102"],
				["Dr. H. Tran", "on-duty", "on-duty", "555-9002"],
				["Dr. James Furlong", "on-duty", "on-duty", "1102"],
				["Dr. Pat Morris", "on-duty", "on-duty", "1102"],
				["Dr. H. Post", "off-duty", "off-duty", "555-9004"],
				["Dr. Pierre Renaud", "off-duty", "off-duty", "1102"],
				["Dr. M. Carey", "off-duty", "off-duty", "1102"],
				["Dr. Rosa Ritazza", "off-duty", "off-duty", "1102"]
                        ];
                        
State.NeurologyStaff =   [
                ["Dr. Annie Suarez", "on-call", "on-call", "1102"],
				["Dr. Brent Davidson", "on-duty", "on-duty", "1101"],
				["Dr. R. Curtis", "off-duty", "off-duty", "1102"],
				["Dr. Robert Salvatori", "off-duty", "off-duty", "1102"]
                        ];
                        
State.ObstetricsStaff =   [
				["Dr. Catherine Doe", "on-call", "on-call", "1103"],
				["RN. Gord Smith", "on-duty", "on-duty", "1104"],
				["Dr. Hanna Kalosha", "on-duty", "on-duty", "1105"]
                        ];
                        
 State.OncologyStaff =   [
 				["Dr. Stevie Hart", "on-call", "on-call", "1010"],
				["Dr. Steven Klanch", "off-duty", "off-duty", "1002"]
                       ];
                        
 State.OsteopathyStaff = [
 				["Dr. Lisa Jahnson", "on-call", "on-call", "1102"],
				["Dr. Louisa Peres", "off-duty", "off-duty", "1101"]
                       ];
 State.PsychiatryStaff = [
                ["Dr. Matthew Helm", "on-call", "on-call", "1401"],
                ["Dr. Silvia Hamilton", "off-duty", "off-duty", "1402"]
                        ];               
 State.PulmonologyStaff =   [
 				["Dr. Susanna Hemera", "on-call", "on-call", "1202"],
				["Dr. Tom Sawyer", "on-duty", "on-duty", "1203"]
                       ];
                        
 State.UrologyStaff =   [
 				["Dr. John Lauren", "on-call", "on-call", "1302"],
				["Dr. Kevin Swan", "off-duty", "off-duty", "1305"]
                       ];


// deptName, staffList
State.DepartmentStaff =	   [
            ["Cardiology", State.CardiologyStaff],
            ["Neurology", State.NeurologyStaff],
            ["Obstetrics", State.ObstetricsStaff],
            ["Oncology", State.OncologyStaff],
            ["Osteopathy", State.OsteopathyStaff],
            ["Pulmonology", State.PulmonologyStaff],
            ["Psychiatry",State.PsychiatryStaff],
            ["Urology", State.UrologyStaff]
			   ];
                        
//=======================================================================
// The defined field numbers common to all task tables
State.TaskDescriptionInd = 0; // index to field "task description"
State.TaskStateInd = 1; // index to field "state of task". ie. idle, requested, completed
State.TaskTimeReqInd = 2; // index to field "requested time". Timestamp when task was requested
State.TaskTimeDoneInd = 3; // index to field "completed time". Timestamp when task was performed/completed
State.TaskRecTypeInd = 4; // index to field "type of task". ie transpo, housekeeping etc
State.TaskBedInd = 5; // index to field "bed number" - bed task is assoicated with.
// taskName, task state - idle|requested|done, time requested, time completed, taskType - (1=Transpo,2=FoodServ,3=Housekeeping,4=physio), bed - 0|1|-1(outside location)
// time requested/done are 1, 3 or 4 digit
State.ServTasksDB = [   
                        // Transpo - bed 0
                        ["To physio 1", 0,  "", "", 1, 0], 
                        ["From physio 1", 0, "", "", 1, 0],
                        ["To radiology", 0, "", "", 1, 0],
                        ["From radiology", 0, "", "", 1, 0],
                        ["Wheelchair hoist",  0, "", "", 1, 0],
                        ["To physio 2", 0, "", "", 1, 0],
                        ["From physio 2", 0, "", "", 1, 0],
                        // Transpo - bed 1
                        ["To physio 1", 0,  "", "", 1, 1],
                        ["From physio 1", 0, "", "", 1, 1],
                        ["To radiology", 0, "", "", 1, 1],
                        ["From radiology", 0, "", "", 1, 1],
                        ["Wheelchair hoist",  0, "", "", 1, 1],
                        ["To physio 2", 0, "", "", 1, 1],
                        ["From physio 2", 0, "", "", 1, 1],              
                        // Food Services - bed 0
                        ["Breakfast", 0, "", "", 2, 0],
                        ["Lunch", 0, "", "", 2, 0],
                        ["Dinner", 0, "", "", 2, 0],
                        // Food Services - bed 1
                        ["Breakfast", 0, "", "", 2, 1],
                        ["Lunch", 0, "", "", 2, 1],
                        ["Dinner", 0, "", "", 2, 1],
                        // Housekeeping - bed 0
                        ["Spill cleanup", 0, "", "", 3, 0],
                        ["Linen change", 0, "", "", 3, 0],
                        ["Linen tray", 0, "", "", 3, 0],
                        ["Bed changeover", 0, "", "", 3, 0],
                        // Housekeeping - bed 1
                        ["Spill cleanup", 0, "", "", 3, 1],
                        ["Linen change", 0, "", "", 3, 1],
                        ["Linen tray", 0, "", "", 3, 1],
                        ["Bed changeover", 0, "", "", 3, 1],
                        // Physio - bed 1
                        ["Post surgery. eval.", 0, "", "", 4, 0],
                        ["Patient education", 0, "", "", 4, 0],
                        ["Patient training", 0, "", "", 4, 0],
                        // Physio - bed 2
                        ["Post surgery. eval.", 0, "", "", 4, 1],
                        ["Patient education", 0, "", "", 4, 1],
                        ["Patient training", 0, "", "", 4, 1]
                    ];
                  


                 
// Some dummy tasks that can be displayed for the various users
// There is 1 dummy task per user type
// fields are 0=location, 1=patient, 2=task
State.DummyTasks = [
                    ["", "", ""], // none for the nurse
                    ["Obs A - Bed 13", "Frank Rain", "Hoist to wheelchair"], // transpo
                    ["Rm. 613", "Nancy Dew", "Breakfast"], // food services
                    ["Rm. 603", "R. Lundman", "Linen tray"], // Housekeeping
                    ["Rm. 202", "D. Frances", "Breathing Instruction"] // physio
                ];
//========================================================================
// TroubleCodeName, ActiveState (on|off), activatedTime (0 = not activated), Room related (0|1)
State.TroubleCodes =  [
                        ["BLUE - Medical Emergency", 0, 1],
                        ["PINK - Pediatrics Emergency", 0, 1],
                        ["RED - Fire", 0, 1],
                        ["WHITE - Violent Patient", 0, 1],
                        ["GREEN - Evacuation", 0, 0],
                        ["ORANGE - External disaster", 0, 0],
                        ["YELLOW - Missing Patient", 0, 1],
                        ["BLACK - Bomb Threat", 0, 0],
                        ["BROWN - Decontamination", 0, 1]
                    ];



State.ShowMainPage = function() {
    // Show main page based on user type
    switch(State.CurrUser) {
        case 0: //nurse
            State.ShowPage("FullMainPage.aspx");
            break;
        case 1: // Porter
        case 2: // FoodServer
        case 3: // Houskeeping
        case 4: //physio
            //State.ShowPage("MainPage.aspx");
            State.ShowPage("TaskListPage.aspx");
            break;
     }
}

State.ShowTaskPage = function(listType) {
    State.ListType = listType;
    if(State.CurrUser == 0) { // Nurse
        State.ShowPage("FullTaskList.aspx");
    }
    else {
       State.ShowPage("TaskListPage.aspx");
    }
}

State.ShowFullTaskPage = function(bed) {
    State.CurrBed = bed;
    State.ShowPage("FullBedTaskList.aspx");
}

State.ShowStaffPage = function(staffIndex)
{
    State.CurrentStaffDisplay = staffIndex;
    State.ShowPage("HealthCareStaff.aspx");
}

var b = getBrowser();
var bOK = (b == "IE");
function getBrowser(){ // Only recognizes IE
	if((navigator.appName.indexOf("Microsoft")>-1) || (navigator.appName.indexOf("MSIE")>-1))
		return "IE";
	else
		return navigator.appName;
}

State.ShowPage = function(page_name) 
{
    if (parent.TelML)
    {
        document.getElementById("MainFrame").document.location.href = page_name;
    }
    else
    {    
        if (getBrowser() == "IE")
        {
            MainFrame.document.location.href = page_name;
        }
        else
        {
            document.getElementById("MainFrame").contentWindow.document.location.href = page_name;
        }
    }
    
}

// Resets the "database" by reloading the Main page.
State.ResetPage = function()
{
    var page_name = "Main.aspx";
    AllLampsOff(); // In case they are flashing for a trouble code.
    if (parent.TelML)
    {
        document.location.href = page_name;
    }
    else
    {    
        if (getBrowser() == "IE")
        {
            document.location.href = page_name;
        }
        else
        {
            document.location.href = page_name;
        }
    }
}

