/***********************************************
 The clear fields function is used to clear fields  that are no longer valid. 
 For example, there may be  a list of four radio buttons, if you check on 
 button then you you can fill out options for that context, however if you check 
 the other button you will have other fields to fill out. This function clears the 
 fields of the option that isn't checked. 
 
 Arguments: 
 	The first argument is the index of the field that is checked
	The Second is a 2 dim array, the first dimension is the radio buttons, 
		the second dimension is the fields valid for that option
************************************************/

function clearFields(inx, arr)
  { 
  var i, subArray, a, fld, fldType
  for (i = 0; i < arr.length; i++) 
     { 
	 if (i != inx) 
	   { 
		  subArray = arr[i]; 
		  for (a = 0; a < subArray.length; a++)
		  	{ 
			fld = arr[i][a];
			 
			// We need to get our field type
			if (document.forms[1][fld][0])
			  fldType = "radio";
			else 
			  { 
			  fldType = document.forms[1][fld].type;  
			  }
			  
			 if (fldType)
			 {
				switch (fldType)
				  { 
				  case 'text':
					  document.forms[1][fld].value = ""; 
					  break; 
				  case 'radio': 
					for (var cnt = 0; cnt < document.forms[1][fld].length; cnt++)
						document.forms[1][fld][cnt].checked = false; 
					break; 
				  case 'select-one': 
					document.forms[1][fld].selectedIndex = 0; 
					break;	
				  default: 
					break;
				  } 
			  }  
			} 
	   } 
	 } 
  } 
  
function checkField(fldName, inx) 
  { 
  	if (document.forms[1][fldName][inx])
	   	document.forms[1][fldName][inx].checked = true; 
  } 
  
function unCheck(arr, inx) 
  { 
  var i, fldName, fldType, list; 
  list = arr[inx];  
  for (i = 0; i < list.length; i++)
     { 
     fldName = list[i]; 
	 
	 if (document.forms[1][fldName][0])
		fldType = "radio";
	 else 
		fldType = document.forms[1][fldName].type;  
 	
	  if (fldType)	
	   { 
	   switch (fldType) 
	     { 
		 case 'text':
		 	document.forms[1][fldName].value = ""; 
			break;
		 case 'radio':
		 	for (var cnt = 0; cnt < document.forms[1][fldName].length; cnt++)
				document.forms[1][fldName][cnt].checked = false; 
			break; 
		 case 'checkbox':	
				document.forms[1][fldName].checked = false; 
			break; 
		 case 'select-one': 
			document.forms[1][fldName].selectedIndex = 0; 
			break;	
		 default: 
			break;	
		 } 	
	   } 
	 } 
  } 
  
  
/*******************************************************************
	Below here is the code for the "other" text boxes. 
********************************************************************/  
  	function isOther(selObj)
	 {
	
	 if(selObj.selectedIndex) 
	 	{ 
		 var selval = selObj[selObj.selectedIndex].value; 
		 var selName = selObj.name; 
		 if (selval.toLowerCase() == "other")
		 	showOther(selName); 
		 else 
		 	hideOther(selName); 
		}
	 }
	 
	 function showOther(selBox)
	 { 
	 	other = selBox + "_other"; 
	 	//document.forms[1][other].value = "Specify"; 	
		if (document.getElementById && !document.all)
		{ 
		  document.getElementById(other).style.visibility = "visible";  
		} 
		 else if (document.all) 
			document.all[other].style.visibility = "visible";
	 } 
	 
	function hideOther(selBox)
	  { 
		 other = selBox + "_other";  
		 //document.forms[1][other].value = ""; 
		 selBoxLength = document.forms[1][selBox].length;
		 document.forms[1][selBox][(selBoxLength - 1)].value = "other"; 
		 if (document.getElementById && !document.all)
			 document.getElementById(other).style.visibility = "hidden"; 
		 else if (document.all) 
		 	document.all[other].style.visibility = "hidden"; 	
	  } 
	  
    function updateSelect(selObj, val)
	  { 
	  	var selBoxLength = document.forms[1][selObj].length; 
	  	document.forms[1][selObj][(selBoxLength -1)].value = val; 
	  }
	  
/************************************************************************
The following fucntions are for clearing out select lists and repopulating them 
if necessary. 
************************************************************************/
function populateList(listVals, listName)
    {
	var opt = new Option
	    opt.value = "-:none:-"; 
		opt.text = "Please choose one..."; 
		document.forms[1][listName].options[0] = opt;
	
	 var opt = new Option
	    opt.value = "-:none:-"; 
		opt.text = "- - - - - - - - - - - - - - - - - - - -"; 
		document.forms[1][listName].options[1] = opt;
		
	
	for (var i = 0; i < listVals.length; i++) 
	  { 
	    var opt = new Option
	    opt.value = listVals[i]; 
		opt.text = listVals[i]; 
		document.forms[1][listName].options[i+2] = opt;
	  } 	 
    } 
	
function noOptions(listName)
   {
   var opt = new Option
	    opt.value = "-:none:-"; 
		opt.text = "No Options"; 
		document.forms[1][listName].options[0] = opt;
   }
	
function clearList(listName) 
  {  
  var opLength = document.forms[1][listName].options.length
  for(var a = 0; a < opLength; a++)
  	 {
	 document.forms[1][listName].options[0] = null;
	 }
  } 
  
  
function confirmSubmit(mesg, submitForm)
  { 
  if (!mesg) 
  	mesg = "You have not completed filling out the detailed request form. \n\n To submit the form with all the information that you have supplied so far click \"OK\" \n To coninue filling out the detailed request form click \"Cancel\" "; 
	
  if (!submitForm) 
  	submitForm = document.forms[1]; 
	
  if (confirm(mesg))
  	submitForm.submit(); 
	
  }
