//bsb Javascript functions

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function populateAsNone() {
	var oSelect = document.getElementById('SelectedValues');
	
	for (i = oSelect.options.length; i >= 0; i--) {
		oSelect.options[i] = null; 
	}
	RemoveGroups();
	document.getElementById('boxrow').style.display = 'none';
}

function populateAsProject() {
	// create new option group
	// get reference to the `select' element
	document.getElementById('boxrow').style.display = 'inline';

	var oSelect = document.getElementById('SelectedValues');
	
	// empty existing items
	for (i = oSelect.options.length; i >= 0; i--) {
		oSelect.options[i] = null; 
	}
	
	RemoveGroups();
	
	for (i = 0; i < Sector.length; i++) {
		var oGroup = document.createElement('optgroup');
		oGroup.label = Sector[i][1];
	//	alert(Sector[3][2].length);
		if (Sector[i][2].length == 0) {
			var oOption = document.createElement('option');
			oOption.value = '';
			oOption.innerHTML = 'No projects';
			// append the option to the option group
			oGroup.appendChild(oOption);
		}
		for (j = 1; j < Sector[i][2].length; j++) {
			// create new options
			var oOption = document.createElement('option');
			oOption.value = Sector[i][2][j][0];
			oOption.innerHTML = Sector[i][2][j][1];
			if (Sector[i][2][j][2] == "Selected") {
				//	alert(Project[i][2]);
				oOption.selected = true; 
			}

			// append the option to the option group
			oGroup.appendChild(oOption);
			// append the option group

		}
		oSelect.appendChild(oGroup);
	}
}

function RemoveGroups()
      {
         try
         {
		var GroupList = document.getElementById('SelectedValues');

            var initialLength =  GroupList.length;
            for (var o = 0; initialLength > o; o++)
            {
               var cloneOption = GroupList.options[o].cloneNode(true);
               GroupList.appendChild(cloneOption);
            }


            var eachGroup = GroupList.firstChild;
            while ('OPTGROUP' == eachGroup.tagName)
            {
               lastGroup = eachGroup;
               eachGroup = lastGroup.nextSibling;
               GroupList.removeChild(lastGroup)
            }
         }
         catch(er){}

      }

function populateAsSector() {
	// create new option group
	// get reference to the `select' element
	document.getElementById('boxrow').style.display = 'inline';
	var oSelect = document.getElementById('SelectedValues');
	// empty existing items
	for (i = oSelect.options.length; i >= 0; i--) {
		oSelect.options[i] = null; 
	}
	
	RemoveGroups();
	
	
	for (i = 0; i < Project.length; i++) {
		// create new options
		var oOption = document.createElement('option');
		oOption.value = Project[i][0];
		oOption.innerHTML = Project[i][1];
		if (Project[i][2] == "Selected") {
		//	alert(Project[i][2]);
			oOption.selected = true; 
		}
		// append the option to the option group
		oSelect.appendChild(oOption);
		// append the option group
	}

}