﻿// Manage lists of email recipients

var hasChanged = false;

function listTolist(lSrcList, lDestList, all)
{
    if (all)
    {
        for (i=0; i <= lSrcList.options.length-1; i+1)
        {
            addOption(lDestList, lSrcList[i].text, lSrcList[i].value);
            lSrcList.remove(i);
        }
    }
    else
        {
        var addedOne = false;
        for(i=lSrcList.options.length-1;i>=0;i--)
        {
            if(lSrcList[i].selected)
            {
                addOption(lDestList, lSrcList[i].text, lSrcList[i].value);
                lSrcList.remove(i);
                addedOne = true;
                // vvv MDC - Removed 2007-05-08 to allow for multiple item selection
                //i = -1;  // item has been added, so set i = -1 to terminate the FOR loop
                // ^^^ MDC - Removed 2007-05-08
            }
        }
        if (!addedOne)
        {
            alert('Please select an item from the list');
        }
    }
}

function addOption(lTargetList,text,value )
{
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    lTargetList.options.add(optn);
}

function makeHiddenCSV(hiddenCtrl, lSrcList)
{
    for (i=0; i <= lSrcList.options.length-1; i++)
    {
        hiddenCtrl.value += lSrcList[i].value + ","
    }
}

function markAsChanged()
{
    hasChanged = true;
}

function setHasChangedToFalse()
{
    hasChanged = false;
    return true;
}

function openWindowWithScroll(url, name, w, h) {
 var windowprops = "width=" + w + ",height=" + h + ",scrollbars=yes,allowresize,left=0,top=0,toolbar=yes,location=yes";
  popup = window.open(url,name,windowprops);
  }

////function insert(a,nLength, oValue)
////{
////    var x = nLength - 1;

////    while (x>=0 && a[x].text > oValue.text)
////    {
////        a[x+1].text = a[x].text;
////        a[x+1].value = a[x].value;
////        x--;
////    }
////    //alert(oValue.text + ' will go in position ' + (x+1));
////    a[x+1].text = oValue.text;
////    a[x+1].value = oValue.value;
////}
//// 
////function SortList(lList)
////{
////    var aOptions = lList.options
////    var nLength = lList.options.length
////    alert(nLength);
////    for (ii=0; ii<nLength; ii++)
////    {
////        insert(aOptions, ii, aOptions[ii]);
////    }
////    alert('Sorted in memory, ready to reset list');
////    //alert(aOptions[0].text);
////    //alert('aOptions has ' + (aOptions.length) + ' items');
////    for (i=0; i<=aOptions.length-1; i++)
////    {
////        //alert(aOptions[i]);
////        alert(aOptions[i].text);
////        alert(aOptions[i].value);
////        
//////        lList.remove(i);
//////        alert(aOptions[i]);
//////        
//////        addOption(lList,aOptions[i].text, aOptions[i].value);
////    }
////    //alert('Should be sorted');
////}
//function SortList(lList)
//{
//    var aOptions = new Array();
//    var aNewOptions = new Array();
//    var aTextValues = new Array();
//    var aValues = new Array();
//    for (i=0; i<=lList.options.length-1; i++)
//    {
//        aTextValues[i] = lList[i].text;
//        aValues[i] = lList[i].value;
//        aOptions[i] = lList[i];
//        aNewOptions[i] = lList[i];
//        lList.remove(i);
//    }    
//    
//    aTextValues.sort();
//    
//    for (ii=0; ii<=aTextValues.length-1; ii++)
//    {
//        aNewOptions[i].text = aTextValues[i];
//        aOptions.
//    }
//    
//{
