var chat_load_count = 0;
function loadChatterBox()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			//alert(ajaxRequest.responseText);
			if (ajaxRequest.responseText!='NO_UPDATES')
				$("#chatter_box_holder").html(ajaxRequest.responseText);
		}
	}
	
	
	initChatterBox();
	
	ajaxRequest.open("GET", "/global/ajax/chatter_box_load.php", true);
	ajaxRequest.send(null);
}



function initChatterBox()
{
	setTimeout("loadChatterBox()",4000);
}

function checkUserSearch()
{
	if ($("#search_query2").val()=="Search For Your Friends")
	{
		document.getElementById("search_query2").value = "";
	}	
}


function sendChatterBoxMessage()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById("chatter_message").value = "";
			loadChatterBox();
		}
	}
	
	q = "chat_message="+escape(encodeURI($("#chatter_message").val()));
	ajaxRequest.open("GET", "/global/ajax/chatter_box_send.php?"+q, true);
	ajaxRequest.send(null);
}




function sendStatusUpdate()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			document.getElementById("user_status").value = "";
			$("#user_status_count").html("140");
			$("#previous_user_status").fadeOut("slow");
			setTimeout("loadStatusUpdate()",500);
			loadStatusUpdateList();
		}
	}
	
	if ($("#user_status").val()!="")
	{
		q = "status_update="+escape(encodeURI($("#user_status").val()));
		
		ajaxRequest.open("GET", "/global/ajax/user_status_update.php?"+q, true);
		ajaxRequest.send(null);
	}
}


function loadStatusUpdate()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#previous_user_status").html(ajaxRequest.responseText);
			$("#previous_user_status").fadeIn("slow");
		}
	}
	
	ajaxRequest.open("GET", "/global/ajax/user_load_status.php", true);
	ajaxRequest.send(null);
}



function loadStatusUpdateList()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#friend_status_update_all").html(ajaxRequest.responseText);
			//$("#previous_user_status").fadeIn("slow");
		}
	}
	
	ajaxRequest.open("GET", "/global/ajax/user_load_status_list.php", true);
	ajaxRequest.send(null);
}



function countStatusUpdate(the_status)
{
	var current_length = the_status.length;
	var length_diff;
	
	if (current_length>140)
	{
		document.getElementById("user_status").value = the_status.substr(0,139);
	}
	
	length_diff = 140-current_length;
	if (length_diff==0 || length_diff=="")
	{
		length_diff = "0";
	}
	
	$("#user_status_count").html(length_diff);
}





//MAIL
var mail_to_container;
var mail_to_index = 0;
var current_autos = "";
var direction_arrow = "";
var to_username_values = new Array();
var to_user_id_values = new Array();
function MailAutoTo(user_input,event)
{
	
	var count_autos = 0;
	
	switch(event.keyCode)
	{
		case 38: 
			direction_arrow = "up";
		break;
		
		case 40:
			direction_arrow = "down";
		break;
		
		case 13:
			direction_arrow = "choose";
		break;
		
		default:
			direction_arrow = "";
		break;
	}
	
	
	
	 if (user_input=="")
	 {
	 	MailAutoClose_Kill();
		return false;
	 }
	
	
	
	
	if (user_input!="")
	{
		
			var ajaxRequest;  // The variable that makes Ajax possible!
			var return_string;
			
			try{
				// Opera 8.0+, Firefox, Safari
				ajaxRequest = new XMLHttpRequest();
			} catch (e){
				// Internet Explorer Browsers
				try{
					ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try{
						ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e){
						// Something went wrong
						alert("Your browser broke!");
						return false;
					}
				}
			}
			
			// Create a function that will receive data sent from the server
			ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4)
				{
					if (direction_arrow=="")
					{
						return_string = ajaxRequest.responseText;
						$("#message_compose_auto_container").html(return_string);
					}
					
					
					current_autos = getElementsByClassName("auto_default");
					count_autos = current_autos.length;
					
					//alert(current_autos.length)
					if (direction_arrow!="" )
					{
						
						if (count_autos>0)
						{
							if (direction_arrow=='up')
							{
								mail_to_index = mail_to_index - 1;
							}
							
							if (direction_arrow=='down')
							{
								mail_to_index = mail_to_index + 1;
							}
						}
						
						if (mail_to_index>count_autos)
						{
							mail_to_index = (count_autos);
						}
						
						if (mail_to_index<1)
						{
							mail_to_index = 1;
						}
						
						
						if (direction_arrow=='choose')
						{
							//alert("Username = "+to_username_values[mail_to_index]+", User ID="+to_user_id_values[mail_to_index]);
							setMailTo(to_username_values[mail_to_index],to_user_id_values[mail_to_index]);
							return false;
						}
						
						//document.getElementById("count_test").value = mail_to_index+"/"+count_autos;
						
						for (x=0;x<current_autos.length;x++)
						{
							current_autos[x].style.backgroundColor = "#F5F5F5";
						}
						
						if(user_input!="")
						{
							RestoreMailToAuto();
						}
						document.getElementById("mail_auto_index_"+mail_to_index).style.backgroundColor = "#E8F1FA";
					}
					
				}
			}
			
			var queryString = "?mail_to="+user_input+"&direction="+direction_arrow+"&selected_index="+mail_to_index;
			ajaxRequest.open("GET", "/global/ajax/message_to_autocomplete.php" + queryString, true);
			ajaxRequest.send(null);
		
	} else
	{
		//to_field.className = "mail_to_default";
		//document.getElementById("mail_to").innerHTML = "Start typing a username";
		MailAutoClose_Kill();
	}
	$("#message_compose_auto_container_holder").fadeIn("slow");
}


function setMailTo(username, user_id)
{
	var mail_to_field = document.getElementById("mail_to_input");
	document.getElementById("to_user_id").value = user_id;
	mail_to_field.value = username;
	$("#message_compose_auto_container").html("");
	MailAutoClose_Kill();
	
}



function MailAutoClose()
{
	mail_to_container = setTimeout("MailAutoClose_Kill()",800);
}


function MailAutoClose_Kill()
{
	$("#message_compose_auto_container_holder").fadeOut("slow");
}




function RestoreMailToAuto()
{
	clearTimeout( mail_to_container );
}

var message_okay = false;

function checkEmailStatus()
{
	if (message_okay)
		return true;
	else
		return false;
}

function checkMessageRecipient()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var return_string;
	var mail_to = document.getElementById("mail_to_input").value;
	var html = "";
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			return_string = ajaxRequest.responseText;
			if ( return_string==0)
			{
				$("#message_compose_auto_container_holder").fadeIn("slow");
				html = '<div id="message_compose_auto_container_none" onmouseover="RestoreMailToAuto()" onmouseout="MailAutoClose()">';
				html += 'User was not found.';
				html += '</div>';
				$("#message_compose_auto_container").html(html);
				RestoreMailToAuto();
				message_okay = false;
			} else
			{
				document.getElementById("to_user_id").value = return_string;
				message_okay = true;
				document.message_new_form.submit();
			}
		}
	}
	
	var queryString = "?mail_to="+mail_to;
	ajaxRequest.open("GET", "/global/ajax/message_to_verify.php" + queryString, true);
	ajaxRequest.send(null);
}

function MailSetRead(mail_id)
{
	document.getElementById("mail_status_"+mail_id).innerHTML = "Read";
}

function saveMessage(user_message_id)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			return_string = ajaxRequest.responseText;
			if (return_string=="1")
			{
				//alert("Message Was Saved");
				$("#message_save_button").fadeOut("slow");
			}
			
			if (return_string=="0")
			{
				alert("Error While Saving This Message");
			}
		}
	}
	q = "?user_message_id="+user_message_id;
	ajaxRequest.open("GET", "/global/ajax/message_save.php"+q, true);
	ajaxRequest.send(null);
}


function updateFriendRequest(user_status, to_username,umid)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#fr_"+umid).fadeOut("slow");
		}
	}
	q = "?status="+user_status+"&friend="+to_username;
	ajaxRequest.open("GET", "/global/ajax/user_friend_request_save.php"+q, true);
	ajaxRequest.send(null);
}

function deleteFriendRequests(user_map_id)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#fr_"+user_map_id).fadeOut("slow");
		}
	}
	q = "?user_map_id="+user_map_id
	ajaxRequest.open("GET", "/global/ajax/user_friend_request_delete.php"+q, true);
	ajaxRequest.send(null);
}



function deleteProfileComment(comment_id)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	
	if (confirm("Delete this comment?"))
	{
		
		
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
				ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					// Something went wrong
					alert("Your browser broke!");
					return false;
				}
			}
		}
		
		// Create a function that will receive data sent from the server
		ajaxRequest.onreadystatechange = function(){
			if(ajaxRequest.readyState == 4)
			{
				$("#comment_row_"+comment_id).fadeOut("slow");
			}
		}
		q = "?comment_id="+comment_id
		ajaxRequest.open("GET", "/global/ajax/user_comment_delete.php"+q, true);
		ajaxRequest.send(null);
	}
}




/*  AJAX FILE UPLOAD */

function startUploadUserPic()
{
      document.getElementById('process_display').style.display = '';
      document.getElementById('upload_form').style.display = 'none';
      return true;
}

function stopUploadUserPic(success)
{
      var result = '';
	  var html = "";
      if (success !="")
	  {
         result = '<tr><td>Image was uploaded.</td></tr>';
      }
      else 
	  {
         result = '<tr><td>There was an error while uploading.  Try Again.</td></tr>';
      }
      document.getElementById('process_display').style.display = 'none';
	  
	html = '<td>';
	html += "\n";
	html += '<table border="0" cellspacing="2" cellpadding="2">';
	html += "\n";
	html += result;
	html += '<tr>';
	html += "\n";
	html += '<td style="padding-top: 5px;">';
	html += '<strong>Upload a New Image </strong>(.jpg or .gif only):</td>';
	html +='</tr>';
	html += '<tr>';
	html += '<td><input type="file" name="profile_image" id="profile_image" class="profile_form_text" /></td>';
	html += '</tr>';
	html += '<tr>';
	html += '<td><input type="submit" value="Update My Picture" class="profile_btn" /></td>';
	html += '</tr>';
	html += '</table>';
	html += '</td>';
	  
     $("#upload_form").html(html);
	 document.getElementById("current_user_image_pic").src = success;
	 document.getElementById("main_user_display_pic").src = success;
      document.getElementById('upload_form').style.display = '';      
      return true;   
}


function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}




var image_options = "";
var current_image_id = "";

function showImageOptions(user_album_image_id)
{
	var all_image_options = getElementsByClassName("album_image_drop_container");
	var image_count = all_image_options.length;
	var current_image_id = user_album_image_id;
	
	for (x=0;x<image_count;x++)
	{
		$("#"+all_image_options[x].id).fadeOut("slow");
	}
	
	$("#image_options_"+user_album_image_id).fadeIn("slow");
}


function restoreImageOptions(user_album_image_id)
{
	current_image_id=user_album_image_id;
	clearTimeout(image_options);
}

function hideImageOptions(user_album_image_id)
{
	image_options = setTimeout("hideImageOptionsNow("+user_album_image_id+")",1000);
	current_image_id = "";
}



function hideImageOptionsNow(user_album_image_id)
{
	if (current_image_id!=user_album_image_id)
	{
		$("#image_options_"+user_album_image_id).fadeOut("slow");
	}
}


function confirmDeleteImage(user_album_image_id, user_album_id)
{
	if (confirm("Are you sure you want to delete this image?"))
	{
		window.location.href = "/global/controls/user_album_image_delete.php?user_album_image_id="+user_album_image_id+"&user_album_id="+user_album_id;
	}
}


function verifyDeleteComment(username,album_id,album_image_id,comment_id)
{
	var q = "/global/controls/user_album_image_comment_delete.php?username="+username+"&user_album_id="+album_id+"&user_album_image_id="+album_image_id+"&user_album_image_comment_id="+comment_id;
	if (confirm("Are you sure you want to delete this comment?"))
	{	
		window.location.href = q;	
	}
}



function verifyDeleteCommentUser(username,album_id,album_image_id,comment_id)
{
	var q = "/global/controls/user_album_image_comment_delete.php?username="+username+"&user_album_id="+album_id+"&user_album_image_id="+album_image_id+"&user_album_image_comment_id="+comment_id+"&type=user";
	if (confirm("Are you sure you want to delete this comment?"))
	{	
		window.location.href = q;	
	}
}




function verifyDeleteAlbum(album_id)
{
	var q = "/global/controls/user_album_delete.php?user_album_id="+album_id;
	if (confirm("Are you sure you want to delete this album and all pictures inside of it?"))
	{	
		window.location.href = q;	
	}
}



function confirmDeleteQuestion(qid)
{
	var q = "/global/controls/qa_user_question_delete.php?question_id="+qid;
	if (confirm("Are you sure you want to delete this question?"))
	{	
		window.location.href = q;
	}
}


function confirmDeleteAnswer(aid)
{
	var q = "/global/controls/qa_user_answer_delete.php?answer_id="+aid;
	if (confirm("Are you sure you want to delete this answer?"))
	{	
		window.location.href = q;
	}
}

function confirmDeleteBuzz(bid)
{
	var q = "/global/controls/user_buzz_delete.php?buzz_id="+bid;
	if (confirm("Are you sure you want to delete this buzz article?"))
	{	
		window.location.href = q;
	}
}


function checkUserBuzz()
{
	
}



function confirmDeleteBulletin(bid)
{
	var q = "/global/controls/user_bulletin_delete.php?bulletin_id="+bid;
	if (confirm("Are you sure you want to delete this Bulletin?"))
	{	
		window.location.href = q;
	}
}

function highlightHeadline()
{
	//$("#headline_edit").addClass("headline_border");
	document.getElementById("headline_edit").style.border = "1px solid #FFF";
}

function unhighlightHeadline()
{
	document.getElementById("headline_edit").style.border = "1px solid #E5E5E5";
}

function editProfileHeadline()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#headline_edit").html(ajaxRequest.responseText);
		}
	}
	var q = "?action=edit";
	ajaxRequest.open("GET", "/global/ajax/profile_load_headline_edit.php"+q, true);
	ajaxRequest.send(null);

}


function saveProfileHeadline()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#headline_edit").html(ajaxRequest.responseText);
			document.getElementById("profile_headline_update").focus();
		}
	}
	var q = "?action=save&headline="+escape(encodeURI($("#profile_headline_update").val()));
	ajaxRequest.open("GET", "/global/ajax/profile_load_headline_edit.php"+q, true);
	ajaxRequest.send(null);

}


var mood_timer;
function showMoods()
{
	restoreMoods();
	$("#mood_selection").fadeIn("slow");
}

function hideMoods()
{
	mood_timer = setTimeout("$(\"#mood_selection\").fadeOut(\"slow\")",1200);
}

function restoreMoods()
{
	clearTimeout(mood_timer);
}



function saveMood(mid)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q;
	
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			return_html = ajaxRequest.responseText;
			$("#mood_selection").fadeOut("slow");
			setTimeout("$(\"#mood_current\").fadeOut(\"fast\");", 600);
			setTimeout("setCurrentMood(return_html)", 950);
			setTimeout("$(\"#mood_current\").fadeIn(\"fast\");", 1300);
			
		}
	}
	var q = "?action=save&mood_id="+mid;
	ajaxRequest.open("GET", "/global/ajax/profile_save_mood.php"+q, true);
	ajaxRequest.send(null);

}

function setCurrentMood(html)
{
	 document.getElementById('mood_current').innerHTML = html;
}




function toggleBuzz(ele)
{
	if(ele.checked)
	{
		$("#buzz_category_id").fadeIn("slow");
	}	 else 
	{
		$("#buzz_category_id").fadeOut("slow");
	}
}



function saveStep1()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q = "";
	
	if (document.getElementById("interests_1").checked) q+= q==""?"1":",1";
	if (document.getElementById("interests_2").checked) q+= q==""?"2":",2";
	if (document.getElementById("interests_3").checked) q+= q==""?"3":",3";
	if (document.getElementById("interests_4").checked) q+= q==""?"4":",4";
	if (document.getElementById("interests_5").checked) q+= q==""?"5":",5";
	if (document.getElementById("interests_6").checked) q+= q==""?"6":",6";
	if (document.getElementById("interests_7").checked) q+= q==""?"7":",7";
	if (document.getElementById("interests_8").checked) q+= q==""?"8":",8";
	if (document.getElementById("interests_9").checked) q+= q==""?"9":",9";
	if (document.getElementById("interests_10").checked) q+= q==""?"10":",10";
	if (document.getElementById("interests_11").checked) q+= q==""?"11":",11";
	if (document.getElementById("interests_12").checked) q+= q==""?"12":",12";
	if (document.getElementById("interests_13").checked) q+= q==""?"13":",13";
	if (document.getElementById("interests_14").checked) q+= q==""?"14":",14";
	if (document.getElementById("interests_15").checked) q+= q==""?"15":",15";
	if (document.getElementById("interests_16").checked) q+= q==""?"16":",16";
	if (document.getElementById("interests_17").checked) q+= q==""?"17":",17";
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			loadStep2();
		}
	}
	
	ajaxRequest.open("GET", "/global/ajax/user_registration1.php?interests="+q, true);
	ajaxRequest.send(null);
}

function loadStep2()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q = "";
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			$("#registration_steps_content").html(ajaxRequest.responseText);
			$("#registration_steps_title_bar").html("Invite Your Friends and Family");
		}
	}
	
	ajaxRequest.open("GET", "/global/ajax/user_registration_invite.php?action=load", true);
	ajaxRequest.send(null);
}


function saveStep2()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q = "";
	var c = 0;	
	if (document.getElementById("fname1").value!="")
	{
		e = document.getElementById("femail1").value;
		if (e=="" || e.indexOf(".")==-1 || e.indexOf("@")==-1 )
		{
			alert("Friend's email 1 is invalid");
			c++;
		} else 
		{
			q += "&fname1="+escape(encodeURI($("#fname1").val()));
			q+= "&femail1="+escape(encodeURI($("#femail1").val()));
		}
	}
	
	if (document.getElementById("fname2").value!="")
	{
		e = document.getElementById("femail2").value;
		if (e=="" || e.indexOf(".")==-1 || e.indexOf("@")==-1 )
		{
			alert("Friend's email 2 is invalid");
			c++;
		} else 
		{
			q += "&fname2="+escape(encodeURI($("#fname2").val()));
			q+= "&femail2="+escape(encodeURI($("#femail2").val()));
		}
	}
	
	
	if (document.getElementById("fname3").value!="")
	{
		e = document.getElementById("femail3").value;
		if (e=="" || e.indexOf(".")==-1 || e.indexOf("@")==-1 )
		{
			alert("Friend's email 3 is invalid");
			c++;
		} else 
		{
			q += "&fname3="+escape(encodeURI($("#fname3").val()));
			q+= "&femail3="+escape(encodeURI($("#femail3").val()));
		}
	}
	
	
	if (document.getElementById("fname4").value!="")
	{
		e = document.getElementById("femail4").value;
		if (e=="" || e.indexOf(".")==-1 || e.indexOf("@")==-1 )
		{
			alert("Friend's email 4 is invalid");
			c++;
		} else 
		{
			q += "&fname4="+escape(encodeURI($("#fname4").val()));
			q+= "&femail4="+escape(encodeURI($("#femail4").val()));
		}
	}
	
	
	if (document.getElementById("fname5").value!="")
	{
		e = document.getElementById("fname5").value;
		if (e=="" || e.indexOf(".")==-1 || e.indexOf("@")==-1 )
		{
			alert("Friend's email 5 is invalid");
			c++;
		} else 
		{
			q += "&fname5="+escape(encodeURI($("#fname5").val()));
			q+= "&femail5="+escape(encodeURI($("#femail5").val()));
		}
	}
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			var r = ajaxRequest.responseText;
			if (r=='exit')
			{
				closeRegistrationSteps()
			} else 
			{
				loadStep3();
			}
		}
	}	
	
	ajaxRequest.open("GET", "/global/ajax/user_registration2.php?action=send"+q, true);
	ajaxRequest.send(null);
}


function loadStep3()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q = "";
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			var r = ajaxRequest.responseText;
			if (r=='skip')
			{
				closeRegistrationSteps();
			} else 
			{
				$("#registration_steps_content").html(ajaxRequest.responseText);
				$("#registration_steps_title_bar").html("Add Hive Users With Similar Interests As You");
			}
		}
	}
	
	ajaxRequest.open("GET", "/global/ajax/user_registration_requests.php?action=load", true);
	ajaxRequest.send(null);
}

function saveStep3()
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	var q = "";
	
	
	var v = document.getElementsByName("requests");
	for (x=0;x<v.length;x++)
	{
		if (v[x].checked)
		{
			q += q==""?v[x].value:","+v[x].value;
		}
	}
	
	if (q=="")
	{
		closeRegistrationSteps();
		return false;
	}
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			var r = ajaxRequest.responseText;
				closeRegistrationSteps();
		}
	}
	
	ajaxRequest.open("GET", "/global/ajax/user_registration_requests.php?action=send&user_ids="+q, true);
	ajaxRequest.send(null);
}



function closeRegistrationSteps()
{
	$("#registration_steps_container").fadeOut("fast");
}