function sendMail(){

new Ajax.Request('sendmail.php', {
				method: 'post',
				postBody: Form.serialize(document.getElementById('contactform')),
				onSuccess: function(t){
					document.getElementById('msgsub').value=t.responseText;
					new Effect.toggle('usercp','blind', {duration:1});
				}
});

}

function saveBlog(){

new Ajax.Request('postblog.php', {
						method:'post',
						postBody: Form.serialize(document.getElementById('blogdata')),
						onSuccess: function(t){
							document.getElementById('blogsubmit').value=t.responseText;
						}
});
}

function contactPage(){
new Ajax.Updater('usercp','sendmail.php', {
			asynchronous: true,
			onComplete: function(){
					new Effect.toggle('usercp','blind', {duration:1});
			}
});

}

function newBlog(){
new Ajax.Updater('usercp','postblog.php',{
						asynchronous: true,
						onComplete: function(){
							new Effect.toggle('usercp','blind', {duration:1});
						}
});
}

function doRegister(){
					
					document.getElementById('submitty').value="registering..";
					
new Ajax.Request('register.php', {
					method:'post',
					postBody: Form.serialize(document.getElementById('doregister')),
					onSuccess: function(t){
					
						if (t.responseText != 'success'){
							document.getElementById('submitty').value="register";
							document.getElementById('regmsg').innerHTML=t.responseText;
						} else {
							tLoad();
							document.getElementById('submitty').value="succcess";
								
								new Effect.toggle('regbar','blind', {
												duration: 1,
												afterFinish: function(){
													
													new Ajax.Updater('bottombar','userinfo.php?db=1', {
																asynchronous: true,
																onComplete: function(){
																	tLoad();
																	new Effect.toggle('bottombar','blind',{duration:1})
																}
													});
												}
								});
						}
						
					}
});
}

function registerUser(){
	tLoad();
	new Effect.toggle('bottombar','blind', {
							duration: 1,
							afterFinish: function(){
										
										new Ajax.Updater('regbar','register.php', {
											asynchronous: true,
											onComplete: function(){
														tLoad();
														new Effect.toggle('regbar','blind', {duration: 1});
											}
										});
							}
	});
							

}

function test(post,page){
			
						new Effect.toggle('commentsdiv','appear',{
								afterFinish: function(){
											tLoad();	
											// commentscontainer
											new Ajax.Updater('commentsdiv','comments.php?p='+post+'&page='+page, {
																			asynchronous: true,
																			onComplete: function(){
																					tLoad();
																					new Effect.toggle('commentsdiv','appear');
																			}
											});
								}
						});
			
}

function closeCP(){

new Effect.toggle('usercp','blind', {
				duration: 1
				});
									
}

function saveCP(){

					document.getElementById('submit2').value="saving...";
					
new Ajax.Request('usercp.php', {
					method:'post',
					postBody: Form.serialize(document.getElementById('cpdata')),
					onSuccess: function(t){
						document.getElementById('submit2').value=t.responseText;
					}
});
	
}

function avBox(avatar){

	div = document.getElementById('cpav');
		
	new Effect.toggle('cpav','appear',{duration: 0.8,
		afterFinish: function(){
			
			new Ajax.Updater('cpav','show.php?i='+avatar+'&w=60', {
				asynchronous: true,
				onComplete: function(){
				new Effect.toggle('cpav','appear',{duration: 0.8});
				}	

			});
			
				
		}
	
	});
	
}

function doComments(post){

	
	new Effect.toggle('loading', 'appear',{
			duration: 0.2,
			afterFinish: function(){
					
					new Ajax.Updater('commentsdiv','comments.php?p='+post, {
						asynchronous: true,
						onComplete: function(){
								
								new Effect.toggle('commentsdiv','blind',{
										duration: 1
								});	
								
								tLoad();

			
						}
					});
			}
	});


}	

	

function tLoad(){
			new Effect.toggle('loading', 'appear',{
				duration: 0.2
			});
}

function closeComments(){
			new Effect.toggle('commentsdiv', 'blind', {
				duration: 1
			});		
}
 
function moveUp() {
   content.scrollTop =  content.scrollTop - 30;
}

function moveDown() {
 		content.scrollTop =  content.scrollTop + 30;
}


function postComment(){
	
		tLoad();
	new Effect.toggle('commentsdiv','blind', {
		duration: 1,
		afterFinish: function(){
			
				new Ajax.Request('comments.php', {
					method:'post',
					postBody: Form.serialize(document.getElementById('postcomment')),
					onSuccess: function(t){
						
						new Ajax.Updater('commentsdiv',	'comments.php?p='+t.responseText, {
							asynchronous: true,
							onComplete: function(){
								new Effect.toggle('commentsdiv','blind', {
									duration: 1
								});
								tLoad();
							}
						});	
					}
				});
		}
	});
				
}	


function logIn(){
				
		//alert('lil');		
        tLoad();
        new Effect.toggle('bottombar', 'blind', {
                duration: 1,
                afterFinish: function(){
         				
        		new Ajax.Request('login.php', {
                		method:'post',
                		postBody: Form.serialize(document.getElementById('login')),
                		onSuccess: function(t){
                		
                		tLoad();
                		
						if (t.responseText == 0){
                				document.getElementById('submit').value="incorrect";
                				new Effect.toggle('bottombar', 'blind', {duration: 1});
					} else {
						
						new Ajax.Updater('bottombar','userinfo.php?db=1', {
							asynchronous: true,
							onComplete: function(){
								
								//tLoad();
								
								new Effect.toggle('bottombar', 'blind', {
								duration: 1
								});
								
							}
						});
						
					}
					
 			}});
 	
 		}});


}


function logOut(){

	tLoad();
	
	new Effect.toggle('bottombar', 'blind', {
		duration: 1,
		afterFinish: function(){
			
			new Ajax.Updater('bottombar','login.php?l=1', {
				asynchronous: true,
				onComplete: function(){
				
					tLoad();
					
					new Effect.toggle('bottombar', 'blind', {
						duration: 1
					});
				}
			});
		
		}
	});
	
}
function getPage(direction){

	tLoad();



	new Effect.toggle('content', 'appear', {
		duration: 0.2,
		afterFinish: function(){
		
					post = document.getElementById('postid').className;
		
							if (direction.length >= 2){
								output = direction+'.php';
							} else {			
								output = 'blog.php?p='+post+'&d='+direction;
							}
	
					new Ajax.Updater('content', output, {
                              asynchronous:true,
                              onComplete: function(){
                              		
                          		tLoad();
                              		
                              		new Effect.toggle('content','appear', {
                              			duration: 0.2
                              		});
                              
                              }
          });
			
		}
	});
}

function userCP(action){

	tLoad();
	
	if (action == 'ui'){
		extra = "?a=ui";
	}
	

			new Ajax.Updater('usercp','usercp.php', {
				asynchronous: true,
				onComplete: function(){
					tLoad();
					new Effect.toggle('usercp','blind', {duration: 1});
				}
			});

				

}

function errFunc(t) {
    alert('hit errfunc somehow');
}

