var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1);

function imprimePagina(ref)
{
  ref.focus()
  if (pr) // NS4, IE5
    ref.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize o menu de opções para imprimir a página.(Atalho CTRL+P)");
  return false;
}

function printPage()
{
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Desculpe seu browser não suporta esta função. Por favor utilize o menu de opções para imprimir a página.(Atalho CTRL+P)");
  return false;
}

function Confirma(theform,str){
	if(window.confirm(str)){
		theform.submit();
	}
	return;
}

function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
} // end of the 'setPointer()' function


function recarrega(valor){
	var ativa_recarrega = document.cadastro.ativa_recarrega.value;

	if(!ativa_recarrega){
		document.cadastro.ativa_recarrega.value = valor;
		document.cadastro.submit();
	}
}

function tamanho(campo)
{
	var marcado = 0;
	if(!campo)
		return marcado;

	if(campo.type)
	{
		switch(campo.type)
		{
			case "select-one":
			case "select-multiple":
				for(i = 0; i < campo.length; i++)
				{
					if(campo.options[i].selected)
						marcado++;
				}
				break;
			case "radio"://radio nao tem campo.type
				for(i = 0; i < campo.length; i++)
				{
					if(campo[i].checked)
						marcado++;
				}
				break;
			case "checkbox":
				marcado = campo.checked;
				break;
			case "textarea":
			case "text":
			case "hidden":
				marcado = campo.value.length;
				break;
		}
	}
	else if(campo.length)
	{
		if(campo[0])//radio
		{
			for(i = 0; i < campo.length; i++)
			{
				if(campo[i].checked)
					marcado++;
			}
		}
/*
		else if(campo.options[0])//select
		{
			for(i = 0; i < campo.length; i++)
			{
				if(campo.options[i].selected)
					marcado++;
			}
		}
*/
	}
	return marcado;
}
