/*	-------------------------------------------------
	FUNCTIONS
	-------------------------------------------------	*/
	function getMLSID(strIDString) {
		var arrIDParts;
		var strCurMLSID		= "";
		
		if (strIDString.indexOf("-") > -1) {
			arrIDParts		= strIDString.split("-");
			
			if (arrIDParts.length > 1) {
				strCurMLSID		= arrIDParts[1];
			}
		}
		
		arrIDParts			= null;
		
		return strCurMLSID;
	}

	function validateLogin() {
		var boolErrorFound			= false;
		var strErrorText			= "";
		
		if (($("#strEmail").val().length == 0) || ($("#strEmail").val() == STR_HEADER_LOGIN_USERNAME)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your e-mail address.\n";
		} else if (($("#strEmail").val().indexOf("@") == -1) || ($("#strEmail").val().indexOf(".") == -1)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter a valid e-mail address.\n";
		}
		if ($("#strPassword").val().length < 6) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your password.\n";
		}
		
		if (boolErrorFound) {
			alert(STR_STANDARD_ERROR + strErrorText);
			return false;
		} else {
			return true;
		}
	}

	function validateForgot() {
		var boolErrorFound			= false;
		var strErrorText			= "";
		
		if (($("#strForgotEmail").val().length == 0) || ($("#strForgotEmail").val() == STR_HEADER_LOGIN_USERNAME)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your e-mail address.\n";
		} else if (($("#strForgotEmail").val().indexOf("@") == -1) || ($("#strForgotEmail").val().indexOf(".") == -1)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter a valid e-mail address.\n";
		}
		
		if (boolErrorFound) {
			alert(STR_STANDARD_ERROR + strErrorText);
			return false;
		} else {
			return true;
		}
	}

	function validateRegistration() {
		var boolErrorFound			= false;
		var strErrorText			= "";
		
		if ($("#strFirstName").val().length == 0) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your first name.\n";
		}
		if ($("#strLastName").val().length == 0) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your last name.\n";
		}
		if (($("#strEmail").val().length == 0) || ($("#strEmail").val() == STR_HEADER_LOGIN_USERNAME)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your e-mail address.\n";
		} else if (($("#strEmail").val().indexOf("@") == -1) || ($("#strEmail").val().indexOf(".") == -1)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter a valid e-mail address.\n";
		}
		if ($("#strPassword").val().length < 6) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter the password you would like to use.  It must be at least six characters.\n";
		} else { 
			if ($("#strPasswordV").val().length < 6) {
				boolErrorFound			= true;
				strErrorText			+= "- Please enter the password you would like to use again in the \"Confirm Password\" box.\n";
			} else {
				if ($("#strPassword").val() != $("#strPasswordV").val()) {
					boolErrorFound			= true;
					strErrorText			+= "- The passwords you entered did not match.  Please enter them again.\n";
					
					$("#strPassword").val("");
					$("#strPasswordV").val("");
				}
			}
		}
		
		if (boolErrorFound) {
			alert(STR_STANDARD_ERROR + strErrorText);
			return false;
		} else {
			return true;
		}
	}

	function validateUpdateRegistration() {
		var boolErrorFound			= false;
		var strErrorText			= "";
		
		if ($("#strFirstName").val().length == 0) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your first name.\n";
		}
		if ($("#strLastName").val().length == 0) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your last name.\n";
		}
		if (($("#strEmail").val().length == 0) || ($("#strEmail").val() == STR_HEADER_LOGIN_USERNAME)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter your e-mail address.\n";
		} else if (($("#strEmail").val().indexOf("@") == -1) || ($("#strEmail").val().indexOf(".") == -1)) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter a valid e-mail address.\n";
		}
		
		if (boolErrorFound) {
			alert(STR_STANDARD_ERROR + strErrorText);
			return false;
		} else {
			return true;
		}
	}

	function validateUpdatePassword() {
		var boolErrorFound			= false;
		var strErrorText			= "";
		
		if ($("#strPassword").val().length < 6) {
			boolErrorFound			= true;
			strErrorText			+= "- Please enter the password you would like to use.  It must be at least six characters.\n";
		} else { 
			if ($("#strPasswordV").val().length < 6) {
				boolErrorFound			= true;
				strErrorText			+= "- Please enter the password you would like to use again in the \"Confirm Password\" box.\n";
			} else {
				if ($("#strPassword").val() != $("#strPasswordV").val()) {
					boolErrorFound			= true;
					strErrorText			+= "- The passwords you entered did not match.  Please enter them again.\n";
					
					$("#strPassword").val("");
					$("#strPasswordV").val("");
				}
			}
		}
		
		if (boolErrorFound) {
			alert(STR_STANDARD_ERROR + strErrorText);
			return false;
		} else {
			return true;
		}
	}
	
	function confirmDeleteProperty(strMLSID) {
		jQuery.facebox(function() { 
			jQuery.get(	"_delete.php", 
						{
							id: strMLSID
						}, 
						function(txtData) {
							jQuery.facebox(txtData)
						})
		});
	}
	
	function deleteProperty(strMLSID) {
		$.post(	"_delete.php", 
				{
					action: "delete", 
					id: strMLSID
				}, 
				function(txtData) {
					window.location.reload();
				});
	}

	function saveAlerts(txtAlerts) {
		$.post(	"_save-alerts.php", 
				{
					alerts: txtAlerts, 
					enabled: $("#chkAlertsEnabled").val()
				}, 
				function(txtData) {
					jQuery.facebox(txtData)
				});
	}

	function setupAlertsOptions() {
		$("#strAlertsQuery").focus(function() {
			if ($("#strAlertsQuery").val() == STR_HEADER_SEARCH_DEFAULT) {
				$("#strAlertsQuery").val("");
				$("#strAlertsQuery").removeClass("unselected");
			}
		});
		$("#strAlertsQuery").blur(function() {
			if ($("#strAlertsQuery").val() == "") {
				$("#strAlertsQuery").val(STR_HEADER_SEARCH_DEFAULT);
				$("#strAlertsQuery").addClass("unselected");
			}
		});
	}
	
	function buildAlertsString() {
		var txtJSON			= "{";

		txtJSON				+=	"\"enabled\": \"" + $("#chkAlertsEnabled").val() + "\",";
		txtJSON				+=	"\"q\": \"" + ($("#strAlertsQuery").val() == STR_HEADER_SEARCH_DEFAULT ? "" : $("#strAlertsQuery").val()) + "\",";
		txtJSON				+=	"\"type_h\": \"" + $("#chkAlertsTypeHouse").val() + "\",";
		txtJSON				+=	"\"type_c\": \"" + $("#chkAlertsTypeCondo").val() + "\",";
		txtJSON				+=	"\"type_t\": \"" + $("#chkAlertsTypeTownhouse").val() + "\",";
		txtJSON				+=	"\"type_m\": \"" + $("#chkAlertsTypeMulti").val() + "\",";
		txtJSON				+=	"\"type_l\": \"" + $("#chkAlertsTypeLand").val() + "\",";
		txtJSON				+=	"\"type_o\": \"" + $("#chkAlertsTypeOther").val() + "\",";
		txtJSON				+=	"\"price_m\": \"" + $("#intAlertsPriceMin").val() + "\",";
		txtJSON				+=	"\"price_x\": \"" + $("#intAlertsPriceMax").val() + "\",";
		txtJSON				+=	"\"beds_m\": \"" + $("#intAlertsBedsMin").val() + "\",";
		txtJSON				+=	"\"beds_x\": \"" + $("#intAlertsBedsMax").val() + "\",";
		txtJSON				+=	"\"baths\": \"" + $("#intAlertsBaths").val() + "\",";
		txtJSON				+=	"\"sqft_m\": \"" + $("#intAlertsSqftMin").val() + "\",";
		txtJSON				+=	"\"sqft_x\": \"" + $("#intAlertsSqftMax").val() + "\",";
		txtJSON				+=	"\"ls_m\": \"" + $("#intAlertsLotMin").val() + "\",";
		txtJSON				+=	"\"ls_x\": \"" + $("#intAlertsLotMax").val() + "\",";
		txtJSON				+=	"\"pkg\": \"" + $("#intAlertsParking").val() + "\",";
		txtJSON				+=	"\"yb_m\": \"" + $("#intAlertsYearMin").val() + "\",";
		txtJSON				+=	"\"yb_x\": \"" + $("#intAlertsYearMax").val() + "\"";
		
		txtJSON				+=	"}";
		
		return txtJSON;
	}
	
	function populateAlertsSettings() {
		if (objAlerts) {
			if (typeof(objAlerts) == "object") {
				if (objAlerts.q != null) {
					setCheckbox("chkAlertsEnabled", objAlerts.enabled);
					setCheckbox("chkAlertsTypeHouse", objAlerts.type_h);
					setCheckbox("chkAlertsTypeCondo", objAlerts.type_c);
					setCheckbox("chkAlertsTypeTownhouse", objAlerts.type_t);
					setCheckbox("chkAlertsTypeMulti", objAlerts.type_m);
					setCheckbox("chkAlertsTypeLand", objAlerts.type_l);
					setCheckbox("chkAlertsTypeOther", objAlerts.type_o);
					
					$("#strAlertsQuery").removeClass("unselected");
			
					if (objAlerts.q == "") {
						$("#strAlertsQuery").val(STR_HEADER_SEARCH_DEFAULT);
						$("#strAlertsQuery").addClass("unselected");
					} else {
						$("#strAlertsQuery").val(objAlerts.q);
					}
					
					$("#intAlertsPriceMin").val(objAlerts.price_m);
					$("#intAlertsPriceMax").val(objAlerts.price_x);
					$("#intAlertsBedsMin").val(objAlerts.beds_m);
					$("#intAlertsBedsMax").val(objAlerts.beds_x);
					$("#intAlertsBaths").val(objAlerts.baths);
					$("#intAlertsSqftMin").val(objAlerts.sqft_m);
					$("#intAlertsSqftMax").val(objAlerts.sqft_x);
					$("#intAlertsLotMin").val(objAlerts.ls_m);
					$("#intAlertsLotMax").val(objAlerts.ls_x);
					$("#intAlertsParking").val(objAlerts.pkg);
					$("#intAlertsYearMin").val(objAlerts.yb_m);
					$("#intAlertsYearMax").val(objAlerts.yb_x);
				}
			}
		}
	}
	