/*
 * Name:    fnHideShow                                           
 * Purpose: Toggles the display of a tabular detail block of the 
 *         currently displayed page.                            
 *                                                              
 * Input Parameter  Type    Reqd    Description                  
 * --------------------------------------------------------------
 * itemStr          string  Y       ID Property of event image   
 *                                                              
 * Returns: n/a                                                  
 * Calls:   nil                                                  
 *                                                              
 * Ver  Date        Author          Description                  
 * --------------------------------------------------------------
 * 1.0  11/6/02     G.Oborn         Function created             
 */                                                              




 function fnHideShow(itemStr) {
   var urlStr    = new String;
   var domainStr = new String;
   var objItem = document.getElementById( "obj" + itemStr );
 
// XXX - try and get it work in Netscape
   // if (document.layers) {//netscape
   //   return;
   // }
   
   // alert("itemStr = '" + itemStr + "'");

   // If item id currently hidden then show it, otherwise hide it
   if (objItem.style.display == "none") {
     objItem.style.display = "block";
   } else {
     objItem.style.display = "none";
   }

   // If image type is 'closed' then change it to 'open' (or vice versa)
   // urlStr = document.all("img" + itemStr).src;
   urlStr = document.getElementById( "img" + itemStr ).src;
   if (urlStr.indexOf("closed.gif") != -1) {
     domainStr = urlStr.slice(0, urlStr.indexOf("closed.gif"));
     document.all("img" + itemStr).src = domainStr + "open.gif";
   } else {
     domainStr = urlStr.slice(0, urlStr.indexOf("open.gif"));
     document.all("img" + itemStr).src = domainStr + "closed.gif";
   }
 }

/*
 * Name:    transferOptions
 * Purpose: moves option from source SELECT list to destination SELECT list
 *                                                              
 */                                                              
	function transferOptions (lbxSource, lbxDestination) {
		var newElement = document.createElement("OPTION");
		while (lbxSource.options.selectedIndex > 0) {
			newElement.text = lbxSource.options[lbxSource.options.selectedIndex].text;
			newElement.value = lbxSource.options[lbxSource.options.selectedIndex].value;
			lbxDestination.options.add(newElement);
			lbxSource.options.remove(lbxSource.options.selectedIndex);
			var newElement = document.createElement("OPTION");
		}
	}

/* ******************************************************************** */

/*
 * Name:    selectAll
 * Purpose: mark all OPTIONS's in a SELECT list as selected (except
 *          those with a value of 0, ie. the headings)
 *                                                              
 */                                                              
function selectAll(selObj)
{
   var i = 0;
   for (i = 0; i < selObj.length; i++) {
      // alert("The value is '" + selObj.options[i].value + "'");
			if (selObj.options[i].value != "0") {
				selObj.options[i].selected = true;
			}
	}
}

/* ******************************************************************** */
/* ******************************************************************** */
/*
 *      JavaScript for internal site.
 */
/* ******************************************************************** */
 /* ******************************************************************** */                                                          
  function moveSelectedOptions (fromListBox, toListBox) {
    while (fromListBox.options.selectedIndex > -1) {

	// Do not move options with a value of 0
	var fromVal = fromListBox.options[fromListBox.options.selectedIndex].value;
	if (fromVal == 0) {
	fromListBox.options[fromListBox.options.selectedIndex].selected = false;
	} else {
      var newOption = new Option();
      newOption.value = fromListBox.options[fromListBox.options.selectedIndex].value;
      newOption.text = fromListBox.options[fromListBox.options.selectedIndex].text;
      newOption.selected = true;
      toListBox.options[toListBox.options.length] = newOption;
      // Does not work in IE
      fromListBox.options.remove(fromListBox.options.selectedIndex);
	}
    }
  }


  function moveOptionUp(theListBox) {
    for(var i = 0; i < theListBox.options.length; i++) {
      if (theListBox.options[i].selected && 
          theListBox.options[i] != "" && 
          theListBox.options[i] != theListBox.options[0]) {
	var tmpval = theListBox.options[i].value;
	var tmpval2 = theListBox.options[i].text;
	theListBox.options[i].value = theListBox.options[i - 1].value;
	theListBox.options[i].text = theListBox.options[i - 1].text
	theListBox.options[i-1].value = tmpval;
	theListBox.options[i-1].text = tmpval2;
	theListBox.options[i-1].selected = true;
      }
    }
  }


  function moveOptionDown(theListBox) {
    for(var i = 0; i < theListBox.options.length; i++) {
      if (theListBox.options[i].selected && 
          theListBox.options[i] != "" && 
          theListBox.options[i+1] != theListBox.options[theListBox.options.length]) {
	var tmpval = theListBox.options[i].value;
	var tmpval2 = theListBox.options[i].text;
	theListBox.options[i].value = theListBox.options[i+1].value;
	theListBox.options[i].text = theListBox.options[i+1].text
	theListBox.options[i+1].value = tmpval;
	theListBox.options[i+1].text = tmpval2;
	theListBox.options[i+1].selected = true;
      }
    }
  }


  function removeSelectedOptions (theListBox) {
    while (theListBox.options.selectedIndex > 0) { 
      theListBox.options.remove(theListBox.options.selectedIndex);
    } 
  }


  // NOT USED
  function removeAllOptions (theListBox) {
    i = theListBox.options.length - 1;
    while (theListBox.options.length > 1) { 
      theListBox.options.remove(i);
      i = i - 1;  
    }
  }


  function selectAllOptions (theListBox) {
    if (theListBox.options.length < 2) {
      var newElem = window.document.createElement("OPTION"); 
      newElem.value = "0"; 
      newElem.text = "NULL";  
      theListBox.options.add(newElem);
    }
    for (i=0;i < theListBox.options.length;i++) {
      theListBox.options[i].selected = true;
      //theListBox.options[i].selected=true;    
      //theListBox.options[0].value = theListBox.options[0].value + ',' + theListBox.options[i].value;
      //alert (theListBox.options[0].value);
      }
      //alert (theListBox.options[0].value = theListBox.options[0].value.slice(1,theListBox.options[0].value.length)); 
    //theListBox.options[0].selected = true;
  }


  function moveCategoryLeft (theListBox) {
    alert('Moving Category Left');
  }


  function moveCategoryRight (theListBox) {
    strSpacer = '    ';
    var strPrevVal = theListBox.options[theListBox.options.selectedIndex - 1].text;
    var strCurrentVal = theListBox.options[theListBox.options.selectedIndex].text;
    alert (strCurrentVal);
    //alert (strCurrentVal.lastIndexOf(strSpacer));
    intPrevValIdx = -1;
    intCurrValIdx = -1;
    while (strCurrentVal.lastIndexOf(strSpacer, intCurrValIdx) > -1) {
      intCurrValIdx = strCurrentVal.lastIndexOf(strSpacer, intCurrValIdx);
    }
    alert (intCurrValIdx);  
    if (strCurrentVal.lastIndexOf(strSpacer) < strPrevVal.lastIndexOf(strSpacer) + 3) {
      theListBox.options[theListBox.options.selectedIndex].text = strSpacer + strCurrentVal;
    }
  } 


  function moveCategoryUp (theListBox) {
    alert('Moving Category Up');
  } 
  
  function moveCategoryDown (theListBox) {
    alert('Moving Category Down');
  }

function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}


	


	
function moveUp(obj) {
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

function moveDown(obj) {
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}
   
