
function displayWorkOrder(id)
{
    window.open('WorkOrderView.aspx?woid='+id, 'woid'+id, 'width=1000,height=670,menubar=no,location=no,resizable=noscrollbars=yes,status=no');
}

function showHide(menuId)
{
	var objMenu = document.getElementById(menuId);
	if (objMenu)
    	objMenu.style.display = objMenu.style.display == 'none' ? 'block' : 'none';
}

function viewInventory(id)
{
    WindowObjectReference = window.open("locationinventory.aspx?loc="+id,"invPopup","toolbar=no, location=no, directories=no, resizable=yes, scrollbars=yes, status=no, menubar=no, copyhistory=no, width=518, height=375");
}

function viewLineUsage(id)
{
    WindowObjectReference = window.open("lineusage.aspx?loc="+id,"linePopup","toolbar=no, location=no, directories=no, resizable=yes, scrollbars=yes, status=no, menubar=no, copyhistory=no, width=518, height=475");
}

function searchLocation()
{
    WindowObjectReference = window.open("admin/locationsearch.aspx","searchPopup","toolbar=no, location=no, directories=no, resizable=yes, scrollbars=yes, status=no, menubar=no, copyhistory=no, width=530, height=375");
}

function searchVendor()
{
    WindowObjectReference = window.open("admin/vendorsearch.aspx", "searchPopup","toolbar=no, location=no, directories=no, resizable=yes, scrollbars=yes, status=no, menubar=no, copyhistory=no, width=530, height=325");
}

function setSelection(type, id)
{
    if (!window.opener.closed)
    {
         window.opener.selectOption(type, id);
    }
    window.close();
}


function getTimestamp()
{
    // DATE: MM/DD/YYYY
    var today = new Date()
    var month = today.getMonth()+1
    var year = today.getYear()
    var day = today.getDate()
    if(day<10) day = "0" + day
    if(month<10) month= "0" + month 
    if(year<1000) year+=1900
    
    
    // TIME:  HH:MM AM/PM
    var hour = today.getHours()
    var min = today.getMinutes()
    var AMPM = " AM"
    if (hour >= 12)
    {
        hour -= 12
        AMPM = " PM"
    }
    if (hour == 0) hour = 12

    today = month + "/" + day + "/" + year + " " + hour + ":" 
        + ((min < 10) ? "0" : "") + min + " " + AMPM;

    return today;
}


function addNote(newNoteId, oldNoteId, actionLinkId, bSaveId, bSaveCloseId)
{
    // hide/show the textboxes
    showHide(newNoteId);
    showHide(oldNoteId);

    var tbNewNote = (document.getElementById(newNoteId)).getElementsByTagName('textarea');
    var tbOldNote = (document.getElementById(oldNoteId)).getElementsByTagName('textarea');
    var spanOldNote = (document.getElementById(oldNoteId)).getElementsByTagName('span');
    var actionLink = document.getElementById(actionLinkId);
    
    if(actionLink.innerHTML == 'Add/Edit My Note')
    {
        // disable save button
        if (document.getElementById(bSaveId))
            document.getElementById(bSaveId).disabled = true;
        if (document.getElementById(bSaveCloseId))
            document.getElementById(bSaveCloseId).disabled = true;

        actionLink.style.backgroundColor = "yellow";
        actionLink.innerHTML = 'Apply';
        tbNewNote[0].focus();
    }
    else if(actionLink.innerHTML == 'Apply')
    {
        // enable save button
        if (document.getElementById(bSaveId))
            document.getElementById(bSaveId).disabled = false;
        if (document.getElementById(bSaveCloseId))
            document.getElementById(bSaveCloseId).disabled = false;
        
        actionLink.style.backgroundColor = "";
        actionLink.innerHTML = 'Add/Edit My Note';
        var newNote = tbNewNote[0].value;
        var oldNote = spanOldNote[0].innerHTML;

        if(newNote != "")        
            tbOldNote[0].value = initials + ': ' + newNote + '\r\n \r\n' + oldNote;
        else
            tbOldNote[0].value = oldNote;
    }
    else
        alert('Invalid action link text');
}
