tela = {
	moveTo : function(x,y) { window.scroll(x,y); },
	moveBy : function(x,y) { this.moveTo(this.sx()+x,this.sy()+y) },
	sx : function() { return (is.ie) ? (document.body.scrollLeft) : (window.pageXOffset) },
	sy : function() { return (is.ie) ? (document.body.scrollTop) : (window.pageYOffset) },
	dw : function() { return (is.ie) ? (document.body.scrollWidth) : (document.width) },
	dh : function() { return (is.ie) ? (document.body.scrollHeight) : (document.height) },
	ww : function() { return (is.ie) ? (document.body.clientWidth) : (window.innerWidth) },
	wh : function() { return (is.ie) ? (document.body.clientHeight) : (window.innerHeight) },
	sw : function() { return (screen.width) },
	sh : function() { return (screen.height) }
};

String.prototype.XPGTV_replace = function(a,b) {
	var str = "";
	for (lS=0; lS < this.length; lS++){
		if (this.charAt(lS) == a) { str += b } else { str += this.charAt(lS) }
	}
	return str;
}

function popup(pagina,largura,altura,nome,mais) {
	calcleft = (tela.sw() / 2) - (largura / 2);
	calctop = (tela.sh() / 2) - (altura / 2);
	pop = window.open(''+pagina+'',''+nome+'','width='+largura+',height='+altura+',left='+calcleft+',top='+calctop+',scrollbars=1'+((mais)?','+mais:''));
	pop.focus();
}

function populaCombo(arr, objCombo) {
	for (i=0; i < arr.length; i++) {
		var op = document.createElement("OPTION");
		op.text = arr[i][1];
		op.value = arr[i][0];
		objCombo.options.add(op);
	}
}

function selectOption(obj, value) {
	for(i=0; i < obj.options.length; i++) {
		if (obj.options[i].value == value) {
			obj.options[i].selected = true;
			break;
		}
	}
}

function popupFull(pagina) {
	calcleft = 0;
	calctop = 0;
	pagina += "video_full.php";
	pop = window.open(''+pagina+'','popFull','width='+(screen.width-10)+',height='+screen.height+',left='+calcleft+',top='+calctop+',scrollbars=0');
	pop.focus();
}

function escreveCategoriasBusca(idCatSelecionada) {
	var quebra = 1;
	var html = '<table width="100%" border="0" cellspacing="0" cellpadding="5">\n';
	for (i=0; i<arrCats.length; i++) {
		if (quebra > 3 || quebra == 1) { html += '	<tr>\n';	}
		html += '<td class="style3" valign="top" abbr="33%"><img src="./imagens/bullet.gif" width="8" height="7" /> <a href="busca.php?cat='+arrCats[i][0]+'&catN='+arrCats[i][1]+'&recentes=1" style="'+((arrCats[i][0] == idCatSelecionada) ? "font-weight: bold" : "")+'">'+arrCats[i][1]+'</a></td>\n';
		if (quebra == 3) { html += '	</tr>\n'; ((quebra != 1) ? quebra=0 : ""); }
		quebra = quebra + 1;
	}
	html += '</table>';
	document.getElementById("spanCategorias").innerHTML = html;
}

function escreveCategorias(idCatSelecionada) {
	var quebra = 1;
	var html = '<table width="100%" border="0" cellspacing="0" cellpadding="5">\n';
	for (i=0; i<arrCats.length; i++) {
		if (quebra > 3 || quebra == 1) { html += '	<tr>\n';	}
		html += '<td class="style3" valign="top" abbr="33%"><img src="./imagens/bullet.gif" width="8" height="7" /> <a href="#" onclick="return carregaCategoria('+arrCats[i][0]+', \''+arrCats[i][1]+'\')" style="'+((arrCats[i][0] == idCatSelecionada) ? "font-weight: bold" : "")+'">'+arrCats[i][1]+'</a></td>\n';
		if (quebra == 3) { html += '	</tr>\n'; ((quebra != 1) ? quebra=0 : ""); }
		quebra = quebra + 1;
	}
	html += '</table>';
	document.getElementById("spanCategorias").innerHTML = html;
}

function escreveCategoriasCheckbox(arraySelecionados) {
	document.write('<span id="spanCategorias"></span>');
	var checked = "";
	var quebra = 1;
	var html = '<table width="100%" border="0" cellspacing="0" cellpadding="3">\n';
	for (i=0; i<arrCats.length; i++) {
		if (arraySelecionados) {
			checked = "";
			for(f=0; f<arraySelecionados.length; f++) {
				if (arraySelecionados[f] == arrCats[i][0]) {
					checked = "checked";
					break;
				}
			}
		}
		
		if (quebra > 3 || quebra == 1) { html += '	<tr>\n';	}
		html += '<td class="style3" valign="top" abbr="33%" nowrap><input onclick="validaCategoria(3, '+arrCats.length+', this)" type="checkbox" name="cat[]" id="cat'+i+'" value="'+arrCats[i][0]+'" '+checked+'> '+arrCats[i][1]+'</td>\n';
		if (quebra == 3) { html += '	</tr>\n'; ((quebra != 1) ? quebra=0 : ""); }
		quebra = quebra + 1;
	}
	html += '</table>';
	document.getElementById("spanCategorias").innerHTML = html;
}

function validaCategoria(maxCat, totCat, obj) {
	var counter = 0;
	document.F1.categoria.value = "";
	for (i=0; i<totCat; i++) {
		if (document.getElementById("cat"+i).checked == true) {
			if(document.getElementById("cat"+i).value == 14) {
				document.getElementById("msgNaoAdulto").style.display = "block";
				document.getElementById("trCategoria").style.display = "none";
				document.getElementById("titulo").disabled = true;
				document.getElementById("descricao").disabled = true;
				document.getElementById("tags").disabled = true;
				document.getElementById("secaoTudo").style.display = "none";
				document.getElementById("seguirUm").style.display = "none";
				document.getElementById("cat"+i).checked = false;
				break;
			}
			document.F1.categoria.value += document.getElementById("cat"+i).value + ",";
			counter++;
		}
		if (counter > maxCat) {
			alert("Selecione no máximo três.");
			obj.checked = false;
			return false;
			break;
		}
	}
}

function showAgain() {
	document.getElementById("trCategoria").style.display = "block";
	document.getElementById("titulo").disabled = false;
	document.getElementById("descricao").disabled = false;
	document.getElementById("tags").disabled = false;
	document.getElementById("secaoTudo").style.display = "block";
	document.getElementById("seguirUm").style.display = "block";
	document.getElementById('msgNaoAdulto').style.display = 'none';
}

function carregaCategoria(catId, catName) {
	if (catId == 14) {
		document.getElementById('msgAdulto').style.display = 'block';
		document.getElementById('allCats').style.display = 'none';
		return false;
	}
	window.location = 'galeria_videos_categoria.php?cat='+catId+'&catN='+catName+'';
}

function hover(obj, newSrc) {
	obj.src = newSrc;
}

function desabilitarMais(obj, botao) {
	obj.style.display = "none";
	document.getElementById(botao).style.display = "block";
}


try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
        xmlhttp = false;
    }
}
if  (!xmlhttp && typeof  XMLHttpRequest != 'undefined' ) {
    try  {
        xmlhttp = new  XMLHttpRequest();
    } catch  (e) {
        xmlhttp = false ;
        }
}

function quickLog(video_id_md5){
    if (xmlhttp) {
		var send = 'sended=' + video_id_md5 +'|';
                xmlhttp.open("POST",'quicklist_gravar.php', true); //Abre a url.
                xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                xmlhttp.onreadystatechange = function(){
                   if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					//document.getElementById("qtdeVotos").innerHTML = xmlhttp.responseText;
					document.getElementById("trAguarde").style.display = "none";
                }
            }
            xmlhttp.send(send); //Envia dados ao documento da url.
    }
	return false;
}
