// JavaScript Document

// SITEMAP TOGGLE
$(document).ready(function() {
  $('#sitemapcontainer').hide();
  
  $('#sitemap').click(function() {
    $('#sitemapcontainer').slideToggle(400);
    return false;
  });
});


<!-- GOOGLE MAP -->
function ShowMap() {
	//alert('Show Map');
	$('#map_canvas').slideDown(400);
	$('#hidemap').show();	
	$('#showmap').hide();	
}

function HideMap() {
	//alert('Hide Map');
	$('#map_canvas').slideUp(400);
	$('#hidemap').hide();	
	$('#showmap').show();	
}


function ShowOfficesSelect() {
	//alert('Show Offices');
	$('.showofficesselect').hide();	
	$('.hideofficesselect').show();
	$('#officeselect').show();		
}

function HideOfficesSelect() {
	//alert('Hide Offices');
	$('.showofficesselect').show();	
	$('.hideofficesselect').hide();
	$('#officeselect').hide();	
}

<!-- CONTACT FORMS -->
function isValidPhoneNumber(phone) {
	var stripped = phone.replace(/[\s()+-]|ext\.?/gi, "");
	return ((/\d{10,}/i).test(stripped));
}

$(document).ready(function(){
	$(".formsubmit").click(function(){
		//alert('Form Submit')
		var formname = $("#formname").val();		
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		var phone = $("#phone").val()		
		var cellphone = $("#cellphone").val()
		var fax = $("#fax").val()
		var email = $("#email").val()
		var address1 = $("#address1").val()
		var address2 = $("#address2").val()
		var city = $("#city").val()		
		var state = $("#state").val()
		var zipcode = $("#zipcode").val()
		
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

	    var dataString = 'firstname='+ firstname + '&lastname='+ lastname + '&phone='+ phone + '&cellphone='+ cellphone + '&fax='+ fax + '&email='+ email + '&address1='+ address1 + '&address2='+ address2 + '&city='+ city + '&state='+ state + '&zipcode='+ zipcode + '&formname='+ formname;

		if(firstname == '') {
			$("#firstname").after('<div class="error">Enter your first name.</div>');
			hasError = true;
		}	
		if(lastname == '') {
			$("#lastname").after('<div class="error">Enter your last name.</div>');
			hasError = true;
		}				

		if(phone == '999-999-9999') {			
			$("#phone").after('<div class="error">Enter your phone number.</div>');			
			hasError = true;
		} else if(!isValidPhoneNumber(phone)) {
			$("#phone").after('<div class="error">Enter a valid phone number.</div>');
			hasError = true;
		}

		if(email == '') {			
			$("#email").after('<div class="error">Enter your email address.</div>');				
			hasError = true;
		} else if(!emailReg.test(email)) {
			hasError = true;
			$("#email").after('<div class="error">Enter a valid email address.</div>');
		}				
		if(address1 == '') {			
			$("#address1").after('<div class="error">Enter your primary address.</div>');				
			hasError = true;
		}				
		if(city == '') {			
			$("#city").after('<div class="error">Enter your city.</div>');	
			hasError = true;
		}				
		if(state == '') {
			$("#state").after('<div class="error" style="width:96px; float:right;">Select your state.</div>');	
			hasError = true;
		}				
		if(zipcode == '99999-9999') {			
			$("#zipcode").after('<div class="error" style="width:70px;">Enter zip code.</div>');	
			hasError = true;
		}	

		if(hasError == false) {
			$(this).hide();
			$("#contactbutton").append('<span class="error">SENDING...</span>');
				//alert(dataString)
				$.ajax({ type: "POST",
    			url: "contactform.php",
    			data: dataString,
    			success: function(msg){
				//alert(msg);
    			$('#contact').slideUp();
    			//$('#contact').hide();									
				$('#success').fadeIn(200).show();

   				}
			});
		}
	
		return false;
	});
});


<!-- LIST PROPERTIES -->
$(document).ready(function(){
	$(".propertysubmit").click(function(){
		//alert('Property Submit')
		var formname = $("#formname").val();		
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val()	
		var phone = $("#phone").val()		
		var cellphone = $("#cellphone").val()
		var fax = $("#fax").val()
		var email = $("#email").val()
		var address1 = $("#address1").val()
		var address2 = $("#address2").val()
		var city = $("#city").val()		
		var state = $("#state").val()
		var zipcode = $("#zipcode").val()
		
		var paddress1 = $("#property_address1").val()
		var paddress2 = $("#property_address2").val()
		var pcity = $("#property_city").val()		
		var pstate = $("#property_state").val()
		var pzipcode = $("#property_zipcode").val()		
		var pmonth = $("#property_month").val()
		var pday = $("#property_day").val()		
		var pyear = $("#property_year").val()	
		var phigh = $("#property_pricehigh").val()	
		var plow = $("#property_pricelow").val()				
		var ptype = $("#property_type").val()	
		var pbeds = $("#property_bedrooms").val()	
		var pbaths = $("#property_bathrooms").val()			
		var pfeatures = $("#property_features").val()	
		
		var pbefore = $('input[name=before]:checked').val() 
		var plisted = $('input[name=listed]:checked').val() 
		//alert(listed);
		
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

	    var dataString = 'firstname=' + firstname + '&lastname=' + lastname + '&phone=' + phone + '&cellphone=' + cellphone + '&fax=' + fax + '&email=' + email + '&address1=' + address1 + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&zipcode=' + zipcode + '&formname=' + formname + '&paddress1=' + paddress1 + '&paddress2=' + paddress2 + '&pcity=' + pcity + '&pstate=' + pstate + '&pzipcode=' + pzipcode + '&pbefore=' + pbefore + '&plisted=' + plisted + '&pmonth=' + pmonth + '&pday=' + pday + '&pyear=' + pyear + '&phigh=' + phigh + '&plow=' + plow + '&ptype=' + ptype + '&pbeds=' + pbeds + '&pbaths=' + pbaths + '&pfeatures=' + pfeatures;

		if(firstname == '') {
			$("#firstname").after('<div class="error">Enter your first name.</div>');
			hasError = true;
		}	
		if(lastname == '') {
			$("#lastname").after('<div class="error">Enter your last name.</div>');
			hasError = true;
		}
						
		if(phone == '999-999-9999') {			
			$("#phone").after('<div class="error">Enter your phone number.</div>');			
			hasError = true;
		} else if(!isValidPhoneNumber(phone)) {
			$("#phone").after('<div class="error">Enter a valid phone number.</div>');
			hasError = true;
		}

		if(email == '') {			
			$("#email").after('<div class="error">Enter your email address.</div>');				
			hasError = true;
		} else if(!emailReg.test(email)) {
			hasError = true;
			$("#email").after('<div class="error">Enter a valid email address.</div>');
		}				
		if(address1 == '') {			
			$("#address1").after('<div class="error">Enter your primary address.</div>');				
			hasError = true;
		}				
		if(city == '') {			
			$("#city").after('<div class="error">Enter your city.</div>');	
			hasError = true;
		}				
		if(state == '') {
			$("#state").after('<div class="error" style="width:110px;">Select your state.</div>');	
			hasError = true;
		}				
		if(zipcode == '') {			
			$("#zipcode").after('<div class="error" style="width:75px;">Enter zip code.</div>');	
			hasError = true;
		}
		
		if(paddress1 == '') {			
			$("#property_address1").after('<div class="error">Enter the property address.</div>');	
			hasError = true;
		}	
		if(pcity == '') {			
			$("#property_city").after('<div class="error">Enter the property city.</div>');	
			hasError = true;
		}		
		if(pstate == '') {			
			$("#property_state").after('<div class="error">Select the property state.</div>');	
			hasError = true;
		}
		if(pzipcode== '') {			
			$("#property_zipcode").after('<div class="error">Select the property zipcode.</div>');	
			hasError = true;
		}
		
		if(ptype== '') {			
			$("#property_type").after('<div class="error">Select the type of property.</div>');	
			hasError = true;
		}					
		if(pbeds== '') {			
			$("#property_bedrooms").after('<div class="error">Select the # of berooms.</div>');	
			hasError = true;
		}
		if(pbaths== '') {			
			$("#property_bathrooms").after('<div class="error">Select the # of bathrooms.</div>');	
			hasError = true;
		}


		if(hasError == false) {
			$(this).hide();
			$("#contactbutton").append('<span class="error">SENDING...</span>');
				//alert(dataString)
				$.ajax({ type: "POST",
    			url: "propertyform.php",
    			data: dataString,
    			success: function(msg){
				//alert(msg);
    			$('#personalinfo').hide();				
    			$('#property').slideUp();					
				$('#success').fadeIn(200).show();
   				}
			});
		}
	
		return false;
	});
});


$(function() { 
    $("button[rel]").overlay(); 
});

$(function() { 
    $("a[rel]").overlay(); 
});



<!-- CITY AUTO_SUGGEST -->
var citiesListTotal   =  5;
var citiesListCurrent = 0;

$(document).ready(function() {
	$('#cities').click(function(){ setTimeout("$('#cities').val('');officesboxhide();", 50) });
	$('#cities').blur(function(){ setTimeout("citiesboxhide()", 200) });						   

	$('#cities').keyup(function(e){
		var citykeyCode = e.keyCode || window.event.keyCode;
		//alert (keyCode);
		
		if(citiesArrows(citykeyCode)){
			//alert(citiesListCurrent);
			return;
		}

		if(citykeyCode == 13) {
			//alert('Enter key Pressed');
			var cityid = $("#suggestionslist li.selected").attr('id');
			//alert('City ID '+cityid);
			if (cityid != '') {
				citynavigate(cityid);
			}
			return;
		}
		
		if(citykeyCode == 27) {
			//alert('Escape key Pressed');
			$('#cities').val('');
			$('#suggestionsbox').fadeOut();
			return;
		}		
		

		var inputString = $('#cities').val();			
		if(inputString.length == 0) {
			//alert('No Cities Input');
			$('#suggestionsbox').fadeOut();
		} else {
			//alert(inputString);
			$('#cities').addClass('load');			
			setTimeout(function () {suggestCities(inputString)}, 500);			
		};
	 });
})


function suggestCities(inputString){
	//alert(inputString);
	$.post("cityselect.php", {queryString: ""+inputString+""}, function(data){
		$('#suggestionsbox').fadeIn();
		$('#cities').removeClass('load');				
		if(data.length >11) {
			$('#suggestionslist').html(data);
			//setTimeout("$('#suggestionsbox').fadeOut();", 5000);
		} else {
			$('#suggestionslist').html('<ul><li>No matching cities found.</li></ul>');
			//setTimeout("$('#suggestionsbox').fadeOut();", 1000);					
		}
	});
}


function citiesArrows(citykeyCode) {
	if(citykeyCode == 40 || citykeyCode == 38){

		if(citykeyCode == 38){ // keyUp
			//alert ('Cities Up Arrow was pressed');
			citiesListCurrent--;
		} else { // keyDown
			//alert ('Cities Down Arrow was pressed');		
			citiesListCurrent++;
		}

		var totalcities = $("#suggestionslist li").size();
		//alert (total);
		
		if( citiesListCurrent <= totalcities){
			var i=0;
			for (i=0;i<=totalcities;i++) {
				if(citiesListCurrent == i){
					$("#suggestionslist ul li:nth-child("+i+")").addClass("selected");
				} else {
					$("#suggestionslist ul li:nth-child("+i+")").removeClass("selected");				
				}
			}
		}
		
		//NEW
		var cityname = $("#suggestionslist li.selected").text();
		$('#cities').val(cityname);
		
		return true;

	} else {
		// reset
		citiesListCurrent = 0;
		return false;
	}
}

function citynavigate(cityid) {
	//alert(cityid);
	if (cityid != '') {
		$.post("cityrotate.php", {queryString: ""+cityid+""}, function(data){
			if(data.length > 20) {
				//$('#cities').val('home listings by city');
				//alert(data);
				top.location = data;
			} else {
				alert('No links found for this city!');	
			}
		});
	}
}

function citiesboxhide() {
	$('#suggestionsbox').hide();
	$('#cities').val('enter city to search');		
}



<!-- OFFICES AUTO_SUGGEST -->
var officesListTotal   =  5;
var officesListCurrent = 0;

$(document).ready(function() {
	$('#offices').click(function(){ setTimeout("$('#offices').val('');citiesboxhide();", 50) });
	$('#offices').blur(function(){ setTimeout("officesboxhide()", 200) });						   


	$('#offices').keyup(function(e){
		var keyCode = e.keyCode || window.event.keyCode;
		//alert (keyCode);
		
		if(officesArrows(keyCode)){
			//alert(officesListCurrent);
			return;
		}
		
		if(keyCode == 13) {
			//alert('Enter key Pressed');
			var id = $("#officeslist li.selected").attr('id');
			//alert (id);
			officenavigate(id);
			return;
		}
		
		if(keyCode == 27) {
			//alert('Escape key Pressed');
			$('#offices').val('');
			$('#officesbox').fadeOut();
			return;
		}
		
		var inputString = $('#offices').val();			
		if(inputString.length == 0) {
			//alert('No Input');
			$('#officesbox').fadeOut();
		} else {
			//alert(inputString);
			$('#offices').addClass('load');			
			setTimeout(function () {suggestOffice(inputString)}, 500);			
		};
	 });
});


function suggestOffice(inputString){
	//alert(inputString);
	$.post("officeselect.php", {queryString: ""+inputString+""}, function(data){
		$('#officesbox').fadeIn();																			  
		$('#offices').removeClass('load');				
			if(data.length >10) {
				$('#officeslist').html(data);
			} else {
				$('#officeslist').html('<ul><li>No matching offices found.</li></ul>');
			}
	});
}

function officesArrows(keyCode) {
	if(keyCode == 40 || keyCode == 38){

		if(keyCode == 38){ // keyUp
			//alert ('Up Arrow was pressed');
			officesListCurrent--;
		} else { // keyDown
			//alert ('Down Arrow was pressed');		
			officesListCurrent++;
		}

		var offtotal = $("#officeslist li").size();
		//alert (totalli);
		
		if( officesListCurrent <= offtotal){
			var i=0;
			for (i=0;i<=offtotal;i++) {
				if(officesListCurrent == i){
					$("#officeslist ul li:nth-child("+i+")").addClass("selected");
				} else {
					$("#officeslist ul li:nth-child("+i+")").removeClass("selected");				
				}
			}
		}
		return true;

	} else {
		// reset
		officesListCurrent = 0;
		return false;
	}
}
	 
function officenavigate(id) {	
	$('#offices').val(id);
	$('#offices').val('enter zipcode or city');
	if(id != ''){
		top.location = "officedetails.php?fullid="+id;
	}
}

function officesboxhide() {
	$('#officesbox').hide();
	$('#offices').val('enter zipcode or city');		
}
