//FUNÇÃO PARA VERIFICAR SE AS SENHAS SÃO IGUAIS
function validaSENHA(senha1,senha2,campo){
	if (senha1!=senha2){
		alert("As Senhas não conferem.");
		campo.focus();
		return false;
	}else if (senha1=="" || senha2==""){
		alert("Preencha corretamente o campo senha.");
		campo.focus();
		return false;
	}
}

//RETORNA UM NUMERO RANDOMICO
function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}

//FUNÇÃO PARA MOSTRAR UM ARQUIVO FLASH SEM BORDAS DO ACTIVEX
function printSWF(nomeSWF,larguraSWF,alturaSWF,wmodeSWF){
document.write('<embed src="'+nomeSWF+'?rnd=000000022" type="application/x-shockwave-flash" width="'+larguraSWF+'" height="'+alturaSWF+'" wmode="'+wmodeSWF+'"></embed>')
}

//FUNÇÃO PARA MOSTRAR UM ARQUIVO FLASH DO YOUTUBE SEM BORDAS DO ACTIVEX
function printSWF_YOUTUBE(nomeSWF,larguraSWF,alturaSWF,wmodeSWF){
document.write('<embed src="'+nomeSWF+'" type="application/x-shockwave-flash" width="'+larguraSWF+'" height="'+alturaSWF+'" wmode="'+wmodeSWF+'"></embed>')
}

//MOSTRA 1 TABLE E ESCONDE OUTRAS
function escondeCurso(id){
for (i=0;i<document.form1.elements.length;i++){
	id1 = document.form1.elements[i].value
	if (id1!=undefined){
		if (id != id1){
			document.getElementById(id1).style.display = "none";
			document.getElementById(id1).style.position = "absolute";
		}
	}
}
if (document.getElementById(id).style.display == 'block'){
	document.getElementById(id).style.display = "none";
	document.getElementById(id).style.position = "absolute";
}else{		
	document.getElementById(id).style.display = "block";
	document.getElementById(id).style.position = "static";
	}
}

//MOSTRA 1 TABLE E ESCONDE OUTRAS, ADAPTADO PARA VIDEOS
function escondeVideo(id,linkEMBED){

for (i=0;i<document.form1.elements.length;i++){
	id1 = document.form1.elements[i].value;
	
	if (id1!=undefined){
		if (id != id1){
			document.getElementById(id1).innerHTML = "&nbsp;";
			document.getElementById(id1).style.position = "absolute";
			document.getElementById(id1).style.display = "none";		
		}
	}
}


if (document.getElementById(id).style.display == 'block'){
	document.getElementById(id).innerHTML = "&nbsp;";
	document.getElementById(id).style.display = "none";
	document.getElementById(id).style.position = "absolute";
}else{		
	document.getElementById(id).style.display = "block";
	document.getElementById(id).innerHTML = "<embed src='"+linkEMBED+"' type='application/x-shockwave-flash' width='420' height='327'></embed>";	
	document.getElementById(id).style.position = "static";
	}
}


//PINTA A TD COM ONMOUSEOVER E ONMOUSEOUT
function pinta(id1,sts){
   for (i=0;i<document.f1.elements.length;i++){
      if(document.f1.elements[i].name == "foto_"){
	     id2=document.f1.elements[i].value;
	     document.getElementById(id2).style.backgroundColor="";
	  }
   }


if (sts=="on") document.getElementById(id1).style.backgroundColor="#e6e7e8";   

}

//PINTA A TD COM ONMOUSEOVER E ONMOUSEOUT
function pinta1(id1,sts,outcolor){
//   for (i=0;i<document.f1.elements.length;i++){
//      if(document.f1.elements[i].name == "foto_"){
//	     id2=document.f1.elements[i].value;
//	     document.getElementById(id2).style.backgroundColor="";
//	  }
//   }


if (sts=="on") document.getElementById(id1).style.backgroundColor="#e6e7e8";   
if (sts=="off") document.getElementById(id1).style.backgroundColor=outcolor; 
}

//FUNÇÃO PARA ABRIR POPUP
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable){
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'yes';
  resizable_str = resizable ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

//VERIFICA O EMAIL
function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
	alert("Endereço de e-mail incorreto.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("O nome de usuário contém caracters inválidos.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("O nome do domíniio contém caracteres inválidos.");
return false;
   }
}

if (user.match(userPat)==null) {
alert("O nome de usuário é inválido.");
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Endereço IP do destinatário é inválido!");
return false;
   }
}
return true;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("O Nome do domínio não é válido.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Endereço de e-mail inválido.");
return false;
}

if (len<2) {
alert("Está faltando o nome do domínio!");
return false;
}

return true;
}

//FUNÇÃO PARA CARREGAR CEPS
function loadCEP(qcep){
	parent.document.getElementById("endereco").className="impR";
	parent.document.getElementById("bairro").className="impR";
	parent.document.getElementById("cidade").className="impR";
	parent.document.getElementById("estado").className="impR";	
	
	document.getElementById("endereco").value="carregando...";
	document.getElementById("bairro").value="carregando...";
	document.getElementById("cidade").value="carregando...";
	document.getElementById("estado").value="carregando...";
	
	tmppage.location.href='loadcep.asp?cep='+qcep;	
}
function lvalida (){
if (document.lform.login.value==''){
	alert("Informar nome de Usuário");
	document.lform.login.focus();
	return false;
	}
if (document.lform.senha.value==''){
	alert("Informar senha");
	document.lform.senha.focus();
	return false;
	}
}


function atualizaIframe(nct){
var tamanho = document.getElementById("pagina").offsetHeight;
parent.document.getElementById(nct).style.height = tamanho;
}


//FUNÇÃO PARA CHECKIN
var xmlHttp
function checkin(vidc,vflg_conteudo,vid_conteudo){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	}
	
	var url="/globalcoop/funcoes/checkin.asp"
	url=url+"?vflg_conteudo="+vflg_conteudo
	url=url+"&vid_conteudo="+vid_conteudo
	url=url+"&idc="+vidc	
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
//		document.getElementById("txtHint").innerHTML=xmlHttp.responseText
	}
}

function GetXmlHttpObject(){
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

return objXMLHttp
}