// basic javascript functions
// --------------------------


function getObject( obj ) {
	if (typeof(obj) == 'object') {
		return obj;
	} else {
    		var strObj;
    		if ( document.all ) {
   			strObj = document.all.item( obj );
    		} else if ( document.getElementById ) {
    			strObj = document.getElementById( obj );
   		}
    		return strObj;
	}
    }



//function tabMediator(tabIdList, contentArray, contentDivId, highlightFGColor, highlightBGColor, fgColor, bgColor)
function tabMediator(tabIdList, contentArray, contentDivId, oldClass, newClass) {
  this.list = tabIdList;
  this.contentArray = contentArray;
  this.contentDivId = contentDivId; 
  this.oldClass = oldClass;
  this.newClass = newClass;

  this.setTab = function(tabId) {
    for(var i=0; i< this.list.length; i++){
      var obj = getObject(this.list[i]);
      if (obj) {
        if (this.list[i] == tabId) {
	  addAttribute("class", this.newClass, this.list[i]);
	  //obj.style.backgroundColor = this.highlightBGColor;
	  //obj.style.color = this.highlightFGColor;
          var contentDiv = getObject(contentDivId);
	  if (contentDiv) {
	    contentDiv.innerHTML = contentArray[i];
	  }
        } else {
	  addAttribute("class", this.oldClass, this.list[i]);
	  //obj.style.backgroundColor = this.bgColor;
	  //obj.style.color = this.fgColor;
        }
      }
    }
  }
}




function addAttribute(name, value, id) {
    var attr = document.createAttribute(name);
    attr.nodeValue = value;
    var obj = getObject(id);
    if (obj) {
	obj.setAttributeNode(attr);
    }
}

/* Validates the field and shows the alerttxt if empty */
function validate_required(field,alerttxt)
{
field = getObject(field);
// for radio buttons and check boxes
if (field.length > 1) {
  if (valButton(field) == null) {
  	alert(alerttxt);return false;
  } else {
	return true;
  }
}

// for text fields
with (field)
{
if (value==null||value=="") {
  alert(alerttxt);return false;
}
else {return true}
}
}

function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

/* validates an array of checkboxes for minimal one selection */
function minimal_one_selection(obj,alerttxt) {
  for(var i=0; i< obj.length; i++){
	if (obj[i].checked===true) {
		return true;
	}
  }
  alert(alerttxt);return false;
}

