// JavaScript Document

	// gets how much the document was scrolled at X
	function getScrollX() {
		var v = getScrollXY();
		return v[0];
	}
	// gets how much the document was scrolled at Y
	function getScrollY() {
		var v = getScrollXY();
		return v[1];
	}
	// gets how much the document was scrolled at [X,Y]
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		 //Netscape compliant
		 scrOfY = window.pageYOffset;
		 scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		 //DOM compliant
		 scrOfY = document.body.scrollTop;
		 scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		 //IE6 standards compliant mode
		 scrOfY = document.documentElement.scrollTop;
		 scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}

	function LinkAction(obj, over) {
		if (over == true) {
			obj.style.textDecoration = 'underline';	
		} else {
			obj.style.textDecoration = 'none';
		}
	}
	
	

		var WindowOpen = function (path) {
			this.rect = function() {
			
			}
		
			this.window_name++;

			this.rect.left = 0;
			this.rect.top = 0;
			this.rect.width = 150;
			this.rect.height = 150;
			this.rect.screenwidth = 760;
			this.rect.screenheight = 520;
			
			if (typeof screen.width !== 'undefined') {
				this.rect.screenwidth = screen.width;
				this.rect.screenheight = screen.height;
			}
			
			this.rect.left = (this.rect.screenwidth / 2) - (this.rect.width / 2);
			this.rect.top = (this.rect.screenheight / 2) - (this.rect.height / 2);
			
			this.rect.w = window.open('', 'OpenCentralized'+this.window_name, 'left=' + this.rect.left + ',top=' + this.rect.top + ',width=' + this.rect.width + ',height=' + this.rect.height +'');
			this.rect.w.document.write('<html><head><title></title></head><body style="margin:0px"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td valign="middle" align="center"><div id="aguarde" style="font-family: Verdana; font-size: 12px; color: #660000;">Por favor, aguarde.. <br><br></div><img src="' + path + '" id="img" style="visibility: hidden; position: absolute;"><div style="height: 5px; overflow: hidden;"></div><a onClick="window.close();" style="cursor: pointer;"><font face="Verdana" style="font-size: 11px;">FECHAR</font></a></td></tr></table></body></html>');
			this.rect.w.document.close();
			
			this.rect.interval = setInterval(CheckFinish, 500);
			
			function CheckFinish() {
				try {
					this.obj = this.rect.w.document.getElementById('img');
					this.aguarde = this.rect.w.document.getElementById('aguarde');
					if (this.obj && this.aguarde) {
						if (this.obj.width > 0) {
							this.aguarde.style.display = "none";
							this.obj.style.visibility = "visible";
							this.obj.style.position = "";
							clearInterval(this.rect.interval);
							
							this.diffX = 30;
							this.diffY = 75+30;
							
							this.rect.left = (this.rect.screenwidth / 2) - ((this.obj.width+this.diffX) / 2);
							this.rect.top = (this.rect.screenheight / 2) - ((this.obj.height+this.diffY) / 2);
							
							this.rect.w.window.moveTo(this.rect.left, this.rect.top);
							this.rect.w.window.resizeTo(this.obj.width+this.diffX, this.obj.height+this.diffY);
						}
					} 
				} catch(e) {
					clearInterval(this.rect.interval);				
				}
			}
		}
		
		

		/* Begin - Rating Implementation */
		
					var RatinghandleSuccess = function(o){
						if (o.responseText !== undefined) {
							if (o.argument.modo == "changeRating") {
								var hp = document.getElementById(o.argument.objname);
								if (hp) {
									if (typeof hp.filters !== 'undefined')
										hp.filters[0].Apply(); 
									hp.innerHTML = o.responseText;
									if (typeof hp.filters !== 'undefined')
										hp.filters[0].Play(); 
								}
								
								if (o.responseText.search('<!--jaexiste-->') != -1) {
									alert('Conteúdo já avaliado, por favor escolha outro.');	
								}

								RatingFadeOut(o.argument.objname, 0);
							}
							
						}
					}
						
					var RatinghandleFailure = function (o) {
						
					}
					
					var RatingFadeIngStop = false;
					function RatingFadeIn(objname, opacity) {
						if (opacity == 100) {
							RatingFadeIngStop = false;
						}
						
						if (RatingFadeIngStop == true) return;
						
						this.obj = document.getElementById(objname);
						opacity = opacity - 10;
						if (this.obj) {
							if (typeof this.obj.style.MozOpacity !== 'undefined') {
								this.obj.style.MozOpacity = (opacity/100);
							} else {
								if (typeof this.obj.filters !== 'undefined')
									this.obj.filters[0].Apply(); 
								this.obj.innerHTML = '';

								if (typeof this.obj.filters !== 'undefined')
									this.obj.filters[0].Play(); 
								opacity = 0;
							}							
							if (opacity > 0) {
								setTimeout("RatingFadeIn('"+objname+"', "+opacity+")", 50);
							}
						}											
					}
					
					function RatingFadeOut(objname, opacity) {
						RatingFadeIngStop = true;
						this.obj = document.getElementById(objname);
						opacity = opacity + 10;
						if (this.obj) {
							if (typeof this.obj.style.MozOpacity !== 'undefined') {
								this.obj.style.MozOpacity = (opacity/100);
								if (opacity < 100) {
									setTimeout("RatingFadeOut('"+objname+"', "+opacity+")", 50);
								}
							} 						
						}											
					}				
					
					function OnRatingClick(id, number, codConteudo) {
					
						RatingFadeIn(id, 100);

						this.callback = 
						{
						  success: RatinghandleSuccess,
						  failure: RatinghandleFailure,
						  argument: { modo: "changeRating", objname: id }
						};
						
						this.sUrl = "ajax/avaliacao_contabilizar.asp?codConteudo="+codConteudo+"&avaliacao="+number+'&id='+id;
						this.request = YAHOO.util.Connect.asyncRequest('GET', this.sUrl, this.callback);
					
					}
				 
					function RatingObj(nameobj) {
						return document.getElementById(nameobj);
					}
				 	function OnRatingOver(nameobj, number) {
						for (i = 1; i <= number; i++) {
							this.obj = RatingObj(nameobj+'_'+i);
							if (typeof this.obj.saveClass == 'undefined') {
								this.obj.saveClass = this.obj.className;
							}
							this.obj.className = 'ratingOver';
						}
						for (i = number+1; i <= 5; i++) {
							this.obj = RatingObj(nameobj+'_'+i);
							if (typeof this.obj.saveClass == 'undefined') {
								this.obj.saveClass = this.obj.className;
							}
							this.obj.className = this.obj.saveClass;
						}
						
					}
					function OnRatingOut(nameobj, number) {
						for (i = 1; i <= 5; i++) {
							this.obj = RatingObj(nameobj+'_'+i);
							this.obj.className = this.obj.saveClass;
						}
					}
		/* End - Rating Implementation */



	
	/* Begin Class for comments */
	function ComentarioClass() {
		this.maxvalue = 800;
		this.str_maxcharreached = 'O número máximo de caracteres foi atingido.';
		this.str_maxcharnumber = 'O número máximo de caracteres permitido é '+this.maxvalue+'. Por favor, corrija sua mensagem.';
		this.str_mustbelogged = 'É necessário estar logado para comentar.';
		this.str_digitecomentario = 'É necessário digitar um comentário.';
	
		this.contarCaracteres = function () {
			this.charobj = document.getElementById('strNumChars');
			this.obj = document.getElementById('strComentario');			
			if (this.obj.value.length > this.maxvalue) {
				this.obj.value = this.obj.value.substr(0, 800);
				alert(this.str_maxcharreached);
			}
			this.charobj.value = this.maxvalue-this.obj.value.length;
		}

		this.verificarFormulario = function (codUsua) {
			this.obj = document.getElementById('strComentario');
			if (this.obj.value.length > this.maxvalue) {
				alert(this.str_maxcharnumber);
				this.obj.focus();
				return false;
			}
			
			if (this.obj.value.length <= 1) {
				alert(this.str_digitecomentario);
				this.obj.focus();
				return false;
			}
			
			if (codUsua == '') {
				alert(this.str_mustbelogged);
				return false;
			}
			
			return true;
		}
		
		this.verificarLogin = function (codUsua) {			
			if (codUsua == '') {
				this.obj = document.getElementById('naoregistrado');
				if (this.obj) {
					this.obj.style.visibility = 'visible';
				}
			}
		}
		
		this.fecharAvisoLogin = function () {
			this.obj = document.getElementById('naoregistrado');
			if (this.obj) {
				this.obj.style.visibility = 'hidden';
			}
		}		

	}
	var comentario = new ComentarioClass();
	/* End Class for comments */