function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277&
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            // executa o script
            //eval(codigo);
            /**********************
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            ***********************/
            novo = document.createElement("script")
            novo.text = codigo;
            document.body.appendChild(novo);
        }
    }
}



function calculo(valor,id,maxcursos){
	MaximodeCursos =  maxcursos;
	
	spl = valor.split('-');
	var nivel_curso = spl[0];
	id_modulo = spl[1];
	var marcado = document.getElementById(id).checked;
	
	if (marcado==true)
	val = 1
	else
	val = 0
	

xmlHttp=GetXmlHttpObject();

var url="calculo_tempo.asp";
url=url+"?id_modulo="+id_modulo;
url=url+"&nivel_curso="+nivel_curso;
url=url+"&val="+val;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=MostraValoresdeTempo;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}


function MostraValoresdeTempo() 
{ 

if(xmlHttp.readyState<4)
{
		habilitaRadio(1);	
}
		
if (xmlHttp.readyState==4)
{
habilitaRadio(0);
	   
var xmlDoc=xmlHttp.responseXML.documentElement;
document.getElementById(id_modulo+"_carga_horaria").innerHTML = xmlDoc.getElementsByTagName("carga_horaria")[0].childNodes[0].nodeValue;
//document.getElementById("resultado").innerHTML = xmlDoc.getElementsByTagName("resultado")[0].childNodes[0].nodeValue;
//document.getElementById("resultado_horas").innerHTML = xmlDoc.getElementsByTagName("resultado_horas")[0].childNodes[0].nodeValue;
document.getElementById("resultado_dias").innerHTML = xmlDoc.getElementsByTagName("resultado_dias")[0].childNodes[0].nodeValue;
}

}

function CalculaValor(tot,ini,maxx){
		maxcursos = maxx;
		GlobalIni = ini;
		GlobalMaxx = maxx;
		if(tot==0){
			alert('Selecione o Número de Participantes')
			document.getElementById('pessoas').focus()
			return false
			}		
xmlHttp=GetXmlHttpObject();
var url="calculo_total.asp";
url=url+"?pessoas="+tot;
url=url+"&ini="+ini;
url=url+"&maxx="+maxx;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=MostraValoresTotais;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
	}
	
function MostraValoresTotais() 
{ 
if (xmlHttp.readyState<=3)
{
  document.getElementById("resultadoCalculo").innerHTML="<table width='100' cellpadding='2' cellspacing='2'><tr><td><img src='../site2/img/carregando.gif' width='20'><br></td></tr><tr><td nowrap><span style='font-size:9px'>...Calculando Valores, Por Favor Aguarde...</span></td></tr></table>"
}

if (xmlHttp.readyState==4)
{ 
var result = xmlHttp.responseText
	if (result=='erro')
	alert('Nenhum Curso Foi Selecionado')
	else
	if (result=='erro_dias'){
	alert('Carga horária inferior a 3 horas, favor contatar a IFRS4all®');
	document.getElementById("resultadoCalculo").innerHTML="";
	}
	else
	{
		for(i=1;i<= maxcursos ;i++)
		{
		document.getElementById(i+'-0-nulo').disabled=true
		document.getElementById(i+'-1-basico').disabled=true
		document.getElementById(i+'-2-intermediario').disabled=true
		document.getElementById(i+'-3-avancado').disabled=true
		}	
    document.getElementById("resultadoCalculo").innerHTML=result;
		
	 }	
	}

}

function MostraOculta(div){
	if(document.getElementById(div).style.display=='none')
		document.getElementById(div).style.display='inline'
    else
		document.getElementById(div).style.display='none';	
	}
	

function habilitaRadio(param,acao)
{
 if(acao!='')
 {
		if(param==1){
		valor=true;
		}
		else{
		valor=false;
		}
		
		for(i=1;i<= MaximodeCursos ;i++)
		{
		document.getElementById(i+'-0-nulo').disabled=valor;
		document.getElementById(i+'-1-basico').disabled=valor;
		document.getElementById(i+'-2-intermediario').disabled=valor;
		document.getElementById(i+'-3-avancado').disabled=valor;
		}	
 }
/* else
 {
 CalculaValor(document.getElementById('pessoas').value,GlobalIni,GlobalMaxx);	 
 }
 */
}


