///////////////////////////////////////////////////////////////////////////////
/////////////////////// INICIALIZAÇÃO DE OBJETOS GLOBAIS //////////////////////
///////////////////////////////////////////////////////////////////////////////
/**
	 Variabeis Globais de Interface de Comunicação xFWeb
*/
var IE = false;
if (document.all) {IE = true;}

var _documentAll = null;
function DocumentAll() {
	if (_documentAll==null) {
		if (IE) {
			_documentAll = document.all;
		}else{
    		 document.all = (document.all) ? document.all : 
          ((document.getElementsByTagName("*").length > 0) ?
          document.getElementsByTagName("*") : null)
			_documentAll = document.all;
		}	
	}
	return _documentAll;
}
//alert(DocumentAll);
DocumentAll = new DocumentAll();
var XFWEB_LOADED = false;
var xFWebObject;
var xFWebBehaviors;
var Validation;
var util;
var PATH_SYSTEM_DIALOG = "../../core/components/Dialogs/SystemDialog.jsp";
var globalObjetosxFWeb;
var xFWebSearch;
var xFWeb;
var request;
var layout;
//configuracoes
var MENSAGEM_OBRIGATORIO = "O campo é obrigatório, favor preencher.";
var TIPO_VALIDACAO = "TEXT:DATE:TIME:DATE_TIME:DIA_MES:INTEGER:SELECTED:POSITIVE_INTEGER:"+
					 "PASSWORD:REAL:EMAIL:CREDIT_CARD:IP:CEP:URL:CPF:CNPJ:SEQUENCE:YEAR:"+
					 "MATRICULA_SERVIDOR:POPULATED:CLASSIFICACAO_ORCAMENTARIA:VARIABLE";
/** Instancia do objeto de validacao */
util = new util();
xFWebBehaviors = new xFWebBehaviors();
xFWebObject = new xFWebObject();
Validation = new Validation();




///////////////////////////////////////////////////////////////////////////////
///////////////////////////// INTERFACE ICOMXML ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////
function iAttributexFWeb() {
	/** Referencia do Objeto HTML */
	this.objeto;
	/** Tipo de Objeto HTML */
	this.tipo;
}
function formatar(src, mask) {
var i = src.length;
var saida = mask.substring(i,i+1);
var ascii = event.keyCode;
if (saida == "A") {
if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
else { event.keyCode = 0; }
} else if (saida == "0") {
if ((ascii >= 48) && (ascii <= 57)) { return }
else { event.keyCode = 0 }
} else if (saida == "#") {
return;
} else {
src += saida;
i += 1
saida = mask.substring(i,i+1);
if (saida == "A") {
if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
else { event.keyCode = 0; }
} else if (saida == "0") {
if ((ascii >= 48) && (ascii <= 57)) { return }
else { event.keyCode = 0 }
} else { return; }
}
}

function xFWebBehaviors() {

this.CNPJ = function CNPJ() 
{ 
//	this.value = formatar(this.value,'000.000.000-00');
	IE4 = (document.all);
	NS4 = (document.layers);
	
	if (NS4) document.captureEvents(Event.KEYPRESS);

//	whichASC = (NS4) ? e.which : event.keyCode;
//	tecla = String.fromCharCode(whichASC).toLowerCase();
	tecla = (NS4) ? e.which : event.keyCode;

var vr = new String(this.value); 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace("/", ""); 
vr = vr.replace("-", ""); 
tam = vr.length + 1 ; 
if(tecla != 9 && tecla !=8){ 
if(tam > 2 && tam < 6)
this.value = vr.substr(0, 2) + '.' + vr.substr(2, tam); 
if(tam >= 6 && tam < 9) 
this.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5); 
if(tam >= 9 && tam < 13) 
this.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8); 
if(tam >= 13 && tam < 15)
this.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12); 
}
}

this.CPF = function CPF() 
{ 
//	this.value = formatar(this.value,'000.000.000-00');
	IE4 = (document.all);
	NS4 = (document.layers);
	
	if (NS4) document.captureEvents(Event.KEYPRESS);

//	whichASC = (NS4) ? e.which : event.keyCode;
//	tecla = String.fromCharCode(whichASC).toLowerCase();
	tecla = (NS4) ? e.which : event.keyCode;

var vr = this.value; 
vr = vr.replace(".", ""); 
vr = vr.replace(".", ""); 
vr = vr.replace("-", ""); 
tam = vr.length + 1; 
if(tecla != 9 && tecla !=8){ 
if(tam > 3 && tam < 7) 
this.value = vr.substr(0, 3) + '.' + vr.substr(3, tam); 
if(tam >= 7 && tam <10) 
this.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6); 
if(tam >= 10 && tam < 12) 
this.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9); 
} 

} 

this.REAL = function REAL() {
	/***
	*	A proprierada maxlength desse tipo de campo deve ser 16.
	*****/

//	alert('REAL');
//	fVal = this.value.replace(/[^\d\.]/g, "")*1;

	IE4 = (document.all);
	NS4 = (document.layers);
	
	if (NS4) document.captureEvents(Event.KEYPRESS);

//	whichASC = (NS4) ? e.which : event.keyCode;
//	tecla = String.fromCharCode(whichASC).toLowerCase();
	tecla = (NS4) ? e.which : event.keyCode;
	var tammax;

	if (this.value.maxlength)	tammax = this.value.maxlength;
	else tammax = 13;



	vr = this.value;

	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8)	tam = vr.length + 1 ; 
	// Backspace
	if ( tecla == 8 ) tam = tam - 1;

						 // >= 48 && <= 57 sao numeros // ?????
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
		if ( tam <= 2 ){ 
	 		this.value = vr ; 
		}
	 	if ( (tam > 2) && (tam <= 5) ) {
			this.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		this.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		this.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 12) && (tam <= 14) ){
			if ( tam != tammax )
			 	this.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; 
		}
	 	if ( (tam >= 15) && (tam <= 17) ) {
	 		this.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 ) ;
		}
	}
		
		/*
		if (this.maxlength) {
			tammax = this.maxlength;
		}else{
			tammax = 250
		}
		campo = this;
		var tecla = window.event.keyCode;
		vr = campo.value;
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
		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 ){
			if ( tam <= 2 ){ 
		 		campo.value = vr ; }
		 	if ( (tam > 2) && (tam <= 5) ){
		 		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
		 	if ( (tam >= 6) && (tam <= 8) ){
		 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 ) ;}
		}		
		*/
}
	this.DATE = function DATE() {
		var teclapres = window.event;
		var tecla = teclapres.keyCode;
		var Campo = this;
		vr = Campo.value;
		vr = vr.replace( ".", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length + 1;
		if ( tecla != 9 && tecla != 8 ){
			if ( tam > 2 && tam < 5 )
				Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
			if ( tam >= 5 && tam <= 10 )
				Campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
	}
	
		this.DIA_MES = function DIA_MES() {
		var teclapres = window.event;
		var tecla = teclapres.keyCode;
		var Campo = this;
		vr = Campo.value;
		vr = vr.replace( ".", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		tam = vr.length + 1;
		if ( tecla != 9 && tecla != 8 ){
			if ( tam == 3 || tam == 4)
				Campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		}
	}

	this.CEP = function CEP() {
		var teclapres = window.event;
		var tecla = teclapres.keyCode;
		var Campo = this;
		vr = Campo.value;
		vr = vr.replace( "-", "" );		
		tam = vr.length + 1;		
			if (tecla != 8){
				if(tam == 6)Campo.value = vr.substr( 0, tam - 1  ) + '-' + vr.substr( tam - 1, tam );
			}
	}


	this.MATRICULA_SERVIDOR = function MATRICULA_SERVIDOR() {
		var tecla = window.event.keyCode;
		var Campo = this;
		vr = Campo.value;
		tam = vr.length+1;
		if (tecla != 8) {
			if ((tam==3) || (tam == 7)) {
				Campo.value = vr + ".";
			}
			if (tam ==11) {
				Campo.value = vr + "-";
			}
		}
	}
	this.onKeyDown = function onKeyDown() {
		var maskValue = xFWebObject.searchAttribute(this);
		if (maskValue != "") {
			if (Validation.isValidacao(this)) {
				try {
					eval("this.onkeydown = xFWebBehaviors."+maskValue.toUpperCase());
//					this.onkeydown = xFWebBehaviors.REAL;
				}
				catch(ex){}
			}
			else {
				util.logxFWebException(ex,"A validação [" + maskValue + "] não é valida para o Template xFWeb.");
				return false;					
			}
		}
//		return false;
	}
}
function xFWebObject() {
	/**
		Método que retorna um objeto xFWeb encontrado no documento HTML
	*/
	this.searchAttribute = function searchAttribute(obj) {
			if (IE) {
				if (obj.mask) {return obj.mask;}
				if (obj.MASK) {return obj.MASK;}
				if (obj.Mask) {return obj.Mask;}
			}else{
				if (obj.getAttribute("mask")!=null){
					return obj.getAttribute("mask");
				}
			}
			return "";
	}
	/**
		Método que retorna um array de objetos xFWeb encontrados no documento HTML
	*/
 	this.getObjects = function getObjects() {
		try {
			if (!globalObjetosxFWeb) {
			 	var arrayObjectsHTML = new Array();
				var indexArray = 0;
				var ObjetoBuscaHTML;
				for (t=0;t<DocumentAll.length;t++) {
					ObjetoBuscaHTML = DocumentAll.item(t);
					 	 if (this.searchAttribute(ObjetoBuscaHTML) != "") {
							eval("itemObjetoQ" + indexArray + " = new iAttributexFWeb()");
							eval("itemObjetoQ" + indexArray + ".objeto = ObjetoBuscaHTML");
							eval("itemObjetoQ" + indexArray + ".tipo = ObjetoBuscaHTML.type");
						 	eval("arrayObjectsHTML[indexArray] = itemObjetoQ" + indexArray );
							indexArray++;
					}
				}
				globalObjetosxFWeb = arrayObjectsHTML;				
			}
			return globalObjetosxFWeb;
		}catch(ex){
			util.logxFWebException(ex,"xFWebObject.getObjects");
		}
	 }
	 this.loadBehaviors = function() {
		var LoadArrayObjectsxFWeb = xFWebObject.getObjects();
		for(var i=0;i<LoadArrayObjectsxFWeb.length;i++) {
			if (!LoadArrayObjectsxFWeb[i].objeto.onKeyDown) {
			 	LoadArrayObjectsxFWeb[i].objeto.onkeydown = xFWebBehaviors.onKeyDown;
			}
		}
	 }

 }

 
 
///////////////////////////////////////////////////////////////////////////////
///////////////////////////// UTILITÁRIO xFWeb //////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/**
	Interface de tratamento de exeções e utilitario
*/

	function eventHandle()
	{
		var eObj=window.event.srcElement;
		if (eObj.id==objName)
		{
			window.event.returnValue=false;
			if (waitingWin!=null) waitingWin.close();
			eObj.detachEvent(dEventName, eventHandle)
		}
	}

	var sDialogReturn;
	
	
	function xFWebWindowAlert(icon, msg, w, h, btns, rtn)
	{
		//var docTitle=escape(document.title);

		var docTitle="";
		 sDialogReturn="";

		if (w==0) w=380; if (h==0) h=200; width=w; height=h;

		lPos = (screen.width)/2 -(width/2);
		tPos = (screen.height)/2 -(height/2);

		var		url =  PATH_SYSTEM_DIALOG+"?icon="+icon+"&msg="+util.URLEncode(msg)+"&btns="+btns+"&title="+docTitle; 
		//scroll:no;
		if (IE) {
AlertModel=window.showModalDialog(url,window,"dialogLeft:"+lPos+";dialogTop:"+tPos+"; dialogHeight: "+height +"px; dialogWidth: "+width+"px; edge: Raised; center: Yes; help: no; resizable: no; status: no;");
		}else{
		
		AlertModel = window.open(url,"window","left=250,top=250,alwaysRaised,hotkeys=no,width="+width+",height="+height); 		
		
		}
		if (!AlertModel) { if (sDialogReturn && rtn) return sDialogReturn; }
	}

	var waitingWin;	
	var objName;
	var dEventName;

	function waitingDlg(dlgType, msg, w, h, sCloseEvent, objID)
	{
		var docTitle=document.title;
		objName=objID; dEventName=sCloseEvent;
		obj=document.getElementById(objID);
		if (obj!=null) obj.attachEvent(sCloseEvent, eventHandle);
		if (w==0) w=380; if (h==0) h=200; width=w; height=h;

		lPos = (screen.width)/2 -(width/2);
		tPos = (screen.height)/2 -(height/2);

		return waitingWin=window.showModelessDialog(PATH_SYSTEM_DIALOG+"?msg="+msg+"&title="+docTitle+"&dlgType="+dlgType,window,"dialogLeft:"+lPos+";dialogTop:"+tPos+"; dialogHeight: "+height +"px; dialogWidth: "+width+"px; edge: Raised; center: Yes; help: no; resizable: no; status: no;");
	}

	function closeWait()
	{
		if (waitingWin!=null) waitingWin.close();
	}

function util() {

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/


/*
// VERIFICAR O PROJETO QUE UTILIZA ESTA FUNÇÃO, REVER POIS EXISTE UMA OUTRA DECLARAÇÃO DE SETCOOKIE QUE ESTÁ GERANDO CONFLIXO
this.setCookie = function setCookie(name, value, path, expires, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
*/

this.setCookieWithParameter = function setCookieWithParameter(name, value, path, expires, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

this.getCookie = function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

this.deleteCookie = function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

this.fixDate = function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}






	this.URLEncode = function URLEncode(plaintext)
		{
			var SAFECHARS = "0123456789" +					
							"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	
							"abcdefghijklmnopqrstuvwxyz" +
							"-_.!~*'()";					
			var HEX = "0123456789ABCDEF";
		
			var encoded = "";
			for (var i = 0; i < plaintext.length; i++ ) {
				var ch = plaintext.charAt(i);
				if (ch == " ") {
					encoded += "+";				
				} else if (SAFECHARS.indexOf(ch) != -1) {
					encoded += ch;
				} else {
					var charCode = ch.charCodeAt(0);
					if (charCode > 255) {						
						encoded += "+";
					} else {
						encoded += "%";
						encoded += HEX.charAt((charCode >> 4) & 0xF);
						encoded += HEX.charAt(charCode & 0xF);
					}
				}
			} 
		
			return encoded;
		};
		
		this.URLDecode  = function URLDecode( encoded )
		{
		   var plaintext = "";
		   var i = 0;
		   while (i < (encoded.length-2)) {
			   var ch = encoded.charAt(i);
			   if (ch == "+") {
				   plaintext += " ";
				   i++;
			   } else if (ch == "%" && encoded.charAt(i+1) != "%") {
				   plaintext += unescape( encoded.substr(i,3) );
				   i += 3;
				} else {
				   plaintext += ch;
				   i++;
				}
			} 
			if (i < encoded.length) {
				plaintext += encoded.substr(i,encoded.length-i);
			}
		   return unescape(plaintext);
		}

	

	this.getFloatValue = function getFloatValue(newValor){
	if (newValor.indexOf(".")>0) {
		newValor = newValor.replace(".","");	
		newValor = newValor.replace(".","");	
		newValor = newValor.replace(".","");	
		newValor = newValor.replace(".","");	
		newValor = newValor.replace(".","");	
		newValor = newValor.replace(".","");	
		newValor = newValor.replace(".","");	
	}
	if (newValor.indexOf(",")>0) {
		newValor = util.replace(newValor,",",".");
	}
	return parseFloat(newValor);	
}

	this.formatCurrency = function formatCurrency( num ) {
        var isNegative = false;
        num = num.toString().replace(/\\$|\\,/g,'');
        if( isNaN( num ) ) {
          num = "0";
        }
        if ( num < 0 ) {
          num = Math.abs( num );
          isNegative = true;
        }
        cents = Math.floor( ( num * 100 + 0.5 ) % 100 );
        num = Math.floor( ( num * 100 + 0.5 ) / 100 ).toString();
        if ( cents < 10 ) {
          cents = "0" + cents;
        }
        for ( 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 ) );
        }

//        var result = '$' + num + ',' + cents;
        var result = num + ',' + cents;
        if ( isNegative ) {
          result = "-" + result;
        }
        return result;
      }



	/**
		Remove espaços em branco
	*/
	this.WindowInformation = function(msg){
		xFWebWindowAlert('dvuInformation', msg, 310,175,'dvuOKOnly');
	}
	this.WindowExclamation = function(msg){
		xFWebWindowAlert('dvuExclamation', msg, 310,175,'dvuOKOnly');
	}
	this.WindowCritical = function(msg){
		xFWebWindowAlert('dvuCritical', msg, 310,175,'dvuOKOnly');
	}
	this.WindowQuestion = function(msg){
		xFWebWindowAlert('dvuQuestion', msg, 310,175,'dvuOKOnly');
	}
	this.WindowOkCancel = function(msg){
		xFWebWindowAlert('dvuQuestion', msg, 310,175,'dvuOKCancel');
	}

	this.WindowAbortRetryIgnore = function(msg){
		xFWebWindowAlert('dvuQuestion', msg, 310,175,'dvuAbortRetryIgnore');
	}

	this.WindowYesNoCancel = function(msg){
		xFWebWindowAlert('dvuQuestion', msg, 310,175,'dvuYesNoCancel');
	}
	this.WindowYesNo = function(msg){
		xFWebWindowAlert('dvuQuestion', msg, 310,175,'dvuYesNo');
	}
	this.WindowRetryCancel = function(msg){
		xFWebWindowAlert('dvuQuestion', msg, 310,175,'dvuRetryCancel');
	}
	
	this.trim = function trim( strValue ) {
		 var objRegExp = /^(\s*)$/;
		    if(objRegExp.test(strValue)) {
		       strValue = strValue.replace(objRegExp, '');
		       if( strValue.length == 0)
		          return strValue;
		    }
		   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
		   if(objRegExp.test(strValue)) {
		       strValue = strValue.replace(objRegExp, '$2');
		    }
		  return strValue;
	}


	this.saveFieldTextToCookie = function saveFieldTextToCookie(refObj){
		try {
			var objName = refObj.name;
			var name = util.replace(location.pathname,"/","_");
			name = util.replace(name,"-","_");
			name = name.substring(0,name.length-3)+objName;
			setCookie(name,refObj.value,2);
		}catch(ex){}
	}

	this.restoreFieldTextFromCookie = function restoreFieldTextFromCookie(checked,fields){
		try {
			var aField = fields.split(",");
			var urlName = util.replace(location.pathname,"/","_");
			urlName = util.replace(urlName,"-","_");
			urlName = urlName.substring(0,urlName.length-3);
			for(var i=0;i<aField.length;i++){
				var name = aField[i];
				try {
					if (checked){
						var valor = getCookie(urlName+name);
						if (valor!=null){
							document.all[name].value = valor;
						}
					}else{
						document.all[name].value = "";
					}
				}
				catch (ex2){}
			}
		}catch(ex){}
	}

	this.extenso = function extenso(c) {
	c = this.trim(c);
	c = c.replace( ".", "" );
	c = c.replace( ".", "" );
	c = c.replace( ".", "" );
	c = c.replace( ".", "" );
	c = c.replace( ".", "" );
	c = c.replace( ".", "" );
	c = c.replace( ".", "" );

	if (c==""){
		return "";
	}
	if(c < 0 || c >=10000000)
		{
		return("NÃO SUPORTADO");
		}
	else
		{
		if(c == 0)
			{
			return(" ZERO ");
			}
		else
			{
			aUnid = new Array();
			aDezena = new Array();
			aCentena = new Array();
			aGrupo = new Array();
			aTexto = new Array();
			
			aUnid[1] = "UM ";
			aUnid[2] = "DOIS ";
			aUnid[3] = "TRÊS ";
			aUnid[4] = "QUATRO ";
			aUnid[5] = "CINCO ";
			aUnid[6] = "SEIS ";
			aUnid[7] = "SETE ";
			aUnid[8] = "OITO ";
			aUnid[9] = "NOVE ";
			aUnid[10] = "DEZ ";
			aUnid[11] = "ONZE ";
			aUnid[12] = "DOZE ";
			aUnid[13] = "TREZE ";
			aUnid[14] = "QUATORZE ";
			aUnid[15] = "QUINZE ";
			aUnid[16] = "DEZESSEIS ";
			aUnid[17] = "DEZESETE ";
			aUnid[18] = "DEZOITO ";
			aUnid[19] = "DEZENOVE ";

			aDezena[1] = "DEZ ";
			aDezena[2] = "VINTE ";
			aDezena[3] = "TRINTA ";
			aDezena[4] = "QUARENTA ";
			aDezena[5] = "CINQÜENTA ";
			aDezena[6] = "SESSENTA ";
			aDezena[7] = "SETENTA ";
			aDezena[8] = "OITENTA ";
			aDezena[9] = "NOVENTA ";

			aCentena[1] = "CENTO ";
			aCentena[2] = "DUZENTOS ";
			aCentena[3] = "TREZENTOS ";
			aCentena[4] = "QUATROCENTOS ";
			aCentena[5] = "QUINHENTOS ";
			aCentena[6] = "SEISCENTOS ";
			aCentena[7] = "SETECENTOS ";
			aCentena[8] = "OITOCENTOS ";
			aCentena[9] = "NOVECENTOS ";

			if(c.indexOf(".") != -1)
				{
				aGrupo[4] = c.substring(c.indexOf(".")+1,c.length);
				aGrupo[4] = aGrupo[4].substring(0,2);
				ct = c.substring(0,c.indexOf("."));
				}
			else
				{
				if(c.indexOf(",") != -1)
					{
					aGrupo[4] = c.substring(c.indexOf(",")+1,c.length);
					aGrupo[4] = aGrupo[4].substring(0,2);
					ct = c.substring(0,c.indexOf(","));
					}
				else
					{
					aGrupo[4] = "00";
					ct = c;
					}
				tt = "";
				for(f=0;f<(10-ct.length);f++)
					{
					tt += "0";
					}
				tt += ct;
				}
			aGrupo[1] = tt.substring(1,4);
			aGrupo[2] = tt.substring(4,7);
			aGrupo[3] = tt.substring(7,10);
			aGrupo[4] = "0"+aGrupo[4];

			for(f=1;f<5;f++)
				{
				cParte = aGrupo[f];
				if(parseFloat(cParte) < 10)
					{
					nTamanho = 1;
					}
				else
					{
					if(parseFloat(cParte) < 100)
 						{
						nTamanho = 2;
						}
					else
						{
						if(parseFloat(cParte) < 1000)
							{
							nTamanho = 3;
							}
						else
							{
							nTamanho = 0;
							}
						}
					}
				aTexto[f] = "";
				if(nTamanho == 3)
					{
					if(cParte.substring(1,3) != "00")
						{
						aTexto[f] += aCentena[cParte.substring(0,1)] + "E ";
						nTamanho = 2;
						}
					else
						{
						if(cParte.substring(0,1) == "1")
							{
							aTexto[f] += "CEM ";
							}
						else
							{
							aTexto[f] += aCentena[cParte.substring(0,1)];
							}
						}
					}
				if(nTamanho == 2)
					{
					if(parseFloat(cParte.substring(1,3)) < 10)
						{
						aTexto[f] += aUnid[cParte.substring(2,3)];
						}
					else
						{
						if(parseFloat(cParte.substring(1,3)) < 20)
							{
							aTexto[f] += aUnid[cParte.substring(1,3)];
							}
						else
							{
							aTexto[f] += aDezena[cParte.substring(1,2)];
							if(cParte.substring(2,3) != "0")
								{
								aTexto[f] += "E ";
								nTamanho = 1;
								}
							}
						}
					}
				if(nTamanho == 1)
					{
					aTexto[f] += aUnid[cParte.substring(2,3)];
					}
				}
			if(parseFloat(aGrupo[1] + aGrupo[2] + aGrupo[3]) == 0 && parseFloat(aGrupo[4]) != 0)
				{
				cFinal = aTexto[4];
				if(parseFloat(aGrupo[4]) == 1)
					{
					cFinal +=  "CENTAVO";
					}
				else
					{
					cFinal +=  "CENTAVOS";
					}
				}
			else
				{
				if(parseFloat(aGrupo[1]) != 0)
					{
					cFinal = aTexto[1];
					if(parseFloat(aGrupo[1]) > 1)
						{
						cFinal += "MILHÕES ";
						}
					else
						{
						cFinal += "MILHÃO ";
						}
					if(parseFloat(aGrupo[2] + aGrupo[3]) == 0)
						{
						cFinal += "DE ";
						}
					else
						{
						cFinal += "E ";
						}
					}
				else
					{
					cFinal = "";
					}
				if(parseFloat(aGrupo[2]) != 0)
					{
					cFinal += aTexto[2] + "MIL ";
					if(parseFloat(aGrupo[3]) != 0)
						{
						cFinal += "E ";
						}
					}
				if(parseFloat(aGrupo[3]) != 0)
					{
					cFinal += aTexto[3];
					}
				if(parseFloat(aGrupo[1] + aGrupo[2] + aGrupo[3]) == 1)
					{
					cFinal += "REAL";
					}
				else
					{
					cFinal += "REAIS";
					}
				if(parseFloat(aGrupo[4]) != 0)
					{
					cFinal += " E "+aTexto[4];
					if(parseFloat(aGrupo[4])==1)
						{
						cFinal += "CENTAVO";
						}
					else
						{
						cFinal += "CENTAVOS";
						}
					}
				}
			return(cFinal);
			}
		}
	}
	/**
		Substitui Padrão
	*/
	this.replace = function replace(strOrigem,strPadrao,strValor) {
		var regExpressao = new RegExp (strPadrao, "gi");
		return strOrigem.replace(regExpressao, strValor);
	}
	this.containsArray = function containsArray(pArray,key){
		for (i=0; i < pArray.length; i++) {   
			if (pArray[i]==key){
				return i;
			}
		}
		return -1;
	}



this.openMaxWindow = function openMaxWindow( aURL, aWinName )
{
   var wOpen;
   var sOptions;

   sOptions = 'toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,screenX=0,screenY=0,resizable=0';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}


	this.windowMoveToCenter = function windowWidth(w,h){
		lPos = (screen.width)/2 -(w/2);
		tPos = (screen.height)/2 -(h/2);
		window.moveTo(lPos,tPos);	
		window.resizeTo(w,h);
	}
	this.windowWidth = function windowWidth(){
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement &&
			  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		  return myWidth;
//		  window.alert( 'Height = ' + myHeight );
	}
	

	this.checkUncheck = function checkUncheck(obj,search){
		var objCheck = document.all['CHK-'+search];
		if (objCheck.length!=undefined){
			for(var i=0;i<objCheck.length;i++){
				if (!objCheck[i].disabled) {
					objCheck[i].checked = obj.checked;
					checkRecord(search,objCheck[i],'M');
				}
			}
		}else{
			if (!objCheck.disabled) {
				objCheck.checked = obj.checked;
				checkRecord(search,objCheck,'M');
			}
		}
	}



	this.openURLWithRecord = 	function openURLWithRecord(srcURL,search){
		var OId = xFWebSearch.getRecordId(search);
		if (OId!="") {
			if (OId.indexOf(",")!=-1){
				util.WindowExclamation("Selecione apenas um registro para esta operação.");
			}else{
				if (srcURL.indexOf("?")!=-1) {
					location.href=srcURL+'&OId='+OId;		
				}else{
					location.href=srcURL+'?OId='+OId;		
				}
			}			
		}else{
			util.WindowExclamation("Selecione um registro para esta operação.");
		}
	}



this.checkRecord = function checkRecord(searchName,obj,tipoEscolha){
	try {
		//Tipos de escolhas: [U] único e [M] multiplos
		if (tipoEscolha == "M") {
//			var value = nameLine.substr(3,nameLine.length); 
			var value = obj.value; 
			var index = util.containsArray(arrayMultipleLine,value);
			var removed = false;
			if (index==-1){
				arrayMultipleLine.push(value);
			}else{
				removed = arrayMultipleLine.splice(index, 1);
			}
			var sMultipleLine = "";
			for (i=0; i < arrayMultipleLine.length; i++) {   
				sMultipleLine += arrayMultipleLine[i]+",";
			}
			sMultipleLine = sMultipleLine.substring(0,sMultipleLine.length-1);
			if (document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"]!=undefined){
			document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value = sMultipleLine;
			}
		}else{
			if (obj.checked){
				if (searchName!=undefined && searchName!=null && 	document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"]!=undefined) {
					document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value = obj.value;
				}

			}else{
				if (searchName!=undefined && searchName!=null && 	document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"]!=undefined) {
					document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value = "";
				}
			}

		}
	}catch(ex){
		util.logxFWebException(ex,"Erro na função de seleção de linha");
	}
}



	this.windowHeight = function windowHeight(){
		  var myWidth = 0, myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if( document.documentElement &&
			  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		return myHeight;
	}
	
	this.logxFWebException = function logxFWebException(objErro,objOrigem){
		if (objErro.name!=null) {
			alert("[" + objOrigem + "] (" + objErro.lineNumber + ") [ " + objErro.name + " ] " + objErro.description);
		}else{
			alert("[" + objErro + "] - " + objOrigem);		
		}
	}
	this.getBodyIframe = function getBodyIframe(nameIframeConteudo) {
		var strCorpo = nameIframeConteudo+".document.body";
		var oRet = eval(strCorpo);
		return oRet;
	}
	this.getDocumentIframe = function getDocumentIframe(nameIframeConteudo) {				
		var strCorpo = nameIframeConteudo+".document";
		var oRet = eval(strCorpo);
		return oRet;
	}
	this.addOption = function addOption(objLst,objOption,newValue,selected){
		if (arguments.length==4){
			selected = arguments[3];
		}else{
			selected = objOption.selected;
		}
		if (objLst.length != -1) {
			if (arguments[2]) {
		    	objLst.options[objLst.length] = new Option(objOption.text,newValue,false,selected);			
			}else{			
		    	objLst.options[objLst.length] = new Option(objOption.text,objOption.value,false,selected);
			}
		} else{
			if (arguments[2]) {
		    	objLst.options[0] = new Option(objOption.text,newValue,false,selected);
			}else{			
		    	objLst.options[0] = new Option(objOption.text,objOption.value,false,selected);
			}		
		}
	}	
	this.addOptionItem = function addOption(objLst,text,newValue,selected){
		if (arguments.length==4){
			selected = arguments[3];
		}else{
			selected = false;
		}
		if (objLst.length != -1) {
	    	objLst.options[objLst.length] = new Option(text,newValue,false,selected);			
		} else{
	    	objLst.options[0] = new Option(text,newValue,false,selected);
		}
	}	
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////// INTERFACE IVALIDACAO /////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/**
	Objeto de manipulação de pesquisa de conteúdo do xFWeb
	Para mais validações: http://www.regexlib.com
*/
function Validation(){
	 this.objeto;
	 this.mensagem_obrigatorio = MENSAGEM_OBRIGATORIO;
	 var sValidacao = TIPO_VALIDACAO;
	 if (IE) {
	 	this.arrayValidacao = sValidacao.split(":");
	 }else{
		this.arrayValidacao = sValidacao.split (/:/);
	 }
	this.getRequired = function getRequired(obj) {
			if (IE) {
			return ((obj.required == "") || (obj.REQUIRED == "") || (obj.Required == ""));
			}else{
				if (obj.getAttribute("required")==""){
					return true;
				}
			}
	}
	this.getValidationMsg = function getValidationMsg(obj) {
			if (IE) {
				if (obj.validationmsg) {return obj.validationmsg;}
				if (obj.VALIDATIONMSG) {return obj.VALIDATIONMSG;}
				if (obj.ValidationMsg) {return obj.ValidationMsg;}
			}else{
				if (obj.getAttribute("validationmsg")!=null){
					return obj.getAttribute("validationmsg");
				}
			}
			return "";
	}
	this.getMaxLength = function getMaxLength(obj) {
			if (IE) {
				if (obj.maxlength) {return obj.maxlength;}
				if (obj.MAXLENGTH) {return obj.MAXLENGTH;}
				if (obj.MaxLength) {return obj.MaxLength;}
			}else{
				if (obj.getAttribute("maxlength")!=null){
					return obj.getAttribute("maxlength");
				}
			}
			return "";
	}
	this.getValidationExpression = function getValidationExpression(obj) {
			if (IE) {
				if (obj.validationexpression) {return obj.validationexpression;}
				if (obj.VALIDATIONEXPRESSION) {return obj.VALIDATIONEXPRESSION;}
				if (obj.ValidationExpression) {return obj.ValidationExpression;}
			}else{
				if (obj.getAttribute("validationexpression")!=null){
					return obj.getAttribute("validationexpression");
				}
			}
			return "";
	}
	this.getSelectAll = function getSelectAll(obj) {
			if (IE) {
			return ((obj.selectall == "") || (obj.SELECTALL == "") || (obj.SelectAll == ""));
			}else{
				if (obj.getAttribute("selectall")==""){
					return true;
				}
			}
	}	
	this.getToUpperCase = function getToUpperCase(obj) {
			if (IE) {
			return ((obj.touppercase == "") || (obj.TOUPPERCASE == "") || (obj.ToUpperCase == "") || (obj.toUpperCase == ""));
			}else{
				if (obj.getAttribute("touppercase")==""){
					return true;
				}
			}
	}	
	
	this.isValidField = function (objField,maskValue){
		this.objeto = objField;
					if (!eval("this."+maskValue.toUpperCase()+"()") && (this.objeto.value!="")) {
							util.WindowExclamation(this.getMensagem());
							try {
								this.objeto.focus();
							}catch(ex){
							/** Não faz nada caso não realizar o foco definir do objeto */
							}
							return false;
					}
					return true;
	}
	
	 this.isValid = function isValid(oFrm){
		try {	 
			var arrayObjectsxFWeb = xFWebObject.getObjects();	 
			for (var i=0;i<arrayObjectsxFWeb.length;i++) {
				this.objeto = arrayObjectsxFWeb[i].objeto;
//				alert(this.objeto.form.name+' == '+oFrm.name);
				if (this.objeto.form.name == oFrm.name) {
//				alert(this.objeto.form.name);
				if (this.objeto.value) {this.objeto.value = util.trim(this.objeto.value);}
				var maskValue = xFWebObject.searchAttribute(this.objeto);
				if (maskValue != "") {
					if (this.isValidacao()) {
//						if (!eval("this."+maskValue.toUpperCase()+"()") && this.getRequired(this.objeto)) {
						//alert(this.getMaxLength(this));
						if (!eval("this."+maskValue.toUpperCase()+"()") && ((this.objeto.value!="") || ((maskValue.toUpperCase()=="POPULATED") && (this.getRequired(this.objeto))))) {
							util.WindowExclamation(this.getMensagem());
//							alert(this.getMensagem());
							try {
								this.objeto.focus();
							}catch(ex){
							/** Não faz nada caso não realizar o foco definir do objeto */
							}
							return false;
						}
					}else{
						util.logxFWebException("ERRO DE VALIDAÇÃO","A validação [" + maskValue + "] não é valida para o Template xFWeb.");
						return false;					
					}
				}
				var expressionValue = this.getValidationExpression(this.objeto);
				if (expressionValue != "") {
						var strExpressao = expressionValue;
//						alert(strExpressao)
						for (var e=0;e<arrayObjectsxFWeb.length;e++) {
							if (arrayObjectsxFWeb[e].objeto.form.name == oFrm.name) {
								if (arrayObjectsxFWeb[e].objeto.name) {
								var tmp = arrayObjectsxFWeb[e].objeto.name;
								if (tmp.substr(tmp.length-3,tmp.length).toUpperCase()=="_ON") {
									nameField = tmp.substr(0,tmp.length-3);
								}else{
									nameField = tmp;							
								}
								valueField = arrayObjectsxFWeb[e].objeto.value;
	//							arraySemantic = nameField.split(".");
	//							alert(nameField + " = " + valueField+"\n"+strExpressao);
								strExpressao = util.replace(strExpressao,nameField,"'"+valueField+"'");
								}
							}
						}
						strExpressao = "("+strExpressao+")";
//						alert(strExpressao);
						try {							
							if (!eval(strExpressao)){
								util.WindowExclamation(this.getMensagem());			
//								alert(this.getMensagem());
								try {
									this.objeto.focus();
								}catch(ex){
								/** Não faz nada caso não realizar o foco definir do objeto */
								}
								return false;
							}
						}catch(ex){
							alert("ATENÇÃO: Falha ao processar a expressão:\n ["+strExpressao+"]\nProcure o administrador do sistema.");
							return false;
						}
				}
				if (this.getRequired(this.objeto)){
					if ((this.objeto.value == "") && (maskValue.toUpperCase()!="POPULATED")){
						util.WindowExclamation(this.getMensagem());			
//						alert(this.getMensagem());
						try {
							this.objeto.focus();
						}catch(ex){
						/** Não faz nada caso não realizar o foco definir do objeto */
						}
						return false;
					}
				}
				if (this.getMaxLength(this.objeto)!="") {
					if (parseInt(this.objeto.value.length) > parseInt(this.getMaxLength(this.objeto))) {
						util.WindowExclamation("O tamanho máximo do campo é: "+this.getMaxLength(this.objeto)+" caracteres. "+this.getMensagem());
						return false;
					}
				}
				
			}
			}
			
			// caso especial de select multiple
			
			for (var i=0;i<arrayObjectsxFWeb.length;i++) {
				this.objeto = arrayObjectsxFWeb[i].objeto;
				if (this.objeto.form.name == oFrm.name) {
					if (this.getSelectAll(this.objeto)) {
						for (var o=0;o<this.objeto.options.length;o++) {
							this.objeto.options.item(o).selected = true;
						}
					}
					// Tratamento para 
					if (this.getToUpperCase(this.objeto)) {
						this.objeto.value = this.objeto.value.toUpperCase();
					}
				}
			}
			// tratamento para o uppercase


			
//			return false;
			return true;
		}catch(ex){
			status = "(Validation.isValid) Falha na Validação do Formulário: "+ex;
			return true;
//			util.logxFWebException(ex,"Validation.isValid");
		}
	 }
 	this.isValidacao = function isValidacao(objRef){
		if (objRef) {
			var maskValue = xFWebObject.searchAttribute(objRef);
		}else{
			var maskValue = xFWebObject.searchAttribute(this.objeto);
		}
		if (maskValue != "") {
			for (var i=0;i<this.arrayValidacao.length;i++) {
				if (this.arrayValidacao[i] == maskValue.toUpperCase()) {
					return true;
				}
			}
		}
		return false;
	}
	this.getMensagem = function getMensagem(objRef) {
			if (objRef) {
				var mensagem = this.getValidationMsg(objRef);
			}else{
				var mensagem = this.getValidationMsg(this.objeto);
			}
			if (mensagem != "") {
				return mensagem;
			}else{
				return this.mensagem_obrigatorio;
			}
	} 
	this.getMesengerStatus = function getMesengerStatus() {
		objMensagem = DocumentAll["XFWEB_MESSAGE"];
		if (objMensagem) {
			msgStatus=DocumentAll["XFWEB_MESSAGE"].value;		
			MensagemType = DocumentAll["XFWEB_MESSAGE_TYPE"].value.toUpperCase();
			if (MensagemType == "ERROR") {
				util.WindowCritical(msgStatus);
			}else if(MensagemType == "WARNING") {	
				util.WindowExclamation(msgStatus);			
			}else if(MensagemType == "INFO") {	
				util.WindowInformation(msgStatus);						
			}
		}
	}
	this.isPatternValido = function isPatternValido(objRegExp){
		try {
			return (objRegExp.test(this.objeto.value));
		}catch(ex){
			util.logxFWebException(ex,"Validation.isPatternValido");
		}
	}
	this.MATRICULA_SERVIDOR = function MATRICULA_SERVIDOR() {
		if (this.objeto.value.length != 12){return false;}
		var matricula = this.objeto.value;
		matricula = matricula.replace(".","");
		matricula = matricula.replace(".","");
		matricula = matricula.replace("-","");
		var objRegExp = /^[0-9]+$/;
		return (objRegExp.test(matricula));
	}
	this.TEXT = function TEXT() {
		/** possivel tratamento futuro */
		return true;
	}

	this.VARIABLE = function VARIABLE() {
		return this.isPatternValido(/^[0-9a-zA-Z]+$/);
	}

	this.CLASSIFICACAO_ORCAMENTARIA = function CLASSIFICACAO_ORCAMENTARIA() {
		//TODO IMPLEMENTAR. Sistema de Convênios
		return true;
	}
	
	this.SELECTED = function SELECTED() {
		var selecionado = false;
		switch (this.objeto.type.toUpperCase()) { 
		   case "RADIO" : 
			  objRadio = document.all[this.objeto.name];
		   	  for (c=0;c<objRadio.length;c++) {
			  		if (objRadio[c].checked) {
						selecionado = true;
						break;
					}
			  }
		      break; 
		   case "CHECKBOX" : 
			  objCheckbox = document.all[this.objeto.name];
		   	  for (c=0;c<objCheckbox.length;c++) {
			  		if (objCheckbox[c].checked) {
						selecionado = true;
						break;
					}
			  }
		      break; 
		   case "SELECT-ONE" : 
			  if (this.objeto.value != "") {
					selecionado = true;
			  }
		      break; 
		   case "SELECT-MULTIPLE" : 
				if (this.objeto.selectedIndex == -1) {
					selecionado = false;
				}else{
				 	if (this.objeto[this.objeto.selectedIndex].value != "") {
						selecionado = true;
					}
				}
		      break; 
		   default:
			  if (this.objeto.value != "") {
					selecionado = false;
			  }
		}
		return selecionado;
	}
	this.POPULATED = function POPULATED() {
		if (!this.getRequired(this.objeto)) {
			return true;
		}
		return (this.objeto.length>0);
	}
		
	this.EMAIL = function EMAIL() {
		return this.isPatternValido(/^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i);
	}
	this.INTEGER = function INTEGER() {
		return this.isPatternValido(/(^-?\d\d*$)/);
	}
	this.CEP = function CEP() {
		return this.isPatternValido(/^\d{5}(-\d{3})?$/);
	}
	this.POSITIVE_INTEGER = function POSITIVE_INTEGER() {
		return this.isPatternValido(/^[0-9]+$/);
	}

	this.SEQUENCE = function SEQUENCE() {
		return this.isPatternValido(/^\d{1,10}\/\d{4}$/);
	}

	this.YEAR = function YEAR() {
		return this.isPatternValido(/^[1-9]\d{3}$/);
	}

	this.REAL = function REAL() {
		return this.isPatternValido(/^\$?([0-9]{1,3}.([0-9]{3}.)*[0-9]{3}|[0-9]+)(,[0-9][0-9])?$/);
	}
	this.PASSWORD = function PASSWORD() {
		/** senha entre 4 e 15 digitos */
//		return this.isPatternValido(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,15}$/);	
	}
	this.IP = function IP() {
		return this.isPatternValido(/\b((25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)\.){3}(25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)\b/);	
	}
	/*
	this.URL = function URL() {
		return this.isPatternValido(/(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/);	
	}
	*/
	this.DATE_TIME = function DATE_TIME() {
  		var objRegExpHora = /^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9]))|(([0]?[0-9]|1[0-9]|2[0-4])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$/;
		data = this.objeto.value.substring(0,10);
		hora = this.objeto.value.substring(11,19);
		return (this.isDate(data) && objRegExpHora.test(hora));
	}
	this.TIME = function TIME() {
		return this.isPatternValido(/^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9]))|(([0]?[0-9]|1[0-9]|2[0-4])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$/);
	}
	this.DATE = function DATE() {
//		data = this.objeto.value.substring(0,10);
		data = this.objeto.value;
		return this.isDate(data);
	}
	
	this.DIA_MES = function DIA_MES() {
//		data = this.objeto.value.substring(0,10);
		data = this.objeto.value;
		return this.isDiaMes(data);
	}
	
	this.CREDIT_CARD = function CREDIT_CARD() {
		/** Matches major credit cards including: Visa (length 16, prefix 4), Mastercard 
		(length 16, prefix 51-55), Discover (length 16, prefix 6011), 
		American Express (length 15, prefix 34 or 37).
		All 16 digit formats accept optional hyphens (-) between each grou ...  */
		return this.isPatternValido(/^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$/);	
	}
	this.isDate = function isDate(data) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = data.match(datePat); // is the format ok?
		
		if (matchArray == null) {
//		alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
		}		
		
		day = matchArray[1]; // p@rse date into variables
		month = matchArray[3];
		year = matchArray[5];

		if (day < 1 || day > 31) {
//		alert("Day must be between 1 and 31.");
		return false;
		}

		if (month < 1 || month > 12) { // check month range
//		alert("Month must be between 1 and 12.");
		return false;
		}
	
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//		alert("Month "+month+" doesn`t have 31 days!")
		return false;
		}
		
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
//		alert("February " + year + " doesn`t have " + day + " days!");
			return false;
			}
		}
		return true; // date is valid
		
	/*	
		var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
		if(!objRegExp.test(data)) {
			return false;
		}else{
		    var arrayDate = data.split(RegExp.$1); //split date into month, day, year
			var intDay = parseInt(arrayDate[0],10); 
		    var intMonth = parseInt(arrayDate[1],10);
			var intYear = parseInt(arrayDate[2],10);
			//check for valid month
			if(intMonth > 12 || intMonth < 1) {
				return false;
			}
		    //create a lookup for months not equal to Feb.
		    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
		                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31};
		    //check if month value and day value agree
		    if(arrayLookup[arrayDate[0]] != null) {
		      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
		        return true; //found in lookup table, good date
		    }
		    //check for February
			var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		    if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
		      return true; //Feb. had valid number of days
		}
			return true;		
	*/			
	}
	
	this.isDiaMes = function isDiaMes(data) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})$/;
		var matchArray = data.match(datePat); // is the format ok?
		
		if (matchArray == null) {
//		alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
		return false;
		}		
		
		day = matchArray[1]; // p@rse date into variables
		month = matchArray[3];		

		if (day < 1 || day > 31) {
//		alert("Day must be between 1 and 31.");
		return false;
		}

		if (month < 1 || month > 12) { // check month range
//		alert("Month must be between 1 and 12.");
		return false;
		}
	
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//		alert("Month "+month+" doesn`t have 31 days!")
		return false;
		}
		
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0);
			if (day > 29 || (day==29 && !isleap)) {
//		alert("February " + year + " doesn`t have " + day + " days!");
			return false;
			}
		}
		return true; // date is valid
		
	/*	
		var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
		if(!objRegExp.test(data)) {
			return false;
		}else{
		    var arrayDate = data.split(RegExp.$1); //split date into month, day, year
			var intDay = parseInt(arrayDate[0],10); 
		    var intMonth = parseInt(arrayDate[1],10);
			var intYear = parseInt(arrayDate[2],10);
			//check for valid month
			if(intMonth > 12 || intMonth < 1) {
				return false;
			}
		    //create a lookup for months not equal to Feb.
		    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
		                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31};
		    //check if month value and day value agree
		    if(arrayLookup[arrayDate[0]] != null) {
		      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
		        return true; //found in lookup table, good date
		    }
		    //check for February
			var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		    if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
		      return true; //Feb. had valid number of days
		}
			return true;		
	*/			
	}
	
	
	this.CPF = function CPF() {
		return this.isPatternValido(/^\d{3}\x2E\d{3}\x2E\d{3}\x2D\d{2}$/);
 
 

		/* (^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$) */
		/*
		 NumCPF = this.objeto.value;
		 var Soma, Laco, Digito1, Digito2, Count;
		   Soma = 0;
		   for (Laco=0;Laco<9;Laco++) {
		     	Soma = Soma + (NumCPF.substring(Laco,Laco+1)*(Laco+1));
		   }
		   Digito1 = Soma % 11;
		   if (parseInt(Digito1) == 10) {
		       	Digito1 = 0;
		   }
		   Soma = 0;
		   for (Laco=0;Laco<8;Laco++) {
		     	Soma = Soma + (NumCPF.substring(Laco+1,Laco+2)*(Laco+1));
		   } 
		   Soma = Soma + (Digito1 * 9);
		   Digito2 = Soma % 11;
		   if (parseInt(Digito2) == 10) { 
				Digito2 = 0;
		   }
		   if (parseInt(Digito1) == parseInt(NumCPF.substring(9,10))) {
		     	if (parseInt(Digito2) == parseInt(NumCPF.substring(10,11))) {
		       		return true;
		     	}
		   }
		   return false;
		   */
	}

	this.CNPJ = function CNPJ() {

		return this.isPatternValido(/^[0-9]{2,3}\.[0-9]{3}\.[0-9]{3}\/[0-9]{4}-[0-9]{2}$/);

		/*
			alert('CNPJ');
			s = this.objeto.value;
			alert('s='+s);
			var i;
			s = limpaString(s);
			var c = s.substr(0,12);
			var dv = s.substr(12,2);
			var d1 = 0;
			for (i = 0; i < 12; i++)
			{
				d1 += c.charAt(11-i)*(2+(i % 8));
			}
		        if (d1 == 0) return false;
		        d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;
			if (dv.charAt(0) != d1)
			{
				return false;
			}
			d1 *= 2;
			for (i = 0; i < 12; i++)
			{
				d1 += c.charAt(11-i)*(2+((i+1) % 8));
			}
			d1 = 11 - (d1 % 11);
			if (d1 > 9) d1 = 0;
			if (dv.charAt(1) != d1)
			{
				return false;
			}
	        return true;
			*/
	}


}

function initxFWeb() {
	if (!XFWEB_LOADED) {
		// limpa seleção de objetos da listagem
		var arrayObjetosForm = document.getElementsByTagName("INPUT");
		 for (z=0;z<arrayObjetosForm.length;z++){ 
		 	objeto = arrayObjetosForm[z];
			switch (objeto.type.toUpperCase()) { 
			   case "CHECKBOX" : 
			   					if (objeto.id.substring(0,4) == "CHK-"){
									for (i=0;i<objeto.length;i++){
											objeto[i].checked = false;
									}
								}
				break;
			}	 
		}
		xFWebObject.loadBehaviors();
		//Possiciona o cursor no primeiro campo texto do primeiro formulario
		try{	
			var achoufocus = false;
			for (var f=0;f<document.forms.length;f++)  {
//			if (document.forms[0]) {
				for (i=0;i<document.forms[f].length;i++)  {
					if (document.forms[f].elements[i].type.toUpperCase() == "TEXT") {
						try{
							var att = document.forms[f].elements[i].attributes;
							//if (document.forms[f].elements[i].nofocus==undefined) {
							if (att.getNamedItem("nofocus")==null) {
								document.forms[f].elements[i].focus();
								achoufocus = true;
								break;
							}
						}catch(ex){}
					}
				}
				if (achoufocus) {
					break;
				}
//			}
			}
		}catch(ex){}
		//funcao auxiliar para onload funcions
		try{
			loadxFWeb();
		}catch(ex){}
		// Recuperar mensgaens do cabecalho, para status de operacao
		Validation.getMesengerStatus();
		// Iniicia os Combos Dinâmicos
//		xFWebComboObject.init();
		XFWEB_LOADED = true
	}
}
