// JavaScript Document
// JavaScript Document

var dados = "";
//Construi Post

function alteraAviso(id){
	http.open('GET','alterAviso.php',true);
	http.onreadystatechange=makeAvisos;
	http.send(null);
}

function makeAvisos(){
	if(http.readyState==4){
		var tmp = hhtp.responseText.split('|');	
	}	
}

function makePost(){
	var frm = document.form1;
	var tam = (frm.elements.length-1);
	var str = new Array(tam);
	for(i=0;i<tam;i++){
		str[i] = frm.elements[i].name + "=" + encodeURIComponent(frm.elements[i].value);
	}
	dados = str.join("&");
}

//Funções selecionadoras
function SelCurso(id,par){
	setSession('curso',id,par);
}

function verSess(){
	http.open('GET','verSe.php',true);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			alert(http.responseText);
		}
	}
	http.send(null);
}

function SelModulos(id,par){
	setSession('modulo',id,par);
}

//Apagar
function apagaCursos(){
	setApagar('tbcurso','curso','cursos.php');
}

function exc(pag){
	if(confirm("Deseja realmente excluir?")){
		var nots = 'note='+ document.getElementById('sec').value;
		http.open("POST",pag,true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		http.onreadystatechange = troca;
		http.send(nots);
	}
}


//Seta Sessões
function setSession(sess,idf,par){
	var cores = new Array("#fff","#C3DCE3");
	var tmp = idf.split('|');
	var idd = tmp[1];
	var cor=cores[par];
	var lcor="#000";
	http.open('GET','setSessao.php?sessao='+sess+'&id='+idd,true);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			if(http.responseText=='n'){
				cor = "#336666";
				lcor = "#fff";	
			}
			
			document.getElementById(idf).style.background = cor;
			document.getElementById(idf).style.color = lcor;
		}
	}
	http.send(null);
}

//seta Apagar
function setApagar(tabela,sessao,volta){
	http.open('GET','exclui.php?tabela='+tabela+'&sessao='+sessao+'&chamada='+volta,true);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			document.getElementById('meio').innerHTML=http.responseText;
		}
	}
	http.send(null);
}

//Inserções
//o nome do formulario tem q ser form1 para o makePost()
function ins(pag){
	makePost();
	http.open('POST',pag,true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}

function mudaTurma(idaluno,idta,idcurso,iditem){
	var turma = document.getElementById("turma"+idcurso).value;
	var dados = "idaluno="+idaluno+"&idturma="+turma+"&idta="+idta+"&iditens="+iditem;
	http.open("POST","alunosAT.php",true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = function(){
		if(http.readyState==4){
			alert(http.responseText);
		}
	}
	http.send(dados);
}

function InsertNot(){
	makePost();
	http.open("POST","notc.php",true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}


function InsertProf(){
	makePost();
	http.open("POST","professorC.php",true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
	
}

function InsertDesc(){
	makePost();
	http.open("POST","incDesconto.php",true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
	
}

//Chama Formulário!!!
function formProf(){
	http.open("GET","docentesC.php",true);
	http.onreadystatechange = troca;
	http.send(null);
}

function getPagsMeio(pag){
	http.open("GET",pag, true);
	http.onreadystatechange = troca;
	http.send(null);
}


//Updates

function trocaImg(idd,tb){
	var situa=document.getElementById('situa'+idd).value;
	http.open("GET","trocaSinal.php?situacao="+situa+"&id="+idd+"&tb="+tb, true);
	http.onreadystatechange = function(){
		if(http.readyState==4){
			var img = new Array("redSinal.png","greenSinal.png");
			var s = new Array("1","0");
			document.getElementById('sinal'+idd).src = "images/"+img[situa];
			document.getElementById('situa'+idd).value = s[situa];
		}	
	}
	http.send(null);
}


function pagoPedido(idd){
	http.open('GET','pagopedido.php?id='+idd,true); 
	http.onreadystatechange= function(){
		if(http.readyState==4){
			var vet= http.responseText.split(";"); 
			var ids = vet[1].split("|"); 
			for(i=0;i<ids.length;i++){
				document.getElementById('sinal'+ids[i]).src=vet[0];
				document.getElementById('situa'+ids[i]).value=vet[0];				
			}
		}
	}
	http.send(null);
}


function upsNot(){
	makePost();
	http.open('POST','upsNot.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}


function upsProf(){
	makePost();
	http.open('POST','upsProf.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}

function upsMod(){
	makePost();
	http.open('POST','UpsMod.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}

function upsDesc(){
	makePost();
	http.open('POST','upsDesconto.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}

function edNOt(ids){
	http.open('GET','Ednoticias.php?id='+ids,true);
	http.onreadystatechange=troca;
	http.send(null); 
	
}

function edProf(ids){
	window.location="docentesA.php?id="+ids;
}

function edMod(id){
	http.open('GET','altMod.php?id='+id,true);
	http.onreadystatechange=troca;
	http.send(null);
}

function edDesc(id){
	http.open('GET','descE.php?idd='+id,true);
	http.onreadystatechange=troca;
	http.send(null);
}

function edAula(){
	makePost();
	http.open('POST','edAula.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange=subtroca;
	http.send(dados);
}

function edCurso(idc){
	http.open('GET','edCurso.php?id='+idc,true);
	http.onreadystatechange=troca;
	http.send(null);
}

function edSite(idc){
	makePost();
	http.open('POST','edSite.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange=subtroca;
	http.send(dados);
}

function altAula(id){
	http.open('GET','editAula.php?aula='+id,true);
	http.onreadystatechange=subtroca;
	http.send(null);
}

function altSite(id){
	http.open('GET','editSite.php?aula='+id,true);
	http.onreadystatechange=subtroca;
	http.send(null);
}


//exclusão

function excluir(tb,pag){
	if(confirm("Deseja realmente excluir?")){
		var ids = 'ids='+document.getElementById('sec2').value+"&tb="+tb+"&pag="+pag;
		http.open("POST","exclui.php",true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		http.onreadystatechange=troca;
		http.send(ids);
	}
}

function excNot(){
	if(confirm("Deseja realmente excluir?")){
		var nots = 'note='+ document.getElementById('sec').value;
		http.open("POST","Enoticias.php",true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		http.onreadystatechange = troca;
		http.send(nots);
	}
}

function excDesc(){
	if(confirm("Deseja realmente excluir?")){
		var nots = 'desc='+ document.getElementById('sec').value;
		http.open("POST","Edesconto.php",true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		http.onreadystatechange = troca;
		http.send(nots);
	}
}

function excProf(){
	if(confirm("Deseja realmente excluir?")){
		var nots = 'prof='+ document.getElementById('sec').value;
		http.open("GET","docentesD.php",true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		http.onreadystatechange = troca;
		http.send(nots);
	}
}

function excCurso(){
	if(confirm("Deseja realmente excluir?")){
		var nots = 'curso='+ document.getElementById('sec').value;
		http.open("POST","ecurso.php",true);
		http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		http.onreadystatechange = troca;
		http.send(nots);
	}
}

function excMod(){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET","emodulo.php?mod="+document.getElementById('sec2').value,true);
		http.onreadystatechange = troca;
		http.send(null);
	}
}

function excPCurso(){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET","excPCurso.php?cprof="+document.getElementById('sec2').value,true);
		http.onreadystatechange = troca;
		http.send(null);
	}
}

function excAula(idd){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET","excAula.php?idaula="+document.getElementById('sec').value+"&id="+idd,true);
		http.onreadystatechange = subtroca;
		http.send(null);
	
	}
}

function excImage(idd){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET","excImage.php?idaula="+document.getElementById('sec').value+"&id="+idd,true);
		http.onreadystatechange = subtroca;
		http.send(null);
	}
}

function excImg(){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET","excImg.php",true);
		http.onreadystatechange = imgtroca;
		http.send(null);
	}
}

function excSite(idd){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET","excSite.php?idaula="+document.getElementById('sec').value+"&id="+idd,true);
		http.onreadystatechange = subtroca;
		http.send(null);
	}
}

function excIncMat(pag,idd){
	if(confirm("Deseja realmente excluir?")){
		http.open("GET",pag+"?idaula="+document.getElementById('sec').value+"&id="+idd,true);
		http.onreadystatechange = subtroca;
		http.send(null);
	}
}


function addMod(nameText,id){
	var nomeModulo = document.getElementById(nameText).value;
	var cab = 'nome='+nomeModulo+'&id='+id;
	http.open("POST","incModulo.php",true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(cab);
	
}


function Islogar(){
	makePost();
	http.open("POST","log.php",true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange = troca;
	http.send(dados);
}
//links do menu
function getPags(pag){
	http.open("GET",pag, true);
	http.onreadystatechange = troca;
	http.send(null);
}

function getCnoticias(){
	http.open("GET","Cnoticias.php", true);
	http.onreadystatechange = troca;
	http.send(null);
}

function getIncMat(idmod){
	http.open("GET","incMaterial.php?idm="+idmod,true);
	http.onreadystatechange = troca;
	http.send(null);
}

function getMat(valor,idm){
	http.open("GET",valor+".php?idm="+idm,true);
	http.onreadystatechange = subtroca;
	http.send(null);
}

//monta combos
function getCombo(cmp,pag){
	var cmb = document.getElementById(cmp);
	http.open("GET",pag,true);
	http.onreadystatechange = function(){
		if(http.readyState==4){
			cmb.options.length=1;
			cmb.options[0]=new Option("Nenhum","-1");
			var resp = http.responseText.split(",");
			var tam = resp.length-1;
			for(i=0;i<tam;i++){
				var opt = resp[i].split("|");
				cmb.options[i]=new Option(opt[1],opt[0]);
			}
		}
	}
	http.send(null);
}
//fim combos

function insCurso(){
	http.open('GET','cursosC.php',true);
	http.onreadystatechange=troca;
	http.send(null); 
}

function insCurPro(idd){
	var curso = document.getElementById('curso'+idd).value;
	var turno = document.getElementById('turno'+idd).value;
	var serie = document.getElementById('serie'+idd).value;
	var disc = document.getElementById('disciplina'+idd).value;
	if((curso!=0)&&(turno!='')&&(serie!=0)&&(disc!=0)){
		window.location='cursProf.php?idprof='+idd+'&curso='+curso+'&turno='+turno+'&serie='+serie+'&disc='+disc
	}else{
		alert("Você deve selecionar o Curso,Turno,Série e Disciplina");
	}

}

function incMat(pag){
	http.open('GET',pag,true);
	http.onreadystatechange=subtroca;
	http.send(null);
}

function incDesconto(){
	http.open('GET','descC.php',true);
	http.onreadystatechange=troca;
	http.send(null);
}

function incApostila(idm){
	http.open('GET',''+idm,true);
	http.onreadystatechange=subtroca;
	http.send(null);
}


function incImage(idm){
	http.open('GET','incImage.php?idm='+idm,true);
	http.onreadystatechange=subtroca;
	http.send(null);
}

function incSite(idm){
	http.open('GET','incSite.php?idm='+idm,true);
	http.onreadystatechange=subtroca;
	http.send(null);
}

//Inclusao
function incluiMat(pag){
	makePost();
	http.open('POST',pag,true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange=subtroca; 
	http.send(dados);
}


function incluiAula(){
	makePost();
	http.open('POST','incluiAula.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange=subtroca; 
	http.send(dados);
}

function incluiApostila(){
	makePost();
	http.open('POST','incluiApostila.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange=subtroca; 
	http.send(dados);
}


function incluiSite(){
	makePost();
	http.open('POST','incluiSite.php',true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
	http.onreadystatechange=subtroca; 
	http.send(dados);
}


function getMatIndex(idmod,pg){
	http.open("GET","incMaterial.php?idm="+idmod+"&pg="+pg,true);
	http.onreadystatechange = troca;
	//getMat("matImage",idmod);
	http.send(null);
}


function troca(){
	if(http.readyState==4){
		document.getElementById('meio').innerHTML = http.responseText;
	}
}

function subtroca(){
	if(http.readyState==4){
		document.getElementById('detMat').innerHTML = http.responseText;
	}
}

function imgtroca(){
	if(http.readyState==4){
		document.getElementById('trocaImg').innerHTML = http.responseText;
	}
}



function getAjax(){
	ajax = null;
	try{
		ajax = new XMLHttpRequest();
		}catch(e){
			try{
				ajax = new ActiveXObject("Microsoft.XMLHttp");
			}catch(e){
				try{
					ajax = new ActiveXObject("MSXML2.XMLHttp");
				}catch(e){
					alert("Seu navegador não suporta Ajax");
				}
			}
	    }
	return ajax;
}

var http = getAjax();

