// JavaScript Document

function selection(obj, set_text_default){   
    /* @author Bernardo Rufino  
     * @license Creative Commons Developing Nations: http://creativecommons.org/licenses/devnations/2.0/  
     * @description Function to manipulate the actual selection  
     * @returns It returns an object with an attribute *text* with the current selection text and  
     *        a method *setText()* that receives one argument, the text to be set in the selection.  
     * @parameters The first is the object where you want the selection (DOM or String with id), and  
     *           the second (optional), a boolean, if is true then the *setText()* method will  
     *           append the text if there's no way to replace the selection.  
     *  
     *     !Nao retire essas informacoes!  
     *     !Do not drop this information!  
    */  
    if(obj.constructor == String){
	
		obj = document.getElementById(obj);
	
	}   
	
    var set_text = (set_text_default) ? function(text){obj.value += text;} : function(){return false;};   
    var selection = {text: null, setText: set_text};   
    if(document.selection){   
        
		var range = document.selection.createRange();   
		if (range.text !=""){
		
		selection.text = range.text;   
		selection.setText = function(text){   
		range.text = text.replace(/\\r?\\n/g, "\\r\\n");   
			
		}
		}
    } else if(typeof(obj.selectionStart) != "undefined"){   
        
		selection.text = obj.value.substring(obj.selectionStart, obj.selectionEnd);   
        selection.setText = function(text){   
			if(text != null && text != ""){
            obj.value = obj.value.substring(0, obj.selectionStart) + text + obj.value.substring(obj.selectionEnd);   
			}
        }   
    } else if(window.getSelection){   
        selection.text = window.getSelection().toString();   
		 
    }   
	
    return selection;   
}  

function handleEnter (field, event) {
        var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if (keyCode == 13) {
            field.value += "<br>"
        } 
    }      


function SetBold(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<b>" + selected.text + "</b>");  
	}
}

function SetItalic(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<i>" + selected.text + "</i>");  
	}
}

function SetUnderline(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<u>" + selected.text + "</u>");  
	}
}
function SetCenter(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<center>" + selected.text + "</center>");  
	}
}
function SetRight(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<div align='right'>" + selected.text + "</div>");  
	}
}
function SetLeft(txt){
	if (txt != ""){
		selected = selection(txt, true);
		selected.setText("<Div align='left'>" + selected.text + "</div>");  
	}
}







function ajaxInit() {
	var req;
	try {
		 req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		 try {
			  req = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch(ex) {
		 try {
		   req = new XMLHttpRequest();
	     } catch(exc) {
	 		  alert("Esse browser não tem recursos para uso do Ajax");
	  		 req = null;
	     }
	 }
}
return req;
}

function PreviewPanel(texto) {
	ajax = ajaxInit();
	
	if(ajax) {
			ajax.open("GET","PreviewPanel.asp?texto=" + texto, true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {
						
						document.getElementById("PreviewPanel").innerHTML = ajax.responseText;
						
					}else{	
						alert(ajax.statusText)
					}
				}
			}
			ajax.send(null);
		
	}
}

function verificaEmail(email) {
	ajax = ajaxInit();
	if(ajax) {
		ajax.open("GET","verifica_email.asp?email=" + email, true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					
					document.getElementById("alerta").value = ajax.responseText;
					if(document.getElementById("alerta").value == 'N'){
						document.getElementById("textoAlerta").style.display = "";
					}
					
				}else{	
					alert(ajax.statusText)
				}
			}
		}
		ajax.send(null);		
	}
}

function Confirm(text, url) {
	var answer = confirm(text)
	if (answer){
		location.href = url;
		
	}
	else{
		
	}
}

var win = null;
function NewWindowPanel(valor){
	
	LeftPosition = (screen.width) ? (screen.width-400)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-300)/2 : 0;
	settings =
	'height=300,width=400,top='+TopPosition+',left='+LeftPosition+',scrollbars=Yes,resizable'
	win = window.open("PreviewPanel.asp?texto="+valor,"",settings)
}

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
	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+',resizable'
	win = window.open(mypage,myname,settings)
}

function sizeFont (elem, acao){    // tamanho inicial da fonte (em px)
    var tamInic = 11;    // Tamanho mínimo da [b]fonte (em px)
	var tamMin = 9;    // Tamanho máximo da fonte (em px)    
	var tamMax = 24;    // Pega o tamanho da fonte. Se não foi setada ainda (primeira vez que a função é executada) terá como tamanho padrão 'tamInic'.
	el = elem.split(",");
	for (x = 0 ; x <= el.length-1; x++){
		if (document.getElementById(el[x]).style.fontSize == "") {            
			var tamFonte = tamInic;
		}else{            
			var tamFonte = parseInt(document.getElementById(el[x]).style.fontSize);            
		}            
		switch (acao){                // Aumenta o tamanho, enquanto foi menor que 'tamMax'                
			case '+':                        
				if (tamFonte < tamMax)
					document.getElementById(el[x]).style.fontSize = (tamFonte + 2) + "px";
			break;                // Diminui o tamanbo, enquanto for maior que 'tamMin'                
			case '-':                        
				if (tamFonte > tamMin)                                
					document.getElementById(el[x]).style.fontSize = (tamFonte - 2) + "px";
			break;
		}
	}
}

function apagarValue(controle, obj){
	if(controle.value == "0"){
		obj.value = ""
		controle.value = "1"
	}
}

function fecha(){
	ajax = ajaxInit();
	if(ajax){
		ajax.open("GET","desconecta.asp", true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					document.getElementById("menu_resp").innerHTML = ajax.responseText;
				}else{	
				}
			}
		}
		ajax.send(null);
	}
}

function checado(name, cod, id){
	
	novoCod="";
	if(document.getElementById(name).checked){
		document.getElementById(id).value += cod+"|"; 
	}
	if(document.getElementById(name).checked==false){
		valores = document.getElementById(id).value;
		document.getElementById(id).value="";
		codigos = valores.split("|");
		
		for (i=0;i<=codigos.length-2;i++){
			
			if(codigos[i] != cod){
				novoCod = novoCod+codigos[i]+"|";
				document.getElementById(id).value=novoCod;
			}
		}
	}
}

function setarHora()
	{
		var time = new Date()
		var hora = time.getHours();
		var minuto = time.getMinutes();
		var segundos = time.getSeconds();
		document.getElementById("hora").value = hora  + ":" + minuto + ":" + segundos;
	}
	
function mostraResp(contador,idSelected,strID)
{
	
	for(i=1;i<=contador;i++)
	{
		//document.getElementById(strID + i).style.display='none'; 
	}
	document.getElementById(idSelected).style.display='block';                
}	

function Contador(field,MaxLength) 
{
      
  //obj = document.all(field);
  document.getElementById(field)
  if (MaxLength !=0) {
	 if (  document.getElementById(field).value.length > MaxLength)  {
		  document.getElementById(field).value =   document.getElementById(field).value.substring(0, MaxLength);
		}
  }
  document.getElementById('contador').innerHTML =   document.getElementById(field).value.length + '/' + MaxLength;
}
function mostra(mostra,resposta)
{
	
	var valor = document.getElementById(mostra).value;
	if (valor == 1)
	{
		document.getElementById(resposta).style.display="none";
		document.getElementById(mostra).value = "2"
	}
	if (valor == 2)
	{
		document.getElementById(resposta).style.display="";
		document.getElementById(mostra).value = "1"
	}
}
function enviaForm()
{
	if(validaFormGeral() == false)
	{
		return false;
	}
	setarHora();
	return true
}
function janelaJogo(wurl)
{
	
	winDt = window.open(wurl,'','top=80,left=200,width=600,height='+ screen.height +',scrollbars=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1');
	winDt.focus();
}
function ocultaCanais(id)
{
	
	id_par = id;
	vet_id = id_par.split("_");
	id_element = vet_id[1];
	img = document.getElementById(id);
	div_canais = document.getElementById(id_element);
	var aux_class = div_canais.className;
	if (aux_class == "visivel")
	{
		div_canais.className = "oculto";
		img.src = "imagens/icon_mais.jpg";
		img.alt = "Mostrar Canais"
	}
	if (aux_class == "oculto")
	{
		div_canais.className = "visivel";
		img.src = "imagens/icon_menos.jpg";
		img.alt = "Mostrar Canais"
	}
}


function abrirCanal(cod)
{
	wurl = "canal_det.asp?codigo=" + cod	
	left = (parseInt(screen.width) / 2) - 350
	var top = (parseInt(screen.height) / 2) - 250
	winDt = window.open(wurl,'','top='+ top +',left=' + left + ',width=550,height=440,scrollbars=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0');
	winDt.focus();	
	
	
}
var controle = true
var left = 0
function abrirChat()
{
	
	if( controle == false)
	{
		
		window.resizeTo(550,510);
		window.moveBy(250,0)
		document.getElementById("imgChat").src = "imagens/abrir_chat.jpg";
		document.getElementById("imgChat").alt = "Fechar Chat";				
		document.getElementById("chat").style.visibility = "hidden"
		controle = true;
	}
	else
	{
		
		window.resizeTo(1050,510);
		window.moveBy(-250,0)
		document.getElementById("imgChat").src = "imagens/fechar_chat.jpg";
		document.getElementById("imgChat").alt = "Abrir Chat"
		document.getElementById("chat").style.visibility = "visible"	
		controle = false;
	}
}
function redimensiona()
{
	left = (parseInt(screen.width) / 2) - 350
	var top = (parseInt(screen.height) / 2) - 250
	window.resizeTo(550,510);
	window.moveTo(left,top)
}

function carregaConteudo(url, id,tipo) {
	
	ajax = ajaxInit();
	var vetId = id.split("_")
	if(tipo == "R")
	{
			
		ajax.open("GET","carrega_conteudo.asp?tipo=U", true);
				
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {					
				
					window.opener.document.getElementById("caixaUltimas").innerHTML = ajax.responseText
										
					
				}else{
					alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
		
		setTimeout(function(){
		
			url = url + "&class=" + window.opener.document.getElementById("controleCor_"+vetId[1]).value
			
			if(window.opener.document.getElementById("controleCor_"+vetId[1]).value == "respTopicoCinza")
			{
				window.opener.document.getElementById("controleCor_"+vetId[1]).value = "respTopicoVerde"	
			
			}
			else
			{
				window.opener.document.getElementById("controleCor_"+vetId[1]).value = "respTopicoCinza"		
				
			}
			if(ajax) {
		
			
				ajax.open("GET",url, true);
				
				ajax.onreadystatechange = function() {
					if(ajax.readyState == 4) {
						if(ajax.status == 200) {						
							objDiv = window.opener.document.createElement("div")
							objDiv.id = "divAux1"+id
							objDiv2 = window.opener.document.createElement("div")
							objDiv2.id = "divAux2"+id
							window.opener.document.getElementById(id).appendChild(objDiv)
							window.opener.document.getElementById(id).appendChild(objDiv2)
							window.opener.document.getElementById(id).id = "divAux3"+id
							window.opener.document.getElementById("divAux1"+id).id = id
							window.opener.document.getElementById("divAux2"+id).innerHTML = ajax.responseText
							close();	
							
							
						}else{
							alert(ajax.statusText);
						}
					}
				}
				ajax.send(null);
			}
		
		
		},1500)
	}
	
	
	if(tipo != "C")
	{
		
		if(tipo != "R")
		{
					
			if(ajax) {
			
				
				ajax.open("GET",url, true);
				
				ajax.onreadystatechange = function() {
					if(ajax.readyState == 4) {
						if(ajax.status == 200) {						
							objDiv = window.opener.document.createElement("div")
							objDiv.id = "divAux1"+id
							objDiv2 = window.opener.document.createElement("div")
							objDiv2.id = "divAux2"+id
							window.opener.document.getElementById(id).appendChild(objDiv)
							window.opener.document.getElementById(id).appendChild(objDiv2)
							window.opener.document.getElementById(id).id = "divAux3"+id
							window.opener.document.getElementById("divAux1"+id).id = id
							window.opener.document.getElementById("divAux2"+id).innerHTML = ajax.responseText
							close();	
							
							
						}else{
							alert(ajax.statusText);
						}
					}
				}
				ajax.send(null);
				
			}
		}
		
	}
	else
	{
			if(document.getElementById("busca"))
			{
				if(url == "carrega_conteudo.asp")
				{
					url = url + "?categ=" + document.getElementById("cod_categ").value;	
					url = url + "&busca=" + document.getElementById("busca").value
					
				}
				
				objDiv = document.createElement("div")
				objDiv.className = "divCarregando"
				objDiv.style.left = "25%"
				objDiv.style.top = "-110px"
				objDiv.style.paddingTop = "0px"
				objDiv.style.height = "90px"
				objDiv.style.width = "90px"
				objDiv.style.textAlign = "left"
				objImg = document.createElement("img")
				objImg.src = "../imagens/loading.gif";
				objBody = document.getElementById(id)
				objBody.appendChild(objDiv);
				objDiv.appendChild(objImg)
			}
			
			if(ajax) {
			
			ajax.open("GET",url, true);
			
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) {						
						
						document.getElementById(id).innerHTML = ajax.responseText
						
					}else{
						alert(ajax.statusText);
					}
				}
			}
			ajax.send(null);
		}	
	}
	
	scaleImg()
}
function carregaUltimasPostagens()
{
	
	
	ajax = ajaxInit();
	if(ajax){
		ajax.open("carrega_conteudo.asp?tipo=U", true);
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					window.opener.document.getElementById("caixaUltimas").innerHTML = ajax.responseText
					close();
				}else{	
				}
			}
		}
		ajax.send(null);
	}
	
}
function mudarTitulo(titulo)
{
	document.getElementById("tituloSecao").innerHTML = titulo	
	
}

function janelaNovo(url,height)
{
	url = url + "&categ=" + document.getElementById("cod_categ").value;	
	var left = (parseInt(screen.width) / 2) - 350
	var top = (parseInt(screen.height) - parseInt(height) )/ 2
	winDt = window.open(url,'','top=' + top + ',left=' + left +',width=535,height='+ parseInt(height) +',scrollbars=1,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1');
	winDt.focus();

}   

function selecaoSmile(id)
{
	
	if(document.getElementById(id).className == "smileBordaNone" || document.getElementById(id).className == "")
	{
		obj = document.getElementById("listaSmiles").getElementsByTagName("img")
		for(i=0;i<obj.length;i++)
		{
			obj[i].className = "smileBordaNone"
		
		}
		document.getElementById(id).className = "smileBorda"
		var str = document.getElementById(id).src		
		document.getElementById("smilie").value = document.getElementById(id).src
	}
	else
	{
		document.getElementById(id).className = "smileBordaNone"	
		document.getElementById("smilie").value = ""
	}
	
	
}
var contTopicoVisivel = 0
function mostraRespTop(id)
{
	
	if(document.getElementById(id).style.display == "none")
	{
		document.getElementById(id).style.display = "block"
		if(controlePause == false)
		{
			pausarTempo()	
		}
		contTopicoVisivel = parseInt(contTopicoVisivel) + 1
	}
	else
	{
		document.getElementById(id).style.display = "none"
		contTopicoVisivel = parseInt(contTopicoVisivel) - 1
		if(contTopicoVisivel == 0)
		{
			pausarTempo()	
		}
	}
}
function limparBusca()
{
	document.getElementById("busca").value = ""
	url = "carrega_conteudo.asp?categ=" + document.getElementById("cod_categ").value
	carregaConteudo(url,'listagemPergunta','C')
}

objI = new Object();
var tempo = 182;
function contTempo()
{
	
	  if(tempo == 0)
	  {
		  clearInterval(objI);
		  carregaConteudo('carrega_conteudo.asp','listagemPergunta','C')
		  contTempoAuto()
		  tempo = 181
	  }
	  else
	  {
		  tempo = parseInt(tempo) - 1;
		  document.getElementById('contadorTemp').childNodes[0].nodeValue = tempo
		  
	  }
					  
				
}
function contTempoAuto()
{
	
	objI = 	setInterval('contTempo()',1000)
	
}
var controlePause = false;
function pausarTempo()
{
	if(controlePause == false)
	{
		 clearInterval(objI);	
		 controlePause = true
	}
	else
	{
		contTempoAuto()	
		controlePause = false;
	}
	
}
function insNumeric(obj,event)
{
    var tecla = event.charCode;
    var ie = event.keyCode;
    if (!event) event = window.event;
    var code;
    if (event.keyCode) code = event.keyCode;
    else if (event.which) code = event.which; // Netscape 4.?
//se nao for número nem parentesis ou espaço
    if ((code < 48 || code > 59) && (code != 8 ) ){
      event.returnValue = false;
      if (event.which){
        event.preventDefault();
      }
      return false;
    }else{
      event.returnValue = true;
      return true;
    }
}
function formatarMascara(id, mask)
{
	src = document.getElementById(id);
	var i = src.value.length;
  	var saida = mask.substring(0,1);
  	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida)
  	{
    	src.value += texto.substring(0,1);
  	}
}
var vetImg = new Array()
function scaleImg() {
  var scalePhotos = document.getElementsByClassName('scale-image');
  
  floorSize = .26;
  ceilingSize = 1.0;
  //v = floorSize + (v * (ceilingSize - floorSize));

  for (i=0; i < scalePhotos.length; i++)
  {
    vetImg[i] = new Image();
	vetImg[i].src = scalePhotos[i].src
	
  }
  setTimeout(function(){
	  for (i=0; i < scalePhotos.length; i++)
	  {
		if( vetImg[i].width > 500 )
		{		
			scalePhotos[i].style.width = "500px";
		}
		
	  }
	  var script = document.createElement('script');
	  script.src = '../includes/js/jquery.js';
	  script.type = 'text/javascript';
	  script.defer = true;
	  script.id = 'scriptID'; // This will help us in referencing the object later for removal
		// Insert the created object to the html head element
	  var head = document.getElementsByTagName('head').item(0);
	  head.appendChild(script);
	  
  },3000)
} 


function janelaNovo2(url,height)
{
	
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	
	
	$("<div id='fundoOpaco'></div>"	).appendTo("body").show()		
	
	
	
	objF = document.getElementById('fundoOpaco')
	objF.style.width = pageWidth + "px"
	objF.style.height = (pageHeight+100) + "px"
	$("#fundoOpaco").click(function(){		
		$("#conteudoCad").remove()
		$("#fundoOpaco").remove()
		$("#img_carregando").remove()
		
	})
	
	if (document.all)
	{
		var wtop = parseInt(document.documentElement.scrollTop) + 30
		
	}
	else
	{
		var wtop = parseInt(window.scrollY) + 30	
	}
	var wleft = ( (parseInt(screen.width) - 560) / 2 )
	
	var strDiv = "<div id='conteudoCad'><p id='img_carregando' style='text-align:center'><img src='../imagens/loading.gif'><p id='rst'></p><p style='text-align:left;' id='p_fecharJanela'><img src='../imagens/closelabel.gif' id='btn_fecharJanela'></p><div>"
	
	$(strDiv).css("left",parseInt(wleft)).css("height",height).css("top",wtop).appendTo("body").hide()
	setTimeout( function(){ 
			
			$("#conteudoCad").load(url,function() { $("#img_carregando").remove(); $("#conteudoCad").show(); $("#p_fecharJanela").show() } ) 
							  
	},500);
	
}
function salvarTopico()
{
	if( validaCadTopico() )
	{
		
		strDiv = "<p class='divCarregando' style='z-index:40;'><img src='../imagens/loading.gif' style='position:absolute;left:200px;top:250px;'></p>"
		$(strDiv).appendTo("#conteudoCad");
		
		var codObj = "";
		obj= $("#frmCadTopico input,#frmCadTopico textarea")	
		for(i=0;i<obj.length;i++)
		{
			if( obj[i].type != "checkbox" )
			{
				codObj += "&" + obj[i].name + "=" + obj[i].value		
			}
			else
			{
				if( obj[i].checked	== true )
				{
					codObj += "&" + obj[i].name + "=" + obj[i].value	
				}
			}		
		}
		codObj = "cadastro_topico2.asp?envia=sim" + codObj		
		
		ajax = ajaxInit();
		if(ajax){
			ajax.open("GET",codObj, true);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4) {
					if(ajax.status == 200) 
					{
						setTimeout(function(){
							var wurl = "carrega_conteudo.asp?categ=" + $("#cod_categ").val()
							carregaConteudo(wurl,'listagemPergunta','C');
							$("#conteudoCad").remove()
							$("#fundoOpaco").remove()
							$("#divCarregando").remove()
						},1000)	
					}
					else
					{
						alert(ajax.status)	
					}
				}
			}
			ajax.send(null);
		}
	}
}
function salvarRespostaTopico(url,id)
{
	if(validaFormGeral())
	{
		if(document.getElementById("descricao").value != "")
		{
			var vetId = id.split("_")
			
			strDiv = "<p class='divCarregando' style='z-index:40;'><img src='../imagens/loading.gif' style='position:absolute;left:200px;top:250px;'></p>"
			$(strDiv).appendTo("#conteudoCad");
			
			var codObj = "";
			obj= $("#frmCadTopico input,#frmCadTopico textarea")	
			for(i=0;i<obj.length;i++)
			{
				if( obj[i].type != "checkbox" )
				{
					codObj += "&" + obj[i].name + "=" + obj[i].value		
				}
				else
				{
					if( obj[i].checked	== true )
					{
						codObj += "&" + obj[i].name + "=" + obj[i].value	
					}
				}
			}
			codObj = url + codObj		
			
			ajax = ajaxInit();
			if(ajax){
				ajax.open("GET",codObj, true);
				ajax.onreadystatechange = function() {
					if(ajax.readyState == 4) {
						if(ajax.status == 200) 
						{
							wcod = ajax.responseText
							
							setTimeout(function(){
								$("#caixaUltimas").load("carrega_conteudo.asp?tipo=U",function(){
									
									
									url = "carrega_conteudo.asp?tipo=P&class=" + document.getElementById("controleCor_"+vetId[1]).value + "&codigo=" + wcod
									
									if(document.getElementById("controleCor_"+vetId[1]).value == "respTopicoCinza")
									{
										document.getElementById("controleCor_"+vetId[1]).value = "respTopicoVerde"	
									
									}
									else
									{
										document.getElementById("controleCor_"+vetId[1]).value = "respTopicoCinza"		
										
									}
									
									objDiv = document.createElement("div")
									objDiv.id = "divAux1"+id
									objDiv2 = document.createElement("div")
									objDiv2.id = "divAux2"+id
									document.getElementById(id).appendChild(objDiv)
									document.getElementById(id).appendChild(objDiv2)
									document.getElementById(id).id = "divAux3"+id
									document.getElementById("divAux1"+id).id = id									
									$("#divAux2"+id).load(url)
									
									
								})			
								
								$("#conteudoCad").remove()
								$("#fundoOpaco").remove()
								$("#divCarregando").remove()
								
							},1000)	
						}
						else
						{
							alert(ajax.status)	
						}
					}
				}
				ajax.send(null);
			}
		}
		else
		{
			alert("Preencha o campo Resposta")	
			document.getElementById("descricao").focus();
			
		}
	}	
	
}
function janelaVideo(codigo)
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	
	
	
	$("#conteudoVideo").remove()
	
	
	$("<div id='fundoOpaco'></div>").appendTo("body").show()		
	
	
	
	objF = document.getElementById('fundoOpaco')
	objF.style.width = pageWidth + "px"
	objF.style.height = pageHeight + "px"
	$("#fundoOpaco").click(function(){		
		$("#conteudoVideo").remove()
		$("#fundoOpaco").hide("slow")
		$("#fundoOpaco").remove()
		$("#img_carregando").remove()
		$("#btn_fecharVideo").remove()
		$("#videosChat").show()
		
	})
	
	if (document.all)
	{
		var wtop = parseInt(document.documentElement.scrollTop) + 30
		
	}
	else
	{
		var wtop = parseInt(window.scrollY) + 30	
	}
	var wleft = ( (parseInt(screen.width) - 560) / 2 )
	$("<div id='conteudoVideo'/>").css('top',wtop+20).appendTo("body").hide()
	$("<img src='../imagens/loading_videos.gif' id='img_carregando'>").css('top',wtop+100).css('left',wleft+100).appendTo("body").show(function(){
		setTimeout( function(){ 
				
			var wurl = "carrega_video.asp?codigo="+codigo
			
			$("#conteudoVideo").load(wurl,function() { 
				setTimeout(function(){					
					wleft = ( parseInt(pageWidth) - parseInt($("#conteudoVideo").width()) ) / 2
					wleft = parseInt(wleft)
					$("#conteudoVideo").css("left",wleft)
					wleft = parseInt(wleft) + parseInt($("#conteudoVideo").width()) - 58
					$("<img src='../imagens/closelabel.gif' id='btn_fecharVideo'>").css('top',wtop-2).css('left',wleft).appendTo("body").hide()
					$("#img_carregando").remove() 
					$("#videosChat").hide()
					$("#fundoOpaco").fadeTo('normal', 1.0,function(){
						
						$("#conteudoVideo").fadeIn("slow",function(){
							$("#btn_fecharVideo").show()										   
						})
						
						$("#btn_fecharVideo").click(function(){
							$("#fundoOpaco").click()								
						})
					})
				},2000)
			} ) 
								  
		},500);
	})
	
}
