var IMG_BTN_CONSULTAR_OVER 	= "imagens/btn_consultar_over.gif";
var IMG_BTN_CONSULTAR_OUT 	= "imagens/btn_consultar.gif";
var IMG_BTN_INCLUIR_OVER 	= "imagens/btn_incluir_over.gif";
var IMG_BTN_INCLUIR_OUT 	= "imagens/btn_incluir.gif";
var IMG_BTN_EXCLUIR_OVER 	= "imagens/btn_excluir_over.gif";
var IMG_BTN_EXCLUIR_OUT 	= "imagens/btn_excluir.gif";

function WF_changeImage (P_ObjName , P_ImgName){
	 var Obj = document.all.item(P_ObjName);  
	 if (Obj != null){
		Obj.src = P_ImgName;
	 } 
	 return true;
}


function showMessage(msg){
	document.all.partes.innerHTML = msg;
}

function setCurrentYear(idx){
	if (trim(WF_getElement("filtroNOF" + idx).value) != "" && trim(WF_getElement("filtroSerie" + idx).value) != ""){
        WF_getElement("filtroAno" + idx).value = WF_getElement("actualYear").value;
	}
}

//Not used for now
function changeFocusNotam(idx, obj){
	if (obj.name == ("filtroNOF" + idx) && obj.value.length == 4){
        WF_getElement("filtroSerie" + idx).focus();
	}
}

//*************************************************
// # General Functions #
//*************************************************
//-------------------------------------------------
//***[Recupera um Frame.]***
function WF_getFrame(frameName){
   return window.parent.frames.item(frameName);
}
//-------------------------------------------------
//***[Recupera um objeto no documento.]***
function WF_getElement(ctlName, frame){
    if (frame != null) {
       if (frame != "[object]") frame = getFrame(frame);  
       return frame.document.all.item(ctlName);
    } else {
       return document.all.item(ctlName);
    }
}
//-------------------------------------------------
//***[Corta os espaços em branco.]***
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} 
//-------------------------------------------------
//***[Abre uma Janela PopUp.]***
function WF_showPopUp(idJanela, url, w, h, debugMode){
    var t = 100;
    var l = 150;
    if (debugMode == null) debugMode = false;
    if (debugMode){
       url += "&modal=N";
       window.open(url, idJanela, "menubar=false, width=" + w + ", height=" + h + ", top=" + t + ", left=" + l + ";");
    } else {
       url += "&modal=S";
       window.showModalDialog(url, window, "center: yes; status: no; help: no; resizable: no; scroll:no;dialogWidth:" + w + "px;dialogHeight:" + h + "px");
    }  
} 
//-------------------------------------------------
function recuperaDescricao(ctlObj, onLoadEvent, extraParms, height, width, semAlerta){
    var url = "BuscaDescricaoServlet?nomeControle=" + ctlObj.name;
    semAlerta = (semAlerta == null) ? false : semAlerta;

    if (extraParms != null) url += "&" + extraParms;

    if (height == null) height = 100;
    if (width == null) width = 220;

    if (navigator.appVersion.indexOf("5.")==-1){
       height = height + 20;
    }
    height += "px";
    width += "px";
    var htmlSize = "dialogWidth: " + width + "; dialogHeight: " + height + "; ";
    var res = window.showModalDialog(url,onLoadEvent,"center: yes; status: no; help: no; resizable: no; scroll:no; " + htmlSize);

}
//-------------------------------------------------
function toUpperCase(obj){
	obj.value = obj.value.toUpperCase();
}
//-------------------------------------------------
function putValue(objName, value){
	WF_getElement(objName).value = value;
}

//-------------------------------------------------
//--- Abre uma janela popup para retornar a descrição do NOF
var idx = 0;
function getDescription(ctlObj, index){
	idx = index;
	var nof = WF_getElement("filtroNOF" + index).value;	
	var serie = WF_getElement("filtroSerie" + index).value;	
	if ( (trim(nof) == "") && (trim(serie) == "") ){
		WF_getElement("filtroDescricao" + index).value = "";	
		return;	
	}
	if ( (trim(nof) == "") || (trim(serie) == "") ) return;
	var extraParams = "nof=" + nof + "&serie=" + serie;

    recuperaDescricao(ctlObj, populaDescricao, extraParams);
}

function populaDescricao(wnd){    

    if (WF_getElement("descricao",wnd) != null){
       WF_getElement("filtroDescricao" + idx).value = WF_getElement("descricao",wnd).innerHTML; 
    }

}
//-------------------------------------------------
//***[Testa se uma data é maior que a outra.]***
//FORMATO: YYYY/MM/DD
function WF_dataIniFim (dataIni, dataFim){
	var dIni, dFim;
    var anoIni = dataIni.substring(0,4);
    var mesIni = dataIni.substring(5,7);
    var diaIni = dataIni.substring(8,10);

    var anoFim = dataFim.substring(0,4);
    var mesFim = dataFim.substring(5,7);
    var diaFim = dataFim.substring(8,10);
	
	dIni = new Date(anoIni, mesIni - 1, diaIni);
	dFim = new Date(anoFim, mesFim - 1, diaFim);
	if (dIni.getTime() > dFim.getTime()) {
		return false;
	}
	return true;
}
//-------------------------------------------------
//***[Testa se a data de inicio é maior que a data atual.]***
//FORMATO: YYYY/MM/DD
function WF_dataIniAtual (dataIni){
	var dIni, dFim;
	var dataAtual = WF_getElement("actualDate").value;

    var anoIni = dataIni.substring(0,4);
    var mesIni = dataIni.substring(5,7);
    var diaIni = dataIni.substring(8,10);

    var anoFim = dataAtual.substring(0,4);
    var mesFim = dataAtual.substring(5,7);
    var diaFim = dataAtual.substring(8,10);
	
	dIni = new Date(anoIni, mesIni - 1, diaIni);
	dFim = new Date(anoFim, mesFim - 1, diaFim);
	if (dIni.getTime() > dFim.getTime()) {
		return false;
	}
	return true;
}
//-------------------------------------------------
function WF_setFocus(obj){
    obj.focus();
}
//-------------------------------------------------
