function StartTimer(hour,min,sec, incidentId){
    document.getElementById('timerDisplay').innerHTML = "H: "+hour+" M: "+min+" S: "+sec+" On Incident #"+incidentId;
    sec++;
    if(sec==60){
        sec = 0;
        min++;
    }

    if(min==60){
        min = 0;
        hour++;
    }
    go = setTimeout("StartTimer("+hour+","+min+","+sec+","+incidentId+")",1000);
}

function ContinueTimer(hour,min,sec,incidentId) {
    StartTimer(hour,min,sec,incidentId);
}

function StopTimer(switchTimer){
    clearTimeout(go);
    xajax_StopTimer(switchTimer);
}

function SwitchTimer(){
    clearTimeout(go);
    xajax_SwitchTimer();
}

function CloseNoteStopTimer(){
    xajax_CloseNoteStopTimer();
}

function CloseDialogResetTimer() {
    $(parent.document).find('#switchTimer').trigger('click');
    $(parent.document).find('#closedailog').trigger('click');
}

function UpdateTimerLinks(){
    var ids = new Array();
    var sizes = new Array();
    $('.timerButton:visible').each(function(i){
        if($(this).parent().attr('id') != 'timerLinkImage'){
            ids.push($(this).attr('id'));
            sizes.push($('img',this).width());
        }
    });
    xajax_UpdateTimerLinks(ids, sizes);
}

/*
+------------------------------+
|  POPUP DIALOG INTERACTIVITY  |
+------------------------------+
*/
function PopupSpecial(popupName,incidentId,refreshPage,basePath,switchTimer){
    // destroy any settings previously assigned to the dialog div
    $("#popupIncidentSection").dialog('destroy');
    // assign new properties to the dialog div
    $("#popupIncidentSection").SetIncidentDialogProperties(popupName,refreshPage);
    switch(popupName){
        case 'submitUser' :
        case 'organization' :
        case 'product' :
            var pageValue = "&popupName="+popupName;
            document.getElementById('popupSpecial').src = basePath+"/SPRT_server/change_incident_value.php?incidentId="+incidentId+pageValue;
            break;
        case 'addEmail' :
            var pageValue = "&action=email";
            document.getElementById('popupSpecial').src = basePath+"/incident_note.php?incidentId="+incidentId+pageValue;
            break;
        case 'addPrivate' :
            var pageValue = "&action=private";
            document.getElementById('popupSpecial').src = basePath+"/incident_note.php?incidentId="+incidentId+pageValue;
            break;
        case 'addNote' :
            var closeIncident = '&closeIncident=0';
            if(switchTimer=='closeIncident') {
                closeIncident = "&closeIncident=1"
            }
            var pageValue = "&action=notTimer";
            document.getElementById('popupSpecial').src = basePath+"/incident_note.php?incidentId="+incidentId+pageValue+closeIncident;
            break;
        case 'addOrgNote' :
            var pageValue = "&action=orgNote";
            document.getElementById('popupSpecial').src = basePath+"/incident_note.php?incidentId="+incidentId+pageValue;
            break;
        case 'updateNote' :
            var pageValue = "&action=private";
            var noteId = "&noteId="+refreshPage;
            document.getElementById('popupSpecial').src = basePath+"/incident_note.php?incidentId="+incidentId+pageValue+noteId;
            break;
        case 'timer' :
            var pageValue = "&action=timer";
            var startTime = "&startTime="+refreshPage;
            var switchTimer = "&switch="+switchTimer;
            document.getElementById('popupSpecial').src = basePath+"/incident_note.php?incidentId="+incidentId+pageValue+startTime+switchTimer;
            break;
        case 'incidentResolution':
            document.getElementById('popupSpecial').src = basePath+"/incident_resolution.php?incidentId="+incidentId;
            break;
        case 'printIncident':
            var fromOrg = "&fromOrg=0";
            document.getElementById('popupSpecial').src = basePath+"/print_incident_chooser.php?incidentId="+incidentId+fromOrg;
            break;
        case 'printIncidentOrg':
            var fromOrg = "&fromOrg=1";
            document.getElementById('popupSpecial').src = basePath+"/print_incident_chooser.php?incidentId="+incidentId+fromOrg;
            break;
        default:
            document.getElementById('popupSpecial').src = basePath+"/default.php";
    }
    $('#popupSpecial').removeClass('ui-helper-hidden');
    $("#popupIncidentSection").parent().addClass('no-exit'); //don't show dialog close 'x' button
    $("#popupIncidentSection").dialog('open');
}

/*
+------------------------------+
|  JAVASCRIPT SHOW/HIDE BLOCK  |
+------------------------------+
*/

function toggleViewEdit(id){
    view = document.getElementById(id);
    input = document.getElementById(id + '_visible');
    button = document.getElementById(id + '_button');
    if(view.style.display == 'none'){
        if(button) {
            button.innerHTML = "-";
        }
        view.style.display = 'block';
        input.value = 'true';
    }else{
        if(button) {
            button.innerHTML = "+";
        }
        view.style.display = 'none';
        input.value = 'false';
    }
    $('#'+id).setInputHeight();
}

