﻿// Wait until the DOM is ready
$(document).ready(function() {

    //Fade out message notifications
    $("#tblmsg").fadeOut(6500)
    
    //all hover and click logic for buttons
    $(".fg-button:not(.ui-state-disabled)")
	.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
	.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
	.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
		}
	
	});
	
	//Init the request details tabs (USER)
	$("#usrRequestDetails").tabs();
	$("#prefTabs").tabs();
		
	$("#staffDashboardLeft").tabs();	
	$('#staffDashboardRight').tabs({
    select: function(event, ui) {
        var url = $.data(ui.tab, 'load.tabs');
        if( url ) {
            location.href = url;
            return false;
        }
        return true;
    }
});  
            
}); //End DOM Ready

// This function calls the Web service method and 
// passes the event callback function.  
function CheckUsername(a)
{
   OPSD.wsChecker.CheckUsername(a, UsernameSucceededCallback);
    
}


// This function calls the Web service method and 
// passes the event callback function.  
function CheckEmail(a)
{
    OPSD.wsChecker.CheckEmail(a, EmailSucceededCallback);
    
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function UsernameSucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("UserAvailability");
    RsltElem.innerHTML = result;
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function EmailSucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("EmailAvailability");
    RsltElem.innerHTML = result;
}

// This is the callback function invoked if the web service
// succeeded
function updateCRKey(value)
{
    var behavior = $find('lstCanned_DynamicPopulateExtender');
        if (behavior) {
            behavior.populate(value);
        }
}

// This is the callback function invoked if the web service
// succeeded
function updateKBKey(value)
{
    var behavior = $find('lstKBLink_DynamicPopulateExtender');
        if (behavior) {
            behavior.populate(value);
        }
}

//This is the calendar callback
function afterRender(data) {
    if (data) {
        if (data.message) {
            showMessage(data.message + " (id " + data.id + ")");
        }
        else {
            showMessage(data);
        }
    }
}

// calendar message helpers

var timeout = null;

function showMessage(text) {
    var messageDiv = document.getElementById("message");
    messageDiv.innerHTML = text;
    messageDiv.style.display = '';
    
    if (timeout) {
        window.clearTimeout(timeout);
    }
    timeout = window.setTimeout('clearMessage()', 4000);
}

function clearMessage() {
    var messageDiv = document.getElementById("message");
    messageDiv.innerHTML = '';
    messageDiv.style.display = 'none';
}

// resource manager helpers

// function to filter the resource manager based on the selected resource
function resourcefilter(property, value) {
     if (!dps1.clientState.filter) {
         dps1.clientState.filter = {};
     }
     if (dps1.clientState.filter[property] != value) { // only refresh when the value has changed
         dps1.clientState.filter[property] = value;
         dps1.commandCallBack('filter');
     }
}







