// JavaScript Document

function mostrarImg(div, img) {
	var div = document.getElementById(div);
	if (div.innerHTML == "") {
		div.innerHTML = '<img src="' + img + '" border="1" width="56" heigth="40">';
	}
	else {
		div.style.visibility = "visible";
	}
}

function mudarCoreImg(div, img, classe, id) {
	document.getElementById(div).innerHTML = '<img src="' + img + '" border="1" width="56" heigth="40">';
	document.getElementById(id).className = classe;
}

function fichas(url, l, a) {
	var x = parseInt((screen.width-l)/2);
	var y = parseInt((screen.height-a)/2);
	var win = window.open(url,'','scrollbars=yes, width='+l+',height='+a);
	win.moveTo(x,y);
}

function check() {
	document.getElementById('c1').disabled="disabled";
	document.getElementById('c2').disabled="disabled";
	document.getElementById('c3').disabled="disabled";
	document.getElementById('c4').disabled="disabled";
	document.getElementById('c5').disabled="disabled";
	document.getElementById('c6').disabled="disabled";
}

function setaOver(id, img) {
	document.getElementById(id).src = img;
}

function fichas(url, l, a) {
	var x = parseInt((screen.width-l)/2);
	var y = parseInt((screen.height-a)/2);
	var win = window.open(url,'','scrollbars=yes, width='+l+',height='+a);
	win.moveTo(x,y);
}

function mostrarResultado(id, total, prefixo, consulta, location, tipo) {
	var div = document.getElementById(prefixo + id);
	var divID = prefixo + id;
	buscarAjax(consulta, location, tipo, divID);
	for (var i = 0; i < total; i++) {
		if (id != i) {
			document.getElementById(prefixo + i).innerHTML = "&nbsp;";
		}
	}
}

/**
 * updates a counter for a standard text area with a maximum length of
 * opt_maxSize.
 *
 * @param opt_countedTextBox is the id of the text area that has a max length.
 *        Default = "countedTextBox"
 * @param opt_countBody is the id of the div with the text displaying remaining 
 *        character count. Default = "countedBody"
 * @param opt_maxSize is the maximum size allowed for the text area.
 *        Default = 1024
 */
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
  var countedTextBox = opt_countedTextBox ?
    opt_countedTextBox : "countedTextBox";
  var countBody = opt_countBody ? opt_countBody : "countBody";
  var maxSize = opt_maxSize ? opt_maxSize : 1024;
    
  var field = document.getElementById(countedTextBox);
  if (field && field.value.length >= maxSize) {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(countBody);
  if (txtField) {  
    txtField.innerHTML = field.value.length;
  }
}

function mudarTopCCR(action, i) {
	for (j = 1; j <= 6; j++) {
		if (j != i) {
			$(j.toString()).style.fontWeight = "normal";
		}
	}
	$(i).style.fontWeight = "bold";
	if (action == "filmes") {
		$('inc_top_ccr_titulo').innerHTML = "<span>&nbsp;&nbsp;<b>TOP CCR - <i>FILMES</i></b></span>";
		$('inc_top_ccr_subtitulo').innerHTML = "<i>Mais Visitados do Mês Atual</i>";
	}
	else if (action == "filmes_semana") {
		$('inc_top_ccr_titulo').innerHTML = "<span>&nbsp;&nbsp;<b>TOP CCR - <i>FILMES</i></b></span>";
		$('inc_top_ccr_subtitulo').innerHTML = "<i>Mais Visitados da Semana</i>";
	}
	else if (action == "personalidades") {
		$('inc_top_ccr_titulo').innerHTML = "<span>&nbsp;&nbsp;<b>TOP CCR - <i>PERSONALIDADES</i></b></span>";
		$('inc_top_ccr_subtitulo').innerHTML = "<i>Mais Visitadas do Mês Atual</i>";
	}
	else if (action == "personalidades_semana") {
		$('inc_top_ccr_titulo').innerHTML = "<span>&nbsp;&nbsp;<b>TOP CCR - <i>PERSONALIDADES</i></b></span>";
		$('inc_top_ccr_subtitulo').innerHTML = "<i>Mais Visitadas da Semana</i>";
	}
	else if (action == "criticas") {
		$('inc_top_ccr_titulo').innerHTML = "<span>&nbsp;&nbsp;<b>TOP CCR - <i>CRÍTICAS</i></b></span>";
		$('inc_top_ccr_subtitulo').innerHTML = "<i>Mais Visitadas do Mês Atual</i>";
	}
	else if (action == "criticas_semana") {
		$('inc_top_ccr_titulo').innerHTML = "<span>&nbsp;&nbsp;<b>TOP CCR - <i>CRÍTICAS</i></b></span>";
		$('inc_top_ccr_subtitulo').innerHTML = "<i>Mais Visitadas da Semana</i>";
	}
	
	loadTopCCR(action);	
}
