// JavaScript Document

$(document).ready(function() {
	var sendAjaxDelay = undefined;
	
	 /*********For side Login Forum************/
	
	$('form[name="sideforumLogin"]').submit(function() {													 
		//alert('test');		
		var fEmail = $('#sideforumUser').val();
		var fPassword = $('#sideforumPassword').val();		
		var errMsg ='';		
		if(fEmail.length == 0) {
			$('#sideforumUser').addClass('error');
			errMsg = 'There is an error';
		}
		
		if(fPassword.length == 0) {
			$('#sideforumPassword').addClass('error');
			errMsg = 'There is an error';			
		}	
		
		if(errMsg.length == 0 ) {
			var HTML = '<img src="images/icons/ajax-loader.gif" id="sendLoadingGIF" style="padding-left:10px;" />';
			$('#LoginBtnSide').hide();			
			if (sendAjaxDelay !== undefined){
				clearTimeout(sendAjaxDelay);
			}					
			$('#sideSendLoading').append(HTML);			
			  
			   sendAjaxDelay = setTimeout(function() {	
				   $.ajax({
				   type: "POST",
				   url: "forum-login-ajax.asp",
				   data: ({	'userId' :  fEmail ,
							'password' : fPassword,
							'ajaxapp' : 'forumLogin'												
						}),
				   beforeSend: function() {				   			
												
							},
					success: function(r) {	
							if (r.substring(0,1) == 'T') {
								$('#sideforumLogin').hide();								
								if($('.loginBoxOverlay').length > 0) {
									  $('.loginBoxOverlay').hide();
									}
								var NickName = '';
								NickName = r.substring(5);
								if($('#commentName').length > 0 ) {									
									$('#commentName').text(NickName);
								}
								
								var HTML = '<div id="sideforumLogin"><div id="Nickname">' +  NickName + '</div><a href="forum-logout.asp" id="forumLogout">Log Out</a><a href="/forum-registration.asp">Edit your detail</a></div>';	
								$('#forumSection').empty();
								$('#forumSection').html(HTML);
							}
							else {
								$('#sideSendLoading').empty();
								$('#LoginBtnSide').show();								
							}											
					}	   
				  
				 });
				   }, 1000);	
						
			//return of if ErrMsg   
		}			
			
		return false;
													   
	});		   
						   
				   
						   
});
