// JavaScript Document
function gotoPageAndSelectCol(module, section, tableName, colIndex, highlightColor) {  
  gotoPageEx(module, section, subpages[module]);
  highlightTabColumn(tableName, colIndex, highlightColor);
}

function showAllTableRows(tableName) {
  var tab = document.getElementById(tableName);
  for(var i = 0; i < tab.rows.length; i++) {
	  tab.rows[i].style.display = "table-row";
  }
}

function showHideDiv(divName) {
  var div = document.getElementById(divName);
  if (div.style.display != "block") {
    div.style.display = "block";
  } 
  else
  {
    div.style.display = "none";
  }  
}

function highlightTabColumn(tableName, colIndex, highlightColor) {
  var tab = document.getElementById(tableName);
  for(var rowNum = 0; rowNum < tab.rows.length; rowNum++) {
	  var curRow = tab.rows[rowNum];
    var absColIndex = -1;
    var previousAbsColIndex = -1;
    for(var colNum = 0; colNum < curRow.cells.length; colNum++) {
      previousAbsColIndex = absColIndex;
      var col = curRow.cells[colNum];
      absColIndex += col.colSpan;
      var active = (colIndex == absColIndex) || ((previousAbsColIndex < colIndex) && (absColIndex > colIndex));
      col.style.backgroundColor = (active ? highlightColor : '');
    }
  }
}

function postForm(formName) {
  var frm = document.getElementById(formName);
  frm.submit();
}	

var subpages = Array();

function gotoPageSection(module, submodule) {
  switch(module) {
    case 'hosting': switch (submodule) {
                      case '#basic': gotoPageAndSelectCol('hosting', 'basic', 'compareVersions', 1, '#e8fac3'); break;
                      case '#standard': gotoPageAndSelectCol('hosting', 'standard', 'compareVersions', 2, '#e8fac3'); break;
                      case '#professional': gotoPageAndSelectCol('hosting', 'professional', 'compareVersions', 3, '#e8fac3'); break;
                      case '#enterprise': gotoPageAndSelectCol('hosting', 'enterprise', 'compareVersions', 4, '#e8fac3'); break;
                      case '#cluster': gotoPageAndSelectCol('hosting', 'cluster', 'compareVersions', 5, '#e8fac3'); break;
                      default: gotoPageAndSelectCol('hosting', 'overview', 'compareVersions');
                    };
                   break;
  case 'installer': switch (submodule) {
                      case '#free': gotoPageAndSelectCol('installer', 'free', 'compareVersions', 1, '#e8fac3'); break;
                      case '#lite': gotoPageAndSelectCol('installer', 'lite', 'compareVersions', 2, '#e8fac3'); break;
                      case '#gold': gotoPageAndSelectCol('installer', 'gold', 'compareVersions', 3, '#e8fac3'); break;
                      case '#buy': gotoPageAndSelectCol('installer', 'buy', 'compareVersions'); break;
                      case '#premium': gotoPageAndSelectCol('installer', 'premium', 'compareVersions', 4, '#e8fac3'); break;
                      default: gotoPageAndSelectCol('installer', 'intro', 'compareVersions');
                   }
                   break;
    case 'outsourcing': switch (submodule) {
                        case '': gotoPageEx('outsourcing', 'intro', subpages['outsourcing']); break;
                        case '#': gotoPageEx('outsourcing', 'intro', subpages['outsourcing']); break;
                        case '#api': gotoPageEx('outsourcing', 'free', subpages['outsourcing']); break;				  
                        case '#custom': gotoPageEx('outsourcing', 'all', subpages['outsourcing']); break;
                        case '#cobranca': gotoPageEx('outsourcing', 'paypal', subpages['outsourcing']); break;//Legado
                        case '#cobranca3d': gotoPageEx('outsourcing', 'paypal', subpages['outsourcing']); break;//Legado					  
                        default: gotoPageEx('outsourcing', submodule.substring(1, 50), subpages['outsourcing']);
                    }
                    break;
					
    case 'systems': switch (submodule) {
                        case '': gotoPageEx('systems', 'intro', subpages['systems']); break;
                        case '': gotoPageEx('systems', 'contabilidade1', subpages['systems']); break;
                        case '': gotoPageEx('systems', 'nfse1', subpages['systems']); break;
			case '': gotoPageEx('systems', 'nfe1', subpages['systems']); break;						
                        default: gotoPageEx('systems', submodule.substring(1, 50), subpages['systems']);
                    }
                    break;					
									
	case 'cluster': switch (submodule) {
                       case '': gotoPageEx('cluster', 'overview', subpages['cluster']); break;
                       case '#': gotoPageEx('cluster', 'overview', subpages['cluster']); break;
                       case '#cluster1': gotoPageEx('cluster', 'cluster1', subpages['cluster']); break;				  
                       case '#cluster2': gotoPageEx('cluster', 'cluster2', subpages['cluster']); break;
                       case '#cluster3': gotoPageEx('cluster', 'cluster3', subpages['cluster']); break;
                       default: gotoPageEx('outsourcing', submodule.substring(1, 50), subpages['cluster']);
                    }
                    break;
   case 'support': switch (submodule) {
		                  case '#contacts': gotoPageEx('support', 'contacts', subpages['support']); break;
                      case '#faq': gotoPageEx('support', 'faq', subpages['support']); break;    		   
                      case '#docs': gotoPageEx('support', 'docs', subpages['support']); break;    
                      default: gotoPageEx('support', 'contacts', subpages['support']);
				   }
                   break;	  
	  case 'docs': break;
  }
}

function gotoPageEx(module, secName, secList) {
  _gaq.push(['_trackEvent', module, secName]);

  for(var i = 0; i <= secList.length; i++) {
    var currSection = secList[i];
    var div = document.getElementById("pageContent_" + currSection);
    var menuitem = document.getElementById("menuitem_" + currSection);
    if(div && menuitem) {
      div.style.display = "none";
      menuitem.className = "normalItem";
      
      if(currSection == secName) {
        div.style.display = "block";
        menuitem.className = "selected";
      }
    }
  }  
}
