/********************************************************************/
/* common.js - Common functions used throughout the web application */
/********************************************************************/

/* Preloads images for a page.  All parameters will be treated
 * as the src path of an image to preload.
 */
var loadedImages=new Array();
function preloadImages(){
	var i;
	for(i=0;i<arguments.length;i++){
		loadedImages[i]=new Image();
		loadedImages[i].src=arguments[i];
	}
}

/*
 * A better preload function.
 */
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}
/*
 * Swap image src
 */
function changeImage(imgName,imgObj) {
	if (document.images) {
		document.images[imgName].src = eval(imgObj+".src")
	}
}


/* Cross browser function to find the page element identified by id.
 */
function getElemRefs(id){
	// W3C DOM: getElementById
	// MSIE 4 DOM: document.all
	// NN 4 DOM: document.layers
	return (document.getElementById) ? window.document.getElementById(id) : 
				   (document.all) ? window.document.all[id] : 
				   	 (document.layers) ? nav4findLayer(document,id) :	
				   	   null;
}


/* Cross-browser function to write content (including HTML) 
 * to the area on the page identified by id.
 */
function writeContent(id,content){
	var elem=getElemRefs(id);  //get layer
	if(elem!=null){
		if (document.layers){
			 elem.document.open();
			 elem.document.write(content); //write content to layer
			 elem.document.close();
		}else{
			elem.innerHTML=content; //write content to layer
		}
		return true;
	}
	return false;
}

/* Submits the form identified by id.  Optional parameters:
 * page: the page to set on the form
 * action: the action to set on the form
 */
function submitForm(id){
	var frm=getElemRefs(id);
	if (arguments.length>=2) frm.page.value=arguments[1];
	if (arguments.length>=3) frm.action.value=arguments[2];
	frm.submit();
}

/* Cross browser function to find the style of the object identified by id.
 */
function getStyleObject(objectId){
  if(document.getElementById && document.getElementById(objectId)){
	  return document.getElementById(objectId).style;
  }else if(document.all && document.all(objectId)){
    return document.all(objectId).style;
  }else if(document.layers && document.layers[objectId]){
		return document.layers[objectId];
  }else{
		return false;
  }
}

function omo(obj, color) {
 obj.style.backgroundColor = color;
}

// Open window 
function openWindow(newURL, newName) { 
    window.open(newURL, "", "width=400, height=400, location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no"); 
} 
/* Finds the style of the object identified by id and changes the
 * its visibility if possible.  
 * Returns true when successful, false otherwiwse.
 */
function changeObjectVisibility(id, newVisibility){
	// get a reference to the cross-browser style object
  var styleObject = getStyleObject(id);
  if(styleObject){// make sure the object exists
		styleObject.visibility = newVisibility;
		return true;
  }else{// object does not exist
		return false;
  }
}
function showHidden(id){
	// get a reference to the cross-browser style object
  var styleObject = getStyleObject(id);
  if(styleObject){// make sure the object exists
		styleObject.visibility = 'visible';
		styleObject.display = 'block';
		return true;
  }else{// object does not exist
		return false;
  }
}

function hideVisible(id){
	// get a reference to the cross-browser style object
  var styleObject = getStyleObject(id);
  if(styleObject){// make sure the object exists
		styleObject.visibility = 'hidden';
		styleObject.display = 'none';
		return true;
  }else{// object does not exist
		return false;
  }
}

function disableButton(frm, buttonId, txt) {
	frm.elements[buttonId].value = txt;
	frm.elements[buttonId].disabled = true;
}

// nav4findLayer was taken from
/*
 * xbDOM.js
 * $Revision: 1.5 $ $Date: 2004/09/29 23:26:49 $
 */

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Netscape code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2001
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Bob Clary <bclary@netscape.com>
 *
 * ***** END LICENSE BLOCK ***** */
function nav4findLayer(doc, id){
	var i;
  var subdoc;
  var obj;
  for(i=0;i<doc.layers.length;++i){
  	if (doc.layers[i].id && id == doc.layers[i].id) return doc.layers[i];
    subdoc=doc.layers[i].document;
    obj=nav4FindLayer(subdoc,id);
    if (obj != null)return obj;
  }
  return null;
}

