//<![CDATA[
var savethissearchmessage_offset;	
var foo1 = false;
var foo2 = false;
var c = 0;
var t;
		   
dojo.addOnLoad(function(){	
	// First, load the search form for the selected reagion, then run the on-load functions
	//alert('signed in: ' + signedin);
	//alert('logged in: ' + loggedin);
	//alert('region selected: ' + regionselected);
	//alert('which region: ' + whichRegion);
	loadSearchForm(whichRegion);
});

////////////////////////////////////////////////////////////////////////////////////////////////
// SHOW SEARCH FORM FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////
function onLoadFunctions() {
	
	if ((!(signedin)) && (!(loggedin))) {
		showSignInForm();
	}
	
	if (!(regionselected)) {
		showRegionSelectForm();
	}		

	if (dojo.byId('savethissearch')) {
		dojo.style.show(dojo.byId('savethissearch'));
		var coords = cumulativeOffset(dojo.byId('savethissearch'));
		savethissearchmessage_offset = coords[1];
		dojo.style.hide(dojo.byId('savethissearch'));
	} else {
		savethissearchmessage_offset = '';
	}
	
	if ((loggedin) && (dojo.byId('hidaction').value == 'newsavedsearch')) {
		clearSearchForm();
		showSaveSearchForm();
		dojo.byId('hidaction').value = '';
	} else if ((loggedin) && (dojo.byId('hidaction').value == 'editsavedsearch')) {
		showSaveSearchForm();		
	} else if ((loggedin) && (dojo.byId('hidaction').value == 'currentsavedsearch')) {
		showSaveSearchForm();	
	} else if ((loggedin) && (dojo.byId('hidaction').value == 'unsubscribe') && (dojo.byId('searchid').value != '')) {
		unsubscribeSavedSearch();	
	} else if ((dojo.byId('hidaction').value == 'unsubscribe') && (dojo.byId('searchid').value != '')) {
		showLoginRegisterButtons('', '', 'unsubscribe');		
	} else if (dojo.byId('hidaction').value == 'editsavedsearch') {
		showLoginRegisterButtons('', '', 'searchform');
	} else if (dojo.byId('hidaction').value == 'currentsavedsearch') {
		showLoginRegisterButtons('', '', 'searchform');
	} else if (dojo.byId('hidaction').value == 'newsearch') {
		clearSearchForm();		
	}

}

function loadSearchForm(selectedRegion)	{
	
	if (selectedRegion.length != 1) {selectedRegion = default_mls_region;}
	
	var search_form = dojo.byId('search_form');
	var search_holder = dojo.byId('search_holder');
	var loading_div = dojo.byId('loading_div');
	
	dojo.style.hide(search_form);
	
	if ((signedin) && (regionselected)) {
			dojo.style.show(loading_div);
	}
	
	var whichPage = '/res/includes/search_forms/search_form_' + selectedRegion + '.asp';
	var whichJS = '/res/includes/search_forms/search_form_' + selectedRegion + '.js';
	var local_javascript = dojo.byId('local_javascript');
	
	dojo.event.browser.clean(local_javascript);
	local_javascript.innerHTML = '';
	
	var bindArgs = {
	sync: true,
	url: whichPage,
	method: 'post',
	formNode: dojo.byId('frmSearchHolder'),
	error: function(type, data, evt){
		search_form.innerHTML='<div style="margin-top: 20px; margin-bottom: 40px;  font-size: 12px; font-weight: bold;">An error occurred and we could not load the search form.  Please refresh this page to try again.</div>';
	},
	load: function(type, data, evt){
		//load the contents of the selected search form into the search container
		dojo.event.browser.clean(search_form);
		search_form.innerHTML=data;

		if ((signedin) && (regionselected)) {
			dojo.style.hide(loading_div);		
			dojo.style.show(search_form);
		}
		
		//once that's done, clear the place holder search form in order to clear duplicate element ids.
		dojo.event.browser.clean(search_holder);
		search_holder.innerHTML='';
		var foo2 = true
	},
	mimetype: 'text/html'
	};
	
	dojo.io.bind(bindArgs);		

	dojo.io.bind(
	 {
		sync: true,
		url: whichJS,
		transport: "ScriptSrcTransport",
		checkString: "foo", //This means (typeof(foo) != undefined) indicates that the script loaded.
		load: function(type, data, evt) {
			local_javascript.innerHTML = '<script language=\"javascript\" type=\"text/javascript\">' + data +  '</script>';
			runOnLoadFunctions();
		},
		error: function(type, data, event, kwArgs) { /* type will be "error", data and event will have the error, , and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
		timeout: function() { /* Called if there is a timeout */},
		timeoutSeconds: 10 //The number of seconds to wait until firing timeout callback in case of timeout.		
	 }
	 );		

}

function changeSearchForm(selectedRegion)	{
	
	
	if (selectedRegion.length != 1) {selectedRegion = default_mls_region;}
	
	var search_form = dojo.byId('search_form');
	var loading_div = dojo.byId('loading_div');
	var mlsregion = dojo.byId('mlsregion');
	
	mlsregion.value = selectedRegion;
	
	dojo.html.setOpacity(loading_div,1);
	loading_div.style.display='';
	dojo.style.show(loading_div);

	var whichPage = '/res/includes/search_forms/search_form_' + selectedRegion + '.asp';
	var whichJS = '/res/includes/search_forms/search_form_' + selectedRegion + '.js';
	var local_javascript = dojo.byId('local_javascript');
	
	dojo.event.browser.clean(local_javascript);
	local_javascript.innerHTML = '';

	var bindArgs = {
	sync: true,
	url: whichPage,
	method: 'post',
	formNode: dojo.byId('frmSearch'),
	error: function(type, data, evt){
		dojo.style.show(search_form, 500);
		search_form.innerHTML='<div style="margin-top: 20px; margin-bottom: 40px;  font-size: 12px; font-weight: bold;">An error occurred and we could not load the search form.  Please refresh this page to try again.</div>';
	},
	load: function(type, data, evt){
		//load the contents of the selected search form into the search container
		whichRegion = selectedRegion;
		dojo.event.browser.clean(search_form);
		search_form.innerHTML=data;
		
		dojo.style.hide(loading_div);
		dojo.html.setOpacity(search_form,0);
		search_form.style.display = '';
		dojo.lfx.fadeShow(search_form, 500).play();		
	},
	mimetype: 'text/html'
	};
	
	dojo.io.bind(bindArgs);	
	
	dojo.io.bind(
	 {
		url: whichJS,
		transport: "ScriptSrcTransport",
		checkString: "foo", //This means (typeof(foo) != undefined) indicates that the script loaded.
		load: function(type, data, evt) {
			local_javascript.innerHTML = '<script language=\"javascript\" type=\"text/javascript\">' + data +  '</script>';
			runOnLoadFunctions();
		},
		error: function(type, data, event, kwArgs) { /* type will be "error", data and event will have the error, , and kwArgs are the keyword arguments used in the dojo.io.bind call. */ },
		timeout: function() { /* Called if there is a timeout */},
		timeoutSeconds: 10 //The number of seconds to wait until firing timeout callback in case of timeout.		
	 }
	 );		

}

////////////////////////////////////////////////////////////////////////////////////////////////
// REGION SELECT FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////

function showRegionSelectForm()	{
	
	eraseCookie('siregion');
	
	var region_select = dojo.byId('region_select');
	var search_form = dojo.byId('search_form');
	var search_holder = dojo.byId('search_holder');
	
	dojo.html.setOpacity(region_select,0);
	
	var anim1 = dojo.lfx.fadeHide(search_form, 500);
	var anim2 = dojo.lfx.fadeShow(region_select, 500);
	var composed = dojo.lfx.chain(anim1,anim2)
	composed.play();

}

function processRegionSelect(selectedRegion) {
	
	regionselected = 'true';
	createCookie('siRegionSelected','true',730);
	createCookie('siregion',selectedRegion,730);
	
	var region_select = dojo.byId('region_select');
	var search_form = dojo.byId('search_form');	
	
	if (selectedRegion != whichRegion) {
		window.scrollTo(0, 0);
		dojo.lfx.fadeHide(region_select, 500).play();
		changeSearchForm(selectedRegion);
	} else {
		window.scrollTo(0, 0);					
		var anim1 = dojo.lfx.fadeHide(region_select, 500);
		var anim2 = dojo.lfx.fadeShow(search_form, 500);		
		var composed = dojo.lfx.chain(anim1,anim2)
		composed.play();		
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////
// SIGN IN SEARCH FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////

function showSignInForm()	{
	
	var sign_in = dojo.byId('sign_in');	
	var search_form = dojo.byId('search_form');
	
	dojo.style.show(sign_in);
	dojo.style.hide(search_form);
	
	sign_in.innerHTML='<div style="margin-top: 20px; margin-bottom: 40px;  font-size: 12px; font-weight: bold;"><img src="res/images/loading_big.gif" align="absmiddle"><strong> Loading. Please wait....</strong></div>';	
	
	var bindArgs = {
	url: 'pages/sign_in.asp',
	method: 'get',	
	error: function(type, data, evt){
		dojo.event.browser.clean(sign_in);
		sign_in.innerHTML='';
		dojo.style.hide(sign_in);
		dojo.style.show(search_form);				
	},
	load: function(type, data, evt){
		dojo.event.browser.clean(sign_in);
		sign_in.innerHTML=data;

		var anim1 = dojo.lfx.wipeIn(sign_in,500);
		var anim2 = dojo.lfx.highlight(sign_in, '#FFFF99', 800);
		var composed = dojo.lfx.chain(anim1, anim2)
		composed.play();				
	},
	mimetype: 'text/html'
	};
	
	dojo.io.bind(bindArgs);	

}

function processSignIn() {
	
	var sign_in = dojo.byId('sign_in');	
	var search_form = dojo.byId('search_form');	
	var searchform_message = dojo.byId('searchform_message');
	
	dojo.require("dojo.validate");
	dojo.require("dojo.validate.check");
	dojo.require("dojo.validate.datetime");
	dojo.require("dojo.validate.us");
	dojo.require("dojo.validate.web");	
	
	var bindArgs = {
	url: 'pages/sign_in_process.asp',
	method: 'post',
	formNode: dojo.byId('frmRegister'),
	error: function(type, data, evt){
		dojo.event.browser.clean(sign_in);
		sign_in.innerHTML='';
		dojo.style.hide(sign_in);
		dojo.style.show(search_form);	
	},
	load: function(type, data, evt){
		var returnVal = parseFloat(data);
		if (returnVal != 1) {
			searchform_message.innerHTML = '<strong>Thank you for signing in.</strong>&nbsp;&nbsp;And don\'t forget to sign up for Property Tracker to get the new listings you want emailed daily.';
			var coords = cumulativeOffset(dojo.byId('search_form'));
			window.scrollTo(0, coords[1]-40);					
			var anim1 = dojo.lfx.fadeHide(sign_in, 500);
			var anim2 = dojo.lfx.fadeShow(search_form, 500);
			var anim3 = dojo.lfx.fadeShow(searchform_message, 100);
			var anim4 = dojo.lfx.highlight(searchform_message, '#FFFF99', 3000);			
			var composed = dojo.lfx.chain(anim1,anim2,anim3,anim4)
			composed.play();							
		} else {
			signedin = true;
			createCookie('siSignedIn','true',730);

			searchform_message.innerHTML = '<strong>Thank you for signing in.</strong> And don\'t forget to sign up for Property Tracker to get the new listings you want emailed daily.';			
			var coords = cumulativeOffset(dojo.byId('search_form'));
			window.scrollTo(0, coords[1]-40);					
			var anim1 = dojo.lfx.fadeHide(sign_in, 500);
			var anim2 = dojo.lfx.fadeShow(search_form, 500);
			var anim3 = dojo.lfx.fadeShow(searchform_message, 500);
			var anim4 = dojo.lfx.highlight(searchform_message, '#FFFF99', 800);			
			var composed = dojo.lfx.chain(anim1,anim2,anim3,anim4)
			composed.play();						
		}
		
	},
	mimetype: 'text/html'
	};	
	
	// Validate the form contents before submitting
	var valProfile = {
		// filters change the field value and are applied before validation.
		trim: ["registeremail", "registerfirstname", "registerlastname"],
		uppercase: [],
		lowercase: [],
		ucfirst: ["registerfirstname", "registerlastname"],
		digit: [],
		required: ["registeremail", "registerfirstname", "registerlastname", "registerphone"],
		dependancies:    {},
		constraints: {
			"registeremail" : [dojo.validate.isEmailAddress]
		},
		confirm: {}
	};

	var valResults = dojo.validate.check(dojo.byId('frmRegister'), valProfile);	
	
	if (valResults.isSuccessful()) {
			dojo.byId('registersubmit').value = 'Processing Info...';
			dojo.byId('registersubmit').style.width = '145px';	
			dojo.io.bind(bindArgs);
	} else if (valResults.hasMissing()) {
		alert('Please enter all of the required fields.');
		return false;
	} else if (valResults.isInvalid('registeremail')) {
		alert('Please enter a valid email address.');
		dojo.byId('registeremail').focus();
		return false;
	}
	
}

////////////////////////////////////////////////////////////////////////////////////////////////
// SAVE SEARCH FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////

function showSaveSearchForm() {

	if (savethissearchmessage_offset.length == 0) {
		dojo.style.show('savethissearch');	
		var coords = cumulativeOffset(dojo.byId('savethissearch'));
		window.scrollTo(0, coords[1]-40);
		dojo.style.hide('savethissearch');
	} else {
		window.scrollTo(0, savethissearchmessage_offset-40);
	}	
	
	dojo.html.setOpacity(dojo.byId('savethissearchfields'),1);
	dojo.html.setOpacity(dojo.byId('savethissearchmessage'),1);	
	
	dojo.style.show(dojo.byId('savethissearchfields'));
	dojo.style.hide(dojo.byId('savethissearchmessage'));	
	
	dojo.html.setOpacity(dojo.byId('search_buttons'),1);
	dojo.html.setOpacity(dojo.byId('save_buttons_2'),1);
	
	dojo.html.setOpacity(dojo.byId('search_buttons_2'),1);
	dojo.html.setOpacity(dojo.byId('save_buttons_3'),1);	

	var savethissearch = dojo.byId('savethissearch');
	var anim1 = dojo.lfx.wipeIn(savethissearch, 500);
	var anim2 = dojo.lfx.highlight(savethissearch, '#FFFF99', 800);
	var composed1 = dojo.lfx.chain(anim1, anim2);
	composed1.play();	

	dojo.style.hide(dojo.byId('search_buttons'));
	dojo.style.show(dojo.byId('save_buttons_2'));
	
	dojo.style.hide(dojo.byId('search_buttons_2'));
	dojo.style.show(dojo.byId('save_buttons_3'));	
}

function hideSaveSearchForm() {
	var savethissearch = dojo.byId('savethissearch');
	
	dojo.html.setOpacity(dojo.byId('search_buttons'),1);
	dojo.html.setOpacity(dojo.byId('save_buttons_2'),1);
	
	dojo.html.setOpacity(dojo.byId('search_buttons_2'),1);
	dojo.html.setOpacity(dojo.byId('save_buttons_3'),1);		
	
	dojo.lfx.wipeOut(savethissearch, 500).play();
	
	dojo.style.hide(dojo.byId('save_buttons_2'));
	dojo.style.show(dojo.byId('search_buttons'));

	dojo.style.hide(dojo.byId('save_buttons_3'));	
	dojo.style.show(dojo.byId('search_buttons_2'));	
	
	dojo.html.setOpacity(dojo.byId('savethissearchfields'),1);
	dojo.html.setOpacity(dojo.byId('savethissearchmessage'),1);	
	
	dojo.style.show(dojo.byId('savethissearchfields'));
	dojo.style.hide(dojo.byId('savethissearchmessage'));
	
	dojo.event.browser.clean(dojo.byId('savethissearchmessage'));
	dojo.byId('savethissearchmessage').innerHTML = '';	
	dojo.byId('hidaction').value = '';
	
}

function clearSavedSearchForm() {
	if (dojo.byId('searchname')) {dojo.byId('searchname').value = ''}
	document.frmSearch.sendemail[0].checked=true;
	document.frmSearch.enddate[0].selected=true;
	dojo.byId('hidaction').value = '';
}

// calls the saved_search_process.asp page to save a new search or edit an existing search
function saveSearch() {
	
	dojo.require("dojo.validate");
	dojo.require("dojo.validate.check");
	dojo.require("dojo.validate.datetime");
	dojo.require("dojo.validate.us");
	dojo.require("dojo.validate.web");		
	
	var returnVal;
	returnVal = -2;
	
	var bindArgs = {
	url: 'pages/saved_search_process.asp',
	method: 'post',
	sync: true,
	formNode: dojo.byId("frmSearch"),
	error: function(type, data, evt){
		alert('An error occurred and the search could not be saved. Please try again.');
		dojo.byId('savesearch1').value = 'Save Search';
		dojo.byId('savesearch1').style.width = '120px';	
		dojo.byId('savesearch2').value = 'Save Search';
		dojo.byId('savesearch2').style.width = '120px';				
	},
	load: function(type, data, evt){
		returnVal = parseFloat(data); 
		
		if (returnVal >= 1) {
			
			dojo.byId('searchid').value = returnVal;
			dojo.byId('hidaction').value = '';
			
			if (savethissearchmessage_offset.length == 0) {
				dojo.style.show(dojo.byId('savethissearch'));	
				var coords = cumulativeOffset(dojo.byId('savethissearch'));
				window.scrollTo(0, coords[1]-40);
				dojo.style.hide(dojo.byId('savethissearch'));
			} else {
				window.scrollTo(0, savethissearchmessage_offset-40);
			}				
			
			// display the message that the search was saved successfully, then fade it out.
			dojo.event.browser.clean(dojo.byId('savethissearchmessage'));
			dojo.byId('savethissearchmessage').innerHTML = '<strong>Success!</strong> The search was saved successfully.<br /><br />To run this search now, <a href="javascript: full_search_from_form(\'2\');">click here</a>.&nbsp;&nbsp;To go to your Property Tracker, <a href="javascript: full_search_from_form(\'5\');">click here.</a>';			
			var anim1 = dojo.lfx.fadeHide(dojo.byId(dojo.byId('savethissearchfields')), 500);
			var anim2 = dojo.lfx.fadeShow(dojo.byId(dojo.byId('savethissearchmessage')), 500);			
			var anim3 = dojo.lfx.highlight(dojo.byId('savethissearchmessage'), '#FFFF99', 800);
			var composed2 = dojo.lfx.chain(anim1, anim2, anim3)
			composed2.play();
			
			dojo.html.setOpacity(dojo.byId('search_buttons'),1);
			dojo.html.setOpacity(dojo.byId('save_buttons_2'),1);
			
			dojo.html.setOpacity(dojo.byId('search_buttons_2'),1);
			dojo.html.setOpacity(dojo.byId('save_buttons_3'),1);			
			
			dojo.byId('savesearch1').value = 'Save Search';
			dojo.byId('savesearch1').style.width = '120px';	
			dojo.byId('savesearch2').value = 'Save Search';
			dojo.byId('savesearch2').style.width = '120px';	
			dojo.byId('savesearch3').value = 'Save Search';
			dojo.byId('savesearch3').style.width = '120px';				
			
			dojo.style.hide(dojo.byId('save_buttons_2'));
			dojo.style.show(dojo.byId('search_buttons'));
			
			dojo.style.hide(dojo.byId('save_buttons_3'));
			dojo.style.show(dojo.byId('search_buttons_2'));
			
			dojo.byId('runSavedSearches').innerHTML += '<ul class="sidebar" style="margin-top: 0px;"><li class="sidebar"><a href="javascript: run_saved_search(\'' + returnVal + '\', \'2\');" style="text-decoration: underline;">' + dojo.byId('searchname').value + '</a></li></ul>';
			sidebarUpdateSavedSearchesText(numSearches + 1);
			
			var anim6 = dojo.lfx.wipeOut(dojo.byId('savethissearch'), 600);
			var composed3 = dojo.lfx.chain(anim6);
			composed3.play(12000);				
		} else {
			alert('An error occurred and the search could not be saved. Please try again.');
			dojo.byId('savesearch1').value = 'Save Search';
			dojo.byId('savesearch1').style.width = '120px';	
			dojo.byId('savesearch2').value = 'Save Search';
			dojo.byId('savesearch2').style.width = '120px';
			dojo.byId('savesearch3').value = 'Save Search';
			dojo.byId('savesearch3').style.width = '120px';				
		}
	},
	mimetype: 'text/html'
	};
	
	// Validate the form contents before submitting
	var valProfile = {
		// filters change the field value and are applied before validation.
		trim: ["searchname"],
		uppercase: [],
		lowercase: [],
		ucfirst: [],
		digit: [],
		required: ["searchname"],
		dependancies:    {},
		constraints: {},
		confirm: {}
	};

	var valResults = dojo.validate.check(dojo.byId('frmSearch'), valProfile);	
	
	if (valResults.isSuccessful()) {
		
		if ((document.frmSearch.sendemail[0].checked) && (document.frmSearch.enddate[document.frmSearch.enddate.selectedIndex].value == '')) {
			alert('Please select an end date for the new listings alerts.');
			document.frmSearch.enddate.focus();
			return false;
		} else {
			dojo.byId('savesearch1').value = 'Please Wait...';
			dojo.byId('savesearch1').style.width = '145px';	
			dojo.byId('savesearch2').value = 'Please Wait...';
			dojo.byId('savesearch2').style.width = '145px';	
			dojo.byId('savesearch3').value = 'Please Wait...';
			dojo.byId('savesearch3').style.width = '145px';				
			
			// run the XHR Request
			dojo.io.bind(bindArgs);
		}
	} else if (valResults.hasMissing()) {
		alert('Please enter a name for your search.');
		document.frmSearch.searchname.focus();
		return false;
	}		
}

function unsubscribeSavedSearch() {
	
	var returnVal;
	returnVal = -2;
	
	dojo.style.show(dojo.byId('savethissearch'));
	dojo.style.hide(dojo.byId('savethissearchfields'));
	dojo.style.show(dojo.byId('savethissearchmessage'));
	dojo.byId('hidaction').value = '';
	
	var bindArgs = {
	url: 'pages/saved_search_process.asp',
	method: 'post',
	sync: true,
	formNode: dojo.byId("frmSearch"),
	error: function(type, data, evt){
		alert('An error occurred and the search could not be unsubscribed. Please try again.');		
	},
	load: function(type, data, evt){
		returnVal = parseFloat(data);
		if (dojo.byId('hidaction')) {
			dojo.byId('hidaction').value = '';
		}
		
		if (returnVal >= 1) {
			
			if (savethissearchmessage_offset.length == 0) {
				var coords = cumulativeOffset(dojo.byId('savethissearch'));
				window.scrollTo(0, coords[1]-40);
			} else {
				window.scrollTo(0, savethissearchmessage_offset-40);
			}				
			
			// display the message that the search was saved successfully, then fade it out.
			dojo.event.browser.clean(dojo.byId('savethissearchmessage'));
			dojo.byId('savethissearchmessage').innerHTML = '<strong>Unsubscribe Successful!</strong> You will no longer receive email alerts for this search.<br /><br />To enable alerts for this search at any time, just go to your <a href="javascript: full_search_from_form(\'5\');">Property Tracker (click here)</a>.';
			var anim2 = dojo.lfx.fadeShow(dojo.byId(dojo.byId('savethissearchmessage')), 500);			
			var anim3 = dojo.lfx.highlight(dojo.byId('savethissearchmessage'), '#FFFF99', 800);
			var composed2 = dojo.lfx.chain(anim2, anim3)
			composed2.play();
			
			dojo.html.setOpacity(dojo.byId('search_buttons'),1);
			dojo.html.setOpacity(dojo.byId('save_buttons_2'),1);
			
			dojo.html.setOpacity(dojo.byId('search_buttons_2'),1);
			dojo.html.setOpacity(dojo.byId('save_buttons_3'),1);			
			
			dojo.byId('savesearch1').value = 'Save Search';
			dojo.byId('savesearch1').style.width = '120px';	
			dojo.byId('savesearch2').value = 'Save Search';
			dojo.byId('savesearch2').style.width = '120px';	
			dojo.byId('savesearch3').value = 'Save Search';
			dojo.byId('savesearch3').style.width = '120px';				
			
			dojo.style.hide(dojo.byId('save_buttons_2'));
			dojo.style.show(dojo.byId('search_buttons'));
			
			dojo.style.hide(dojo.byId('save_buttons_3'));
			dojo.style.show(dojo.byId('search_buttons_2'));			
			
			var anim6 = dojo.lfx.wipeOut(dojo.byId('savethissearch'), 600);
			var composed3 = dojo.lfx.chain(anim6);
			composed3.play(10000);				
		} else {
			alert('An error occurred and the search could not be unsubscribed. Please try again.');
			dojo.html.setOpacity(dojo.byId('search_buttons'),1);
			dojo.html.setOpacity(dojo.byId('save_buttons_2'),1);
			
			dojo.html.setOpacity(dojo.byId('search_buttons_2'),1);
			dojo.html.setOpacity(dojo.byId('save_buttons_3'),1);			
			
			dojo.byId('savesearch1').value = 'Save Search';
			dojo.byId('savesearch1').style.width = '120px';	
			dojo.byId('savesearch2').value = 'Save Search';
			dojo.byId('savesearch2').style.width = '120px';
			dojo.byId('savesearch3').value = 'Save Search';
			dojo.byId('savesearch3').style.width = '120px';			
			
			dojo.style.hide(dojo.byId('save_buttons_2'));
			dojo.style.show(dojo.byId('search_buttons'));
			
			dojo.style.hide(dojo.byId('save_buttons_3'));
			dojo.style.show(dojo.byId('search_buttons_2'));			
			
			var anim6 = dojo.lfx.wipeOut(dojo.byId('savethissearch'), 600);
			var composed3 = dojo.lfx.chain(anim6);
			composed3.play(6000);			
		}
	},
	mimetype: 'text/html'
	};

	dojo.io.bind(bindArgs);
		
}

	

////////////////////////////////////////////////////////////////////////////////////////////////
// QUICK SEARCH FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////
// Shows quick search form on search form
var currentquicksearchid;
function quicksearch_show(quicksearchid){
	var quick_search_container = dojo.byId('quick_search_container');
	if(quicksearchid!=currentquicksearchid){
		dojo.event.browser.clean(quick_search_container);
		quick_search_container.innerHTML='<img src="res/images/loading.gif" align="absmiddle"> Loading...';
		
		var bindArgs = {
		url: 'pages/quick_search.asp',
		method: 'get',
		content: {
			quicksearchtype: quicksearchid
		},		
		error: function(type, data, evt){
			alert('An error occurred and we could not retrieve the quick search form.  Please try again.');
		},
		load: function(type, data, evt){
			quick_search_container.innerHTML=data;
			
			var quickwipeIn = dojo.lfx.wipeIn(quick_search_container,300);
			var quickHighlight = dojo.lfx.html.highlight(quick_search_container, '#ffff99', 700, 700);
			dojo.lfx.chain(quickwipeIn, quickHighlight).play();
		},
		mimetype: 'text/html'
		};
		
		dojo.io.bind(bindArgs);
		
		currentquicksearchid=quicksearchid;
	} else {
		dojo.lfx.wipeOut(quick_search_container,300).play();
		currentquicksearchid='';
		dojo.event.browser.clean(quick_search_container);
		quick_search_container.innerHTML='';
	}	
}

// Validates quick search form and runs search
function quick_search(quicksearchid) {

	clearHiddenFieldsFromSearchForm();
	document.frmSearch.quicksearchid.value = quicksearchid;
	
	if (quicksearchid=='1') 
	{
		var mlsVal = false;
		
		for (counter = 1; counter <= 8; counter++) {
			if (dojo.byId('mls'+counter).value != '') {
				mlsVal = true;
			}
		}
		
		if (mlsVal == true) {
			dojo.byId('quicksearchid').value=quicksearchid;
			full_search('2');
		} else {
			alert('Please enter at least one MLS number.');
			return false;
		}
	} else if (quicksearchid=='2') {
		var zipVal = false;
		
		for (counter = 1; counter <= 8; counter++) {
			if (dojo.byId('zip'+counter).value != '') {
				zipVal = true;
			}
		}
		
		if (zipVal == true) {
			dojo.byId('quicksearchid').value=quicksearchid;
			full_search('2');
		} else {
			alert('Please enter at least one Zip code.');
			return false;
		}		
		
	} else if (quicksearchid=='3') {
		var streetVal = false;
		
		for (counter = 1; counter <= 3; counter++) {
			if ((dojo.byId('streetnumber'+counter).value != '') || (dojo.byId('streetname'+counter).value != '')) {
				streetVal = true;
			}
		}
		
		if (streetVal == true) {
			dojo.byId('quicksearchid').value=quicksearchid;
			full_search('2');
		} else {
			alert('Please enter at least one street number or street name.');
			return false;
		}		
		
	} else if (quicksearchid=='4') {
		var agentVal = false;
		
		for (counter = 1; counter <= 3; counter++) {
			if (dojo.byId('agentlastname'+counter).value != '') {
				agentVal = true;
			}
		}
		
		if (agentVal == true) {
			dojo.byId('quicksearchid').value=quicksearchid;
			full_search('2');
		} else {
			alert('Please enter at least one agent name.');
			return false;
		}	
		
	} else if (quicksearchid=='6') {
		var projectVal = false;
		
		for (counter = 1; counter <= 3; counter++) {
			if (dojo.byId('condoprojectname'+counter).value != '') {
				projectVal = true;
			}
		}
		
		if (projectVal == true) {
			dojo.byId('quicksearchid').value=quicksearchid;
			full_search('2');
		} else {
			alert('Please enter at least one project name.');
			return false;
		}			
		
	}
}

// When main property category changes, shows the prop types available for that category
function propertytype_show(listtype){
	
	if (listtype != '') {
		var property_type_container = dojo.byId('property_type_container')
		
		dojo.event.browser.clean(property_type_container);
		property_type_container.innerHTML='<img src="res/images/loading.gif" align="absmiddle"> Loading...';
	
		var bindArgs = {
		url: 'pages/property_types.asp',
		method: 'post',
		formNode: dojo.byId('frmSearch'),		
		error: function(type, data, evt){
			alert('An error occurred and we could not retrieve the property types.  Please try again.');
		},
		load: function(type, data, evt){
			dojo.event.browser.clean(property_type_container);
			property_type_container.innerHTML=data;
			
			var quickwipeIn = dojo.lfx.wipeIn(property_type_container,300);
			var quickHighlight = dojo.lfx.html.highlight(property_type_container, '#ffff99', 700, 700);
			var composed = dojo.lfx.chain(quickwipeIn, quickHighlight);
			composed.play(200);
		},
		mimetype: 'text/html'
		};
	
		dojo.io.bind(bindArgs);	
	}
}



function validateLPrice()
{
		
	var lPrice = dojo.byId('lprice');
	var uPrice = dojo.byId('uprice');
	
	var minPrice = parseInt(lPrice.options[lPrice.selectedIndex].value);
	var maxPrice = parseInt(uPrice.options[uPrice.selectedIndex].value);
	
	if(isNaN(maxPrice))
	{
		maxPrice = 0;
	}
	var newSelected = false;

	var newMax = lPrice.options[lPrice.selectedIndex + 1].value;
	if(maxPrice > newMax)
	{
		newMax = maxPrice;
	}
	
	for (var i=1;i<lPrice.options.length; i++)
	{
	
		if(parseInt(lPrice.options[i].value) < minPrice)
		{
			//alert("Set it grey");			
			//lPrice.options[i].style.color='#999999';
		}
		else if(parseInt(lPrice.options[i].value) <= newMax)
		{
			lPrice.options[i].style.color='#000000';
		}
		else
		{
			break;
		}
	}

	for (var i=uPrice.options.length - 1;i>=0; i--) {
		if(parseInt(uPrice.options[i].value) < minPrice)
		{
			//uPrice.options[i].disabled = true;					
			//alert(i);
			//alert(uPrice.options[i].style.color);
			uPrice.options[i].style.color = '#CCCCCC';
			//alert(uPrice.options[i].style.color);
			if(!newSelected && maxPrice < minPrice)
			{
				if( (i + 2) < uPrice.options.length)
				{					
					if(uPrice.selectedIndex != 0)
					{
						uPrice.options[i + 2].selected = true;
					}
					newSelected = true;
				}
			}
			//uPrice.remove(i);
		}
		else
		{
			uPrice.options[i].style.color='#000000';
			//uPrice.options[i].disabled = false;
		}
	}

}

function validateUPrice()
{	

	var lPrice = dojo.byId('lprice');
	var uPrice = dojo.byId('uprice');
	
	var minPrice = parseInt(lPrice.options[lPrice.selectedIndex].value);
	var maxPrice = parseInt(uPrice.options[uPrice.selectedIndex].value);
	
	if(isNaN(minPrice))
	{
		minPrice = 0;
	}
	uPrice.options[uPrice.selectedIndex].style.color = '#000000';
	//var newSelected = false;
	for (var i=lPrice.options.length - 1;i>=0; i--) {
		if(parseInt(lPrice.options[i].value) >= maxPrice)
		{
			lPrice.options[i].style.color='#CCCCCC';
			//lPrice.options[i].disabled = true;
			//lPrice.options[i].style.display = "none"
			//lPrice.remove(i);
			if( minPrice > maxPrice)
			{
				lPrice.options[i - 1].selected = true;	
				lPrice.options[i - 1].style.color = '#000000';
			}
		}	
		else if(parseInt(lPrice.options[i].value) >= minPrice)
		{
			lPrice.options[i].style.color='#000000';
			//lPrice.options[i].disabled = false;
		}
	}
}

// Show and hide the advanced search options
function showMoreOptions(){		
	var listtypeid = '';

	for (counter = 0; counter < document.frmSearch.listtype.length; counter++) {
		if (document.frmSearch.listtype[counter].checked) {
			listtypeid = document.frmSearch.listtype[counter].value;
		}
	}		
	
	if (dojo.byId('more_options').style.display == 'none') {
		dojo.lfx.wipeIn(dojo.byId('more_options'),500).play();
	}
	dojo.style.show(dojo.byId('search_buttons_2'));	
}

function hideMoreOptions(){
	dojo.lfx.wipeOut(dojo.byId('more_options'),500).play();
	clearMoreOptions();
	
	dojo.style.hide(dojo.byId('save_buttons_3'));
	dojo.style.hide(dojo.byId('search_buttons_2'));
}

function scrolltoOptions() {
		var coords = cumulativeOffset(dojo.byId('more_options'));		
		window.scrollTo(0, coords[1]-200);
}

//]]>
