// 
// DESC: write content html into the elements
// content - string - is the HTML you want to write
// elementIdList - string - comma delimited list of element IDs
//
function writeInnerHTML(content, elemIdList) {
    var idList = elemIdList.split(',');
	  for(i = 0; i < idList.length; i++) {
	      var elem = document.getElementById(idList[i]);
	      if (elem != null)
	          elem.innerHTML = content.replace(/^\s+|\s+$/, '');
	  }
}

// TabPages - manages tabbed divs
//
// (by manipulating the display property usually of divs, requires
// (all the tabs/divs to be inside a larger outside container
// (start by defining a TabPages element like so
//    var myTabs = new TabPages('pagedContentContainer1');
// (then add tabs to it likd so
//    myTabs.addTab("tab01");
//    myTabs.addTab("tab00");
// (then show the first (zero-eth) tab like so
//    myTabs.showTab("cont00")
// (assumptions:
// (   tabs are held in an array from 0 - number of
// (   tab/div ids should not start with numbers (keep the form cont4)
// (ideally the containers will not be displayed to start with and
// (the showTab("cont00") will show the first tab.
//
//
function TabPages(tabsContainerDiv) {
    //
    // private variables
    //
    var tabs = new Array();
    var tabCurrent = 0;
    var tabContainer = document.getElementById(tabsContainerDiv);
    var callbackFunc   = null; // callback function to call on tab change

    this.addTab = function(contId) {
        tabs[tabs.length] = contId;
    }
    this.getTabsSize = function() {
        return tabs.length;
    }
    this.getNextTotal = function(total,ipp) {
      if (this.getCurrentTabNumber() < (this.getTabsSize()-1)) {
        return ipp;
      } else {
        lastpage = total % (this.getTabsSize()-1);
        return lastpage;
      }
    }
    this.getCurrentIndex = function() {
    	  return tabCurrent;
    }
    this.getCurrentTabNumber = function () {
    	  return tabCurrent + 1;
    }
    this.getTabs = function() {
    	  return tabs;
    }
    this.setCallback = function(funcName) {
    	  this.callbackFunc = funcName;
    }
    this.goToNext = function() {
        tabCurrent++;
        if ( tabCurrent >= tabs.length ) tabCurrent = tabs.length - 1;
        if ( tabCurrent <= 0           ) tabCurrent = 0;
        this.showTab(tabs[tabCurrent]);
    };
    this.goToPrevious = function() {
        tabCurrent--;
        if ( tabCurrent >= tabs.length ) tabCurrent = tabs.length - 1;
        if ( tabCurrent <= 0           ) tabCurrent = 0;
        this.showTab(tabs[tabCurrent]);
    };
    this.goToFirst = function() {
        tabCurrent = 0;
        this.showTab(tabs[tabCurrent]);
    };
    this.goToLast = function () {
        tabCurrent = tabs.length - 1;
        this.showTab(tabs[tabCurrent]);
    };
    this.showTab = function(idNumber) {
        // check if array of tabs has been set up
        if ( (tabs == null) || (tabs.length == 0) )
            alert("Tabs is null (or zero lenth), nothing to show, config error");

        aTab = null;
        for (i = 0; i < tabs.length; i++) {
            aTab = document.getElementById(tabs[i]);
            if ( (tabs[i] == idNumber) || (i == idNumber) ) {
                tabCurrent = i;
                aTab.style.display = 'block';
            } else {
                aTab.style.display = 'none';
            }
        }
        if (this.callbackFunc != null) eval (this.callbackFunc);
        return false;
    };
    this.getNavigation = function() {
        var out = "";
        out += "<a href=\"#\" onclick=\"myTabs.goToPrevious();\">&lt; previous</a> | ";
        for(i = 0; i < tabs.length; i++) {
        	  var tabNo = i + 1;
        	  if (i == this.getCurrentIndex())
        	     out += "<b>" + tabNo + "</b> | ";
        	  else
               out += "<a href=\"#\" onclick=\"myTabs.showTab('cont" + i + "');\">" + tabNo + "</a> | ";
        }
        out += "<a href=\"#\" onclick=\"myTabs.goToNext();\">next &gt;</a>";
        return out;
    }
    this.toString = function() {
        return "TabPages with " + tabs.length + " panes";
    };
}


function newWin(n,wn,w,h,t,l,s) { new_window=window.open(n, wn, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+s+',resizable=0,width='+w+',height=' + h + ((t)?',screenX='+t+',top='+t:'') + ((l)?',screenY='+l+',left='+l:'')); if (new_window.opener==null) { new_window.opener=self; } if (window.focus) new_window.focus(); }
