function alterarBorda(campo, valor){
	campo.style.color = valor;
}

var BORDA_INPUT = "#FFFFFF";
var BORDA_ERRO = "#a02628";

function validarDia(valor) {
	if(valor >= 1 && valor <= 31)
		return true;
	return false;
}

function validarMes(valor) {
	if(valor >= 1 && valor <= 12)
		return true;
	return false;
}

function mascarar(campo, mascara, e){
	var posicao = campo.value.length;
	var usarMascara = true;
	var code = recuperaCode(e);
	if(code == 8 || code == 9 || code == 46 || (code >= 33 && code <= 46))
		usarMascara = false;
	if(usarMascara){
		if(mascara.substring(posicao, posicao + 1) != "#"){
			campo.value += mascara.substring(posicao, posicao + 1);
		}
	}
}

function colocarZero(campo) {
	if(campo.value.indexOf(",") == -1) {
		campo.value += ",00";
	}else{
		var aux = campo.value.split(",");
		if(aux[1].length >= 2)
			campo.value = aux[0] + "," + aux[1].substring(0, 2);
		else
			campo.value = aux[0] + "," + aux[1] + "0";
	}
}

function somenteNumero(e){
	var code = recuperaCode(e);
	if(code == 8 || code == 9 || code == 46 || (code >= 33 && code <= 46) || (code >= 48 && code <= 57) || (code >= 96 && code <= 105))
		return true;
	else
		return false;
}

function monetario(e){
	var code = recuperaCode(e);
	if(code == 8 || code == 9 || code == 46 || (code >= 33 && code <= 46) || (code >= 48 && code <= 57) || (code >= 96 && code <= 105) || code == 188)
		return true;
	else
		return false;
}

function recuperaCode(e){
	if (e.keyCode) return e.keyCode;
	else if (e.which) return e.which; // Netscape 4.?
	else if (e.charCode) return e.charCode; // Mozilla
}

function ValidarCPF(Objcpf) {
	var cpf = Objcpf.value;
	exp = /\.|\-/g
	cpf = cpf.toString().replace(exp, "");
	var digitoDigitado = eval(cpf.charAt(9) + cpf.charAt(10));
	var soma1 = 0, soma2 = 0;
	var vlr = 11;

	for (i = 0; i < 9; i++) {
		soma1 += eval(cpf.charAt(i) * (vlr - 1));
		soma2 += eval(cpf.charAt(i) * vlr);
		vlr--;
	}
	soma1 = (((soma1 * 10) % 11) == 10 ? 0 : ((soma1 * 10) % 11));
	soma2 = (((soma2 + (2 * soma1)) * 10) % 11);

	var digitoGerado = (soma1 * 10) + soma2;
	if (digitoGerado != digitoDigitado) {
		return true;
	}
	return false;
}

function abrir (ID) {
		document.getElementById(ID).style.display = "block";
	}
	
	function fechar (ID) {
		document.getElementById(ID).style.display = "none";
	}	

function getBrowserVersion()   {
	if(navigator.appVersion.indexOf("MSIE 7") != -1){
		if(document.getElementById("blog") != null)
			document.getElementById("blog").style.margin = "0 0 0 65px";
		if(document.getElementById("titulo-presenca-nacional") != null)
			document.getElementById("titulo-presenca-nacional").style.margin = "21px 30px 30px 20px";
	}else if(navigator.appVersion.indexOf("MSIE 6") != -1){
		if(document.getElementById("blog") != null)
			document.getElementById("blog").style.margin = "0 0 0 40px";
		if(document.getElementById("titulo-presenca-nacional") != null)
			document.getElementById("titulo-presenca-nacional").style.margin = "21px 25px 30px 20px";
	}else{
		if(document.getElementById("blog") != null)
			document.getElementById("blog").style.margin = "0 0 0 65px";
		if(document.getElementById("titulo-presenca-nacional") != null)
			document.getElementById("titulo-presenca-nacional").style.margin = "21px 30px 30px 20px";
	}
}

function marcarCheck(target) {
	target.checked = true;
}

// JavaScript para exibir o flash
function swfobject_comFundo(largura, altura, arquivo){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle" valign="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" /><param name="allowScale" value="noScale" />');
	document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="'+arquivo+'" wmode="transparent" quality="best" width="'+largura+'" height="'+altura+'" name="teste" align="middle" allowScale="noScale" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
function swfobject_semFundo(largura, altura, arquivo){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle" valign="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="allowScale" value="noScale" />');
	document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="'+arquivo+'" quality="best" width="'+largura+'" height="'+altura+'" name="teste" align="middle" allowScale="noScale" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
/*
	CRIR - Checkbox & Radio Input Replacement
	Author: Chris Erwin (me[at]chriserwin.com)
	www.chriserwin.com/scripts/crir/

	Updated July 27, 2006.
	Jesse Gavin added the AddEvent function to initialize
	the script. He also converted the script to JSON format.
	
	Updated July 30, 2006.
	Added the ability to tab to elements and use the spacebar
	to check the input element. This bit of functionality was
	based on a tip from Adam Burmister.
*/

crir = {
	init: function() {
		arrLabels = document.getElementsByTagName('label');
	
		searchLabels:
		for (var i=0; i<arrLabels.length; i++) {			
			// get the input element based on the for attribute of the label tag
			if (arrLabels[i].getAttributeNode('for') && arrLabels[i].getAttributeNode('for').value != '') {
				labelElementFor = arrLabels[i].getAttributeNode('for').value;				
				inputElement = document.getElementById(labelElementFor);
			}
			else {				
				continue searchLabels;
			}	
							
			inputElementClass = inputElement.className;	
		
			// if the input is specified to be hidden intiate it
			if (inputElementClass == 'crirHiddenJS') {
				inputElement.className = 'crirHidden';
				
				inputElementType = inputElement.getAttributeNode('type').value;	
				
				// add the appropriate event listener to the input element
				if (inputElementType == "checkbox") {
					inputElement.onclick = crir.toggleCheckboxLabel;
				}
				else {
					inputElement.onclick = crir.toggleRadioLabel;
				}
				
				// set the initial label state
				if (inputElement.checked) {
					if (inputElementType == 'checkbox') { arrLabels[i].className = 'checkbox_checked'}
					else { arrLabels[i].className = 'radio_checked' }
				}
				else {
					if (inputElementType == 'checkbox') { arrLabels[i].className = 'checkbox_unchecked'}
					else { arrLabels[i].className = 'radio_unchecked' }
				}
			}
			else if (inputElement.nodeName != 'SELECT' && inputElement.getAttributeNode('type').value == 'radio') { // this so even if a radio is not hidden but belongs to a group of hidden radios it will still work.
				arrLabels[i].onclick = crir.toggleRadioLabel;
				inputElement.onclick = crir.toggleRadioLabel;
			}
		}			
	},	
	
	findLabel: function (inputElementID) {
		arrLabels = document.getElementsByTagName('label');
	
		searchLoop:
		for (var i=0; i<arrLabels.length; i++) {
			if (arrLabels[i].getAttributeNode('for') && arrLabels[i].getAttributeNode('for').value == inputElementID) {				
				return arrLabels[i];
				break searchLoop;				
			}
		}		
	},	
	
	toggleCheckboxLabel: function () {
		labelElement = crir.findLabel(this.getAttributeNode('id').value);
	
		if(labelElement.className == 'checkbox_checked') {
			labelElement.className = "checkbox_unchecked";
		}
		else {
			labelElement.className = "checkbox_checked";
		}
	},	
	
	toggleRadioLabel: function () {			 
		clickedLabelElement = crir.findLabel(this.getAttributeNode('id').value);
		
		clickedInputElement = this;
		clickedInputElementName = clickedInputElement.getAttributeNode('name').value;
		
		arrInputs = document.getElementsByTagName('input');
	
		// uncheck (label class) all radios in the same group
		for (var i=0; i<arrInputs.length; i++) {			
			inputElementType = arrInputs[i].getAttributeNode('type').value;
			if (inputElementType == 'radio') {
				inputElementName = arrInputs[i].getAttributeNode('name').value;
				inputElementClass = arrInputs[i].className;
				// find radio buttons with the same 'name' as the one we've changed and have a class of chkHidden
				// and then set them to unchecked
				if (inputElementName == clickedInputElementName && inputElementClass == 'crirHidden') {				
					inputElementID = arrInputs[i].getAttributeNode('id').value;
					labelElement = crir.findLabel(inputElementID);
					labelElement.className = 'radio_unchecked';
				}
			}
		}
	
		// if the radio clicked is hidden set the label to checked
		if (clickedInputElement.className == 'crirHidden') {
			clickedLabelElement.className = 'radio_checked';
		}
	},
	
	addEvent: function(element, eventType, doFunction, useCapture){
		if (element.addEventListener) 
		{
			element.addEventListener(eventType, doFunction, useCapture);
			return true;
		} else if (element.attachEvent) {
			var r = element.attachEvent('on' + eventType, doFunction);
			return r;
		} else {
			element['on' + eventType] = doFunction;
		}
	}
}

crir.addEvent(window, 'load', crir.init, false);

function alterarSelect(target, valor) {
	for(var i = 0; i < target.length; i++) {
		if(target[i].value == valor){
			target[i].selected = true;
			break;
		}
	}
}

function proximoCampo(campo, quantCaracteres, target){
	if(campo.value.length == quantCaracteres)
		target.focus();
}

String.prototype.endsWith = function(str) {
	return (this.match(str+"$")==str)
}