/*
Usefull JavaScript functions taken from the Node7 project
*/

var img_path = "./images/";
var img_swap_ary = new Array();
img_swap_ary["forw.gif"]="back1.gif";
img_swap_ary["back1.gif"]="forw.gif";
img_swap_ary["up.gif"]="down.gif";
img_swap_ary["down.gif"]="up.gif";
img_swap_ary["tip.gif"]="tip_on.gif";
img_swap_ary["tip_on.gif"]="tip.gif";

var tip_ary = new Array();
tip_ary[0] = 'tip1';
tip_ary[1] = 'tip2';
tip_ary[2] = 'tip3';

function get_obj(id)
{
	var obj = "";

  // Check browser compatibility
  if(document.getElementById)
  	obj = document.getElementById(id);
  else if(document.all)
  	obj = document.all[id];
  else if(document.layers)
  	obj = document.layers[id];
  else
  	return 1;
  return obj;
}

function swap_image(id, img)
{
	var obj = get_obj(id);
	
	if(!obj || obj == 1){
		return 1;	
	}
	else if (obj.src){
		var image_str = obj.src;
		var image_path = image_str.substring(0,image_str.lastIndexOf("/") + 1);
		image_str = image_str.substring(image_str.lastIndexOf("/") + 1);
		//alert(image_str + " " + image_path);
		obj.src = image_path + img_swap_ary[image_str];
	}
}

function show_hide(id) {
	var obj = "";

  // Check browser compatibility
  if(document.getElementById)
  	obj = document.getElementById(id);
  else if(document.all)
  	obj = document.all[id];
  else if(document.layers)
  	obj = document.layers[id];
  else
  	return 1;

	if (!obj) {
  	return 1;
  }
  else if (obj.style)
  {
  	obj.style.display = ( obj.style.display != "none" ) ? "none" : "";
  }
  else
  {
  	obj.visibility = "show";
  }
}

//
// Show/Hide a set of predefined id-blocks displaying Tip/Help information
function showTip() {

	for (var i=0; i<tip_ary.length; i++) {
		show_hide(tip_ary[i]);
	}
	// return false?
	// can we put showTip in an onClick event
	// and use the return value to activate a static link/url if the browser doesn't support javascript? 
	return false;
}

//
// Clear Form elements
function clearForm(form){
	for(i=0; i<form.elements.length; i++)
	{
		with(form.elements[i]){
			if(type=='text' || type=='textarea' || type=='password'){
				value='';			
			}			
			checked = false;		
		}
	}
}

//
// Move text - move value from one field to another
function move_text(from, to)
{
	var field1 = get_obj(from);
	var field2 = get_obj(to);
	
	field2.value = field1.value;
	field1.value = '';
}
