function CheckSelected(checkboxes)
{
	var idArray = $(checkboxes).map(function ()
	{
		return $(this).val();
	});

	return $.makeArray(idArray).join(','); 
}

function append(this_string, that_string)
{
	if(that_string != '')
		that_string += '&' + this_string;
	else
		that_string = '/?' + this_string

	return that_string;	
}

function goPage(url, search_query, tag_query, category_query)
{
	query_string = '';

	if(tag_query != '')
		query_string = append('tag=' + tag_query, query_string);
	if(category_query != '')
		query_string = append('cat=' + category_query, query_string);
	if(search_query != '')
		query_string = append('s=' + search_query, query_string);

	$('#background_image_form').attr('action', url + query_string);
	$('#background_image_form').submit();
}

$(document).ready(function()
{
	
	$("form#states #cats").tooltip({ relative: "false", position: "bottom left"});
    
	$("#states_all").click(function() {
		$("#filters input[type=checkbox]").attr('checked', true);
	});
	
	$("#states_none").click(function() {
		$("#filters input[type=checkbox]").attr('checked', false);
	});
	
	$("table").tablesorter({
		widthFixed: true,
		widgets: ['zebra'],
		headers: { 3: {sorter: false}}
	})/*.tablesorterPager({container: $("#pager")})*/;

	background_image_url = $('#domain_name').val() + '/wp-content/themes/aca/images/' + $('#background_image_file').val();
	background_image_attributes = 'background-image: url("' + background_image_url + '");';
	//$('#frontpage #background_image').attr('style', background_image_attributes);
	$('body#frontpage').attr('style', background_image_attributes);
	$('#contentpage #main_nav_image').attr('style', background_image_attributes);
       
	$('a#search_button').click(function()
	{
		$('#searchform').slideToggle(400);
		return false;
	});

	$('a[href*="files"]').addClass("file_link");
	$('a[href*="uploads"]').addClass("file_link");
	$('a[href*="mailto"]').addClass("mail_link");
	
	$('a:not(#search_button, #loginbutton, #filter_button, .external_link, .file_link, .mail_link)').click(function()
	{
		$('#background_image_form').attr('action', $(this).attr('href'));
		$(this).attr('href', "javascript:$('#background_image_form').submit()");
	});

	$('#searchsubmit').val('Find');

  $('#pass1').val('');
  

  // hide profile fields not required
  $("#profile h3:contains('Name')").hide();
  $("#profile h3:contains('Contact Info')").hide();
  $("#profile h3:contains('About Yourself')").hide();

  $("label[for='first_name']").parents('tr').hide();
  $("label[for='last_name']").parents('tr').hide();
  $("label[for='nickname']").parents('tr').hide();
  $("label[for='display_name']").parents('tr').hide();
  $("label:contains('Biographical Info')").parents('tr').hide();
  $('#jabber').parent('td').parent('tr').hide();
  $('#aim').parent('td').parent('tr').hide();
  $('#yim').parent('td').parent('tr').hide();

	// hide redundant fields for admin front side
	$("input[name='cimy_uef_STREET_ADDRESS']").parents('tr').hide();
	$("input[name='cimy_uef_STREET_ADDRESS_2']").parents('tr').hide();
	$("input[name='cimy_uef_STREET_ADDRESS_SB']").parents('tr').hide();
	$("input[name='cimy_uef_STREET_ADDRESS_PC']").parents('tr').hide();
	$("input[name='cimy_uef_FAX-PUBLIC']").parents('tr').hide();
	$("input[name='cimy_uef_WEB-ADDRESS']").parents('tr').hide();
	$("input[name='cimy_uef_EMAIL-CONTACT']").parents('tr').hide();


	// change profile page labels front side
	$("label[for='user_login']").html("Member Number");
	
	var inputuser = $("input[name='user_login']");
	$("input[name='user_login']").parent().html(inputuser);
	
	//$("#your-profile h3:contains('Practice Details')").hide();
	//$("#your-profile h3:contains('Practice')").hide();
	
  // basic required fields warning
  $("#profile input[name='cimy_uef_PRACTICE_NAME']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile input[name='email']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile input[name='cimy_uef_POSTAL_ADDRESS']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile input[name='cimy_uef_POSTAL_ADDRESS_SB']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile input[name='cimy_uef_POSTAL_ADDRESS_PC']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile select[name='cimy_uef_STATE']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile input[name='cimy_uef_PHONE-NUMBER']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});
  $("#profile input[name='cimy_uef_CONTACT-PERSON']").css({"border-color":"red", "border-width":"2px" , "border-style":"solid"});

  // change login screen text username to email
  $(".login label[for='log-tml-page']").html("Member Number or Primary Email");
  $(".login label[for='log-tml-page']").css({"border-color":"red", "border-width":"2px"});
  
  // remove error messaae form lost pass page
  $("form#lostpasswordform-tml-page").prev(".error").remove();
  
  // change username to member # on lost pass page
  $("form#lostpasswordform-tml-page label[for='user_login-tml-page']").html("Member number or Email");
  
  //expanding posts
  $("#contentpage #content_body .item p").contents().filter(function() {
  	return this.nodeType == 8;
  })
  	.replaceWith('<span class="expander">...read more</span>');

	//$("#contentpage #content_body .item p span.expander").parent().nextAll(":not('.postmeta')").wrapAll('<div class="expandingblock" />');
	
	$("#contentpage #content_body .item p span.expander").each(function() {
		$(this).parent().nextAll(":not('.postmeta')").wrapAll('<div class="expandingblock" />');
		$(this).click(function() {
			$(this).parent().next(".expandingblock").show('fast');
			$(this).remove();
		});
	});

  
  //Empty profile page inputs:
  //$('#your-profile table input').val("");
});

/*
$(window).unload(function()
{
	alert("Bye now!");
});


$.ui.dialog.defaults.bgiframe = true;
$(function() {
	$("#dialog").dialog();
});
*/

