function IsDate(day, month, year) {
	var date = new Date();
	
	date.setFullYear(year, month -1, day);
	
	return (date.getDate() == day && date.getMonth() == month -1 && date.getFullYear() == year);
}

function IsEmpty(value) {
	return (value.replace(/^\s+|\s+$/gim, "").length == 0);
}

function IsDisplayNone(element) {
	return (element.style.display.toLowerCase().match(/\s*none[\s;]*/))
}

ClearMask.Expressions = new Object();
ClearMask.Expressions.Date = /_+|\/+/gim;
ClearMask.Expressions.CPF = /_+|\.+|-/gim;
ClearMask.Expressions.String = /_+/gim;

ClearMask.Masks = new Object();
ClearMask.Masks.Date = "date";
ClearMask.Masks.CPF = "cpf";
ClearMask.Masks.String = "string";

function ClearMask(value, mask) {
	var ret;
	
	switch (mask) {
		case ClearMask.Masks.Date:
			ret = value.replace(ClearMask.Expressions.Date, "");
			break;
		case ClearMask.Masks.CPF:
			ret = value.replace(ClearMask.Expressions.CPF, "");
			break;
		case ClearMask.Masks.String:
			ret = value.replace(ClearMask.Expressions.String, "");
			break;
	}
	
	return ret;
}

InspectMaxlength.interval = undefined;
InspectMaxlength.elements = new Object();
InspectMaxlength.elementsIDs = [];

function InspectMaxlength(element, length) {
    if (InspectMaxlength.elements[element.id] == undefined) {
        InspectMaxlength.elements[element.id] = {element: element, maxlength: length};
        InspectMaxlength.elementsIDs.push(element.id);
        
        if (InspectMaxlength.interval == undefined) {
            InspectMaxlength.interval = window.setInterval("InspectMaxlengthElements();", 100);
        }
    }
    
    element.mLength = String(length);
    
    InspectMaxlength.currentElement = element;
}

function InspectMaxlengthElements() {
    var current = InspectMaxlength.currentElement;
    
    for (var i = 0; i < InspectMaxlength.elementsIDs.length; i++) {
        var id = InspectMaxlength.elementsIDs[i];
        var object = InspectMaxlength.elements[id];
        var element = object.element;
        var length = object.maxlength;
        
        if (element.value.length > length)
            element.value = element.value.substring(0, length);
    }
    
    if (current != undefined)
        CountTextarea(current);
}

function CountTextarea(field) {
    if (CountTextarea.label == undefined) {
        CountTextarea.label = document.createElement("DIV");
        
        CountTextarea.label.className = "counter";
    }
    
    var label = CountTextarea.label;
    var count = Number(field.mLength) - field.value.length;
    var labelContent;
    
    field.parentElement.appendChild(label);
    
    if (count == 1) {
        labelContent = String(count) + " caractere restante de um total de " + field.mLength;
    }
    else if (count == Number(field.mLength)) {
        labelContent = "Nenhum caractere preenchido de um total de " + field.mLength;
    }
    else if (count > 0) {
        labelContent = String(count) + " caracteres restantes de um total de " + field.mLength;
    }
    else if (count < 0) {
        labelContent = String(count) + " caracteres excedentes de um total de " + field.mLength;
    }
    else if (Number(field.mLength) == 1) {
        labelContent = "Limite de " + field.mLength + " caractere atingido";
    }
    else {
        labelContent = "Limite de " + field.mLength + " caracteres atingido";
    }
    
    label.innerText = labelContent;
    
    CountTextarea.field = field;
    
    field.attachEvent("onblur", function() {
            CountTextarea.label.removeNode(true);
            InspectMaxlength.currentElement = undefined;
        });
}

function LoadVideoObjectString(url) {
    var player = document.createElement("OBJECT");
    var pFName = document.createElement("PARAM");
    var pAAStart = document.createElement("PARAM");
    var pTAStart = document.createElement("PARAM");
    var pAStart = document.createElement("PARAM");
    var pASize = document.createElement("PARAM");
    var pSStatusBar = document.createElement("PARAM");
    var pSControls = document.createElement("PARAM");
    var pSDisplay = document.createElement("PARAM");
    var embed = document.createElement("EMBED");
    var objectMediaPlayer = document.getElementById("objectMediaPlayer");
    
    if (objectMediaPlayer) {
		if (isIE()) {
			objectMediaPlayer.removeNode(true);
		}
		else {
			objectMediaPlayer.parentNode.removeChild(objectMediaPlayer);
		}
    }
    
    url = "http://videos.itau.com.br:9999/Unicef2009/" + url;
    
    player.setAttribute("classID", "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95");
    player.setAttribute("type", "application/x-mplayer2");
    player.setAttribute("width", "380");
    player.setAttribute("height", "360");
    player.setAttribute("id", "objectMediaPlayer");
    player.setAttribute("name", "objectMediaPlayer");
    
    pFName.setAttribute("name", "FileName");
    pFName.setAttribute("value", url);
    
    pAAStart.setAttribute("name", "AnimationAtStart");
    pAAStart.setAttribute("value", "False");
    
    pTAStart.setAttribute("name", "TransparentAtStart");
    pTAStart.setAttribute("value", "False");
    
    pAStart.setAttribute("name", "AutoStart");
    pAStart.setAttribute("value", "True");
    
    pASize.setAttribute("name", "AutoSize");
    pASize.setAttribute("value", "False");
    
    pSStatusBar.setAttribute("name", "ShowStatusBar");
    pSStatusBar.setAttribute("value", "True");
    
    pSControls.setAttribute("name", "ShowControls");
    pSControls.setAttribute("value", "True");
    
    pSDisplay.setAttribute("name", "ShowDisplay");
    pSDisplay.setAttribute("value", "False");
    
    embed.setAttribute("src", pFName.getAttribute("value"));
    embed.setAttribute("width", player.getAttribute("width"));
    embed.setAttribute("height", player.getAttribute("height"));
    embed.setAttribute("autoStart", pAStart.getAttribute("value"));
    embed.setAttribute("type", player.getAttribute("type"));
    embed.setAttribute("pluginsPage", "mms://www.microsoft.com/windows/windowsmedia/intl/download/default.asp?DispLang=br");
    embed.setAttribute("name", "embedMediaPlayer");
    embed.setAttribute("id", "embedMediaPlayer");
    embed.setAttribute("showControls", pSControls.getAttribute("value"));
    embed.setAttribute("showDisplay", pSDisplay.getAttribute("value"));
    
    player.appendChild(pFName);
    player.appendChild(pAAStart);
    player.appendChild(pTAStart);
    player.appendChild(pAStart);
    player.appendChild(pASize);
    player.appendChild(pSStatusBar);
    player.appendChild(pSControls);
    player.appendChild(pSDisplay);
    
    if (!isIE()) {
		player.appendChild(embed);
	}
	else {
		var ret = player.outerHTML.replace(/\>\</gim, "/><");
		
		ret = ret.substring(0, ret.toUpperCase().indexOf("</OBJECT>"))
			+ embed.outerHTML + "</EMBED>" + ret.substring(ret.toUpperCase().indexOf("</OBJECT>"));
		
		player = ret;
	}
    
    return player;
}

LoadAudioObjectString.Unicef2009BaseURL = "";

function LoadAudioObjectString(url) {
    var player = document.createElement("OBJECT");
    var pFName = document.createElement("PARAM");
    var pAAStart = document.createElement("PARAM");
    var pTAStart = document.createElement("PARAM");
    var pAStart = document.createElement("PARAM");
    var pASize = document.createElement("PARAM");
    var pSStatusBar = document.createElement("PARAM");
    var pSControls = document.createElement("PARAM");
    var pSDisplay = document.createElement("PARAM");
    var embed = document.createElement("EMBED");
    var objectMediaPlayer = document.getElementById("objectMediaPlayer");
    
    if (objectMediaPlayer) {
		if (isIE()) {
			objectMediaPlayer.removeNode(true);
		}
		else {
			objectMediaPlayer.parentNode.removeChild(objectMediaPlayer);
		}
    }
    
    url = "http://videos.itau.com.br:9999/Unicef2009/" + url;
    
    player.setAttribute("classID", "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95");
    player.setAttribute("type", "application/x-mplayer2");
    player.setAttribute("width", "380");
    player.setAttribute("height", "69");
    player.setAttribute("id", "objectMediaPlayer");
    player.setAttribute("name", "objectMediaPlayer");
    
    pFName.setAttribute("name", "FileName");
    pFName.setAttribute("value", url);
    
    pAAStart.setAttribute("name", "AnimationAtStart");
    pAAStart.setAttribute("value", "False");
    
    pTAStart.setAttribute("name", "TransparentAtStart");
    pTAStart.setAttribute("value", "False");
    
    pAStart.setAttribute("name", "AutoStart");
    pAStart.setAttribute("value", "True");
    
    pASize.setAttribute("name", "AutoSize");
    pASize.setAttribute("value", "False");
    
    pSStatusBar.setAttribute("name", "ShowStatusBar");
    pSStatusBar.setAttribute("value", "True");
    
    pSControls.setAttribute("name", "ShowControls");
    pSControls.setAttribute("value", "True");
    
    pSDisplay.setAttribute("name", "ShowDisplay");
    pSDisplay.setAttribute("value", "False");
    
    embed.setAttribute("src", pFName.getAttribute("value"));
    embed.setAttribute("width", player.getAttribute("width"));
    embed.setAttribute("height", player.getAttribute("height"));
    embed.setAttribute("autoStart", pAStart.getAttribute("value"));
    embed.setAttribute("type", player.getAttribute("type"));
    embed.setAttribute("pluginsPage", "mms://www.microsoft.com/windows/windowsmedia/intl/download/default.asp?DispLang=br");
    embed.setAttribute("name", "embedMediaPlayer");
    embed.setAttribute("id", "embedMediaPlayer");
    embed.setAttribute("showControls", pSControls.getAttribute("value"));
    embed.setAttribute("showDisplay", pSDisplay.getAttribute("value"));
    
    player.appendChild(pFName);
    player.appendChild(pAAStart);
    player.appendChild(pTAStart);
    player.appendChild(pAStart);
    player.appendChild(pASize);
    player.appendChild(pSStatusBar);
    player.appendChild(pSControls);
    player.appendChild(pSDisplay);
    
    if (!isIE()) {
		player.appendChild(embed);
	}
	else {
		var ret = player.outerHTML.replace(/\>\</gim, "/><");
		
		ret = ret.substring(0, ret.toUpperCase().indexOf("</OBJECT>"))
			+ embed.outerHTML + "</EMBED>" + ret.substring(ret.toUpperCase().indexOf("</OBJECT>"));
		
		player = ret;
	}
    
    return player;
}

function SetInnerHTML(element, textContent) {
    if (isIE()) {
        element.innerHTML = textContent;
    }
    else {
        var range;
        var contextualFragment;
        
        range = element.ownerDocument.createRange();
        
        range.selectNodeContents(element);
        range.deleteContents();
        
        contextualFragment = range.createContextualFragment(textContent);
        
        element.appendChild(contextualFragment);
    }
}

function SetZero(field) {
    SetZero.field = field;
    
    if (field.value.replace(/\D/gim, "").length == 0) {
        field.value = "0";
        window.setTimeout("SetZero.field.value = \"0\";", 10);
    }
}

function ClearZero(field) {
    if (Number("0" + field.value.replace(/\D/gim, "")) == 0)
        field.value = "";
}

function isIE() {
    return (navigator.appName.indexOf("Internet Explorer") > -1);
}

function Numeric(evt) {
	var key;
	
	if (isIE())
		key = evt.keyCode;
	else
		key = evt.charCode;
	
	if (isNaN(String.fromCharCode(key))) {
		if (isIE())
			evt.returnValue = false;
		else if (key != 0)
			evt.preventDefault();
	}
}

function MaxLength(element, length)
{
    if (element.value.length >= length) {
        event.returnValue = false;
        
        element.value = element.value.substring(0, length);
        
        return false;
    }
    
    return true;
}

function abreRegulamento() {
    window.open('pdf/Regulamento_A4.pdf','_blank','location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=0');
}

function abreInscricao(url) {
    window.open(url,'_blank','location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=0');
}

function FormataCGC(Formulario, Campo, TeclaPres) { 
    var tecla = TeclaPres.keyCode; 
    var strCampo; 
    var vr; 
    var tam; 
    var TamanhoMaximo = 14; 

    //alert("document." + Formulario + "." + Campo);

    eval("strCampo = document." + Formulario + "." + Campo); 

    vr = strCampo.value; 
    vr = vr.replace("/", ""); 
    vr = vr.replace("/", ""); 
    vr = vr.replace("/", ""); 
    vr = vr.replace(",", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace(".", ""); 
    vr = vr.replace("-", ""); 
    vr = vr.replace("-", ""); 
    vr = vr.replace("-", ""); 
    vr = vr.replace("-", ""); 
    vr = vr.replace("-", ""); 
    tam = vr.length; 

    if (tam < TamanhoMaximo && tecla != 8) { 
      tam = vr.length + 1; 
    } 

    if (tecla == 8) { 
        tam = tam - 1; 
    } 

    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) { 
        if (tam <= 2) { 
            strCampo.value = vr; 
        }

        if ((tam > 2) && (tam <= 6)) { 
            strCampo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam); 
        }
        
        if ((tam >= 7) && (tam <= 9)) { 
            strCampo.value = vr.substr(0, tam - 6) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
        }
        
        if ((tam >= 10) && (tam <= 12)) { 
            strCampo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
        }
        
        if ((tam >= 13) && (tam <= 14)) { 
            strCampo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
        }
        
        if ((tam >= 15) && (tam <= 17)) { 
            strCampo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam); 
        }
    }
} 
  
  function ContaChar(textbox,limite)
  { 
	if(textbox.value.length >= limite)
	{ 
		alert("O limite foi ultrapassado!");
		textbox.value = textbox.value.substr(0, limite+1);
	} 
  } 
  
   function Enum(textbox)
  {
	var valor = textbox.value;
			
	if(valor ==  "")
	{
		valor = "0";
	}
	else
	{
		if(isNaN(textbox.value))
		{	
			alert("Valor incorreto!");
			textbox.value = "0";
			valor = "0";
			textbox.focus();
		}
	}
	return valor;
 }
  
  function EnumMoeda(textbox)
  {
	var valor = textbox.value;
	var aux = new String(valor);
	var aux1;
	var x;
	var ok = false

	if((x = aux.indexOf(".")) != -1)
	{
		aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
		aux = aux1;
		ok = true;
	}
	
	if((x = aux.indexOf(".")) != -1)
	{
		aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
		aux = aux1;
		ok = true;
	}
	
	if((x = aux.indexOf(",")) != -1)
	{
		aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
		aux = aux1;
		ok = true;
	}
		
	valor = aux;
	
	if(valor ==  "")
	{
		valor = "0";
	}
	else
	{
		if(isNaN(valor))
		{	
			alert("Valor incorreto!");
			textbox.value = "";
			textbox.value = "0,00";
			valor = "0";
			textbox.focus();
		}
		else
		{
			if(!ok)	
			{
				valor = aux.concat("00");
			}
		}
	}
	return valor;
 }

  function EnumMoedaSemDecimal(textbox) {
	var valor = textbox.value;
	var aux = new String(valor);
	var aux1;
	var x;
	var ok = false

	if((x = aux.indexOf(".")) != -1) {
		aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
		aux = aux1;
		ok = true;
	}
	
	if((x = aux.indexOf(".")) != -1) {
		aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
		aux = aux1;
		ok = true;
	}
	
	valor = aux;
	
	if(valor ==  "") {
		valor = "0";
	} else {
		if(isNaN(valor)) {	
			alert("Valor incorreto!");
			textbox.value = "";
			textbox.value = "0,00";
			valor = "0";
			textbox.focus();
		} else {
			if(!ok) {
				valor = aux.concat("00");
			}
		}
	}
	
	return valor;
 }

function Ezero(textbox)
  {
	var valor = textbox.value;
		
	if(valor ==  "0")
	{
		valor = "";
	}
	return valor;
  }

function DesabilitaTextForm17(a,txt)
		{
			if(a.checked == true)
			{
				txt.disabled = false;
			}
			else
			{
				txt.disabled = true;
			}
			
		}  
  
function insereLinhaOrcamento()
{
	var cont = parseInt(document.form1.hddCont.value);
	var linhas = window.tbl.rows.length -1;
	window.tbl.insertRow(linhas);
	var tr = window.tbl.rows(linhas);
	tr.bgColor = "#FFFFFF";
	tr.insertCell(0);
	tr.insertCell(1);
	tr.insertCell(2);
	tr.insertCell(3);
	
	var td = tr.cells[0];
	td.width="253";
	td.className = "style2";
	td.innerHTML = "<strong><input name='txtResp13a"+ cont +"qual' id='txtResp13a"+ cont +"qual' maxlength='40' type='text' size='17'></strong>";	
	
	td = tr.cells[1];
	td.className = "style2";
	td.innerHTML = "&nbsp;<input type='text' maxlength='10' size='8' name='txtResp13a"+ cont +"1' id='txtResp13a"+ cont +"1' onchange='javascript:somaTabOrcamento();'>";	
	
	td = tr.cells[2];
	td.className = "style2";
	td.innerHTML = "&nbsp;<input type='text' maxlength='10' size='5' name='txtResp13a"+ cont +"2' id='txtResp13a"+ cont +"2' onchange='javascript:Enum(this);'>";	
	
	td = tr.cells[3];
	td.className = "style2";
	td.innerHTML = "&nbsp;<input type='text' maxlength='50' size='25' name='txtResp13a"+ cont +"3' id='txtResp13a"+ cont +"3'>";	
	
	cont++;
	document.form1.hddCont.value = cont;
}

function somaTabOrcamento()
{
	var cont = parseInt(document.form1.hddCont.value);
	var x; 
	var y;
	var aux;
		
	for(var i=1; i<cont; i++)
	{
		x = EnumMoeda(eval("document.form1.txtResp13a"+ i +"1"));
		//alert("x:"+x);
		y = parseInt(EnumMoeda(document.form1.txtResp13aTotal)) + parseInt(x);
		//alert("total:"+y);
		aux  = new String(y);
		aux = aux.substr(0, aux.length-2).concat(",").concat(aux.substr(aux.length-2, 2));
		document.form1.txtResp13aTotal.value = aux;
		
		if(aux.substr(0, aux.indexOf(",")).length == 4)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 1).concat(".").concat(aux.substr(1, aux.length));
		} 
		if(aux.substr(0, aux.indexOf(",")).length == 5)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 2).concat(".").concat(aux.substr(2, aux.length));
		} 
		if(aux.substr(0, aux.indexOf(",")).length == 6)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 3).concat(".").concat(aux.substr(3, aux.length));
		} 
		if(aux.substr(0, aux.indexOf(",")).length == 7)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 4).concat(".").concat(aux.substr(4, aux.length));
		} 
		if(aux.substr(0, aux.indexOf(",")).length == 8)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 5).concat(".").concat(aux.substr(5, aux.length));
		} 
		if(aux.substr(0, aux.indexOf(",")).length == 9)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 6).concat(".").concat(aux.substr(6, aux.length));
		} 
		if(aux.substr(0, aux.indexOf(",")).length == 10)
		{
			document.form1.txtResp13aTotal.value = aux.substr(0, 7).concat(".").concat(aux.substr(7, aux.length));
		} 
	}
}

function formataNumero(fld, tamanho, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if (whichCode == 13) {
		return true;
	}

	key = String.fromCharCode(whichCode);  // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) {
		return false;  // Chave inválida
	}
	
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if (fld.value.charAt(i) != '0') {
			break;
		}
	}

	aux = '';
	for(; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) {
			aux += fld.value.charAt(i);
		}
	}

	aux += key;
	len = aux.length;
	if (len == 0) {
		fld.value = '';
	} else if (len < tamanho) {
		fld.value = aux.substring(0, len);
	} else {
		fld.value = aux.substring(0, tamanho);
	}

	return false;
}

function formataReais(fld, milSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if (whichCode == 13) {
		return true;
	}

	key = String.fromCharCode(whichCode);  // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) {
		return false;  // Chave inválida
	}
	
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if (fld.value.charAt(i) != '0') {
			break;
		}
	}

	aux = '';
	for(; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) {
			aux += fld.value.charAt(i);
		}
	}

	aux += key;
	len = aux.length;
	if (len == 0) {
		fld.value = '';
	}
	if (len <= 3) {
		fld.value = aux;
	}
	if (len > 3) {
		aux2 = '';
		j = 0;
		for (i = len - 1; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		
		fld.value = '';
		len2 = aux2.length;
		for (i = len2; i >= 0; i--) {
			fld.value += aux2.charAt(i);
		}
	}

	return false;
}

function formataReais(fld, milSep, tamanho, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if (whichCode == 13) {
		return true;
	}

	key = String.fromCharCode(whichCode);  // Valor para o código da Chave
	if (strCheck.indexOf(key) == -1) {
		return false;  // Chave inválida
	}
	
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if (fld.value.charAt(i) != '0') {
			break;
		}
	}

	aux = '';
	for(i = 0; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) {
			aux += fld.value.charAt(i);
		}
	}

	aux += key;
	len = aux.length;
	
	if (len > tamanho) {
		aux = aux.substring(0, tamanho);
	} else {
		aux = aux.substring(0, len);
	}
	len = aux.length;
	
	if (len == 0) {
		fld.value = '';
	}
	if (len <= 3) {
		fld.value = aux;
	}
	if (len > 3) {
		aux2 = '';
		j = 0;
		for (i = len - 1; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		
		fld.value = '';
		len2 = aux2.length;
		aux3 = '';
		for (i = len2; i >= 0; i--) {
			fld.value += aux2.charAt(i);
			aux3 += aux2.charAt(i);
		}
		
	}

	return false;
}

function desformataMoeda(textbox) {
	var valor = textbox.value;
	var aux = new String(valor);
	var aux1;
	var x;
	
	if (valor == "") {
		retorno = 0;
	} else {
		while ((x = aux.indexOf(".")) != -1) {
			aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
			aux = aux1;
		}
		
		if ((x = aux.indexOf(",")) != -1) {
			aux1 = aux.substr(0, x).concat(aux.substr(x+1, aux.length));
			aux = aux1;
		}

		retorno = aux;
	}
	
	return retorno;
 }
 
 function formataMoeda(total){
 	aux  = new String(total);
	len = aux.length;
	if (len == 0) {
		aux3 = '';
	}
	if (len <= 3) {
		aux3 = aux;
	}
	if (len > 3) {
		aux2 = '';
		j = 0;
		for (i = len - 1; i >= 0; i--) {
			if (j == 3) {
				aux2 += '.';
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		
		aux3 = '';
		len2 = aux2.length;
		for (i = len2; i >= 0; i--) {
			aux3 += aux2.charAt(i);
		}
	}
	
	return aux3;
}

function count(fld,long) {
	var maxlength = new Number(long); // Change number to your max length.
	if (fld.value.length > maxlength){
		fld.value = fld.value.substring(0,maxlength);
		alert("Apenas " + long + " caracteres permitidos!");
	}
}

function insereLinhaEquipeProjeto()
{
	//var cont = parseInt(document.form1.hddCont.value);
	var linhas = window.tbEquipe.rows.length;
	alert(linhas);
	window.tbEquipe.insertRow(linhas);
	var tr = window.tbEquipe.rows(linhas);
	tr.bgColor = "#FFFFFF";
	tr.insertCell(0);
	tr.insertCell(1);
	tr.insertCell(2);
	tr.insertCell(3);
	tr.insertCell(4);
	tr.insertCell(5);
	tr.insertCell(6);
	tr.insertCell(7);
	tr.insertCell(8);

	var td = tr.cells[0];
//	td.height="200";
	td.className = "txt_form";
	td.innerHTML = "<INPUT type='text'>";

	td = tr.cells[1];
	td.className = "txt_form";
	td.innerHTML = "coluna1";

	td = tr.cells[2];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "coluna2";

	td = tr.cells[3];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "coluna3";

	td = tr.cells[4];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "coluna4";

	td = tr.cells[5];
	td.className = "txt_form";
	td.innerHTML = "coluna5";

	td = tr.cells[6];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "coluna6";

	td = tr.cells[7];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "coluna7";

	td = tr.cells[8];
	td.className = "txt_form";
	td.innerHTML = "coluna8";
	
/*
	var td = tr.cells[0];
	td.height="200";
	td.className = "txt_form";
	td.innerHTML = "<asp:textbox id='txtNome_2' runat='server' cssclass='box'></asp:textbox>";

	td = tr.cells[1];
	td.className = "txt_form";
	td.innerHTML = "<asp:textbox id='txtAtividade_2' runat='server' cssclass='box'></asp:textbox>";

	td = tr.cells[2];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "<asp:radiobutton id='radEsc_fundamental_1' runat='server'>";

	td = tr.cells[3];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "<asp:radiobutton id='radEsc_medio_1' runat='server'></asp:radiobutton>";

	td = tr.cells[4];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "<asp:radiobutton id='radEsc_superior_1' runat='server'></asp:radiobutton>";

	td = tr.cells[5];
	td.className = "txt_form";
	td.innerHTML = "<asp:textbox id='txtFormacao_1' runat='server' cssclass='box'></asp:textbox>";

	td = tr.cells[6];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "<asp:radiobutton id='radTrab_remunerado_1' runat='server'></asp:radiobutton>";

	td = tr.cells[7];
	td.className = "txt_form";
	td.align = "center";
	td.innerHTML = "<asp:radiobutton id='radTrab_voluntario_1' runat='server'></asp:radiobutton>";

	td = tr.cells[8];
	td.className = "txt_form";
	td.innerHTML = "<asp:textbox id='txtCarga_1' runat='server' cssclass='box'></asp:textbox>";
*/
/*
	var cont = parseInt(document.form1.hddCont.value);
	var linhas = window.tbl.rows.length -1;
	window.tbl.insertRow(linhas);
	var tr = window.tbl.rows(linhas);
	tr.bgColor = "#FFFFFF";
	tr.insertCell(0);
	tr.insertCell(1);
	tr.insertCell(2);
	tr.insertCell(3);
	
	var td = tr.cells[0];
	td.width="253";
	td.className = "style2";
	td.innerHTML = "<strong><input name='txtResp13a"+ cont +"qual' id='txtResp13a"+ cont +"qual' maxlength='40' type='text' size='17'></strong>";	
	
	td = tr.cells[1];
	td.className = "style2";
	td.innerHTML = "&nbsp;<input type='text' maxlength='10' size='8' name='txtResp13a"+ cont +"1' id='txtResp13a"+ cont +"1' onchange='javascript:somaTabOrcamento();'>";	
	
	td = tr.cells[2];
	td.className = "style2";
	td.innerHTML = "&nbsp;<input type='text' maxlength='10' size='5' name='txtResp13a"+ cont +"2' id='txtResp13a"+ cont +"2' onchange='javascript:Enum(this);'>";	
	
	td = tr.cells[3];
	td.className = "style2";
	td.innerHTML = "&nbsp;<input type='text' maxlength='50' size='25' name='txtResp13a"+ cont +"3' id='txtResp13a"+ cont +"3'>";	
	
	cont++;
	document.form1.hddCont.value = cont;
*/
}

function mascaraCep(objeto){
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5) { 
		objeto.value = ""; 
	}
	
	if (objeto.value.length == 5) {
		objeto.value += "-";
	}
}


function abreTelaAviso(url)
{
	window.open('https://ww46.itau.com.br/itau/alerta/aviso.jsp?lk='+ url,'saida','width=700,height=412');
}

function isCNPJValido(cnpj)
{
  var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
  digitos_iguais = 1;
  if (cnpj.length < 14 && cnpj.length < 15)
        return false;
  for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1))
              {
              digitos_iguais = 0;
              break;
              }
  if (!digitos_iguais)
        {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0,tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
              {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                    pos = 9;
              }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
              return false;
        tamanho = tamanho + 1;
        numeros = cnpj.substring(0,tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
              {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                    pos = 9;
              }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1))
              return false;
        return true;
        }
  else
        return false;
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
