var profFilterZoomStatus = 0;
var profFilterSortStatus = 0;
var profFilterStatus = 0;
var profFilterSelected = new Array();
var profFilterChanged = 0;

function profFilterPopSpec() {
	tmpCount = profFilterSelected.length;
	if (profFilterStatus == 1) {
		if (tmpCount > 0) {
			$("wFilterSpecialtyOpen").innerHTML = "<img src=\"/images/nav_popleft.png\" /> Filter By Specialty (" + tmpCount + ")";
			$("wFilterSpecialtyKill").className = "filter";
			$("wFilterSpecialtyKill").innerHTML = "<img src=\"/images/icon_killfilter.png\" alt=\"Clear Filter\" />";
		} else {
			$("wFilterSpecialtyOpen").innerHTML = "<img src=\"/images/nav_popleft.png\" /> Filter By Specialty";
			$("wFilterSpecialtyKill").className = "filterOff";
			$("wFilterSpecialtyKill").innerHTML = "<img src=\"/images/icon_killfilter_dis.png\" alt=\"Clear Filter\" />";
		}
		profFilterStatus = 0;
		new Effect.Fade("wFilterSpecialtyPop", {duration:0.2});
		if (profFilterChanged == 1) {
			tmpSel = "";
			for (i = 0; i < profFilterSelected.length; i++) {
				if (tmpSel != "") {
					tmpSel = tmpSel + "-";
				}
				tmpSel = tmpSel + profFilterSelected[i];
			}
			location.href = "/professionals/" + profFilterZoom + "/" + tmpSel + "/" + profFilterSort + "/1";
		}
	} else {
		if (tmpCount > 0) {
			$("wFilterSpecialtyOpen").innerHTML = "<img src=\"/images/nav_popright.png\" /> Apply Filter (" + tmpCount + ")";
			$("wFilterSpecialtyKill").className = "filter";
			$("wFilterSpecialtyKill").innerHTML = "<img src=\"/images/icon_killfilter.png\" alt=\"Clear Filter\" />";
			for (i = 0; i < profFilterSelected.length; i++) {
				$("filterSpecialty"+profFilterSelected[i]).className = "on";
			}
		} else {
			$("wFilterSpecialtyOpen").innerHTML = "<img src=\"/images/nav_popright.png\" /> Apply Filter";
			$("wFilterSpecialtyKill").className = "filterOff";
			$("wFilterSpecialtyKill").innerHTML = "<img src=\"/images/icon_killfilter_dis.png\" alt=\"Clear Filter\" />";
		}
		profFilterStatus = 1;
		new Effect.Appear("wFilterSpecialtyPop", {duration:0.2});
	}
}
function profFilterToggleSpecialty(filterSpecialty) {
	var tmpInArray = -1;
	var tmpArray = new Array();
	var tmpOut = "";
	for (i = 0; i < profFilterSelected.length; i++) {
		if (filterSpecialty == profFilterSelected[i]) {
			tmpInArray = i;
		} else {
			tmpArray.push(profFilterSelected[i]);
		}
	}
	if (tmpInArray > -1) {
		profFilterSelected = tmpArray;
		$("filterSpecialty"+filterSpecialty).className = "";
	} else {
		profFilterSelected.push(filterSpecialty);
		$("filterSpecialty"+filterSpecialty).className = "on";
	}
	tmpCount = profFilterSelected.length;
	if (tmpCount > 0) {
		$("wFilterSpecialtyOpen").innerHTML = "<img src=\"/images/nav_popright.png\" /> Apply Filter (" + tmpCount + ")";
		$("wFilterSpecialtyKill").className = "filter";
		$("wFilterSpecialtyKill").innerHTML = "<img src=\"/images/icon_killfilter.png\" alt=\"Clear Filter\" />";
	} else {
		$("wFilterSpecialtyOpen").innerHTML = "<img src=\"/images/nav_popright.png\" /> Apply Filter";
		$("wFilterSpecialtyKill").className = "filterOff";
		$("wFilterSpecialtyKill").innerHTML = "<img src=\"/images/icon_killfilter_dis.png\" alt=\"Clear Filter\" />";
	}
	profFilterChanged = 1;
}

function profFilterPopZoom() {
	var tmpPfzLabel = "";
	
	switch(profFilterZoom) {
		case "zip":
			tmpPfzLabel = "Search Zip Code";
			break;
		case "city":
			tmpPfzLabel = "Search City";
			break;
		case "metro":
			tmpPfzLabel = "Search Metro Area";
			break;
		case "state":
			tmpPfzLabel = "Search State";
			break;
		case "region":
			tmpPfzLabel = "Search Region";
			break;
		case "follow":
			tmpPfzLabel = "Search Followed";
			break;
		default:
			tmpPfzLabel = "Search Entire Site";
			break;
	}
	$("filterZoom" + profFilterZoom.capitalize()).className = "on";
	if (profFilterZoomStatus == 1) {
		$("wFilterZoomOpen").innerHTML = "<img src=\"/images/nav_popleft.png\" /> " + tmpPfzLabel;
		profFilterZoomStatus = 0;
		new Effect.Fade("wFilterZoomPop", {duration:0.2});
	} else {
		$("wFilterZoomOpen").innerHTML = "<img src=\"/images/nav_popright.png\" /> " + tmpPfzLabel;
		profFilterZoomStatus = 1;
		new Effect.Appear("wFilterZoomPop", {duration:0.2});
	}
}

function profFilterPopSort() {
	var tmpPfsLabel = "";
	
	switch(profFilterSort) {
		case "r":
			tmpPfsLabel = "Sort By Peer Reviews";
			break;
		case "u":
			tmpPfsLabel = "Sort By Recently Updated";
			break;
		default:
			profFilterSort = "a";
			tmpPfsLabel = "Sort Alphabetically";
			break;
	}
	$("filterSort" + profFilterSort.capitalize()).className = "on";
	if (profFilterSortStatus == 1) {
		$("wFilterSortOpen").innerHTML = "<img src=\"/images/nav_popleft.png\" /> " + tmpPfsLabel;
		profFilterSortStatus = 0;
		new Effect.Fade("wFilterSortPop", {duration:0.2});
	} else {
		$("wFilterSortOpen").innerHTML = "<img src=\"/images/nav_popright.png\" /> " + tmpPfsLabel;
		profFilterSortStatus = 1;
		new Effect.Appear("wFilterSortPop", {duration:0.2});
	}
}

function profFilterAutopop() {
	var tempLocation = location.hash;
	tempLocation = tempLocation.replace("?","");
	if (tempLocation != "" && tempLocation != "#") {
		tempLocation = tempLocation.replace("#","");
		switch(tempLocation) {
			case "sort":
				profFilterPopSort();
				break;
			case "spec":
				profFilterPopSpec();
				break;
			case "zoom":
				profFilterPopZoom();
				break;
		}
	}
}

var profFollowId = 0;
function profFollow(profId) {
	profFollowId = profId;
	new Ajax.Request("/data/prof_follow.php?pid=" + profId, {onSuccess: profFollowDraw});
}
function profFollowDraw(t) {
	tmpResponse = t.responseText;
	if (tmpResponse == "//followed//") {
		$("ftag_" + profFollowId).innerHTML = "<a href=\"#\" onclick=\"profFollow(" + profFollowId + ");return false;\"><img src=\"/images/tag_ax_remove_off.png\" alt=\"Stop following this professional.\" onmouseover=\"aM(this,'on');\" onmouseout=\"aM(this,'off');\" /></a>";
		alertBubbleAdd("You are now following this professional.");
	} else {
		$("ftag_" + profFollowId).innerHTML = "<a href=\"#\" onclick=\"profFollow(" + profFollowId + ");return false;\"><img src=\"/images/tag_ax_follow.png\" alt=\"Start following this professional.\" /></a>";
		alertBubbleAdd("You are no longer following this professional.");
	}
}
