function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function carrega() {
	MM_preloadImages('images/box_depoimentos_over.jpg','images/box-cursos_over.jpg');	
}

function aparece(id) {
	if (document.getElementById(id).style.display == "none") {
		document.getElementById(id).style.display = "block";
	} else {
		document.getElementById(id).style.display = "none";
	}
}

function in_array (x, matriz){
	var txt = "¬" + matriz.join("¬") + "¬";
	var er = new RegExp ("¬" + x + "¬", "gim");
	return ( (txt.match (er)) ? true : false );
}

function validateForm(form) {
	
	var formulario = document.getElementById(form);
	var campos = ["nome","aluno","formacao","cpf","rg","email","endereco_res","cidade_res","bairro_res","cep_res","banco","agencia","conta","arquivo"];
	var nm_campos = ["Nome","Aluno","Formação","CPF","RG","E-mail","Endereço (Residencial)","Cidade (Residencial)","Bairro (Residencial)","CEP (Residencial)","Banco","Agência","Conta","Arquivo"];
	
	for (var i=0; i < formulario.length; i++) {
		
		for (a=0; a < campos.length; a++) {
			if (formulario.elements[i].id == campos[a]) {
				if (formulario.elements[i].value == "") {
					alert("Favor, preencher o campo obrigatório " + nm_campos[a]);
					formulario.elements[i].focus();
					return false;
				}		
			}
		}
		
	}
	
	return true;
}

function ajaxInit() {
	var xmlhttp ;
	try {
		xmlhttp = new XMLHttpRequest() ;
	} catch (ee) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			 xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	}
	return xmlhttp ;
}

function include(url,id,parametros) {
	mostra = document.getElementById(id) ? document.getElementById(id) : document.all[id];
	ajax = ajaxInit();
	if (ajax) {
		parametros = "?" + Math.ceil(Math.random() * 100000) + (parametros != null ? parametros : '');
		ajax.open('GET',url,true);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					texto=unescape(ajax.responseText.replace(/\+/g," "));
					mostra.innerHTML = texto;
					extraiScript(texto);
				}
			}
		}
		ajax.send(null);
	}
}


function opcao() {
	include("cronograma.php?curso=" + document.getElementById("curso").value + '&turma=' + document.getElementById("turma").value,"cronogramass");
}
function opcao2() {
	include("cronograma2.php?curso=" + document.getElementById("curso").value + '&turma=' + document.getElementById("turma").value,"cronogramass");
}

function extraiScript(texto){   
    var ini, pos_src, fim, codigo;   
    var objScript = null;   
    ini = texto.indexOf('<script', 0)   
    while (ini!=-1){   
        var objScript = window.document.createElement("script");   
        pos_src = texto.indexOf(' src', ini)   
        ini = texto.indexOf('>', ini) + 1;   
        if (pos_src < ini && pos_src >=0){
            ini = pos_src + 4;    
            fim = texto.indexOf('.', ini)+4; 
            codigo = texto.substring(ini,fim);   
            codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">",""); 
            objScript.src = codigo;   
        }else{ 
            fim = texto.indexOf('</script>', ini);   
            codigo = texto.substring(ini,fim);    
            objScript.text = codigo;   
        }   
        window.document.body.appendChild(objScript);   
        ini = texto.indexOf('<script', fim);   
 
        objScript = null;   
    }   
}
