function cadastro(){
	xmlHttp = getXmlHttpObject();
	if(xmlHttp == null){
		alert("Seu browser n�o suporta AJAX!");
		return;
	}
	var oForm = document.forms[0];
	var sBody = criaReqStr(oForm);
		
	var url = "cad_agendamento.php";
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(sBody);
}

function cadastroCurso(){
	xmlHttp = getXmlHttpObject();
	if(xmlHttp == null){
		alert("Seu browser n�o suporta AJAX!");
		return;
	}
	var oForm = document.forms[0];
	var sBody = criaReqStr(oForm);
		
	var url = "cad_cursos.php";
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(sBody);
}

function getXmlHttpObject(){
	var xmlHttp = null;
	try{
		xmlHttp = new XMLHttpRequest();
	} catch(e){
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function stateChanged(){
	if(xmlHttp.readyState == 4){
		document.getElementById("retorno").innerHTML = xmlHttp.responseText;
	}
}

function criaReqStr(oForm){
    var aPostStr = new Array();

  	for(var i = 0; i < oForm.elements.length; i++){
        var sValor = encodeURIComponent(oForm.elements[i].name);
        sValor += "=";
		sValor += encodeURIComponent(oForm.elements[i].value);
		aPostStr.push(sValor);
	}
	return aPostStr.join("&");
}

function validaContato(){

	if(document.forms[0].nome.value == ""){
		document.forms[0].nome.focus();
		return false;
	} else if(document.forms[0].email.value == ""){
		document.forms[0].email.focus();
		return false;
	} else if(document.forms[0].ddd.value == ""){
		document.forms[0].ddd.focus();
		return false;
	} else if(document.forms[0].telefone.value == ""){
		document.forms[0].telefone.focus();
		return false;
	} else if(document.forms[0].mensagem.value == ""){
		document.forms[0].mensagem.focus();
		return false;
	}
}

function numeros(e){
   	if(window.event) {
        // para IE
    	key = e.keyCode;
    } else if(e.which) {
        //para Firefox
    	key = e.which;
    }
   	if (key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8) || (key==58));{
    	return true;
   	}
}

function mascaraData(campoData){
	var data = campoData.value;
    if (data.length == 2){
		data = data + '/';
    	document.forms[0].data.value = data;
      	return true;              
	}
	if (data.length == 5){
		data = data + '/';
		document.forms[0].data.value = data;
		return true;
	}
}

function $(obj){
	return document.getElementById(obj);		
}


// função formatar para uso/estudo futuro
/*function formatar(src, mask) {
	var i = src.value.length;
    var saida = mask.substring(i,i+1);
    var ascii = event.keyCode;
    if (saida == "A") {
    	if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
        	else { event.keyCode = 0; }
        } else if (saida == "0") {
            if ((ascii >= 48) && (ascii <= 57)) {
            	return
            } else { 
            	event.keyCode = 0 
            }
        } else if (saida == "#") {
            return;
        } else {
            src.value += saida;
        if (saida == "A") {
	        if ((ascii >=97) && (ascii <= 122)) { event.keyCode -= 32; }
        } else { return; }
	    }
}*/
