var panes = new Array();
var tabHelp = new Object();

function setupPanes(containerId) {
  panes[containerId] = new Array();
  var container = $(containerId);
  var paneContainer = $(containerId + 'panes');
  var paneList = paneContainer.getElementsByTagName('div');
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (! pane.className ) continue;
    if (! ( pane.className == 'pane' ||
      pane.className.search("\\bpane\\b") != -1 )) continue;
    if (pane.nodeType != 1) continue;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    container.parentNode.parentNode.style.display="block";
}

// dja: do we still need this for tax fields?
function fixTaxHelp () {
	if (currentHelpVar.substr(0,14) == 'Tax_Group_Help') { sbsiHelpLoad('Tax_Group_Help'); };
	if (currentHelpVar.substr(0,4) == 'STI_') { sbsiHelpLoad('STI'); };
	if (currentHelpVar.substr(0,4) == 'STA_') { sbsiHelpLoad('STA'); };
	if (currentHelpVar.substr(0,7) == 'STACCT_') { sbsiHelpLoad('STACCT'); };
	if (currentHelpVar.substr(0,5) == 'STI2_') { sbsiHelpLoad('STI2'); };
	if (currentHelpVar.substr(0,5) == 'STA2_') { sbsiHelpLoad('STA2'); };
	if (currentHelpVar.substr(0,8) == 'STACCT2_') { sbsiHelpLoad('STACCT2'); };
}

// dja:  obsolete
function setVisibility () {
/* dja:  all of this stuff doesn't work with nuwiz gone
    if ($('SALESTAX').checked) {
        $('taxontext').style.display= "inline";
        $('STACCTREQUIRED').style.display= "block";
        $('STIREQUIRED').style.display= "block";
        $('STAREQUIRED').style.display= "block";
    } else {
        $('taxontext').style.display= "none";
        $('STACCTREQUIRED').style.display= "none";
        $('STIREQUIRED').style.display= "none";
        $('STAREQUIRED').style.display= "none";
    }

    var custoption=$('CUSTOPTION');
    if (custoption.options[custoption.selectedIndex].value=='0') {
        $('CSUFTABLE').style.display= "none";
        $('DUMMYCUSTTABLE').style.display= "none";
        $('CSUFWIZTABLE').style.display= "none";
        $('DUMMYCUSTWIZTABLE').style.display= "none";
        $('custSet0').style.display= "block";
        $('custSet1').style.display= "none";
        $('custSet2').style.display= "none";
    } else if (custoption.options[custoption.selectedIndex].value=='1') {
        $('CSUFTABLE').style.display= "none";
        $('DUMMYCUSTTABLE').style.display= "block";
        $('CSUFWIZTABLE').style.display= "none";
        $('DUMMYCUSTWIZTABLE').style.display= "inline";
        $('custSet0').style.display= "none";
        $('custSet1').style.display= "block";
        $('custSet2').style.display= "none";
    } else if (custoption.options[custoption.selectedIndex].value=='2') {
        $('CSUFTABLE').style.display= "block";
        $('DUMMYCUSTTABLE').style.display= "none";
        $('CSUFWIZTABLE').style.display= "inline";
        $('DUMMYCUSTWIZTABLE').style.display= "none";
        $('custSet0').style.display= "none";
        $('custSet1').style.display= "none";
        $('custSet2').style.display= "block";
    }


    fixTaxHelp();
    var sttype=$('STTYPE');
    if (sttype.options[sttype.selectedIndex].value=='0') {
        $('STACCTTABLE').getElementsByTagName("a")[0].innerHTML='Sales Tax Payable Account Name :&nbsp;';
        $('STACCTWIZTABLE').getElementsByTagName("a")[0].innerHTML='Sales Tax Payable Account Name';
        $('STITABLE').getElementsByTagName("a")[0].innerHTML='Sales Tax Item :&nbsp;';
        $('STIWIZTABLE').getElementsByTagName("a")[0].innerHTML='QuickBooks Sales Tax Item Name';
        $('STATABLE').getElementsByTagName("a")[0].innerHTML='Sales Tax Agency (vendor) :&nbsp;';
        $('STAWIZTABLE').getElementsByTagName("a")[0].innerHTML='Sales Tax Agency Name (vendor)';
        $('STACCT2TABLE').style.display= "none";
        $('STACCT2WIZTABLE').style.display= "none";
        $('STI2TABLE').style.display= "none";
        $('STI2WIZTABLE').style.display= "none";
        $('STA2TABLE').style.display= "none";
        $('STA2WIZTABLE').style.display= "none";
    } else if (sttype.options[sttype.selectedIndex].value=='1') {
        $('STACCTTABLE').getElementsByTagName("a")[0].innerHTML='GST Payable Account Name :&nbsp;';
        $('STACCTWIZTABLE').getElementsByTagName("a")[0].innerHTML='GST Payable Account Name';
        $('STITABLE').getElementsByTagName("a")[0].innerHTML='GST Item :&nbsp;';
        $('STIWIZTABLE').getElementsByTagName("a")[0].innerHTML='GST Item Name';
        $('STATABLE').getElementsByTagName("a")[0].innerHTML='GST Agency (vendor) :&nbsp;';
        $('STAWIZTABLE').getElementsByTagName("a")[0].innerHTML='GST Agency Name (vendor)';
        $('STACCT2TABLE').style.display= "block";
        $('STACCT2WIZTABLE').style.display= "inline";
        $('STI2TABLE').style.display= "block";
        $('STI2WIZTABLE').style.display= "inline";
        $('STA2TABLE').style.display= "block";
        $('STA2WIZTABLE').style.display= "inline";
    } else if (sttype.options[sttype.selectedIndex].value=='2') {
        $('STACCTTABLE').getElementsByTagName("a")[0].innerHTML='VAT Control Account Name :&nbsp;';
        $('STACCTWIZTABLE').getElementsByTagName("a")[0].innerHTML='VAT Control Account Name';
        $('STITABLE').getElementsByTagName("a")[0].innerHTML='VAT Item :&nbsp;';
        $('STIWIZTABLE').getElementsByTagName("a")[0].innerHTML='VAT Item Name';
        $('STATABLE').getElementsByTagName("a")[0].innerHTML='VAT Agency (vendor) :&nbsp;';
        $('STAWIZTABLE').getElementsByTagName("a")[0].innerHTML='VAT Agency Name (vendor)';
        $('STACCT2TABLE').style.display= "none";
        $('STACCT2WIZTABLE').style.display= "none";
        $('STI2TABLE').style.display= "none";
        $('STI2WIZTABLE').style.display= "none";
        $('STA2TABLE').style.display= "none";
        $('STA2WIZTABLE').style.display= "none";
    }

*/

/** dja:  obsolete
    var oscommerce=$('OSCOMMERCE');
    if (oscommerce.value=="") {
        $('OSCOMMERCETABLE').style.display= "none";
    } else {
        $('OSCOMMERCETABLE').style.display= "block";
    }
**/
}

var lastPane;
var currentPane;
function showPane(paneId, showHelp) {
  // hide other panes (siblings)
  // make pane visible
    if (showHelp === undefined) showHelp="yes";
  
    for (var con in panes) {
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = $(paneId);
      pane.style.display = "block";
      lastPane=currentPane;
      currentPane=paneId;
      window.scrollTo(0,140);
      var helpId = tabHelp[paneId];
      if (helpId && showHelp == "yes") sbsiHelpLoad(helpId);
      var container = $(con);
      var tabs = $(container.id + 'tabs');
      var tabList = tabs.getElementsByTagName("a")
      for (var i in panes[con]) {
        var pane2 = panes[con][i];
        if (pane2 == undefined) continue;
        if (pane2.id == paneId) continue;
		var paneIluminada = $(pane2.id);
		if (paneIluminada) paneIluminada.style.display = "none";
      }
      var wizP = /^wiz(.*)$/;
      var result;
      var inputList = pane.getElementsByTagName("input");
      for (var i=0; i<inputList.length; i++ ) {
        var inputEl = inputList[i];
	if ((result = wizP.exec(inputEl.id)) != null) {
           var formField = $(result[1]);
           if (inputEl.type == "hidden" || inputEl.type == "text") {
              inputEl.value = formField.value;
           } else if (inputEl.type == "checkbox") {
              inputEl.checked = formField.checked;
           }
        }
      }
      var selectList = pane.getElementsByTagName("select");
      for (var i=0; i<selectList.length; i++ ) {
        var selectEl = selectList[i];
	if ((result = wizP.exec(selectEl.id)) != null) {
           var formField = $(result[1]);
           selectEl.selectedIndex = formField.selectedIndex;
        }
      }
    }
  }

/** dja: this gives an error since we dropped nuwiz_
  if (paneId.substr(0,6) == 'nuwiz_') {
     $('newbiehelpbox').style.display='inline';
  } else {
     $('newbiehelpbox').style.display='inline';
  }
**/

  return false;    
}


// hide all panes 
function hidePanes(con) {
	var container = $(con);
	if (container.style.display != "none") {
		container.style.display = "none";
	} else {
		container.style.display = "block";
	}
	return false;    
}

<!-- ADDED Form Glue for Forms within Tab Panes

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false


// dja: can we check SHOWHELP here maybe?  this is otherwise totally broken...
function setStartPane() {

	// check that we have finished doing our settings
	generalf = (ns4) ? document.generalPage.document.generalForm : document.generalForm
	taxf = (ns4) ? document.taxPage.document.taxForm : document.taxForm
	salesf = document.salesForm;

	// if we haven't done our settings, show the startHere page
	if ( generalf.PAYPAL.value == "" || generalf.DEFINC.value == "" || generalf.DEFEXP.value == "" ||
		( taxf.SALESTAX.checked == 1 && 
		( taxf.STACCT.value == "" || taxf.STI.value == "" || taxf.STA.value == "" ))
	|| ( salesf.F3.value == '1' && salesf.DEFITEM.value == "" )
	) {
		showPane("startHere", "yes" );
	} 

	// otherwise, check for missing PPTEMPHOLD and do a popup if this isn't setup! 
	else if ( generalf.PPTEMPHOLD.value == "" ) {
		showPane("newsPage", "yes");
	}

	// otherwise, go directly to the process page
	else {
		showPane("expressStep", "yes" );
	}

	// update the help column accordingly
	showUpdates();
}


function basicTabNav(thisTab, backDest, nextDest) {
   var backButton = $("backButton" + thisTab);
   var nextButton = $("nextButton" + thisTab);
   backButton.onclick=function(){ return showPane(backDest);};
   nextButton.onclick=function(){ return showPane(nextDest);};
}

// dja:  this is just so damn ugly - sure wish we could do this a better way,
// collect all sptabs/ forms fields into mainf for posting to kwikpal_process
// check for required fields while we are at it, and prevent the post if something goes wrong
// command names are as follows:
//	settingTab --> ppgetcfg to save our current settings to a file on the users computer
//		the point of this is just to save the settings, and return 1 if everything is OK
//	settingTab --> ppputcfg to load settings from a file on the users computer
//	expressStep --> ppgetiif to call pp2iif to run the thing and return an iif file
//	expressStep --> ppgetlog to call pp2iif and return the log file of what happened (dja: ?) 
//  ?? --> ppgetdef dja: not sure who or what calls this one

var settingsOK;
function sendKPForm( command ) {

	// clear if anything goes wrong
	// dja: note that this is stupid, as we have multiple return points, and don't check it at the end 
	settingsOK=1;

	// dja: factor this out, or better yet make it work through discovery,
	//	so that it just collapses ALL form elements other than mainf into mainf,
	//	or go hunting for each element in mainForm in others to get values?  
	// or just push these sections into each settingPage tab so it's responsible 
	//	for converting into mainf as well as doing any field checks?

	// target form 
	mainf = document.mainForm
	mainf.command.value = command;

	// source forms
	generalf = (ns4) ? document.generalPage.document.generalForm : document.generalForm
	taxf = (ns4) ? document.taxPage.document.taxForm : document.taxForm
	shippingf = (ns4) ? document.shippingPage.document.shippingForm : document.shippingForm
	depositsf = (ns4) ? document.depositsPage.document.depositsForm : document.depositsForm
	salesf = (ns4) ? document.salesPage.document.salesForm : document.salesForm
	otherf = (ns4) ? document.otherPage.document.otherForm : document.otherForm

	// dja: what was this for?  
	// glue data
	// mainf.QBDOC.value = generalf.QBDOC.value

	// general
	mainf.PAYPAL.value = generalf.PAYPAL.value
	mainf.DEFINC.value = generalf.DEFINC.value
	mainf.DEFEXP.value = generalf.DEFEXP.value
	mainf.CURRENCY.value = generalf.CURRENCY.value
	mainf.DATEFMT.value = generalf.DATEFMT.options[generalf.DATEFMT.selectedIndex].value
	mainf.PPFEE.value = generalf.PPFEE.value
	mainf.PPTEMPHOLD.value = generalf.PPTEMPHOLD.value
	
	// taxes
	mainf.STTYPE.value = taxf.STTYPE.options[taxf.STTYPE.selectedIndex].value
	mainf.STACCT.value = taxf.STACCT.value
	mainf.STI.value = taxf.STI.value
	mainf.STA.value = taxf.STA.value
	mainf.STACCT2.value = taxf.STACCT2.value
	mainf.STI2.value = taxf.STI2.value
	mainf.STA2.value = taxf.STA2.value
	mainf.STSHIP.value = (taxf.STSHIP.checked) ? "1" : "0" // Sales Tax on shipping
	mainf.SALESTAX.value = (taxf.SALESTAX.checked) ? "1" : "0" // sales tax
	mainf.NOTAXITEM.value = taxf.NOTAXITEM.value
	
	// shipping
	mainf.POSTAGEIN.value = shippingf.POSTAGEIN.value
	mainf.SHIPITEM.value = shippingf.SHIPITEM.value
	mainf.POSTAGEVENDOR.value = shippingf.POSTAGEVENDOR.value
	mainf.POSTAGE.value = shippingf.POSTAGE.value
	mainf.UPSSHIP.value = (shippingf.UPSSHIP.checked) ? "1" : "0"
	
	// deposits
	mainf.CC1.value = depositsf.CC1.value
	mainf.CCA1.value = depositsf.CCA1.value
	mainf.CC2.value = depositsf.CC2.value
	mainf.CCA2.value = depositsf.CCA2.value
	mainf.CC3.value = depositsf.CC3.value
	mainf.CCA3.value = depositsf.CCA3.value
	mainf.CC4.value = depositsf.CC4.value
	mainf.CCA4.value = depositsf.CCA4.value
	mainf.CCDEFAULT.value = depositsf.CCDEFAULT.value
	mainf.MYBANK.value = depositsf.MYBANK.value
	mainf.PARENT.value = depositsf.PARENT.value
	
	// sales
	mainf.SALESACCT.value = salesf.SALESACCT.value
	mainf.REFACCT.value = salesf.REFACCT.value
	mainf.F3.value = (salesf.F3.checked) ? "1" : "0" 
	mainf.CUSTOPTION.value = salesf.CUSTOPTION.options[salesf.CUSTOPTION.selectedIndex].value
	mainf.CSUF.value = salesf.CSUF.value
	mainf.DUMMYCUST.value = salesf.DUMMYCUST.value
	mainf.F9.value = (salesf.F9.checked) ? "1" : "0" 
	mainf.SRPRINT.value = (salesf.SRPRINT.checked) ? "1" : "0"
	mainf.SRSEND.value = (salesf.SRSEND.checked) ? "1" : "0" 
	mainf.DEFITEM.value = salesf.DEFITEM.value
//	mainf.DEFMODE.value = salesf.DEFMODE.options[salesf.DEFMODE.selectedIndex].value
	mainf.DEFMODE.value = "0";

	// other/misc
	mainf.A5.value = otherf.A5.value
	mainf.PPMM.value = otherf.PPMM.value
	mainf.EBFEE.value = otherf.EBFEE.value
	mainf.A13.value = otherf.A13.value
	mainf.F15.value = (otherf.F15.checked) ? "1" : "0" 
	mainf.CLSEXP.value = otherf.CLSEXP.value
	mainf.F4.value = (otherf.F4.checked) ? "1" : "0" 
	mainf.CLSSHIP.value = otherf.CLSSHIP.value
	mainf.CLSSALE.value = otherf.CLSSALE.value
	mainf.SKIPEBAY.value = (otherf.SKIPEBAY.checked) ? "1" : "0" 


// dja: can we factor out field checks at least to their own function, or better yet - push them
//	back into the expressStep page where this all happens?

	// verify that we have the cya buttons checked
	if ( command == 'ppgetlog' || command == 'ppgetiif' ) {
		if ( ! mainf.back_up_qb.checked && command == 'ppgetiif' ) {
			alert('Your QuickBooks Company File MUST be backed up before importing the SimplePort iif file, please check the checkbox');
			showPane('expressStep');
			settingsOK=0;
			return(false);
		}
		if ( mainf.uploaded_file.value == '') {
			alert("Please select the PayPal export file from your hard disk");
			showPane('expressStep');
			settingsOK=0;
			return(false);
		}
	}


	// check for reasonable BASIC settings
	if ( command == 'ppgetiif' || command == 'ppgetcfg' ) {

		if ( mainf.PAYPAL.value == '' || mainf.DEFINC.value == '' || mainf.DEFEXP.value == ''
			|| mainf.CURRENCY.value == '' || mainf.DATEFMT.value == '' || mainf.PPFEE.value == '' ) {
				alert( "Before you can download SimplePort QB iif files, you must configure your BASIC settings" );
				showPane('startHere', 'yes' );
				settingsOK=0;
				return(false);
		}

		// check for required sales fields
		if ( salesf.F3.value == "1" && salesf.DEFITEM.value == '' ) {
			alert( 'Please configure your sales default item name/number setting.' );
			showPane( 'salesPage', 'yes' );
			settingsOK = 0;
			return( false );		 
		}

		// check for required tax fields
		if ( (mainf.STACCT.value == '' || mainf.STI.value == '' || mainf.STA.value == '')
			&& mainf.SALESTAX.value == 1) {
			alert("With Sales Tax ON in QuickBooks, you need to fill out the settings in the Taxes tab");
			var pat = /Page$/;
			if ( ! pat.test(currentPane) ) {
						settingBack=currentPane;
			}
					showPane('taxPage', 'yes');
			settingsOK=0;
			return(false);
		}

		// check that PPTEMPHOLD is set, and if not - warn them about the new feature
		if ( generalf.PPTEMPHOLD.value == '' ) {
			alert("You must enter a value for the PayPal Temporary Hold Asset Account!" );
			showPane('newsPage');
			settingsOK=0;
			return(false);
		}
	}

	if ( command == 'ppputcfg' ) {
		if (mainf.settings_file.value == '') {
			alert("Please select the settings file from your hard disk");
			settingsOK=0;
			return(false);
		}
		if (! confirm('Are you sure you want to load saved settings?'+"\n"+'Current settings will be lost.')) {
			return(false);
		}
	}

	if (command == 'ppgetdef'){
		if (! confirm('Are you sure you want to load default settings?'+"\n"+'Any un-saved settings will be lost.')) {
			return(false);
		}
	}
	
	return(true);
}


