
function toggle(imgName,state) {

	var img = findImage(imgName);

	if(img != null) {
		var src = img.src;
		src = src.replace("_off.gif","").replace("_on.gif","");
		img.src = src + "_" + state + ".gif";
	} 

}


function toggleBreadcrumb(bcName,state) {

	var img = findImage("bc_image_" + bcName);

	if(img != null) {
		var src = img.src;
		src = src.replace("_off.gif","").replace("_on.gif","");
		img.src = src + "_" + state + ".gif";
	}

	var link = findObject("bc_link_" + bcName);

	if(link != null) {
	    link.className = "breadcrumb_" + state;
	}

}

function swapImage(imgName,src) {

	var img = findImage(imgName);

	if(img != null) {
		img.src = src;
	}
}


function swapClassname(objId,className) {

	var obj = findObject(objId);

	if(obj != null) {
		obj.className = className;
	}
}


function preloadImages(arrImageNames) {

	if(typeof arrImageNames == 'undefined' || !arrImageNames) {
		return;
	}


	var arrPreloadImages = new Array();

	for(var i = 0;i<arrImageNames.length;i++) {

		var img = new Image();
		img.src =  arrImageNames[i];
		arrPreloadImages[arrPreloadImages.length] = img;

	}

}


function preloadNavImages(arrImageNames) {

	if(typeof arrImageNames == 'undefined' || !arrImageNames) {
		return;
	}


	var arrPreloadImages = new Array();

	for(var i = 0;i<arrImageNames.length;i++) {
		var img = new Image();
		//img.onerror = function errAlert(){alert('cannot load ' + this.src);};
		img.src = arrImageNames[i] + "_on.gif";
		arrPreloadImages[arrPreloadImages.length] = img;

		var img2 = new Image();
		//img2.onerror = function errAlert(){alert('cannot load ' + this.src);};
		img2.src = arrImageNames[i] + "_off.gif";
		arrPreloadImages[arrPreloadImages.length] = img2;
	}

}


function findImage(strName) {

	var img = null;

	if(img == null && document.images) {
		img = document.images[strName];
	}

	if(img == null && document.all) {
		img = document.all[strName];
	}

	if(img == null && document.getElementById) {
		img = document.getElementById(strName);
	}


	return img;
}


function findObject(strId) {

	var obj = null;

	if(obj == null && document.all) {
		obj = document.all[strId];
	}

	if(obj == null && document.getElementById) {
		obj = document.getElementById(strId);
	}


	return obj;
}

function launchHelp(helpKeyName) {
	var myWin = window.open('admin?action=help&helpKeyName='+helpKeyName,'help','top=0,left=0,width=300,height=150,scrollbars=yes,scrolling=yes,toolbars=no,status=no');

	myWin.focus();
}

function launchWindow(strUrl,winName,features) {
    var myWin = window.open(strUrl,winName,features);
    myWin.focus();
}

function flashSCMSVideoPlayer(strVideoUrl) {
	var myWin = window.open('videoPopup?video=' + strVideoUrl,'vidwin','top=30,left=30,width=375,height=375,scrollbars=yes,scrolling=yes,toolbars=no,status=no');
	myWin.focus();
}

function DisableFormElements(ptrForm, strClass) {
   /* 
   DisableFormElements: Visibly disable elements in a form.
   ptrForm:  The form object containing the elements to disable
   strClass:  The stylesheet class for the items to disable
   
   This function disables all form elements in form ptrForm with
   class strClass.
   
   This function is both a convenience function and makes up for 
   the fact that Internet Explorer does not visually "grey out" 
   all form elements when they are disabled.
   */
   
  // Make sure the form has elements
  if (ptrForm.length) {
    
    // Run through the form.  If an item has the
    // class ptrClass, disable it.
    for (i = 0; i < ptrForm.length; i++) {
      if (ptrForm[i].className == strClass) {
        ptrForm[i].disabled=true;
        strType = ptrForm[i].type;
        
        // Next, change the visual style so that the items are
        // visible as disabled.  Not necessary for checkboxes
        // and radio buttons.
        if ((strType != "checkbox") && (strType != "radio")) {
          ptrForm[i].style.backgroundColor="#D4D0C8";
        }
      }
    }
  }
}


function EnableFormElements(ptrForm, strClass) {
  /*
  EnableFormElements:  Visibly re-enable elements in a form.
  ptrForm:  The form object containing the form elements to enable
  strClass:  The stylesheet class for the items to enable.
  
  This function enables all form elements in form ptrForm with
  class strClass.
  
  This function is both a convenience function and makes up for the
  fact that Internet Explorer does not visually restore all greyed
  out form elements when they are re-enabled.
  */
    
  // Make sure the form has elements
  if (ptrForm.length) {
 
    // Run through the form.  If an item has the
    // class ptrClass, enable it.
    for (i = 0; i < ptrForm.length; i++) {
      if (ptrForm[i].className == strClass) {
        strType = ptrForm[i].type;
        ptrForm[i].disabled=false;
 
        // Next, change the visual style so that the items are
        // visible as enabled.  Not necessary for checkboxes
        // and radio buttons.
        if ((strType != "checkbox") && (strType != "radio")) {
          ptrForm[i].style.backgroundColor="#ffffff";
        }
      }
    }
  }
}

function GreyLabels(strClass) {
  /*
  GreyLabels:  Grey the labels of form fields that have been disabled.
  Provides visual feedback that the form fields are not available.
  strClass:  The class of the labels to grey out.
  
  Limitations: only checks span tags.
  */
  
  var ptrSpans = document.getElementsByTagName("span");
  for (i = 0; i < ptrSpans.length; i++) {
    if (ptrSpans[i].className == strClass) {
      ptrSpans[i].style.color = "#999999";
      var ptrHrefs = ptrSpans[i].getElementsByTagName("a");
      if (ptrHrefs.length > 0) {
        for (j = 0; j < ptrHrefs.length; j++) {
          if (!ptrHrefs[j].style.color) {
            ptrHrefs[j].className = "href_rowColor1_disabled";
          }
        }
      }
    }
  }
}

function BlackLabels(strClass) {
  /*
  BlackLabels:  Black the labels of form fields that have been enabled.
  Provides visual feedback that the form fields are available.
  strClass:  The class of the labels to change.
  
  Limitations: only checks span tags.
  */
  
  var ptrSpans = document.getElementsByTagName("span");
  for (i = 0; i < ptrSpans.length; i++) {
    if (ptrSpans[i].className == strClass) {
      ptrSpans[i].style.color = "#666666";
      var ptrHrefs = ptrSpans[i].getElementsByTagName("a");
      if (ptrHrefs.length > 0) {
        for (j = 0; j < ptrHrefs.length; j++) {
          if (!ptrHrefs[j].style.color) {
            ptrHrefs[j].className = "href_rowColor1";
          }
        }
      }
    }
  }
}

function ChangeTextColor(strClass, strTextColor, strHrefClass) {
  /*
  ChangeLabelColor: Change the color of text. Also changes
    the color of any a links within the text.
  strClass:  The stylesheet class of the text to change.
  strTextColor: the hex color to change the text color to.
    Leave blank to not change text.
  strHrefClass: the stylesheet class to change any a links to.
    Leave blank to not change links.
  
  Limitations:  Only checks the classes of span tags.
  */
  
  // Get the spans in the document.
  var ptrSpans = document.getElementsByTagName("span");

  // Go through them and find the ones that have the correct class.
  for (i = 0; i < ptrSpans.length; i++) {
    if (ptrSpans[i].className == strClass) {
    
      // Change text color if strTextColor is not null
      if (strTextColor.length > 0) {
        ptrSpans[i].style.color = strTextColor;      
      }
      
      // If strHrefClass is not null, we need to change the
      // color of all contained a tags.  So start by
      // geting all a tags in the current span
      if (strHrefClass.length > 0) {
        var ptrHrefs = ptrSpans[i].getElementsByTagName("a");
        
        // If there are any a tags, go through them and change 
        // their color.
        if (ptrHrefs.length > 0) {
          for (j = 0; j < ptrHrefs.length; j++) {
            ptrHrefs[j].style.color = strHrefClass;
          }
        }
      }
    }
  }
}