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+',noresizable'
win = window.open(mypage,myname,settings)
}

function closeTip() {
		document.getElementById('showTip').style.display = 'none';
		document.getElementById('showTipTitle').style.display = 'none';	
}


function checar()
	{
		erro = true;
	
		if (document.enviar.remetente.value.length < 3)		
		{
		
			window.alert('Digite seu nome');
			erro = false;
			return erro;
		
		}

		if (document.enviar.meuemail.value.length < 10)		
		{
		
			window.alert('Digite seu e-mail');
			erro = false;
			return erro;
			
		}

		if (document.enviar.seunome.value.length < 3)		
		{
		
			window.alert('Digite o nome do destinatário');
			erro = false;
			return erro;
		
		}

		if (document.enviar.seuemail.value.length < 10)		
		{
		
			window.alert('Digite o email do destinatário');
			erro = false;
			return erro;
		
		}

		
	
	}
	
	
	function cleanFields(myid) {
			  
	  	document.getElementById(myid).value = '';
	  	document.getElementById(myid).style.color = '#000';
	  	if(myid == 'pass') {
	  		//document.getElementById('pass').type = 'password';
	  		document.getElementById('pass').style.backgroundImage = 'url(/view/images/naoexiste.gif)';
	  	}
	  	document.getElementById('msgbox').style.display = 'none';
	  	
	  
	  }

	  function setFields(myid, ini) {
	  
	  	if(document.getElementById(myid).value == "") {
	  	
	  		//document.getElementById(myid).type = 'textfield';
	  		if(myid == 'pass') {
	  			document.getElementById(myid).style.backgroundImage = 'url(/view/images/senha.png)';
	  		}
	  		document.getElementById(myid).value = ini; 
	  		document.getElementById(myid).style.color = '#999999';
	  	
	  	}
	  
	  }
	  
	  function setCookie(c_name,value,expiredays)
		{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
		
		}
	  
	  function hideWarning() {
			
				document.getElementById('msgbox').style.display = 'none';
			
			
	  }
	  
	  function Delete_Cookie() {
		document.cookie = 'userff =; expires=Thu, 01-Jan-70 00:00:01 GMT;';
		document.location="/control/rule/ProcLogins.class.php?action=logoutUser";
		}
	  
	  
	   $().ready(function() {
				 
				$('#ex2').jqm({ajax: '/login/cadastramento.html', trigger: 'a.cadastro',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex3').jqm({ajax:'@href', trigger: 'a.email',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex4').jqm({ajax:'@href', trigger: 'a.addfrases',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex5').jqm({ajax:'@href', trigger: 'a.addautor',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex6').jqm({ajax:'@href', trigger: 'a.twitter',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex7').jqm({ajax:'@href', trigger: 'a.profile',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex8').jqm({ajax:'@href', trigger: 'a.comment_users',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex9').jqm({ajax:'@href', trigger: 'a.denfrase',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex10').jqm({ajax:'@href', trigger: 'a.denusuario',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex11').jqm({ajax:'@href', trigger: 'a.favusuarios',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex12').jqm({ajax:'@href', trigger: 'a.upload',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex13').jqm({ajax:'@href', trigger: 'a.contact',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#ex14').jqm({ajax:'@href', trigger: 'a.upload_author',ajaxText: '<strong style="color:#3f2d04;font-size:12px;">CARREGANDO...</strong>'});
				$('#forgot').jqm();
				
				  
			  });
			  
			  $(document).ready(function()
{
			  
			  $("#login_form").submit(function()
				{
				        //remove all the class add the messagebox classes and start fading
				        $("#msgbox").removeClass().addClass('messagebox').text('Verificando.....').fadeIn(1000);
				        //check the username exists or not from ajax
				        $.post("/control/rule/ProcLogins.class.php?action=loginUser",{ user_name:$('#login').val(),password:$('#pass').val(),rand:Math.random() } ,function(data)
				        {
				          if(data=='false')
				          {
				                $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				                {
				                  //add message and change the class of the box and start fading
				                  $(this).html('Login ou senha inv&aacute;lido...').addClass('messageboxerror').fadeTo(900,1);
				                });
				          }
				          else if(data=='confirmar')
				          {
				          		$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
				                {
				                  //add message and change the class of the box and start fading
				                  $(this).html('Confirme seu cadastro no e-mail.').addClass('messageboxerror').fadeTo(900,1);
				                });
				          
				          }
				          
				          else //if correct login detail
				          {
				                $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
				                {
				                  //add message and change the class of the box and start fading
				                  $(this).html('Logando.....').addClass('messageboxok').fadeTo(900,1,
				                  function()
				                  {
				                     //redirect to secure page
				                     setCookie('userff',data,'30');
				                     document.location='/userAreas/'+data+'/home.html';
				                  });
				                });
				          }
				          
				       });
				       return false;//not to post the  form physically
				});
			  	
			  	
			  	$("#aut_pass").blur(function()
				{
				        $("#login_form").trigger('submit');
				});


				

});



$(document).ready(function()
{

	$("#buttonForgot").click(function()
	{
		$("#msgbox_forgot").removeClass().addClass('messagebox').text('Verificando.....').fadeIn(1000);
	
		$.post("/control/rule/ProcLogins.class.php?action=mailMyPass",{ myemail:$('#myemail').val(),rand:Math.random() } ,function(data2)
		{
			  if(data2=='true') 
	          {
	                $("#msgbox_forgot").fadeTo(200,0.1,function()  
	                {
	                  
	                  $(this).html('Mensagem enviada com sucesso.').addClass('messageboxok').fadeTo(900,1);
	                  
	                });
	          }
	          else if(data2 == 'confirmar')
	          {
	          		$("#msgbox_forgot").fadeTo(200,0.1,function() 
	                {
	                  $(this).html('Confirme seu cadastro no e-mail.').addClass('messageboxerror').fadeTo(900,1);
	                });
	          
	          }
	          else if(data2 == 'erro')
	          {
	          		$("#msgbox_forgot").fadeTo(200,0.1,function() 
	                {
	                  $(this).html('Erro no envio. Tente mais tarde.').addClass('messageboxerror').fadeTo(900,1);
	                });
	          
	          }
	          else
	          {
	                $("#msgbox_forgot").fadeTo(200,0.1,function() 
	                {
	                 $(this).html('E-mail inexistente.').addClass('messageboxerror').fadeTo(900,1);
	                });
	          }
		});		
		return false;
	
	});


				$("#myemail").blur(function()
				{
				        $("#buttonForgot").trigger('click');
				});

});



// slowEach() plugin by "Michael Geary"
// http://groups.google.com/group/jquery-en/browse_thread/thread/1790787be89b92bc/876c4ba8f01d8443#msg_72c18cfa10b7d7b6
// callback2 - fired after last element, can be used to build functions chain (added by Orkan)
jQuery.fn.slowEach = function(interval, callback, callback2) {
	var items = this, i = 0;
	if(!items.length) return;
	function next() {
		(callback.call(items[i], i, items[i]) !== false && ++i < items.length) ? setTimeout(next, interval) : callback2 && callback2.call(items, i, items);
	}
	next();
};

$(document).ready(function()
{
	
	$(".rat").children().not(":radio").hide();
	
	
	// Create stars
	$(".rat").stars({
		callback: function(ui, type, value)
		{
			var arr = ui.$stars.find("a");
			
			
			arr.slowEach(100, 
				function(){ $(this).animate({top: "28px"}, 300)},
				function()
				{
					var rid = value.split("_")[1];
					var myvalue = value.split("_")[0];
					$("#loader_"+rid).fadeIn(function()
					//$("[id^=rat_]").children("[class^=star_]").click(function()
					{
						
						$.post("/config/proccess.php", {rate: value,fra_id: rid, hsum:$('#hsum_'+rid).val(), hvotes:$('#hvotes_'+rid).val()}, function(db)
						{
							//var fraseid = '11396';
							//
							ui.select(Math.round(db.avg));
							$("#avg_"+rid).text(db.avg);
							$("#votes_"+rid).text(db.votes);
							$("#havg_"+rid).text(db.avg);
							$("#hsum_"+rid).text(db.sum);
							//$("#rvotes_"+rid).text(db.votes);
							//$("#ravg_"+rid).text(db.avg);
							//$("#rsum_"+rid).text(db.sum);
							//$("#frase_"+rid).text(db.frase);
							
							

							$("#loader_"+rid).fadeOut(function(){ 
								arr.slowEach(100, function(){ $(this).animate({top: 0}, 300) });
							});

						}, "json");
					});
					//});
				});
		},
		oneVoteOnly: true
	});
});



	$(document).ready(function() {
          
           $("[id^=question_]").click(function() {
                   var uid = $(this).attr('id').split("_")[1];
                   $("[id^=answer_]").fadeOut("slow");
                   
                   if($("ul#answer_"+uid).is(":hidden")){
                   		$("ul#answer_"+uid).fadeIn("slow");
                   }
           });
           
          
   });



function cleanMessage() {
	document.getElementById('addfrase_ok').innerHTML="";	
}

function closeFollowCad(){
	document.getElementById('followCad').style.display = 'none';
}
		
