checkMlsNum = function(keyword) {
	if (!keyword) {
		$('mls_error').setStyle({display:'block'});
		$('mls_error').innerHTML = 'Please enter an ML #';
		return;
	}
	new Ajax.Request('/wwwroot/r/remax-midland-mi/ajax/checkMLS.cfm', {
	  postBody:'keyword='+keyword,
	  onSuccess: function(transport) {
		eval(transport.responseText);
		//alert(mlsResult.length);
		if (mlsResult.length > 0) {
			$('mls_error').setStyle({display:'none'});
			window.open('/templates/reales/re_dishomes.cfm?classid='+mlsResult[0]+'&pids=79,80,81&secure=&idxcomp_id=252&header=arheader2.cfm&header_pg=arheader2.cfm','_blank');
		} else {
			$('mls_error').setStyle({display:'block'});
			$('mls_error').innerHTML = 'No listing was found.';
			$('mls').focus();
		}
	  }.bind(this)
	  ,onException: function(transport) {alert(transport.responseText);}
	  ,onFailure: function(transport) {alert(transport.responseText);}
	});
}

flashPropSearch = function(criteria) {
	// Variables
	criteria = criteria || {}
	selectedAreas = [];
	checkedAreas = [];
	optionsPropTypes = [];
	optionsPricingFeatures = [];
	propStatus = false;
	obj = this;
	selectedAreasOutside = false;
	searchedAreas = [];	
	
	// Initialize: This is executed when the flash map loads. It will display the interface panel to the right of the map.
	this.init = function() {
		var ie = navigator.appName.indexOf("Microsoft") != -1;
		flashVideoPlayer = (ie) ? window['searchMap'] : document['searchMap'];
		this.panel.display.contentOptions();
		propStatus = true;
	}
	// Passed to JS by Flash Map to select an area and update the UI panel.
	this.selectArea = function(area,area_name,deselect,deselect_out) {
		//alert(deselect);
		
		if (deselect) {
			//alert('1: '+deselect_out);
			this.deselectAll(deselect_out);
		}
		if (selectedAreas.length == 1) {
			//alert(selectedAreas[0]);
			if (selectedAreas[0].search(/outside/) > -1) {
				//alert('2: '+deselect_out);
				this.deselectAll(deselect_out);
			}
		}
		
		var area_id = area.split('.');
		if (area_id[1].search(/outside/) > -1) {
			selectedAreasOutside = true;
			//alert(area_id[1]);
			if (area_id[1].search(/north/) > -1) {
				area_id = '4,28,29,31,32,34,35,36,37,38,39,40,41,42,43,44,47,48,49,50,51';
			} else if (area_id[1].search(/east/) > -1) {				
				area_id = '2,3,5,10,12,30,33,34,42,46,51,56,63,65,69,71,74,75,80,81';
			} else if (area_id[1].search(/south/) > -1) {					
				area_id = '2,5,7,9,11,56,57,58,59,60,61,62,63,65,67,68,69,71,74,75,76,78,80,81,82,83';
			} else {
				area_id = '6,7,8,9,11,28,29,32,35,36,38,39,40,43,44,47,48,50,52,54,55,57,58,60,61,62,68,72,78,82,83,125';
			}
			//alert(area_id);
		} else {
			
			area_id = area_id[1].replace(/area_/,'');
			// If it's williams township, then add the city of Auburn to the list of ids to search
			if (area_id == 154) {
				area_id = '154,13';
			// Tittabawassee / Freeland
			} else if (area_id == 231) {
				area_id = '231,8';
			}
						
			if (selectedAreasOutside) {
				//alert('3: '+deselect_out);
				this.deselectAll(deselect_out);
				selectedAreasOutside = false;
				//flashVideoPlayer.highlightArea(area_id,area_name,deselect);
			}
		}
			area_id = area_id+'|'+area_name;
			selectedAreas.push(area_id);
			
		this.panel.updateTabs();
		// If the panel is current on the Selected Areas, update the panel.
		if ($('panel_areas').getStyle('display') == 'block') {
			this.panel.display.contentSelectedAreas();
		}
	}
	//	
	this.deselectArea = function(area,area_name) {
		var area_id = area.split('.');
			if (area_id[1].search(/outside/) > -1) {
				//alert(area_id[1]);
				if (area_id[1].search(/north/) > -1) {
					area_id = '4,28,29,31,32,34,35,36,37,38,39,40,41,42,43,44,47,48,49,50,51';
				} else if (area_id[1].search(/east/) > -1) {				
					area_id = '2,3,5,10,12,30,33,34,42,46,51,56,63,65,69,71,74,75,80,81';
				} else if (area_id[1].search(/south/) > -1) {					
					area_id = '2,5,7,9,11,56,57,58,59,60,61,62,63,65,67,68,69,71,74,75,76,78,80,81,82,83';
				} else {
					area_id = '6,7,8,9,11,28,29,32,35,36,38,39,40,43,44,47,48,50,52,54,55,57,58,60,61,62,68,72,78,82,83,125';
				}
				selectedAreasOutside = false;
				//alert(area_id);
			} else {
				area_id = area_id[1].replace(/area_/,'');
				
				// If it's williams township, then add the city of Auburn to the list of ids to search
				if (area_id == 154) {
					area_id = '154,13';
				// Tittabawassee / Freeland
				} else if (area_id == 231) {
					area_id = '231,8';
				}
				
			}
		
		selectedAreas = selectedAreas.without(area_id+'|'+area_name);
		
		this.panel.updateTabs();
		// If the panel is current on the Selected Areas, update the panel.
		if ($('panel_areas').getStyle('display') == 'block') {
			this.panel.display.contentSelectedAreas();
		}
	}
	
	this.deselectChecked = function() {
		flashVideoPlayer.unselectAll(''+checkedAreas+'');
		// Loop through the Checked Areas array and remove the checked area from the 
		var tempArray = [];
		checkedAreas.each(function(c){
			for(var p = 0;p<selectedAreas.length;p++) {
				var str = selectedAreas[p];
				var temp = str.split('|');
					temp = temp[0].replace(/area_/,'');
				if (temp == c) {
					tempArray.push(str);
				}
			}
		});
		tempArray = tempArray.uniq()
			
		for(var t = 0;t<tempArray.length;t++) {
			selectedAreas = selectedAreas.without(''+tempArray[t]+'');
		}
		
		// Clear the Checked Areas array
		checkedAreas = [];
		this.panel.updateTabs();
		// If the panel is current on the Selected Areas, update the panel.
		if ($('panel_areas').getStyle('display') == 'block') {
			this.panel.display.contentSelectedAreas();
		}
	}
	
	this.deselectUnChecked = function() {
		// Loop through the Checked Areas array and remove the unchecked area from the map / selected tab
		var tempArray = [];
		var tempArray2 = [];
		var temp;
		
		if (checkedAreas.length == 0) {
			this.deselectAll();
			return;
		}
		
		checkedAreas.each(function(c){
			for(var p = 0;p<selectedAreas.length;p++) {
				var str = selectedAreas[p];
				var temp = str.split('|');
					temp = temp[0].replace(/area_/,'');

				if (temp != c && checkedAreas.indexOf(temp) == -1) {
					tempArray.push(temp);
					tempArray2.push(str);
				}
			}
		});
				
		tempArray = tempArray.uniq()
		tempArray2 = tempArray2.uniq()
		
		flashVideoPlayer.unselectAll(''+tempArray+'');
		
		for(var t = 0;t<tempArray2.length;t++) {
			selectedAreas = selectedAreas.without(''+tempArray2[t]+'');
		}
		
		// Clear the Checked Areas array
		checkedAreas = [];
		this.panel.updateTabs();
		// If the panel is current on the Selected Areas, update the panel.
		if ($('panel_areas').getStyle('display') == 'block') {
			this.panel.display.contentSelectedAreas();
		}
	}
	
	this.deselectAll = function(deselect_out) {
		selectedAreas = [];
		checkedAreas = [];
		this.panel.updateTabs();
		// If the panel is current on the Selected Areas, update the panel.
		if ($('panel_areas').getStyle('display') == 'block') {
			this.panel.display.contentSelected();
		}
		if(!flashVideoPlayer) {alert('This property search requires IE7, Firefox 2.0 or Safari to view. Please also have the latest version of Adobe Flash, you can download or update your Flash player by going to www.adobe.com');return;}
		
		flashVideoPlayer.unselectManual(deselect_out);
	}
	
	this.togglePropType = function(prop) {
		if (optionsPropTypes.indexOf(prop) > -1) {
			optionsPropTypes = optionsPropTypes.without(prop);
			if($('check'+prop)) {
				$('check'+prop).checked = false;
			}
		} else {
			optionsPropTypes.push(prop);
			if($('check'+prop)) {
				$('check'+prop).checked = true;
			}
		}
	}
	
	this.searchedResults = function() {
		if (searchedAreas.length > 0) {
			searchResults = [];
			searchedAreas.each(function(r) {
				var name = r.name;
				if (name.search(/twp/gi) == -1) {
					name = r.name+', City of';
				} else {
					name = r.name;
				}
				searchResults.push('<div class="result" onmouseover="this.className=\'result_over\';" onmouseout="this.className=\'result\';" onclick="flashVideoPlayer.jsToggleArea(\''+r.id+'\',\''+name+'\',false);this.display=\'none\'"><div class="title">'+name+'</div><div class="county">'+r.county+' (county)</div></div>');	
			});
			$('searchedAreas_container').setStyle({display:'block'});
			$('searchedAreas_results').innerHTML = searchResults.join("\n");
		} else {
			$('searchedAreas_container').setStyle({display:'block'});
			$('searchedAreas_results').innerHTML = '<br><div style="color:#767676;font-weight:bold;text-align:center;">Sorry, no cities/townships matched your search criteria.</div><br>';
		}
		$('area_search').focus();
		//alert(searchResults.join("\n"));
	}
	
	this.searchAreas = function(keyword) {
		new Ajax.Request('/wwwroot/r/remax-midland-mi/ajax/searchAreas.cfm', {
		  postBody:'keyword='+keyword,
		  onSuccess: function(transport) {
			eval(transport.responseText);
			this.searchedResults();
		  }.bind(this)
		  ,onException: function(transport) {alert(transport.responseText);}
		  ,onFailure: function(transport) {alert(transport.responseText);}
		});
	}
	
	this.toggleSelectedAreas = function(area) {

		if (checkedAreas.indexOf(area) > -1) {
			checkedAreas = checkedAreas.without(area);
			if($('area'+area)) {
				$('area'+area).checked = false;
			}
		} else {
			checkedAreas.push(area);
			if($('area'+area)) {
				$('area'+area).checked = true;
			}
		}
		//alert(checkedAreas.length);
	}
	
	this.createURL = function() {		
		//if (!propStatus) {alert('The search application has not loaded yet.');return;}
		
		var errors = [];		
		var minPrice = $('min_price').value;
		var maxPrice = $('max_price').value;
		var minBeds = $('min_beds').value;
		//var maxBeds = $('max_beds').value;
		var minBaths = $('min_baths').value;
		var keywords = $('_keyword').value;
		var aids;
		
		minPrice = minPrice.replace(/(\$|,|\.)/gi,'');
		maxPrice = maxPrice.replace(/(\$|,|\.)/gi,'');
		byKeyword = '';
		
		if (minPrice > '') {
			if (isNaN(minPrice)) {
				errors.push('Min Price must be a number.');
			}
			minPrice = '&minprice='+minPrice;
		} else {
			minPrice = '';
		}
		if (keywords > '') {
			byKeyword = '&Adtext=' + keywords;
		} else {
			byKeyword = '';
		}		
		if (maxPrice > '') {
			if (isNaN(maxPrice)) {
				errors.push('Max Price must be a number.');
			}
			maxPrice = '&maxprice='+maxPrice;
		} else {
			maxPrice = '';
		}
		
		if (minBeds == '') {
			minBeds = '';
		} else {
			minBeds = '&bedrooms='+minBeds;
		}
		
		if (minBaths == '') {
			minBaths = '';
		} else {
			minBaths = '&bathrooms='+minBaths;
		}
		
		/*if (maxBeds == '') {
			maxBeds = '';
		} else {
			maxBeds = '&maxbedrooms='+maxBeds;
		}*/
		
		if (optionsPropTypes.length > 0) {
			aids = '&aids='+optionsPropTypes;
		} else {
			aids = '';
		}
		
		// The selected area is one of the four: "All Properties %direction% of Midland"
		if (selectedAreas.length > 0 && selectedAreas[0].search(/of Midland/gi) > -1) {
			var area_ids = selectedAreas[0];
				area_ids = area_ids.split('|');
			areas = '&counties='+area_ids[0];
		// Selected areas are cities
		} else if (selectedAreas.length > 0) {
			var area_ids;
			var ar_areas = [];
			selectedAreas.each(function(s) {
				area_ids = s.split('|');
				ar_areas.push(area_ids[0]);
			});
			areas = '&cities='+ar_areas.join(',');
		// No selected areas
		} else {
			areas = '';
		}
		
		
		//alert(optionsPropTypes);
		if (errors.length == 0) {		
			//alert("/templates/reales/re_query.cfm?idxcomp_id=252&board_id=761&header=arheader2.cfm&pushed=1"+aids+minPrice+maxPrice+minBeds+minBaths+areas);
			// minprice=___&maxprice=____&&cities=______&aids=_______
			window.open("/templates/reales/re_query.cfm?idxcomp_id=252&board_id=761&header=remax-midland-mi.cfm"+aids+minPrice+maxPrice+minBeds+minBaths+areas+byKeyword+'&linkcolor=800000&activelinkcolor=808080&visitedlinkcolor=008080&bannerbgcolor=ffffff&bgcolor=ffffff','_blank');
		} else {
			alert(errors.join('\n'));
		}
		
		// &bedrooms=_______
		// /templates/reales/re_query.cfm?minprice=___&maxprice=____&idxcomp_id=252&cities=______&aids=_______&board_id=761&header=arheader2.cfm&pushed=1
	}
	
	this.panel = {
		// Load both panels : Options & Selected Areas
		display : {
			// Loads the Options tab <div>'s: Property Types & Pricing / Features.
			contentOptions : function() {
				// Show welcome message?
				var welcome_message2;
				if (readCookie('ARmessage1')) {
					welcome_message1 = ['<div class="bubble">',
										'    <div class="top">&nbsp;</div>',
										'    <div class="body">',
										'    	Welcome to our new property search application. We hope this will be an easier and more conveniant way of finding your dream home.',
										'        <div style="padding-top:5px;text-align:right;"><a href="javascript://" onclick="propSearch.panel.hideMessage.tabOptions();">Hide this Message</a></div>',
										'    </div>',
										'    <div class="footer">&nbsp;</div>',
										'</div>'];
				} else {
					welcome_message1 = ['<div class="bubble">',
										'    <div class="top">&nbsp;</div>',
										'    <div class="body">',
										'        <div style="text-align:right;"><a href="javascript://" onclick="propSearch.panel.hideMessage.tabOptions();">Show Message</a></div>',
										'    </div>',
										'    <div class="footer">&nbsp;</div>',
										'</div>'];
				}
				
				var opt_res, opt_com, opt_vac, opt_wat, opt_ope;
				
				if (optionsPropTypes.indexOf(908) > -1) {
					opt_res = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(908)">',
					'	<input type="checkbox" id="check908" checked><label for="check908">Residential</label>',
					'</div>'];
					
				} else {
					opt_res = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(908)">',
					'	<input type="checkbox" id="check908"><label for="check908">Residential</label>',
					'</div>'];
				}
				
				if (optionsPropTypes.indexOf(911) > -1) {
					opt_com = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(911)">',
					'	<input type="checkbox" id="check911" checked><label for="check911">Commercial</label>',
					'</div>'];
				} else {
					opt_com = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(911)">',
					'	<input type="checkbox" id="check911"><label for="check911">Commercial</label>',
					'</div>'];
				}
				
				if (optionsPropTypes.indexOf(909) > -1) {
					opt_vac = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(909)">',
					'  	<input type="checkbox" id="check909" checked><label for="check909">Vacant Land</label>',
					'</div>'];
				} else {
					opt_vac = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(909)">',
					'	<input type="checkbox" id="check909"><label for="check909">Vacant Land</label>',
					'</div>'];
				}
				
				if (optionsPropTypes.indexOf(1240) > -1) {
					opt_wat = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(1240)">',
					'  	<input type="checkbox" id="check1240" checked><label for="check1240">Waterfront</label>',
					'</div>'];
				} else {
					opt_wat = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(1240)">',
					'	<input type="checkbox" id="check1240"><label for="check1240">Waterfront</label>',
					'</div>'];
				}
				
				if (optionsPropTypes.indexOf(896) > -1) {
					opt_lease = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(896)">',
					'  	<input type="checkbox" id="check896" checked><label for="check896">Lease</label>',
					'</div>'];
				} else {
					opt_lease = ['<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.togglePropType(896)">',
					'	<input type="checkbox" id="check896"><label for="check896">Lease</label>',
					'</div>'];
				}
				
				if (optionsPropTypes.indexOf(1111111) > -1) {
					opt_ope = '        	<input type="checkbox" id="check1" checked onclick="propSearch.togglePropType(1240)"><label for="check1">Open Houses</label>';
				} else {
					opt_ope = '        	<input type="checkbox" id="check1" onclick="propSearch.togglePropType(1111111)"><label for="check1">Open Houses</label>';
				}
				
				
				var a = [

				'<div class="bubble">',

				'    <div class="body">',
				'    	<table width="188" border="0" cellpadding="2" cellspacing="0">',
				'          <tr>',
				'            <td colspan="2">',
				'            	<div class="title">Street Name</div>',
				'               <input type="text" size="29" id="_keyword">',
				'            </td>',
				'          </tr>',
				'          <tr>',
				'            <td>',
				'            	<div class="title">Min Price</div>',
				'                <input type="text" size="10" id="min_price">',
				'            </td>',
				'            <td>',
				'            	<div class="title">Max Price</div>',
				'                <input type="text" size="10" id="max_price">',
				'            </td>',
				'          </tr>',
				'          <tr>',
				'            <td>',
				'            	<div class="title">Min Bedrooms</div>',
				'            </td>',
				'            <td>',
				'                <select id="min_beds">',
				'               		<option value=""></option>',
				'               		<option value="1">1</option>',
				'               		<option value="2">2</option>',
				'               		<option value="3">3</option>',
				'               		<option value="4">4</option>',
				'               		<option value="5">5</option>',
				'               </select>',
				'            </td>',
				'          </tr>',
				'          <tr>',
				'            <td>',
				'            	<div class="title">Min Bathrooms</div>',
				'            </td>',
				'            <td>',
				'                <select id="min_baths">',
				'               		<option value=""></option>',
				'               		<option value="1">1</option>',
				'               		<option value="2">2</option>',
				'               		<option value="3">3</option>',
				'               		<option value="4">4</option>',
				'               		<option value="5">5</option>',
				'               </select>',
				'            </td>',
				'          </tr>',
				'        </table>',
				opt_res.join(''),
				opt_com.join(''),
				opt_vac.join(''),
				opt_wat.join(''),
				opt_lease.join(''),
				'    </div>',
				'    <div class="footer">&nbsp;</div>',
				'</div>',
				'<input type="submit" value="Find Properties" onClick="propSearch.createURL();" style="cursor:hand;cursor:pointer;float:center;" />',
				'<br /><br />',
				'<hr style="color:#6699cc;height:1px;border-style:dashed;">',
				'<br />',
				'<div class="bubble">',
				'    <div class="header" style="padding-right:107px;padding-bottom:5px;">',
				'        Search by MLS:',
				'    </div>',
				'    <div class="body">',
				'		<div style="color:#ae0000;font-size:11px;text-align:center;font-weight:bold;padding-bottom:10px;display:none;" id="mls_error"></div>',
				'		<input type="text" size="14" id="mls"> <input type="button" style="width:79px;" onClick="checkMlsNum($(\'mls\').value)" name="submit" value="Search">',
				'    </div>',
				'    <div class="footer">&nbsp;</div>',
				'</div>'];
				$('panel_areas').setStyle({display:'none'});
				$('panel_options').setStyle({display:'block'});
				$('panel_options').innerHTML = a.join(' ');
			},
			// Loads the Selected Areas tab <div>'s: Selected Areas & Search Areas.
			contentSelected : function(pref) {
				var pref = pref || {}
				start = pref.start || 0
				// Compile list of selected areas if there are any
				var v = '';
				if (start < 0) {start = 0;}
				if (start > selectedAreas.length) {return;}
				if (selectedAreas.length > 0) {
					var end;
					if (start == 0) {
						if (selectedAreas.length >= 6) {
							end = 6;
						} else {
							end = selectedAreas.length;
						}
					} else {
						if ((6+start) > selectedAreas.length) {
							end = selectedAreas.length
						} else {
							end = start+6;
						}
					}
					
					//alert(checkedAreas);
					
					for(var s = start;s<end;s++) {
						n = selectedAreas[s];
						n = n.split('|');
						//alert(n[0]);
						if (checkedAreas.indexOf(''+n[0]+'') > -1) {
							v = v + '<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.toggleSelectedAreas(\''+n[0]+'\')"> <input type="checkbox" id="area'+n[0]+'" checked><label for="area'+n[0]+'">'+n[1]+'</label> </div>';
						} else {
							v = v + '<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.toggleSelectedAreas(\''+n[0]+'\')"> <input type="checkbox" id="area'+n[0]+'"><label for="area'+n[0]+'">'+n[1]+'</label> </div>';
						}
						
						//v = v + '<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" style="position:relative;padding:2px;height:22px;"><div style="width:21px;position:absolute;left:2px;"><input type="checkbox" id="'+n[1]+'" style="padding:0px;margin:0px;"></div><div style="width:100px;position:absolute;left:22px;padding:3px;">'+n[1]+'</div></div>';
					}
				} else {
					v = '<div style="color:#767676;font-weight:bold;"><br><br><br>You have no selected areas. Search below or use the map to your left.</div>';
				}
				// If array is greater than 5, show pagination
				var paginationBubble;
				
				if (selectedAreas.length > 6) {
					var next = start + 6;
					var previous = start - 6;
					var pagination;
					pagination = '	  <div class="footer2"><a href="javascript://" onclick="propSearch.panel.display.contentSelectedAreas({start:'+previous+'});">Prev</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="javascript://" onclick="propSearch.panel.display.contentSelectedAreas({start:'+next+'});">Next</a></div>';
				} else {
					pagination = '    <div class="footer">&nbsp;</div>';
				}
				
				
				// Show welcome message?
				var welcome_message2;
				if (readCookie('ARmessage2')) {
					welcome_message2 = ['<div class="bubble">',
										'    <div class="top">&nbsp;</div>',
										'    <div class="body">',
										'    	Below is the selected areas your property search results will be returned from. You may remove and add areas from this panel.',
										'        <div style="padding-top:5px;text-align:right;"><a href="javascript://" onclick="propSearch.panel.hideMessage.tabSelected();">Hide this Message</a></a></div>',
										'    </div>',
										'    <div class="footer">&nbsp;</div>',
										'</div>'];
				} else {
					welcome_message2 = ['<div class="bubble">',
										'    <div class="top">&nbsp;</div>',
										'    <div class="body">',
										'        <div style="text-align:right;"><a href="javascript://" onclick="propSearch.panel.hideMessage.tabSelected();">Show Message</a></div>',
										'    </div>',
										'    <div class="footer">&nbsp;</div>',
										'</div>'];
				}
				
				if (selectedAreas.length > 0) {
					selectedOptions = ['    <div class="top2">Remove: <a href="javascript://" onclick="propSearch.deselectChecked();">Checked</a> | <a href="javascript://" onclick="propSearch.deselectUnChecked();">UnChecked</a>  | <a href="javascript://" onclick="propSearch.deselectAll(3);">All</a></div>'];
				} else {
					selectedOptions = ['    <div class="top">&nbsp;</div>'];
				}
				
				// HTML array to be compiled
				var a = [
				'<div class="bubble">',
				'    <div class="header">',
				'        Selected Areas',
				'        <div>These areas will be searched for listings.</div>',
				'    </div>',
				,'<div id="_selected_areas">',
				selectedOptions.join(''),
				'    <div class="body" style="height:130px;">',
				v, 				  // Selected Properties
				'    </div>',
				pagination,
				'</div>',
				'	<div class="bubble">',
				'      <div class="header">',
				'          Search Areas',
				'          <div>Can\'t find an area? Search for it by name.</div>',
				'      </div>',
				'      <div class="top">&nbsp;</div>',
				'      <div class="body">',
				'	  	  <input type="text" id="area_search" size="17" onchange="propSearch.searchAreas(this.value);"> <input type="button" onclick="" value="Search"> ',
				'      </div>',
				'	   <div class="footer">&nbsp;</div>',
				'</div>',
				'	<div class="bubble" id="searchedAreas_container" style="display:none;">',
				'      <div class="top">&nbsp;</div>',
				'      <div class="body" id="searchedAreas_results">',
				'      </div>',
				'	   <div class="footer">&nbsp;</div>',
				'</div>'];
				
				// Element settings
				$('panel_areas').innerHTML = a.join(' ');
				$('panel_options').setStyle({display:'none'});
				$('panel_areas').setStyle({display:'block'});
				$('tab_areas').className = 'areas';
				$('tab_options').className = 'options_off';
			},
			
			// Loads the Selected Areas tab <div>'s: Selected Areas & Search Areas.
			contentSelectedAreas : function(pref) {
					var pref = pref || {}
					start = pref.start || 0
					// Compile list of selected areas if there are any
					var v = '';
					if (start < 0) {start = 0;}
					if (start > selectedAreas.length) {return;}
					if (selectedAreas.length > 0) {
						var end;
						if (start == 0) {
							if (selectedAreas.length >= 6) {
								end = 6;
							} else {
								end = selectedAreas.length;
							}
						} else {
							if ((6+start) > selectedAreas.length) {
								end = selectedAreas.length
							} else {
								end = start+6;
							}
						}
						
						//alert(checkedAreas);
						
						for(var s = start;s<end;s++) {
							n = selectedAreas[s];
							n = n.split('|');
							//alert(n[0]);
							if (checkedAreas.indexOf(''+n[0]+'') > -1) {
								v = v + '<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.toggleSelectedAreas(\''+n[0]+'\')"> <input type="checkbox" id="area'+n[0]+'" checked><label for="area'+n[0]+'">'+n[1]+'</label> </div>';
							} else {
								v = v + '<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" onclick="propSearch.toggleSelectedAreas(\''+n[0]+'\')"> <input type="checkbox" id="area'+n[0]+'"><label for="area'+n[0]+'">'+n[1]+'</label> </div>';
							}
							
							//v = v + '<div class="item" onMouseOver="this.className=\'item hover\'" onMouseOut="this.className=\'item\'" style="position:relative;padding:2px;height:22px;"><div style="width:21px;position:absolute;left:2px;"><input type="checkbox" id="'+n[1]+'" style="padding:0px;margin:0px;"></div><div style="width:100px;position:absolute;left:22px;padding:3px;">'+n[1]+'</div></div>';
						}
					} else {
						v = '<div style="color:#767676;font-weight:bold;"><br><br><br>You have no selected areas. Search below or use the map to your left.</div>';
					}
					// If array is greater than 5, show pagination
					var paginationBubble;
					
					if (selectedAreas.length > 6) {
						var next = start + 6;
						var previous = start - 6;
						var pagination;
						pagination = '	  <div class="footer2"><a href="javascript://" onclick="propSearch.panel.display.contentSelectedAreas({start:'+previous+'});">Prev</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="javascript://" onclick="propSearch.panel.display.contentSelectedAreas({start:'+next+'});">Next</a></div>';
					} else {
						pagination = '    <div class="footer">&nbsp;</div>';
					}
					
									
					if (selectedAreas.length > 0) {
						selectedOptions = ['    <div class="top2">Remove: <a href="javascript://" onclick="propSearch.deselectChecked();">Checked</a> | <a href="javascript://" onclick="propSearch.deselectUnChecked();">UnChecked</a>  | <a href="javascript://" onclick="propSearch.deselectAll(3);">All</a></div>'];
					} else {
						selectedOptions = ['    <div class="top">&nbsp;</div>'];
					}
					
					// HTML array to be compiled
					var a = [selectedOptions.join(''),
					'    <div class="body" style="height:130px;">',
					v, 				  // Selected Properties
					'    </div>',
					pagination];
					
					// Element settings
					$('_selected_areas').innerHTML = a.join(' ');
			}
		},
		// Update tabs: mainly selected areas number
		updateTabs : function() {
			var tab_total_selected_areas = $('total_selected_areas');
		},
		// Set cookie to hide message bubble for either panel, then refresh panel.
		hideMessage : {
			tabOptions : function() {
				var cookie = readCookie('ARmessage1');
				if (cookie) {
					eraseCookie('ARmessage1');
				} else {
					createCookie('ARmessage1',1,340,'10.0.0.5');
				}
				obj.panel.display.contentOptions();
			},
			tabSelected : function() {
				var cookie = readCookie('ARmessage2');
				if (cookie) {
					eraseCookie('ARmessage2');
				} else {
					createCookie('ARmessage2',1,340,'10.0.0.5');
				}
				obj.panel.display.contentSelected();
			}
		}
	}
	
}
propSearch = new flashPropSearch();