		$(document).ready(function() {
			resizelivroscroll();
			scrollbooks(0);
			//selectaba(0);
		});


		function SomenteNumero(e) {
		    var tecla = (window.event) ? event.keyCode : e.which;
		    if ((tecla > 47 && tecla < 58)) return true;
		    else {
		        if (tecla != 8) return false;
		        else return true;
		    }
		}
		
		function resizelivroscroll() {
			var minsize = 924;
			var numbooks = $('#livrosscroll').children('div.livroitem').length;
			var bookcellwidth = $('#livrosscroll').children('div.livroitem').width() + 26;
			var totalareawidth = bookcellwidth * numbooks;
			if (totalareawidth < 924) {
				totalareawidth = 924;
			}
			var finalwidth = totalareawidth + "px";
			$('#livrosscroll').css({'width' : finalwidth});
		}
		
		function takeYear(theDate) {
			x = theDate.getYear();
			var y = x % 100;
			y += (y < 38) ? 2000 : 1900;
			document.write(y);
		}
		
		function scrollbooks(objct) {
			$('#livrosarea').scrollTo($('div#livrosscroll div.livroitem:eq(0)'));
			if (!objct) {
				var inibook = 0;
			} else {
				var inibook = objct;
			}
			if ($('#livrosscroll').width() > $('#livrosarea').width() + 6) {
				slidescrollbook(inibook);
			} else {
				$('a[name=proximo]').attr('class','arrowrightoff');
			}
		}
		
		function slidescrollbook(inibook) {
			var maxbooks = $('#livrosscroll').children('div.livroitem').length - 1;
			var livrosxarea = parseInt(($('#livrosscroll').width() - $('#livrosarea').width()) - 20);
			$('a[name=proximo]').click( function() { 
				inibook++
				if ($('#livrosarea').scrollLeft() <= livrosxarea) {
					$('#livrosarea').scrollTo($('div#livrosscroll div.livroitem:eq('+ inibook +')'), 200);
					var livrowidth = 0;
					for (i = inibook; i <= maxbooks; i++) {
						livrowidth = livrowidth + $('div#livrosscroll div.livroitem:eq('+ i +')').width();
					}
					if (livrowidth <= $('#livrosarea').width()) {
						$('a[name=proximo]').attr('class','arrowrightoff');
					}
					$('a[name=anterior]').attr('class','arrowlefton');
				} else {
					inibook = inibook - 1;
					$('a[name=proximo]').attr('class','arrowrightoff');
				}
			});
			$('a[name=anterior]').click( function() { 
				inibook--
				if(inibook >= 0) {
					$('#livrosarea').scrollTo($('div#livrosscroll div.livroitem:eq('+ inibook +')'), 200);
					$('a[name=proximo]').attr('class','arrowrighton');
					if (inibook == 0) {
						$('a[name=anterior]').attr('class','arrowleftoff');
					}
				} else {
					inibook = 0;
					$('a[name=anterior]').attr('class','arrowleftoff');
				}
			});
		}
		
		function selectaba(objctaba) {
			$('#fdiframe').attr('src','http://www.folhadirigida.com.br');
			if (!objctaba) {
				var abaselected = 0;
			} else {
				var abaselected = objctaba;
			}
			var maxabas = $('#mainabas').children('li').length;
			$('#mainabas').children('li a').click( function(i) {
				cleanaba();
				auxababckg = $(this).children('li a').attr('id');
				auxabaclass = $(this).children('li a').attr('id') + "on";
				$(this).children('li a').attr('class', auxabaclass);
				$('#mainabas').css({'backgroundImage':"url(imgs/abas_" + auxababckg + ".jpg)"});
			});
		}
		
		function cleanaba() {
			$('#mainabas').children('li a').each(function() {
				abaclass = $(this).children('li a').attr('id');
				$(this).children('li a').attr('class', abaclass);
			});
		}

		function run(nomeSWF, Width, Height, fxml) // tutorial by IVI CONCEPT - www.ivi-concept.com
		{

		    if (nomeSWF == '') {
		        return false;
		    } else {

		        var archivo = nomeSWF; // nombre de la pelicula swf que quieres incluir (incluir ruta si es necesario)
		        var ancho = Width; // ancho de la peli swf en píxeles o en porcentaje
		        var alto = Height; // alto de la peli swf en píxeles o en porcentaje
		        var version = "6,0,0,0"; // version del flash player
		        var quality = "high"; // calidad de visualización de la peli
		        var bgcolor = "#ffffff"; // color de fondo de la peli
		        var wmode = "transparent"; // color de fondo de la peli

		        document.write('<object type="application/x-shockwave-flash" data=' + archivo + ' width=' + ancho + ' height=' + alto + '>\n');
		        document.write('<param name="movie" value=' + archivo + ' />\n');
		        document.write('<param name="quality" value=' + quality + ' />\n');
		        document.write('<param name="bgcolor" value=' + bgcolor + ' />\n');
		        document.write('<param name="wmode" value=' + wmode + ' />\n');
		        document.write('<param name="FlashVars" value="fxmlopen=' + fxml + '" />\n');
		        document.write('</object>\n');
		    }
		}

		function fncOnFocusText(txtBox, textTxt) {
		    if ((txtBox.value != '') && (txtBox.value == textTxt)) {
		        txtBox.value = '';
		    }
		    else if (txtBox.value == ''){
		    txtBox.value = textTxt;
		    }	 	   
		  }
		  

		function fncExibeTodosComentarios(CodEspecial) {
		    var url = "../Ajax/aFdgVisualizarCometariosEspecial.aspx?pIntCodEspecial=" + CodEspecial + "&rnd=" + Math.random();
		    document.getElementById('divRetorno').style.height = "auto";
		    document.getElementById('divRetorno').innerHTML = '<div align=center style=\"height:100%;vertical-align:middle;"\><font face=Arial size=1>Carregando</font><br/><img src=../Imgs/icoLoad.gif></div>';
		    fncAjax(url, 'fncUpdateTodosComentarios');
		}


		function fncUpdateTodosComentarios() {
		    if (http_request.readyState == 4) {
		        //document.write (http_request.responseText);
		        if (http_request.status == 200) {
		            var pStrRetorno = http_request.responseText;
		            document.getElementById('divRetorno').style.height = "500px";
		            document.getElementById("divRetorno").innerHTML = pStrRetorno;
		            document.getElementById("divModalPopupSombra").style.top = self.document.body.scrollTop + 30;
		        } else {
		            alert('There was a problem with the request.');
		        }
		    }
		}

		function fncSegueScroll() {
		    if (document.getElementById("divModalPopupSombra").style.display == 'block') {
		        document.getElementById("divModalPopupSombra").style.top = document.body.scrollTop + 30;
		    }
		}

		function MM_openBrWindow(theURL, winName, features) { //v2.0
		    window.open(theURL, winName, features);
		}


		function NoneBlock(bitOveflow){
		    document.getElementById("divModalPopupSombra").style.display = 'block';
		    document.getElementById("bkgPopLayer").style.display = 'block';
		    document.getElementById("bkgPopLayer").style.height = document.body.scrollHeight + "px";
		    if (bitOveflow == 0) {
		        document.getElementById("divRetorno").style.overflow = "auto";
		    } else {
		        document.getElementById("divRetorno").style.overflow = "scroll";
		    }
		    opacity('divModalPopupSombra', 0, 100, 200);
		    document.getElementById("divModalPopupSombra").style.top = self.document.body.scrollTop + 30;		    
		}

		/*---------------------------------------- FUNCAO DE OPACITY-----------------------------------------------------*/
		function opacity(id, opacStart, opacEnd, millisec) {
		    var speed = Math.round(millisec / 100);
		    var timer = 0;

		    //Sumindo
		    if (opacStart > opacEnd) {
		        for (i = opacStart; i >= opacEnd; i--) {
		            setTimeout("changeOpac(" + i + ",'" + id + "', 1)", (timer * speed));
		            timer++;
		        }
		    } else if (opacStart < opacEnd) {
		        //Aparecendo
		        for (i = opacStart; i <= opacEnd; i++) {
		            setTimeout("changeOpac(" + i + ",'" + id + "', 0)", (timer * speed));
		            timer++;
		        }
		    }
		}

		function changeOpac(opacity, id, bitSumir) {
		    var object = document.getElementById(id).style;
		    object.opacity = (opacity / 100);
		    object.MozOpacity = (opacity / 100);
		    object.KhtmlOpacity = (opacity / 100);
		    object.filter = "alpha(opacity=" + opacity + ")";
		    if (opacity == 0 && bitSumir == 1) {
		        object.display = "none";
		    }
		}
		/*-------------------------------------------------------------------------------------------------------------*/

		function fechar() {
		    opacity('divModalPopupSombra', 100, 0, 200);
		    document.getElementById('bkgPopLayer').style.display = 'none';
		}

		function fncExibeFormDenuncieComent(CodComentario, CodUsuario) {
		    var url = "../Ajax/aFdgFormDenuncieComentarioEspecial.aspx?CodComentario=" + CodComentario + "&CodUsuario=" + CodUsuario + "&rnd=" + Math.random();
		    parent.document.getElementById('divRetorno').style.height = "auto";
		    parent.document.getElementById('divRetorno').innerHTML = '<div align=center style=\"height:100%;vertical-align:middle;"\><font face=Arial size=1>Carregando</font><br/><img src=../Imgs/icoLoad.gif></div>';
		    fncAjax(url, 'fncUpdateExibeFormDenuncieComent');
		}

		function fncUpdateExibeFormDenuncieComent() {
		    //document.write (http_request.responseText);
		    if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		            var pStrRetorno = http_request.responseText;
		            parent.document.getElementById('divRetorno').style.height = "500px";
		            parent.document.getElementById("divRetorno").innerHTML = pStrRetorno;
		            parent.document.getElementById("divModalPopupSombra").style.top = self.document.body.scrollTop + 30;
		        } else {
		            alert('There was a problem with the request.');
		        }
		    }
		}


		var limite = 1000;
		var txtValue = "";
		function fncContaCaracter() {
		    if (parent.document.getElementById('txtComentDenuncie').value.length <= 1000) {
		        parent.document.getElementById('caracteres').value = document.getElementById('txtComentDenuncie').value.length;
		        txtValue = parent.document.getElementById('txtComentDenuncie').value;
		    } else {
		        parent.document.getElementById('txtComentDenuncie').value = txtValue;
		        return false;
		    }
		}


		function fncEnviaDenunciaComentario(CodComentConteudo, CodUsuario) {
		    //var CodUsuario = document.getElementById('CodUsuarioDenunciante').value
		    var txtDenuncia = document.getElementById('txtComentDenuncie').value;
		    var txtMotivoDenuncia = document.getElementById('txtComentDenuncie')
		    if (txtMotivoDenuncia.value.length == 0) {
		        alert('Por favor, digite o motivo de sua den&uacute;ncia!');
		        txtMotivoDenuncia.focus();
		        //return false;
		    }
		    else {

		        var url = "../Ajax/aFdgProcDenunciaComentarioEspecial.aspx?CodUsuarioDenunciante=" + CodUsuario + "&CodConteudo=" + CodComentConteudo + "&txtDenuncia=" + txtDenuncia + "&rnd=" + Math.random();
		        document.getElementById('divRetorno').style.height = "auto";
		        document.getElementById('divRetorno').innerHTML = '<div align=center style=\"height:100%;vertical-align:middle;"\><font face=Arial size=1>Carregando</font><br/><img src=../imgs/icoLoad.gif></div>';
		        fncAjax(url, 'fncUpdateDenunciaComentario');
		    }  
		}

		function fncUpdateDenunciaComentario() {
		    if (http_request.readyState == 4) {
		        //document.write (http_request.responseText);
		        if (http_request.status == 200) {
		            var pStrRetorno = http_request.responseText;
		            parent.document.getElementById("divRetorno").innerHTML = pStrRetorno;
		        } else {
		            alert('There was a problem with the request.');
		        }
		    }
		}

		// função para verificar a altura do documento e ajusta o iframe para a mesma altura
		function checkHeight(nomeDoIframe) {
		    if (document.getElementById) {
		        parent.document.getElementById(nomeDoIframe).height = document.body.scrollHeight;
		    }
		    else {
		        parent.document.all(nomeDoIframe).height = document.body.scrollHeight;
		    }
		}
		function fncGerarChave() {
		    var url = "FdgRedirecionaLink.aspx?pStrPaginaSeguinte=../Ajax/aFdgGeraChaveAcessoPrv.asp?rnd=" + Math.random();
		    fncAjax(url, 'fncRetornoGerarChave');
		    //document.write (url);
		}

		function fncRetornoGerarChave() {		   
		    if (http_request.readyState == 4) {
		        if (http_request.status == 200) {
		            var pStrRetorno = http_request.responseText;		            
		            window.open('http://www.provasdirigidas.com.br?pStrExKey=' + pStrRetorno, 'Provas');
		            //document.getElementById("areaPrv").href = 'http://www.provasdirigidas.com.br?pStrExKey=' + pStrRetorno
		        } else {
		            //alert('show perereca!');
		            window.open('http://www.provasdirigidas.com.br', 'Provas');
		            //document.getElementById("areaPrv").href = 'http://www.provasdirigidas.com.br'
		        }
		    }
		}