/* Copyright 2005 Camptocamp SA. 
   Licensed under the GPL (www.gnu.org/copyleft/gpl.html) */

function setupFolders() {
 var myfolders = xGetElementsByClassName('folder', null, null);
  var myform = document.forms['carto_form']
  var folder_idx = myform.js_folder_idx.value;
  ontop(folder_idx);
  var container = xGetElementById('container');
  container.style.display="block";
}

function setupFolders_pop() {

  var myfolders_pop = xGetElementsByClassName('popfol', null, null);
  var myform_pop = document.forms['carto_form']
   var folderpop_idx = myform_pop.js_folderpop_idx.value;
  
  
}


function ontop(id) {
 var myfolders = xGetElementsByClassName('folder', null, null);
  for (i = 0; i < myfolders.length; i++) {
    currentFolder = myfolders[i];
    current = currentFolder.id.substring(6);
    currentLabel = xGetElementById('label' + current);
    if (current == id) {
   
    	
     if (setupFoldersInit == false)
     	{
     		Effect.toggle(currentFolder.id,'Appear');
      }
     	else
     		{
     			setupFoldersInit = false;
     			
     		}
     currentLabel.className = 'active';
     
     
    } else {
    	
      	currentFolder.style.display = "none";
      currentLabel.className = '';
    }
  }
  document.carto_form.js_folder_idx.value = id;
  // temporary check to prevent safari from screwing the template
  // to remove once safari is patched
  // see http://bugzilla.opendarwin.org/show_bug.cgi?id=3677 for bug description
  // see http://developer.apple.com/internet/safari/uamatrix.html for safari version detection
  safari = false;
  xUA = navigator.userAgent.toLowerCase();
  i = xUA.indexOf('safari');
  if (i>0) {
      v = xUA.slice(i+7,i+10);
      if (v <= 312 || v == 412) {
          safari = true;
      }
  }
 
  if (!isTopRowClicked(id) && !safari)
    swapRows();
    
}

function pop_ontop(id) {
var myfolders_pop = xGetElementsByClassName('popfol', null, null);
 for (i = 0; i < myfolders_pop.length; i++) {
    currentFolder_pop = myfolders_pop[i];
    current_pop = currentFolder_pop.id.substring(6);
    currentLabel_pop = xGetElementById('pop_label' + current_pop);
    if (current_pop == id) {
      currentFolder_pop.style.display = "block";
      currentLabel_pop.className = 'active';
    } else {
      currentFolder_pop.style.display = "none";
      currentLabel_pop.className = '';
    }
  }
  
  document.carto_form.js_folderpop_idx.value = id;
  // temporary check to prevent safari from screwing the template
  // to remove once safari is patched
  // see http://bugzilla.opendarwin.org/show_bug.cgi?id=3677 for bug description
  // see http://developer.apple.com/internet/safari/uamatrix.html for safari version detection
  safari = false;
  xUA = navigator.userAgent.toLowerCase();
  i = xUA.indexOf('safari');
  if (i>0) {
      v = xUA.slice(i+7,i+10);
      if (v <= 312 || v == 412) {
          safari = true;
      }
  }
/*
  for (i = 0; i < myfolders_pop.length; i++) {
    currentFolder_pop = myfolders_pop[i];
    current_pop = currentFolder_pop.id.substring(6);
    currentLabel_pop = xGetElementById('pop_label' + current_pop);
    if (current_pop == id) {
   
    	
     if (setupFoldersInit == false)
     	{
     		Effect.toggle(currentFolder_pop.id,'Appear');
      }
     	else
     		{
     			setupFoldersInit_pop = false;
     			
     		}
     currentLabel_pop.className = 'active';
     
     
    } else {
    	
      	currentFolder_pop.style.display = "none";
      currentLabel_pop.className = '';
    }
  }
  document.carto_form.js_folderpop_idx.value = id;
  // temporary check to prevent safari from screwing the template
  // to remove once safari is patched
  // see http://bugzilla.opendarwin.org/show_bug.cgi?id=3677 for bug description
  // see http://developer.apple.com/internet/safari/uamatrix.html for safari version detection
  safari = false;
  xUA = navigator.userAgent.toLowerCase();
  i = xUA.indexOf('safari');
  if (i>0) {
      v = xUA.slice(i+7,i+10);
      if (v <= 312 || v == 412) {
          safari = true;
      }
  }
 
 */
    
}

// 
function isTopRowClicked(id) {
  var clickedLabel = xGetElementById('label' + id);
  return (clickedLabel.parentNode.id == 'tabnav1');
}

function swapRows() {
  var topRow = xGetElementById('tabnav1');
  var lowRow = xGetElementById('tabnav2');
  var temp = topRow.innerHTML;
  topRow.innerHTML = lowRow.innerHTML;
  lowRow.innerHTML = temp;
}
setupFoldersInit=true;
EventManager.Add(window, 'load', setupFolders, false);


