// Regular Expression Patterns

var NSX = (navigator.appName == "Netscape");
var IE4 = (document.all) ? true : false;

function searchList(listArray,id)
{
	var match = false;

	for (counter=0;counter<listArray.length;counter++)
	{

		if (listArray[counter]==id) 
		{
			match=true;
			break;

		}
	}
	return match;
}


function authAdmin(seriesName,id)
{
	var match = false;
	listArray = eval(seriesName);
	
	for (counter=0;counter<listArray.length;counter++)
	{
		if (listArray[counter]==id) 
		{
			match=true;
			break;
		}

	}


	return match;
}


function qryArray(seriesName,id,cols,range,start)
{
	var listArray;
	var counter=0;
	var match = "";
	var subCounter = 0;

	if (range==null) range=1;
	if (cols==null) cols=2;
	if (start==null) start=1;

	listArray = eval(seriesName);
	if (seriesName=="arDivList") cols=3;

	while ((counter<listArray.length) && (match==""))
	{
		
		if (listArray[counter]==id)
		{
			for (subCounter=(counter+start);subCounter<=(counter+range);subCounter++)
			{
				match = match + listArray[subCounter];
				if ((range>2) && (subCounter<counter+range)) match=match+", "
			}
		}
		counter=counter+cols;
	}
	return match;
}

function buildDropdown(seriesName,frame,tagOver,blankspace,cols,targetByID,series2)
{
	var listArray;
	var selectList;
	var selectBox;
	var optItem;
	var colLength;
	var itemSelect;
	var globalFilter;
	var strTag;
	var arTag;
	var b;
	listArray = eval(seriesName);
	
	
	//Purpose of series 2 is if I have more than one dropdown with the same name and ID series
	//See phonebook with the Start and Finish times.

	if ((series2!=null)&&(series2!="")) seriesName=series2;
	var targetFrame


	if (frame!=null)
	{
		targetFrame = document.frames(frame).document
		selectList = document.frames(frame).document.all.item(seriesName);
	}
	else
	{
		targetFrame = document;
		selectList = document.all.item(seriesName);
	}

	if (selectList!=null)
	{


	if (targetByID!=null)
	{
		for(a=0;a<selectList.length;a++)
		{
			b = a;
			if (selectList(a).name==targetByID)
			{
				b=selectList.length;
				selectList = selectList(a);
			}
			a = b;
		}
	}

	if (selectList!=null)
	{

		if ((selectList.tagName=="SELECT") && (selectList.childNodes.length>0))
		{
			//Whats happened here is that its only found one select list, but with
			//child nodes i.e. OPTIONS already loaded in to it
			//Setting the innerHTML to '' effectively wipes this.
			selectList.innerHTML="";
			colLength=0;
		}
		else
		{
			colLength = selectList.length;
		}
	}

	if (selectList!=null)
	{
		for (a=0;a <= colLength;a++)
		{
			if (colLength>0)
			{
				selectBox = selectList.item(a);
			}
			else
			{
				selectBox = selectList;
			}

			for (d=selectBox.length;d>0;d--)
			{
				selectBox.remove(0);
			};


			if (blankspace>0)
			{
				optItem = targetFrame.createElement("OPTION");
				optItem.value = 0;

				switch (blankspace)
				{
					case 1:
						optItem.text = "Select....";
						break;
					case 2:
						optItem.text = "(include all)";
						break;
					case 3:
						optItem.text = "(none)";
						break;
					default:
						optItem.text = "";
						break;
				}

				selectBox.add(optItem);
			};

			globalFilter = null;
			itemSelect = null;

			if (selectBox.tag!=null) 
			{	strTag = selectBox.tag.toLowerCase();
			} else {strTag="0"};

			if ((tagOver!=null) && (tagOver!=0))
			{
				strTag = tagOver.toString();
			}
			if (strTag!=null)
			{
				strTag.toLowerCase();
				arTag = strTag.split("|")
				if (arTag.length>=2)
				{
					globalFilter = strTag.split("|");
					itemSelect = arTag[0];
					arTag[0]=null;
				}
				else
				{
					itemSelect = strTag;
				}
			}

			for (b=0;b<listArray.length;b+=cols)
			{
				if ((globalFilter==null) || (authAdmin(arTag,listArray[b+2])))
				{
					optItem = targetFrame.createElement("OPTION");
					optItem.value = listArray[b];
					if (cols>1) optItem.text = listArray[b+1];
					else optItem.text = listArray[b];

					selectBox.add(optItem);
				}

				if (listArray[b].toLowerCase()==itemSelect)
				{
					optItem.selected = true
				};

			};

			if (selectBox.length==0)
			{
				optItem=targetFrame.createElement("OPTION");
				optItem.value=-1;
				optItem.text="<undefined>"
				selectBox.add(optItem);
			};
			if (a==colLength-1) a++;
		};
	};

	};
};



		
	function addOption(objCbo,strValue,strText)
	{
		//Add an option to the select box
		if (IE4)
		{
			var objNewOpt = document.createElement("OPTION");
			objNewOpt.text = strText;
			objNewOpt.value = strValue;
			objCbo.add(objNewOpt);
		}
		if (NSX)
		{
			var objNewOpt  = new Option(strText, strValue);
			objCbo.options[objCbo.length] = objNewOpt;
		}
	}
			
	function deleteOption(objCbo,intOptionIndex)
	{
		//Remove an option from the select box
		if (IE4)
		{
			objCbo.remove(intOptionIndex);
		}
		if (NSX)
		{
			objCbo.options[intOptionIndex] = null;
		}
	}
		
	function swapOption(strFormName,strGroupName,strAction)
	{
		//Swap an option from one select to another and change the contents of the hidden field
		var strEval = "document.forms." + strFormName + "." + strGroupName;
		var objAll = eval(strEval);
		var strEval = "document.forms." + strFormName + "." + strGroupName + "Selected";
		var objSelected = eval(strEval);
		var strEval = "document.forms." + strFormName + "." + strGroupName + "Hidden";
		var objHid = eval(strEval);
		var strIDs = "";	

		if (strAction == "A" && objAll.length >= 1)
		{
			//An item is to be selected
			addOption(objSelected,objAll.options[objAll.selectedIndex].value,objAll.options[objAll.selectedIndex].text);
			deleteOption(objAll,objAll.selectedIndex);
		}

		if (strAction == "C" && objAll.length >=1 )
		{
			addOption(objSelected,objAll.options[objAll.selectedIndex].value,objAll.options[objAll.selectedIndex].text);
		}	

		if(strAction == "D" && objSelected.length >= 1)
		{
			//An item is to be unselected
			deleteOption(objSelected,objSelected.selectedIndex);
		}
					
		if(strAction == "R" && objSelected.length >= 1)
		{
			//An item is to be unselected
			addOption(objAll,objSelected.options[objSelected.selectedIndex].value,objSelected.options[objSelected.selectedIndex].text);
			deleteOption(objSelected,objSelected.selectedIndex);
		}
					
		//Update the hidden input
		objHid.value = "";
		for (intLoop = 0; intLoop < objSelected.length; intLoop++)
		{
			strIDs = strIDs + "," + objSelected.options[intLoop].value;
		}			
		if (strIDs != "") strIDs = strIDs.substr(1);
		objHid.value = strIDs;
	}


		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_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_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];}
		}

