var ie4 = document.all ? true:false;

function openCloseDiv(div) {
	if (document.getElementById(div).style.display != 'none') {
		showHideLayer(div,'0');
	} else {
		showHideLayer(div,'1');
	}
}


function viewfilter2(layer1,layer2,index) {
    if(index == 1) {
		eval(document.getElementById(layer1)).style.display = 'none';
		eval(document.getElementById(layer2)).style.display = 'block';
	}
    else {
		eval(document.getElementById(layer1)).style.display = 'block';
		eval(document.getElementById(layer2)).style.display = 'none';
	}
}
function grabGrid() {
    divXant = event.clientX;
}

function moveGrid(cell) {
    if ((event.type == 'mousemove') && (event.button == 1)) {
        d = document.getElementById(cell);
        d.scrollLeft += divXant - event.clientX;
        divXant = event.clientX;
    }
}
function init() {
	mylayer = new DynLayer("boxDHTML")
	mylayer.slideInit();
}
function calcPos() {	// funcao 	: calculo posicao
	leftCentro=0; 		// variavel	: muda relacao com o centro criado pelo calculo 
	if(document.layers) var nn4=15; else var nn4=0; 	// incremento netscape4
	return parseInt(((((document.all)?document.body.clientWidth:window.innerWidth-nn4)-775)/2)+leftCentro);
}
function corrigeDHTML() {
	mylayer.slideTo(calcPos(),null,50000,0);
}
function corrigeFLASH() {
	posTop=38;
	if (document.layers) { // ns4
		boxFlyer=document.layers["boxFlash"];
		boxFlyer.top=posTop;
		boxFlyer.left=calcPos();
	}
	  else if (document.all && !document.getElementById) { // ie4
		boxFlyer=boxFlash; 
		boxFlyer.style.top=posTop+"px";
		boxFlyer.style.left=calcPos()+"px";
	}
	  else if (document.getElementById && document.body.style) { // outros
		boxFlyer=document.getElementById("boxFlash");
		boxFlyer.style.top=posTop+"px";
		boxFlyer.style.left=calcPos()+"px";
	}
}
boxFechado=1;
function acaoLayer() {
	if(boxFechado) mylayer.slideTo(calcPos(),472,20,0,'slideBaixo()');
	else { mylayer.slideTo(calcPos(),201,20,0,'slideCima();'); MM_showHideLayers('hmBarra','','show'); }
}

function boxShow() { setTimeout("MM_showHideLayers('boxFlash','','show','boxDHTML','','show')",1000); }

// finalizacao de abertura do dhtml
function slideBaixo() {
	boxFechado=0; MM_swapImage('btnAbreFecha','','images/btn_dhtml_fecha.gif');
	MM_showHideLayers('hmBarra','','hide');
}
// finalizacao de fechamento do dhtml
function slideCima() {
	boxFechado=1; MM_swapImage('btnAbreFecha','','images/btn_dhtml_abre.gif');
}

// scroll janela
var currentpos=0,alt=1,curpos1=0,curpos2=-1
function scrollwindow(){
	if (document.all) temp=document.body.scrollTop
	else temp=window.pageYOffset;
	
	if (alt==0) alt=1
	else alt=0
	
	if (alt==0) curpos1=temp
	else curpos2=temp
	
	if (curpos1!=curpos2) {
		if (document.all) currentpos=document.body.scrollTop+20
		else currentpos=window.pageYOffset+20
		window.scroll(0,currentpos)
	}
}
function scrollit() { setInterval("scrollwindow()",1) }



function toggleTable(strDivName1, strDivName2, strDivName3, strDivName4, strImgName)
{
    
	img = document.getElementById(strImgName);
    if (eval (document.getElementById(strDivName1)).style.display == 'none')
    {
        //Expand the branch
        eval (document.getElementById(strDivName1)).style.display = 'block';
		eval (document.getElementById(strDivName2)).style.display = 'block';
		eval (document.getElementById(strDivName3)).style.display = 'none';
		eval (document.getElementById(strDivName4)).style.display = 'none';
		img.src = 'images/tableexpand.gif';
    }
    else //Collapse the branch if it IS visible
    {
        //Collapse the branch
        eval (document.getElementById(strDivName1)).style.display = 'none';
		eval (document.getElementById(strDivName2)).style.display = 'none';
		eval (document.getElementById(strDivName3)).style.display = 'block';
		eval (document.getElementById(strDivName4)).style.display = 'block';
		img.src = 'images/tablecollapse.gif';
    }
}


function Abas(index){

	if (index != startIndex){
	
		imgLeft = document.getElementById("leftCorner"+index);
		cell = document.getElementById("tdTab"+index);
		celll = document.getElementById("tdlTab"+index);
		
		if (startIndex != ""){
			startIndex = index;
			imgLeftOld = document.getElementById("leftCorner"+startIndex);
			cellOld = document.getElementById("tdTab"+startIndex);
			cellO2d = document.getElementById("tdlTab"+startIndex);
			
			
			imgLeftOld.src = 'images/abao.gif';
			cellOld.className = "tbTab";
			cellO2d.className = "tbTab";
			
			revelar('layerTab'+startIndex, '0');
		}
		startIndex = index;
		
		imgLeft.src = 'images/abav.gif';
		cell.className = "tbTab_on";
		celll.className = "tbTab_on";
		
		revelar('layerTab'+index, '1'); 	
	}
}

function revelar(layer, option) { 
styleObj = document.getElementById(layer).style; if (option == 1) 
styleObj.display = 'block'; else if (option == 0) styleObj.display = 'none' 


}

function openWin(page, idControl,descControl,top,left,width,height,title){
    idField=idControl;
    descField=descControl;
    if (width==null) width = 350;
    if (height==null) height = 200;
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
    if (top==null) top = wint;
    if (left==null) left = winl;
    if ((title != null) && (title != 'null') && (title != 'undefined')) {
        window.open(page, title,'resizable=yes,scrollbars=yes,status=no,menubar=no,top='+top+',left='+left+',width='+width+',height='+height);
    } else {
        window.open(page, 'popup','resizable=yes,scrollbars=yes,status=no,menubar=no,top='+top+',left='+left+',width='+width+',height='+height);
    }
}

function resizePopup(altura,largura) {
	altura += 55;
	largura += 10;
	resizeTo(largura,altura)
}

function openHelp(page){
   // Vari?vel local
   //root = 'file:///C:/projects/bunge/eservices/eServicesJ2EE/doc/prototype'
   root = '';
   helpPage = root + page;
   window.open(helpPage,'Help','resizable=yes,scrollbars=yes,status=no,menubar=yes,top=200,left=200,width=500,height=400');
}

function FormatDate(field) {
 var re_date = /^(\d+)\/(\d+)\/(\d+)$/;
  if (field.value.indexOf("/") == -1 && field.value.length == 8) {
      field.value = field.value.substr(0,2) + "/" + field.value.substr(2,2) + "/" + field.value.substr(4,4);
  }
  if (!re_date.exec(field.value) && (field.value != "") || (ValidDate(field)==1 && (field.value != ""))){
    alert("Invalid Date format: "+ field.value+"\nEx: 01/01/2003");
    field.focus();
    field.select();
  }
}

function FormatTime(field) {
 var re_time = /^(\d+)\:(\d+)$/;
    if (field.value.indexOf(":") == -1 && field.value.length == 4) {
        field.value = field.value.substr(0,2) + ":" + field.value.substr(2,2);
    }
  if (!re_time.exec(field.value) && (field.value != "") || (ValidTime(field)==1 && (field.value != ""))){
    alert("Invalid Time format: "+ field.value+"\nEx: 10:15");
    field.focus();
    field.select();
  }
}

function verifyCheckedCheckBox(form, checkboxName,msg) {
    if (msg == 'undefined' || msg == null || msg == '') {
       msg = "Delete selected record(s)?";
    }
    if (checkboxName == 'undefined' || checkboxName == null || checkboxName == '') {
       checkboxName = "ids";
    }
    selected = checkedCheckBox(form,checkboxName);
    if (selected == 0) {
        return false
    }
    if (confirm(msg)) {
        return true;
    }
    else {
        return false;
    }
}

function checkedCheckBox(form,checkboxName) {
    ids = eval("document."+form.name+"."+checkboxName);
    if (ids==null) {
        return 0;
    }
    var total = 0;
    var max = ids.length;
    if (max==null) {
        if (eval("document."+form.name+"."+checkboxName+".checked") == true) {
            total += 1;
        }
    } else {
        for (var i = 0; i < max; i++) {
            if (eval("document."+form.name+"."+checkboxName+"[" + i + "].checked") == true) {
                total += 1;
            }
        }
    }
    return total;
}



function selectOption (form,field,string) {
  var f = form;
		var selection = eval("f.elements['"+field+"']");
		var totalOptions= selection.options.length;
		for (i=0;i<	totalOptions;i++) {
    iSelection = (eval("selection.options["+i+"].value"));
		  if (iSelection==string){
							selection.selectedIndex = i;
							}
		}
}


function KeyDate(field) {
var size=field.value.length;
var temp=field.value;
var year=new Date().getYear();

if (event.keyCode < 48 || event.keyCode > 57) {event.returnValue = false;}

if (size==2) {field.value=temp + "/";}
if (size==5) {field.value=temp + "/"+year;}
}

function KeyTime(field) {
var size=field.value.length;
var temp=field.value;

if (event.keyCode < 48 || event.keyCode > 57) {event.returnValue = false;}

if (size==2) {field.value=temp + ":";}
}

function ValidTime(time) {
    var hour = time.value.substring(0,2);
    var minute = time.value.substring(3,5);

    if(time.value.length == 0)
    {
        return 1;
    }
    if(hour>23 || minute>59)
    {
        return 1;
    }
    return 0;

}


function ValidDate(data) {
    var intDia = data.value.substring(0,2);
    var intMes = data.value.substring(3,5);
    var intAno = data.value.substring(6,10);

    if(data.value.length == 0)
    {
        return 1;
    }
    var valor = /[^0-9\/]/;
    valor = valor.exec(data.value);
       if(valor != null)
    {
        //alert("Existem caracteres inv?lidos para Data, Use formato (DD/MM/AAAA)");
        return 1;
    }                                                                                          //alterei colocando o ano
    if(data.value.substring(2,3) != "/" || data.value.substring(5,6) != "/" || data.value.length < 10)
    {
        //alert("Data no formato inv?lido (DD/MM/AAAA)");
        return 1;
    }

     // Testa valor do mes entre 1 e 12
        if(intMes < 1 || intMes > 12) {
      //alert("Data inv?lida! (M?s inv?lido).");
        return 1;
        }

        // Testa valor do dia entre 1 e 31
        if(intDia < 1 || intDia > 31) {
        //alert("Data inv?lida! (Dia inv?lido).");
        return 1;
        }

        // Testa valor do dia para o mes de fevereiro
        if((intMes == 2) && (intDia > 29)) {
        //alert("Data inv?lida! (Este m?s possui menos dias do que o informado).");
        return 1;
        }

        // Testa valor do dia para o mes fevereiro em ano bisexto
        // pode falhar a partir de 2118
        if(intMes == 2 && (intAno % 4) != 0 && intDia == 29) {
        //alert("Data inv?lida! (Este m?s possui apenas 28 dias).");
        return 1;
        }

        // Testa valor do dia para meses com apenas 30 dias
        if((intMes == 4 || intMes == 6 || intMes == 9 || intMes == 11) && intDia == 31) {
        //alert("Data inv?lida! (Este m?s possui apenas 30 dias).");
        return 1;
        }
        return 0;
}

function Compare2Dates(data1,data2,time1,time2,msg) {
    var vazios = false;
    if ((parseFloat(time1.value)==0 || time1.value=="") && (parseFloat(time2.value)==0 || time2.value=="")) {
       vazios = true;//campos estimated
    }
    var stringTime1 = time1.name;
    if (stringTime1.indexOf("stimat")>-1) {
       var estimated = true;
    } else var estimated = false;

    if (data1.value!="") {

         var intDia1 = data1.value.substring(0,2);

         var intMes1 = data1.value.substring(3,5);
         var intAno1 = data1.value.substring(6,10);
         var intHora1 = time1.value.substring(0,2);
         var intMin1 = time1.value.substring(3,5);

         var Date1 = new Date(Date.UTC(intAno1,(intMes1-1),intDia1,intHora1,intMin1,0));
         Date1=(Date1.getTime()/1000.0);

    }


    if (data2.value!="") {

    var intDia2 = data2.value.substring(0,2);
    var intMes2 = data2.value.substring(3,5);
    var intAno2 = data2.value.substring(6,10);
    var intHora2 = time2.value.substring(0,2);
    var intMin2 = time2.value.substring(3,5);

    var Date2 = new Date(Date.UTC(intAno2,(intMes2-1),intDia2,intHora2,intMin2,0));
    Date2=(Date2.getTime()/1000.0);

    }

    var dif = Date2-Date1

       if (dif<0) {

          var selectable=data2.type;
          if (selectable!='hidden') 
          data2.focus();
          else data1.focus();
          alert(msg);
          if (selectable!='hidden')
          data2.select();
          else data1.select();
          return false;
       }

    return true;

}


function PasswordCheck(field1,field2,msg){

if (field2.value!=""){

    if (field1.value != field2.value)
        {
        field2.value="";
        alert(msg);
        field1.focus();
        }

}
}

function checkSpaces(field,msg) {
if (msg == 'undefined' || msg == null || msg == '') {
    msg = "Please, remove spaces from this field!";
}

str = field.value;
flag = 0;
for (i = 0; i < str.length; i++) {
  if (str.charAt(i) == " ") {
  flag++;
  }
}
if (flag > 0) {
  alert(msg);
  field.focus();
}
return flag;
}


//Commom Logostics

//************************************************************************************
//Function   : transferItems
//Purpose    : To transfer data from one list box to another
//Parameters : selFrom -> The list box from which the data is be transfered
//                        Ex: Document.FormName.ListBoxName
//             selTo   -> The list box to which the data is transfered to
//                        Ex: Document.FormName.ListBoxName
//             strQty  -> "All", if all the items in the list have to be transfered
//                        "Selected" or "*", if the selected item has to be transfered (default)
//             strText -> The name of the item (to display in the alert messages)
//************************************************************************************
function transferItems(selFrom, selTo, strQty, strText)
{
    var lstFrom = eval(selFrom);
    var lstTo = eval(selTo);
    var blnItemPresent;

    //Set default text for alert message
    if (strText == "")
    {
        strText = "item";
    }

    if (strQty == "All")//Transfer all items
    {
        if (lstFrom.length > 0 )
        {
            //Transfer all data from "FROM" list box to "TO" list box
            for(j=0;j<lstFrom.length;j++)
            {
                blnItemPresent = false;

                //If a particular data item is present before, dont transfer that
                for(i=0;ilstTo.length;i++)
                {
                    if(lstFrom.options[j].value == lstTo.options[i].value)
                    {
                        blnItemPresent = true;
                    }
                }

                if  (! blnItemPresent)
                {
                    //Transfer the data item
                    lstTo.options[lstTo.length] = new Option(lstFrom.options[j].text, lstFrom.options[j].value);
                }
            }

            //Delete all the items from the "FROM" list box.
            while (lstFrom.length > 0)
            {
                lstFrom.options[0] = null;
            }
        }
        else
        {
            alert("No " + strText + " in the list");
        }
    }
    else //Transfer only the selected items
    {
        if (lstFrom.selectedIndex >= 0)
        {
            for(j=0;j<lstFrom.length;j++)
            {
                blnItemPresent = false;

                if (lstFrom.options[j].selected)
                {
                    //If the selected data item is present before, dont transfer it
                    for(i=0;ilstTo.length;i++)
                    {
                        if(lstFrom.options[j].value == lstTo.options[i].value)
                        {
                            alert("Selected " + strText + " already present");
                            blnItemPresent = true;
                        }
                    }

                    //Transfer the data item
                    if (!blnItemPresent)
                    {
                        lstTo.options[lstTo.length] = new Option(lstFrom.options[j].text, lstFrom.options[j].value);
                    }
                }
            }

            //Delete the selected items from the "FROM" list box.
            while (lstFrom.selectedIndex >= 0)
            {
                lstFrom.options[lstFrom.selectedIndex] = null;
            }
        }
        else
        {
            alert("Please select a " + strText);
        }
    }
    return;
}

//C'tor for ListItem
//listId - The numeric/character value to be used in
//         <option value="">text</option> value attribute of option tag
//         used in HTML select dropdown box.
//listName - The text value to be used in  <option value="">text</option>
//           text part of option tag used in HTML select dropdown box.
function ListItem(listId, listName)
{
    this.id = listId;
    this.name = listName;
    this.parentId = "";
}

//C'tor for ListItem
//listId - The numeric/character value to be used in
//         <option value="">text</option> value attribute of option tag
//         used in HTML select dropdown box.
//listName - The text value to be used in  <option value="">text</option>
//           text part of option tag used in HTML select dropdown box.
//listParentId - The id of the parent item for this item. This is the
//               value which is used in the <option value="">text</option>
//               value attribute of option tag of the controller dropdown
//               box.
function ListItem(listId, listName, listParentId)
{
    this.id = listId;
    this.name = listName;
    this.parentId = listParentId;
}

//***************************************************************************************
//Function   : Transfer
//Purpose    : To transfer data from one list box to another
//Parameters : selFrom -> The list box from which the data is be transfered
//                        Ex: Document.FormName.ListBoxName
//             selTo   -> The list box to which the data is transfered to
//                        Ex: Document.FormName.ListBoxName
//             strQty  -> "All", if all the items in the list have to be transfered
//                        "Selected" or "*", if the selected item has to be transfered (default)
//             strText -> The name of the item (to display in the alert messages)
//****************************************************************************************
function transfer(selFrom, selTo, strQty, strText)
{
    var lstFrom = eval(selFrom);
    var lstTo = eval(selTo);
    var blnItemPresent;

    //Set default text for alert message
    if (strText == "")
    {
        strText = "item";
    }

    if (strQty == "All")//Transfer all items
    {
        if (lstFrom.length > 0 )
        {
            //Transfer all data from "FROM" list box to "TO" list box
            for(j=0;j<lstFrom.length;j++)
            {
                blnItemPresent = false;

                //If a particular data item is present before, dont transfer that
                for(i=0;ilstTo.length;i++)
                {
                    if(lstFrom.options[j].value == lstTo.options[i].value)
                    {
                        blnItemPresent = true;
                    }
                }

                if  (! blnItemPresent)
                {
                    //Transfer the data item
                    lstTo.options[lstTo.length] = new Option(lstFrom.options[j].text, lstFrom.options[j].value);
                }
            }

            //Delete all the items from the "FROM" list box.
            while (lstFrom.length > 0)
            {
                lstFrom.options[0] = null;
            }
        }
        else
        {
            alert("No " + strText + " in the list");
        }
    }
    else //Transfer only the selected items
    {
        if (lstFrom.selectedIndex >= 0)
        {
            for(j=0;j<lstFrom.length;j++)
            {
                blnItemPresent = false;

                if (lstFrom.options[j].selected)
                {
                    //If the selected data item is present before, dont transfer it
                    for(i=0;ilstTo.length;i++)
                    {
                        if(lstFrom.options[j].value == lstTo.options[i].value)
                        {
                            alert("Selected " + strText + " already present");
                            blnItemPresent = true;
                        }
                    }

                    //Transfer the data item
                    if (!blnItemPresent)
                    {
                        lstTo.options[lstTo.length] = new Option(lstFrom.options[j].text, lstFrom.options[j].value);
                    }
                }
            }

            //Delete the selected items from the "FROM" list box.
            while (lstFrom.selectedIndex >= 0)
            {
                lstFrom.options[lstFrom.selectedIndex] = null;
            }
        }
        else
        {
            alert("Please select a " + strText);
        }
    }
    return;
}

function addDropDownItem(formName, dropDownName, item, removeAll)
{
    var dropDown = eval('document.' + formName + '.' + dropDownName);
    if(removeAll)
    {
        // Remove the Existing Elements From the Dependent Drop Down
        // box.
        dropDown.length = 1;
        for(i=0; i < dropDown.length; i++)
        {
            dropDown.options[i] = null;
        }
    }
    dropDown.options[dropDown.length] = new Option(item.name, item.id);
    dropDown.options[0].selected = true;
}

function handleDropDown(formName, dropDownName)
{
    var selText, selValue;
    var dropDownElement = eval('document.' + formName + '.dd_' + dropDownName);
    for(i=0; i < dropDownElement.length; i++)
    {
        if(dropDownElement[i].selected == true)
        {
            selText = dropDownElement[i].text;
            selValue = dropDownElement[i].value;
        }
    }
    if(selText == "Add New")
    {
        eval('dd_' + dropDownName + '_layer').style.display = 'none';
        eval('txt_' + dropDownName + '_layer').style.display = 'block';
        eval('document.' + formName + '.' + dropDownName + 'DropDownState').value = 1;
        eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = "";
        eval('document.' + formName + '.' + dropDownName + 'SelectedValue').value = -1;
        addDropDownItem(formName, dropDownName, new ListItem(-1,""), true);
    }
    else
    {
        eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = selText;
        eval('document.' + formName + '.' + dropDownName + 'SelectedValue').value = selValue;
        addDropDownItem(formName, dropDownName, new ListItem(selValue, selText), true);
    }
}

function handleDropDownEdit(source, formName, dropDownName)
{
    var txtElement = eval('document.' + formName + '.txt_' + dropDownName);
    var dropDownElement = eval('document.' + formName + '.dd_' + dropDownName);
    if(event.type == "click")
    {
        eval('dd_' + dropDownName + '_layer').style.display = 'block';
        eval('txt_' + dropDownName + '_layer').style.display = 'none';
        dropDownElement.options[0].selected = true;
        txtElement.value = "";
        var selText = eval('document.' + formName + '.txt_' + dropDownName + '.value');
        eval('document.' + formName + '.' + dropDownName + 'DropDownState').value = 0;
        eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = dropDownElement.options[0].text;
        eval('document.' + formName + '.' + dropDownName + 'SelectedValue').value = dropDownElement.options[0].value;
        addDropDownItem(formName, dropDownName, new ListItem(dropDownElement.options[0].value, dropDownElement.options[0].text), true);
    }
    else
    {
        eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = txtElement.value;
        addDropDownItem(formName, dropDownName, new ListItem(-1, txtElement.value), true);
    }
}

function handleNoDropDownEdit(formName, dropDownName)
{
    var txtElement = eval('document.' + formName + '.txt_' + dropDownName);
    var orignalText = eval('document.' + formName + '.' + dropDownName + 'OriginalText').value;
    var orignalValue = eval('document.' + formName + '.' + dropDownName + 'OriginalValue').value;
    if(event.type == "click")
    {
        if(txtElement.readOnly)
        {
            txtElement.readOnly = false;
            txtElement.value = "";
            eval('document.' + formName + '.' + dropDownName + 'DropDownState').value = 1;
            eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = "";
            eval('document.' + formName + '.' + dropDownName + 'SelectedValue').value = -1;
            addDropDownItem(formName, dropDownName, new ListItem(-1, ""), true);
        }
        else
        {
            eval('document.' + formName + '.' + dropDownName + 'DropDownState').value = 0;
            eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = orignalText;
            eval('document.' + formName + '.' + dropDownName + 'SelectedValue').value = orignalValue;
            addDropDownItem(formName, dropDownName, new ListItem(originValue, orignalText), true);
            txtElement.value = orignalText;
            txtElement.readOnly = true;
        }
    }
    else
    {
        eval('document.' + formName + '.' + dropDownName + 'SelectedText').value = txtElement.value;
        addDropDownItem(formName, dropDownName, new ListItem(-1, txtElement.value), true);
    }
}

function toggleContent(strDivName)
{
    //Unfold the branch if it isn't visible
    if (eval (document.getElementById(strDivName)).style.display == 'none')
    {
        //Expand the branch
        eval (document.getElementById(strDivName)).style.display = 'block';
    }
    else //Collapse the branch if it IS visible
    {
        //Collapse the branch
        eval (document.getElementById(strDivName)).style.display = 'none';
    }
}
function toggleContentV(strDivName, Nindex)
{
    //Unfold the branch if it isn't visible
    if (eval (document.getElementById(strDivName)).style.visibility == 'hidden' && Nindex == 0)
    {
        //Expand the branch
		
        eval (document.getElementById(strDivName)).style.visibility = 'visible';
    }
    else //Collapse the branch if it IS visible
    {
		
        //Collapse the branch
        eval (document.getElementById(strDivName)).style.visibility = 'hidden';
    }
		if (eval (document.getElementById(strDivName)).style.visibility == 'hidden' && Nindex == 1)
    {
        //Expand the branch
		
        eval (document.getElementById(strDivName)).style.visibility = 'hidden';
    }
}

//***********************************************************************************
//Function  : Toggle the expanding and collapsible leaf struture.
//Purpose   : Expand and Collapse the leafs defined in the document.
//Parameters: strImgName -> The image name used in the html.
//            strExpandImgSource -> The FQN of the image file name used for showing
//                                    the expanded leafs.
//       strCollapseImgSource -> The FQN of the image file name used for
//                                       showing the collapsed leafs.
//            strDivName -> The name/id of div which builds the leaf struture in HTML
//***********************************************************************************
function toggleLeafs(strDivName, strImgName, strExpandImgSource, strCollapseImgSource)
{
    //Unfold the branch if it isn't visible
    if (eval (document.getElementById(strDivName)).style.display == 'none')
    {
        expand(strImgName, strExpandImgSource, strDivName);
    }
    else //Collapse the branch if it IS visible
    {
        collapse(strImgName, strCollapseImgSource, strDivName);
    }
}

//***********************************************************************************
//Function  : collapse
//Purpose   : Collapse the leafs defined in the document.
//Parameters: strImgName -> The image name used in the html.
//            strImgSource -> The FQN of the image file name used for showing the
//                              collapsed leafs.
//            strDivName -> The name/id of div which builds the leaf struture in HTML
//***********************************************************************************
function collapse(strImgName, strImgSource, strDivName)
{
    //Collapse the branch
    eval (document.getElementById(strDivName)).style.display = 'none';

    //Change the image
    document.images[strImgName].src = strImgSource
}

//***********************************************************************************
//Function  : expand
//Purpose   : Expand the leafs defined in the document.
//Parameters: strImgName -> The image name used in the html.
//            strImgSource -> The FQN of the image file name used for showing the
//                              expanded leafs.
//            strDivName -> The name/id of div which builds the leaf struture in HTML
//***********************************************************************************
function expand(strImgName, strImgSource, strDivName)
{
    //Expand the branch
    eval(document.getElementById(strDivName)).style.display = 'block';

    //Change the image
    document.images[strImgName].src = strImgSource;

}

function showHideLayerComment(layerName, imgName){
img = document.getElementById(imgName);

image = img.src;
if (image.indexOf("EditComment.gif")>1) { status = 1;} else { status = 0;}

if (status == 1) {
		MM_showHideLayers(layerName,'','show');
		img.src = '../icon/EditingComment.gif';
		} else
		{ 
		MM_showHideLayers(layerName,'','hidden');
		img.src = '../icon/EditComment.gif';
		}
}
function showHideLayerCommentNE(layerName, imgName){
img = document.getElementById(imgName);
image = img.src;
if (image.indexOf("EditCommentNE.gif")>1) { status = 1;} else { status = 0;}

if (status == 1) {
		MM_showHideLayers(layerName,'','show');
		img.src = '../icon/EditingCommentNE.gif';
		} else
		{ 
		MM_showHideLayers(layerName,'','hidden');
		img.src = '../icon/EditCommentNE.gif';
		}
}


//***********************************************************************************
//               VALIDADE MEASURE UNIT
//***********************************************************************************

function InvalidMeasure(entry) {
test = ""; //temporary holder
temp1 = ""; //temporary holder
temp = (entry.value).split (",");
temp = temp.join(".");
if (isNaN(parseFloat(temp.charAt(0))) || isNaN(parseFloat(temp.charAt(temp.length-1)))) {return (true)}
//varre o campo, e l? caracteres inv?lidos
dots=0;
for (i=1;i<=temp.length;i++) {
  test=(temp.substring(i-1, i));
    if ((test.charCodeAt(0) >= 47) && (test.charCodeAt(0) <= 57)){
    temp1 = temp1 + (test);
    }
    else if (test.charCodeAt(0) == 46){
    temp1 = temp1 + (test);
    dots++;
    }
    else return (true);
}
if (dots>1) {return (true)}
temp=temp1;
entry.value=temp;
if (isNaN(parseFloat(temp)) || parseFloat(temp)<0) {return (true)}
}


//************************Mascara de data
function KeyDate(field) { // aplica m?scara
	var size = field.value.length;
	var temp = field.value;
	
	if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;
	if (size == 2) field.value=temp + "/";
	if (size == 5) field.value=temp + "/";
	if (size == 10) event.returnValue = false
}

function FormatDate(field) {
	var dia = field.value.substr(0,2);
	var mes = field.value.substr(3,2);
	var ano = field.value.substr(6,4);
	var anoBis;
	var data = true;
	
	if (field.value != "") {
		if (field.value.length < 10) data = false;
		
		// Validando m?s e dia no geral
		if ((dia < 01) || (dia > 31) || (mes < 01) || (mes > 12) || (ano < 1900)) {
			data = false;
		}
		
		// Validando meses com 30 dias
		if ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) {
			if (dia > 30) {
				data = false;
			}
		}
		
		// Valida??es de fevereiro
		if (mes == 02){
			if (ano % 4 != 0) anoBis = false;
			else {
				if (ano % 100 != 0) anoBis = true;
				else {
					if (ano % 400 != 0) anoBis = false; 
					else anoBis = true;
				}
			}
			if (!anoBis) {
				if (dia > 28) data = false;
			} 
			else {
				if (dia > 29) data = false;
			}
		}
		// Se data inv?lida (data == false)
		if (!data) {
			alert("Invalid Date format: "+ field.value+"\nEx: 01/01/2005");
			field.value = "";
			field.focus();
		}
	}
}
//***********************************************************************************
// TABS
//***********************************************************************************

function changeTab(index){
	if (index != startIndex){
		imgLeft = document.getElementById("leftCorner"+index);
		imgRight = document.getElementById("rightCorner"+index);
		cell = document.getElementById("tdTab"+index);
		if (startIndex != ""){
			imgLeftOld = document.getElementById("leftCorner"+startIndex);
			imgRightOld = document.getElementById("rightCorner"+startIndex);
			cellOld = document.getElementById("tdTab"+startIndex);
			imgLeftOld.src = '/estatico/pagamentosweb/images/tabLeftCorner.gif';
			imgRightOld.src = '/estatico/pagamentosweb/images/tabRightCorner.gif';
			cellOld.className = "tabButton";
			showHideLayer('layerTab'+startIndex, '0');
		}
		startIndex = index;
		imgLeft.src = '/estatico/pagamentosweb/images/tabLeftCorner_on.gif';
		imgRight.src = '/estatico/pagamentosweb/images/tabRightCorner_on.gif';
		cell.className = "tabButton_on";
		showHideLayer('layerTab'+index, '1'); 	
	}
}

function changeTabi(index){

	if (index != startIndexi){
	
		
		cell = document.getElementById("tdTabi"+index);
		
		if (startIndexi != ""){
			
			cellOldi = document.getElementById("tdTabi"+startIndexi);
			
			
			cellOldi.className = "tbTabi";
			
			showHideLayeri('layerTabi'+startIndexi, '0');
		}
		startIndexi = index;
		
		
		cell.className = "tbTabi_on";
		
		showHideLayeri('layerTabi'+index, '1'); 	
	}
}
function changeTabbox(indexbox){

	if (indexbox != startIndexbox){
	
		imgLeft = document.getElementById("leftCorner"+indexbox);
		imgRight = document.getElementById("rightCorner"+indexbox);
		cell = document.getElementById("tbTabBox"+indexbox);
		
		if (startIndexbox != ""){
			imgLeftOld = document.getElementById("leftCorner"+startIndexbox);
			imgRightOld = document.getElementById("rightCorner"+startIndexbox);
			cellOld = document.getElementById("tbTabBox"+startIndexbox);
			
			imgLeftOld.src = '../icon/TbBoxL.gif';
			imgRightOld.src = '../icon/TbBoxR.gif';
			cellOld.className = "tbTabBox";
			
			showHideLayer('layerTab'+startIndexbox, '0');
		}
		startIndexbox = indexbox;
		
		imgLeft.src = '../icon/TbBoxL_on.gif';
		imgRight.src = '../icon/TbBoxR_on.gif';
		cell.className = "tbTabBox_on";
		
		showHideLayer('layerTab'+indexbox, '1'); 	
	}
}
function changeTabG(index){

	if (index != startIndex){
	
		imgLeft = document.getElementById("leftCorner"+index);
		imgRight = document.getElementById("rightCorner"+index);
		cell = document.getElementById("tdTab"+index);
		
		if (startIndex != ""){
			imgLeftOld = document.getElementById("leftCorner"+startIndex);
			imgRightOld = document.getElementById("rightCorner"+startIndex);
			cellOld = document.getElementById("tdTab"+startIndex);
			
			imgLeftOld.src = 'images/cantoeG.jpg';
			imgRightOld.src = 'images/cantodG.jpg';
			cellOld.className = "tbTab";
			
			showHideLayer('layerTab'+startIndex, '0');
		}
		startIndex = index;
		
		imgLeft.src = 'images/cantoeG_on.jpg';
		imgRight.src = 'images/cantodG_on.jpg';
		cell.className = "tbTab_on";
		
		showHideLayer('layerTab'+index, '1'); 	
	}
}




function sendPage(pageName) { window.location.href = pageName }
function changeImage(imgName,imgObj) { eval('document.images["'+imgName+'"].src = '+imgObj+'.src') }
function preloadImage(imgObj,imgSrc) { eval(imgObj+' = new Image()'); eval(imgObj+'.src = "'+imgSrc+'"') }
function Radio(inputName,imgName,length,defaultValue) { this.imgName = imgName; this.inputName = inputName; this.length = length; this.change = RadioChange; this.value = (defaultValue)? defaultValue : "" }
function RadioChange(value,index) { this.value = value; for (var i=1; i<=this.length; i++) changeImage(this.imgName+i,'radioOff'); changeImage(this.imgName+index,'radioOn'); formulario = document.forms[0]; eval("formulario." + this.inputName + ".value = '"+value+"'") }
function CheckBox(inputName,imgName,trueValue,falseValue,defaultToTrue) { this.imgName = imgName; this.inputName = inputName; this.trueValue = trueValue; this.falseValue = falseValue; this.state = (defaultToTrue) ? 1 : 0; this.value = (this.state) ? this.trueValue : this.falseValue; this.change = CheckBoxChange }
function CheckBoxChange() { this.state = (this.state) ? 0 : 1; this.value = (this.state) ? this.trueValue : this.falseValue; changeImage(this.imgName,'check'+this.state); form = document.forms[0]; eval("form."+this.inputName+".value = "+this.value) }

function fgFixPosition(arrfDiv, arrfTop, arrfLeft) { if (navigator.appName == "Netscape") for (var i = 0; i < arrfDiv.length; i++) { obj = eval("document.getElementById('" + arrfDiv[i] + "')"); if (obj != null) { obj.style.top = arrfTop[i]; obj.style.left = arrfLeft[i] } } }
function fgSelectAll(vfFormName, vfInputNameAll, vfInputNameEach) { form = eval("document." + vfFormName); for (var i = 0; i < form.elements.length; i++) { var e = form.elements[i]; if ((e.name != vfInputNameAll) && (e.type == "checkbox")) { if (vfInputNameEach != null) { if (e.name == vfInputNameEach) e.checked = eval("form." + vfInputNameAll + ".checked") } else { e.checked = eval("form." + vfInputNameAll + ".checked") } } } }
function fgDisable(vfFormName, vfInputName, vfDisable) { var form = document.forms[vfFormName]; for (i = 0; i < form.elements.length; i++) { var e = form.elements[i]; if (e.name.indexOf(vfInputName) != -1) { e.disabled = vfDisable; e.style.backgroundColor = (vfDisable) ? '#F0F0F0' : '' } } }
function fgCheckSelect(vfFormName, vfSelectName, vfLayerId, vfInputName) { inpSelect = eval("document.forms['" + vfFormName + "']." + vfSelectName); if (inpSelect.options[inpSelect.selectedIndex].value == '') { showHideLayer(vfLayerId, 0); if (vfInputName) eval("document.forms['" + vfFormName + "']." + vfInputName + ".value = ''") } else showHideLayer(vfLayerId, 1) }
function showHideLayer(layer, option) { styleObj = document.getElementById(layer).style; if (option == 1) styleObj.display = 'block'; else if (option == 0) styleObj.display = 'none' }
function showHideLayeri(layer, option) { styleObj = document.getElementById(layer).style; if (option == 1) styleObj.display = 'block'; else if (option == 0) styleObj.display = 'none' }


function showHideLayer2(layerName, imgName){
img = document.getElementById(imgName);

image = img.src;
if (image.indexOf("mais.gif")>1) { status = 1;} else { status = 0;}

if (status == 1) {
		MM_showHideLayers(layerName,'','show');
		img.src = '../images/bullet_panel_menos.gif';
		} else
		{ 
		MM_showHideLayers(layerName,'','hidden');
		img.src = '../images/bullet_panel_mais.gif';
		}
}
function showHideLayerInt(layerName, imgName){
img = document.getElementById(imgName);

image = img.src;
if (image.indexOf("mais.gif")>1) { status = 1;} else { status = 0;}

if (status == 1) {
		MM_showHideLayers(layerName,'','show');
		img.src = '../images/bullet_panel_menos.gif';
		} else
		{ 
		MM_showHideLayers(layerName,'','hidden');
		img.src = '../images/bullet_panel_mais.gif';
		}
}
function showHideDisInt(layerName, imgName){
img = document.getElementById(imgName);

image = img.src;
if (image.indexOf("mais.gif")>1) { status = 1;} else { status = 0;}

if (status == 1) {
		
		eval (document.getElementById(layerName)).style.display = 'block';
		img.src = '../images/bullet_panel_menos.gif';
		} else
		{ 
		eval (document.getElementById(layerName)).style.display = 'none';
		img.src = '../images/bullet_panel_mais.gif';
		}
}
function showHideLayer3(layerName, imgName){
img = document.getElementById(imgName);

image = img.src;
if (image.indexOf("More.gif")>1) { status = 1;} else { status = 0;}

if (status == 1) {
		MM_showHideLayers(layerName,'','show');
		img.src = '../images/arrowMinus.gif';
		} else
		{ 
		MM_showHideLayers(layerName,'','hidden');
		img.src = '../images/arrowMore.gif';
		}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function transfer(selFrom, selTo, strQty, strText)
{
    var lstFrom = eval(selFrom);
    var lstTo = eval(selTo);
    var blnItemPresent;

    //Set default text for alert message
    if (strText == "")
    {
        strText = "item";
    }

    if (strQty == "All")//Transfer all items
    {
        if (lstFrom.length > 0 )
        {
            //Transfer all data from "FROM" list box to "TO" list box
            for(j=0;j<lstFrom.length;j++)
            {
                blnItemPresent = false;

                //If a particular data item is present before, dont transfer that
                for(i=0;i<lstTo.length;i++)
                {
                    if(lstFrom.options[j].value == lstTo.options[i].value)
                    {
                        blnItemPresent = true;
                    }
                }

                if  (! blnItemPresent)
                {
                    //Transfer the data item
                    lstTo.options[lstTo.length] = new Option(lstFrom.options[j].text, lstFrom.options[j].value);
                }
            }

            //Delete all the items from the "FROM" list box.
            while (lstFrom.length > 0)
            {
                lstFrom.options[0] = null;
            }
        }
        else
        {
            alert("No " + strText + " in the list");
        }
    }
    else //Transfer only the selected items
    {
        if (lstFrom.selectedIndex >= 0)
        {
            for(j=0;j<lstFrom.length;j++)
            {
                blnItemPresent = false;

                if (lstFrom.options[j].selected)
                {
                    //If the selected data item is present before, dont transfer it
                    for(i=0;i<lstTo.length;i++)
                    {
                        if(lstFrom.options[j].value == lstTo.options[i].value)
                        {
                            alert("Selected " + strText + " already present");
                            blnItemPresent = true;
                        }
                    }

                    //Transfer the data item
                    if (!blnItemPresent)
                    {
                        lstTo.options[lstTo.length] = new Option(lstFrom.options[j].text, lstFrom.options[j].value);
                    }
                }
            }

            //Delete the selected items from the "FROM" list box.
            while (lstFrom.selectedIndex >= 0)
            {
                lstFrom.options[lstFrom.selectedIndex] = null;
            }
        }
        else
        {
            alert("Please select a " + strText);
        }
    }
    return;
}

function RetiraAcentos(Campo)
{
   var Acentos = "???????????????????????????abcdefghijklmnopqrstuvxwyz'";
   var Traducao ="AAAAAAAAAEEEEIIOOOOOOUUUUCCABCDEFGHIJKLMNOPQRSTUVXWYZ ";
   var Posic, Carac;
   var TempLog = "";
   for (var i=0; i < Campo.length; i++)
   {
   Carac = Campo.charAt (i);
   Posic  = Acentos.indexOf (Carac);
   if (Posic > -1)
	  TempLog += Traducao.charAt (Posic);
   else
      TempLog += Campo.charAt (i);
   }
      return (TempLog);
}

// Permite que o usuario digite apenas numeros sem sinal.
// Funciona no mozilla e no ie
// Nao coloca pontos ou virgulas, mas pode ser combinada com funcao keyDownNumber para adicionar a mascara
// Para um campo de 5 digitos sem sinal e sem mascara:
  // <INPUT name=ano maxLength=5 onkeypress="return(maskUnsignedNumber(event, this, 5))" size=7 class="form">
function maskUnsignedNumber(e, campo, tam_max) {
  if(String.fromCharCode(ie4 ? e.keyCode : e.which) == '-')
    return false;
  return maskNumber(e, campo, tam_max);
}

// Permite que o usuario digite apenas numeros. No 1ro caracter aceita tambem o sinal de '-'
// Funciona no mozilla e no ie
// Nao coloca pontos ou virgulas, mas pode ser combinada com funcao keyDownNumber para adicionar a mascara
// Para um campo de 5 digitos com sinal e sem mascara:
  // <INPUT name=ano maxLength=6 onkeypress="return(maskNumber(event, this, 5))" size=7 class="form">
function maskNumber(e, campo, tam_max) {
  var keyCode = (ie4 ? e.keyCode : e.which);
  var keyChar = String.fromCharCode(keyCode);
  var cont = 0;

  if(keyCode == 0 || keyCode == 8 || keyCode == 13)
    return true;
  if("-1234567890".indexOf(keyChar) == -1 || (keyChar == '-' && campo.value.length > 0))
    return false;
  // Verifica se nao excedeu o tam max
  texto = campo.value;
  for(i = 0; i < texto.length; i++)
    if(texto.charAt(i) >= '0' && texto.charAt(i) <= '9')
      cont++;
  return(cont < tam_max);
}

//Completa com zeros a esquerda o input text
//usage: onblur="completaCodigo('numcartao', 9);"
function completaCodigo(idObj, size){
	var codigo = document.getElementById(idObj);
	codigo.value = trim(codigo.value);
	if (codigo.value != '') {
		var offset = size - parseInt(codigo.value.length ,10);
		if (offset < size) {
			for (i = 0; i < offset; i++){
				codigo.value = '0' + codigo.value;
			}
		}
	}
}

//trim
function trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}