//variavel global

var req;
var res;
var idMensagem;
			
function getContextName()
{
  var strLink     = document.forms[0].action;
  var strContexto = "/" + strLink.split('/')[1];
  return strContexto;
}

function preenchecombo(valor, campo, idAtual){
	var marcar =0;
	if(campo.length>0){
		for(i = campo.length; i >= 0; i--){		
			campo.options[i] = null			
		}
	}
	campo.length = 0;
	for(i = 0; i < valor.length; i++){
		campo_temp = valor[i].split("|")
		if(new String(campo_temp[0]) != "undefined" && campo_temp[0] != "" ){
			if (campo_temp[0] == idAtual){
				marcar = idAtual;
			}
		}	
		var newoption = new Option(campo_temp[1],campo_temp[0], false, false);
		campo.options[i] = newoption;				
	}
	campo.value=marcar;
}
function replaceChars(entry,out,add) {
	temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	return temp;
}
function retornazero(valor){
	if(valor == ""){
		return "0";
	} else {
		return valor;
	}
}
function trim(valor){
 for (i=0;i<valor.length;i++){
  if(valor.substr(i,1) != " "){
   valor = valor.substr(i);
   break;
  }
  if (i == valor.length-1){
   valor = "";
  }
 }
 for (i=valor.length-1;i>=0;i--){
  if(valor.substr(i,1) != " "){
   valor = valor.substr(0,i+1);
   break;
  }
 }
 return valor;
}
function replaceChars(entry,out,add) {
	temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
	}
	return temp;
}
function centerpopup(url,width,height,name,scrollbars){

	var str="height="+height;//+",innerHeight="+height;
		str+=",width="+width;//+",innerWidth="+width;
	if (window.screen) {
		var ah=screen.availHeight-30;
		var aw=screen.availWidth-10;

		var xc=(aw-width)/2;
		var yc=(ah-height)/2;

		str+=",left="+xc+",screenX="+xc;
		str+=",top="+yc+",screenY="+yc;
		str_scroll=(scrollbars != null) ? scrollbars : "auto";
	}
	str+=",toolbar=no,location=no,status=no,menubar=no,scrollbars="+str_scroll+",resizable=no";

		window.open(url,name,str);
}
function SomenteNumerico(e){

//Sintaxe
//<input type='text' onKeyPress='return SomenteNumerico(event);'>

	if(document.all) // Internet Explorer
	var tecla = event.keyCode;

	else if(document.layers) // Nestcape
	var tecla = e.which;

	if(tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else
	{
	if (tecla != 8 && tecla != 44) // backspace
		return false;
	else
		return true;
	}

}
//Struts
  function pegaNomeContexto()
  {
    var strLink     = document.all['meuLink'].href;
    var strContexto = "/" + strLink.split('/')[3];
    return strContexto;
  }
      
