var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

function getURL() {
	uri =  new Object();
	
	uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
	uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
	uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
	uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
	pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
	uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
	uri.file = uri.page;
	if (uri.ext != '') uri.file += '.' + uri.ext;
	if (uri.file == '') uri.page = 'index';
	uri.args = location.search.substr(1).split("?");
	
	return uri;
}


function FreeTrial(id){
	
	getDados(id,"TRIAL","FreeTrial");
	
	//var win = window.open( "index.php?p=retencao_cursos&curso_id="+id+"&link=TRIAL', 'Free Trial', 'width=500, height=450'); 
	
//	var win window.open("elearning/cursos/freetrial.php?curso_id="+id,"_trial","width=780,height=495, left=0,top=0,resizable=no, status=0");
		
	//var win = window.open( "index.php?p=retencao_cursos&curso_id="+id+"&link=TRIAL", "_trial","width=780,height=495, left=0,top=0,resizable=no, status=0");
	
//	win.moveTo(0,0);
//	win.focus();
}

function SaindoFreeTrial(id_curso)
{
	if(ft_flag == 0)
	{
	//	NewWindow('/cursos/elearning/cursos/popup_freetrial.php?id_curso='+id_curso+'&nome='+ft_nome+'&email='+ft_email+'&id_curso='+id_curso+'&ft_flag='+ft_flag,'popup_freetrial','300','670','');
	}
}

function setFreeTrial(nome, email, flag_final)
{
	ft_email = email;
	ft_nome = nome;
	ft_flag = flag_final;
}

function hidelayer(lay)
{
	if (ie4) {document.all[lay].style.visibility = "hidden";}
	if (ns4) {document.layers[lay].visibility = "hide";}
	if (ns6) {document.getElementById([lay]).style.visibility="hidden"};
}

function showlayer(lay)
{
	if (ie4) {document.all[lay].style.visibility = "visible";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.visibility="visible"}; 
}

function writeDiv(divName, newValue) // APS 6/29/00
{
	var divObject = simpleFindObj(divName);

	if (divObject && divObject.innerHTML)
	{
		divObject.innerHTML = newValue;
	}

	else 
	if (divObject && divObject.document)
	{
		divObject.document.writeln(newValue);
		divObject.document.close();
	}
}

function simpleFindObj(name, inLayer){
	return document[name] || (document.all && document.all[name])
	|| (document.getElementById && document.getElementById(name))
	|| (document.layers && inLayer && document.layers[inLayer].document[name]);
}


function NewWindow(mypage, myname, w, h, scroll, menubar, status){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',menubar='+menubar+',status='+status+',resizable';
	eval("var win_"+myname+ "= window.open(mypage, myname, settings);");
	eval("win_"+myname+ ".focus();");
}

function abrirAtendimentoOnline(){
	var win = window.open("http://dtplat.directtalk.com.br/server20/directtalk_chat.dll/user?S=I&id_s=50DC005989FA501198B5&origem=educacao+executiva", "_atendimento","width=500,height=350, left=100,top=200,resizable=yes,scrollbars=yes ,status=no");
	win.focus();
}

function abrirCancelamentoPec(id_participante){
	//windowajuda = NewWindow('cms/cancelamento.php?id_participante='+id_participante, 'Cancelamento','480','445','','','');
	windowajuda = NewWindow('index.php?p=cancelamento_teo', 'Cancelamento','480','470','no','no','no','no');
}

function abrirConteudoProgramatico(id_participante, tipo){
	windowajuda = NewWindow('assinantes/conteudoProgramatico.php?id_participante='+id_participante+'&tipo='+tipo, 'Conteúdo','700','600','yes','','');
}

function verificaLogin(){
	
	var url = getURL();
	
	if (url.dom == "www.beata.catho.com.br")
	{
		document.frm_login.action = "http://www.beata.catho.com.br/cursos/index.php?p=login";
	}

	if(document.frm_login.login.value == '')
	{
		alert('Digite seu login.');
		document.frm_login.login.focus();
		return false;
	}
	else if(document.frm_login.senha.value == '')
	{
		alert('Digite sua senha.');
		document.frm_login.senha.focus();
		return false;
	}
	else
		return true;
}

function EsqueciMinhaSenha()
{
	var win = window.open("lembrar_senha.php", "_senha","width=200,height=200,left=100,top=200,resizable=no,status=no");
	win.focus();
}

function checkVazio(fld,frm,msg)
{
	obj = eval('document.'+frm+'.'+fld);
	if(obj.value == '')
	{
		alert(msg);
		obj.focus();
		return false;
	} else
		return true;
}

function indique(curso, titulo,caminho){
//	alert('aqui');
	var url = document.URL;
	url = url.replace("&", "*");
	url = url.replace("?", "!");
	
	location.href = caminho+"index.php?p=indique&id_curso="+curso+"&url="+url;

	/*
	var url = document.URL;
	var win = window.open("indique.php?titulo="+titulo+"&id_curso="+curso+"&url="+url, "_indique","width=230,height=395,left=100,top=200,resizable=yes, status=no");
	win.focus();
	*/
}

function Depoimentos(id, tipo)
{
	var win = window.open("./?p=depoimentos&curso="+id+"&tipo="+tipo,"_depoimento","width=320,height=240, left=100,top=200,resizable=yes, status=no, scrollbars=yes");
	win.focus();
}

function Presencial(id)
{
	var win = window.open("./?p=presencial_show&id="+id,"_presencial","width=550,height=650, left=0,top=0, resizable=yes, status=no, scrollbars=yes");
	win.focus();
}

function getDados(id,link,janela)
{
	var win = window.open("index.php?p=retencao_cursos&curso_id="+id+"&link="+link, janela, "width=500, height=450,resizable=yes, status=no, scrollbars=yes");
	win.focus();	
}

function PrintInfo(id)
{
	getDados(id,"PDF","PDF");
	/*
	var win = window.open("./index.php?p=pdf&id_curso="+id+"&kind=online","_info","width=550,height=400, left=0,top=0, resizable=yes, status=no, scrollbars=yes");
	win.focus();
	*/	
}

function PrintPresencialInfo(id)
{
	getDados(id,"PDFP","Presencial");
	/*
	var win = window.open("./index.php?p=pdf&id_curso="+id+"&kind=presencial","_presencial_show","width=550,height=400, left=0,top=0, resizable=yes, status=no, scrollbars=yes");
	win.focus();
	*/	
}

function PrintHowtoInfo(id)
{
	getDados(id,"PDFHT","Howto");
	
	//var win = window.open("./index.php?p=pdf&id_curso="+id+"&kind=howto","_howto_show","width=550,height=400, left=0,top=0, resizable=yes, status=no, scrollbars=yes");
	//win.focus();
}

function desc_curso_presencial(id)
{
	var win = window.open("./popup.php?id="+id,"_presencial_mais","width=650,height=400, left=0,top=0, resizable=yes, status=no, scrollbars=yes");
	win.focus();
}

function strquery()
{
	
	var start, key,url,vari,expr;
	var vars = new Array();
	
	
	url =  document.location.toString();
	key = /\?/i;   
	start = url.search(key);
//	alert(url.substring(start+1).search("="));
	if(start>1&&url.substring(start+1).search("=")>0)
	{
		url = url.substring(start+1);   
		vari = url.split("&");
//		alert(vari.length);
		for (var i=0;i<vari.length;i++)
		{
			expr = vari[i].split("=");
			if (expr.length == 2){ 
//				alert(i+"-"+vari[0]+" aaa" + vari[1] + " BBB "); 
				var campo = expr[0];
				var valor = expr[1];
				
				vars[i] = new Array();
				vars[i][0] = campo;			
				vars[i][1] = valor;
//				alert(expr[0]+' = '+expr[1]);
			}

			// verifica todo o envio

		}
	}
	return vars;
}

function PopupPresencialInscricao(id){
	var win = window.open("./index.php?p=popup_inscricoes_presencial&id="+id,"_presencial_show","width=600,height=600, left=0,top=0, resizable=yes, status=no, scrollbars=yes");
	win.focus();	
}

<!--

//configuration

OAS_url ='http://banner.catho.com.br/RealMedia/ads/';

OAS_listpos = 'Top,Top3,TopLeft';

OAS_query = '';

OAS_sitepage = 'www.catho.com.br/curso';

//end of configuration

OAS_version = 10;

OAS_rn = '001234567890'; OAS_rns = '1234567890';

OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);

function OAS_NORMAL(pos) {

document.write('<A HREF=' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + ' TARGET=_top>');

document.write('<IMG SRC=' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + ' BORDER=0></A>');
}

//-->

<!--

OAS_version = 11;

if (navigator.userAgent.indexOf('Mozilla/3') != -1)

OAS_version = 10;

if (OAS_version >= 11)

document.write('<SCRIPT LANGUAGE=JavaScript1.1 SRC=' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + OAS_query + '><\/SCRIPT>');

//-->

<!--

document.write('');

function OAS_AD(pos)
{
if (OAS_version >= 11)
 OAS_RICH(pos);
else
 OAS_NORMAL(pos);
}

function isEmail(elm) 
{	
	if (elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1" && elm.value.length > 7 )
		return true;
	else 
		return false;
}

function verificaEmail(email)
{
	if (!isEmail_bad(email) && isEmail(email) && email.value != '')
		return true;
	else
	{
		alert("Email invalido");
		email.focus();
		return false;
	}
}

function isEmail_bad(elm) 
{
	if (elm.value.indexOf("@.") == "-1" &&
		elm.value.indexOf(".br.") == "-1" &&
		elm.value.indexOf("\"") == "-1" &&
		elm.value.indexOf(" ") == "-1" &&
		elm.value.indexOf("'") == "-1" &&
		elm.value.indexOf(";") == "-1" &&
		elm.value.indexOf(",") == "-1" &&
		elm.value.indexOf("{") == "-1" &&
		elm.value.indexOf("}") == "-1" &&
		elm.value.indexOf("[") == "-1" &&
		elm.value.indexOf("]") == "-1" &&
		elm.value.indexOf("<") == "-1" &&
		elm.value.indexOf(">") == "-1" &&
		elm.value.indexOf("?") == "-1" &&
		elm.value.indexOf("|") == "-1" &&
		elm.value.length > 7 )
			return false;
		else 
			return true;
}

function processaSecurity(url)
{
	//alert(url);
	//alert('estou na home');
}

/**

 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

 */

// Declaring valid date character, minimum year and maximum year

var dtCh= "/";

var minYear=1900;

var maxYear=2100;

function isInteger(s)
{
	var i;

	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);
		
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag)
{
	var i;

	var returnString = "";
	
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n)
{
	for (var i = 1; i <= n; i++)
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)

	var pos1=dtStr.indexOf(dtCh)

	var pos2=dtStr.indexOf(dtCh,pos1+1)

	var strDay=dtStr.substring(0,pos1)

	var strMonth=dtStr.substring(pos1+1,pos2)

	var strYear=dtStr.substring(pos2+1)

	strYr=strYear

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

	for (var i = 1; i <= 3; i++)
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}

	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

	if (pos1==-1 || pos2==-1)
	{
		alert("Por favor, digite uma data válida.")
		return false
	}

	if (strMonth.length<1 || month<1 || month>12)
	{
		alert("Por favor, digite uma data válida.")
		return false
	}

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		alert("Por favor, digite uma data válida.")
		return false
	}

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
	{
		alert("Por favor, digite uma data válida.")
		return false
	}

	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		alert("Por favor, digite uma data válida.")
		return false
	}
	return true
}

function popupAjuda(id_modulo, id_participante, origem,id_curso)
{
	windowajuda = NewWindow('cms/ajuda.php?id_modulo='+id_modulo+'&id_participante='+id_participante+'&origem='+origem+'&id_curso='+id_curso,'ajuda','480','320','','','');
}

function chamaInfo(id_curso)
{
	window.open('click.php?pid=CDV&url=index.php!p=info*id='+id_curso);
}

//Função utilizada pelo siatema do professor
function ReloadPlataforma(sistema)
{
	if(sistema == 'monitor')
	{
		return false;
	}
	else
	{	
		window.opener.location.reload(); //Da reload na pagina que abriu o pop
	}
	
}

//Função utilizada pelo sistema do monitor
function AlteraLeituraMensagem(id_mensagem, tarefa)
{
	opener.document.form1.leitura.value = 'disponivel';
	opener.document.form1.id_mensagem.value = id_mensagem;
	opener.document.form1.tarefa.value = tarefa;
	opener.document.form1.submit();
}

//Função utilizada pelo sistema do monitor
function detectaNavegador() 
{
	if (navigator.appName.toLowerCase().indexOf('microsoft internet explorer') > -1)
	return('ie');
	else
	if (navigator.appName.toLowerCase().indexOf('netscape') > -1)
	return('firefox');
}

//Função utilizada pelo sistema do monitor
function ajustaTamanhoIframe(div,iframe,div_iframe) 
{
	navegador = detectaNavegador();
	//div = div da pagina que abre o iframe
	//iframe = id do iframe 
	//div_iframe = div que esta no iframe
	
	if (navegador == 'firefox') 
	{
		var tamanho = parent.document.getElementById(iframe).contentDocument.body.scrollHeight;
		parent.document.getElementById(iframe).style.height = (tamanho+10)+'px';
		parent.document.getElementById(div).style.height = (tamanho+10)+'px';
	}
	else 
	{
		if (navegador == 'ie')
		{
			var tamanho = document.getElementById(div_iframe).offsetHeight;
			//alert(window.parent.document.getElementById(iframe));
			window.parent.document.getElementById(iframe).height = tamanho+20;
			window.parent.document.getElementById(div).height = tamanho+70;
		}
	}
	
}
