function openRequestPassword() {
	window.open('http://www.englishvox.com.br/contact_page/requisicao_senha.html','_blank','width=450,height=320,scrollbars=0');
}

function openContact() {
	//window.open('http://www.englishvox.com.br/atendimento/livezilla.php','','width=600,height=550,left=0,top=0,resizable=yes,menubar=no,location=yes,status=yes,scrollbars=yes');
	window.open('http://www.englishvox.com.br/contact_page.php','','width=420,height=600,scrollbars=0');
}

function openChat(userID, cursoID) {
	// Abre o chat do Livezilla com o usuário logado
	
	var httpReq;
	httpReq = inicializaHttpReq(httpReq);
	httpReq.onreadystatechange = function() {
		if (httpReq.readyState == 4) {
			if (httpReq.status == 200) {
				var xml = httpReq.responseXML;
				var link = xml.getElementsByTagName("link")[0].firstChild.nodeValue;
				window.open(link, '', 'width=600,height=550,left=0,top=0,resizable=yes,menubar=no,location=yes,status=yes,scrollbars=yes');
			}
		}
	}
	httpReq.open("POST", "../xmldocs/retorna_dados_usuario_atendimento.php", true); 
	httpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	httpReq.send("userID="+userID+"&cursoID="+cursoID);
}

function openWin(url, width, height) {
	if (url == "contact_page.php") {
		openContact();
	}
	else {
		window.open(url, '', 'width='+width+',height='+height+',scrollbars=no');
	}
}

function inicializaHttpReq(httpReq) {
	httpReq = false;
	if (window.XMLHttpRequest) {
		httpReq = new window.XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		try {
			httpReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				document.write("Năo foi possível construir o objeto da classe XMLHttpRequest");
			}
		}
	}
	return httpReq;
}

function cleanElem(elem) {
	while(elem.firstChild)
		elem.removeChild(elem.firstChild);
}

function _void() {
	return;
}

function janelaPagamento(pedidoID, valor, idioma, meioPagamento, formaPagamento, userID, nome, email, duracaoTrial) {
	window.open("https://www.englishvox.com.br/compras/compra_captura_dados_cartao.php?pedidoID="+pedidoID+"&valor="+valor+"&idioma="+idioma+"&meioPagamento="+meioPagamento+"&formaPagamento="+formaPagamento+"&userID="+userID+"&nome="+nome+"&email="+email+"&duracaoTrial="+duracaoTrial, "pagamento", "width=600, height=500, scrollbars=0");
	if (cancelamento = document.getElementById("cancelamento")) {
		if (!cancelamento.firstChild) {
			cancelamento.appendChild(document.createTextNode("Caso queira trocar de meio de pagamento, "));
			var span = document.createElement("span");
			span.className = "clicavel";
			span.appendChild(document.createTextNode(" clique aqui."));
			span.pedidoID = pedidoID;
			span.codigoPagamento = meioPagamento;
			span.formaPagamento = formaPagamento;
			span.onclick = function() {
				window.location.href = "../idea_commerce/url_de_erro.php?codigo_erro=100&descricao_erro=Usuário fechou a janela do meio de pagamento&uid_pedido=0&codigo_pedido="+this.pedidoID+"&codigo_pagamento="+this.codigoPagamento+"&forma_pagamento="+this.formaPagamento;
			}
			cancelamento.appendChild(span);
		}
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

window.onload = function() {
	externalLinks();
}