var newwindow = '';
function PopUpWin(url,wi,hi,top,left,loc) {
	if(top == null){
	 	top = 100;
	}
	if(left == null){
		left = 100;
	}
	
	if (loc == null) {
		loc='no';
	}
	
  newwindow=window.open(url,'','height='+hi+',width='+wi+',toolbar='+loc+',directories=no,location='+loc+',menubar=no,status=yes,scrollbars=yes,left='+left+',top='+top+',resizable=yes');
}
function show_calendar(url) {
	window.open("/newcalendar/calendar.cfm?formfield=" + url, "Calendar", "width=230,height=150,status=no,resizable=no,top=100,left=400");
}

function showLoadbar(state) {
	if (state == null) { 
		state = 'visible';
	}
	document.getElementById('loadingbar').style.visibility = state; // loadingbar is in the topNavBar include
}

windowSize = function(what)
{
        var w = 0;
        var h = 0;

        //IE
        if(!window.innerWidth)
        {
                //strict mode
                if(!(document.documentElement.clientWidth == 0))
                {
                        w = document.documentElement.clientWidth;
                        h = document.documentElement.clientHeight;
                }
                //quirks mode
                else
                {
                        w = document.body.clientWidth;
                        h = document.body.clientHeight;
                }
        }
        //w3c
        else
        {
                w = window.innerWidth;
                h = window.innerHeight;
        }

        if (what == 'width') {
                return w;
         } else if (what == 'height') {
                return h;
         } else {
                return 0;
        }

        // return(width:w,height:h);
}


// Read a page's GET URL variables and return them as an associative array.
function getURLVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	if (hashes)
	{
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	} else {
		return 0;
	}
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function sortByName(a, b) {
    var x = a.text;
    var y = b.text;
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;	
  
  var lb = theSel;
	arrTexts = new Array();
	
	for(i=0; i<lb.length; i++)  {
	  arrTexts[i] = {value:lb.options[i].value, text:lb.options[i].text};
	}
	
	arrTexts.sort(sortByName);
	
	for(i=0; i<lb.length; i++)  {
	  lb.options[i].text = arrTexts[i].text;
	  lb.options[i].value = arrTexts[i].value;
	}
}


function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
}

function SelectAllList(CONTROL){
	if (CONTROL.length == 0) { 
		var newOpt = new Option("NONE","");
		CONTROL.options[0] = newOpt;
	}
	for(var i = 0;i < CONTROL.length;i++){
		CONTROL.options[i].selected = true;
	}	
}


