// the following function tries to run an "onLoad" function, but doesn't complain if there's not one
function tryOnLoad()
{
	try
	{
		onLoad();
	} catch (e)
	{
		// ignore - usually "not defined"
	}
}

function tryOnUnload()
{
	
	try
	{
		onUnload();
	} catch (e)
	{
		// ignore - usually "not defined"
	}
}

function tryOnLoadAndCallGo(admin,accountCoord,CustSvc,loggedIn)
{
	try
	{
	    Go();
	} catch (e)
	{
		// ignore - usually "not defined"
	}
	try
	{
		onLoad();
	} catch (e)
	{
		// ignore - usually "not defined"
	}
}
function tryOnLoadAndCallGo()
{
	try
	{
	    Go();
	} catch (e)
	{
		// ignore - usually "not defined"
	}
	try
	{
		onLoad();
	} catch (e)
	{
		// ignore - usually "not defined"
	}
}
//use the following 2 functions to disable or enable elements
function disableElement()
{    
  for (var i = 0; i < arguments.length; i++)
  {
  	if (arguments[i] != null)
  	{
    	arguments[i].disabled=true;
    	arguments[i].style.backgroundColor="#CCCCCC";
   	}
  }
}

function enableElement()
{
  for (var i = 0; i < arguments.length; i++)
  {
  	if (arguments[i] != null)
  	{
	  arguments[i].disabled=false;
	  arguments[i].style.backgroundColor="#FFFFFF";
	}
  }
}

// the following function clears all the input/textarea/select elements on a form
function clearForm(form)
{
  //clear all text fields
  var textFields = getFormElements(form, "text");
  for (var i = 0; i < textFields.length; i++)
  {
    textFields[i].value = "";
  }

  // clear all textareas
  var textAreaFields = getFormElements(form, "textarea");
  for (var i = 0; i < textAreaFields.length; i++)
  {
    textAreaFields[i].value = "";
  }
  //clear all selected values in select box
  var selectFields = getFormElements(form, "select");
  for (var i = 0; i < selectFields.length; i++)
  {
    selectFields[i].value = "";
    selectFields[i].selectedIndex = -1;
  }
}

function getFormElements(form, elementType)
{
  var elementArray = new Array();
  var numberOfElements = 0;
  var isSelect = elementType == "select"; // select has two types, treated differently
  for (var i = 0; i < form.elements.length; i++)
  {
    if ((!isSelect && form.elements[i].type == elementType) ||
        (isSelect && (form.elements[i].type == "select-one" || form.elements[i].type == "select-multiple")))
    {
      elementArray[numberOfElements++] = form.elements[i];
    }
  }
  return elementArray;
}

function showvars(obj)
{
  var names = "";
  for (var i in obj) names += i + "     ";
  alert(names);
  
} // end of showvars()

    // Routines for expand/collapse.  
	function handMouse()
	{
		document.body.style.cursor="hand";
	}
	function defaultMouse()
	{
		document.body.style.cursor="default";
	}
	imgout=new Image(9,9);
	imgin=new Image(9,9);

	imgout.src="images/icon_expand.gif";
	imgin.src="images/icon_collapse.gif";

	//this switches expand collapse icons
	function filter(imagename,objectsrc){
		if (document.images){
			document.images[imagename].src=eval(objectsrc+".src");
		}
	}
	
	//show OR hide funtion depends on if element is shown or hidden
	function shoh(id) { 
		
		if (document.getElementById) { // DOM3 = IE5, NS6
			if (document.getElementById(id).style.display == "none"){
				document.getElementById(id).style.display = 'block';
				filter(("img"+id),'imgin');			
			} else {
				filter(("img"+id),'imgout');
				document.getElementById(id).style.display = 'none';			
			}	
		} else { 
			if (document.layers) {	
				if (document.id.display == "none"){
					document.id.display = 'block';
					filter(("img"+id),'imgin');
				} else {
					filter(("img"+id),'imgout');	
					document.id.display = 'none';
				}
			} else {
				if (document.all.id.style.visibility == "none"){
					document.all.id.style.display = 'block';
				} else {
					filter(("img"+id),'imgout');
					document.all.id.style.display = 'none';
				}
			}
		}
	}

  //Routines to hide/display a div section
  function HideContent(d) 
  {
	  document.getElementById(d).style.display = "none";
  }
  function ShowContent(d)  
  {
	  document.getElementById(d).style.display = "block";
  }
  function ReverseContentDisplay(d) 
  {
	  if(document.getElementById(d).style.display == "none") 
	  { 
	    document.getElementById(d).style.display = "block"; 
	  }
	  else 
	  { 
	    document.getElementById(d).style.display = "none"; 
	  }
  }      
  function toggleSearch(div, param) //This one uses nested call to shoh
  {
//      alert("Pre:HideSearch["+document.getElementById(param).value+"]");
      shoh(div); // changes the displayStyle between none and block
	  if(document.getElementById(div).style.display == "none") 
	  { 
	    document.getElementById(param).value = 1;
	  }
	  else 
	  { 
	    document.getElementById(param).value =0;
	  }
//      alert("Post:HideSearch["+document.getElementById(param).value+"]");
  }  
  
	//show OR hide funtion depends on if element is shown or hidden
	function shoh_noImg(id) { 
      // change the displayStyle between none and block... shoh w/o img calls
		if (document.getElementById) { // DOM3 = IE5, NS6
			if (document.getElementById(id).style.display == "none"){
				document.getElementById(id).style.display = 'block';				
			} else {
				document.getElementById(id).style.display = 'none';			
			}	
		} else { 
			if (document.layers) {	
				if (document.id.display == "none"){
					document.id.display = 'block';
				} else {
					document.id.display = 'none';
				}
			} else {
				if (document.all.id.style.visibility == "none"){
					document.all.id.style.display = 'block';
				} else {
					document.all.id.style.display = 'none';
				}
			}
		}  
	}
  function toggleServices(div, param) //This one uses nested call to shoh
  {
      shoh_noImg(div); // changes the displayStyle between none and block      
	  if(document.getElementById(div).style.display == "none") 
	  { 
	    document.getElementById(param).value = 1;
	  }
	  else 
	  { 
	    document.getElementById(param).value =0;
	  }
  }  
  
  var popupWin;
  function windowOpener(url, name, args) {
	if (typeof(popupWin) != "object"){
		popupWin = window.open(url,name,args);
	} else {
		if (!popupWin.closed){ 
			popupWin.location.href = url;
		} else {
			popupWin = window.open(url, name,args);
		}
	}
	popupWin.focus();
  }

  function closePopupWin(){
	try
	{
		popupWin.close();
	} catch (e)
	{
		// Do nothing because popupWin has not been opened
	}
  }