﻿/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmCancel                                                                                   ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the cancel of changes.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmCancel()
{
    if (confirm("Are you sure you want to cancel all changes made on this page?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmCancelBox                                                                                ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the cancel of changes in a sub box on a page
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmCancelBox()
{
    if (confirm("Are you sure you want to cancel all changes?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmCancelAppointment                                                                        ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the cancel of appointment.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmCancelAppointment() {
    if (confirm("Are you sure you want to cancel this appointment?") == true) {
        return true;
    }
    else {
        return false;
    }
}



/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmExitAppointment                                                                          ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the exit from the appointment edit section
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmExitAppointment()
{
    if (confirm("Are you sure you want to exit and lose all changes to this appointment?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmDelete                                                                                   ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the delete of an item.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmDelete()
{
    if (confirm("Are you sure you want to delete this item?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmRemove                                                                                   ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the removal of an item.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmRemove() 
{
    if (confirm("Are you sure you want to remove this item?") == true) 
    {
        return true;
    }
    else 
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmDeletes                                                                                  ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the deletes of an item.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmDeletes()
{
    if (confirm("Are you sure you want to delete these items?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmDeleteFile                                                                               ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the delete of a file.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmDeleteFile(strFilename)
{
    if (confirm("This will delete the file from disk. Are you sure you want to delete the file [" + strFilename + "]?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmRemoveImage                                                                              ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the removal of an image.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmRemoveImage()
{
    if (confirm("Are you sure you want to remove this image?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmReset                                                                                    ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the resetting of an item.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmReset()
{
    if (confirm("Are you sure you want to reset this item to its default value?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmUserReset                                                                                ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms the resetting of a user.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmUserReset()
{
    if (confirm("Are you sure you want to log this user out and reset their session?") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: checkTextLength                                                                                 ***/
/***                                                                                                        ***/
/// <summary>
/// If the length of the text in the control reaches 'length' it moves focus to the given control.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function checkTextLength(txt1, txt2, maxLength)
{
    /**********************************************************************************************************/
    /***  Get the length of the first text box                                                              ***/
    /**********************************************************************************************************/

    var count = document.getElementById(txt1).value.length;

    /**********************************************************************************************************/
    /***  If it's over 'maxLength' move focus to the next text box                                          ***/
    /**********************************************************************************************************/
    
    if (count >= maxLength)
    {
        document.getElementById(txt2).focus()
    }
}

/**************************************************************************************************************/
/***  Variables used for sliding                                                                            ***/
/**************************************************************************************************************/

var timerlen = 5;
var slideAniLen = 500;
var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();
var m_bChildrenAsParent = false;
var ctrlChildrenToHide = new Array();

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: toggleSlide                                                                                     ***/
/***                                                                                                        ***/
/// <summary>
/// Expands/collapses a control in a slidey manner.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function toggleSlide(divid)
{
    toggleSlide(divid, null, null);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: toggleSlide                                                                                     ***/
/***                                                                                                        ***/
/// <summary>
/// Expands/collapses a control in a slidey manner.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function toggleSlide(divid, bChildrenAsParent, ctrlChild1)
{
    if (bChildrenAsParent != null)
    {
        m_bChildrenAsParent = bChildrenAsParent;
    }
    
    if (ctrlChild1 != null)
    {
        ctrlChildrenToHide[divid] = ctrlChild1;
    }
    
    /**********************************************************************************************************/
    /***  If the control is hidden, slide down (expand), otherwise slide up (collapse)                      ***/
    /**********************************************************************************************************/
    
    if(document.getElementById(divid).style.display == "none")
    {
        slidedown(divid);
    }
    else
    {
        slideup(divid);
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: slidedown                                                                                       ***/
/***                                                                                                        ***/
/// <summary>
/// Starts the control sliding down (expanding).
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function slidedown (objName)
{
    /**********************************************************************************************************/
    /***  If the control is already moving, ignore                                                          ***/
    /**********************************************************************************************************/
    
    if (moving[objName] == true)
    {
        return;
    }

    /**********************************************************************************************************/
    /***  If the control is not hidden, it's already expanded                                               ***/
    /**********************************************************************************************************/
    
    if  (document.getElementById(objName).style.display != "none")
    {
        return;
    }

    /**********************************************************************************************************/
    /***  Set the variables                                                                                 ***/
    /**********************************************************************************************************/
    
    moving[objName] = true;
    dir[objName] = "down";
    startslide(objName);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: slideup                                                                                         ***/
/***                                                                                                        ***/
/// <summary>
/// Starts the control sliding up (collapsing).
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function slideup (objName)
{
    /**********************************************************************************************************/
    /***  If the control is already moving, ignore                                                          ***/
    /**********************************************************************************************************/
    
    if (moving[objName] == true)
    {
        return;
    }

    /**********************************************************************************************************/
    /***  If the control is hidden, it's already collapsed                                                  ***/
    /**********************************************************************************************************/
    
    if  (document.getElementById(objName).style.display == "none")
    {
        return;
    }

    /**********************************************************************************************************/
    /***  Set the variables                                                                                 ***/
    /**********************************************************************************************************/
    
    moving[objName] = true;
    dir[objName] = "up";
    startslide(objName);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: startslide                                                                                      ***/
/***                                                                                                        ***/
/// <summary>
/// Starts the control sliding.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function startslide (objName)
{
    /**********************************************************************************************************/
    /***  Set the control and it's height and start time                                                    ***/
    /**********************************************************************************************************/
    
    obj[objName] = document.getElementById(objName);
    endHeight[objName] = parseInt(obj[objName].style.height);
    startTime[objName] = (new Date()).getTime();

    /**********************************************************************************************************/
    /***  If we're sliding down, start the height at 1px                                                    ***/
    /**********************************************************************************************************/
    
    if(dir[objName] == "down")
    {
        obj[objName].style.height = "1px";

        /******************************************************************************************************/
        /***  If we need to, hide/show the child control                                                    ***/
        /******************************************************************************************************/
    
        if (ctrlChildrenToHide[objName] != null && m_bChildrenAsParent == true)
        {
            document.getElementById(ctrlChildrenToHide[objName]).style.display = "";
        }
        else
        {
            document.getElementById(ctrlChildrenToHide[objName]).style.display = "none";
        }
    }
    
    /**********************************************************************************************************/
    /***  Set the display and the timer                                                                     ***/
    /**********************************************************************************************************/
    
    obj[objName].style.display = "block";
    timerID[objName] = setInterval('slidetick(\'' + objName + '\');',timerlen);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: slidetick                                                                                       ***/
/***                                                                                                        ***/
/// <summary>
/// Changes the control height, to imitate sliding.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function slidetick(objName)
{
    /**********************************************************************************************************/
    /***  Get the time elapsed                                                                              ***/
    /**********************************************************************************************************/
    
    var elapsed = (new Date()).getTime() - startTime[objName];

    /**********************************************************************************************************/
    /***  If enough time has elapsed, end the slide                                                         ***/
    /**********************************************************************************************************/
    
    if (elapsed > slideAniLen)
    {
        endSlide(objName)
    }
    else
    {
        /******************************************************************************************************/
        /***  Get the number of pixels to slide                                                             ***/
        /******************************************************************************************************/
    
        var d = Math.round(elapsed / slideAniLen * endHeight[objName]);

        /******************************************************************************************************/
        /***  If it's sliding up, set the number of pixels left (otherwise, it's already correct)           ***/
        /******************************************************************************************************/
    
        if(dir[objName] == "up")
        {
            d = endHeight[objName] - d;
        }

        /******************************************************************************************************/
        /***  Set the height                                                                                ***/
        /******************************************************************************************************/
    
        obj[objName].style.height = d + "px";
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: endSlide                                                                                        ***/
/***                                                                                                        ***/
/// <summary>
/// Ends the sliding.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function endSlide(objName)
{
    /**********************************************************************************************************/
    /***  Clear the timer                                                                                   ***/
    /**********************************************************************************************************/
    
    clearInterval(timerID[objName]);

    /**********************************************************************************************************/
    /***  If it's a slide up, hide the control                                                              ***/
    /**********************************************************************************************************/
    
    if(dir[objName] == "up")
    {
        obj[objName].style.display = "none";
    }

    /**********************************************************************************************************/
    /***  Set the final height of the control                                                               ***/
    /**********************************************************************************************************/
    
    obj[objName].style.height = endHeight[objName] + "px";

    /**********************************************************************************************************/
    /***  If we need to, hide/show the child control                                                        ***/
    /**********************************************************************************************************/
    
    if (ctrlChildrenToHide[objName] != null)
    {
        if (dir[objName] == "up")
        {
            if (m_bChildrenAsParent == true)
            {
                document.getElementById(ctrlChildrenToHide[objName]).style.display = "none";
            }
            else
            {
                document.getElementById(ctrlChildrenToHide[objName]).style.display = "";
            }
        }
    }
    
    /**********************************************************************************************************/
    /***  Delete all the info stored in the arrays                                                          ***/
    /**********************************************************************************************************/
    
    delete(moving[objName]);
    delete(timerID[objName]);
    delete(startTime[objName]);
    delete(endHeight[objName]);
    delete(obj[objName]);
    delete(dir[objName]);
    delete(ctrlChildrenToHide[objName]);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: popUp                                                                                           ***/
/***                                                                                                        ***/
/// <summary>   
/// Function to open a pop-up window to a given url and resize it to full screen (its not maximised though)
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function popUp(url)
{    
    var myWindow = window.open(url, 'myWindow', 'status=0,toolbar=0,location=0,menubar=1,directories=0,resizable=1,scrollbars=1');
    myWindow.moveTo(0,0)
    myWindow.resizeTo(screen.availWidth, screen.availHeight)
    myWindow.focus();
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: ResetAllLM                                                                                      ***/
/***                                                                                                        ***/
/// <summary>   
/// Resets the ddl and puts the selected index back to the dummy 0                                                  
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function ResetLM(ddlID)
{    
    var ddl = document.getElementById(ddlID);
    
    if  (ddl)
    {
        ddl.selectedIndex = 0;
    }    
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: ResetAllLM                                                                                      ***/
/***                                                                                                        ***/
/// <summary>   
/// Loops over the various rows in the specified table and sets the ddls in column 4 to the dummy item at index 0
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function ResetAllLM(tableID)
{    
    var table = document.getElementById(tableID);
    
    //Start at row 1 as the first one is the header
    for (var i = 1; i < table.tBodies[0].rows.length; i++)
    {
        var row = table.tBodies[0].rows[i];        
        var select = row.cells[3].childNodes[0];
        select.selectedIndex = 0;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: switchEmployeeView                                                                              ***/
/***                                                                                                        ***/
/// <summary>
/// On the employee edit screen - flips between the different tabs
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function switchEmployeeView(divToShowId, divHide1Id, divHide2Id, divHide3Id, divHide4Id,
    butSelectedId, butNormal1Id, butNormal2Id, butNormal3Id, butNormal4Id,
    hiddenId)
{
    var divShow = document.getElementById(divToShowId);
    var divHide1 = document.getElementById(divHide1Id);
    var divHide2 = document.getElementById(divHide2Id);
    var divHide3 = document.getElementById(divHide3Id);
    var divHide4 = document.getElementById(divHide4Id);
    
    /**********************************************************************************************************/
    /***  If its not there then leave now - this would happen if there were no employees and we were        ***/
    /***  showing the                                                                                       ***/
    /**********************************************************************************************************/
    
    if  (!divShow)
    {
        return;
    }
    
    divShow.style.display = '';
    divHide1.style.display = 'none';
    divHide2.style.display = 'none';
    divHide3.style.display = 'none';
    divHide4.style.display = 'none';
    
    var butSelected = document.getElementById(butSelectedId);
    var butNormal1 = document.getElementById(butNormal1Id);
    var butNormal2 = document.getElementById(butNormal2Id);
    var butNormal3 = document.getElementById(butNormal3Id);
    var butNormal4 = document.getElementById(butNormal4Id);
    
    butSelected.className = 'PanelButtonSelected';
    butNormal1.className = 'PanelButton';
    butNormal2.className = 'PanelButton';
    butNormal3.className = 'PanelButton';

    /**********************************************************************************************************/
    /***  Check the last button is there, as it may be hidden (if holidays are turned off)                  ***/
    /**********************************************************************************************************/
        
    if (butNormal4 != null)
    {
        butNormal4.className = 'PanelButton';
    }
    
    var hidden = document.getElementById(hiddenId);
    hidden.value = divToShowId;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: switchContactView                                                                               ***/
/***                                                                                                        ***/
/// <summary>
/// On the contact edit screen - flips between the different tabs
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function switchContactView(divToShowId, divHide1Id, divHide2Id, 
    butSelectedId, butNormal1Id, butNormal2Id, 
    hiddenId) 
{
    var divShow = document.getElementById(divToShowId);
    var divHide1 = document.getElementById(divHide1Id);
    var divHide2 = document.getElementById(divHide2Id);
    
    /**********************************************************************************************************/
    /***  If its not there then leave now - this would happen if there were no employees and we were        ***/
    /***  showing the                                                                                       ***/
    /**********************************************************************************************************/

    if (!divShow) 
    {
        return;
    }

    divShow.style.display = '';
    divHide1.style.display = 'none';
    divHide2.style.display = 'none';
    
    var butSelected = document.getElementById(butSelectedId);
    var butNormal1 = document.getElementById(butNormal1Id);
    var butNormal2 = document.getElementById(butNormal2Id);
    
    butSelected.className = 'PanelButtonSelected';
    butNormal1.className = 'PanelButton';
    
    /**********************************************************************************************************/
    /***  Check the 2nd hide button is there as it will only be there if appointments are turned on         ***/
    /**********************************************************************************************************/
    
    if (butNormal2 != null) 
    {
        butNormal2.className = 'PanelButton';
    }

    var hidden = document.getElementById(hiddenId);
    hidden.value = divToShowId;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: checkAllDataGridCheckBoxes                                                                      ***/
/***                                                                                                        ***/
/// <summary>
/// Checks all DataGrid CheckBoxes with the given name with the given value
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function checkAllDataGridCheckBoxes(aspCheckBoxID, checkVal) 
{
    re = new RegExp(aspCheckBoxID + '$');  //generated control name starts with a colon

    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];

        if (elm.type == 'checkbox') 
        {
            if (re.test(elm.name)) 
            {
                elm.checked = checkVal;
            }
        }
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: showHideDueTimeTextBox                                                                          ***/
/***                                                                                                        ***/
/// <summary>
/// Shows or hide a due time control based on what is selected in a different control
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function showHideDueTimeTextBox(ddlID, liID, timeUntilDueVal)
{
    ddl = document.getElementById(ddlID);
    li = document.getElementById(liID);
    if  (ddl.options[ddl.selectedIndex].value == timeUntilDueVal)
    {
        li.style.display = '';
    }
    else
    {
        li.style.display = 'none';
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: numKeysAllowedCheck                                                                             ***/
/***                                                                                                        ***/
/// <summary>
/// Used to check that when a text changed event is fired, we ignore if its not a number
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function numKeysAllowedCheck(objTextInput, e)
{ 		 			
	var keyCode0 = 48;				//ascii code for 0
	var keyCode9 = 57;				//ascii code for 9
	
	// Get the key pressed							
	var keyCodePressedByUser;
	if (window.event)
	{ 	keyCodePressedByUser = window.event.keyCode;	}
	else 
	{	if (e)
			keyCodePressedByUser = e.which;							
		else 
			return true;
	}										

	return (keyCodePressedByUser >= keyCode0 && keyCodePressedByUser <= keyCode9);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: areThereAttachments                                                                             ***/
/***                                                                                                        ***/
/// <summary>
/// Checks if any of the file upload controls have a file specified.  If not it just hides the popup to save an
/// unnecessary postback.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function areThereAttachments(mpe, fu1, fu2, fu3, fu4, fu5)
{
    // Check each one
    var val1 = $get(fu1).value;
    var val2 = $get(fu2).value;
    var val3 = $get(fu3).value;
    var val4 = $get(fu4).value;
    var val5 = $get(fu5).value;
    
    // If they are all empty then just hide the popup and return false (so we don't post back)
    if  (val1 == '' && val2 == '' && val3 == '' && val4 == '' && val5 == '')
    { 
        $find(mpe).hide();
        return false;
    }
    else
    {   
        return true;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: areAnyDocumentsAttached                                                                         ***/
/***                                                                                                        ***/
/// <summary>
/// Checks if any checkboxes matching the given name are checked, if they are will return true, if not will close
/// the given popup and return false
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function areAnyDocumentsAttached(mpe) 
{
    re = new RegExp('cbDocumentChecked' + '$');  //generated control name starts with a colon
    
    var oneChecked = false;

    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];

        if (elm.type == 'checkbox') 
        {
            if (re.test(elm.name)) 
            {
                if (elm.checked == true)
                {
                    oneChecked = true;
                    break;
                }
            }
        }
    }
    
    // If nothing is checked, then just hide and return false
    if  (oneChecked == false)
    {
        $find(mpe).hide();
        return false;
    }
    else
    {
        return true;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: cleanAndShowAttachLocalFilesPopup                                                               ***/
/***                                                                                                        ***/
/// <summary>
/// Opens the attach document popup, and also makes sure that the check boxes are unticked
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function cleanAndShowAttachLocalFilesPopup(mpe, chk1, chk2, chk3, chk4, chk5)
{
    //Make sure all the checkboxes are turned off
    $get(chk1).checked = false;
    $get(chk2).checked = false;
    $get(chk3).checked = false;
    $get(chk4).checked = false;
    $get(chk5).checked = false;

    //Now show the popup
    $find(mpe).show();
    return false;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: cleanAndShowAttachDocPopup                                                                      ***/
/***                                                                                                        ***/
/// <summary>
/// Opens the attach document popup, and also makes sure that the check boxes are unticked
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function cleanAndShowAttachDocPopup(mpe)
{
    // Make sure they are all unticked
    $get('chkAllDocuments').checked = false;
    $get('chkAllDocuments').onclick();
    
    //Now show the popup
    $find(mpe).show();
    return false;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: confirmGlobalEmails                                                                             ***/
/***                                                                                                        ***/
/// <summary>
/// Confirms that an organisation should be using global email definitions, thus losing their specific email 
/// definitions.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function confirmGlobalEmails()
{
    if (confirm("Are you sure you want this organisation to use global email definitions? If you choose OK " +
        "the specific email definitions for this organisation will be lost and it will use the global ones. " +
        "This cannot be undone. Select OK to use global email definitions for this organisation.") == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: switchTwoPanel                                                                                  ***/
/***                                                                                                        ***/
/// <summary>
/// Flips between two different panels.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function switchTwoPanel(divToShowId, divHide1Id, butSelectedId, butNormal1Id, hiddenId)
{
    var divShow = document.getElementById(divToShowId);
    var divHide1 = document.getElementById(divHide1Id);
    
    divShow.style.display = '';
    divHide1.style.display = 'none';
    
    var butSelected = document.getElementById(butSelectedId);
    var butNormal1 = document.getElementById(butNormal1Id);
    
    butSelected.className = 'PanelButtonSelected';
    butNormal1.className = 'PanelButton';
    
    var hidden = document.getElementById(hiddenId);
    hidden.value = divToShowId;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: switchThreePanel                                                                                ***/
/***                                                                                                        ***/
/// <summary>
/// Flips between three different panels.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function switchThreePanel(divToShowId, divHide1Id, divHide2Id,
    butSelectedId, butNormal1Id, butNormal2Id,
    hiddenId)
{
    var divShow = document.getElementById(divToShowId);
    var divHide1 = document.getElementById(divHide1Id);
    var divHide2 = document.getElementById(divHide2Id);
    
    divShow.style.display = '';
    divHide1.style.display = 'none';
    divHide2.style.display = 'none';
    
    var butSelected = document.getElementById(butSelectedId);
    var butNormal1 = document.getElementById(butNormal1Id);
    var butNormal2 = document.getElementById(butNormal2Id);
    
    butSelected.className = 'PanelButtonSelected';
    butNormal1.className = 'PanelButton';
    butNormal2.className = 'PanelButton';
    
    var hidden = document.getElementById(hiddenId);
    hidden.value = divToShowId;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: clearTextBox                                                                                    ***/
/***                                                                                                        ***/
/// <summary>
/// Clears the given text box.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function clearTextBox(txtTextBoxId)
{
    var txtTextBox = document.getElementById(txtTextBoxId);
    
    txtTextBox.value = '';
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: enableDisableOnCheckbox                                                                         ***/
/***                                                                                                        ***/
/// <summary>
/// Enables/disables a control, based on the check state of the given checkbox.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function enableDisableOnCheckbox(cbCheckBoxId, ctrlControlId)
{
    var cbCheckBox = document.getElementById(cbCheckBoxId);
    var ctrlControl = document.getElementById(ctrlControlId);
    var strDisabled;
    
    /**********************************************************************************************************/
    /***  If there's a control, set its disabled property                                                   ***/
    /**********************************************************************************************************/
    
    if (ctrlControl != undefined)
    {
        /******************************************************************************************************/
        /***  Get whether it's disabled or not                                                              ***/
        /******************************************************************************************************/
    
        if  (cbCheckBox.checked == true)
        {
            strDisabled = '';
        }
        else
        {
            strDisabled = 'disabled';
        }
        
        /******************************************************************************************************/
        /***  Set the property                                                                              ***/
        /******************************************************************************************************/
        
        ctrlControl.disabled = strDisabled;
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: saveCheckBoxStates                                                                              ***/
/***                                                                                                        ***/
/// <summary>
/// Stores the checked state of the checkboxes to the given hidden field.
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function saveCheckBoxStates(hdnHiddenFieldId)
{
    /**********************************************************************************************************/
    /***  Get the hidden field and parent control                                                           ***/
    /**********************************************************************************************************/
    
    var hdnHiddenField = document.getElementById(hdnHiddenFieldId);
    
    hdnHiddenField.value = '';
    
    /**********************************************************************************************************/
    /***  Create a RegEx to get all the relevant checkboxes                                                 ***/
    /**********************************************************************************************************/
 
    re = new RegExp('cbPerms');

    /**********************************************************************************************************/
    /***  Loop over all the controls, looking for checkboxes                                                ***/
    /**********************************************************************************************************/
 
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        /******************************************************************************************************/
        /***  Get the next element                                                                          ***/
        /******************************************************************************************************/
        
        elm = document.forms[0].elements[i];
        
        /******************************************************************************************************/
        /***  If it's a checkbox, process further                                                           ***/
        /******************************************************************************************************/
        
        if (elm.type == 'checkbox') 
        {
            /**************************************************************************************************/
            /***  If it's name matches, process further                                                     ***/
            /**************************************************************************************************/
        
            if (re.test(elm.name)) 
            {
                /**********************************************************************************************/
                /***  Add the client ID and checked state to the hidden fields value                        ***/
                /**********************************************************************************************/
                
                str = elm.id + ':' + elm.checked;
                hdnHiddenField.value = hdnHiddenField.value + ',' + str;
            }
        }
    }
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: setDateFilterText                                                                               ***/
/***                                                                                                        ***/
/// <summary>
/// Sets the date filter text boxes based on the values passed in
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function setDateFilterText(calFromID, calToID, txtFromText, txtToText)
{
    var textBox1 = $get(calFromID);
    if (textBox1.AjaxControlToolkitTextBoxWrapper) 
    {
        textBox1.AjaxControlToolkitTextBoxWrapper.set_Value(txtFromText);
    }
    else 
    {
        textBox1.value = txtFromText;
    }
    
    var textBox2 = $get(calToID);
    if (textBox2.AjaxControlToolkitTextBoxWrapper) 
    {
        textBox2.AjaxControlToolkitTextBoxWrapper.set_Value(txtToText);
    }
    else 
    {
        textBox2.value = txtFromText;
    }
    
    return false;
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: closeListManyRowConfirm                                                                         ***/
/***                                                                                                        ***/
/// <summary>
/// Gets the modal popup and closes it
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function closeListManyRowConfirm()
{
    var mpe = $find('mpeConfirmPopup');
        
    if  (mpe)
    {
        mpe.hide();
    }
}