// Copyright 2008 Google Inc.
// All Rights Reserved.

/* Delete, Suspend, Change name */
var dv = false;
var sv = false;

var dv1 = true;
var sv1 = false;

function mostrarGenericaOcultar(i,j) { 
  h(j); 
  sv1=false; 
  if (dv1) {
    uh(i); 
  } 
 
};

function mostrarGenerica(i) { 
  //h('sd'); 
  sv=false; 
  if (dv) {
    h(i); 
  } else {
    uh(i); 
  }
  dv = !dv;
};

function d22(i) { 
  //h('sd'); 
  sv=false; 
  if (dv) {
    h('dd' + i); 
  } else {
    uh('dd' + i); 
  }
  dv = !dv;
};

function d() { 
  h('sd'); 
  sv=false; 
  if (dv) {
    h('dd'); 
  } else {
    uh('dd'); 
  }
  dv = !dv;
};

function s() { 
  h('dd'); 
  dv=false; 
  if (sv) {
    h('sd');
  } else {
    uh('sd');
  }
  sv = !sv;
};

function cn() {
  if (dv) {
    dv=false; h('dd')
  }
  if (sv) {
    sv=false; h('sd')
  }
  h('displayName'); 
  uh('editName');
  h('changeNameLink'); 
  uh('changeName');
};

function h(id) { 
  document.getElementById(id).style.display = "none";
};

/* un-hide, hide */
function uh(id) {
  document.getElementById(id).style.display = "";
};


/**
 * Starts an edit operation, opening up editItem and closing dispItem.
 * Optionally sets opt_setid elem to true
 */
function startEditOp(editItem,dispItem,opt_setid) {
  switchItem2(dispItem,editItem);
  set_isset(true,opt_setid);
};

/**
 * Cancels an edit operation, blanking out all input values found
 * in editItem, then switching its display w/ dispItem.
 * Uses cbTbl for traversing the DOM
 * @param editItem (String) ID of an elem containing edit fields
 * @param dispItem (String) ID of an elem displaying content
 * @param opt_setid ID of hidden elem indicating field is "set"/opened
 */
function cancelar(editItem,dispItem,opt_setid) {
  switchItem2(editItem,dispItem);
  var editwrapper = document.getElementById(editItem);
  var inputElems = cbTbl.findNodes(editwrapper,
      function(node) {
        return node.nodeName.toLowerCase() == 'input' &&
               (!node.type || node.type.toLowerCase() != 'hidden') &&
               node.value;
      });
  for (var i = 0; i < inputElems.length; ++i) {
    var inputElem = inputElems[i];
    var newVal = '';
    if (inputElem.id) {
      var origElem = document.getElementById(inputElem.id + '.orig');
      newVal = (origElem && origElem.value) ? origElem.value : newVal;
    }
    inputElems[i].value = newVal;
  }
  set_isset(false,opt_setid);
};

/* show item */
function showItem(item)	{
  document.getElementById(item).style.display='block';
};

/* hide item */
function hideItem(item) {
  document.getElementById(item).style.display='none';
};

/* hide item */
function hideItemIfExists(item) {
  var item = document.getElementById(item);
  if (item) {
    item.style.display='none';
  }
};

/*switch items */
var currentItem="item1";

function switchItem(which) {
  switchItem2(currentItem, which);
  currentItem=which;
};

/* hide one item, show another */
function switchItem2(toHide,toShow) {
  hideItem(toHide);
  showItem(toShow);
};

// Esta funcion sirve para validar que por lo menos haya un checkbox seleccionado
// Ing. Carlos Otero fecha: 06/08/2008
function validarCheckbox(form) { //v2.0
  var contador = 0; // almacena el nro de checkbox seleccionados
  var valorRetornado = true ;
  
  for (i = 0; i < form.length - 1; i++) { 
  
		if (form.elements[i].type == "checkbox") { // valida si el elemento es un validarCheckbox
			
			if (form.elements[i].checked == true) { // valida que el validarCheckbox este seleccionado
				contador ++;
			}
		}
  }
  
  if (contador == 0){ // si es cero, no hay ningun checkbox seleccionado
  	valorRetornado = false;
	alert("Debe seleccionar un programador como mínimo.");
  }
  
  return valorRetornado;
}
// Esta funcion envia un formulario y modifica el action para saber a que ruta invocar
// Ing John Henao 13/08/2008
function EnviarFormulario(formulario,ruta)
{
formulario.action = ruta;
formulario.submit();
}
