var prev_id = 'twitter';

function browse_tab(tab_id){
	$(tab_id).toggle();
	$(prev_id).toggle();
	$(tab_id + "_tab").toggleClassName("selected");
	$(prev_id + "_tab").toggleClassName("selected");
	prev_id = tab_id;
}
function search_opportunities(){
	
	new Ajax.Updater('opportunities_container','http://xanetwork.org/searchopportunities.php',{
		onLoading:function(request){
			Element.hide('opportunities_container', { duration: 0.2 });
			Element.show('spinner');
		},
		onComplete:function(request){
			Element.hide('spinner');
			Element.show('opportunities_container');
	
		}, parameters: $('the_search_form').serialize(), evalScripts:true, asynchronous:true
	});
}
function search_students(){
	
	new Ajax.Updater('student_box','http://xanetwork.org/searchstudents.php',{
		onLoading:function(request){
			Element.hide('student_box', { duration: 0.2 });
			Element.show('spinner');
		},
		onComplete:function(request){
			Element.hide('spinner');
			Element.show('student_box');
	
		}, parameters: $('the_search_form').serialize(), evalScripts:true, asynchronous:true
	});
}
function update_profile(){
	
	new Ajax.Updater('profile_status','http://xanetwork.org/updateprofile.php',{
		onLoading:function(request){
			Element.show('spinner');
			Element.hide('profile_close');
		},
		onComplete:function(request){
			Element.hide('profile_box');
		}, parameters: $('profile_form').serialize(), evalScripts:true, asynchronous:true
	});
}
function interested(id){
	
	var params;
	params = $('interested_'+id).serialize(true);
	params.is_interested = $('button_'+id).hasClassName('selected');
	
	new Ajax.Updater('status_'+id,'http://xanetwork.org/interested.php',{
		onLoading:function(request){

		},
		onComplete:function(request){
			if($('button_'+id).hasClassName('selected')){
				$('button_'+id).removeClassName('selected')
			}else{
				$('button_'+id).addClassName('selected')
			}
			
		}, parameters: params, evalScripts:true, asynchronous:true
	});
}
function remove_student(userid, postid){
	
	var answer = confirm("Are you sure you want to remove this user from the interested list?")
	if (answer){

		new Ajax.Updater('status_'+postid,'http://xanetwork.org/remove_user.php',{
			onLoading:function(request){

			},
			onComplete:function(request){
				Effect.Fade('user_'+userid+'_'+postid);
			}, parameters: {user_id:userid, post_id:postid}, evalScripts:true, asynchronous:true
		});
	}
}

function deny_user(userid){
	
	var answer = confirm("Are you sure you want to DELETE this users registration?")
	if (answer){

		new Ajax.Updater('status_'+userid,'http://xanetwork.org/denyuser.php',{
			onLoading:function(request){

			},
			onComplete:function(request){
				//Effect.Highlight('user_'+userid, { startcolor: '#e76565',endcolor: '#ffffff' });
				$('user_'+userid).setStyle({backgroundColor: '#e76565'});
				Effect.Fade('user_'+userid);
			}, parameters: {user_id:userid}, evalScripts:true, asynchronous:true
		});
	}
}
function approve_user(userid){
	
	var answer = confirm("Are you sure you want to APPROVE this users registration?")
	if (answer){

		new Ajax.Updater('status_'+userid,'http://xanetwork.org/approveuser.php',{
			onLoading:function(request){

			},
			onComplete:function(request){
				//Effect.Highlight('user_'+userid, { startcolor: '#65e765',endcolor: '#ffffff' });
				$('user_'+userid).setStyle({backgroundColor: '#65e765'});
				Effect.Fade('user_'+userid);
			}, parameters: {user_id:userid}, evalScripts:true, asynchronous:true
		});
	}
}

function disable_fields(){
	if($('signup_org').checked){
		Effect.Fade('student');
	}else{
		Effect.Appear('student');
	}
		
}
function delete_opportunity(postid){
	
	var answer = confirm("Are you sure you want to delete this posted opportunity?")
	if (answer){

		new Ajax.Updater('delete_status_'+postid,'http://xanetwork.org/delete_opportunity.php',{
			onLoading:function(request){

			},
			onComplete:function(request){
				Effect.Fade('opportunity_'+postid);
			}, parameters: {post_id:postid}, evalScripts:true, asynchronous:true
		});
	}
}
