// JavaScript Document
	function Browser(){
		this.name = navigator.appName;
		if (this.name == 'Microsoft Internet Explorer') this.browser = 'ie';
		else if (this.name.match(/Netscape/)) this.browser = 'ns';
		else this.browser = this.name;
		this.version = parseInt(navigator.appVersion);
		this.ns = (this.browser=='ns' && this.version>=4);
		this.ns4 = (this.browser=='ns' && this.version==4);
		this.ns6 = (this.browser=='ns' && this.version>=5);
		this.ie = (this.browser=='ie' && this.version>=4);
		this.ie4 = (this.browser=='ie' && navigator.userAgent.indexOf('MSIE 4')>-1);
		this.ie5 = (this.browser=='ie' && navigator.userAgent.indexOf('MSIE 5')>-1);
		this.ie6 = (this.browser=='ie' && navigator.userAgent.indexOf('MSIE 6')>-1);
		if (this.ie5) this.version = 5;
		this.op5 = (navigator.userAgent.indexOf('Opera 5')>-1);
		if (this.op5){this.browser = 'op'}
		this.dom1 = (document.implementation && document.implementation.hasFeature)?true:false;
		this.os = (navigator.platform)?navigator.platform:'unknown';
		if (this.ie){ this.language = navigator.userLanguage.substring(0,2).toLowerCase() } else if (this.ns || this.op5) { this.language = navigator.language.substring(0,2).toLowerCase() }
		this.toString = function(){ return '[object Browser]'}
		return this;
	}
											
	function setOpacity(objId, i){
		b = new Browser();
		if (b.ie) {
			obj = document.all[objId];
			obj.style.filter = "alpha(opacity=" + i + ")";
		}
		else if (b.ns6) {
			obj = document.getElementById(objId);
			//obj.style.MozOpacity = i+'%';
			obj.style.MozOpacity = i/100;
		}
	}
	
	function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}

	function FormataValorDecimal(num) {
	
	   x = 0;
	
	   if(num<0) {
		  num = Math.abs(num);
		  x = 1;
	   }   if(isNaN(num)) num = "0";
		  cents = Math.floor((num*100+0.5)%100);
	
	   num = Math.floor((num*100+0.5)/100).toString();
	
	   if(cents < 10) cents = "0" + cents;
		  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			 num = num.substring(0,num.length-(4*i+3))+'.'
				   +num.substring(num.length-(4*i+3));   ret = num + ',' + cents;   if (x == 1) ret = ' - ' + ret;return ret;
	
	}
	
	function showFocus(obj)
	{
		if(!document.getElementById)
			return; // else do the thing
		//obj.style.border = "1px solid #396224";
		obj.style.background = "#FFFFCC";
		obj.value = obj.value.toUpperCase();
	}
	
	function showBlur(obj)
	{
		if(!document.getElementById)
			return; // else do the thing
		//obj.style.border = "1px solid #666666";
		obj.style.background = "#FFFFFF";
		obj.value = obj.value.toUpperCase();
	}
	
	function showFocusChekBox(obj)
	{
		if(!document.getElementById)
			return; // else do the thing
		obj.style.border = "1px dashed #666666";
	}
	
	function showBlurChekBox(obj)
	{
		if(!document.getElementById)
			return; // else do the thing
		obj.style.border = "none";
	}
	
	function Sistema(q,CdU,Tw,Th) {
		var Tw1 = (screen.width - Tw) / 2;
		var Th1 = (screen.height - Th) / 2;
		window.open('/SysCon/Login/?Q=' + q + '&CdU=' + CdU,'Sistema','width=' + (screen.width - 10) + ',height=' + (screen.height - 80) + ',top=0,left=0,scrollbars=yes');
	}

	// para valores numéricos
	function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
	aux = validos.indexOf(valor.substring(i, i+1));
	if (aux>=0) {
	result += aux;
	}
	}
	return result;
	}
	
	//Formata número tipo moeda usando o evento onKeyDown
	
	function Formata(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	
	if (tecla == 8 )
	   { tam = tam - 1 ; }
	
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
	dec=2
	if ( tam <= dec )
	{ campo.value = vr ; }
	
	if ( (tam > dec) && (tam <= 5) ){
	campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ;}
	if ( (tam >= 6) && (tam <= 8) ){
	campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;}
	if ( (tam >= 9) && (tam <= 11) ){
	campo.value = vr.substr( 0, tam  - 8 ) + "." + vr.substr( tam  - 8, 3 ) +  "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;}
	if ( (tam >= 12) && (tam <= 14) ){
	campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;}
	if ( (tam >= 15) && (tam <= 17) ){
	campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	} 
	
	}
	
	var dFilterStep;
	
	function dFilterStrip (dFilterTemp, dFilterMask) {
		dFilterMask = replace(dFilterMask,'#','');
		for (dFilterStep = 0; dFilterStep < dFilterMask.length++; dFilterStep++)
			{
				dFilterTemp = replace(dFilterTemp,dFilterMask.substring(dFilterStep,dFilterStep+1),'');
			}
			return dFilterTemp;
	}
	
	function dFilterMax (dFilterMask) {
			dFilterTemp = dFilterMask;
		for (dFilterStep = 0; dFilterStep < (dFilterMask.length+1); dFilterStep++)
			{
					if (dFilterMask.charAt(dFilterStep)!='#')
					{
					dFilterTemp = replace(dFilterTemp,dFilterMask.charAt(dFilterStep),'');
					}
			}
			return dFilterTemp.length;
	}
	
	function dFilter (key, textbox, dFilterMask) {
	   dFilterNum = dFilterStrip(textbox.value, dFilterMask);
			
	   if (key==9) {
		  return true;
	   }
	   else if (key==8&&dFilterNum.length!=0) {
		  dFilterNum = dFilterNum.substring(0,dFilterNum.length-1);
	   }
	   else if ( ((key>47&&key<58)||(key>95&&key<106)) && dFilterNum.length<dFilterMax(dFilterMask) ) {
		  dFilterNum=dFilterNum+String.fromCharCode((key>95&&key<106) ? key-48 : key);
	   }
	
	   var dFilterFinal='';
	   for (dFilterStep = 0; dFilterStep < dFilterMask.length; dFilterStep++) {
		  if (dFilterMask.charAt(dFilterStep)=='#') {
			 if (dFilterNum.length!=0) {
				dFilterFinal = dFilterFinal + dFilterNum.charAt(0);
				dFilterNum = dFilterNum.substring(1,dFilterNum.length);
			 }
			 else {
				dFilterFinal = dFilterFinal + "";
			 }
		  }
		  else if (dFilterMask.charAt(dFilterStep)!='#') {
			 dFilterFinal = dFilterFinal + dFilterMask.charAt(dFilterStep); 			
		  }
	   }
	
	   textbox.value = dFilterFinal;
	   return false;
	}

	function replace(fullString,text,by) {
	// Replaces text with by in string
		var strLength = fullString.length, txtLength = text.length;
		if ((strLength == 0) || (txtLength == 0)) return fullString;
	
		var i = fullString.indexOf(text);
		if ((!i) && (text != fullString.substring(0,txtLength))) return fullString;
		if (i == -1) return fullString;
	
		var newstr = fullString.substring(0,i) + by;
	
		if (i+txtLength < strLength)
			newstr += replace(fullString.substring(i+txtLength,strLength),text,by);
	
		return newstr;
	}
	
	function vProcess(icod){
		
		if(icod == 1){
			document.getElementById('Process').style.visibility = 'visible';
			setOpacity('Process',50);
		}
		if(icod == 0){
			document.getElementById('Process').style.visibility = 'hidden';
		}
	}
	
	function isNumber(txtField){
	  numExp = txtField.value;
	  if (isNaN(numExp) || (numExp.length == 0)){
		txtField.value = '';
		}
	  return false;
	}
	
	function TxtMsgBox(vMsg){
		var vBox = document.getElementById('messages');
		if (vMsg != ''){
			vBox.innerHTML = '<strong>' + vMsg + '</strong>';
			vBox.style.background = '#FFF8EC';
			vBox.style.border = '1px solid #FF9900';
			vBox.style.padding = '8px';
			vBox.style.width = '60%';
			vBox.style.color = '#006600';
			return false;
		}
		vBox.innerHTML = '';
		vBox.style.background = 'transparent';
		vBox.style.border = '0px';
		vBox.style.width = '1px';
	}

	function Voip0800(Tw,Th) {
	var Tw1 = (screen.width - Tw) / 2;
	var Th1 = (screen.height - Th) / 2;
	  window.open('/Includes/0800.asp','0800','width=' + Tw + ',height=' + Th + ',top=' + Th1 + ',left=' + Tw1 + ',scrollbars=no');
	}
	
	function VerFotoCentroPage(iFoto){
		document.getElementById('ViewFotoFundo').style.visibility = 'visible';
		setOpacity('ViewFotoFundo','80');
		document.getElementById('ViewFoto').style.visibility = 'visible';
		document.getElementById('FotografiaCentro').src = iFoto;
		}
		
	function FechaFotoCentroPage(){
		document.getElementById('FotografiaCentro').src = '/Img/loading.gif';
		document.getElementById('ViewFotoFundo').style.visibility = 'hidden';
		document.getElementById('ViewFoto').style.visibility = 'hidden';
		}
