/* registry check input fields*/
$('#reg_form').submit(function() {
	var tmp=0;
		$('#reg_form input').each(function (){
			//alert($(this).val());
			if($(this).val()==''){
				$(this).css('border','1px solid red');
				tmp=1;
			}
		});
	tmp2=$('#reg_form input:checkbox').attr('checked'); // el van e fogadva a terms and conds

	if((tmp == 0) && tmp2){return true;} 
	else {return false;}
});

$('#reg_form input').focus(function (){
	$(this).css('border','1px solid #e7e6e6');
});

/*----------------------------*/

/* register click*/

	$('#register_span').click(function(){
		$('#forum_main').hide();
		$('#forum_register').show();
		$('#login_popup').hide();
		$('#forgot_pass_popup').hide();
		$('#forum_header_title').text('forum registration');
	});
	
	$('#login_span').click(function(){
		$('#popup_background').show();
		$('#login_popup').show();
	});
	
	$('#pass_span').click(function(){
		$('#popup_background').show();
		$('#modpass_popup').show();
	});
	

/*----------------------------*/

/* forgot btn click*/
$('#forgot_pass').click(function(){
	$('#popup_background').show();
	$('#forgot_pass_popup').show();
});

$('#forgot_pass_btn').click(function(){
	email = $('#login_email').val();
	$.ajax({
	   type: "POST",
	   url: "../index.php?node=forum",
	   data: "email="+email+"&cmd=forgot_pass",
	   success: function(msg){
		   		$('#login_error_text_email').text(msg);  
	   }
	 });
});

/*-----------------*/

/* MODIFY PASSWORD */

$('#modpass_btn').click(function(){
	old = $('#modpass_oldpass').val();
	pass = $('#modpass_pass').val();
	pass2 =$('#modpass_pass2').val(); 

	$.ajax({
	   type: "POST",
	   url: "../index.php?node=forum",
	   data: "oldpass="+old+"&pass="+pass+"&pass2="+pass2+"&cmd=mod_pass",
	   success: function(msg){
	   		if(msg=='error') $('#modpass_error_text').text("Error! please check fields' data");  
	   		else $('#modpass_popup').hide();
	   }
	 });
});
	

/*-----------------*/

/* hide popups*/
 
$('#popup_background').click(function(){
	$('#login_popup').hide();
	$('#modpass_popup').hide();
	$('#forgot_pass_popup').hide();
	$('#create_topic_popup').hide();
	$('#popup_background').hide();
	
})

/*---------------------------*/

/*login*/

$('#login_btn').click(function(){
	uname = $('#login_username').val();
	pass =  $('#login_userpass').val(); 
	$.ajax({
	   type: "POST",
	   url: "./index.php?node=forum",
	   data: "username="+uname+"&password="+pass+"&cmd=login",
	   success: function(msg){
		   if(msg=='OK'){
		   		document.location="./index.php?node=forum";
		   } else{
		 		$('#login_error_text').text(msg);  
		   }
	     
	   }
	 });
});

$('#logout_span').click(function (){
	$.ajax({
	   type: "POST",
	   url: "./index.php?node=forum",
	   data: "cmd=logout",
	   success: function(msg){
		   		document.location="./index.php?node=forum";
	   }
	 });
});



/*-----*/

/* create topic popoup */

$('#create_topic_text').click(function(){
	$('#popup_background').show();
	$('#create_topic_popup').show();
});
/* ------------ */


/* create topic */

$('#create_topic_btn').click(function(){
	if($('#topic_title').val().length>3){
		cat_id=$('#create_topic_cat_id').val();
		$.ajax({
				   type: "POST",
				   url: "./index.php?node=forum",
				   data: "cat_id="+cat_id+"&cmd=add_topic&desc="+$('#topic_comment').val()+"&topic_title="+$('#topic_title').val(),
				   success: function(html){
							document.location="./index.php?node=forum&cmd=list_topics&cat_id="+cat_id+"&ct=1";
					} // success
				 });//ajax
	} else {
		$('#login_error_text_create_topic').text('Legalább 4 karakter szükséges!');
	}
});
/*------*/





/**/

/* leave a comment*/
$('#submit_comment').click(function(){
	if($('#comment_input').val().length>2){
		topic_id=$('#h_topicid').val();
		cat_id=$('#h_catid').val();
		reply="";
		reply_msg='<pre><i><font color=gray>'+$("#reply_tmp").val()+'</font></i></pre>';
		reply_to=$('#reply_to_tmp').val();
		if($('#reply_to_tmp').val()!=""){
			reply="&reply_to="+reply_to+"&reply_msg="+reply_msg;
		}
		
		$.ajax({
		   type: "POST",
		   url: "./index.php?node=forum",
		   data: "cat_id="+cat_id+"&topic_id="+topic_id+"&cmd=add_comment&message="+$('#comment_input').val()+"&row_num="+$('#forum_comment_list_main table').length+""+reply,
		   success: function(html){
					
					document.location="./index.php?node=forum&cmd=list_comments&topic_id="+topic_id+"&cat_id="+cat_id+"&lc=1";
/*					$('#forum_comment_list_main').append(html);
					$('#comment_input').val('');
					
					$('#reply_tmp').val('');
					$('#reply_to_tmp').val('');
				
					$('#leave_comment_text').html('Leave a comment');*/
					
					
			} // success
		 });//ajax
	} else{
		alert('minimum 3 karakter szükséges!');
	}// if
 });
 
 
 $('#create_comment_text').click(function(){
 	$('#comment_input').focus();
 });
/*-----*/

/* -replay- */

$('.forum_comment_one_row_reply').click(function(){
	id=$(this).attr('id');
	reply_msg=$('#msg_'+id).html();
	reply_to=$(this).parent().find('.forum_comment_one_row_username').text();
	
	$('#reply_tmp').val(reply_msg);
	$('#reply_to_tmp').val(reply_to);
	//alert(reply_msg);
	
	$('#leave_comment_text').html('Leave a comment to <span style="color:#d98315;text-transform:lowercase;">@'+reply_to);
	$('#comment_input').focus();
	
	
	
});

/* ---------*/

/* clock */
function setClock(){
	var currentTime = new Date()
	var hour = currentTime.getHours();
	var min = currentTime.getMinutes();
	var sec = currentTime.getSeconds();
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	$('#forum_header_date').text(month + "/" + day + "/" + year + " "+hour+":"+min+":"+sec);
}


/*--------*/
