﻿//Selects the text in the specified control
function selectControlText(controlID)
{
    var control = document.GetElementByID(controlID);
   if(control !== null)
   {
        control.select();
   }
    
   return true; 
}

//Disables the specified control
function DisableControl(controlID)
{
    if(document.getElementById(controlID) !== null)
    {
        document.getElementById(controlID).disabled = true;
    }
}

//Enables the specified control
function EnableControl(controlID)
{
    if(document.getElementById(controlID) !== null)
    {
        document.getElementById(controlID).disabled = false;
    }
}

//Opens a new window with the specified URL
function OpenWindow(url)
{
    popup_window=window.open(url);
}

//Prints the current window
function PrintMe()
{
    this.print();
}

//Closes the current window
function CloseMe()
{
    self.close();
}

//Changes the src property of the specified control to the specified image
function ChangeImageSrc(controlID, imagePath) 
{
    var control = document.getElementById(controlID);
    if (control && control.src) 
    {
        control.src = imagePath;
    }
}

var lastSortField
var ascending;

///AJAX function that AJAX enabled pages can use to change the sort order of a table
///This function automatically alternates between ascending and descending sorting as it is called
function TableSortPostback(sortField) {
    if (__doPostBack && sortField && typeof sortField !== 'undefined' && sortField !== '') {
        if (sortField === lastSortField) {
            ascending = !ascending;
        }
        else {
            ascending = false;
        }

        lastSortField = sortField;
        
        if (ascending) {
            sortField = sortField + " DESC";
        }
        else {
            sortField = sortField + " ASC";
        }
        
        ///this requires that the processing animation be inclued on the page
        ///you need some element to be the source, if you can think of a better way, go for it
        __doPostBack(document.getElementById('processinganimation').id, sortField);
    }
    
}