// JavaScript Document
document.title = document.title + " | HomeFree.com";

function ge(id)
{
	return document.getElementById(id);
}

function searhdon()
{
	if (document.searchhd.searchbar.value == "Enter a Neighborhood, City, or Zip")
	{
		document.searchhd.searchbar.value = "";
	}
}

function searhdooff()
{
	if (document.searchhd.searchbar.value == "")
	{
		document.searchhd.searchbar.value = "Enter a Neighborhood, City, or Zip";
	}
}

function logineon()
{
	if (document.loginview.username.value == "Username")
	{
		document.loginview.username.value = "";
	}
}

function logineoff()
{
	if (document.loginview.username.value == "")
	{
		document.loginview.username.value = "Username";
	}
}

function loginpon()
{
	if (document.loginview.password.value == "Password")
	{
		document.loginview.password.value = "";
	}
}

function loginpoff()
{
	if (document.loginview.password.value == "")
	{
		document.loginview.password.value = "Password";
	}
}

function adsearcon()
{
	if (document.buy_01.local_search.value == "City & State, OR Zip Code")
	{
		document.buy_01.local_search.value = "";
	}
}

function adsearcoff()
{
	if (document.buy_01.local_search.value == "")
	{
		document.buy_01.local_search.value = "City & State, OR Zip Code";
	}
}

function adlinkon()
{
	if (document.spon_03.f_add_link.value == "http://")
	{
		document.spon_03.f_add_link.value = "";
	}
}

function adlinkoff()
{
	if (document.spon_03.f_add_link.value == "")
	{
		document.spon_03.f_add_link.value = "http://";
	}
}

function arcstyon()
{
	if (document.sell_04.arc_style.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.arc_style.value = "";
	}
}

function arcstyoff()
{
	if (document.sell_04.arc_style.value == "")
	{
		document.sell_04.arc_style.value = "Optional (100 Characters Max.)";
	}
}

function heatcoolon()
{
	if (document.sell_04.heat_cool.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.heat_cool.value = "";
	}
}

function heatcooloff()
{
	if (document.sell_04.heat_cool.value == "")
	{
		document.sell_04.heat_cool.value = "Optional (100 Characters Max.)";
	}
}

function kitfton()
{
	if (document.sell_04.kit_feat.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.kit_feat.value = "";
	}
}

function kitftoff()
{
	if (document.sell_04.kit_feat.value == "")
	{
		document.sell_04.kit_feat.value = "Optional (100 Characters Max.)";
	}
}

function bathfton()
{
	if (document.sell_04.bath_feat.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.bath_feat.value = "";
	}
}

function bathftoff()
{
	if (document.sell_04.bath_feat.value == "")
	{
		document.sell_04.bath_feat.value = "Optional (100 Characters Max.)";
	}
}

function fpinfoon()
{
	if (document.sell_04.fp_info.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.fp_info.value = "";
	}
}

function fpinfooff()
{
	if (document.sell_04.fp_info.value == "")
	{
		document.sell_04.fp_info.value = "Optional (100 Characters Max.)";
	}
}

function flinfoon()
{
	if (document.sell_04.floor_info.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.floor_info.value = "";
	}
}

function flinfooff()
{
	if (document.sell_04.floor_info.value == "")
	{
		document.sell_04.floor_info.value = "Optional (100 Characters Max.)";
	}
}

function flinfoon()
{
	if (document.sell_04.floor_info.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.floor_info.value = "";
	}
}

function flinfooff()
{
	if (document.sell_04.floor_info.value == "")
	{
		document.sell_04.floor_info.value = "Optional (100 Characters Max.)";
	}
}

function dinefton()
{
	if (document.sell_04.dining_feat.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.dining_feat.value = "";
	}
}

function dineftoff()
{
	if (document.sell_04.dining_feat.value == "")
	{
		document.sell_04.dining_feat.value = "Optional (100 Characters Max.)";
	}
}

function pooldescon()
{
	if (document.sell_04.pool_desc.value == "Optional (100 Characters Max.)")
	{
		document.sell_04.pool_desc.value = "";
	}
}

function pooldescoff()
{
	if (document.sell_04.pool_desc.value == "")
	{
		document.sell_04.pool_desc.value = "Optional (100 Characters Max.)";
	}
}

function marktdescon()
{
	if (document.sell_04.markt_desc.value == "(750 Characters Max.)")
	{
		document.sell_04.markt_desc.value = "";
	}
}

function marktdescoff()
{
	if (document.sell_04.markt_desc.value == "")
	{
		document.sell_04.markt_desc.value = "(750 Characters Max.)";
	}
}

function markdesctip()
{
	if (document.getElementById("sell003").style.display == "none")
	{
		document.getElementById("sell003").style.display = "inline";
	}
}

function cobuyshow()
{
	if (document.buy_09.co_buyer.checked == true)
	{
		document.getElementById("co-buyer-show").style.display = "block";
	} else
	{
		document.getElementById("co-buyer-show").style.display = "none";
	}
}

function palendershow()
{
	if (document.buy_09.my_lender_5.checked == true)
	{
		document.getElementById("pre-approval-lender").style.display = "block";
	} else
	{
		document.getElementById("pre-approval-lender").style.display = "none";
	}
}

function markdesctoff()
{
	document.getElementById("sell003").style.display = "none";
}

function ismaxlength(obj)
{
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length > mlength)
		obj.value = obj.value.substring(0, mlength)
}

function MM_jumpMenu(targ, selObj, restore)
{ //v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore) selObj.selectedIndex = 0;
}

$(function()
{
	$("#checkAllPms").click(function()
	{
		var checked_status = this.checked;
		$("input[name=pm[]]").each(function()
		{
			this.checked = checked_status;
		});
	});

	// ===============
	// Login Box
	// ===============
	var fbStatus = $("#fbIcon").attr('class');
	var twStatus = $("#twIcon").attr('class');

	$("#fbIcon").mouseover(function()
	{
		if (fbStatus != 'active') oAuthActivate('fb', fbStatus);
	});
	$("#fbIcon").mouseout(function()
	{
		if (fbStatus != 'active') oAuthDisable('fb', fbStatus);
	});
	$("#twIcon").mouseover(function()
	{
		if (twStatus != 'active') oAuthActivate('tw', twStatus);
	});
	$("#twIcon").mouseout(function()
	{
		if (twStatus != 'active') oAuthDisable('tw', twStatus);
	});

	function oAuthActivate(oAuthType, status)
	{
		if (status == 'inactive')
		{
			$("#" + oAuthType + "Icon").removeClass('inactive');
			$("#" + oAuthType + "Icon").addClass('hover');
		}
	}

	function oAuthDisable(oAuthType, status)
	{
		$("#" + oAuthType + "Icon").removeClass('hover');
		$("#" + oAuthType + "Icon").removeClass('active');
		$("#" + oAuthType + "Icon").addClass('inactive');
	}

	// =========================
	// Notification close button
	// =========================
	$('.notification').hover(function()
	{
		$(this).css('cursor', 'pointer');
	}, function()
	{
		$(this).css('cursor', 'auto');
	});

	$('.notification span').click(function()
	{
		$(this).parents('.notification').fadeOut(800);
	});

	$('.notification').click(function()
	{
		$(this).fadeOut(800);
	});


	// ===================
	// Change input styles
	// ===================
	changeInputs();

	// ===================
	// Dropdown buttons
	// ===================
	const OPEN = 1, CLOSED = 0;

	$("div.dropButton").data('status', CLOSED);

	$("div.dropButton input[type=checkbox]").click(function(event)
	{
		event.stopPropagation()
	});

	$("div.dropButton").each(function()
	{
		$(this).click(function(event)
		{
			event.stopPropagation();

			//Close other buttons except for '$(this)' one
			closeButtons($(this));

			var pos = $(this).offset(),
					height = $(this).height(),
					offset = 11;

			$(this).next("div.dropMenu").css({
				"left": (pos.left) + "px",
				"top": (pos.top + height + offset) + "px"
			});

			$(this).next("div.dropMenu").slideToggle();

			$(this).toggleClass('dropButtonActive');

			changeStatus(this);
		});
	});

	function closeButtons(target)
	{
		var buttons;

		if (typeof target == 'undefined')
			buttons = $("div.dropButton");
		else
			buttons = $("div.dropButton").not(target);

		buttons.each(function(index, element)
		{
			if ($(element).data('status') == OPEN)
			{
				$(element).next("div.dropMenu").slideUp();
				$(element).removeClass('dropButtonActive');

				changeStatus(element);
			}
		});
	}

	function changeStatus(element)
	{
		if ($(element).data('status') == CLOSED)
		{
			$("span", element).html('&#x25B2');
			$(element).data('status', OPEN);
		}
		else
		{
			$("span", element).html('&#x25BC');
			$(element).data('status', CLOSED);
		}
	}

	$('.dropMenu').click(function(event)
	{
		event.stopPropagation();
		return true;
	});
	
	$('.dropMenu ul li').click(function(event)
	{
		window.location = $(event.target).children().attr('href');
	});

	$(document).click(function()
	{
		closeButtons();
	});

	$(".skip").click(function()
	{
		window.location = 'dashboard.php';
	});
});

function changeInputs()
{
	$("input:text, input:password").addClass('text');
	$("input:submit, input:button").not(".skip").addClass('button');
	$("input:submit[disabled]").removeClass().addClass('skip');
}
