// jCompany 1.0 : Arquivo Javascript espec?fico da aplica??o
// ? inserido e disponibilizado em todas as p?ginas


function submeterFormCaptcha(){
var formulario = document.getElementById('geraCaptcha');
formulario.submit();
}

function limpaCep(idMun,idUf,tamanho){
if (tamanho!= 10){
document.getElementById(idMun).value='';
document.getElementById(idUf).value='';
}
  
}

function verificaCombo(){
if(document.getElementsByName('flgUsuarioExterno')!=null&&document.getElementById('valor')!=null){
var checkboxFlg=document.getElementsByName('flgUsuarioExterno');
var valor=document.getElementById('valor');
if(checkboxFlg.checked=='checked')
{
  		valor.value='0';
}
else{
		valor.value='1';
}
}
}

/**
 * Limpa o conte?do dos campos informados.
 * Informe os campos separados por v?rgula.
 *
 * @author Roberto Badar? 
 */
 
function limpaCampos(camposALimpar) {
	if (!camposALimpar) {
		return false;
	}
	
	var campos = camposALimpar.split(',');
	for (i=0; i<campos.length; i++) {
		setValorCampo(campos[i],'');
	}
	return false;
}

/**
 * Fun??o criada para limitar o tamanho de texto dentro de um textarea
 
 * @author Jos? Humberto Cruvinel - 11/02/2005 - GPS
 */
function verificaTamanho (campo, rows, cols){
	
	var tam = rows * cols - 20;
	if (campo.value.length > tam){
		campo.value = campo.value.substring(0, tam);
	}
	return false;
}

/**
 * Fun??o criada esconder dois div e setar valores nulos em dois campos quaisquer
 
 * @author Walmir
 */
function ocultarPrefCart(IDDIV1,IDDIV2,id,campo1,campo2){
	 if (id=="5"||id=="6"){
	    document.getElementById(IDDIV1).style.display='block'
	 }else{
	   document.getElementById(IDDIV1).style.display='none'
	 }
	 
	 if (id=="5"||id=="6"){
	 	if (document.getElementById(IDDIV2)!=null)
		    document.getElementById(IDDIV2).style.display='block'
	 }else{
	 	if (document.getElementById(IDDIV2)!=null)	 
			document.getElementById(IDDIV2).style.display='none'
	 }	 
	 
	 if (campo1!="")
		 document.getElementById(campo1).value='';
	
	 if (campo2!="")
		 document.getElementById(campo2).value='';	 
}


	//Vari?vel array para conter bot?es de ajuste
	var botoesAjuste = new Array();
	/**
		Fun??o que cria objetos representando bot?es para ajuste
		Par?metros:
		nomeBotao = nome do bot?o (label) a ser ajustado (recomendado chave evento)
		campo = nome do campo cujo valor ser? testado para ajuste
		valor = valor para ajuste. Se n?o informado assumido como vazio.
	*/

	function regBotaoAjuste(nomeBotao, nomeCampo, valorAjuste){
	
//		alert("Entrei regBotaoAjuste!");
		
		this.nomeBotao = nomeBotao;
		this.nomeCampo = nomeCampo;
		this.valorAjuste = valorAjuste;
	}

	/**
	Fun??o que ajusta os bot?es conforme dados registrados de forma gen?rica
	*/
	function ajustaBotoes(){
	
//		alert("Entrei ajustaBotoes");
//		botoesAjuste[0] = new regBotaoAjuste('F7 Novo','seqBeneficiario','47');		
			
		for(var i = 0; i < botoesAjuste.length; i++){

		    var botaoAjuste = selBotao(botoesAjuste[i].nomeBotao);
		    var campoAjuste = getCampo(botoesAjuste[i].nomeCampo);
		    var valorAjuste = botoesAjuste[i].valorAjuste;
	
//			alert("botaoAjuste: "+botaoAjuste+" - campoAjuste: "+campoAjuste+" - valorAjuste: "+valorAjuste);
	
		    if(!valorAjuste || ""+valorAjuste == "undefined")
		        valorAjuste = "";
		    if(campoAjuste.value == valorAjuste){
		        botaoAjuste.style.display = 'none';
		    }else{
		        botaoAjuste.style.display = 'inline';
		    }
		}
	}
	
	/**
	 * Seta os campos para a atualiza??o da lista de lookup e dipara o bot?o com a a??o.
	 *  
	 * @param classeLookupPlc nome da classe sem o caminho, ex: TipoEquipamento
	 * @param orderByPlc campo(s) de orderBy para o lookup, ex: nome
	 *
	 * @author: Cesar Correia - Powerlogic 2003 (c)
	 */
	function efetuaRefreshLookup(classeLookupPlc, camposOrderByPlc){
	
	      setValorCampo('lookupPlc',classeLookupPlc); 
	      setValorCampo('orderByPlc',camposOrderByPlc); 
	      disparaAcaoBotao('botaoRefreshLookup');
	}
	
	/**
	 * Dispara a a??o de um bot?o.
	 *  
	 * @param nomeBotao nome do botao
	 * 
	 * @author: Cesar Correia - Powerlogic 2003 (c)
	 */
	
	function disparaAcaoBotao(nomeBotao)
	{
		alert('entrou');
		document.forms[0].elements[nomeBotao].click();
		alert('saiu');
	}
	
	
/**
* Fun??o que altera o CLASS de um elemento
* Colar dentro do elemento: styleId="botao_menu" onmouseover="animar(event , \'2\')"  onmouseout="animar(event, \'\')"
*/
function animar(e, classe) 
{
	var obj;
	if(NavYes)
		obj = e.target;
	else	
		obj = e.srcElement;
	var originalClass = obj.id;
	if(originalClass){
		if(originalClass.indexOf("2") != -1)
			originalClass = originalClass.substring(0, originalClass.length-1);
	
		classe = originalClass+classe;
		//if (DomExp) 
			obj.id = classe;
	}
}
function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("menujs").getElementsByTagName("ul"); 
		if(el.style.display != "block"){ 
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}
function increaseFontSize() {
	increaseFontSizeTag('td');
	increaseFontSizeTag('p');
	increaseFontSizeTag('a');
	increaseFontSizeTag('div');
	increaseFontSizeTag('p');
	increaseFontSizeTag('span');
}
function increaseFontSizeTag(tagElemento){
   try{
   var min=8;
   var max=18;
   var p = document.getElementsByTagName(tagElemento);
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   } catch(e){}
}
function decreaseFontSize() {
	decreaseFontSizeTag('td');
	decreaseFontSizeTag('p');
	decreaseFontSizeTag('a');
	decreaseFontSizeTag('div');
	decreaseFontSizeTag('p');
	decreaseFontSizeTag('span');
}
function decreaseFontSizeTag(tagElemento) {
   try {
   var min=8;
   var max=18;
   var p = document.getElementsByTagName(tagElemento);
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
   } catch(e){}
}	
	
// -------------------------------------------------------------------------------------
// Importado de masks.js
// -------------------------------------------------------------------------------------
function _MaskAPI(){
	this.version = "0.4b";
	this.instances = 0;
	this.objects = {};
}
MaskAPI = new _MaskAPI();

function Mask(m, t){
	this.mask = m;
	this.type = (typeof t == "string") ? t : "string";
	this.error = [];
	this.errorCodes = [];
	this.value = "";
	this.strippedValue = "";
	this.allowPartial = false;
	this.id = MaskAPI.instances++;
	this.ref = "MaskAPI.objects['" + this.id + "']";
	MaskAPI.objects[this.id] = this;
}

// define the attach(oElement) function
Mask.prototype.attach = function (o){
	$addEvent(o, "onkeydown", "return " + this.ref + ".isAllowKeyPress(event, this);", true);
	$addEvent(o, "onkeyup", "return " + this.ref + ".getKeyPress(event, this);", true);
	$addEvent(o, "onblur", "this.value = " + this.ref + ".format(this.value);", true);
}

Mask.prototype.isAllowKeyPress = function (e, o){
	if( this.type != "string" ) return true;
	var xe = new qEvent(e);

	if( ((xe.keyCode > 47) && (o.value.length >= this.mask.length)) && !xe.ctrlKey ) return false;
	return true;
}

Mask.prototype.getKeyPress = function (e, o, _u){
	this.allowPartial = true;
	var xe = new qEvent(e);

//	var k = String.fromCharCode(xe.keyCode);

	if( (xe.keyCode > 47) || (_u == true) || (xe.keyCode == 8 || xe.keyCode == 46) ){
		var v = o.value, d;
		if( xe.keyCode == 8 || xe.keyCode == 46 ) d = true;
		else d = false

		if( this.type == "number" ) this.value = this.setNumber(v, d);
		else if( this.type == "date" ) this.value = this.setDateKeyPress(v, d);
		else this.value = this.setGeneric(v, d);

		o.value = this.value;
	}
	/* */

	this.allowPartial = false;
	return true;
}

Mask.prototype.format = function (s){
	if( this.type == "number" ) this.value = this.setNumber(s);
	else if( this.type == "date" ) this.value = this.setDate(s);
	else this.value = this.setGeneric(s);
	return this.value;
}

Mask.prototype.throwError = function (c, e, v){
	this.error[this.error.length] = e;
	this.errorCodes[this.errorCodes.length] = c;
	if( typeof v == "string" ) return v;
	return true;
}

Mask.prototype.setGeneric = function (_v, _d){
	var v = _v, m = this.mask;
	var r = "x#*", rt = [], nv = "", t, x, a = [], j=0, rx = {"x": "A-Za-z", "#": "0-9", "*": "A-Za-z0-9" };

	// strip out invalid characters
	v = v.replace(new RegExp("[^" + rx["*"] + "]", "gi"), "");
	if( (_d == true) && (v.length == this.strippedValue.length) ) v = v.substring(0, v.length-1);
	this.strippedValue = v;
	var b=[];
	for( var i=0; i < m.length; i++ ){
		// grab the current character
		x = m.charAt(i);
		// check to see if current character is a mask, escape commands are not a mask character
		t = (r.indexOf(x) > -1);
		// if the current character is an escape command, then grab the next character
		if( x == "!" ) x = m.charAt(i++);
		// build a regex to test against
		if( (t && !this.allowPartial) || (t && this.allowPartial && (rt.length < v.length)) ) rt[rt.length] = "[" + rx[x] + "]";
		// build mask definition table
		a[a.length] = { "chr": x, "mask": t };
	}

	var hasOneValidChar = false;
	// if the regex fails, return an error
	if( !this.allowPartial && !(new RegExp(rt.join(""))).test(v) ) return this.throwError(1, "The value \"" + _v + "\" must be in the format " + this.mask + ".", _v);
	// loop through the mask definition, and build the formatted string
	else if( (this.allowPartial && (v.length > 0)) || !this.allowPartial ){
		for( i=0; i < a.length; i++ ){
			if( a[i].mask ){
				while( v.length > 0 && !(new RegExp(rt[j])).test(v.charAt(j)) ) v = (v.length == 1) ? "" : v.substring(1);
				if( v.length > 0 ){
					nv += v.charAt(j);
					hasOneValidChar = true;
				}
				j++;
			} else nv += a[i].chr;
			if( this.allowPartial && (j > v.length) ) break;
		}
	}
	
	if( this.allowPartial && !hasOneValidChar ) nv = "";
	if( this.allowPartial ){
		if( nv.length < a.length ) this.nextValidChar = rx[a[nv.length].chr];
		else this.nextValidChar = null;
	}

	return nv;
}

Mask.prototype.setNumber = function(_v, _d){
	var v = String(_v).replace(/[^\d.-]*/gi, ""), m = this.mask;
	// make sure there's only one decimal point
	v = v.replace(/\./, "d").replace(/\./g, "").replace(/d/, ".");

	// check to see if an invalid mask operation has been entered
	if( !/^[\$]?((\$?[\+-]?([0#]{1,3},)?[0#]*(\.[0#]*)?)|([\+-]?\([\+-]?([0#]{1,3},)?[0#]*(\.[0#]*)?\)))$/.test(m) )
		return this.throwError(1, "An invalid mask was specified for the \nMask constructor.", _v);

	if( (_d == true) && (v.length == this.strippedValue.length) ) v = v.substring(0, v.length-1);

	if( this.allowPartial && (v.replace(/[^0-9]/, "").length == 0) ) return v;
	this.strippedValue = v;

	if( v.length == 0 ) v = NaN;
	var vn = Number(v);
	if( isNaN(vn) ) return this.throwError(2, "The value entered was not a number.", _v);

	// if no mask, stop processing
	if( m.length == 0 ) return v;

	// get the value before the decimal point
	var vi = String(Math.abs((v.indexOf(".") > -1 ) ? v.split(".")[0] : v));
	// get the value after the decimal point
	var vd = (v.indexOf(".") > -1) ? v.split(".")[1] : "";
	var _vd = vd;

	var isNegative = (vn != 0 && Math.abs(vn)*-1 == vn);

	// check for masking operations
	var show = {
		"$" : /^[\$]/.test(m),
		"(": (isNegative && (m.indexOf("(") > -1)),
		"+" : ( (m.indexOf("+") != -1) && !isNegative )
	}
	show["-"] = (isNegative && (!show["("] || (m.indexOf("-") != -1)));


	// replace all non-place holders from the mask
	m = m.replace(/[^#0.,]*/gi, "");

	/*
		make sure there are the correct number of decimal places
	*/
	// get number of digits after decimal point in mask
	var dm = (m.indexOf(".") > -1 ) ? m.split(".")[1] : "";
	if( dm.length == 0 ){
		vi = String(Math.round(Number(vi)));
		vd = "";
	} else {
		// find the last zero, which indicates the minimum number
		// of decimal places to show
		var md = dm.lastIndexOf("0")+1;
		// if the number of decimal places is greater than the mask, then round off
		if( vd.length > dm.length ) vd = String(Math.round(Number(vd.substring(0, dm.length + 1))/10));
		// otherwise, pad the string w/the required zeros
		else while( vd.length < md ) vd += "0";
	}

	/*
		pad the int with any necessary zeros
	*/
	// get number of digits before decimal point in mask
	var im = (m.indexOf(".") > -1 ) ? m.split(".")[0] : m;
	im = im.replace(/[^0#]+/gi, "");
	// find the first zero, which indicates the minimum length
	// that the value must be padded w/zeros
	var mv = im.indexOf("0")+1;
	// if there is a zero found, make sure it's padded
	if( mv > 0 ){
		mv = im.length - mv + 1;
		while( vi.length < mv ) vi = "0" + vi;
	}


	/*
		check to see if we need commas in the thousands place holder
	*/
	if( /[#0]+,[#0]{3}/.test(m) ){
		// add the commas as the place holder
		var x = [], i=0, n=Number(vi);
		while( n > 999 ){
			x[i] = "00" + String(n%1000);
			x[i] = x[i].substring(x[i].length - 3);
			n = Math.floor(n/1000);
			i++;
		}
		x[i] = String(n%1000);
		vi = x.reverse().join(",");
	}


	/*
		combine the new value together
	*/
	if( (vd.length > 0 && !this.allowPartial) || ((dm.length > 0) && this.allowPartial && (v.indexOf(".") > -1) && (_vd.length >= vd.length)) ){
		v = vi + "." + vd;
	} else if( (dm.length > 0) && this.allowPartial && (v.indexOf(".") > -1) && (_vd.length < vd.length) ){
		v = vi + "." + _vd;
	} else {
		v = vi;
	}

	if( show["$"] ) v = this.mask.replace(/(^[\$])(.+)/gi, "$") + v;
	if( show["+"] ) v = "+" + v;
	if( show["-"] ) v = "-" + v;
	if( show["("] ) v = "(" + v + ")";
	return v;
}

Mask.prototype.setDate = function (_v){
	var v = _v, m = this.mask;
	var a, e, mm, dd, yy, x, s;

	// split mask into array, to see position of each day, month & year
	a = m.split(/[^mdy]+/);
	// split mask into array, to get delimiters
	s = m.split(/[mdy]+/);
	// convert the string into an array in which digits are together
	e = v.split(/[^0-9]/);
	
	if( s[0].length == 0 ) s.splice(0, 1);

	for( var i=0; i < a.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ) mm = parseInt(e[i], 10)-1;
		else if( x == "d" ) dd = parseInt(e[i], 10);
		else if( x == "y" ) yy = parseInt(e[i], 10);
	}

	// if year is abbreviated, guess at the year
	if( String(yy).length < 3 ){
		yy = 2000 + yy;
		if( (new Date()).getFullYear()+5 < yy ) yy = yy - 100;
	}

	// create date object
	var d = new Date(yy, mm, dd);

	if( d.getDate() != dd ) return this.throwError(1, "An invalid day was entered.", _v);
	else if( d.getMonth() != mm ) return this.throwError(2, "An invalid month was entered.", _v);

	var nv = "";

	for( i=0; i < a.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ){
			mm++;
			if( a[i].length == 2 ){
				mm = "0" + mm;
				mm = mm.substring(mm.length-2);
			}
			nv += mm;
		} else if( x == "d" ){
			if( a[i].length == 2 ){
				dd = "0" + dd;
				dd = dd.substring(dd.length-2);
			}
			nv += dd;
		} else if( x == "y" ){
			if( a[i].length == 2 ) nv += d.getYear();
			else nv += d.getFullYear();
		}

		if( i < a.length-1 ) nv += s[i];
	}

	return nv;
}

Mask.prototype.setDateKeyPress = function (_v, _d){
	var v = _v, m = this.mask, k = v.charAt(v.length-1);
	var a, e, c, ml, vl, mm = "", dd = "", yy = "", x, p, z;

	if( _d == true ){
		while( (/[^0-9]/gi).test(v.charAt(v.length-1)) ) v = v.substring(0, v.length-1);
		if( (/[^0-9]/gi).test(this.strippedValue.charAt(this.strippedValue.length-1)) ) v = v.substring(0, v.length-1);
		if( v.length == 0 ) return "";
	}

	// split mask into array, to see position of each day, month & year
	a = m.split(/[^mdy]/);
	// split mask into array, to get delimiters
	s = m.split(/[mdy]+/);
	// mozilla wants to add an empty array element which needs removed
	if( s[0].length == 0 ) s.splice(0,1);
	// convert the string into an array in which digits are together
	e = v.split(/[^0-9]/);
	// position in mask
	p = (e.length > 0) ? e.length-1 : 0;
	// determine what mask value the user is currently entering
	c = a[p].charAt(0);
	// determine the length of the current mask value
	ml = a[p].length;

	for( var i=0; i < e.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
		if( x == "m" ) mm = parseInt(e[i], 10)-1;
		else if( x == "d" ) dd = parseInt(e[i], 10);
		else if( x == "y" ) yy = parseInt(e[i], 10);
	}
	
	
	var nv = "";
	var j=0;

	for( i=0; i < e.length; i++ ){
		x = a[i].charAt(0).toLowerCase();
	
		if( x == "m" ){
			z = ((/[^0-9]/).test(k) && c == "m");
			mm++;
			if( (e[i].length == 2 && mm < 10) || (a[i].length == 2 && c != "m") || (mm > 1 && c == "m") || (z && a[i].length == 2) ){
				mm = "0" + mm;
				mm = mm.substring(mm.length-2);
			}
			vl = String(mm).length;
			ml = 2;
			nv += mm;
		} else if( x == "d" ){
			z = ((/[^0-9]/).test(k) && c == "d");
			if( (e[i].length == 2 && dd < 10) || (a[i].length == 2 && c != "d") || (dd > 3 && c == "d") || (z && a[i].length == 2) ){
				dd = "0" + dd;
				dd = dd.substring(dd.length-2);
			}
			vl = String(dd).length;
			ml = 2;
			nv += dd;
		} else if( x == "y" ){
			z = ((/[^0-9]/).test(k) && c == "y");
			if( c == "y" ) yy = String(yy);
			else {
				if( a[i].length == 2 ) yy = d.getYear();
				else yy = d.getFullYear();
			}
			if( (e[i].length == 2 && yy < 10) || (a[i].length == 2 && c != "y") || (z && a[i].length == 2) ){
				yy = "0" + yy;
				yy = yy.substring(yy.length-2);
			}
			ml = a[i].length;
			vl = String(yy).length;
			nv += yy;
		}

		if( ((ml == vl || z) && (x == c) && (i < s.length)) || (i < s.length && x != c ) ) nv += s[i];
	}

	if( nv.length > m.length ) nv = nv.substring(0, m.length);

	this.strippedValue = (nv == "NaN") ? "" : nv;

	return this.strippedValue;
}

function qEvent(e){
	// routine for NS, Opera, etc DOM browsers
	if( window.Event ){
		var isKeyPress = (e.type.substring(0,3) == "key");

		this.keyCode = (isKeyPress) ? parseInt(e.which, 10) : 0;
		this.button = (!isKeyPress) ? parseInt(e.which, 10) : 0;
		this.srcElement = e.target;
		this.type = e.type;
		this.x = e.pageX;
		this.y = e.pageY;
		this.screenX = e.screenX;
		this.screenY = e.screenY;
		if( document.layers ){
			this.altKey = ((e.modifiers & Event.ALT_MASK) > 0);
			this.ctrlKey = ((e.modifiers & Event.CONTROL_MASK) > 0);
			this.shiftKey = ((e.modifiers & Event.SHIFT_MASK) > 0);
			this.keyCode = this.translateKeyCode(this.keyCode);
		} else {
			this.altKey = e.altKey;
			this.ctrlKey = e.ctrlKey;
			this.shiftKey = e.shiftKey;
		}
	// routine for Internet Explorer DOM browsers
	} else {
		e = window.event;
		this.keyCode = parseInt(e.keyCode, 10);
		this.button = e.button;
		this.srcElement = e.srcElement;
		this.type = e.type;
		if( document.all ){
			this.x = e.clientX + document.body.scrollLeft;
			this.y = e.clientY + document.body.scrollTop;
		} else {
			this.x = e.clientX;
			this.y = e.clientY;
		}
		this.screenX = e.screenX;
		this.screenY = e.screenY;
		this.altKey = e.altKey;
		this.ctrlKey = e.ctrlKey;
		this.shiftKey = e.shiftKey;
	}
	if( this.button == 0 ){
		this.setKeyPressed(this.keyCode);
		this.keyChar = String.fromCharCode(this.keyCode);
	}
}

// this method will try to remap the keycodes so the keycode value
// returned will be consistent. this doesn't work for all cases,
// since some browsers don't always return a unique value for a
// key press.
qEvent.prototype.translateKeyCode = function (i){
	var l = {};
	// remap NS4 keycodes to IE/W3C keycodes
	if( !!document.layers ){
		if( this.keyCode > 96 && this.keyCode < 123 ) return this.keyCode - 32;
		l = {
			96:192,126:192,33:49,64:50,35:51,36:52,37:53,94:54,38:55,42:56,40:57,41:48,92:220,124:220,125:221,
			93:221,91:219,123:219,39:222,34:222,47:191,63:191,46:190,62:190,44:188,60:188,45:189,95:189,43:187,
			61:187,59:186,58:186,
			"null": null
		}
	}
	return (!!l[i]) ? l[i] : i;
}

// try to determine the actual value of the key pressed
qEvent.prototype.setKP = function (i, s){
	this.keyPressedCode = i;
	this.keyNonChar = (typeof s == "string");
	this.keyPressed = (this.keyNonChar) ? s : String.fromCharCode(i);
	this.isNumeric = (parseInt(this.keyPressed, 10) == this.keyPressed);
	this.isAlpha = ((this.keyCode > 64 && this.keyCode < 91) && !this.altKey && !this.ctrlKey);
	return true;
}

// try to determine the actual value of the key pressed
qEvent.prototype.setKeyPressed = function (i){
	var b = this.shiftKey;
	if( !b && (i > 64 && i < 91) ) return this.setKP(i + 32);
	if( i > 95 && i < 106 ) return this.setKP(i - 48);
	
	switch( i ){
		case 49: case 51: case 52: case 53: if( b ) i = i - 16; break;
		case 50: if( b ) i = 64; break;
		case 54: if( b ) i = 94; break;
		case 55: if( b ) i = 38; break;
		case 56: if( b ) i = 42; break;
		case 57: if( b ) i = 40; break;
		case 48: if( b ) i = 41; break;
		case 192: if( b ) i = 126; else i = 96; break;
		case 189: if( b ) i = 95; else i = 45; break;
		case 187: if( b ) i = 43; else i = 61; break;
		case 220: if( b ) i = 124; else i = 92; break;
		case 221: if( b ) i = 125; else i = 93; break;
		case 219: if( b ) i = 123; else i = 91; break;
		case 222: if( b ) i = 34; else i = 39; break;
		case 186: if( b ) i = 58; else i = 59; break;
		case 191: if( b ) i = 63; else i = 47; break;
		case 190: if( b ) i = 62; else i = 46; break;
		case 188: if( b ) i = 60; else i = 44; break;

		case 106: case 57379: i = 42; break;
		case 107: case 57380: i = 43; break;
		case 109: case 57381: i = 45; break;
		case 110: i = 46; break;
		case 111: case 57378: i = 47; break;

		case 8: return this.setKP(i, "[backspace]");
		case 9: return this.setKP(i, "[tab]");
		case 13: return this.setKP(i, "[enter]");
		case 16: case 57389: return this.setKP(i, "[shift]");
		case 17: case 57390: return this.setKP(i, "[ctrl]");
		case 18: case 57388: return this.setKP(i, "[alt]");
		case 19: case 57402: return this.setKP(i, "[break]");
		case 20: return this.setKP(i, "[capslock]");
		case 32: return this.setKP(i, "[space]");
		case 91: return this.setKP(i, "[windows]");
		case 93: return this.setKP(i, "[properties]");

		case 33: case 57371: return this.setKP(i*-1, "[pgup]");
		case 34: case 57372: return this.setKP(i*-1, "[pgdown]");
		case 35: case 57370: return this.setKP(i*-1, "[end]");
		case 36: case 57369: return this.setKP(i*-1, "[home]");
		case 37: case 57375: return this.setKP(i*-1, "[left]");
		case 38: case 57373: return this.setKP(i*-1, "[up]");
		case 39: case 57376: return this.setKP(i*-1, "[right]");
		case 40: case 57374: return this.setKP(i*-1, "[down]");
		case 45: case 57382: return this.setKP(i*-1, "[insert]");
		case 46: case 57383: return this.setKP(i*-1, "[delete]");
		case 144: case 57400: return this.setKP(i*-1, "[numlock]");
	}
	
	if( i > 111 && i < 124 ) return this.setKP(i*-1, "[f" + (i-111) + "]");

	return this.setKP(i);
}

// define the addEvent(oElement, sEvent, sCmd, bAppend) function
function $addEvent(o, _e, c, _b){
	var e = _e.toLowerCase(), b = (typeof _b == "boolean") ? _b : true, x = (o[e]) ? o[e].toString() : "";
	// strip out the body of the function
	x = x.substring(x.indexOf("{")+1, x.lastIndexOf("}"));
	x = ((b) ? (x + c) : (c + x)) + "\n";
	return o[e] = (!!window.Event) ? new Function("event", x) : new Function(x);
}
// -------------------------------------------------------------------------------------
// Importado de util.js
// -------------------------------------------------------------------------------------
function SoNumero(nro)
{
 var valid    = "0123456789";
 var numerook = "";
 var temp;

  for (var i=0; i< nro.length; i++) {
    temp = nro.substr(i, 1);
    if (valid.indexOf(temp) != -1) 
      numerook = numerook + temp;
   } 
 return(numerook);
}


function DigitaLetra(obj)
{
 var valid    = " abcdefghijklmnopqrstuvwxyz???ABCDEFGHIJKLMNOPQRSTUVWXYZ???";
 var numerook = "";
 var temp;

  for (var i=0; i< obj.value.length; i++) {
    temp = obj.value.substr(i, 1);
    if (valid.indexOf(temp) != -1) 
      numerook = numerook + temp;
   } 
 obj.value = numerook;
}


function DigitaNumero(obj)
{
 var valid    = "1234567890";
 var numerook = "";
 var temp;

  for (var i=0; i< obj.value.length; i++) {
    temp = obj.value.substr(i, 1);
    if (valid.indexOf(temp) != -1) 
      numerook = numerook + temp;
   } 
 obj.value = numerook;
}


function TamanhoMax(campo, TamanhoMaximo)
{
	if (campo.value.length > TamanhoMaximo)	{
	  campo.value = campo.value.substring(0,TamanhoMaximo);
    }
	
}
// -------------------------------------------------------------------------------------
// Importado de cnpj.js
// -------------------------------------------------------------------------------------
function ValidaCNPJ(campo)
{

  if (campo.value == '') return true;
	
 if (campo.value != '') {
   var CNPJ = campo.value;

   while (CNPJ.indexOf(".") != -1)
	 CNPJ = CNPJ.replace(".","");
   while (CNPJ.indexOf("-") != -1)
 	 CNPJ = CNPJ.replace("-","");
   while (CNPJ.indexOf(" ") != -1)
	 CNPJ = CNPJ.replace(" ","");
   while (CNPJ.indexOf("/") != -1)
	 CNPJ = CNPJ.replace("/","");

   var cnpjCalc = CNPJ.substr(0,12);  
   var cnpjSoma = 0;
   var cnpjDigit = 0;  
   var digit = "";    
  
   for (i = 0;  i < 4;  i++) {
     cnpjSoma = cnpjSoma + parseInt(cnpjCalc.charAt(i)) * (5 - i);
    } 
  
   for (i = 0;  i < 8;  i++) {
     cnpjSoma = cnpjSoma + parseInt(cnpjCalc.charAt(i+4)) * (9 - i);            
    }    
 
   cnpjDigit = 11 - cnpjSoma%11;       

   if ((cnpjDigit == 10) || (cnpjDigit == 11)){     
     cnpjCalc = cnpjCalc + "0";        
    } 
   else {     
     digit = digit + cnpjDigit; 
     cnpjCalc = cnpjCalc + (digit.charAt(0));
    }
  
   cnpjSoma = 0;
  
   for (i = 0;  i < 5;  i++){
     cnpjSoma = cnpjSoma + parseInt(cnpjCalc.charAt(i)) * (6 - i);    
    }  
  
   for (i = 0;  i < 8;  i++) {
     cnpjSoma = cnpjSoma + parseInt(cnpjCalc.charAt(i+5)) * (9 - i);    
    }

   cnpjDigit = 11 - cnpjSoma%11;         
    
   if ((cnpjDigit == 10) || (cnpjDigit == 11)) {    
     cnpjCalc = cnpjCalc + "0";    
    } 
   else {     
     digit = "";
     digit = digit + cnpjDigit; 
     cnpjCalc = cnpjCalc + (digit.charAt(0))        
    }
  
   if (CNPJ != cnpjCalc) { 
	 return false;
    }
 
   return true;
  } 
}


function MascaraCNPJ(campo,w)
{
   var CNPJ = SoNumero(campo.value);
   var CNPJAux = ''; 
   var campo1 = campo.value;

   if (w.keyCode == 8) { 
     if (campo1.length == 2 || campo1.length == 6 || campo1.length == 10 || campo1.length == 15) {
        CNPJ = CNPJ.substr(0,CNPJ.length -1);
       } 
    }
    
   if (CNPJ.length < 15) {
     for (var i=0; i<CNPJ.length; i++) {
       CNPJAux = CNPJAux + CNPJ.substr(i,1);     
       if (i == 1 || i == 4) {
         CNPJAux = CNPJAux + ".";
        }
       if (i == 7) {
         CNPJAux = CNPJAux + "/";
        }
       if (i == 11) {
         CNPJAux = CNPJAux + "-";
        }    
      }  
     campo.value = CNPJAux;
    }
   else {
      campo.value = campo.value.substr(0,18);
    }    
}


function CNPJsemMascara(campo)
{
   if (campo.value.length > 14)
     campo.value = campo.value.substring(0,campo.value.length -1);
   else 
     campo.value = SoNumero(campo.value);
}


function DesmascaraCNPJ(campo)
{
  campo.value = SoNumero(campo.value);
}	
// -------------------------------------------------------------------------------------
// Importado de cpf.js
// -------------------------------------------------------------------------------------
function ValidaCPF(campo)
{

	if (campo.value == '') return true;

  if (campo.value != '') {
     var CPF = campo.value;

     while (CPF.indexOf(".") != -1)
    	CPF = CPF.replace(".","");
     while (CPF.indexOf("-") != -1)
	    CPF = CPF.replace("-","");
     while (CPF.indexOf(" ") != -1)
	    CPF = CPF.replace(" ","");

     var cpfCalc = CPF.substr(0,9);  
     var cpfSoma = 0;
     var cpfDigit = 0;
     var digit = "";      
    
     for (i = 0; i < 9; i++) {
       cpfSoma = cpfSoma + parseInt(cpfCalc.charAt(i)) * (10 - i)
      }
  
     cpfDigit = 11 - cpfSoma%11;
    
     if (cpfDigit > 9) {
       cpfCalc = cpfCalc + "0";
      } 
     else {
       digit = digit + cpfDigit;
       cpfCalc = cpfCalc + digit.charAt(0);
      }
  
     cpfSoma = 0;
  
     for (i = 0; i < 10; i++) {
       cpfSoma = cpfSoma + parseInt(cpfCalc.charAt(i)) * (11 - i)
      }
  
     cpfDigit = 11 - cpfSoma%11;
  
     if (cpfDigit > 9) {
       cpfCalc = cpfCalc + "0";
      } 
     else {
       digit = "";
       digit = digit + cpfDigit;
       cpfCalc = cpfCalc + digit.charAt(0);
      }  
   
     if (CPF != cpfCalc){
  	   return false;
	  } 

     return true;
     
     
     
    }  
}

function replaceAll(str, de, para){
    var pos = str.indexOf(de);
    while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
    return (str);
}

function valida_cpf(cpf){
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      cpf=cpf.replace("-","");
      cpf=replaceAll(cpf,".","");
      digitos_iguais = 1;
      if (cpf.length < 11)
            return false;
      for (i = 0; i < cpf.length - 1; i++)
            /*if (cpf.charAt(i) != cpf.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {*/
            numeros = cpf.substring(0,9);
            digitos = cpf.substring(9);
            soma = 0;
            for (i = 10; i > 1; i--)
                  soma += numeros.charAt(10 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            numeros = cpf.substring(0,10);
            soma = 0;
            for (i = 11; i > 1; i--)
                  soma += numeros.charAt(11 - i) * i;
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
           // }
     // else
            //return false;
}

function MascaraCPF(campo,w)
{
   var CPF = SoNumero(campo.value);
   var CPFAux = ''; 
   var campo1 = campo.value;

   if (w.keyCode == 8) {      
     if (campo1.length == 3 || campo1.length == 7 || campo1.length == 11) {
        CPF = CPF.substr(0,CPF.length-1);
       } 
    }
     
   if (CPF.length < 12) {
     
     for (var i=0; i<CPF.length; i++) {
       CPFAux = CPFAux + CPF.substr(i,1);     
       if (i == 2 || i == 5) {
         CPFAux = CPFAux + ".";
        }
       if (i == 8) {
         CPFAux = CPFAux + "-";
        }
      }  
     campo.value = CPFAux;
    }
   else {
      campo.value = campo.value.substr(0,14);
     }    
}


function CPFsemMascara(campo)
{
   if (campo.value.length > 11)
     campo.value = campo.value.substring(0,campo.value.length -1);
   else 
     campo.value = SoNumero(campo.value);
}


function DesmascaraCPF(campo)
{
  campo.value = SoNumero(campo.value);
}
// -------------------------------------------------------------------------------------
// Importado de data.js
// -------------------------------------------------------------------------------------
function ValidaData(campo)
{
	if( campo != '' )
	{
		var strData = campo.value;
		var pos = strData.indexOf("/",0);
		if (pos < 0){
			return false
		}
		dia = strData.slice(0,pos);

		pos2 = strData.indexOf("/",pos+1);
		if (pos < 0){
			return false
		}
		mes = strData.slice(pos+1,pos2);
	
		ano = strData.substr(pos2+1);

		dia= "00" + dia;
		dia = dia.substring(dia.length-2,dia.length);
   		mes= "00" + mes;
		mes = mes.substring(mes.length-2,mes.length);

		if (strData.value != '' && strData.length != 10) {
			return false;
		}
			
		if (isNaN(dia) || isNaN(mes) || isNaN(ano)) {
			return false;
		}
	
		if (ano.length < 4){
			return false;
		}

		if (mes < 1 || mes > 12) {
			return false;
		}

		if (dia < 1 || dia > 31) {
			return false;
		}

		if ((mes==4 || mes==6 || mes==9 || mes==11) && dia==31) {
			return false;
		}

		if (strData.indexOf("_") != -1) {
			return false;
		}

		if (mes == 2) {
			var isleap = (ano % 4 == 0 && (ano % 100 != 0 || ano % 400 == 0))
			if (dia>29 || (dia==29 && !isleap)) {
				return false;
			}
		}
	}
	return true;
}


function MascaraData(campo,w)
{
   var Data = SoNumero(campo.value);
   var DataAux = ''; 
   var campo1 = campo.value;

   if (w.keyCode == 8) {      
     if (campo1.length == 2 || campo1.length == 5) {
        Data = Data.substr(0,Data.length-1);
       } 
    }
    
   if (Data.length < 9) {
     for (var i=0; i < Data.length; i++) {
       DataAux = DataAux + Data.substr(i,1);     
       if (i == 1 || i == 3) {
         DataAux = DataAux + "/";
        }
      }  
     campo.value = DataAux;
    }
   else {
      campo.value = campo.value.substr(0,10);
     }    
}


function DataMaior(dataini, datafim)
{   
   var Dt_inicial = dataini.substr(6,4) + dataini.substr(3,2) + dataini.substr(0,2);
   var Dt_final   = datafim.substr(6,4) + datafim.substr(3,2) + datafim.substr(0,2);
   if (Dt_inicial > Dt_final) {
      return (true);
    }  
   else {
      return (false);
     } 
}


function DataMenor(dataini, datafim)
{   
   var Dt_inicial = dataini.substr(6,4) + dataini.substr(3,2) + dataini.substr(0,2);
   var Dt_final   = datafim.substr(6,4) + datafim.substr(3,2) + datafim.substr(0,2);
   if (Dt_inicial < Dt_final) {
      return (true);
    }  
   else {
      return (false);
     } 
}

function DataIgual(dataini, datafim)
{
  if (!DataMaior(dataini, datafim) && !DataMenor(dataini, datafim)) {
      return (true);
    }  
   else {
      return (false);
     }   
}

function GetDia(Data)
{  
   return (Data.substr(0,2));
}


function GetMes(strData)
{
   return (strData.substr(3,2));
}


function GetAno(strData)
{  
   return (strData.substr(6,4));
}


function DataInversa(strData)
{
    var aaaa = "0000";
    var mm = "00";
    var dd = "00";

    if (strData.length == 10){
        aaaa = GetAno(strData);
        mm   = GetMes(strData);
        dd   = GetDia(strData);
    }
    return (aaaa + mm + dd);
}

/**
 * @author	Willian R. Medeiros
 * @param strDataInformada:	data Informada no formato String
 * @param intDias:	Quantidade de dias a serem incrementados 
 * @return:	data com a quantidade de dias incrementada no formato String
 */
function IncrementaData(strDataInformada, intDias){

	if(isNaN(intDias)){
		return strDataInformada;
	}
	else {
	
		var dia = parseInt(strDataInformada.substr(0,2), 10);
		var mes = parseInt(strDataInformada.substr(3,2), 10);
		var ano = parseInt(strDataInformada.substr(6,4), 10);

		if(isNaN(dia) || isNaN(dia) || isNaN(dia)){
			return strDataInformada;
		}
		else {
			var data = new Date(ano, (mes - 1), dia);
			var acrescimoMillisec = (86400000 * intDias);
			var strData = "";
			
			data.setMilliseconds(acrescimoMillisec);
			
			if(data.getDate() > 9){
				strData = data.getDate() + "/";
			}
			else {
				strData = "0" + data.getDate() + "/";
			}
			
			if((data.getMonth() + 1) > 9){
				strData += (data.getMonth() + 1) + "/";
			}
			else {
				strData += "0" + (data.getMonth() + 1) + "/";
			}
			
			strData += data.getFullYear();
			
			return strData;
		}
	}
}
// -------------------------------------------------------------------------------------
// Importado de email.js
// -------------------------------------------------------------------------------------
function ValidaEmail(email)
{
	if (email.value == '') return true;
	
	var CaracValid = "_-.@0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
	var tam = email.value.length;
	var valido = true;
	var pos1 = email.value.indexOf('@');
	var pos2 = email.value.indexOf('.');
	var pos3 = email.value.indexOf('.',pos1);
		
	for (i = 0;  i < tam;  i++)
	{
		ch = email.value.charAt(i);
		for (j = 0;  j < CaracValid.length;  j++)
		if (ch == CaracValid.charAt(j))
			break;
		if (j == CaracValid.length)
		{
			valido = false;
			break;
		}    
	}
			
	if((pos1 == -1) || (pos1 == 0) )
	{
		valido = false;
	}
	else
	{		
		if(email.value.indexOf('@',pos1+1)!=-1)
		{
			valido = false;
		}
	}
		
	if(tam<=pos1+1)
	{
		valido = false;
	}
		
	if(pos3 == -1)
	{
		valido = false;
	}
		
	if(tam<=pos3+1)
	{
		valido = false;
	}
		
	if(valido)
	{
		return(true);
	}
	else
	{
		return(false);
	}
}
// -------------------------------------------------------------------------------------
// Importado de fone.js
// -------------------------------------------------------------------------------------
function MascaraFone(campo,w)
{
   var Fone = SoNumero(campo.value);
   var FoneAux = ''; 
   var campo1 = campo.value;

  
   if (w.keyCode == 8) {      
     if (campo1.length == 3 || campo1.length == 7 || campo1.length == 11) {
        Fone = Fone.substr(0,Fone.length-1);
       } 
    }
     
   if ( (Fone.length > 8) && (Fone.substring(0,1) != '0'))
      Fone = '0' + Fone;
      
   if (Fone.length < 12) {
     
     for (var i=0; i< Fone.length; i++) {
       FoneAux = FoneAux + Fone.substr(i,1);     
       if (((i == 2) && (Fone.length <= 7)) || ((i == 3 ) && (Fone.length == 8))){
         FoneAux = FoneAux + "-";
        }
       if (Fone.length > 8){
         switch (i){
           case 1 : FoneAux = '(' + FoneAux; break;
           case 2 : FoneAux = FoneAux + ')'; break;
           case 5 : {
                     if ((Fone.length == 9) || (Fone.length == 10))
                       FoneAux = FoneAux + '-'; break;
                    }   
           case 6 : {
                     if (Fone.length == 11)
                       FoneAux = FoneAux + '-'; break;
                    }   
           default : '';
         } 
       }
      }
     campo.value = FoneAux;
    }
   else {
      campo.value = campo.value.substr(0,campo.value.length-1);
      if (campo.value.length > 13)
         campo.value = campo.value.substr(0,14);
     }    
}


function DesmascaraFone(nroFone)
{
     return SoNumero(nroFone);
}
// -------------------------------------------------------------------------------------
// Importado de funcoes.js
// -------------------------------------------------------------------------------------
function strZero(obj,nBytes)
{
   var strRetorno = obj.value.toString();
   if (obj.value.length != nBytes)
      for (var i=1;i<= nBytes - obj.value.length;i++)
         strRetorno = "0" + strRetorno;
  obj.value = strRetorno;
}


function Trim(obj)
{	
    Ltrim(obj);
    Rtrim(obj);
}


function Rtrim(obj) 
{
   varx = obj.value;
   while (varx.substr(varx.length - 1,1) == " ") 
   {
      varx = varx.substr(0, varx.length -1);
   }   
   obj.value = varx;
}


function Ltrim(obj) 
{
   varx = obj.value;
   while (varx.substr(0,1) == " ") 
   {
      varx = varx.substr(1, varx.length -1);
   }
  obj.value = varx;
}
// -------------------------------------------------------------------------------------
// Importado de numero.js
// -------------------------------------------------------------------------------------
function DigitaNumero(campo)
{
 var valid    = "0123456789";
 var numerook = "";
 var temp;
  
    
  for (var i=0; i< campo.value.length; i++) {
    temp = campo.value.substr(i, 1);
    if (valid.indexOf(temp) != "-1") 
      numerook = numerook + temp;
  }
   
 campo.value = numerook;

}

function FormatoMoeda(campo)
{
   
   var Moeda = SoNumero(campo.value);
   var MoedaAux = ''; 
   var campo1 = campo.value;
   var ponto = 3;

   
     for (var i=Moeda.length; i > 0; i--) {
     
       if ((i == Moeda.length - 2) && (Moeda.length > 2)){
         
         MoedaAux =  "," + MoedaAux;
         ponto = 3;
        }
       if ((ponto == 0) && (Moeda.length > 5)){
         MoedaAux =  '.' + MoedaAux;
         ponto = 3;
        }               
       MoedaAux = Moeda.substr(i-1,1) + MoedaAux;     
       ponto --;
      }  
     campo.value = MoedaAux;

}
// -------------------------------------------------------------------------------------
// Criado por Jose Humberto
// -------------------------------------------------------------------------------------
String.prototype.trim = function(){
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function focusNext(form, elemName, evt){
	evt = (evt) ? evt : event;
	var navegador=navigator.appName;
	var versao=navigator.appVersion;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if(navegador=='Microsoft Internet Explorer')
	{
			if (charCode == 13 || charCode == 3 ||charCode == 8){
					form.elements[elemName].focus();
			return false;
			}
	}

	return true;
}
function desabilitaCampo(form, elemName, evt,id){
	evt = (evt) ? evt : event;
	var navegador=navigator.appName;
	var versao=navigator.appVersion;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
		if(document.getElementById(id)!=null){
					if (charCode == 13 || charCode == 3 ||charCode == 8 ||charCode == 46){
						form.elements[elemName].focus();
					return false;
			}	
	
	}

	return true;
}
function autoFocus(field, next, evt){
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	
	if(field.id!='mensagemFaleConosco'){
	field.setAttribute('class','required');
	field.setAttribute('className','required');
	}
	else{
		field.setAttribute('class','requiredarea');
	field.setAttribute('className','requiredarea');
	}
	if (charCode > 31 && field.value.length == field.maxLength){
		field.form.elements[next].focus();
	}		
}
function validarEmail(elem){
	if (!ValidaEmail(elem)){
		elem.setAttribute('class','validationerror');
		elem.setAttribute('className','validationerror');
		alert(unescape('E-mail inv\u00E1lido!'));
		setTimeout("document."+elem.form.name+"."+elem.name+".focus()",100);
		return false;
	} else {
		return true;
	}
}
function validarFone(elem){
	var str =SoNumero(elem.value);
	if (str.length != 10 && str.length != 0){
		elem.setAttribute('class','validationerror');
		elem.setAttribute('className','validationerror');
		if(elem.id=='telefoneEmp'||elem.id=='telefoneRespLeg'||elem.id=='telefoneRespCad'||elem.id=='telefone')	{
			alert(unescape('Telefone inv\u00E1lido!'));
		}
		else{
			if(elem.id=='telefoneResidencial'){
				alert(unescape('Telefone residencial inv\u00E1lido!'));
			}
			else{
				if(elem.id=='telefoneComercial'){
					alert(unescape('Telefone comercial inv\u00E1lido!'));				
				}
				else{
					if(elem.id=='faxEmp'||elem.id=='fax'){
						alert(unescape('Fax inv\u00E1lido!'));
					}
					else{
						if(elem.id=='celular'){
							alert(unescape('Celular inv\u00E1lido!'));
						}					
					}					
				}

			}


		}
		setTimeout("document."+elem.form.name+"."+elem.name+".focus()",100);
		return false;
	} else {
		return true;
	}
}	
/*
function validarCEP(elem){
	var str = SoNumero(elem.value);
	if (str == '') return true;
	
	if (str.length != 8){
		elem.setAttribute('class','validationerror');
		elem.setAttribute('className','validationerror');
		alert('CEP inv?lido!');
		setTimeout("document."+elem.form.name+"."+elem.name+".focus()",100);
		return false;
	} else {
		elem.setAttribute('class','required');
		elem.setAttribute('className','required');
		buscaCEP(elem.value);
		
		document.getElementById('municipio').className='none';
		document.getElementById('uf').className='none';
		document.getElementById('municipio').style='texto_desabilitado';
	//document.getElementById('municipio').style.backgroundColor='white';
	//document.getElementById('municipio').style.borderColor='white';
	
	//document.getElementById('uf').style.backgroundColor='white';
	//document.getElementById('uf').style.borderColor='white';		
		return true;
	}
		if (elem.value == '') return true;
	
		var str = SoNumero(elem.value);
		if (str.length != 8){
			elem.setAttribute('class','erro');
			elem.setAttribute('className','erro');
			alert('CEP inv?lido!');
			setTimeout("document."+elem.form.name+"."+elem.name+".focus()",100);
			return false;
		} else {
			elem.setAttribute('class','required');
			elem.setAttribute('className','required');
			buscaCEP(elem.value);
			return true;
		}	
}	*/
function validarCPF(elem){
	if (!ValidaCPF(elem)){
		elem.setAttribute('class','validationerror');
		elem.setAttribute('className','validationerror');
		alert('CPF invalido!');
		setTimeout("document."+elem.form.name+"."+elem.name+".focus()",100);
		return false;
	} else {
		elem.setAttribute('class','required');
		elem.setAttribute('className','required');
		buscaCPF(elem.value);
		return true;
	}
}	

function isEmpty(elem){
	var str = elem.value;
	if (str == null || str.trim().length == 0){
		if(elem.id!='mensagemFaleConosco'){
		elem.setAttribute('class','validationerror');
		elem.setAttribute('className','validationerror');
		}
		else{
		elem.setAttribute('class','validationerrorTextAreaMensagemContato');
		elem.setAttribute('className','validationerrorTextAreaMensagemContato');		
		}
		return true;
	}
	return false;
}

function abrirJanelaCentralizada(pagina, nomedajanela, largura, altura, scrollbars, resizable) 
{

  var winl = (screen.width - largura) / 2;
  var wint = (screen.height - altura) / 2;
  winprops = 'height='+altura+',width='+largura+',top='+wint+',left='+winl+',status=no,scrollbars='+scrollbars+',resizable='+ resizable +',menubar=no';
 
  return window.open(pagina, nomedajanela, winprops);     

}

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div' );

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;
			
function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	
	cEl.style.fontSize = szs[ sz ];
	
	for ( i = 0; i < tgs.length; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0; j < cTags.length; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}


function carregarCss(){
document.getElementById('css').href='http://sisemanet.meioambiente.mg.gov.br/mbpo/plc/css/semad/semad.css';
}


