function todos(selTodas,variable,totsel){
  var size=eval ("document.getElementById('"+variable+"').length");
  if (selTodas) eval ("document.getElementById('"+totsel+"').value="+size);
  else eval ("document.getElementById('"+totsel+"').value=0");
  for (var i = 0; i < size ; i++)
    eval("document.getElementById('"+variable+"').options[i].selected="+ selTodas);
}

function selectedValues(vars, combo){
  var arr = new Array();
  var strFinal = vars.split("&#039;").join("");
  strFinal = strFinal.split("'").join("");
  strFinal = strFinal.split(" ").join("");
  arr = strFinal.split(",");

  for (j=0; j<eval("document.getElementById('"+combo+"').length") ; j++){
    for (i=0;i<arr.length;i++){
      if(arr[i] == eval("document.getElementById('"+combo+"').options[" + j + "].value")){
        eval("document.getElementById('"+combo+"').options[" + j + "].selected = true");
      }
    }
  }
}

function buscar(sel,variable,valor,opc){

if (valor!=null && valor!=''){
    valor=valor.toUpperCase();
    valor = checkAcentos(valor);
    var len=eval("document.getElementById('"+variable+"').options.length");

    for(var i = 0;i < len;i++){
      if (is.IE){
	      var auxValor=eval("document.forms['formGeneral']."+variable+".options["+i+"].innerText");
      }else{
	      var auxValor=eval("document.getElementById('"+variable+"').options["+i+"].textContent");
      }

      auxValor=trim(auxValor);
      auxValor=auxValor.toUpperCase();
      auxValor = checkAcentos(auxValor);

      if (opc=='content' && auxValor.indexOf(valor)>-1){
      	eval("document.getElementById('"+variable+"').options["+i+"].selected=true");
      }
      else if(opc=='start' && auxValor.indexOf(valor)==0){
        eval("document.getElementById('"+variable+"').options["+i+"].selected=true");
      }
    }
    cuantos(sel,variable);
  }
}

function cuantos(totsel,variable){
var num=1;
  for (var i = 0; i < eval("document.getElementById('"+variable+"').length") ; i++) {  //getElementById
    if (eval("document.getElementById('"+variable+"').options["+i+"].selected") == true) {
      eval ("document.getElementById('"+totsel+"').value="+num);
      num++;
    }
  }
}

function ltrim(s) {
   return s.replace(/^\s+/, "");
}

function rtrim(s) {
   return s.replace(/\s+$/, "");
}

function trim(s) {
   return rtrim(ltrim(s));
}

function checkAcentos(texto){
	texto=texto.replace(/(À|Á|Â|Ã|Ä|Å|Æ)/gi,'A');
	texto=texto.replace(/(È|É|Ê|Ë)/gi,'E');
	texto=texto.replace(/(Ì|Í|Î|Ï)/gi,'I');
	texto=texto.replace(/(Ò|Ó|Ô|Ö)/gi,'O');
	texto=texto.replace(/(Ù|Ú|Û|Ü)/gi,'U');

	pat = /\w|\s|\//
	texto2 = '';
	for(m=0; m<texto.length; m++){
		if(pat.test(texto.charAt(m))) texto2 += texto.charAt(m);
	}
        return texto2;
}

