site_url = 'http://blog.ascentive.com/';
//site_url = 'http://localhost/blog/phpbb/';
	Register = {
	
			validate : function (field) {
						   
						   switch (field) {
							case 'username' :   user_name = $("#username_reg").val();
												$.post('ucp.php?mode=validate',{username:user_name},
														function (data) {
														 Register.show_message(data.msg,data.error,$("#username_reg_error")); 
														},'json'
													);
												break;
							 case 'email' :     email_id = $("#email").val();
												$.post('ucp.php?mode=validate',{email:email_id},
														function (data) {
														 Register.show_message(data.msg,data.error,$("#email_error")); 
														},'json'
													);
												break; 
							case 'new_password' :  password =  $("#new_password").val().trim(); 
											   if(password.length < 4) {
												  Register.show_message('Password must contain atleast 4 letters',1,$("#new_password_error")); 
											   } else {
												  $("#new_password_error").html('');
											   }	
											   break;
																					
						   
						   }    
						},
		validate_all : function () {  
							user_name =   $("#username_reg").val().trim();
							email_id = $("#email").val().trim();
							confirm_email = $("#email_confirm").val().trim();
							password  = $("#new_password").val().trim();
							confirm_password  = $("#password_confirm").val().trim();
							fname =  $("#first_name").val().trim(); 
							lname =  $("#last_name").val().trim(); 
							
							if(user_name == '') {
								this.show_message('User Name can not be Empty',1);
								return false;
							} else if(!/[a-zA-z0-9_!@#\$]{3,20}/.test(user_name)) {
								this.show_message('Invalid Username',1);
								return false;
							}
							
							if(email_id == '') {
								this.show_message('Email can not be Empty',1);
								return false;
							} else if(!/^(.+)@(.+)\.(.+)$/.test(email_id)) {
								this.show_message('Invalid Email Address',1);
								return false;
							}
							
							if(email_id != confirm_email) {
								this.show_message('Emails are not matching',1);
								return false;
							}
							
							if(password == '') {
								this.show_message('Password can not be Empty',1);
								return false;
							} else if(!/[a-zA-z0-9_!@#\$]{6,100}/.test(password)) {
								this.show_message('Invalid Password',1);
								return false;
							}
							
							if(password != confirm_password) {
								this.show_message('Passwords are not matching',1);
								return false;
							}
							
							if(fname == '') {
								this.show_message('First Name can not be Empty',1);
								return false;
							}
							
							if(lname == '') {
								this.show_message('Last Name can not be Empty',1);
								return false;
							}
							
						   
							
							return true; 
							 
							
						},
		show_message : function (data,type,field) {
					   if(field == undefined) {  
						  $("#erro_cont").html(data);
						  $("#erro_cont").fadeIn('slow');
					   } else {
						
						if(type == 1) {
						
							field.html(data);
						  }  else {
						   field.html('');
						   //	field.append(data); 
						  }
                          field.fadeIn('slow');
						/*alert(field.attr('id'));
							$('testing').appendTo(field); 
						 */ 
						
						}
		} 
	}                      
	
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}
	String.prototype.ltrim = function() {
		return this.replace(/^\s+/,"");
	}
	String.prototype.rtrim = function() {
		return this.replace(/\s+$/,"");
	}
	
	
Avatar = {
	show_form : function () {
	
				} ,
	upload    : function () {
			
	}
}

	function ajaxFileUpload()
	{
/*        $("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});*/
 
		$.ajaxFileUpload
		(
			{
				url:'ucp.php?mode=upload',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				beforeSend:function()
				{
					$("#foto_area").html('loading...');
					$("#loading").show();
				},
				complete:function()
				{
					$("#loading").hide();
				},                
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error == 1)
						{
						   $("#foto_msg").addClass('foto_error');	
						   $("#foto_msg").html(data.msg);
						}else
						{   $("#foto_msg").html(data.msg);
							$("#foto").hide();    
							$("#foto").html('<img src="'+site_url+'images/avatars/upload/'+data.filename+'" width="150">');
							$("#foto").fadeIn('slow').delay(15000,function() {location.reload()});	
						  // $.delay(2000,function() {localtion.reload()})
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		);
		
		return false;
 
	}
	
ForumPosts = {
	post_count : 0, 
	recent_posts : function () {// alert('hai');
					post_cnt = $("#post_count").val();
					total_cnt = $("#total_count").val();
					
					/*  $.post(site_url+'ucp.php?mode=latest_posts',{topic_count:this.post_count},function (data) {
															alert('hello');
														},'json');*/
					$("#latest_forum_posts").fadeOut('slow');
					 $("#latest_forum_posts").load(site_url+'ucp.php?mode=latest_posts&c='+post_cnt+'&t='+total_cnt);
				  /*	$.post(site_url+'ucp.php?mode=latest_posts&c='+post_cnt+'&t='+total_cnt,{},function(data) {
									
									//for(i)
									html = '';
								   $.each(data,function(i,post) {
									  html += '<p><a href="'+data[i].topic_url+'"> '+data[i].post_text+'</a><br>'+data[i].post_time+' '+data[i].post_user +' | '+data[i].replies+' replies </p>';
										
									});
									$("#post_count").val(data[1].post_count);
									$("#total_count").val(data[1].total_count); 
									
									$("#latest_forum_posts").html(html);
									
									},'json');
					  
					 $("#latest_forum_posts").slideDown('slow');  
					}*/
					$("#latest_forum_posts").fadeIn('slow'); 
				  
					}

}
Review = {
	validate_add : function () {
	
		 req_fields = [
						'address--Please enter your Address',
						'city--Please enter your City',
						'state--Please enter your State',
						'comments--Please add your Comments'	 
					   ] ;
		 if(Form.validate(req_fields)) {
			 return true;
		 }
		 return false;
	}

}

Form = {

	validate : function (req_data){   
				  req_fields_length = req_data.length;
				  for(i=0;i<req_data.length;i++) {
					 fields = req_data[i].split('--');
					 fields_length = fields.length;
					 $("#"+fields[0]).focus();  
					 field_val = $("#"+fields[0]).val().trim();
					 if(field_val == '') {
						Message.show(fields[1],1);
						return false
					 } else if(fields_length == 3) {
						if(fields[2] == 'email' && (!/^(.+)@(.+)\.(.+)$/.test(field_val))) {
							Message.show('Invalid Email Address',1);
							
							return false;
						}
						
						}
						   
					 }
					 return true;
			}
		  
}

Message  = {
	show : function(data,type,field) {
						if(type == 1) {
							$(".error").html(data);
							$(".error_cont").fadeIn('slow');
							
						   //    field.append(data);
						  }  else {
							$(".error").html(data);
							$(".erro_cont").fadeIn('slow');
						   //    field.append(data); 
						  }
						/*alert(field.attr('id'));
							$('testing').appendTo(field); 
						 */ 
						
						} 

}

Edit = {
	


}
$(document).ready (function(){
	$("#avatar").hide();
	$("#acct_area").hide();    
	$("#acct").bind('click',function () {
					if($("#acct_area").is(":visible")) {
						   $("#acct_area").slideUp('slow'); 
						   $("#avatar").slideDown('slow'); 
					} else {
						   $("#avatar").slideUp('slow'); 
						   $("#acct_area").slideDown('slow'); 
					}
				
				
				});
	$("#avt").bind('click',function () {
				   if($("#avatar").is(":visible")) {
						   $("#acct_area").slideDown('slow'); 
						   $("#avatar").slideUp('slow'); 
					} else {
						   $("#avatar").slideDown('slow'); 
						   $("#acct_area").slideUp('slow'); 
					}
				
				});
	
});

//ForumPosts.recent_posts();	
   setInterval("ForumPosts.recent_posts()",30000);
