// MAIN SITE FUNCTIONS V2.0 - 12/29/2011 9:00 AM

jQuery(document).ready(function() {
								
	var idxurl=window.location.pathname;								
	var siteurl=window.location.pathname;
	var sitename = siteurl.split("/");
	var blogurl = sitename[1];	

	jQuery.cookie('BlogURL', blogurl);
	jQuery.cookie('BlogType', 'main');	
								
	//var baseurl = "http://"+location.host;
	var baseurl = "http://realtyexecutives.com";
	var theme = "rei20";	
	
	var propertyListTotal = 19;
	var propertyListCurrent = 0;

	var numphotos = 2;

	var sfocus;
	jQuery(":input").focus(function () {
    	 sfocus = this.id;
	});


	// GET URL PARAMETERS
	function gup( name ){
  		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  		var regexS = "[\\?&]"+name+"=([^&#]*)";
  		var regex = new RegExp( regexS );
  		var results = regex.exec( window.location.href );
  		if( results == null )
    		return "";
  		else
    		return results[1];
	}
	var mls = gup('mls');
	var cc = gup('cc');

	// SEARCH OPACITY
	jQuery("div#property_search.home").css({ opacity: 0.60 });
	jQuery("div#property_search.home").mouseenter(function() {
		jQuery("div#property_search.home").fadeTo("fast", 1.0);									 
  	});
	jQuery("div#left.home").mouseleave(function() {
		jQuery("div#property_search.home").fadeTo("slow", 0.60);					 
  	});	


	function DisableSearchFormFields() {
		jQuery("select#idx-q-BathsMin").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');		
		jQuery("select#idx-q-PriceMin").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#idx-q-PriceMax").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#idx-q-BedsMin").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');
		return;
	}
	
	function EnableSearchFormFields() {
		jQuery("select#idx-q-BathsMin").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');		
		jQuery("select#idx-q-PriceMin").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-PriceMax").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-BedsMin").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-PropertyTypes").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');		
		return;
	}		

	function ClearSearchFormFields2() {
		jQuery("select#idx-q-BedsMin option[value='']").attr("selected", "selected");
		jQuery("select#idx-q-BathsMin option[value='']").attr("selected", "selected");
		jQuery("select#idx-q-PriceMin option[value='']").attr("selected", "selected");
		jQuery("select#idx-q-PriceMax option[value='']").attr("selected", "selected");
		jQuery("select#idx-q-DaysOnMarketMin option[value='']").attr("selected", "selected");	
		jQuery("select#idx-q-DaysOnMarketMax option[value='']").attr("selected", "selected");			
		jQuery("select#idx-q-PriceDropDays option[value='']").attr("selected", "selected");
		jQuery("select#idx-q-PriceDropPercent option[value='']").attr("selected", "selected");
		jQuery("select#idx-q-YearBuiltMin option[value='']").attr("selected", "selected");		
		jQuery("select#idx-q-YearBuiltMax option[value='']").attr("selected", "selected");		
		return;
	}
	


	function generateGUID() {
		var result, i, j;
		result = '';
		for(j=0; j<32; j++) {
		if( j == 8 || j == 12|| j == 16|| j == 20)
			result = result + '-';
			i = Math.floor(Math.random()*16).toString(16).toUpperCase();
			result = result + i;
		}
		return result;
	}
	
	function is_Integer(value) { 
		var reInteger = /^\d+$/;
   		return (reInteger.test(value));		
	}	

	function is_StateAbbrev(value) {
   		var stateAbbrevRegex = /^(A[LKSZRAP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$/;
   		return (stateAbbrevRegex.test(value));
	}
	
	function is_USZipCode(value) {
   		var zipCodeRegex = /^\d{5}([\-]\d{4})?$/;
   		return (zipCodeRegex.test(value));
	}
	
	function is_CAPostalCode(value) {
		var postalCodeRegex = /^([A-Za-z][0-9][A-Za-z])*$/		
    	return postalCodeRegex.test(value);
	}	

	function updateCityParms(data) { 
		//alert('Enter Key- updateCity '+data);
		var suggest = data.split("|");
		var city = suggest[0];
		var sc = suggest[1];
		var country = suggest[2];
		var cc = suggest[3];
		var desc = city+', '+sc+' - '+country;
		jQuery('input#searchdescription').val(desc);

		jQuery('input#location').val(desc);	
		jQuery('input#idx-q-Cities').val(city);		
		jQuery('input#idx-q-States').val(sc);
		jQuery('input#idx-q-Country').val(cc);
		jQuery('input#mapcountry').val(country);	
		jQuery('input#searchtype').val('city');					

		var pt = jQuery("select#idx-q-PropertyTypes").val();		
		var pn = jQuery("select#idx-q-PriceMin").val();				
		var px = jQuery("select#idx-q-PriceMax").val();				
		var bm = jQuery("select#idx-q-BedsMin").val();				
		var bn = jQuery("select#idx-q-BathsMin").val();
		var domm = jQuery("select#idx-q-DaysOnMarketMin").val();
		var domx = jQuery("select#idx-q-DaysOnMarketMax").val();			
		var pdd = jQuery("select#idx-q-PriceDropDays").val();
		var pdp = jQuery("select#idx-q-PriceDropPercent").val();
		var ybm = jQuery("select#idx-q-YearBuiltMin").val();		
		var ybx = jQuery("select#idx-q-YearBuiltMax").val();			
		var sqft = jQuery("select#idx-q-ImprovedSqFtMin").val();	
		var ws = jQuery("select#idx-q-WalkScore").val();
		var blogurl = jQuery("input#idx-q-BlogURL").val();
		var blogid = jQuery("input#idx-q-BlogID").val();		
		var blogtype = jQuery("input#idx-q-BlogType").val();		
		var vid = jQuery.cookie("VisitorGUID");
		
		var searchstring = 'city='+city+'&sc='+sc+'&country='+country+'&cc='+cc+'&pt='+pt+'&pm='+pn+'&px='+px+'&bm='+bm+'&bn='+bn+'&domm='+domm+'&domx='+domx+'&pdd='+pdd+'&pdp='+pdp+'&ybm='+ybm+'&ybx='+ybx+'&sqft='+sqft+'&ws='+ws+'&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid+'&stab=location&stype=city';
						
		jQuery('input#searchstring').val(searchstring);			
		//alert(searchstring);
		return;
	}

	function updateZipCodeParms(data) { 								// OK - On Tab, Enter or Arrows from Suggestions List
		//alert('updateZipCodeParms '+data);
		var suggest = data.split("|");
		var zip = suggest[0];		
		var city = suggest[1];
		var sc = suggest[2];
		var country = suggest[3];
		var cc = suggest[4];
		var desc = zip+' - '+city+', '+sc+' - '+ country;
		jQuery('input#searchdescription').val(desc);
		
		//alert('Update Zip Code '+data);				
		jQuery('input#location').val(zip);		
		jQuery('input#idx-q-Cities').val(city);		
		jQuery('input#idx-q-States').val(sc);
		jQuery('input#idx-q-Country').val(cc);
		jQuery('input#mapcountry').val(country);		
		jQuery('input#searchtype').val('zipcode');					
		
		var pn = jQuery("select#idx-q-PriceMin").val();				
		var px = jQuery("select#idx-q-PriceMax").val();				
		var bm = jQuery("select#idx-q-BedsMin").val();				
		var bn = jQuery("select#idx-q-BathsMin").val();
		var pt = jQuery("select#idx-q-PropertyTypes").val();
		var domm = jQuery("select#idx-q-DaysOnMarketMin").val();
		var domx = jQuery("select#idx-q-DaysOnMarketMax").val();			
		var pdd = jQuery("select#idx-q-PriceDropDays").val();
		var pdp = jQuery("select#idx-q-PriceDropPercent").val();
		var ybm = jQuery("select#idx-q-YearBuiltMin").val();		
		var ybx = jQuery("select#idx-q-YearBuiltMax").val();			
		var sqft = jQuery("select#idx-q-ImprovedSqFtMin").val();	
		var ws = jQuery("select#idx-q-WalkScore").val();				
		var blogurl = jQuery("input#idx-q-BlogURL").val();
		var blogid = jQuery("input#idx-q-BlogID").val();		
		var blogtype = jQuery("input#idx-q-BlogType").val();		
		var vid = jQuery.cookie("VisitorGUID");

		var searchstring = 'zip='+zip+'&city='+city+'&sc='+sc+'&country='+country+'&cc='+cc+'&pt='+pt+'&pm='+pn+'&px='+px+'&bm='+bm+'&bn='+bn+'&domm='+domm+'&domx='+domx+'&pdd='+pdd+'&pdp='+pdp+'&ybm='+ybm+'&ybx='+ybx+'&sqft='+sqft+'&ws='+ws+'&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid+'&stab=Location&stype=zipcode';						
		jQuery('input#searchstring').val(searchstring);			
		//alert(searchstring);
		return;		
	}


	function updatePostalCodeParms(data) { 								// OK - On Tab, Enter or Arrows from Suggestions List
		//alert('updatePostalCodeParms '+data);
		var suggest = data.split("|");
		var postal = suggest[0];		
		var city = suggest[1];
		var sc = suggest[2];
		var country = suggest[3];
		var cc = suggest[4];
		var desc = postal+' - '+city+', '+sc+' - '+ country;
		jQuery('input#searchdescription').val(desc);
		
		//alert('Update Zip Code '+data);				
		jQuery('input#location').val(postal);		
		jQuery('input#idx-q-Cities').val(city);		
		jQuery('input#idx-q-States').val(sc);
		jQuery('input#idx-q-Country').val(cc);
		jQuery('input#mapcountry').val(country);		
		jQuery('input#searchtype').val('postalcode');					
		
		var pn = jQuery("select#idx-q-PriceMin").val();				
		var px = jQuery("select#idx-q-PriceMax").val();				
		var bm = jQuery("select#idx-q-BedsMin").val();				
		var bn = jQuery("select#idx-q-BathsMin").val();
		var pt = jQuery("select#idx-q-PropertyTypes").val();
		var domm = jQuery("select#idx-q-DaysOnMarketMin").val();
		var domx = jQuery("select#idx-q-DaysOnMarketMax").val();			
		var pdd = jQuery("select#idx-q-PriceDropDays").val();
		var pdp = jQuery("select#idx-q-PriceDropPercent").val();
		var ybm = jQuery("select#idx-q-YearBuiltMin").val();		
		var ybx = jQuery("select#idx-q-YearBuiltMax").val();			
		var sqft = jQuery("select#idx-q-ImprovedSqFtMin").val();	
		var ws = jQuery("select#idx-q-WalkScore").val();				
		var blogurl = jQuery("input#idx-q-BlogURL").val();
		var blogid = jQuery("input#idx-q-BlogID").val();		
		var blogtype = jQuery("input#idx-q-BlogType").val();		
		var vid = jQuery.cookie("VisitorGUID");

		var searchstring = 'postal='+postal+'&city='+city+'&sc='+sc+'&country='+country+'&cc='+cc+'&pt='+pt+'&pm='+pn+'&px='+px+'&bm='+bm+'&bn='+bn+'&domm='+domm+'&domx='+domx+'&pdd='+pdd+'&pdp='+pdp+'&ybm='+ybm+'&ybx='+ybx+'&sqft='+sqft+'&ws='+ws+'&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid+'&stab=Location&stype=postalcode';						
		jQuery('input#searchstring').val(searchstring);			
		//alert(searchstring);
		return;		
	}



	document.onkeyup = KeyCheckUp;
	function KeyCheckUp(e) {
		var keyCode =(window.event)? event.keyCode : e.which;
			
		switch(keyCode) {
			case 9:		//Tab
				//alert( 'Tab Key Pressed' );
				if (sfocus == 'propFirstName' || sfocus == 'propLastName' || sfocus == 'propPhone' || sfocus == 'propUserEmail' || sfocus == 'propComments' || sfocus == 'schedFirstName' || sfocus == 'schedLastName' || sfocus == 'schedPhone' || sfocus == 'schedUserEmail' || sfocus == 'schedMonth' || sfocus == 'schedDay' || sfocus == 'password' || sfocus == 'enter' || sfocus == 'lostemail' || sfocus == 'lostsubmit') {   //Other forms
					return;
				}				
								
				propertyListCurrent = 1;
				jQuery("#suggestionslist ul li").removeClass("cityselected");					
				jQuery("#suggestionslist ul li:nth-child(1)").addClass("cityselected");

				var txt = jQuery("#suggestionslist ul li:nth-child(1)").text();							
				var tit = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").attr("title"); // zipcode,city,state,country,countrycode					
				var csc = jQuery("#suggestionslist ul li:nth-child(1)").attr("id");
				var stype = jQuery("#suggestionslist ul li:nth-child(1)").attr("lang");				
				jQuery('input#location').val(txt);
				jQuery('input#searchtype').val(stype);				
		
				if ( stype == 'city' ) {
					updateCityParms(csc);
				}
				if ( stype == 'zipcode' ) {
					updateZipCodeParms(tit);	
				}				
				if ( stype == 'postalcode' ) {
					updatePostalCodeParms(tit);	
				}				
				break;	

			case 13:	//Enter
			
		 		//alert(sfocus); // NEW 11-10-2011
				if (sfocus == 'propFirstName' || sfocus == 'propLastName' || sfocus == 'propPhone' || sfocus == 'propUserEmail' || sfocus == 'propComments') {   // Request More Info
					//alert('More Property Info');
					jQuery('.ui-dialog').find('button:first').trigger('click');					
					return;
				}				

				if (sfocus == 'schedFirstName' || sfocus == 'schedLastName' || sfocus == 'schedPhone' || sfocus == 'schedUserEmail' || sfocus == 'schedMonth' || sfocus == 'schedDay') {   // Request More Info
					//alert('Schedule Showing');
					jQuery('.ui-dialog').find('button:first').trigger('click');					
					return;
				}	
				
				if (sfocus == 'password' || sfocus == 'enter') {   // Executive Access Login
					jQuery("input#enter").trigger("click");
					return;
				}
		
				if (sfocus == 'lostemail' || sfocus == 'lostsubmit') {   // Lost Password Executive Access Login
					jQuery("input#lostsubmit").trigger("click");
					return;
				}	
	
			
				if (jQuery('div#suggestionsbox').is(":visible")) {  //Box shown
					jQuery('div#suggestionsbox').hide();						
				} else {
					var stype = jQuery("input#searchtype").val();	
					if (stype == 'city') {
						jQuery("div#searchbutton").trigger("click");							
					}
					if (stype == 'zipcode') {
						jQuery("div#searchbutton").trigger("click");							
					}
					if (stype == 'postalcode') {
						jQuery("div#searchbutton").trigger("click");							
					}					
					if (jQuery('div.searchmls').is(":visible")) {
						jQuery("div.searchmls").trigger("click");				
					}				
					if (jQuery('div.searchmap').is(":visible")) {
						jQuery("div.searchmap").trigger("click");
					}
				}				
				break;
	
			case 27:	//Escape
				propertyListCurrent = 0;			
				jQuery('div#suggestionsbox').fadeOut(500); //Location 
				jQuery('input#location').val('Start typing a city or zip/postal code');
				jQuery('input#idx-q-Cities').val('');		
				jQuery('input#idx-q-States').val('');
				jQuery('input#idx-q-Country').val('');
				jQuery("input#searchstring").val('');
				jQuery("input#searchtype").val('');
				jQuery("input#searchdescription").val('');				
				jQuery("input#mapurl").val(''); 		 // Maps
				jQuery("input#mapcountry").val('');
				jQuery("input#mapcc").val('');
				jQuery("input#mapstate").val('');
				jQuery("input#mapsc").val('');				
				break;
				
			case 38:	// Up Arrow
				if ( propertyListCurrent > 1 ) {
					propertyListCurrent--;					
					jQuery("#suggestionslist ul li").removeClass("cityselected");					
					jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").addClass("cityselected");
					var csc = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").attr("id"); // city, state country
					var tit = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").attr("title"); // zipcode,city,state,country,countrycode					
					var txt = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").text(); // city, state country
					var stype = jQuery("#suggestionslist ul li:nth-child(1)").attr("lang");  						
					jQuery('input#location').val(txt);
					jQuery('input#searchtype').val(stype);						
					if ( stype == 'city' ) {
						updateCityParms(csc);
					}
					if ( stype == 'zipcode' ) {
						updateZipCodeParms(tit);	
					}				
					if ( stype == 'postalcode' ) {
						updatePostalCodeParms(tit);	
					}
				}
				break;	

			case 40:	// Down Arrow
				if ( propertyListCurrent < propertyListTotal) {
					propertyListCurrent++;
					jQuery("#suggestionslist ul li").removeClass("cityselected");				
					jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").addClass("cityselected");
					var csc = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").attr("id"); // city, state country
					var tit = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").attr("title"); // zipcode,city,state,country,countrycode						
					var txt = jQuery("#suggestionslist ul li:nth-child("+propertyListCurrent+")").text(); // city, state country
					var stype = jQuery("#suggestionslist ul li:nth-child(1)").attr("lang");  					
					jQuery('input#location').val(txt);
					jQuery('input#searchtype').val(stype);						
					if ( stype == 'city' ) {
						updateCityParms(csc);
					}
					if ( stype == 'zipcode' ) {
						updateZipCodeParms(tit);
					}				
					if ( stype == 'postalcode' ) {
						updatePostalCodeParms(tit);	
					}
				}
				break;

			case 113:	// HIDDEN - SEARCH ALERT  - F2
				jQuery("#sadialog").dialog( "destroy" );
				jQuery("#sadialog").dialog({
					resizable: false,
					draggable: true,			
					width: 640,									
					height: 480,
					modal: true
				});												
				jQuery("#sadialog #comingsoon").addClass("hidden");				
				jQuery("#sadialog #left").removeClass("hidden");				
				jQuery("#sadialog #right").removeClass("hidden");	
				break;

			case 115:	// HIDDEN - ADVANCED SEARCH  - F4
				if (jQuery('div#searchbutton.location').is(":visible")) {		
					jQuery("#advancedsearch").dialog( "destroy" );
					jQuery("#advancedsearch").dialog({
						resizable: false,
						draggable: true,			
						width: 520,		   							
						height: 480,
						modal: true
					});												
					jQuery("#advancedsearch #comingsoon").addClass("hidden");				
					jQuery("#advancedsearch #left").removeClass("hidden");				
					jQuery("#advancedsearch #right").removeClass("hidden");
				}					
				break;

			case 119:	// HIDDEN - SAVE SEARCHES  - F8
				//alert("F8 /Key 119 - My Saved Searches");
				showSavedSearches();				
				break;
				
			case 121:	// HIDDEN - SAVE SEARCHES  - F10
				//alert("F8 /Key 119 - My Saved Searches");
				showSavedOptions();		
				break;
				
			case 122:	// HIDDEN - SAVE SEARCHES  - F11
				//alert("F11/Key 122 - Startup Registration");
				showStartupRegistration();	
				break;

			default:
				//alert (keyCode);
				
				if (sfocus == 'propFirstName' || sfocus == 'propLastName' || sfocus == 'propPhone' || sfocus == 'propUserEmail' || sfocus == 'propComments' || sfocus == 'schedFirstName' || sfocus == 'schedLastName' || sfocus == 'schedPhone' || sfocus == 'schedUserEmail' || sfocus == 'schedMonth' || sfocus == 'schedDay' || sfocus == 'password' || sfocus == 'enter' || sfocus == 'lostemail' || sfocus == 'lostsubmit') {   //Other forms
					return;
				}				
				
				var q = jQuery("input#location").val();  //Search Cities
				//alert(q);
				if(q.length == 0) {  // Nothing entered
					//alert("nothing entered");
					jQuery('div#suggestionsbox').hide();
					return;
				}
			
			
				if(q.length > 2) {  // At least 3 characters
				
					if ( is_Integer(q) == true ) {					// US - Zipcodes
						var dataString = 'q='+q+'&st=zipcode';				
						jQuery.ajax({
							type: "POST",
   		 					url: "http://realtyexecutives.com/wp-content/themes/rei20/functions_custom.php?action=searchlocation",
   		 					data: dataString,				
    						success: function(data){
								//alert('ZIPCODES '+data);
								jQuery('div#suggestionsbox').show();					
								jQuery("div##suggestionslist").empty();
								jQuery(data).appendTo("div##suggestionslist");
								//alert('US Zipcode '+q);
								if ( is_USZipCode(q) == true ) {  	// US 
									jQuery("input#searchtype").val('zipcode');
								}	
							}
						});							
						return;
					}
					
					if ( is_CAPostalCode(q) == true ) {				// CA	- To be determined
						//alert('Postal Code '+q);
						jQuery("input#searchtype").val('postalcode');
						var dataString = 'q='+q+'&st=postalcode';				
						jQuery.ajax({
							type: "POST",
   		 					url: "http://realtyexecutives.com/wp-content/themes/rei20/functions_custom.php?action=searchlocation",
   		 					data: dataString,				
    						success: function(data){
								//alert('POSTAL CODES '+data);
								jQuery("input#searchtype").val('postalcode');									
								jQuery('div#suggestionsbox').show();					
								jQuery("div##suggestionslist").empty();
								jQuery(data).appendTo("div##suggestionslist");
							}
						});						
						return;
					}
					
					var dataString = 'q='+q+'&st=location';				
					jQuery.ajax({
						type: "POST",
   		 				url: "http://realtyexecutives.com/wp-content/themes/rei20/functions_custom.php?action=searchlocation",
   		 				data: dataString,				
    					success: function(data){
							//alert('LOCATIONS '+data)
							jQuery("input#searchtype").val('location');								
							jQuery('div#suggestionsbox').show();					
							jQuery("div##suggestionslist").empty();
							jQuery(data).appendTo("div##suggestionslist");
						}
					});
					return;	

				} else {
					jQuery('div#suggestionsbox').show();					
					jQuery('div##suggestionslist').empty();
					jQuery('<ul><li id="example">EXAMPLES</li><li id="examplesub">City - <span>Phoenix</span></li><li id="examplesub" class="last">Zip/Postal/Code - <span>85001 or N6J 1Y3</span></li></ul>').appendTo("div##suggestionslist");				
					return;
				}
				

			
		} // End Switch		
	} // End Function




	// SEARCH IN PROGRESS DIALOG ==============================================================================
	function showSearchingDialog() {	
		jQuery("#searching").dialog( "destroy" );
		jQuery("#searching").dialog({
			resizable: false,
			draggable: false,			
			width: 200,									
			height: 90,
			modal: true
		});												
		jQuery("#searching").siblings('div.ui-dialog-titlebar').remove();
		return;			
	}
	




								
	// LOCATION SEARCH ===========================================================================	
	// LOCATION TAB	
	jQuery('li#location').bind('click', function(e) {
		//alert('Location Tab');										 
		resetPrices('location');												 
		resetTabs();
		jQuery("li#moreoptshome").show();		
		jQuery("select#idx-q-BedsMin").removeClass('hidden');
		jQuery("select#idx-q-BathsMin").removeClass('hidden');		
		jQuery("a.location").addClass('current');
		jQuery("div#suggest").removeClass('hidden');
		jQuery('div#searchbutton').addClass('location');
		jQuery("input#searchtype").val('city');		
		return;
	});		
	
	// LOCATION FIELD	
	jQuery('input#location').bind('click', function(e) {
		//alert('Location Field');
		propertyListCurrent = 0;		
 		jQuery("input#location").val('');
		jQuery('div#suggestionsbox').hide();

		jQuery("select#idx-q-PropertyTypes").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-PriceMin").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-PriceMax").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-BedsMin").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		jQuery("select#idx-q-BathsMin").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed');
		
		jQuery('input#searchtype').val('');	
		jQuery('input#searchstring').val('');
		jQuery('input#searchdescription').val('');		
		
		jQuery('input#idx-q-Cities').val('');		
		jQuery('input#idx-q-States').val('');
		jQuery('input#idx-q-Country').val('');

		jQuery('input#mapurl').val('');
		jQuery('input#mapcountry').val('');		
		jQuery('input#mapcc').val('');
		jQuery('input#mapstate').val('');
		jQuery('input#mapsc').val('');		
	});
	

	// LOCATION SEARCH BUTTON	
	jQuery('div#searchbutton').bind('click', function(e) {
													  
		var loc = jQuery("input#location").val(); 				// Nothing Entered		
		//alert('Search Button - '+loc);	
		
		if (loc == 'Start typing a city or zip/postal code') {
			alert('Please enter a city or zip/postal code!');		
			return;		
		}
		if (loc == '') {										// Input field is empty
			alert('Please enter a city or zip/postal code!');		
			return;		
		}

		if ( is_USZipCode(loc) == true ) {						//US Zipcode
			//alert('Search Button - Valid Zip Code '+loc);
			jQuery("div#searching").html('SEARCHING ZIPCODES<br /><img id="ajax-search" src="http://realtyexecutives.com/wp-content/images/ajax-search.gif" border="0"/>');			
			showSearchingDialog();			
		
			//var dataString = jQuery("input#searchstring").val();
			//alert(dataString);
			//jQuery.ajax({
			//	type: "POST",
			//	url: ""+baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=visitorsavesearch",
   			// 	data: dataString,				
			//	success: function(data){
					//alert('Save Results = '+data);
			//		setTimeout(function(){
						$url = ''+baseurl+'/idx/zip/'+loc+'/?idx-q-PropertyTypes='+jQuery("select#idx-q-PropertyTypes").val()+'&idx-q-PriceMin='+jQuery("select#idx-q-PriceMin").val()+'&idx-q-PriceMax='+jQuery("select#idx-q-PriceMax").val()+'&idx-q-BedsMin='+jQuery("select#idx-q-BedsMin").val()+'&idx-q-BathsMin='+jQuery("select#idx-q-BathsMin").val()+'&idx-q-DaysOnMarketMin='+jQuery("select#idx-q-DaysOnMarketMin").val()+'&idx-q-DaysOnMarketMax='+jQuery("select#idx-q-DaysOnMarketMax").val()+'&idx-q-PriceDropDays='+jQuery("select#idx-q-PriceDropDays").val()+'&idx-q-PriceDropPercent='+jQuery("select#idx-q-PriceDropPercent").val()+'&idx-q-YearBuiltMin='+jQuery("select#idx-q-YearBuiltMin").val()+'&idx-q-YearBuiltMax='+jQuery("select#idx-q-YearBuiltMax").val()+'&idx-q-ImprovedSqFtMin"='+jQuery("select#idx-q-ImprovedSqFtMin").val()+'&idx-q-WalkScore"='+jQuery("select#idx-q-WalkScore").val()+'&idx-q-BlogURL='+jQuery("input#idx-q-BlogURL").val()+'&idx-q-BlogID='+jQuery("input#idx-q-BlogID").val()+'&idx-q-BlogType='+jQuery("input#idx-q-BlogType").val()+'&idx-q-VID='+jQuery.cookie("VisitorGUID")+'&idx-q-Tab=location&idx-q-SearchType=zipcode';	
						//alert($url);
						window.location = $url;
			//		}, 200);				
			//	}
			//});				
			return;
		}
		
		if ( is_CAPostalCode(loc) == true ) {					//CA Postal Code
			//alert('Search Button - Valid Postal Code '+loc);
			jQuery("div#searching").html('SEARCHING POSTAL CODES<br /><img id="ajax-search" src="http://realtyexecutives.com/wp-content/images/ajax-search.gif" border="0"/>');			
			showSearchingDialog();			
		
			//var dataString = jQuery("input#searchstring").val();
			//alert(dataString);
			//jQuery.ajax({
			//	type: "POST",
			//	url: ""+baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=visitorsavesearch",
   			// 	data: dataString,				
			//	success: function(data){
					//alert('Save Results = '+data);
			//		setTimeout(function(){
						$url = ''+baseurl+'/idx/zip/'+loc+'/?idx-q-PropertyTypes='+jQuery("select#idx-q-PropertyTypes").val()+'&idx-q-PriceMin='+jQuery("select#idx-q-PriceMin").val()+'&idx-q-PriceMax='+jQuery("select#idx-q-PriceMax").val()+'&idx-q-BedsMin='+jQuery("select#idx-q-BedsMin").val()+'&idx-q-BathsMin='+jQuery("select#idx-q-BathsMin").val()+'&idx-q-DaysOnMarketMin='+jQuery("select#idx-q-DaysOnMarketMin").val()+'&idx-q-DaysOnMarketMax='+jQuery("select#idx-q-DaysOnMarketMax").val()+'&idx-q-PriceDropDays='+jQuery("select#idx-q-PriceDropDays").val()+'&idx-q-PriceDropPercent='+jQuery("select#idx-q-PriceDropPercent").val()+'&idx-q-YearBuiltMin='+jQuery("select#idx-q-YearBuiltMin").val()+'&idx-q-YearBuiltMax='+jQuery("select#idx-q-YearBuiltMax").val()+'&idx-q-ImprovedSqFtMin"='+jQuery("select#idx-q-ImprovedSqFtMin").val()+'&idx-q-WalkScore"='+jQuery("select#idx-q-WalkScore").val()+'&idx-q-BlogURL='+jQuery("input#idx-q-BlogURL").val()+'&idx-q-BlogID='+jQuery("input#idx-q-BlogID").val()+'&idx-q-BlogType='+jQuery("input#idx-q-BlogType").val()+'&idx-q-VID='+jQuery.cookie("VisitorGUID")+'&idx-q-Tab=location&idx-q-SearchType=postalcode';	
						//alert($url);
						window.location = $url;
			//		}, 200);				
			//	}
			//});					
			return;
		}

		//alert('Search City - '+loc);

		// Search City
		jQuery("div#searching").html('SEARCHING LOCATION<br /><img id="ajax-search" src="http://realtyexecutives.com/wp-content/images/ajax-search.gif" border="0"/>');
		//showSearchingDialog();	
		
		//var dataString = jQuery("input#searchstring").val();
		//alert('Save Visitor Search = DATA = '+ dataString);
		//jQuery.ajax({
		//		type: "POST",
		//	url: ""+baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=visitorsavesearch",
   		// 	data: dataString,				
		//	success: function(data){
				//alert('Save Results = '+data);
		//		setTimeout(function(){
					$url = ''+baseurl+'/idx/?idx-q-PropertyTypes='+jQuery("select#idx-q-PropertyTypes").val()+'&idx-q-Country='+jQuery("input#idx-q-Country").val()+'&idx-q-States='+jQuery("input#idx-q-States").val()+'&idx-q-Cities='+jQuery("input#idx-q-Cities").val()+'&idx-q-PriceMin='+jQuery("select#idx-q-PriceMin").val()+'&idx-q-PriceMax='+jQuery("select#idx-q-PriceMax").val()+'&idx-q-BedsMin='+jQuery("select#idx-q-BedsMin").val()+'&idx-q-BathsMin='+jQuery("select#idx-q-BathsMin").val()+'&idx-q-DaysOnMarketMin='+jQuery("select#idx-q-DaysOnMarketMin").val()+'&idx-q-DaysOnMarketMax='+jQuery("select#idx-q-DaysOnMarketMax").val()+'&idx-q-PriceDropDays='+jQuery("select#idx-q-PriceDropDays").val()+'&idx-q-PriceDropPercent='+jQuery("select#idx-q-PriceDropPercent").val()+'&idx-q-YearBuiltMin='+jQuery("select#idx-q-YearBuiltMin").val()+'&idx-q-YearBuiltMax='+jQuery("select#idx-q-YearBuiltMax").val()+'&idx-q-ImprovedSqFtMin"='+jQuery("select#idx-q-ImprovedSqFtMin").val()+'&idx-q-WalkScore"='+jQuery("select#idx-q-WalkScore").val()+'&idx-q-BlogURL='+jQuery("input#idx-q-BlogURL").val()+'&idx-q-BlogID='+jQuery("input#idx-q-BlogID").val()+'&idx-q-BlogType='+jQuery("input#idx-q-BlogType").val()+'&idx-q-VID='+jQuery.cookie("VisitorGUID")+'&idx-q-Tab=location&idx-q-SearchType='+jQuery('input#searchtype').val()+'';	
					//alert('URL = '+$url);
					window.location = $url;
		//		}, 200);				
		//	}
		//});		
		return;	
	});





	// MLS SEARCH =============================================================================================================================================================================
	// MLS TAB	
	jQuery('li#mls').bind('click', function(e) {						
		resetTabs();											
		jQuery("a.mls").addClass('current');
		jQuery("div#mls").removeClass('hidden');
		jQuery("input#searchtype").val('mls');		
		return;
	});
	
	// MLS FIELD		
	jQuery('input#mls').bind('click', function(e) {
		jQuery(this).val('')											   
		jQuery("select#mlsstate").attr("disabled", false).css("color", "black").removeClass('fieldsdimmed').attr("selected", "selected").val('');
	});		
	
	// MLS SEARCH BUTTON
	jQuery('div.searchmls').bind('click', function(e) {
		//alert('MLS Button clicked!');												   
												   
		var mls = jQuery("input#mls").val();
		if ( mls == 'Enter a MLS number' ) {
			alert('Please enter a MLS Number!');	
			return;				
		}

		jQuery("div#searching").html('SEARCHING MLS NUMBER<br /><img id="ajax-search" src="http://realtyexecutives.com/wp-content/images/ajax-search.gif" border="0"/>');	
		//showSearchingDialog();
		
		var blogurl = jQuery("input#idx-q-BlogURL").val();
		var blogid = jQuery("input#idx-q-BlogID").val();		
		var blogtype = jQuery("input#idx-q-BlogType").val();	
		var vid = jQuery.cookie("VisitorGUID");
		var mls = jQuery("input#mls").val();
		var sc = jQuery("select#mlsstate").val();

		var country = '';			
		var cc = '';	
		
		if (sc != '') {
			var state = jQuery("select#mlsstate option:selected").text();	
			if ( is_StateAbbrev(sc) == true ) {
				//alert('State '+sc);
				var country = 'United States';			
				var cc = 'US';
			} else {
				//alert('Not a US State '+sc);
				var country = 'Canada';
				var cc = 'CA';				
			}
			var dataString = 'mls='+mls+'&country='+country+'&cc='+cc+'&state='+state+'&sc='+sc+'&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid+'&stype=mls';
		} else {
			var dataString = 'mls='+mls+'&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid+'&stype=mls';			
		}
		
		//jQuery('input#searchstring').val(dataString);	
		//alert(dataString);
		
		//jQuery.ajax({
		//	type: "POST",
		//	url: ""+baseurl+"/wp-content/themes/rei20/functions_custom.php?action=visitorsavesearch",
   		// 	data: dataString,				
		//	success: function(data){
				//alert(data);
				if ( state == '' ) {
					window.location = baseurl+"/idx/?idx-q-MlsNumbers="+mls+"&idx-q-BlogURL="+blogurl+"&idx-q-BlogID="+blogid+"&idx-q-BlogType="+blogtype+"&idx-q-VID="+vid+"&idx-q-Tab=mls&idx-q-SearchType=mls";		
				} else {
					window.location = baseurl+"/idx/?idx-q-MlsNumbers="+mls+"&idx-q-States="+sc+"&idx-q-BlogURL="+blogurl+"&idx-q-BlogID="+blogid+"&idx-q-BlogType="+blogtype+"&idx-q-VID="+vid+"&idx-q-Tab=mls&idx-q-SearchType=mls"; 		
				}				
		//	}
		//});		
		return;		
	});
	



	// MAP SEARCH - OK =============================================================================================================================================================================
	// MAP TAB
	jQuery('li#maps').bind('click', function(e) {
		resetTabs();
		jQuery("a.maps").addClass('current');
		jQuery("div#maps").removeClass('hidden');
		jQuery("div.searchmap").removeClass('hidden');
		jQuery("input#searchtype").val('map');	
		return;	
	});	
	
	// MAP ICON
	jQuery('img#mapicon').bind('click', function(e) {
		var blogurl = jQuery("input#idx-q-BlogURL").val();
		var blogid = jQuery("input#idx-q-BlogID").val();		
		var blogtype = jQuery("input#idx-q-BlogType").val();
		var vid = jQuery.cookie("VisitorGUID");

		var mapurl = "/listings/";

		var dataString = 'stype=map&mapurl='+mapurl+'&blogurl='+blogurl+'&blogid='+blogid+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid;
		//jQuery('input#searchstring').val(dataString);			

		//jQuery.ajax({
		//	type: "POST",
		//	url: baseurl+"/wp-content/themes/rei20/functions_custom.php?action=visitorsavesearch",
   		// 	data: dataString,				
		//	success: function(data){
				//alert(data);	
		//		setTimeout(function(){
					//showSearchingDialog();					
					window.location = baseurl+'/listings/?'+dataString;
		//		}, 200);	
		//	}
		//});	
		return;		
	});	

	// MAP SELECTIONS		
	jQuery('select#mapsregion').bind('change', function(e) {									  
		var url = jQuery(this).val();
		//alert(url);
		var country = jQuery(this).find("option:selected").text();
		var cc = jQuery(this).find("option:selected").attr('title');

		if (url != '') {
			jQuery('input#searchdescription').val(country);
			jQuery('input#mapcountry').val(country);		
			jQuery('input#mapcc').val(cc);			
		} else {
			jQuery('input#searchdescription').val('World');	
			jQuery('input#mapcountry').val('');		
			jQuery('input#mapcc').val('');			
		}
	
		jQuery('input#mapurl').val(url);
		jQuery('input#mapstate').val('');
		jQuery('input#mapsc').val('');
		
		jQuery("select#mapsregion").css("color", "black").removeClass('fieldsdimmed');			
		jQuery("select#mapscountry option[value='']").attr("selected", "selected").css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#mapsstate option[value='']").attr("selected", "selected").css("color", "gray").addClass('fieldsdimmed');				
	});	


	jQuery('select#mapscountry').bind('change', function(e) {							   
		var url = jQuery(this).val();
		//alert(url);		
		var country = jQuery(this).find("option:selected").text();
		var cc = jQuery(this).find("option:selected").attr('title');
		
		if (url != '') {
			jQuery('input#searchdescription').val(country);
			jQuery('input#mapcountry').val(country);		
			jQuery('input#mapcc').val(cc);			
		} else {
			jQuery('input#searchdescription').val('World');	
			jQuery('input#mapcountry').val('');		
			jQuery('input#mapcc').val('');			
		}		
		
		jQuery('input#mapurl').val(url);
		jQuery('input#mapstate').val('');
		jQuery('input#mapsc').val('');			
		
		jQuery("select#mapsregion option[value='']").attr("selected", "selected").css("color", "gray").addClass('fieldsdimmed');			
		jQuery("select#mapscountry").css("color", "black").removeClass('fieldsdimmed');	
		jQuery("select#mapsstate option[value='']").attr("selected", "selected").css("color", "gray").addClass('fieldsdimmed');				
	});	

	jQuery('select#mapsstate').bind('change', function(e) {							 
		var url = jQuery(this).val();
		//alert(url);
		
		var cc = jQuery(this).find("option:selected").attr('title');
		if (cc == 'US') {
			var country = "United States";
		} else {
			var country = "Canada";			
		}		
		var state = jQuery(this).find("option:selected").text();
		var sc = jQuery(this).find("option:selected").attr('id');

		if (url != '') {
			jQuery('input#searchdescription').val(state+', '+cc);
			jQuery('input#mapcountry').val(country);		
			jQuery('input#mapcc').val(cc);
			jQuery('input#mapstate').val(state);
			jQuery('input#mapsc').val(sc);			
		} else {
			jQuery('input#searchdescription').val('World');			
		}
		jQuery('input#mapurl').val(url);

		jQuery("select#mapsregion option[value='']").attr("selected", "selected").css("color", "gray").addClass('fieldsdimmed');			
		jQuery("select#mapscountry option[value='']").attr("selected", "selected").css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#mapsstate").css("color", "black").removeClass('fieldsdimmed');		
	});
	
	
	jQuery('a.mapsregion').bind('click', function(e) {
		jQuery('input#searchdescription').val('');													  
		jQuery("a.mapsregion").addClass('current');
		jQuery("a.mapscountry").removeClass('current');	
		jQuery("a.mapsstate").removeClass('current');
		jQuery("select#mapsregion").show();			
		jQuery("select#mapscountry").hide();	
		jQuery("select#mapsstate").hide();			
	});

	jQuery('a.mapscountry').bind('click', function(e) {
		jQuery('input#searchdescription').val('');												   
		jQuery("a.mapsregion").removeClass('current');
		jQuery("a.mapscountry").addClass('current');	
		jQuery("a.mapsstate").removeClass('current');
		jQuery("select#mapsregion").hide();			
		jQuery("select#mapscountry").show();	
		jQuery("select#mapsstate").hide();			
	});
	
	jQuery('a.mapsstate').bind('click', function(e) {							 
		jQuery('input#searchdescription').val('');	
		jQuery("a.mapsregion").removeClass('current');
		jQuery("a.mapscountry").removeClass('current');	
		jQuery("a.mapsstate").addClass('current');
		jQuery("select#mapsregion").hide();			
		jQuery("select#mapscountry").hide();	
		jQuery("select#mapsstate").show();			
	});
	
	// MAP SEARCH BUTTON
	jQuery('div.searchmap').bind('click', function(e) {
		//alert('Map Search Button clicked');
		var mapurl = jQuery("input#mapurl").val();		
		var country = jQuery("input#mapcountry").val();
		var cc = jQuery("input#mapcc").val();		
		var state = jQuery("input#mapstate").val();
		var sc = jQuery("input#mapsc").val();
		var description = jQuery("input#searchdescription").val();		
		var blogurl = jQuery("input#idx-q-BlogURL").val();
		var blogid = jQuery("input#idx-q-BlogID").val();		
		var blogtype = jQuery("input#idx-q-BlogType").val();
		var vid = jQuery.cookie("VisitorGUID");

		var dataString = 'stype=map&mapurl='+mapurl+'&country='+country+'&cc='+cc+'&state='+state+'&sc='+sc+'&description='+description+'&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid;
		jQuery('input#searchstring').val(dataString);			
		//alert(dataString);
		
		if ( mapurl == '' ) {
			var mapurl = baseurl+'/listings?stype=map&description=World&blogurl='+blogurl+'&blogid='+blogid+'&blogtype='+blogtype+'&vid='+vid;
		}
		//alert(mapurl);
		//jQuery.ajax({
		//	type: "POST",
		//	url: ""+baseurl+"/wp-content/themes/rei20/functions_custom.php?action=visitorsavesearch",
   		// 	data: dataString,				
		//	success: function(data){
				//alert(data);	
		//		setTimeout(function(){
					jQuery("div#searching").html('SEARCHING MAPS<br /><img id="ajax-search" src="http://realtyexecutives.com/wp-content/images/ajax-search.gif" border="0"/>');				
					//showSearchingDialog();									
					window.location = mapurl;
		//		}, 200);			
		//	}
		//});	
		return;		
	});






	// MORE OPTS =============================================================================================================
	jQuery('a.moreoptshome').bind('click', function(e) {			// TESTS OK
		e.preventDefault();	
		if (jQuery("div#moreopts").is(":hidden")) {
			jQuery('div#suggest').css('height', '108');
			jQuery('div#property_search').css('height', '425');	
			jQuery("div#moreopts").show();
			jQuery("a.moreoptshome").html('<img id="arrow" src="'+baseurl+'/wp-content/themes/broker2/images/arrow_green_up.gif" border="0"/>Less Options</a>');
		} else {
			jQuery("div#moreopts").hide();
			jQuery('div#suggest').css('height', '78');
			jQuery('div#property_search').css('height', '425');					
			jQuery("a.moreoptshome").html('<img id="arrow" src="'+baseurl+'/wp-content/themes/broker2/images/arrow_green_dn.gif" border="0"/>More Options</a>');
		}			
		return;		
	});		



	function setRentalPrices(pt) {
		if (pt=="1229") {
			jQuery("select#idx-q-PriceMin").html("");
			jQuery("select#idx-q-PriceMax").html("");			
			var data = "<option value='500'>$500</option><option value='750'>$750</option><option value='1000'>$1,000</option><option value='1500'>$1,500</option><option value='2000'>$2,000</option><option value='2500'>$2,500</option><option value='3000'>$3,000</option><option value='3500'>$3,500</option><option value='4000'>$4,000</option><option value='4500'>$4,500</option><option value='5000'>$5,000</option>";
			jQuery("<option value=''>- Min Price -</option>"+data).appendTo("select#idx-q-PriceMin");
			jQuery("<option value=''>- Max Price -</option>"+data).appendTo("select#idx-q-PriceMax");				
		}		
		return;	
	}


	//PROPERTY TYPES		
	jQuery('select#idx-q-PropertyTypes').bind('change', function(e) {	   
		var pt = jQuery("select#idx-q-PropertyTypes").val();
		//alert('Property Type = '+pt);
		if (pt=="1229") {		
			setRentalPrices(pt);
		} else {
			resetPrices('location');
		}
	});	



	
	// TABS ===========================================================================	
	function resetTabs() {
		jQuery('div#suggestionsbox').hide();
		jQuery('li#moreoptshome').hide();
	
		jQuery("div#searchbutton").removeClass('location');
		
		
		jQuery("a.location").removeClass('current');
		jQuery("a.mls").removeClass('current');
		jQuery("a.maps").removeClass('current');
		jQuery("a.moreoptshome").removeClass('current');
		//jQuery("a.foreclosures").removeClass('current');
		jQuery("div#suggest").addClass('hidden');
		jQuery("div#mls").addClass('hidden');
		jQuery("div#maps").addClass('hidden');		
		jQuery("select#idx-q-PriceMin").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#idx-q-PriceMax").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#idx-q-BedsMin").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');
		jQuery("select#idx-q-BathsMin").attr("disabled", true).css("color", "gray").addClass('fieldsdimmed');			
		jQuery("input#location").val("Start typing a city or zip/postal code");	
		jQuery('input#searchstring').val("");			
		return;
	}
	
	function resetPrices(tab) {
		jQuery("select#idx-q-PriceMin").html("");
		jQuery("select#idx-q-PriceMax").html("");			
		if (tab == 'rentals') {	
			var data = "<option value='500'>$500</option><option value='750'>$750</option><option value='1000'>$1,000</option><option value='1500'>$1,500</option><option value='2000'>$2,000</option><option value='2500'>$2,500</option><option value='3000'>$3,000</option><option value='3500'>$3,500</option><option value='4000'>$4,000</option><option value='4500'>$4,500</option><option value='5000'>$5,000</option>";
		} else {
			var data = "<option value='25000'>$25,000</option><option value='50000'>$50,000</option><option value='75000'>$75,000</option><option value='100000'>$100,000</option><option value='125000'>$125,000</option><option value='150000'>$150,000</option><option value='175000'>$175,000</option><option value='200000'>$200,000</option><option value='250000'>$250,000</option><option value='300000'>$300,000</option><option value='350000'>$350,000</option><option value='400000'>$400,000</option><option value='450000'>$450,000</option><option value='500000'>$500,000</option><option value='600000'>$600,000</option><option value='700000'>$700,000</option><option value='800000'>$800,000</option><option value='900000'>$900,000</option><option value='1000000'>$1,000,000</option><option value='1250000'>$1,250,000</option><option value='1500000'>$1,500,000</option><option value='1750000'>$1,750,000</option><option value='2000000'>$2,000,000</option><option value='3000000'>$3,000,000</option><option value='4000000'>$4,000,000</option><option value='5000000'>$5,000,000</option><option value='6000000'>$6,000,000</option><option value='7000000'>$7,000,000</option><option value='8000000'>$8,000,000</option><option value='9000000'>$9,000,000</option><option value='10000000'>$10,000,000</option> ";
		}
		jQuery("<option value=''>- Min Price -</option>"+data).appendTo("select#idx-q-PriceMin");
		jQuery("<option value=''>- Max Price</option>"+data).appendTo("select#idx-q-PriceMax");
		return;
	}
	

	
	
	// OFFICES	=====================================================================================================================================
	function SetOffices() {
		var ss = jQuery("select#states :selected").val();
		if (ss == "") {
			var ss = jQuery.cookie("State");	
		}
		var state = jQuery("select#states :selected").text();				
		var city = jQuery("select#states :selected").attr('id');				
		var zoom = jQuery("select#states :selected").attr('title');	

		jQuery("div#map").html("");			
		jQuery("table#listofoffices").empty();		
		jQuery.ajax({
			type: "POST",
    		url: baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=offices&state="+ss+"",
    		success: function(data){
				jQuery(data).appendTo("table#listofoffices");				
			} 
		});

		jQuery.ajax({
			type: "POST",
    		url: baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=officemarkers&state="+ss+"",
    		success: function(markers){				
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center='+city+','+state+'&zoom='+zoom+'&size=610x350'+markers+'&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" width="610" height="350" src="http://maps.google.com/maps/api/staticmap?center='+city+','+state+'&zoom='+zoom+'&size=610x350'+markers+'&sensor=false" />').appendTo("div#map");					
			} 
		});	
		return;	
	}



	//OFFICES BY STATE	(AJAX)	
	jQuery('select#states').bind('change', function(e) {
		SetOffices();
		jQuery("div#defaults").show();			
		//return;		
	});	

	// SET DEFAULT COUNTRY	
	jQuery('#setdefaultcountry').bind('click', function(e) {
		var dc = jQuery("select#country :selected").val();
		jQuery.cookie('DefaultCountry', dc);		
		//return;
	});	

	// SET DEFAULT STATE/PROVINCE	
	jQuery('#setdefaultstate').bind('click', function(e) {
		var ds = jQuery("select#states :selected").val();
		jQuery.cookie('DefaultState', ds);
		//return;
	});	



	//SET OFFICES ON DOCUMENT READY	
	if( window.location.pathname == "/our-offices/") {
		var ds = jQuery.cookie("DefaultState");
		var st = gup('state');
		if (st != '') {
			var ds = st; 
		}		
		
		var dc = jQuery.cookie("DefaultCountry");
		var ct = gup('country');
		if (ct != '') {
			var dc = ct; 
		}
		
		if (dc != '' && ds != '') {
			//alert('Default Country = '+dc);
			jQuery("select#country option[value="+dc+"]").attr("selected", "selected");
			jQuery("table#listofoffices").empty();		
			jQuery("select#states").html("");
			jQuery("select#states").hide();		
			jQuery("div#map").html("").hide();	
			
			switch (dc) {
				case 'US':  // UNITED STATES
					jQuery("<option value=''>- Select A State -</option><option value='AK' id='Anchorage' title='5'>Alaska</option><option value='AL' id='Montgomery' title='6'>Alabama</option><option value='AZ' id='New River' title='6'>Arizona</option><option value='CA' id='Stockton' title='5'>California</option><option value='CO' id='Colorado Springs' title='6'>Colorado</option><option value='CT' id='Meridan' title='8'>Connecticut</option><option value='FL' id='Tampa' title='6'>Florida</option><option value='GA' id='Macon' title='6'>Georgia</option><option value='HI' id='Kihei' title='7'>Hawaii</option><option value='IL' id='Bloomington' title='6'>Illinois</option><option value='IN' id='Indianapolis' title='6'>Indiana</option><option value='KS' id='Salina' title='6'>Kansas</option><option value='KY' id='Lexington' title='7'>Kentucky</option><option value='LA' id='Gonzales' title='8'>Louisiana</option><option value='MA' id='Wocester' title='8'>Massachusetts</option><option value='MD' id='Sterling' title='8'>Maryland</option><option value='MI' id='Bay City' title='6'>Michigan</option><option value='MN' id='Little Falls' title='6'>Minnesota</option><option value='MO' id='Rolla' title='6'>Missouri</option><option value='MS' id='Meridan' title='6'>Mississippi</option><option value='MT' id='Hobson' title='6'>Montana</option><option value='NC' id='Raleigh' title='6'>North Carolina</option><option value='ND' id='Harvey' title='6'>North Dakota</option><option value='NJ' id='Plainfield' title='8'>New Jersey</option><option value='NV' id='Tonopah' title='6'>Nevada</option><option value='NY' id='Utica' title='6'>New York</option><option value='OH' id='Columbus' title='6'>Ohio</option><option value='OR' id='Bend' title='6'>Oregon</option><option value='PA' id='Williamsport' title='6'>Pennsylvania</option><option value='SC' id='Columbia' title='7'>South Carolina</option><option value='TN' id='Murfreesboro' title='6'>Tennessee</option><option value='TX' id='Abilene' title='5'>Texas</option><option value='UT' id='Huntington' title='6'>Utah</option><option value='VA' id='Lynchburg' title='6'>Virginia</option><option value='WA' id='Seattle' title='7'>Washington</option><option value='WI' id='Wausau' title='6'>Wisconsin</option><option value='WY' id='Casper' title='6'>Wyoming</option>").appendTo("select#states");
					//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Topeka,KS&zoom=4&size=610x350&sensor=false"></iframe>').appendTo("div#map");
					jQuery('<img id="google" width="610" height="350" src="http://maps.google.com/maps/api/staticmap?center=Topeka,KS&zoom=4&size=610x350&sensor=false" />').appendTo("div#map");					
					
					if (ds != '') {
						jQuery("select#states option[value="+ds+"]").attr("selected", "selected");						
						SetOffices();
					}
					jQuery("select#states").show();
					jQuery("div#map").show();					
					break;

				case 'CA': // CANADA
					jQuery("<option value=''>- Select A Province -</option><option value='Alberta' id='Edmonton' title='5'>Alberta</option><option value='British Columbia' id='Williams Lake' title='5'>British Columbia</option><option value='Manitoba' id='Winnipeg' title='6'>Manitoba</option><option value='New Brunswick' id='Saint John' title='7'>New Brunswick</option><option value='Newfoundland' id='Badger' title='6'>Newfoundland</option><option value='Ontario' id='Kawartha Lakes' title='6'>Ontario</option><option value='Prince Edward Island' id='North Rustico' title='8'>Prince Edward Island</option><option value='Saskatchewan' id='Saskatoon' title='6'>Saskatchewan</option>").appendTo("select#states");
					//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Manitoba,Canada&zoom=3&size=610x350&sensor=false"></iframe>').appendTo("div#map");
					jQuery('<img id="google" width="610" height="350" src="http://maps.google.com/maps/api/staticmap?center=Manitoba,Canada&zoom=3&size=610x350&sensor=false" />').appendTo("div#map");						
					
					if (ds != '') {
						jQuery("select#states option[value="+ds+"]").attr("selected", "selected");						
						SetOffices();
					}					
					jQuery("select#states").show();
					jQuery("div#map").show();					
					break;
			}			
		}
	}
	
	// CHANGE OFFICES
	jQuery('select#country').bind('change', function(e) {
		jQuery("table#listofoffices").empty();		
		jQuery("select#states").html("");
		jQuery("select#states").hide();		
		jQuery("div#map").html("").hide();	
		switch (jQuery(this).val()) {
			case '':  // NO COUNTRY
				jQuery("select#states").hide();		
				jQuery("div#map").hide();					
				break;	
			
			case 'US':  // UNITED STATES
				jQuery("<option value=''>- Select A State -</option><option value='AK' id='Anchorage' title='5'>Alaska</option><option value='AL' id='Montgomery' title='6'>Alabama</option><option value='AZ' id='New River' title='6'>Arizona</option><option value='CA' id='Stockton' title='5'>California</option><option value='CO' id='Colorado Springs' title='6'>Colorado</option><option value='CT' id='Meridan' title='8'>Connecticut</option><option value='FL' id='Tampa' title='6'>Florida</option><option value='GA' id='Macon' title='6'>Georgia</option><option value='HI' id='Kihei' title='7'>Hawaii</option><option value='IL' id='Bloomington' title='6'>Illinois</option><option value='IN' id='Indianapolis' title='6'>Indiana</option><option value='KS' id='Salina' title='6'>Kansas</option><option value='KY' id='Lexington' title='7'>Kentucky</option><option value='LA' id='Gonzales' title='8'>Louisiana</option><option value='MA' id='Wocester' title='8'>Massachusetts</option><option value='MD' id='Sterling' title='8'>Maryland</option><option value='MI' id='Bay City' title='6'>Michigan</option><option value='MN' id='Little Falls' title='6'>Minnesota</option><option value='MO' id='Rolla' title='6'>Missouri</option><option value='MS' id='Meridan' title='6'>Mississippi</option><option value='MT' id='Hobson' title='6'>Montana</option><option value='NC' id='Raleigh' title='6'>North Carolina</option><option value='ND' id='Harvey' title='6'>North Dakota</option><option value='NJ' id='Plainfield' title='8'>New Jersey</option><option value='NV' id='Tonopah' title='6'>Nevada</option><option value='NY' id='Utica' title='6'>New York</option><option value='OH' id='Columbus' title='6'>Ohio</option><option value='OR' id='Bend' title='6'>Oregon</option><option value='PA' id='Williamsport' title='6'>Pennsylvania</option><option value='SC' id='Columbia' title='7'>South Carolina</option><option value='TN' id='Murfreesboro' title='6'>Tennessee</option><option value='TX' id='Abilene' title='5'>Texas</option><option value='UT' id='Huntington' title='6'>Utah</option><option value='VA' id='Lynchburg' title='6'>Virginia</option><option value='WA' id='Seattle' title='7'>Washington</option><option value='WI' id='Wausau' title='6'>Wisconsin</option><option value='WY' id='Casper' title='6'>Wyoming</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Topeka,KS&zoom=4&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Topeka,KS&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();					
				break;


			case 'CA': // CANADA
				jQuery("<option value=''>- Select A Province -</option><option value='Alberta' id='Edmonton' title='5'>Alberta</option><option value='British Columbia' id='Williams Lake' title='5'>British Columbia</option><option value='Manitoba' id='Winnipeg' title='6'>Manitoba</option><option value='New Brunswick' id='Saint John' title='7'>New Brunswick</option><option value='Newfoundland' id='Badger' title='6'>Newfoundland</option><option value='Ontario' id='Kawartha Lakes' title='6'>Ontario</option><option value='Prince Edward Island' id='North Rustico' title='8'>Prince Edward Island</option><option value='Saskatchewan' id='Saskatoon' title='6'>Saskatchewan</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Manitoba,Canada&zoom=3&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Manitoba,Canada&amp;zoom=3&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();					
				break;
				
			case 'AU':	// AUSTRALIA
				jQuery("<option value=''>- Select A Territory -</option><option value='Western Australia' id='Little Sandy Desert' title='5'>Western Australia</option>").appendTo("select#states");	
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Australia&zoom=4&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Australia&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'BZ':	// BELIZE
				jQuery("<option value=''>- Select An Area -</option><option value='Belize' id='Belize City' title='13'>Belize City Area</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Belize City,Belize&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Belize City,Belize&amp;zoom=6&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'CR':	// COSTA RICA
				jQuery("<option value=''>- Select An Area -</option><option value='Alajuela' id='Alajuela' title='11'>Alajuela</option><option value='San Jose' id='San Jose' title='11'>San Jose</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Costa Rica&amp;zoom=6&amp;size=610x350&amp;sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Costa Rica&amp;zoom=6&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;
				
			case 'HN':	// HONDURAS
				jQuery("<option value=''>- Select An Area -</option><option value='Islas de la Bahia' id='' title='10'>Islas de la Bahia</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Tegucigalpa,Honduras&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Tegucigalpa,Honduras&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;	

			case 'IL':	// ISRAEL
				jQuery("<option value=''>- Select An Area -</option><option value='Israel' id='Jerusalem' title='7'>All Areas</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Israel&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Israel&amp;zoom=6&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'MX':	// MEXICO
				jQuery("<option value=''>- Select An Area -</option><option value='Baja California Norte' id='Mexico' title='5'>Baja California Norte</option><option value='Baja California Sur' id='Mexico' title='5'>Baja California Sur</option><option value='Colima' id='Mexico' title='7'>Colima</option><option value='Jalisco' id='Mexico' title='8'>Jalisco</option><option value='Quintana Roo' id='Mexico' title='8'>Quintana Roo</option><option value='Veracruz' id='Mexico' title='8'>Veracruz</option><option value='Sinaloa' id='Mexico' title='7'>Sinaloa</option><option value='Sonora' id='Mexico' title='6'>Sonora</option>").appendTo("select#states");	
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Fresnillo,Mexico&zoom=4&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Fresnillo,Mexico&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'NIC':	// NICARAGUA
				jQuery("<option value=''>- Select An Area -</option><option value='Nicaragua' id='Managua' title='7'>All Areas</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Nicaragua&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Nicaraqua&amp;zoom=6&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'PN':	// PANAMA
				jQuery("<option value=''>- Select An Area -</option><option value='Panama City' id='Panama' title='9'>Panama City</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Panama City,Panama&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Panama City,Panama&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'SA':	// SAUDI ARABIA
				jQuery("<option value=''>- Select An Area -</option><option value='Saudi Arabia'>Riyadh</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Riyadh,Saudi Arabia&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Riyadh,Saudi Arabia&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;

			case 'AE':	// UNITED ARAB EMIRATES
				jQuery("<option value=''>- Select An Area -</option><option value='Qatar'>Qatar</option>").appendTo("select#states");
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Abu Dhabi,United Arab Emirates&zoom=6&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Abu Dhabi,United Arab Emirates&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					
				jQuery("select#states").show();
				jQuery("div#map").show();
				jQuery("div#defaults").hide();					
				break;
		
			default:
				//jQuery('<iframe id="google" width="610" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/api/staticmap?center=Topeka,KS&zoom=4&size=610x350&sensor=false"></iframe>').appendTo("div#map");
				jQuery('<img id="google" src="http://maps.google.com/maps/api/staticmap?center=Topeka,KS&amp;zoom=4&amp;size=610x350&amp;sensor=false" />').appendTo("div#map");					

		}
			
    });	





		
		// MORE PROPERTY INFO DIALOG  12/30/2011
		jQuery('.moreinfo').bind('click', function(e) {									  
			e.preventDefault();
			
			//jQuery("a.maps").trigger("click");
			
			jQuery("input#propFirstName").removeClass('error');
			jQuery("input#propLastName").removeClass('error');						
			jQuery("input#propUserEmail").removeClass('error');	
			jQuery("input#propPhone").removeClass('error');		
			jQuery("label.required").html("* Required");					
					
			jQuery("#morepropertyinfo").dialog( "destroy" );			
			jQuery("#morepropertyinfo").dialog({
				resizable: false,
				height:400,				
				width:300,
				modal: true,
				buttons: {
					"Request Info": function() {
						var fn = jQuery("input#propFirstName").val();
						var ln = jQuery("input#propLastName").val();
						var ph = jQuery("input#propPhone").val();						
						var ue = jQuery("input#propUserEmail").val();
						var cm = jQuery("textarea#propComments").val();
						var pm = jQuery("input#propMLS").val();
						var pa = jQuery("input#propAddress").val();
						var city = jQuery("input#propCity").val();	
						var state = jQuery("input#propState").val();						
						var lc = jQuery("input#propListingCompany").val();							
						var pe = jQuery("input#propEmail").val();
						var sc = jQuery("input#propUserFolder").val();
						var idx = jQuery("input#propIDX").val();
						var vid = jQuery.cookie("VisitorGUID");

						var error = 0;

						if (fn == "") {
							jQuery("input#propFirstName").addClass('error');
							error = 1;
						}
						if (ln == "") {
							jQuery("input#propLastName").addClass('error');
							error = 1;
						}						
						if (ph == "") {
							jQuery("input#propPhone").addClass('error');
							error = 1;
						}
						if (ue == "") {
							jQuery("input#propUserEmail").addClass('error');
							error = 1;
						}
						if (error == 1) {
							//alert("Please fill out the missing information!");
							jQuery("label.required").html("<strong>Please fill out the missing information!</strong>");							
						} else {
						
							var dataString = 'fn='+fn+'&ln='+ln+'&ph='+ph+'&ue='+ue+'&cm='+cm+'&pm='+pm+'&pa='+pa+'&city='+city+'&state='+state+'&lc='+lc+'&pe='+pe+'&sc='+sc+'&idx='+idx+'&vid='+vid;
							//alert(dataString);						
							jQuery.ajax({
								type: "POST",
    							url: baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=propertyinfo",
    					   	 data: dataString,						
    							success: function(msg){
									alert(msg);	
									//if (msg == "OK") {			
									//	jQuery("div#moreinfo_msg").html("Your property information request was successfully sent!");
									//} else {
									//	jQuery("div#moreinfo_msg").html("There was a problem sending your property request.");									
									//}
								}
							});	
						
							jQuery(this).dialog("close");
						}
					},
					Cancel: function() {
						jQuery( this ).dialog( "close" );
					}
				}
			});
		});		


		// SCHEDULE SHOWING DIALOG - 12/19/2010
		jQuery('.schedule').bind('click', function(e) {									  
			e.preventDefault();	

			jQuery("input#schedFirstName").removeClass('error');
			jQuery("input#schedLastName").removeClass('error');						
			jQuery("input#schedUserEmail").removeClass('error');	
			jQuery("input#schedPhone").removeClass('error');
			jQuery("label.required").html("* Required");			

			jQuery("#scheduleshowing").dialog( "destroy" );				
			jQuery("#scheduleshowing").dialog({
				resizable: false,
				height:280,				
				width:300,
				modal: true,
				buttons: {
					"Schedule A Showing": function() {

						var fn = jQuery("input#schedFirstName").val();
						var ln = jQuery("input#schedLastName").val();
						var ph = jQuery("input#schedPhone").val();						
						var ue = jQuery("input#schedUserEmail").val();
						var sm = jQuery("select#schedMonth").val();
						var sd = jQuery("select#schedDay").val();						
						var pm = jQuery("input#schedMLS").val();
						var pa = jQuery("input#schedAddress").val();
						var lc = jQuery("input#schedListingCompany").val();							
						var pe = jQuery("input#schedEmail").val();
						var sc = jQuery("input#propUserFolder").val();					
						var idx = jQuery("input#schedIDX").val();
						var vid = jQuery.cookie("VisitorGUID");
						
						var error = 0;

						if (fn == "") {
							jQuery("input#schedFirstName").addClass('error');
							error = 1;
						}
						if (ln == "") {
							jQuery("input#schedLastName").addClass('error');
							error = 1;
						}						
						if (ph == "") {
							jQuery("input#schedPhone").addClass('error');
							error = 1;
						}
						if (ue == "") {
							jQuery("input#schedUserEmail").addClass('error');
							error = 1;
						}
						if (error == 1) {
							//alert("Please fill out the missing information!");
							jQuery("label.required").html("<strong>Please fill out the missing information!</strong>");								
						} else {
							var dataString = 'fn='+fn+'&ln='+ln+'&ph='+ph+'&ue='+ue+'&sm='+sm+'&sd='+sd+'&pm='+pm+'&pa='+pa+'&lc='+lc+'&pe='+pe+'&sc='+sc+'&idx='+idx+'&vid='+vid;
							//alert(dataString);						
							jQuery.ajax({
								type: "POST",
   		 						url: baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=scheduleshowing",
   	 						  	data: dataString,						
    							success: function(msg){
									alert(msg);								
									//if (msg == "OK") {			
									//	jQuery("div#moreinfo_msg").html("Your request to schedule a showing was successfully sent!");
									//} else {
									//	jQuery("div#moreinfo_msg").html("There was a problem sending your showing request.");									
									//}
								}
							});	
							jQuery(this).dialog("close");
						}
					},
					Cancel: function() {
						jQuery( this ).dialog( "close" );
					}
				}
			});
		});			
		
		

	


	//CHANGE US MAP SELECT STATE
	jQuery('select#select_usa_state').bind('change', function(e) {
		e.preventDefault();
		var ss = jQuery(this).val();
		if (ss != '') {
			window.location = baseurl+"/listings/us/"+ss+"/";
		}
	});		

	//CHANGE US MAP SELECT CITY
	jQuery('select#select_usa_city').bind('change', function(e) {
		e.preventDefault();	
		var url = jQuery(this).val();
			if (url != '') {
			window.location = url;
		}
	});	




	// TOGGLE EXECUTIVE ACCESS FORM
	jQuery('img#sh_execaccess2').bind('click', function(e) {
		e.preventDefault();	
		jQuery('form#executiveaccess2').slideToggle();		
	});		
	

	// SHOW LOST PASSWORD FORM
	jQuery('a#lost').bind('click', function(e) {
		e.preventDefault();
		jQuery('form#lostpassword').slideToggle();
		jQuery('a#lost').hide();
	});


	// LOST PASSWORD RETRIEVE
	jQuery('input#lostsubmit').bind('click', function(e) {					  
		e.preventDefault();	
		var email = jQuery("input#lostemail").val();
		if (email == "- Realty Executives Email Address -" || email == '' ) {
				jQuery("p#lost_msg").html('<span style="color:#CC0000;">No e-mail address was entered!</span>');				
			} else {	
				jQuery('input#lostemail').hide();
				jQuery('input#lostsubmit').hide();				
				var dataString = 'email=' + email;
				jQuery.ajax({
					type: "POST",
    				url: baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=lostpassword",
    				data: dataString,
    				success: function(msg){
					if (msg == 'OK') {
						jQuery("p#lost_msg").html('Please check your email.<br/>Your User Name/Password have been sent to the e-mail address provided.');
					} else {
						jQuery("p#lost_msg").html(msg);					
					} 		
					} 		
		   		});									
			}		
	 });		
	
	//EXECUTIVE ACCESS
	jQuery('div#exec_access').bind('click', function(e) {
		jQuery('#login').toggle();
	});	

	//EXECUTIVE ACCESS USERNAME (SET FOCUS)
	jQuery('input#username').bind('click', function(e) {
		//jQuery("a.maps").trigger("click");
	});	


	

	// ABOVE FOLD IMAGE ========================================================================================= REWORKED 7/15/2011

	//  ABOVE FOLD MLS TEXT	
	jQuery("div#abovefold #right").mouseenter(function(e){
		e.preventDefault();
		jQuery("div#abovefold #right p").fadeIn(400);
   	}).mouseleave(function(){
		jQuery("div#abovefold #right p").fadeOut(400)			
   	});




	if (idxurl == "/") {										//HOMEPAGE
		jQuery("div#maps_slider").removeClass('invisible');	
	
		var randomNum = Math.ceil(Math.random()*numphotos);									 
		jQuery("div#abovefold").addClass('AZ'+randomNum);

		jQuery(window).load(function(){	 // Home page
			var vid = jQuery.cookie("VisitorGUID");
			if (vid == '' || vid == null ) {
		
				var guid = generateGUID();
				jQuery.cookie('VisitorGUID', guid, { expires: 1825 });
				if (jQuery("div#moreopts").is(":hidden")) {
					jQuery("a.moreoptshome").trigger("click");		
				}								
				jQuery("div#abovefold").removeClass('invisible');								 
				jQuery("div#left").removeClass('invisible');
				
				return;
			} else {

				//  ABOVE THE FOLD PROPERTY			
				var imgbg = jQuery("div#abovefold").css("background-image");
				if(imgbg != '') {	
					var imgpath = imgbg.split("/");
					var imgname = imgpath[7];
					if(imgname != '') {	
						var imgmls = imgname.split("_");
						if(imgmls[2] != '') {
							jQuery.ajax({
								type: "POST",			
  		 							url: ""+baseurl+"/wp-content/themes/"+theme+"/functions_custom.php?action=homeproperty&mls="+imgmls[2]+"&state="+imgmls[1]+"",
  	 								success: function(data){
										//alert(data);
									jQuery("div#abovefold #right").html(data);
								} 
							});	
						}
					}
				}

				setTimeout(function() {
					if (jQuery("div#moreopts").is(":hidden")) {
						jQuery("a.moreoptshome").trigger("click");		
					}							
					jQuery("div#abovefold").removeClass('invisible');									
					jQuery("div#left").removeClass('invisible');
				}, 300);
				

			} //End if
		}); //End window Load
		return;	
	} //End homepage		
		

	//SIDEBAR CONTACT FORM		
	jQuery('#sb_submit').bind('click', function(e) {			
		var recipient = jQuery("input#sb_recipient").val();
		var subject = jQuery("input#sb_subject").val();			
		var sbn = jQuery("input#sb_name").val();
		var sbe = jQuery("input#sb_email").val();				
		var sbp = jQuery("input#sb_phone").val();
		var sba = jQuery("input#sb_address").val();
		var sbc = jQuery("input#sb_city").val();		
		var sbs = jQuery("input#sb_state").val();
		var sbz = jQuery("input#sb_zip").val();	
		var sbq = jQuery("textarea#sb_questions").val();			
		
		var dataString = 'recipient='+recipient+'&subject='+subject+'&sbn='+sbn+'&sbe='+sbe+'&sbp='+sbp+'&sba='+sba+'&sbc='+sbc+'&sbs='+sbs+'&sbz='+sbz+'&sbq='+sbq;
		//alert(dataString);
		jQuery.ajax({
			type: "POST",
    		url: "http://realtyexecutives.com/wp-content/themes/rei20/functions_custom.php?action=askquestion",
    		data: dataString,						
    		success: function(msg){
				if (msg == "OK") {
					//window.location.reload();
					jQuery("input#sb_name").val('- Your Name -');
					jQuery("input#sb_email").val('- Email -');				
					jQuery("input#sb_phone").val('- Phone -');				
					jQuery("input#sb_address").val('- Address -');
					jQuery("input#sb_city").val('- City -');		
					jQuery("input#sb_state").val('- State -');
					jQuery("input#sb_zip").val('- Zipcode -');	
					jQuery("textarea#sb_questions").val('- Questions or Comments -');					
					alert("Your inquiry was successfully sent!");
				} else {
					alert(msg);
				}
			}
		});			
	});	




	
	if(idxurl != "/") {	
		jQuery('h3#dsidx-contact-form-header').hide(); 	// Hide Contact Form Header
		jQuery('div.dsidx-contact-form').hide(); 		// Hide Contact Form			
		jQuery('div#dsidx-actions').hide(); 			// Hide Action Bar		
	
		jQuery(window).load(function(){	 // Not Home page
			//alert("Not Homepage");
			jQuery("div#maps_slider").removeClass('invisible');	

			var abbrev= /A[BLKSZRAEP]|BC|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[NHKR]|P[AERW]|RI|S[CKD]|T[NX]|UT|V[AIT]|W[AIVY]/i;	
			var idx = idxurl.split("/");
			//alert('0 = '+idx[0]);
			//alert('1 = '+idx[1]);	
			//alert('2 = '+idx[2]);
			//alert('3 = '+idx[3]);		

			if (idx[1] == "our-offices") {					//Our Offices
				return;	
			}
			if (idx[1] == "our-executives") {				//Our Executives
				return;	
			}		
			if (idx[1] == "sell-a-home") {					//Sell A Home
				return;	
			}	
			if (idx[1] == "listings") {						//Listings
				return;	
			}
			
			if (idx[1] == "office-details" && idx[3] != "") {				//Office Details
				jQuery("div#left.full").hide();
				//alert("Hide Office details");
				return;	
			}	



			if (abbrev.test(idx[1]) && idx[3] != "") {
				//getLastSearch();
				//alert('Property Details');
				
				jQuery('h3#dsidx-contact-form-header').hide(); 	// Hide Contact Form Header
				jQuery('div.dsidx-contact-form').hide(); 		// Hide Contact Form			
				jQuery('div#dsidx-actions').hide(); 			// Hide Action Bar				
	
				var proppath = idx[3].split("-");
				//alert('Property Path 1 - '+proppath[1]);
			
				if (proppath[1] == "mls") {
					//alert(proppath[2]);   // 1-mls, 2-MLS#
					//alert(proppath[3]);   // 1-mls, 2-MLS#, 3-MLS#
					var mls = proppath[2];
					//alert('MLS: '+mls);					
					jQuery("input#propMLS").val(mls);
					jQuery("input#schedMLS").val(mls);

					var state = idx[1].toUpperCase();
					//alert('State: '+state);				
					jQuery("input#propState").val(state);
					jQuery("input#schedState").val(state);					

					var city = idx[2];
					//alert('City: '+city);
					jQuery("input#propCity").val(city);
					jQuery("input#schedCity").val(city);					
			
					var address = jQuery("h1.entry-title").text();	
					//alert('Address: '+address);				
					jQuery("input#propAddress").val(address);
					jQuery("input#schedAddress").val(address);

					var email = jQuery("div#photoname a").text();	
					if (email !='') {
						//alert('Email: '+email);			
						jQuery("input#propEmail").val(email);
						jQuery("input#schedEmail").val(email);				
					} else {
						jQuery("input#propEmail").val('moreinfo.reconnect@gmail.com');
						jQuery("input#schedEmail").val('moreinfo.reconnect@gmail.com');					
					}
			
					var lc = jQuery("p#dsidx-listing-source").text();
					jQuery("input#propListingCompany").val(lc);
					jQuery("input#schedListingCompany").val(lc);			
			
					//alert ('IDX: '+idxurl);
					jQuery("input#propIDX").val(idxurl);
					jQuery("input#schedIDX").val(idxurl);					
					
					var uf = jQuery("div#userfolder").text();	
					jQuery("input#propUserFolder").val(uf);
					jQuery("input#schedUserFolder").val(uf);					
					//alert ('Blog: '+uf);


			
				} //End MLS check

				
			} //End idx3

		}); //End window Load				
	}

}); // end Document Ready





jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


