function select_innerHTML(objeto, innerHTML)
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{ 
		objeto.innerHTML = '';
		var temp = objeto.outerHTML.replace('></', '>' + innerHTML + '</');
		objeto.outerHTML = temp;
	} else
	{
		objeto.setHTML(innerHTML);
	}
}

function switchDisplayBlock(mainValue, values)
{
	for (i in values)
	{
		try
		{
			$(values[i]).style.display = 'none';
		} catch (e) { }
	}
	try
	{
		$(values[mainValue]).style.display = 'block';
	} catch (e) { }
}

function emptyField(campo)
{
	
	var spanName = campo + '_message';
	
	$(spanName).empty();
	
	if($(campo).value == "")
	{
		$(spanName).appendText("Campo n�o preenchido!");
		erros += "erros";
		
	}
	
}

function radioCheck(obj)
{
	var elements = document.getElementsByName(obj.name);

        for(i in elements)
		if (elements[i])
			if (elements[i].checked)
				elements[i].checked = 'false';
	
	obj.checked = 'true';
}

function validaRadioCheck(campo)
{
    var campo_preenchido = false;
    for(i=0;i<campo.length;i++){
        if(campo[i].checked)
            campo_preenchido = true;
    }
    return campo_preenchido;
}

function swapProperties(objName, properties)
{
	for (i in properties)
	{
		var actualPropertyIndex = properties[i].indexOf(eval("$('" + objName + "')." + i));
		var property = properties[i][(actualPropertyIndex + 1) % properties[i].length];
		eval("$('" + objName + "')." + i + "='" + property + "'");
	}
}

function validate_email(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = email;
	if(reg.test(address) == false) {
		return false;
	} else {
		return true;
	}
}

function obrigaNumerico(e){
	var key = window.event ? e.keyCode : e.which;
	if(key >= 48 && key <= 57 ){
		return true;
	}else if(key != 0 && key != 13 && key != 8){
		return false;
	}else{
		return true;
	}
}

function formatoData(objThis){
    if(document.all) // Internet Explorer
        var tecla = event.keyCode;
    else if(document.layers) // Nestcape
        var tecla = e.which;
	if(tecla != 13 && tecla != 8 && tecla != 37 && tecla != 39){
		if(objThis.value.length == 2){
			objThis.value = objThis.value + "/";
		}else if(objThis.value.length == 5){
			objThis.value = objThis.value + "/";
		}
	}
}


function calculaIdade(dataNascimento){
	
	if(dataNascimento == ""){
		return false;
	}else{
		var d = new Date();
		
		anoAtual	= d.getFullYear();
		
		diaUsuario = dataNascimento.substr(0,2);
		mesUsuario = dataNascimento.substr(3,2);
		anoUsuario = dataNascimento.substr(6);
		
		if(diaUsuario < 1 || diaUsuario > 31){
			alert("Data inv�lida!");
			$("data_nascimento").focus();
			$("data_nascimento").value = "";
			return false;
		}
		if(mesUsuario < 1 || mesUsuario > 12){
			alert("Data inv�lida!");
			$("data_nascimento").focus();
			$("data_nascimento").value = "";
			return false;
		}
		if(anoUsuario < 1950 || anoUsuario > 1996){
			alert("Data inv�lida!");
			$("data_nascimento").focus();
			$("data_nascimento").value = "";
			return false;
		}
		
		idade = (anoAtual - anoUsuario);
		
		var conf = confirm("Voc� tem ou completar� esse ano "+idade+" anos de idade?");
		
		if(conf == true){
			return false;
		}else{
			document.getElementById("data_nascimento").focus();
			document.getElementById("data_nascimento").value = "";
		}

	}
	
}

function Trim(str){
       return str.replace(/^\s+|\s+$/g,"");
}

function validaCep(cep){
	if($('cep').value.length < 8){
		alert('O Cep deve ser composto de 8 n�meros');
		$('cep').value = "";
		$('cep').focus();
	}
}

function validaMatricula(matricula){
	if(matricula.length < 11){
		return false;
	}	
	else
		return true;
}