function popup(form, action, IDField) {
	var win = 'popup.cfm?action=' + action + '&' + IDField + 'ID=0';
	if (form.selValue.value == '') 
	{
		alert('You must select an entry to ' + action + '.');
	} 
	else 
	{
		var linkID = form.selValue.value;
		var win = 'popup.cfm?action=' + action + IDField + '&' + IDField + 'ID=' + linkID;
		window.open(win, 'popup', 'width=600,height=400,toolbar=no,scrollable=yes,resizable=yes');
	}
}

function validate_universal(formobj) {

var msg = '';
var cont_msg = '';	

	if (typeof f_arr !="undefined")
	{
		for (i=0; i<f_arr.length; i++)
		{
			if (formobj.elements[f_arr[i]] && formobj.elements[f_arr[i]].value == '')
			{
				msg = msg + '    ' + c_arr[i] + '\n';
			}
		}
	}
	if (typeof r_arr !="undefined")
	{
		for (i=0; i<r_arr.length; i++)
		{
			myOption = -1;
			for (x=formobj.elements[r_arr[i]].length-1; x > -1; x--) 
			{
				if (formobj.elements[r_arr[i]][x].checked == true) 
				{
					myOption = x;
				}
			}
			if (myOption == -1)
			{
				msg = msg + '    ' + rc_arr[i] + '\n';
			}
		}
	}

	if (typeof cont_arr !="undefined")
	{
		for (i=0; i<cont_arr.length; i++)
		{
			if (formobj.elements[cont_arr[i]] && formobj.elements[cont_arr[i]].value == '')
			{
				cont_msg = 1;
			}
		}
		if (cont_msg != '')
		{
			
			msg = msg + '\n At least one of these fields is required: ' + cont_captions + '\n';
		}
	}
	
	if (msg != '')
	{	
		var out = "~"; // replace this
		var add = ","; // with this
		var temp = "" + msg; // temporary holder
		while (temp.indexOf(out)>-1) 
		{
			pos= temp.indexOf(out);
			temp = "" + (temp.substring(0, pos) + add + 
			temp.substring((pos + out.length), temp.length));
		}
		msg = temp;
		alert('The following fields are required: \n' + msg);
		return false;
	}
	else
	{
		formobj.submit();
	}
}

function LookUp(searchbox, list) {
    var found = false;
    if (searchbox != 0) 
	{
        for (var i=0; (i < list.length) && !found; i++) 
		{
            if (list.options[i].text.toUpperCase().indexOf(searchbox.value.toUpperCase()) == 0) 
			{
                found = true;
                list.options[i].selected = true;
            }
            else if (list.options[i].text.toUpperCase() > searchbox.value.toUpperCase()) 
			{
                found = true;
                list.options[i].selected = true;
            }
        }
        if (!found)
		{
           list.options[list.length - 1].selected = true;
		}
    }
}

function setFlag(form, sourceField, targetField) {
	if (sourceField.checked == false) 
	{
		targetField.value = '';
	}
	else
	{
		targetField.value = '1';
	}
}
function setFlagDTS(sourceField, IDField, DTSField) {

	if (sourceField.checked == false) 
	{
		IDField.disabled = true;
		DTSField.disabled = true;
	}
	else
	{
		IDField.disabled = false;
		DTSField.disabled = false;
	}
}

function closeParent() {
	if (window.opener) 
	{
		window.opener.location.reload();
		self.close();
	}
	else
	{
		window.location.reload();
	}
}
function ToggleDisplay(formObj, id) {
	if ( formObj.value == 'Lookup' )
	{	
		formObj.value = '  Hide  ';
		document.getElementById(id).style.display='block';	
	}
	else
	{
		formObj.value = 'Lookup';
		document.getElementById(id).style.display='none';	
	}
}

function passwordConfirm(field1, field2) {
	if (field1.value != field2.value) 
	{
		alert ("\nThe passwords don't match. Please re-enter your password.")
		return false;
	}
	else
	{
		return true;
	}
}

function selAllOptions(theSel) {
	var selLength = theSel.length;
	for(i=selLength-1; i>=0; i--)
	{
		theSel.options[i].selected = true;
	}
}
	
function move(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	for (i = 0; i < tbox.options.length; i++) 
	{
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for (i = 0; i < fbox.options.length; i++) 
	{
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != "") 
		{
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		}
		else 
		{
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
	   }
	}
	//arrFbox.sort();
	//arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var c;
	for (c = 0; c < arrFbox.length; c++) 
	{
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for (c = 0; c < arrTbox.length; c++) 
	{
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	}
}

function validateForm(){
	var val;
	val = 0;
	errMsg.style.display="None";
	errMsg1.style.display="None";
	errMsgX.style.display="None";	
	var strValues = "";
	var boxLength = document.CFForm_1.list2.length;
	var count = 0;
	if (boxLength != 0) 
	{
		for (i = 0; i < boxLength; i++) 
		{
			if (count == 0) 
			{
				strValues = document.CFForm_1.list2.options[i].value;
			}
			else 
			{
				strValues = strValues + "," + document.CFForm_1.list2.options[i].value;
			}
			count++;
	   }
	}
	if (strValues.length == 0) 
	{
		errMsg.style.display="";
		errMsg1.style.display="";
		val=1;
	}
	
	if(val==0)
	{
		document.CFForm_1.StackList.value = strValues;
		return true;
	}
	else
	{
		return false;
	}
}	

function moveUpList(listField) {
   if ( listField.length == -1) 
   {  // If the list is empty
	  alert("There are no values which can be moved!");
   } 
   else 
   {
	  var selected = listField.selectedIndex;
	  if (selected == -1) 
	  {
		 alert("You must select an entry to be moved!");
	  } 
	  else 
	  {  // Something is selected 
		 if ( listField.length == 0 ) 
		 {  // If there's only one in the list
			alert("There is only one entry!\nThe one entry will remain in place.");
		 } 
		 else 
		 {  // There's more than one in the list, rearrange the list order
			if ( selected == 0 ) 
			{
			   alert("The first entry in the list cannot be moved up.");
			} 
			else 
			{
			   // Get the text/value of the one directly above the hightlighted entry as
			   // well as the highlighted entry; then flip them
			   var moveText1 = listField[selected-1].text;
			   var moveText2 = listField[selected].text;
			   var moveValue1 = listField[selected-1].value;
			   var moveValue2 = listField[selected].value;
			   listField[selected].text = moveText1;
			   listField[selected].value = moveValue1;
			   listField[selected-1].text = moveText2;
			   listField[selected-1].value = moveValue2;
			   listField.selectedIndex = selected-1; // Select the one that was selected before
			}  // Ends the check for selecting one which can be moved
		 }  // Ends the check for there only being one in the list to begin with
	  }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}
	
function moveDownList(listField) {
   if ( listField.length == -1) 
   {  // If the list is empty
	  alert("There are no values which can be moved!");
   } 
   else 
   {
	  var selected = listField.selectedIndex;
	  if (selected == -1) 
	  {
		 alert("You must select an entry to be moved!");
	  } 
	  else 
	  {  // Something is selected 
		 if ( listField.length == 0 ) 
		 {  // If there's only one in the list
			alert("There is only one entry!\nThe one entry will remain in place.");
		 } 
		 else 
		 {  // There's more than one in the list, rearrange the list order
			if ( selected == listField.length-1 ) 
			{
			   alert("The last entry in the list cannot be moved down.");
			} 
			else 
			{
			   // Get the text/value of the one directly below the hightlighted entry as
			   // well as the highlighted entry; then flip them
			   var moveText1 = listField[selected+1].text;
			   var moveText2 = listField[selected].text;
			   var moveValue1 = listField[selected+1].value;
			   var moveValue2 = listField[selected].value;
			   listField[selected].text = moveText1;
			   listField[selected].value = moveValue1;
			   listField[selected+1].text = moveText2;
			   listField[selected+1].value = moveValue2;
			   listField.selectedIndex = selected+1; // Select the one that was selected before
			}  // Ends the check for selecting one which can be moved
		 }  // Ends the check for there only being one in the list to begin with
	  }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

function maskKeyPress(objEvent){
	var iKeyCode;  	
	iKeyCode = objEvent.keyCode;	
	//alert(iKeyCode);
	if((iKeyCode>=48 && iKeyCode<=57) || iKeyCode==13 || iKeyCode==46) return true;
  		return false;
}


// function to select all chackboxes in a form using another checkbox
function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
 	for(z=0; z<theForm.length;z++)
	{
		if (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
		{
			theForm[z].checked = theElement.checked;
		}
	}
}

// function to select all chackboxes in a form using a button
function checkUncheckBtn(theForm, theElement) {
	var z = 0;
 	for(z=0; z<theForm.length; z++)
	{
		if (theForm[z].type == 'checkbox')
		{
			if ( theElement.value == 'Select All')
			{
				theForm[z].checked = true;
			}
			else
			{
				theForm[z].checked = false;
			}
		}
	}
	if ( theElement.value == 'Select All')
	{
			theElement.value = 'Deselect All'
	}
	else
	{
		theElement.value = 'Select All'
	}
}

