$(function() {
  	  	
  	//semi hide rants when options are used and the user is not logged in
  	if ($('.washlink').length > 0)
  		$('.washlink').click(modal_div);  

  	
  	//$('label').click(change_label_color);
  	
  	$('.time_tab').click(setTimeTab);
  	
  	$('#save_orders').click(save_orders);  
	
	$('input:checkbox').click(function(){
		label_id = $(this).attr('id');
		
		$('label').attr("for", function(){
			if($(this).attr("for") == label_id){
				$(this).toggleClass("chosen");
			}	
		});				
		
	});
	
	//allow only one checked combobox for saving filters
	$('#most_burns').click(AllowOneCheck);
	$('#most_comments').click(AllowOneCheck);
	$('#most_views').click(AllowOneCheck);
	$('#most_recent').click(AllowOneCheck);
	
	$('#show_advanced_options').click(switchAdvancedOptions); 
	
	//rant ratings actions
	
	$('.comment_burns').click(switchBurnsView);
	$('.comment_burns_over').click(switchBurnsView);
	
	//burn comment
	$('.rant_burn').click(rateRant);
	//wash comment
	$('.rant_wash').click(rateRant);
	
	//add comment ajax
	$('#but_submit_comment').click(addComment);
	
	//add comment from site; captcha check
	$('#but_submit_comment_site').click(addCommentSite);
	
	//reply comment ajax
	$('.but_reply_comment').click(replyComment);
	
	$('.but_reply_comment_site').click(replyCommentSite);
	
	//restrict comments to current user
	$('#only_my_comments').click(OnlyMyComments);	
	
	//restrict comments to friends
	$('#only_friends_comments').click(OnlyFriendsComments);	
	
	//all comments
	$('#all_comments').click(AllComments);	
	
	//sort comments
	$("#sort_options").change(sortComments);
	
	//burners pagination
	$(".pag_ajax").click(getBurners);
	
	//share rant
	$('#but_submit_share').click(shareRant);
	
	//auto expand add comment textarea
	$('textarea.textarea_comment').autogrow();
	
	//show/hide footer
	$('#ico_expand').click(switchFooter);
	$('#ico_collapse').click(switchFooter);		
	
	//share modal; friends background
	$('.friends_share').click(switchFriendsBackground);	
	
	$('#select_all_friends').click(selectAllFriends);
	
	$('#but_submit_shout').click(sendShouts);
	
	$('#shout_email').click(ShoutsTab1);
	
	$('#shout_shout').click(ShoutsTab2);
	
	$('#shout_boomark').click(ShoutsTab3);
	
	//tag rants as favorite
	$('.tag_favorite').click(addFavorite);
	
	//admin module; save order list
	$('#order_button').click(saveOrderList);
	
	//report comment 
	$('.report_rant').click(reportRant);
	
	//report ramble
	$('.report_ramble').click(reportRamble);
	
	//select all checkboxes
	$('#select_all').click(SelectAllCheckboxes);
	
	$('#select_all_rants').click(SelectAllCheckboxesRants);
	
	//delete selected comments
	$('#delete_selected_comments').click(DeleteSelectedComments);
	
	//delete comment reports
	$('#delete_comment_reports').click(DeleteCommentReports);
	
	//delete rant reports
	$('#delete_rant_reports').click(DeleteRantReports);
	
	//delete selected rants
	$('#delete_selected_rants').click(DeleteSelectedRants);
	
	
	$('a#toggle_filters').click(toggleWindow);
	
	$('.reply_comment').click(InsertCommentBox);
	$('.reply_comment_site').click(InsertCommentBoxSite);
	
	$('.comment_replies').click(ShowCommentReplies);
	
	$('.comment_show').click(ShowThreshold);
	$('.comment_hide').click(HideThreshold);
	
	
	$('.comments_next_page').click(CommentsNextPage);
	
	document.onkeydown = keydownfnc;
		
	//==================================================
	
	//alina scripts
		
	$('#google_mail').click(switchGoogleMail);
  	$('#yahoo_mail').click(switchYahooMail);
  	$('#msn_mail').click(switchMSNMail);
  	$('#aol_mail').click(switchAOLMail);
  	$('#cvs_import').click(switchCVSMail);
	
	$('a#invites_selectall').click(function() {
		$('#invite_items input[@type=checkbox]').attr('checked', 'checked');
	});
	
	$('a#invites_deselectall').click(function() {
		$('#invite_items input[@type=checkbox]').attr('checked', '');
	}); 
	
	$('.get_featured_rant').click(GetFeaturedRant);
	
	//==================================================
	
	//safari browser detection; fix drop down list
	//if($.browser.safari)	
	
	//ajax example
	//$.post('?test', {email:'email',user:'user'}, function(response) {
	//	alert(response);
	//});
		
})

function keydownfnc(e)
	{
		if(e==null){keycode=event.keyCode}
		else{keycode=e.which}
		
		if(keycode == 27){
			tb_remove();
			document.onkeydown = keydownfnc;
		}	
	};	

function GetFeaturedRant(){
	if($(this).attr("id").indexOf('previous_rant') != -1){
		type = 0; //previous
	}
	else
		type = 1; //next
	
	$('div.layout_02').html('<div style="padding-top: 50px"><img src="_layouts/images/load3.gif" border="0" /></div>');
	
	//ajax example
	$.post('?get_featured_rant', {type:type}, function(response) {
		$('div.layout_02').html(response);
		$('.get_featured_rant').click(GetFeaturedRant);
	
		$('.washlink').click(modal_div);  
	});

}

function CommentsNextPage(){
	arr = $(this).attr("id").split("_");
	ramble_id = arr[1];
	pag = arr[2];
	
	$('#div_comments_overflow_' + ramble_id + '_' + pag).html('<img src="' + LAYOUTS + 'images/blue_loading.gif" border="0" />');
	
	$.post('?comments_next_page', {ramble_id:ramble_id,pag:pag}, function(response) {
		update = response.split("|||");
		if(update[0] == 1){
		
			$('#comments_overflow_' + ramble_id + '_' + pag).before(update[1]);
			$('#comments_overflow_' + ramble_id + '_' + pag).remove();
			
			$('.comments_next_page').click(CommentsNextPage);
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
			$('.reply_comment').click(InsertCommentBox);
			$('.reply_comment_site').click(InsertCommentBoxSite);
			$('.but_reply_comment').click(replyComment);
			$('.but_reply_comment_site').click(replyCommentSite);
			$('.comment_replies').click(ShowCommentReplies);
			$('.comment_show').click(ShowThreshold);
			$('.comment_hide').click(HideThreshold);
			
		}
	});
	
}

function ShowThreshold(){
	id= $(this).attr("id").substr(17);
	$(this).remove();
	
	//show hide links
	$('div#below_threshold_' + id).append('<a id="toggle_threshold_' + id + '" href="javascript: void(0);" class="comment_hide">Hide</a>');
	
	//author area
	$('div#rant_author_' + id).removeClass("rant_author_disabled");
	$('div#rant_author_' + id).addClass("rant_author");	
	
	//posted date area
	$('div#posted_date_' + id).removeClass("posted_date_disabled");
	$('div#posted_date_' + id).addClass("posted_date");	
	
	//description area
	$('div#rant_description_' + id).css({display: 'block'});
	
	//burns area
	$('div#rant_burns_' + id).removeClass("rant_burns_disabled");
	$('div#rant_burns_' + id).addClass("rant_burns");	
	
	//comment reply container
	$('div#reply_comment_container_' + id).css({display: 'block'});
	
	//reload trigger functions
	$('.comment_show').click(ShowThreshold);
	$('.comment_hide').click(HideThreshold);
}

function HideThreshold(){
	id= $(this).attr("id").substr(17);
	$(this).remove();
	
	$('div#below_threshold_' + id).append('<a id="toggle_threshold_' + id + '" href="javascript: void(0);" class="comment_show">Show</a>');
	
	//author area
	$('div#rant_author_' + id).removeClass("rant_author");
	$('div#rant_author_' + id).addClass("rant_author_disabled");	
	
	//posted date area
	$('div#posted_date_' + id).removeClass("posted_date");
	$('div#posted_date_' + id).addClass("posted_date_disabled");	
	
	//description area
	$('div#rant_description_' + id).css({display: 'none'});
	
	//burns area
	$('div#rant_burns_' + id).removeClass("rant_burns");
	$('div#rant_burns_' + id).addClass("rant_burns_disabled");	
	
	//comment reply container
	$('div#reply_comment_container_' + id).css({display: 'none'});
	
	//reload trigger functions
	$('.comment_show').click(ShowThreshold);
	$('.comment_hide').click(HideThreshold);
}

function ShowCommentReplies(){
	id = $(this).attr("id").substr(10);
	$("#comments_" + id).toggle('fast');
}

function replyComment(){
	
	id = $(this).attr("id").substr(18);
	
	//frm = eval("document.frmComment_" +  id);
	
	text = $('#frmComment_'+id + ' textarea[@name=comment]').val();
		
	//text = frm.comment.value;
	text = url_encode(text);
	//frm.comment.value = '';
	
	$('#frmComment_'+id + ' textarea[@name=comment]').val('');
	
	if(text == null || text == '' || text == ' '){
		msg = ErrorMsg("The comment field is blank. Please try again.", 0);
		$('div#submit_comment_error_' + id).html(msg);
		return;
	}
	
	ramble_id = $('#frmComment_'+id + ' input[@name=ramble_id]').val();
	parent_id = id;
	
	msg = '<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> Processing...'; 
	$('div#submit_comment_error_' + id).html(msg);
	
	$.post('?add_comment', {comment:text,ramble_id:ramble_id, parent_id:parent_id}, function(response) {
		update = response.split("|||");
		if(update[0] == 0){ //error
			msg = ErrorMsg(update[1], 0);
			$('div#submit_comment_error_' + id).html(msg);
			return;
		}
		else{
			//see if this is the 1st comment; must remove "no comments have been posted" text
			$("div#reply_comment_item_" + parent_id).toggle(1000);
						
			if($('ul#comments_' + parent_id).length > 0){
				$('ul#comments_' + parent_id).prepend(response);
				$('ul#comments_' + parent_id).show(1000);
			}
			else{
				$('li#list_item_' + parent_id).after('<ul id="comments_' + parent_id + '" style="padding-left: 10px">' + response + '</ul>');
				$('ul#comments_' + parent_id).show(1000);
			}
			
			//update no_replies
			if($('a#show_list_' + parent_id).length > 0){
				no_replies = $('a#show_list_' + parent_id).text();
				vect = no_replies.split(" ");
				old_value = parseInt(vect[0], 10);
				new_value = old_value + 1;
				if(new_value == 1)
					new_value = '1 Reply';
				else
					new_value = new_value + ' Replies';
					
				$('div#no_replies_' + parent_id).html('<a href="javascript: void(0)" class="tools comment_replies" id="show_list_' + parent_id + '">' + new_value + '</a>');		
			}
			else
				$('div#no_replies_' + parent_id).html('<a href="javascript: void(0)" class="tools comment_replies" id="show_list_' + parent_id + '">1 Reply</a>');
			
				
			//update number of comments in tab			
			comments = $('div#comments_tab').text();		
			
			count = comments.split(" ");
			old_value = parseInt(count[0], 10);
			new_value = old_value+1;
			$('div#comments_tab').text(new_value + " Comments");
			
			//update "Only Mine" number of comments
			span_id = $('.only_mine_comments').attr('id').substr(9);
			comments = parseInt(span_id, 10);
			new_value = comments + 1;
			
			ramble_id = id;
			
			$('#comments_' + span_id).html('<a id="only_my_comments" href="javascript: void(0);" class="ramble_' + ramble_id + '" style="font-size: 12px">Only Mine (' + new_value + ')</a>');
			
			$('#only_my_comments').click(OnlyMyComments);	
			
			$('div#submit_comment_error_' + id).html("<img src='"+LAYOUTS+"images/icon_msg_1.gif' style='vertical-align: middle' /> <span class='greenerror'>Comment successfully added.</span>");
			
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
			$('.reply_comment').click(InsertCommentBox);
			$('.comment_replies').click(ShowCommentReplies);
			$('.but_reply_comment').click(replyComment);
			$('.but_reply_comment_site').click(replyCommentSite);
			$('.comment_show').click(ShowThreshold);
			$('.comment_hide').click(HideThreshold);
		}
						
	});
		
}

function replyCommentSite(){
	
	id = $(this).attr("id").substr(18);
	
	//frm = eval("document.frmComment_" +  id);
	
	text = $('#frmComment_'+id + ' textarea[@name=comment]').val();
		
	//text = frm.comment.value;
	text = url_encode(text);
	//frm.comment.value = '';
	
	//$('#frmComment_'+id + ' textarea[@name=comment]').val('');
		
	if(text == null || text == '' || text == ' '){
		msg = ErrorMsg("The comment field is blank. Please try again.", 0);
		$('div#submit_comment_error_' + id).html(msg);
		return;
	}
	
	msg = '<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> Processing...'; 
	$('div#submit_comment_error_' + id).html(msg);
	
	//ramble_id = frm.ramble_id.value; 
	//parent_id = frm.parent_id.value; 
	
	ramble_id = $('#frmComment_'+id + ' input[@name=ramble_id]').val();
	parent_id = id;
	
	challenge = $('#frmComment_'+id + ' input[@name=recaptcha_challenge_field]').val();
	
	if(challenge){
		
		challenge = $('#frmComment_'+id + ' input[@name=recaptcha_challenge_field]').val();
		response = $('#frmComment_'+id + ' input[@name=recaptcha_response_field]').val();
							
		if(response == null || response == '' || response == ' '){
			msg = ErrorMsg("Spam Validation Failed! Try refreshing the code.", 0);
			$('div#submit_comment_error_' + id).html(msg);
			return;
		}
		
		$.post('?check_captcha', {recaptcha_challenge_field:challenge,recaptcha_response_field:response}, function(response) {
			captcha_check = response;
			
			if(captcha_check == 0){
				msg = ErrorMsg("Spam Validation Failed! Try refreshing the code.", 0);
				$('div#submit_comment_error_' + id).html(msg);
				return false;
			}
			else{ //captcha check is valid	
					
				$.post('?add_comment', {comment:text,ramble_id:ramble_id,parent_id:parent_id}, function(response) {
						
					update = response.split("|||");
					if(update[0] == 0){ //error
						msg = ErrorMsg(update[1], 0);
						$('div#submit_comment_error_' + id).html(msg);
						return;
					}
					else{
						$('#frmComment_'+id + ' textarea[@name=comment]').val('');
						//see if this is the 1st comment; must remove "no comments have been posted" text
						$("div#reply_comment_item_" + parent_id).toggle(1000);
									
						if($('ul#comments_' + parent_id).length > 0){
							$('ul#comments_' + parent_id).prepend(response);
							$('ul#comments_' + parent_id).show(1000);
						}
						else{
							$('li#list_item_' + parent_id).after('<ul id="comments_' + parent_id + '" style="padding-left: 10px">' + response + '</ul>');
							$('ul#comments_' + parent_id).show(1000);
						}	
						
						//update no_replies
						if($('a#show_list_' + parent_id).length > 0){
							no_replies = $('a#show_list_' + parent_id).text();
							vect = no_replies.split(" ");
							old_value = parseInt(vect[0], 10);
							new_value = old_value + 1;
							if(new_value == 1)
								new_value = '1 Reply';
							else
								new_value = new_value + ' Replies';
								
							$('div#no_replies_' + parent_id).html('<a href="javascript: void(0)" class="tools comment_replies" id="show_list_' + parent_id + '">' + new_value + '</a>');		
						}
						else
							$('div#no_replies_' + parent_id).html('<a href="javascript: void(0)" class="tools comment_replies" id="show_list_' + parent_id + '">1 Reply</a>');
						
						comments = $('div#comments_tab').text();		
			
						count = comments.split(" ");
						old_value = parseInt(count[0], 10);
						new_value = old_value+1;
						$('div#comments_tab').text(new_value + " Comments");
								
						$('div#submit_comment_error_' + id).html("<img src='"+LAYOUTS+"images/icon_msg_1.gif' style='vertical-align: middle' /> <span class='greenerror'>Comment successfully added.</span>");
						
						$('.comment_burns').click(switchBurnsView);
						$('.comment_burns_over').click(switchBurnsView);
						$('.rant_burn').click(rateRant);
						$('.rant_wash').click(rateRant);
						$('.reply_comment').click(InsertCommentBox);
						$('.reply_comment_site').click(InsertCommentBoxSite);
						$('.comment_replies').click(ShowCommentReplies);
						$('.but_reply_comment').click(replyComment);
						$('.but_reply_comment_site').click(replyCommentSite);
						$('.comment_show').click(ShowThreshold);
						$('.comment_hide').click(HideThreshold);
					}
					
				});
			}
		});
				
	}
		
}

function CloseCaptchas(){
	$('.reply_comment_item').each(function(){
		$(this).hide('fast');
	});
	
	showRecaptcha('div_captcha', 'submit_button_1', 'red'); 
	
}

function InsertCommentBox(){
	//get reply comment container; generate from php
	
	id = $(this).attr("id").substr(14); 
	//hide all previous textarea boxes
	$('div.reply_comment_item').each(function(){
		current_id = $(this).attr("id").substr(19);
		if(id != current_id)
			$(this).hide('fast');
	});
			
	$("div#reply_comment_item_" + id).toggle(1000);
	//showRecaptcha('div_captcha_' + id, 'submit_button_1', 'red');
}

function InsertCommentBoxSite(){
	//get reply comment container; generate from php
	
	id = $(this).attr("id").substr(14); 
	//hide all previous textarea boxes
	$('div.reply_comment_item').each(function(){
		current_id = $(this).attr("id").substr(19);
		if(id != current_id)
			$(this).hide('fast');
	});
			
	$("div#reply_comment_item_" + id).toggle(1000);
	showRecaptcha('div_captcha_' + id, 'submit_button_1', 'red');
	$('.but_reply_comment').click(replyComment);
	$('.but_reply_comment_site').click(replyCommentSite);
}

function AllowOneCheck(){
	id = $(this).attr('id');
	
	$("input[@name=orders]:checked").each(function()
	{
		if(id != $(this).attr("id")){
			this.checked = false;
			
			label_id = $(this).attr('id');
		
			$('label').attr("for", function(){
				if($(this).attr("for") == label_id){
					$(this).removeClass("chosen");
				}	
			});		
			
		}	
	
	});
	
	 
}

function toggleWindow(){
	link_text = $(this).text();
	
	if(link_text.indexOf('Show') != -1){
		$(this).text("Hide Order Filters");
		id = 1; //window active
		$("#div_toggle_filters").removeClass("toggle_filters_link");
	}
	else{
		$(this).text("Show Order Filters");
		id = 2;
		$("#div_toggle_filters").addClass("toggle_filters_link");
	}
	
	$.post('?save_toggle_option', {option:id}, function(response) {
		
	});
	
	$('#filters_window').toggle(1000);
	return false;
}

function DeleteSelectedComments(){
	
	var string = '0';	
	
	$("input[@name=comments]:checked").each(function()
	{
		string = string + ',' + $(this).val();
	
	});
	
	if(string == '0')
		return false;
	else	
		document.location = '?delete_comments=' + string;
}

function DeleteCommentReports(){
	
	var string = '0';	
	
	$("input[@name=comments]:checked").each(function()
	{
		string = string + ',' + $(this).val();
	
	});
	
	if(string == '0')
		return false;
	else	
		document.location = '?mass_delete_comment_reports=' + string;
}

function DeleteRantReports(){
	
	var string = '0';	
	
	$("input[@name=rants]:checked").each(function()
	{
		string = string + ',' + $(this).val();
	
	});
	
	if(string == '0')
		return false;
	else	
		document.location = '?mass_delete_rant_reports=' + string;
}

function DeleteSelectedRants(){
	
	id = $(this).attr("class");
	
	extra_get = id.split(" ");
	
	if(extra_get[1] != null){
		extra_get[1] = extra_get[1].substr(4);
		get_param = '&list=' + extra_get[1];
	}
	else
		get_param = '';		
	
	var string = '0';	
	
	$("input[@name=rants]:checked").each(function()
	{
		string = string + ',' + $(this).val();
	
	});
	
	if(string == '0')
		return false;
	else	
		document.location = '?delete_rants=' + string + get_param;
}

function SelectAllCheckboxes(){
		
	var checked_status = this.checked;
	$("input[@name=comments]").each(function()
	{
		this.checked = checked_status;
	
	});
		
}

function SelectAllCheckboxesRants(){
		
	var checked_status = this.checked;
	$("input[@name=rants]").each(function()
	{
		this.checked = checked_status;
	
	});
		
}

function getImages(){
	id = $(this).attr("id").substr(7);
	$('div#rants').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');
	
	$.post('?get_images', {ramble_id:id}, function(response) {
		$('div#rants').html(response);
	});
	
}

function getVideos(){
	id = $(this).attr("id").substr(7);
	
	$('div#rants').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');
	
	$.post('?get_videos', {ramble_id:id}, function(response) {
		$('div#rants').html(response);
	});
	
}

function reportRamble(){
	id = $(this).attr("id").substr(14);
	
	$.post('?report_ramble', {ramble_id:id}, function(response) {
		update = response.split("|||");
		if(update[0] == 1){
			//replace report it link with span
			//remove report link
			if($('#report_ramble_' + id).length > 0)
				$('#report_ramble_' + id).remove();
			comment = $('#div_report_ramble_' + id).html();
			$('#div_report_ramble_' + id).html(comment + ' <span class="tools">Report sent!</span>');
		}
	});
}

function reportRant(){
	id = $(this).attr('id').substr(7);
	
	$.post('?report_rant', {rant_id:id}, function(response) {
		update = response.split("|||");
		if(update[0] == 1){ //succes
			
			//replace report it link with span
			//remove report link
			if($('#report_' + id).length > 0)
				$('#report_' + id).remove();
			comment = $('#rant_description_' + id).html();
			$('#rant_description_' + id).html(comment + ' <span class="report_rant_sent" id="report_' + id + '">Report sent!</span>');
		}
	});
}

function saveOrderList(){
	$('#order_button').attr("value", "Saving...");
	$('#order_button').attr("disabled", "true");
	
	ids = '';
	values = '';
	
	$('.ord_id').each(function() {
 		ids += ',' + $(this).attr("id").substr(7);
 		value = $(this).val();
 		if(value.length == 0)
 			value = 0;
 		
 		values += ',' + value;	
	}); 
	
	//remove first comma
	ids = ids.substr(1);
	values = values.substr(1);
	
	//everything ok; send AJAX request
	$.post('?bookmarks_save_order', {ids:ids,values:values}, function(response) {
		update = response.split('|||');
		if(update[0] == 1){
			$('#order_button').attr("value", "Saved...");
			$('#order_button').attr("disabled", "true");
			
			msg = ErrorMsg("List saved. Hit refresh.", 1);
			$('#order_error').html(msg);
			return;
		}
		else
			$('#order_button').attr("value", "Save Order");
			$('#order_button').attr("disabled", "false");
			msg = ErrorMsg("Error...", 0);
			$('#order_error').html(msg);
			return;
	});
		
}

function addFavorite(){
	prefix = $(this).attr('id').split('_');
	if(prefix[0] == 'feat'){//featured ramble
		id = $(this).attr('id').substr(19);
		div_id = "div_featured_wash_option_" + id;
		//check if featured ramble is also in the top rambles list
		if ($("#div_wash_option_" + id).length > 0)
			div_id2 = "div_wash_option_" + id;
		else
			div_id2 = '';	
		
	
	}
	else{
		id = $(this).attr('id').substr(14);
		div_id = "div_wash_option_" + id;
		
		//check if ramble is also in the featured ramble box
		if ($("#div_featured_wash_option_" + id).length > 0)
			div_id2 = "div_featured_wash_option_" + id;
		else
			div_id2 = '';
	}
	
	
	$.post('?add_favorite', {ramble_id:id}, function(response) {
		update = response.split("|||");
		if(update[0] == 1){ //transform link if operation is successful
			$('#' + div_id).html('<img src="' + LAYOUTS + 'images/favorite_1.gif" style="vertical-align: middle" />&nbsp;&nbsp;<a href="javascript: void(0);" class="tools">Favorite</a>');
			if(div_id2 != ''){
					
				$('#' + div_id2).html('<img src="' + LAYOUTS + 'images/favorite_1.gif" style="vertical-align: middle" />&nbsp;&nbsp;<a href="javascript: void(0);" class="tools">Favorite</a>');
			} 
			
		}
	});
}

function ShoutsTab1(){
	$('#shout_section').css({display: 'none'});
	$('#rant_tab_menu').html('<div id="bookmarks_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab.gif\'); background-repeat: no-repeat;"><a href="javascript: void(0);" class="who" id="shout_bookmark">Bookmark It</a></div><div id="comments_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab.gif\'); background-repeat: no-repeat; "><a href="javascript: void(0);" class="who" id="shout_shout">Shout It</a></div><div id="who_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab_active.gif\'); background-repeat: no-repeat; ">Email it</div>');
				
	$('#email_section').css({display: 'block'});
	$('#bookmarks_section').css({display: 'none'});
	
	//reload events
	$('#shout_email').click(ShoutsTab1);
	
	$('#shout_shout').click(ShoutsTab2);
	
	$('#shout_bookmark').click(ShoutsTab3);
}

function ShoutsTab2(){
	$('#shout_section').css({display: 'block'});
	$('#rant_tab_menu').html('<div id="bookmarks_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab.gif\'); background-repeat: no-repeat;"><a href="javascript: void(0);" class="who" id="shout_bookmark">Bookmark It</a></div><div id="comments_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab_active.gif\'); background-repeat: no-repeat; ">Shout It</div><div id="who_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab.gif\'); background-repeat: no-repeat; "><a href="javascript: void(0);" class="who" id="shout_email">Email it</a></div>');
				
	$('#email_section').css({display: 'none'});
	$('#bookmarks_section').css({display: 'none'});
	
	//reload events
	$('#shout_email').click(ShoutsTab1);
	
	$('#shout_shout').click(ShoutsTab2);
	
	$('#shout_bookmark').click(ShoutsTab3);
}

function ShoutsTab3(){
	$('#bookmarks_section').css({display: 'block'});
	$('#rant_tab_menu').html('<div id="bookmarks_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab_active.gif\'); background-repeat: no-repeat;">Bookmark It</div><div id="comments_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab.gif\'); background-repeat: no-repeat; "><a href="javascript: void(0);" class="who" id="shout_shout">Shout It</a></div><div id="who_tab" style="background: url(\'' + LAYOUTS + 'images/rant_tab.gif\'); background-repeat: no-repeat; "><a href="javascript: void(0);" class="who" id="shout_email">Email it</a></div>');
				
	$('#email_section').css({display: 'none'});
	$('#shout_section').css({display: 'none'});
	
	//reload events
	$('#shout_email').click(ShoutsTab1);
	
	$('#shout_shout').click(ShoutsTab2);
	
	$('#shout_bookmark').click(ShoutsTab3);
}

function sendShouts(){
	//get selected friends
	var users = '0';
	
	$('.selected').each(function() {
 		users += ',' + $(this).attr("id");
	}); 
	
	if(users == '0'){
		msg = ErrorMsg("Please select at least one friend.", 0);
		$('div#submit_shout_error').html(msg);
		return;
	}
	
	id = document.frmShareModal.ramble_id.value;
	msg = document.frmShareModal.msg.value;
	
	$('div#submit_shout_error').html('<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> Sending...');
	AjaxSendShouts(users);
	
	
}

function AjaxSendShouts(users){
	id = document.frmShareModal.ramble_id.value;
	msg = document.frmShareModal.msg.value;
	
	$.post('?send_shouts', {ids:users,ramble_id:id,message:msg}, function(response) {
			update = response.split("|||");
			if(update[0] == 0){
				msg = ErrorMsg(update[1], 0);
				$('div#submit_shout_error').html(msg);
				return;
			}
			else if(update[0] == 1 && update[1] != 'Finished.'){
				users = update[2];
				msg = '<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> ' + update[1]; 
				$('div#submit_shout_error').html(msg);
				AjaxSendShouts(users);
			}
			else{
				msg = ErrorMsg("All email have been sent!", 1);
				$('div#submit_shout_error').html(msg);				
				return;
			}
				
				
	});
}

function switchFriendsBackground(){
	$(this).toggleClass("selected");
}

function selectAllFriends(){
	$('.friends_share').toggleClass("selected");
	
}

function switchFooter(){
	
	if(switchFooterId == 0){
		$('#layout_07').css({display: 'none'});
		$('#layout_07_small').css({display: 'block'});
		switchFooterId = 1;
		
	}
	else{
		$('#layout_07').css({display: 'block'});
		$('#layout_07_small').css({display: 'none'});
		switchFooterId = 0;
	}
	
	$.post('index.php?set_footer_option', {option:switchFooterId}, function(response) {
		return;
	});	
	
	
}

function shareRant(){
	id = document.shareRant.ramble_id.value;
	msg = document.shareRant.msg.value;
	sub = document.shareRant.subject.value;
	var arr = new Array();
	arr[0] = '';
	for(i=1;i<9;i++){
		email = eval("document.shareRant.email" + i);
		arr[i] = email.value;
		email.value = '';
	}
	
	if(id == null || msg == null)
		return;
	
	$('div#submit_comment_error').html('<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> Proccessing...');
	$.post('?share_rant', {ramble_id:id,message:msg,email1:arr[1],email2:arr[2],email3:arr[3],email4:arr[4],email5:arr[5],email6:arr[6],email7:arr[7],email8:arr[8],subject:sub}, function(response) {
		update = response.split("|||");
		if(update[0] == 0){ //error
			msg = ErrorMsg(update[1], 0);
			$('div#submit_comment_error').html(msg);
			return;
		}
		else{
			msg = ErrorMsg("Email has been sent.", 1);
			$('div#submit_comment_error').html(msg);
			return;
		}
		
	}); 
}

function getBurners(){
	link_id = $(this).attr('id');
	arr = link_id.split("_");
	//arr[0] - next || previous
	//arr[1] - ramble_id
	//arr[2] - desired page
	
	if(arr[1] == null || arr[2] == null)
		return;
	
	$('div#burners').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');
		
	if($(this).attr('class').indexOf('friends') != -1){
		$.post('?get_burners', {ramble_id:arr[1],pag:arr[2],friends:1}, function(response) {
		$('div#burners').html(response);
	
		$(".pag_ajax").click(getBurners);
	
		});
	}	
	else{
		$.post('?get_burners', {ramble_id:arr[1],pag:arr[2]}, function(response) {
			$('div#burners').html(response);
		
			$(".pag_ajax").click(getBurners);
		
		});
	}
}

function sortComments(){
	//get sorting value
	val = $("#sort_options").val();
	
	//get ramble id
	id = document.frmComment.ramble_id.value;
	
	if(id == null)
		return;
	$('div#rants').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');	
	if(listing_type == 0){ // all comments
		$.post('?get_all_comments', {ramble_id:id,sort:val}, function(response) {
			$('div#rants').html(response);
			
			//reload jquery ajax scripts
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
			$('.reply_comment').click(InsertCommentBox);
			$('.reply_comment_site').click(InsertCommentBoxSite);
			$('.but_reply_comment').click(replyComment);
			$('.but_reply_comment_site').click(replyCommentSite);
			$('.comment_replies').click(ShowCommentReplies);
			$('.comment_show').click(ShowThreshold);
			$('.comment_hide').click(HideThreshold);
			$('.comments_next_page').click(CommentsNextPage);
		});
	}
	else if(listing_type == 1){ // my comments
		$.post('?get_my_comments', {ramble_id:id,sort:val}, function(response) {
			$('div#rants').html(response);
			
			//reload jquery ajax scripts
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
			$('.reply_comment').click(InsertCommentBox);
			$('.reply_comment_site').click(InsertCommentBoxSite);
			$('.but_reply_comment').click(replyComment);
			$('.but_reply_comment_site').click(replyCommentSite);
			$('.comment_replies').click(ShowCommentReplies);
			$('.comment_show').click(ShowThreshold);
			$('.comment_hide').click(HideThreshold);
			$('.comments_next_page').click(CommentsNextPage);
		});
	}
	else{//friends comments		
		$.post('?get_friends_comments', {ramble_id:id,sort:val}, function(response) {
			$('div#rants').html(response);
			
			//reload jquery ajax scripts
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
			$('.reply_comment').click(InsertCommentBox);
			$('.reply_comment_site').click(InsertCommentBoxSite);
			$('.but_reply_comment').click(replyComment);
			$('.but_reply_comment_site').click(replyCommentSite);
			$('.comment_replies').click(ShowCommentReplies);
			$('.comment_show').click(ShowThreshold);
			$('.comment_hide').click(HideThreshold);
			$('.comments_next_page').click(CommentsNextPage);
		});
	}	 
}

//used on the sorting comments function
//0 - all; 1 - mine; 2 - friends
var listing_type = 0;

function AllComments(){
	$('div#rants').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');
	
	id = $(this).attr('class').substr(7);
	$.post('?get_all_comments', {ramble_id:id}, function(response) {
		$('div#rants').html(response);
		
		//reload jquery ajax scripts
		$('.comment_burns').click(switchBurnsView);
		$('.comment_burns_over').click(switchBurnsView);
		$('.rant_burn').click(rateRant);
		$('.rant_wash').click(rateRant);
		$('.reply_comment').click(InsertCommentBox);
		$('.reply_comment_site').click(InsertCommentBoxSite);
		$('.but_reply_comment').click(replyComment);
		$('.but_reply_comment_site').click(replyCommentSite);
		$('.comment_replies').click(ShowCommentReplies);
		$('.comments_next_page').click(CommentsNextPage);
		$('.comment_show').click(ShowThreshold);
		$('.comment_hide').click(HideThreshold);
	});
	listing_type = 1;
}

function OnlyMyComments(){
	$('div#rants').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');
	
	id = $(this).attr('class').substr(7);
	$.post('?get_my_comments', {ramble_id:id}, function(response) {
		$('div#rants').html(response);
		
		//reload jquery ajax scripts
		$('.comment_burns').click(switchBurnsView);
		$('.comment_burns_over').click(switchBurnsView);
		$('.rant_burn').click(rateRant);
		$('.rant_wash').click(rateRant);
		$('.reply_comment').click(InsertCommentBox);
		$('.reply_comment_site').click(InsertCommentBoxSite);
		$('.but_reply_comment').click(replyComment);
		$('.but_reply_comment_site').click(replyCommentSite);
		$('.comment_replies').click(ShowCommentReplies);
		$('.comments_next_page').click(CommentsNextPage);
		$('.comment_show').click(ShowThreshold);
		$('.comment_hide').click(HideThreshold);
	});
	listing_type = 1;
}

function OnlyFriendsComments(){
	$('div#rants').html('<div style="text-align: center"><img src="' + LAYOUTS + 'images/load2.gif" style="vertical-align: middle" /></div>');
	
	id = $(this).attr('class').substr(7);
	$.post('?get_friends_comments', {ramble_id:id}, function(response) {
		$('div#rants').html(response);
		
		//reload jquery ajax scripts
		$('.comment_burns').click(switchBurnsView);
		$('.comment_burns_over').click(switchBurnsView);
		$('.rant_burn').click(rateRant);
		$('.rant_wash').click(rateRant);
		$('.reply_comment').click(InsertCommentBox);
		$('.reply_comment_site').click(InsertCommentBoxSite);
		$('.but_reply_comment').click(replyComment);
		$('.but_reply_comment_site').click(replyCommentSite);
		$('.comment_replies').click(ShowCommentReplies);
		$('.comments_next_page').click(CommentsNextPage);
		$('.comment_show').click(ShowThreshold);
		$('.comment_hide').click(HideThreshold);
	});
	listing_type = 2;
	
}

function addComment(){
	
	text = document.frmComment.comment.value;
	text = url_encode(text);
	document.frmComment.comment.value = '';
	
	if(text == null || text == '' || text == ' '){
		msg = ErrorMsg("The comment field is blank. Please try again.", 0);
		$('div#submit_comment_error').html(msg);
		return;
	}
	
	id = document.frmComment.ramble_id.value; 
	
	msg = '<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> Processing...'; 
	$('div#submit_comment_error').html(msg);
	
	$.post('?add_comment', {comment:text,ramble_id:id}, function(response) {
		update = response.split("|||");
		if(update[0] == 0){ //error
			msg = ErrorMsg(update[1], 0);
			$('div#submit_comment_error').html(msg);
			return;
		}
		else{
			//see if this is the 1st comment; must remove "no comments have been posted" text
			last = $('div#rants').html();
			if(last.indexOf("No comments have been posted...") != -1)
				$('ul#comments_main').html(response);
			else
				$('ul#comments_main').append(response);
					
			//update number of comments in tab			
			comments = $('div#comments_tab').text();		
			
			count = comments.split(" ");
			old_value = parseInt(count[0], 10);
			new_value = old_value+1;
			$('div#comments_tab').text(new_value + " Comments");
			
			//update "Only Mine" number of comments
			span_id = $('.only_mine_comments').attr('id').substr(9);
			comments = parseInt(span_id, 10);
			new_value = comments + 1;
			
			ramble_id = id;
			
			$('#comments_' + span_id).html('<a id="only_my_comments" href="javascript: void(0);" class="ramble_' + ramble_id + '" style="font-size: 12px">Only Mine (' + new_value + ')</a>');
			
			$('#only_my_comments').click(OnlyMyComments);	
			
			$('div#submit_comment_error').html("<img src='"+LAYOUTS+"images/icon_msg_1.gif' style='vertical-align: middle' /> <span class='greenerror'>Comment successfully added.</span>");
			
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
			$('.reply_comment').click(InsertCommentBox);
			$('.reply_comment_site').click(InsertCommentBoxSite);
			$('.but_reply_comment').click(replyComment);
			$('.but_reply_comment_site').click(replyCommentSite);
			$('.comment_replies').click(ShowCommentReplies);
			$('.comment_show').click(ShowThreshold);
			$('.comment_hide').click(HideThreshold);
		}
						
	});
		
}

function addCommentSite(){
	
	text = document.frmComment.comment.value;
	text = url_encode(text);
	//document.frmComment.comment.value = '';
	
	if(text == null || text == '' || text == ' '){
		msg = ErrorMsg("The comment field is blank. Please try again.", 0);
		$('div#submit_comment_error').html(msg);
		return;
	}
	
	msg = '<img src="' + LAYOUTS + 'images/load.gif" style="vertical-align: middle" /> Processing...'; 
	$('div#submit_comment_error').html(msg);
	
	if(document.frmComment.recaptcha_challenge_field){
		
		challenge = document.frmComment.recaptcha_challenge_field.value;
		response = document.frmComment.recaptcha_response_field.value;
		
		if(response == null || response == '' || response == ' '){
			msg = ErrorMsg("Spam Validation Failed! Try refreshing the code.", 0);
			$('div#submit_comment_error').html(msg);
			return;
		}
		
		$.post('?check_captcha', {recaptcha_challenge_field:challenge,recaptcha_response_field:response}, function(response) {
			captcha_check = response;
			
			if(captcha_check == 0){
				msg = ErrorMsg("Spam Validation Failed! Try refreshing the code.", 0);
				$('div#submit_comment_error').html(msg);
				return false;
			}
			else{ //captcha check is valid	
				id = document.frmComment.ramble_id.value; 
	
				$.post('?add_comment', {comment:text,ramble_id:id}, function(response) {
						
					update = response.split("|||");
					if(update[0] == 0){ //error
						msg = ErrorMsg(update[1], 0);
						$('div#submit_comment_error').html(msg);
						return;
					}
					else{
						document.frmComment.comment.value = '';
						//see if this is the 1st comment; must remove "no comments have been posted" text
						last = $('div#rants').html();
						if(last.indexOf("No comments have been posted...") != -1)
							$('ul#comments_main').html(response);
						else
							$('ul#comments_main').append(response);
						
						comments = $('div#comments_tab').text();		
			
						count = comments.split(" ");
						old_value = parseInt(count[0], 10);
						new_value = old_value+1;
						$('div#comments_tab').text(new_value + " Comments");
								
						$('div#submit_comment_error').html("<img src='"+LAYOUTS+"images/icon_msg_1.gif' style='vertical-align: middle' /> <span class='greenerror'>Comment successfully added.</span>");
						
						$('.comment_burns').click(switchBurnsView);
						$('.comment_burns_over').click(switchBurnsView);
						$('.rant_burn').click(rateRant);
						$('.rant_wash').click(rateRant);
						$('.reply_comment').click(InsertCommentBox);
						$('.reply_comment_site').click(InsertCommentBoxSite);
						$('.but_reply_comment').click(replyComment);
						$('.but_reply_comment_site').click(replyCommentSite);
						$('.comment_replies').click(ShowCommentReplies);
						$('.comment_show').click(ShowThreshold);
						$('.comment_hide').click(HideThreshold);
					}
					
				});
			}
		});
				
	}
		
}

function rateRant(){
	//meaning of responses
	//0-error
	//1|||no burns|||no washes - burn;no rating
	//2|||no burns|||no washes - burn; previously washed; rating deleted
	//3|||no burns|||no washes - wash;no rating
		
	id = $(this).attr('id').substr(10);
	
	if($(this).attr('class') == 'rant_burn')
		type = 1;
	else
		type = 0;	
	
	$.post('?rate_rant', {rating:type, rant_id:id}, function(response) {
		update = response.split("|||");
		if(update[0] == 1){ //comment burned
						
			//hide burn button
			$('#rant_options_' + id).html("<img src='"+LAYOUTS+"images/burn_0.png'> <a id='rant_wash_" + id + "' class='rant_wash' href='javascript: void(0);'><img src='" + LAYOUTS + "images/wash_1.png' border='0' /></a>");	
			//update no burns
			
			dif = update[1]-update[2];
			if(dif == 1)
				burn_text = 'burn';
			else
				burn_text = 'burns';
					
			if(update[1] != 0)
				burns = '<span style="font-weight: bold">+' + update[1] + '</span>';
			else
				burns = 0;	
			
			if(update[2] != 0)
				washes = '-' + update[2];
			else
				washes = 0;
						
			$('#rant_burns_' + id).html("<a href='javascript: void(0);' class='comment_burns'><span style='font-weight: bold'>" + dif + "</span> " + burn_text + "</a>" + "<a href='javascript: void(0);' class='comment_burns_over' style='display: none'>" + burns + " / " + washes + "</a>");
			
			//remove report it option if present
			if($('#report_' + id).length > 0)
				$('#report_' + id).remove();
			
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
		}
		else if(update[0] == 2){ //rating deleted
								
			//show both buttons
			$('#rant_options_' + id).html("<a id='rant_burn_" + id + "' class='rant_burn' href='javascript: void(0);'><img src='"+LAYOUTS+"images/burn_1.png' border='0' /></a> <a id='rant_wash_" + id + "' class='rant_wash' href='javascript: void(0);'><img src='" + LAYOUTS + "images/wash_1.png' border='0' /></a>");
		
			//update no burns
			
			dif = update[1]-update[2];
			if(dif == 1)
				burn_text = 'burn';
			else
				burn_text = 'burns';
					
			if(update[1] != 0)
				burns = '<span style="font-weight: bold">+' + update[1] + '</span>';
			else
				burns = 0;	
			
			if(update[2] != 0)
				washes = '-' + update[2];
			else
				washes = 0;
						
			$('#rant_burns_' + id).html("<a href='javascript: void(0);' class='comment_burns'><span style='font-weight: bold'>" + dif + "</span> " + burn_text + "</a>" + "<a href='javascript: void(0);' class='comment_burns_over' style='display: none'>" + burns + " / " + washes + "</a>");
			
			//remove report it option if present
			if($('#report_' + id).length > 0)
				$('#report_' + id).remove();
			
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);	
		}
		else if(update[0] == 3){ //comment washed
			
			//hide wash button
			//show both buttons
			$('#rant_options_' + id).html("<a id='rant_burn_" + id + "' class='rant_burn' href='javascript: void(0);'><img src='"+LAYOUTS+"images/burn_1.png' border='0' /></a> <img src='" + LAYOUTS + "images/wash_0.png' border='0' />");
		
			//update no burns
			
			dif = update[1]-update[2];
			if(dif == 1)
				burn_text = 'burn';
			else
				burn_text = 'burns';
					
			if(update[1] != 0)
				burns = '<span style="font-weight: bold">+' + update[1] + '</span>';
			else
				burns = 0;	
			
			if(update[2] != 0)
				washes = '-' + update[2];
			else
				washes = 0;
						
			$('#rant_burns_' + id).html("<a href='javascript: void(0);' class='comment_burns'><span style='font-weight: bold'>" + dif + "</span> " + burn_text + "</a>" + "<a href='javascript: void(0);' class='comment_burns_over' style='display: none'>" + burns + " / " + washes + "</a>");
			
			//comment washed; display Report option at end of comment
			comment = $('#rant_description_' + id).html();
			$('#rant_description_' + id).html(comment + ' <a class="report_rant" id="report_' + id + '" href="javascript: void(0);">Report It</a>');
			
			//report 
			$('.report_rant').click(reportRant);
			
			$('.comment_burns').click(switchBurnsView);
			$('.comment_burns_over').click(switchBurnsView);
			$('.rant_burn').click(rateRant);
			$('.rant_wash').click(rateRant);
		}
		else{
			//alert(response);
		}
	
	});

	
	return;
}


var switchAdvancedId = 0;
 
function switchAdvancedOptions(){
	if(switchAdvancedId == 0){
	$('#advanced_options_container').css({display: "block"});
	switchAdvancedId = 1;
	}
	else{
	$('#advanced_options_container').css({display: "none"});
	switchAdvancedId = 0;
	} 
} 


var switchViewId = 0;

function switchBurnsView(){
	//alert('aaa');
	
	if(switchViewId == 0){
		$('.comment_burns').css({display: "none"});
		$('.comment_burns_over').css({display: "inline"});
		switchViewId = 1;
	}
	else{
		$('.comment_burns_over').css({display: "none"});
		$('.comment_burns').css({display: "inline"});
		switchViewId = 0;
	}
}

function save_orders(){
	var arr = getSelectedCheckbox(document.frm_order.orders);
	
	var sort = document.frm_order.sort_type.value;
	//1 == ascending
	//2 == descending
		
	if(arr.length != 0){
		$.get('index.php?save_orders=' + arr + '&sort=' + sort, function(response) {
			update = response.split('|||');
			if(update[1] == 'success'){
				$('#save_orders').attr("value", "Saved");
				$('#save_orders').attr("disabled", "true");
				$('#filter_message').html("<img src='"+LAYOUTS+"images/icon_msg_1.gif' style='vertical-align: middle' /> Filters saved. Hit refresh to apply.");
			}
			
			
		});
	}
	else{
		$.get('index.php?save_orders=3' + '&sort=' + sort, function(response) {
			update = response.split('|||');
			if(update[1] == 'success'){
				$('#save_orders').attr("value", "Saved");
				$('#save_orders').attr("disabled", "true");
				$('#filter_message').html("<img src='"+LAYOUTS+"images/icon_msg_1.gif' style='vertical-align: middle' /> Filters saved. Hit refresh to apply.");
			}
			
			
		});
	}
}

function setTimeTab(){

	link_id = $(this).attr('id').substr(8);
	
	for(i = 1; i< 6; i++)
		$('a#time_tab' + i).css({color: "#745610"});
	
	$('a#' + $(this).attr('id')).css({color: "#ff620e"});
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Please install the newest version for your browser!");
	  return;
	} 
	
	var url="index.php?settimetab="+link_id;
	
	url=url+"&sid="+Math.random();
			
	xmlHttp.onreadystatechange=putTimeTab;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	arr = new Array();
	arr[0] = '';
	arr[1] = '';
	arr[2] = '24hrs/';
	arr[3] = '7days/';
	arr[4] = '30days/';
	arr[5] = '365days/';
	
	//replace category links
	$('a').filter(function() {
		//return ($(this).attr('href').indexOf('/category') >= 0 && $(this).attr('class').indexOf('link_recent') < 0);
		return ( ($(this).attr('href').indexOf('/all') >= 0 || $(this).attr('href').indexOf('/life') >= 0 || $(this).attr('href').indexOf('/technology') >= 0 || $(this).attr('href').indexOf('/gaming') >= 0 || $(this).attr('href').indexOf('/politics') >= 0 || $(this).attr('href').indexOf('/business') >= 0 || $(this).attr('href').indexOf('/sports') >= 0 || $(this).attr('href').indexOf('/off-topic') >= 0) && $(this).attr('class').indexOf('link_recent') < 0 );
	
	
	}).each(function() {
		
		//correct links; prevent from adding in loop: 24/hrs/7days/24hrs
		link = $(this).attr('href');
		link_length = link.length;
		
		if(link.indexOf('24hrs/') >= 0){
			correct_link = link.substr(0,(link_length - 6));
		}
		else if(link.indexOf('7days/') >= 0){
			correct_link = link.substr(0,(link_length - 6));
		}
		else if(link.indexOf('30days/') >= 0){
			correct_link = link.substr(0,(link_length - 7));
		}
		else if(link.indexOf('365days/') >= 0){
			correct_link = link.substr(0,(link_length - 8));
		}
		else{
			correct_link = link;
		}
		$(this).attr('href', correct_link + arr[link_id]);
		
	})
	
	//replace tags links
	$('a').filter(function() {
		return ($(this).attr('href').indexOf('/tags') >= 0);
	}).each(function() {
		
		//correct links; prevent from adding in loop: 24/hrs/7days/24hrs
		link = $(this).attr('href');
		link_length = link.length;
		
		if(link.indexOf('24hrs/') >= 0){
			correct_link = link.substr(0,(link_length - 6));
		}
		else if(link.indexOf('7days/') >= 0){
			correct_link = link.substr(0,(link_length - 6));
		}
		else if(link.indexOf('30days/') >= 0){
			correct_link = link.substr(0,(link_length - 7));
		}
		else if(link.indexOf('365days/') >= 0){
			correct_link = link.substr(0,(link_length - 8));
		}
		else{
			correct_link = link;
		}
		$(this).attr('href', correct_link + arr[link_id]);
		
	})
	
}

function putTimeTab(){
	if (xmlHttp.readyState==4){
		response=xmlHttp.responseText;	
		
	}			
}


function change_label_color(){
	
	label_id = $(this).attr('id');
				
	$('label#' + label_id).toggleClass('chosen');
	
}

function modal_div(){
					
		washid = $(this).attr('id').substr(5);
		wash_width = $('div#rambles_'+washid).width();
		wash_height = $('div#rambles_'+washid).height();
		
		
		wash_left = 0;
		if ($.browser.msie){
			
			if(wash_height == 0){		
				wash_height = 107;
				wash_width = 688 - 54;
			}	
			
			if($.browser.version == '6.0')
				wash_left = -460;
			else	
				wash_left = 0;	
		}
		else{
			
		}
		
		wash_top = 0;	
				
		$('div.inline-warning').remove();	
		$('div.featured-warning').remove();	
		remove_opacity();
		
		if(washid != 'f1'){//not featured ramble						
			
			$('div#rambles_'+washid).prepend('<div id="ramble_child" class="inline-warning" style="left: '+wash_left+'; width: '+wash_width+'px; height: '+wash_height+'px;"><div><p><strong>Share your day, have an attitude.</strong> Please <a href="'+ HTTP +'login">login</a> or <a href="' + HTTP + 'create">join FlameUp</a> for free. <img src="' + LAYOUTS + 'images/wash.gif" style="vertical-align: middle; cursor: pointer" onclick="javascript: HideDiv(\'ramble_child\')" border="0" /></p></div></div>');
		}
		else{
			
			wash_height = 122;
			wash_left = 0;
			if ($.browser.msie){
				$('div.opacity').css({filter: "alpha(opacity = 30)"});
				if($.browser.version == '6.0')
					wash_left = -50;
			}
			else
				$('div.opacity').css({opacity: 0.3});
			
			$('div.featured').prepend('<div id="ramble_child" class="featured-warning" style="left: '+wash_left+'; width: '+wash_width+'px; height: '+wash_height+'px; margin-top: 45px;"><div style="margin-left: 30px"><p><strong>Share your day, have an attitude.</strong> Please <a href="' + HTTP + 'login">login</a> or <a href="' + HTTP + 'create">join FlameUp</a> for free. <img src="' + LAYOUTS + 'images/wash.gif" style="vertical-align: middle; cursor: pointer" onclick="javascript: HideDiv(\'ramble_child\')" border="0" /></p></div></div>');
		}
}

function remove_opacity(){
	if ($.browser.msie)
		$('div.opacity').css({filter: "alpha(opacity = 100)"});
	else
		$('div.opacity').css({opacity: 1});
}

var switchGoogleMailId = 0;

function switchGoogleMail(){
	if(switchGoogleMailId == 0){
		$('#google_mail_container').css({display: "block"});
		switchGoogleMailId = 1;
	}
	else{
		$('#google_mail_container').css({display: "none"});
		switchGoogleMailId = 0;
	}	
}

var switchYahooMailId = 0;

function switchYahooMail(){
	if(switchYahooMailId == 0){
		$('#yahoo_mail_container').css({display: "block"});
		switchYahooMailId = 1;
	}
	else{
		$('#yahoo_mail_container').css({display: "none"});
		switchYahooMailId = 0;
	}	
}

var switchMSNMailId = 0;

function switchMSNMail(){
	if(switchMSNMailId == 0){
		$('#msn_mail_container').css({display: "block"});
		switchMSNMailId = 1;
	}
	else{
		$('#msn_mail_container').css({display: "none"});
		switchMSNMailId = 0;
	}	
}


var switchAOLMailId = 0;

function switchAOLMail(){
	if(switchAOLMailId == 0){
		$('#aol_mail_container').css({display: "block"});
		switchAOLMailId = 1;
	}
	else{
		$('#aol_mail_container').css({display: "none"});
		switchAOLMailId = 0;
	}	
}


var switchCVSMailId = 0;

function switchCVSMail(){
	if(switchCVSMailId == 0){
		$('#cvs_mail').css({display: "block"});
		switchCVSMailId = 1;
	}
	else{
		$('#cvs_mail').css({display: "none"});
		switchCVSMailId = 0;
	}	
}