	
	function erase(pos) { if (pos>=0) this.splice(pos,1); else this.splice(0,this.length); return this; }
	Array.prototype.erase = erase;

	var tp='../../core/theme/Default/'; var lastEl=null; var action=false; var multiSelect=new Array();
	function upperCase(obj){
		obj.value = obj.value.toUpperCase();
	}
	function toggle(src)
	{
		var el = document.getElementById(src);
		var el1 = document.getElementById(src+'_image');
		if (el.style.display=="none") {el.style.display="block"; el1.src=tp+"Tree/cen_minus.gif"} 
		else {el.style.display="none"; el1.src=tp+"Tree/cen_plus.gif"}
		repositionDIV();
	}

	function showObject(obj) {obj.visibility = "visible";}
	function hideObject(obj) {obj.visibility = "hidden";}
	
	function getReal(el, type, value) 
	{
		temp = el;
		while ((temp != null) && (temp.tagName != "BODY")) 
		{
			if (eval("temp." + type) == value) {el = temp; return el;}
			temp = temp.parentElement;
		}
		return el;
	}
	
	function pick()
	{
		srcEl=getReal(window.event.srcElement, "tagName", "TR");
		if (window.event.ctrlKey)
		{
			var found=false;
			for (c=0;c<=multiSelect.length;c++) 
			{
				if (multiSelect[c]==srcEl) {found=true; unHighLight(multiSelect[c]); multiSelect.erase(c);}
			}
			if (!found) {multiSelect[multiSelect.length]=srcEl; highLight(srcEl, srcEl.eid, true);}

			if ((multiSelect.length>1) || (multiSelect[0]==null)) action=false;			
/*
			else if (multiSelect[0]!=null)
			{
 				if (multiSelect[0].fid!=5) action=true;
				else action=false;
			}
*/
			action=true;
		}
		else
		{
			if (multiSelect.length>1) selectAll(false,false);
			if (srcEl!=multiSelect[0])
			{
				selectAll(false,false);
				multiSelect[0]=srcEl;
				highLight(multiSelect[0], false);

 				//if (multiSelect[0].fid!=5) action=true;
				//else action=false;
				action=false;
				document.getElementById("selectedrecord").value=multiSelect[0].eid;		
			}
		}
	}
	
	function dblClick()
	{
		if (window.event.ctrlKey) return false;
		
		srcEl=getReal(window.event.srcElement, "tagName", "TR");		
		var winURL=""
		if(srcEl!=lastEl)
		{
			if (lastEl!=null) unHighLight(lastEl);
			lastEl=srcEl;
			multiSelect[0]=srcEl;	

			multiSelect[0].style.fontWeight ="normal";
			var obj=multiSelect[0].document.getElementById(multiSelect[0].eid);		
			if (obj.src.indexOf("consys")>0) obj.src="../../core/theme/Default/Icons/icon_consys_read.gif";
			else if (obj.src.indexOf("error")>0) obj.src="../../core/theme/Default/Icons/icon_error_read.gif";
			else obj.src="../../core/theme/Default/Icons/icon_read.gif";			

			
		}			

//		if (multiSelect[0].fid==5) loc="EditMessage.asp?emailID="+multiSelect[0].eid;
//		else loc="ViewEmailWindow.asp?emailID="+multiSelect[0].eid;
		
		launchWin(600,465,loc,1, parent.window);
	}

	function highLight(el,mSel) 
	{
		el.style.background = "#9CBEE7";

		if ((parent.bPreviewPaneVisible) && (!mSel))
		{
			el.style.fontWeight ="normal";
		
			var obj=el.document.getElementById(el.eid); 
			if (obj.src.indexOf("consys")>0) obj.src="../../core/theme/Default/Icons/icon_consys_read.gif";
			else if (obj.src.indexOf("error")>0) obj.src="../../core/theme/Default/Icons/icon_error_read.gif";			
			else obj.src="../../core/theme/Default/Icons/icon_read.gif";
		}
	}
	
	function unHighLight(el) { el.style.background = ""; }
	
	function selectAll(sel,hLight)
	{
		multiSelect.erase();

		var els=document.all.tags("TR"); 
		for (e=0;e<=els.length-1;e++)
		{
			if(els[e].eid)
			{
				if (sel) {multiSelect[multiSelect.length]=els[e]; if (hLight) highLight(els[e],els[e].eid);}
				else unHighLight(els[e]);
			}
		}
		
		if ((sel) && (hLight)) 
		{
			var els=document.all.tags("TABLE");
			for (e=0;e<=els.length-1;e++) if (els[e].className=="List") {if (els[e].style.display=="none") toggle(els[e].id);}
		}
		
		if (!sel) multiSelect.erase();
		return multiSelect;
	}
	
	function repositionDIV()
	{
//		alert('repositionDIV');
		var offSetTitle = 90;
		if (IE) {
			var w;
			if (document.body.clientWidth>=divList.scrollWidth) {ListHeader.style.marginLeft=0; w=8;} else {w=0;}		
			if (window.endcols) for(x=0;x<=endcols.length-1;x++) if(endcols[x]!=null) endcols[x].style.width=w;			
			if ((window.tblItems) && (tblItems[0]!=null)) {
				for(x=0;x<=tblItems.length-1;x++) if(tblItems[x]!="") tblItems[x].style.width=(ListHeader.scrollWidth-16);		
				divList.style.height=Math.max(document.body.clientHeight-ListHeader.offsetHeight-offSetTitle,0);
				divList.style.width=Math.max(document.body.clientWidth,0);
			}
		}else{
//			alert(parent.document.all['ContentSubModule']);
			var cW;
			var cH; 

			cW = util.windowWidth();
			cH = util.windowHeight(); 
			offSetTitle = 115;

			h = cH-offSetTitle;
			divList.style.height=Math.max(h,0);
			divList.style.width=Math.max(cW,0);
		}
	}
	

	

	
	
	
	
	




//**************************************************************//
//********************* MANIPULAÇÃO DE HORA ********************//
//**************************************************************//

function startClock() {
	if (!document.layers && !document.all)
	return;
	if (seconds<59){ 
		seconds = seconds + 1;}
	else{
	    seconds = 0;
		if (minutes<59){ 
			minutes = minutes + 1;}
		else{
		    minutes = 0;
			if (hours<23){ 
				hours = hours + 1;}
			else{
	    		hours = 0;}
			}
		}			
	var dn = "AM";
	hours2= hours;
	if (hours >= 12) {
		dn = "PM";
		hours2 = hours - 12;
	}
	minutes2 = minutes;
	seconds2 = seconds;
	if (hours == 0) { 	hours2 = 12;}
	if (minutes <= 9) {	minutes2 = "0" + minutes;}
	if (seconds <= 9) {	seconds2 = "0" + seconds;}
	
	movingtime = "<b>"+ hours2 + ":" + minutes2 + ":" + seconds2 + " " + dn + "</b>";
	if (document.layers) {
		document.layers.clock.document.write(movingtime);
		document.layers.clock.document.close();
	}
	else if (document.all) {
		clock.innerHTML = movingtime;
	}
	setTimeout("startClock()", 1000);
}

//**************************************************************//
	
	
//**************************************************************//
//**************** VARIÁVEIS DE CONFIGURAÇÃO ********************//
//**************************************************************//
var undefined;
var styleLineActive = "lineActive"; var styleLine = "line"; 
//**************************************************************//
var styleTabDataActive = "tabDataActive"; var styleTabData = "tabData";
var styleTabDivDataActive = "tabDataDivActive"; var styleTabDivData = "tabDataDiv";
//**************************************************************//
var imgTabLeftActive = "../../core/theme/Default/Tabs/tab_on_left.gif";
var imgTabCenterActive = "../../core/theme/Default/Tabs/tab_on_middle.gif";
var imgTabRigthActive = "../../core/theme/Default/Tabs/tab_on_right.gif";
//**************************************************************//
var imgTabLeft = "../../core/theme/Default/Tabs/tab_off_left.gif";
var imgTabCenter = "../../core/theme/Default/Tabs/tab_off_middle.gif";
var imgTabRigth = "../../core/theme/Default/Tabs/tab_off_right.gif";
//**************************************************************//
var lineSelected = false;
var lineOld = "";
var checkOld;
var frameWorkArea = "AreaDeTrabalho";
var globalObjetosComboQUIMERA;
var quimeraComboObject;
quimeraComboObject = new quimeraComboObject();
//**************************************************************//

//**************************************************************//
//**************** MANIPULAÇÃO DE REGISTROS ********************//
//**************************************************************//
var arrayMultipleLine = new Array();

function selectLine(objLine,searchName,tipoEscolha){
	try {
		var objCheckbox = document.all["CHK-"+searchName];
		
//		if (nameObjCheck == undefined) {
//			nameChek = "CHK-"+objLine.id;
//		}else{
//			nameChek = nameObjCheck+objLine.id;
//		}
		nameLine = objLine.id;
		//Tipos de escolhas: [U] único e [M] multiplos
		if (tipoEscolha == "M") {
//			var value = nameLine.substr(3,nameLine.length); 
			var value = nameLine.substr(nameLine.indexOf("-")+1,nameLine.length); 
			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;
			}

			if (removed) {
				document.all[nameLine].className = styleLine;
			}else{
				document.all[nameLine].className = styleLineActive;								
			}
		}else{
			if (lineOld != "") {
				document.all[lineOld].className = styleLine;
//				document.all[checkOld].checked = false;
			}
			if ((lineOld == objLine) && lineSelected==false) {
				document.all[nameLine].className = styleLine;
//				document.all[nameChek].checked = false;
				lineSelected = true
			}else{
				lineSelected = false
				document.all[nameLine].className = styleLineActive;
				
				if (arguments.length>=2) {
				if (searchName!=undefined && searchName!=null && document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"]!=undefined) {
//					document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value = nameLine.substr(3,nameLine.length);
					var value = nameLine.substr(nameLine.indexOf("-")+1,nameLine.length);
					document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value = value;
					if (objCheckbox!=undefined) {
						if (objCheckbox.length!=undefined) {
							for(var x=0;x<objCheckbox.length;x++){
								if (objCheckbox[x].value==value) {
									objCheckbox[x].checked=true;
								}else{
									objCheckbox[x].checked=false;
								}
							}
						}else{
							objCheckbox.checked = true;
						}
					}
				}
				}

//				document.all[nameChek].checked = true;
				lineOld = nameLine;
//				checkOld = nameChek;
			}
		}
	}catch(ex){
		util.logxFWebException(ex,"Erro na função de seleção de linha");
	}
}






//**************************************************************//
//*********************** COMBO DINÂMICO ***********************//
//**************************************************************//
function iObjectComboQuimera() {
	/** Referencia do Objeto HTML */
	this.objeto;
	this.procedure;
	this.fieldid;
	this.fieldtext;
	this.name;
	this.initvalue;
	this.parentname;
	this.parentvalue;
	this.msglist;
}
function quimeraComboObject() {
	this.onChangeCombo = function onChangeCombo() {
		var objComboSearch = searchObject("parentname",this.name);	
		if (objComboSearch != null) {
			objComboSearch = objComboSearch[0];
			objComboSearch.parentvalue = this[this.selectedIndex].value;
			quimeraComboObject.init(objComboSearch.name);
		}
	}
	this.updateCombo = function updateCombo(nameCombo) {
		var objComboSearch = searchObject("name",nameCombo)[0];
		var objComboQuimera = objComboSearch.objeto;
		optionsLen = objComboQuimera.length-1;
		for(var r=optionsLen;r>=0;r--) {
			objComboQuimera.options[r]=null;
		}
		var objComboQuimeraAux = util.getDocumentIframe("Iframe"+nameCombo).all["ComboTemp"];
		for (var o=0;o<objComboQuimeraAux.options.length;o++) {
			util.addOption(objComboQuimera,objComboQuimeraAux.options.item(o));
		}
	}
	this.init = function init(nameCombo) {
		if (nameCombo){
			var arrayObjectQ = searchObject("name",nameCombo);
		}else{
			var arrayObjectQ = quimeraComboObject.getObjects();		
		}
		for (var i=0;i<arrayObjectQ.length;i++){
			if (!document.all["Iframe"+arrayObjectQ[i].name]) {
				objIframeCombo = document.createElement("IFRAME");
				objIframeCombo.id = "Iframe"+arrayObjectQ[i].name;
				objIframeCombo.frameborder = "0";
				objIframeCombo.marginheight = "0";
				objIframeCombo.marginwidth = "0";
				objIframeCombo.width = "0";
				objIframeCombo.height = "0";
				document.body.appendChild(objIframeCombo);
			}else{
				objIframeCombo = document.all["Iframe"+arrayObjectQ[i].name];
			}
			srcCombo = "teste_COMBO.asp?procedure="+arrayObjectQ[i].procedure+"&fieldid="+arrayObjectQ[i].fieldid+"&fieldtext="+arrayObjectQ[i].fieldtext+"&initvalue="+arrayObjectQ[i].initvalue+"&parentvalue="+arrayObjectQ[i].parentvalue+"&msglist="+arrayObjectQ[i].msglist+"&name="+arrayObjectQ[i].name
			objIframeCombo.src = srcCombo;
		}
	}
	/**
		Método que retorna um objeto QUIMERA encontrado no documento HTML
	*/
	this.searchAttributeProcedure = function searchAttributeProcedure(obj) {
			if (obj.procedure) {return obj.procedure;}
			if (obj.PROCEDURE) {return obj.PROCEDURE;}
			if (obj.Procedure) {return obj.Procedure;}
			return "";
	}
	this.searchAttributeFieldId = function searchAttributeFieldId(obj) {
			if (obj.fieldid) {return obj.fieldid;}
			if (obj.fieldId) {return obj.fieldId;}			
			if (obj.FIELDID) {return obj.FIELDID;}
			if (obj.FieldId) {return obj.FieldId;}
			return "";
	}
	this.searchAttributeFieldText = function searchAttributeFieldText(obj) {
			if (obj.fieldtext) {return obj.fieldtext;}
			if (obj.fieldText) {return obj.fieldText;}			
			if (obj.FIELDTEXT) {return obj.FIELDTEXT;}
			if (obj.FieldText) {return obj.FieldText;}
			return "";
	}
	this.searchAttributeValue = function searchAttributeValue(obj) {
			if (obj.initvalue) {return obj.initvalue;}
			if (obj.initValue) {return obj.initValue;}			
			if (obj.INITVALUE) {return obj.INITVALUE;}
			if (obj.InitValue) {return obj.InitValue;}
			return "";
	}
	this.searchAttributeParentName = function searchAttributeParentName(obj) {
			if (obj.parentname) {return obj.parentname;}
			if (obj.ParentName) {return obj.ParentName;}			
			if (obj.PARENTNAME) {return obj.PARENTNAME;}
			if (obj.ParentName) {return obj.ParentName;}
			return "";
	}
	this.searchAttributeParentValue = function searchAttributeParentValue(obj) {
			if (obj.parentvalue) {return obj.parentvalue;}
			if (obj.ParentValue) {return obj.ParentValue;}			
			if (obj.PARENTVALUE) {return obj.PARENTVALUE;}
			if (obj.ParentValue) {return obj.ParentValue;}
			return "";
	}
	this.searchAttributeMsgList = function searchAttributeMsgList(obj) {
			if (obj.msglist) {return obj.msglist;}
			if (obj.msgList) {return obj.msgList;}			
			if (obj.MSGLIST) {return obj.MSGLIST;}
			if (obj.MsgList) {return obj.MsgList;}
			return "";
	}
	/**
		Método que retorna um array de objetos QUIMERA encontrados no documento HTML
	*/
 	this.getObjects = function getObjects() {
		try {
			if (!globalObjetosComboQUIMERA) {
			 	var arrayObjectsHTML = new Array();
				var indexArray = 0;
				var ObjetoBuscaHTML;
				ObjetoBuscaHTML = document.getElementsByTagName("SELECT");
				 for (z=0;z<ObjetoBuscaHTML.length;z++){ 
				 	 if (this.searchAttributeProcedure(ObjetoBuscaHTML.item(z)) != "") {
					 	ObjetoBuscaHTML.item(z).onchange = this.onChangeCombo;
						eval("itemObjetoComboQ" + indexArray + " = new iObjectComboQuimera()");
						eval("itemObjetoComboQ" + indexArray + ".objeto = ObjetoBuscaHTML.item(z)");
						eval("itemObjetoComboQ" + indexArray + ".procedure = this.searchAttributeProcedure(ObjetoBuscaHTML.item(z))");
						eval("itemObjetoComboQ" + indexArray + ".fieldid = this.searchAttributeFieldId(ObjetoBuscaHTML.item(z))");
						eval("itemObjetoComboQ" + indexArray + ".fieldtext = this.searchAttributeFieldText(ObjetoBuscaHTML.item(z))");						
						eval("itemObjetoComboQ" + indexArray + ".name = ObjetoBuscaHTML.item(z).name");
						eval("itemObjetoComboQ" + indexArray + ".initvalue = this.searchAttributeValue(ObjetoBuscaHTML.item(z))");
						eval("itemObjetoComboQ" + indexArray + ".parentname = this.searchAttributeParentName(ObjetoBuscaHTML.item(z))");						
						eval("itemObjetoComboQ" + indexArray + ".parentvalue = this.searchAttributeParentValue(ObjetoBuscaHTML.item(z))");						
						eval("itemObjetoComboQ" + indexArray + ".msglist = this.searchAttributeMsgList(ObjetoBuscaHTML.item(z))");
					 	eval("arrayObjectsHTML[indexArray] = itemObjetoComboQ" + indexArray );
						indexArray++;
					 }
				}
				globalObjetosComboQUIMERA = arrayObjectsHTML;				
			}
			return globalObjetosComboQUIMERA;
		}catch(ex){
			util.logxFWebException(ex,"quimeraComboObject.getObjects");
		}
	 }
	 this.searchObject = function searchObject(nameProperty,valueProperty){
	 	try {
			arrayObject = quimeraComboObject.getObjects();
	 		var arrayObjectReturn = new Array();
			var indexObject = 0;
			for (var o=0;o<arrayObject.length;o++) {
		 		if (eval("arrayObject[o]." + nameProperty) == valueProperty) {
					arrayObjectReturn[indexObject++] = arrayObject[o];
				}
			}
			if (arrayObjectReturn.length == 0) {
				return null;
			}else{
				return arrayObjectReturn;
			}
		}catch(ex){
			util.logxFWebException(ex,"quimeraComboObject.searchObject");
		}
	 }
 }
 
var ListHeader;
var divList;
var tblItems;
var endcols;	

function xFWebOnLoad(){
	// desregistra os checkbox
	uncheckList();

	lineSelected = false;
	lineOld = "";
	checkOld = undefined;

	try {
//		alert('xFWebOnLoad');
	document.getElementById("divList").onscroll=new Function("ListHeader.style.marginLeft = -divList.scrollLeft");
//		alert('xFWebOnLoad 2');
	ListHeader=document.getElementById("ListHeader");
	divList=document.getElementById("divList");
	if (IE) {
		tblItems=divList.all.tags("TABLE");
	}else{
//		alert(divList);
//		alert(document.getElementsByName('TABLE'));
		tblItems=document.getElementsByName('TABLE');
	}
//		alert('xFWebOnLoad 3');
//		alert(document.getElementById("endcol"));
	if (IE)	{
		endcols=document.all("endcol");	
	}else{
		endcols=document.getElementById("endcol");
	}

//	alert('xFWebOnLoad 3 - 1');
	repositionDIV();		
	document.body.onresize = xFwebBobyOnResize;
//	document.onkeypress = xFwebDoKey;

	}catch(e){}
} 
function xFwebOnUnload(){
	closeWins();
} 

// desregistra os checkbox|
  function uncheckList(){
	  try{

		var ObjetoBuscaHTML;
		for (var t=0;t<DocumentAll.length;t++) {
			ObjetoBuscaHTML = DocumentAll.item(t);
			var name = ObjetoBuscaHTML.name;
			if (name!=undefined){
				if (ObjetoBuscaHTML.name.indexOf("CHK-")!=-1 && ObjetoBuscaHTML.type.toUpperCase() == "CHECKBOX"){
					ObjetoBuscaHTML.checked = false;
				}
			}
		}
	  }catch(ex){}
  }



function xFwebOnMouseMove(){
	//this.y = event.y;
	//this.x = event.x;
} 
function xFwebDoKey(el){
  // Run only in IE
  // and if tab key is pressed
  // and if the control key is pressed
  alert(event);
  if ((9==event.keyCode) && (event.ctrlKey)) {
    // Cache the selection
//    el.selection=document.selection.createRange(); 
    setTimeout("ProcessTab()",0)
  }

  /*
	IE4 = (document.all);
	NS4 = (document.layers);
	if (NS4) document.captureEvents(Event.KEYPRESS);
    whichASC = (NS4) ? e.which : event.keyCode;
	
    whichKey = String.fromCharCode(whichASC).toLowerCase();
//	alert(event.ctrlKey)
	if ((event.ctrlKey) && (whichASC==9)) {
		alert('AQUI');
	}
*/
} 
function ProcessTab() {
	alert('OK');
}

function xFwebBobyOnResize(){
//	alert('xFwebBobyOnResize');
  try{
  	repositionDIV();
  }catch(e){}
} 
 
window.onload = xFWebOnLoad;
window.onunload= xFwebOnUnload;
window.onmousemove = xFwebOnMouseMove;

 
 
 
 
 
 

 
 
 
//**************************************************************//
//*********************** TRATAMENTO DE JANELAS *****************//
//**************************************************************//

	function urlIncQuerystring(str)
	{
		tmp=str.toString(); tmp=tmp.toLowerCase();
		ePos=str.indexOf(".asp"); sPos=str.lastIndexOf("/",ePos);
		if (ePos && sPos) str=tmp.substring(sPos+1, tmp.length);
		return unescape(str);
	}

	function getTFarray()
	{
		/*
		if ((top.opener) && (top.opener.top.frames["ConveaFrame"])) tFrame=top.opener.top.frames["ConveaFrame"].frames["topFrame"];
		if ((top.frames) && (top.frames["ConveaFrame"])) tFrame=top.frames["ConveaFrame"].frames["topFrame"];
		if ((window.dialogArguments) && (window.dialogArguments.top.frames["ConveaFrame"])) tFrame=window.dialogArguments.top.frames["ConveaFrame"].frames["topFrame"];		
		*/
		if (window.tFrame) return tFrame.popupArray;
		else return false;
	}

	var aWin=new Array();
	
	
	function nullOpeners()
	{
		aTPWin=getTFarray();
		if (aTPWin!=null)
		{
			for (i=0;i<aTPWin.length;i++)
			{
				if ((aTPWin[i]) && (!aTPWin[i].closed))
				{
					if (aTPWin[i].owner==document.URL) { aTPWin[i].opener=null; aTPWin[i].owner=null; }
				}
			}
		}
	}

	function closeWins()
	{
		try {
		if (aWin.length>0)
		{
			nullOpeners();
			for (a=0;a<aWin.length;a++) 
			{ 
				if ((aWin[a]) && (!aWin[a].closed)) aWin[a].close();
			}
		}
		}catch(e){}
	}

 
///////////////////////////////////////////////////////////////////////////////
///////////////////////////// INTERFACE SEARCH ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function xFWebSearch(){

	this.setRecordId = function setRecordId(searchName,OId){
		if (document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"]!=undefined){
			document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value = OId;
		}
	}


	this.getRecordId = function getRecordId(searchName){
		if (document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"]!=undefined){
			return document.all["XFWEB_SEARCH_"+searchName.toUpperCase()+"_SELECTED"].value;
		}
		return "";
	}
	this.getPage = function getPage(search) {
		return request.QueryString(this.getVarPage(search));
	}
	this.getVarPage = function getVarPage(search) {
		return search+".page";
	}
	this.getVarRecords = function getVarRecords(search) {
		return search+".page_size";
	}
	this.goURL = function goURL(search,parameter,value){
		url = location.pathname;
		var keys = request.getArrayKeys();
		var values = request.getArrayValues();			
		for (var i=0;i<keys.length;i++) {
			if (i == 0) {
				url = url + "?"
			}else{
				url = url + "&";
			}
			if (keys[i] == parameter) {
				url = url+keys[i]+"="+value;
			}else{
				url = url+keys[i]+"="+values[i];
			}
		}
		if (request.QueryString(parameter) == null) {
			if (keys.length == 0) {
				url = url + "?"
			}
			url = url + "&"+parameter+"="+value;
		}
		location.href = url;		
	}
	this.goURLParametro = function goURL(url,search,parameter,value){
		var keys = request.getArrayKeys();
		var values = request.getArrayValues();			
		for (var i=0;i<keys.length;i++) {
			if (i == 0) {
				url = url + "?"
			}else{
				url = url + "&";
			}
			if (keys[i] == parameter) {
				url = url+keys[i]+"="+value;
			}else{
				url = url+keys[i]+"="+values[i];
			}
		}
		if (request.QueryString(parameter) == null) {
			if (keys.length == 0) {
				url = url + "?"
			}
			url = url + "&"+parameter+"="+value;
		}
		location.href = url;		
	}
	this.testNextPage = function testNextPage(search){
		var PAGECOUNT = document.all[search+"_PAGECOUNT"].value;	
		if ((this.getPage(search) == null) && (parseInt(PAGECOUNT)>1)){
			return true;
		}else{
			if ((parseInt(this.getPage(search))>=1) && (parseInt(this.getPage(search))<parseInt(PAGECOUNT))) {
				return true;
			}
		}
	}

	this.NextPage = function NextPage(search){
		var PAGECOUNT = document.all[search+"_PAGECOUNT"].value;
		if ((this.getPage(search) == null) && (parseInt(PAGECOUNT)>1)){
			this.goURL(search,this.getVarPage(search),2)
		}else{
			if ((parseInt(this.getPage(search))>=1) && (parseInt(this.getPage(search))<parseInt(PAGECOUNT))) {
				this.goURL(search,this.getVarPage(search),parseInt(this.getPage(search))+1)
			}
		}
	}
	this.NextPageParametro = function NextPageParametro(url,search){
		var PAGECOUNT = document.all[search+"_PAGECOUNT"].value;
		if ((this.getPage(search) == null) && (parseInt(PAGECOUNT)>1)){
			this.goURL(url,search,this.getVarPage(search),2)
		}else{
			if ((parseInt(this.getPage(search))>=1) && (parseInt(this.getPage(search))<parseInt(PAGECOUNT))) {
				this.goURL(url,search,this.getVarPage(search),parseInt(this.getPage(search))+1)
			}
		}
	}
	this.testPreviousPage = function testPreviousPage(search){
		return ((this.getPage(search) != null) && (this.getPage(search)>1));
	}
	this.PreviousPage = function PreviousPage(search){
		if (this.testPreviousPage(search)) {
			this.goURL(search,this.getVarPage(search),parseInt(this.getPage(search))-1)		
		}
	}
	this.PreviousPageParametro = function PreviousPageParametro(url,search){
		if (this.testPreviousPage(search)) {
			this.goURL(url,search,this.getVarPage(search),parseInt(this.getPage(search))-1)		
		}
	}
	this.getRecordCount = function getRecordCount(search){
		return document.all[search+"_RECORDCOUNT"].value;
	}
	this.testLastPage = function testLastPage(search){
		var PAGECOUNT = document.all[search+"_PAGECOUNT"].value;
		var PAGE = document.all[search+"_PAGE"].value;
		return (!(parseInt(PAGECOUNT)==parseInt(PAGE)));
	}
	
	this.LastPage = function LastPage(search){
		var PAGECOUNT = document.all[search+"_PAGECOUNT"].value;	
		if (this.testLastPage(search)) {
			this.goURL(search,this.getVarPage(search),parseInt(PAGECOUNT))
		}
	}
	this.LastPageParametro = function LastPageParametro(url,search){
		var PAGECOUNT = document.all[search+"_PAGECOUNT"].value;	
		if (this.testLastPage(search)) {
			this.goURL(url,search,this.getVarPage(search),parseInt(PAGECOUNT))
		}
	}
	this.testFirstPage = function testFirstPage(search){
			var PAGE = document.all[search+"_PAGE"].value;
			return (parseInt(PAGE)>1);
	}
	this.FirstPage = function FirstPage(search){
			if (this.testFirstPage(search)) {
				this.goURL(search,this.getVarPage(search),1);
			}
	}
	this.FirstPageParametro = function FirstPageParametro(url,search){
			if (this.testFirstPage(search)) {
				this.goURL(url,search,this.getVarPage(search),1);
			}
	}
	this.RecordPage = function RecordPage(search,records){
		this.goURL(search,this.getVarRecords(search),records);
	}
	this.SortBy = function SortBy(search,field) {
		var vField = field+" asc";

		var fieldAux = field;
		fieldAux = util.replace(fieldAux," asc","");
		fieldAux = util.replace(fieldAux," desc","");			

		var getSort  = getSortBy(search);
		if (getSort!=null) {
			getSort = util.replace(getSort," asc","");
			getSort = util.replace(getSort," desc","");		
	
			if (fieldAux==getSort){
				field = getSortBy(search);
			}

		}

		if ((field.indexOf(" desc")!=-1)) {
			vField = util.replace(field," desc"," asc");				
		}else if (field.indexOf(" asc")!=-1) {
			vField = util.replace(field," asc"," desc");				
		}else{
			if (this.getTypeSort(search)=="desc") {
				vField = field+" asc";	
			}else if(this.getTypeSort(search)=="asc"){
				vField = field+" desc";			
			}
		}
//		alert("vField="+vField);
		this.goURL(search,search+".sort",vField);		
	}
	this.getSortBy = function getSortBy(search) {
		var value = request.QueryString(search+".sort");
		if (value!=null) {
//			var aValues = value.split(",");
//			var retorno = "";
//			status = value;
//			value = util.replace(value," asc","");
//			value = util.replace(value," desc","");
			return value;
			/* // modo que separava o tipo de ordenacao
			var aFieldOrder = value.split(" ");
			if (aFieldOrder.lenght==0){
				return value;
			}else{
				return aFieldOrder[0];
			}
			*/
		}
		return null;
	}
	this.getTypeSort = function getTypeSort(search) {
		var value = request.QueryString(search+".sort");
		if (value!=null) {
			var aAux = value.split(" ");
			typesort = aAux[aAux.length-1];///value.substr(value.indexOf(" ")+1,value.length);
			if ((typesort=="asc") || (typesort=="desc")) {
				return typesort;
			}else{
				return "asc";
			}
		}	
		return null;	
	}
	this.activeImgSort = function activeImgSort(objImg,typeOrder,srcImgDown,ImgsUp) {
		var srcImgDown;
		var srcImgUp;
		if (arguments.length>=3){
			srcImgDown = arguments[2];
			srcImgUp = arguments[3];
		}else{
			srcImgDown = "../../core/theme/Default/Icons/sort_down.gif";
			srcImgUp = "../../core/theme/Default/Icons/sort_up.gif";
		}
		if (typeOrder=="desc") {
			objImg.src = srcImgDown;
		}else if(typeOrder=="asc"){
			objImg.src = srcImgUp;		
		}
		objImg.style.visibility='visible';
	}

}	
	

function xFWeb(){
	this.refreshPage = function refreshPage(){
		location.replace(location.href)
	}
	this.positionTAB = 1;
//**************************************************************//
//******************** MANIPULAÇÃO DE TABs *********************//
//**************************************************************//
	this.getTab = function getTab(){
		return this.positionTAB+1;
	}
	this.Tab = function Tab(objTab,objDivTab,indexDivArray) {
		if (document.all[objTab]) {objTab = document.all[objTab]};
		if (document.all[objDivTab]) {objDivTab = document.all[objDivTab]};
		indexDivArray = indexDivArray -1;
		// TRATAMENTO ESPECIAL PARA O NS
		if (!IE) {
			var arrObjTab = new Array();
			var arrObjDivTab = new Array();
			var tDivIndex = 0;
			var tIndex = 0;
			var originalId = "";
			var originalDivId = "";

			originalId = objTab.id;
			originalDivId = objDivTab.id;
			// tratamento especial para array de Tabs no NS
			while(document.getElementById(originalId)) {
				tObj = document.getElementById(originalId);
				arrObjTab[tIndex] = tObj
				tObj.id = tObj.id+""+tIndex;
				tIndex = tIndex + 1;
			}
			objTab = arrObjTab;

			// tratamento especial para array de Divs no NS
			while(document.getElementById(originalDivId)) {
				tObj = document.getElementById(originalDivId);
				arrObjDivTab[tDivIndex] = tObj
				tObj.id = tObj.id+""+tDivIndex;
				tDivIndex = tDivIndex + 1;
			}
			objDivTab = arrObjDivTab;
		}
		if (objTab.length != undefined) {
			for (var j=0;j<objTab.length;j++){
				if (j == indexDivArray) {
					if (IE){
						objTab[j].childNodes[0].background = imgTabLeftActive;
						objTab[j].childNodes[1].background = imgTabCenterActive;
						objTab[j].childNodes[2].background = imgTabRigthActive;
						objTab[j].parentNode.parentNode.style.filter='alpha(opacity=100)';
					}else{
						TDs = objTab[j].getElementsByTagName("TD");
						TDs[0].childNodes[0].src = imgTabLeftActive;
						TDs[1].style.background = "url("+imgTabCenterActive+")";
						TDs[2].childNodes[0].src = imgTabRigthActive;
					}
					objTab[j].className = styleTabDataActive;
					objTab[j].parentNode.parentNode.onmouseover = tabDataOnMouseOver;
					objTab[j].parentNode.parentNode.onmouseout = tabDataOnMouseOut;	
				}else{
					if (IE){
						objTab[j].childNodes[0].background = imgTabLeft;
						objTab[j].childNodes[1].background = imgTabCenter;
						objTab[j].childNodes[2].background = imgTabRigth;
						objTab[j].parentNode.parentNode.style.filter='alpha(opacity='+SS_TabAlpha+')';
					}else{
						TDs = objTab[j].getElementsByTagName("TD");
						TDs[0].childNodes[0].src = imgTabLeft;
						TDs[1].style.background = "url("+imgTabCenter+")";
						TDs[2].childNodes[0].src = imgTabRigth;
					}
					objTab[j].className = styleTabData;
					objTab[j].parentNode.parentNode.onmouseover = tabDataOnMouseOver;
					objTab[j].parentNode.parentNode.onmouseout = tabDataOnMouseOut;	
				}
			}	
			for (var j=0;j<objDivTab.length;j++){
				if (j == indexDivArray) {
					objDivTab[j].className = styleTabDivDataActive;
				}else{
					objDivTab[j].className = styleTabDivData;
				}
			}	
		}else{
			if (IE){
				objTab.childNodes[0].background = imgTabLeftActive;
				objTab.childNodes[1].background = imgTabCenterActive;
				objTab.childNodes[2].background = imgTabRigthActive;
				objTab.parentNode.parentNode.style.filter='alpha(opacity=100)';
			}else{
				TDs = objTab.getElementsByTagName("TD");
				TDs[0].childNodes[0].src = imgTabLeftActive;
				TDs[1].style.background = "url("+imgTabCenterActive+")";
				TDs[2].childNodes[0].src = imgTabRigthActive;
			}
			objTab.className = styleTabDataActive;
			objDivTab.className = styleTabDivDataActive;
		}
		this.positionTAB = indexDivArray;

		// recupera os nomes dos tabs para o NS
		if (tIndex!=undefined){
			for (var k=0;k<objTab.length;k++){
				objCandidato = document.getElementById(originalId+""+k);
				objCandidato.id = originalId;
				objDivCandidato = document.getElementById(originalDivId+""+k);
				objDivCandidato.id = originalDivId;
			}

		}
		return false;

	}
	
	this.windowAutoSize = function windowAutoSize(){
		window.resizeTo(document.body.scrollWidth, document.body.scrollHeight+40);
	}

	this.openWindowWithRecord = function openWindowWithRecord(w,h,srcURL,search, sizable, obj, scrollbar){
		var OId = xFWebSearch.getRecordId(search);
		if (OId!="") {
			if (srcURL.indexOf("?")!=-1) {
				xFWeb.openWindow(w,h,srcURL+'&OId='+OId,sizable, obj, scrollbar);		
			}else{
				xFWeb.openWindow(w,h,srcURL+'?OId='+OId,sizable, obj, scrollbar);						
			}
			
		}else{
			util.WindowExclamation("Selecione um Item para essa operação");
		}
	}


	this.openWindowWithOneRecord = function openWindowWithOneRecord(w,h,srcURL,search, sizable, obj, scrollbar){
		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) {
					xFWeb.openWindow(w,h,srcURL+'&OId='+OId,sizable, obj, scrollbar);		
				}else{
					xFWeb.openWindow(w,h,srcURL+'?OId='+OId,sizable, obj, scrollbar);						
				}
			}			
		}else{
			util.WindowExclamation("Selecione um Item para essa operação");
		}
	}

	this.openWithRecord = function openWithRecord(srcURL, search){
		var OId = xFWebSearch.getRecordId(search);
		if (OId != "") {
			if (srcURL.indexOf("?")!=-1) {
				document.location.href=srcURL+'&OId='+OId;		
			}else{
				document.location.href=srcURL+'?OId='+OId;		
			}
		}else{
			util.WindowExclamation("Selecione um Item para essa operação");
		}
	}

	this.selectObjectSearch = function selectObjectSearch(search,field,text){
		var OId = xFWebSearch.getRecordId(search);		
		opener.document.all[field+"_on"].value = OId;
		opener.document.all["SarchObject"+field].value = text;
	}

	this.selectObjectOId = function selectObjectOId(OId,field,text){
		opener.document.all[field+"_on"].value = OId;
		opener.document.all["SarchObject"+field].value = text;
	}
	
	this.selectOneObjectSearch = function selectOneObjectSearch(OId,field,text){
		var cmb = document.all[field];
		// verifica se já existe o objeto 
		for (var o=0;o<cmb.options.length;o++) {
			if (cmb.options.item(o).value==OId) {
				cmb.options.item(o).selected = true;
				return true;
			}
		}
		cmb.options[cmb.length] = new Option(text,OId,true,true);			
	}
		
	
	this.openWindow = function openWindow(w,h,srcURL,sizable, obj, scrollbar)
	{
		aTPWin=getTFarray();
		if (sizable == undefined){
			sizable = "0";
		}
		for (i=0;i<aWin.length;i++)
		{
			if ((aWin[i]) && (!aWin[i].closed))
			{
				winURL=urlIncQuerystring(aWin[i].document.URL);
				newURL=urlIncQuerystring(srcURL);

				if (winURL.indexOf(newURL)>-1) { aWin[i].focus(); return false; }
			}
		}
		if (aTPWin!=null)
		{
			for (i=0;i<aTPWin.length;i++)
			{
				if ((aTPWin[i]) && (!aTPWin[i].closed))
				{
					winURL=urlIncQuerystring(aTPWin[i].document.URL);
					newURL=urlIncQuerystring(srcURL);
	
					if (winURL.indexOf(newURL)>-1) { aTPWin[i].focus(); return false; }
				}
			}
		}	
		if (scrollbar=="") scrollbar=0;
		aPos=aWin.length;
		lPos = (screen.width) ? (screen.width-w)/2 : 0; tPos = (screen.height) ? (screen.height-h)/2 : 0;
		aWin[aPos] = window.open(srcURL, "", "height="+h+", width="+w+", left="+lPos+", top="+tPos+", toolbar=0, location=0,directories=0,status=0,menuBar=0,scrollBars="+scrollbar+",resizable="+sizable);
			objWin = aWin[aPos];

		if (obj!=undefined) {
			aWin[aPos].opener=obj;				
		}else{
			aWin[aPos].opener=window;				
		}
		aWin[aPos].focus();
		aWin[aPos].owner=document.location.href;
	}
	

	this.openLocation = function openLocation(srcURL) {
		location.href=srcURL;
	}
	
	this.openLocationWithRecord = function openLocationWithRecord(srcURL,search){
		var OId = xFWebSearch.getRecordId(search);
		if (OId!="") {
			if (srcURL.indexOf("?")!=-1) {
				location.href=srcURL+'&OId='+OId;		
			}else{
				location.href=srcURL+'?OId='+OId;		
			}
			
		}else{
			util.WindowExclamation("Selecione um Item para essa operação");
		}
	}

	this.openWindowModal = function openWindowModal(w, h, srcURL,sizable)
	{
		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);
		if (sizable!=undefined){
			sizable = "0";
		}
		if (IE) {
			AlertModel=window.showModalDialog(srcURL,window,"dialogLeft:"+lPos+";dialogTop:"+tPos+"; dialogHeight: "+height +"px; dialogWidth: "+width+"px; edge: Raised; center: Yes; help: no; resizable: "+sizable+"; 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; }
	}

	this.formSubmit = function formSubmit(facade){
		objForm = document.all['frm'+facade];

		if (objForm==null) {
			util.WindowCritical("O Facade ["+facade+"] não existe, verifique a chamada da função Javascript \"formSubmit(facade)\".");
			return false;
		}else{
			if (Validation.isValid(objForm)){
				objForm.submit();
			}
		}
	}

	this.isValidSubmit = function isValidSubmit(facade){
		objForm = document.all['frm'+facade];

		if (objForm==null) {
			util.WindowCritical("O Facade ["+facade+"] não existe, verifique a chamada da função Javascript \"validSubmit(facade)\".");
			return false;
		}else{
			return Validation.isValid(objForm);
		}
	}

	this.onKeyDownSubmit = function onKeyDownSubmit(obj){
		if(event.keyCode==13){
			var objForm = document.all[obj.form.name];
			var arrayObjectsxFWeb = xFWebObject.getObjects();	 
//			alert(arrayObjectsxFWeb.length)
			if (arrayObjectsxFWeb.length>1) {
				if (Validation.isValid(objForm)){
					obj.form.submit();
				}
			}
		}	
		return false;
	}
}


function tabDataOnMouseOver(){
	nameClass = this.childNodes[0].childNodes[0].className;
	if (nameClass == styleTabData) {
		this.style.filter='alpha(opacity=100)';
	}
}
function tabDataOnMouseOut(obj){
	nameClass = this.childNodes[0].childNodes[0].className;

	if (nameClass != styleTabDataActive) {
		this.style.filter='alpha(opacity='+SS_TabAlpha+')';
	}
}

	
	
 
 
///////////////////////////////////////////////////////////////////////////////
///////////////////////////// INTERFACE REQUEST ///////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/**
	Interface de tratamento de requests
*/
function request() {

	var arrayQueryStringkeys = new Array();
	var arrayQueryStringvalues = new Array();
	this.getArrayKeys = function getArrayKeys() {
		return arrayQueryStringkeys;
	}
	this.getArrayValues = function getArrayValues() {
		return arrayQueryStringvalues;
	}
	if (IE) {
		QueryStringParse();
	}

	/**
		Retorna um item da query string
		@deprecated
	*/
	this.QueryString = function QueryString(key) {
		try {
			var value = null;
			for (var i=0;i<arrayQueryStringkeys.length;i++) {
				if (arrayQueryStringkeys[i]==key) {
					value = unescape(arrayQueryStringvalues[i]);
					break;
				}
			}
			return value;
		}catch(ex){
			util.logxFWebException(ex,"request.QueryString");
		}
	}
	/**
		Retorna um item da query string
	*/
	this.getQueryString = function getQueryString(key) {
		try {
			var value = null;
			for (var i=0;i<arrayQueryStringkeys.length;i++) {
				if (arrayQueryStringkeys[i]==key) {
					value = unescape(arrayQueryStringvalues[i]);
					break;
				}
			}
			return value;
		}catch(ex){
			util.logxFWebException(ex,"request.getQueryString");
		}
	}
	/**
		Faz o parser da url para recuperar a query string
	*/
	this.QueryStringParse = function QueryStringParse() {
		try {
			var query = window.location.search.substring(1);
			var pairs = query.split("&");
			for (var i=0;i<pairs.length;i++) {
				var pos = pairs[i].indexOf('=');
				if (pos >= 0) {
					var argname = pairs[i].substring(0,pos);
					var value = pairs[i].substring(pos+1);
					arrayQueryStringkeys[arrayQueryStringkeys.length] = argname;
					arrayQueryStringvalues[arrayQueryStringvalues.length] = value;		
				}
			}
		}catch(ex){
			util.logxFWebException(ex,"request.QueryStringParse");
		}
	}
}

 
 
 	
	

xFWeb = new xFWeb();	
xFWebSearch = new xFWebSearch();
request = new request();	
if (!IE) {
	request.QueryStringParse();
}

/********************************************************/
/********************* LAYOUT ***************************/
/********************************************************/

function layout(){
	this.displayDiv = function(name){
		if (document.all[name].style.display==''){
			document.all[name].style.display='none';
		}else{
			document.all[name].style.display='';
		}
	}
	this.displayDivWithCookie = function(name){
		if (document.all[name].style.display==''){
			document.all[name].style.display='none';
			util.setCookieWithParameter("Div"+name,'false','/');
		}else{
			document.all[name].style.display='';
			 //setCookie(name, value, expires, path, domain, secure) 
			util.setCookieWithParameter("Div"+name,'true','/');
		}
	}

	this.loadDivWithCookie = function(name){
			var valorCookie = util.getCookie("Div"+name);
			//alert(name+"="+valorCookie);
			if (!(valorCookie==null || valorCookie==undefined || valorCookie=="")){
				if (valorCookie=="true"){
					document.all[name].style.display='';
				}else{
					document.all[name].style.display='none';
				}
			}
	}
	

	
		
	this.mOvr = function(src,clrOver) {
	  if (!src.contains(event.fromElement)) {
		  src.style.cursor = 'hand';
		  src.id = clrOver;
	  }
	}

	this.mOut = function(src,clrIn) {
	  if (!src.contains(event.toElement)) {
		 src.style.cursor = 'default';
		 src.id = clrIn;
	  }
	}

	this.mClk = function(src) {
	  if(event.srcElement.tagName=='TD'){
			src.children.tags('A')[0].click();
	  }
	}

	
	this.openLink = function(url){
		window.location = url;
	}
	
}
layout = new layout();

