function formAction(href){
	$('form#form').attr({ 
		action: href
	});
        
        $('form#form').submit();
};
  
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* Make sure the required contact fields have something in them */
function checkForm(){
	var errorArray = new Array();
	var emailFilter  = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
	var errorMsg = 'The following highligthed fields have errors:\n\n\n';
	var e = 0;
	focusPoint = '';
	if (jQuery.trim($('#fName').val()) == '' || 
		jQuery.trim($('#fName').val()).length < 2){
		errorArray[e] = ' First Name is either missing or too short';
		errorMsg += ' First Name is either missing or too short\n\n';
		$('#fName').css({background: '#ffdead'});
		if(!focusPoint){
			focusPoint = 'fName';
		}
		e++;
	}
	
	if (jQuery.trim($('#lName').val()) == '' || 
		jQuery.trim($('#lName').val()).length < 2){
		errorArray[e] = ' Last Name is either missing or too short';
		errorMsg += ' Last Name is either missing or too short\n\n';
		$('#lName').css({background: '#ffdead'});
		if(!focusPoint){
			focusPoint = 'lName';
		}
		e++;
	}
	
	if(jQuery.trim($('#email').val()) == ''){
		if(!emailFilter.test($('#email').val())){
			errorMsg += 'Email address is invalid\n\n';
		}
		errorArray[e] = 'Email address is required';		
		$('#email').css({background: '#ffdead'});
		$("#validEmail").css({ "background-image": "url('images/validNo.png')" });
		if(!focusPoint){
			focusPoint = 'email';
		}
		e++;
	}
	
	if (jQuery.trim($('#phone').val()) == '' || 
		jQuery.trim($('#phone').val()).length < 10){
		errorArray[e] = ' Invalid phone number. Enter Area Code then number (ie. 7571234567)';
		errorMsg += ' Invalid phone number. Enter Area Code then number (ie. 7571234567)\n\n';
		$('#phone').css({background: '#ffdead'});
		if(!focusPoint){
			focusPoint = 'phone';
		}
		e++;
	}
	         
	if ($('select#selectHearAboutUs :selected').val() == 'none'){
		errorArray[e] = ' Please enter how you heard about us.';
		errorMsg += ' Please enter how you heard about us\n\n';
		$('select#selectHearAboutUs').css({background: '#ffdead'});
		if(!focusPoint){
			focusPoint = 'selectHearAboutUs';
		}
		e++;
	}
	
	if(e > 0){ $('#'+focusPoint).focus(); alert(errorMsg);  return false; } else { sendMail();  }
};
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* If the all the required contact fields are filled then send the email */
function sendMail() {	
	$.getJSON("emailRequest.php",{
		mailTo: $('select#selectProperty :selected').val(),
		community: $('select#selectProperty :selected').text(),
		name: $('#fName').val()+'  '+$('#lName').val(),
		address: $('#addrs').val(),
		city: $('#city').val() + ', '+$('select#selectState :selected').val()+' '+$('#zip').val(),
		email: $('#email').val(),
		phone: '( '+$('#phone').val().substr(0,3)+' )'+$('#phone').val().substr(3,3)+'-'+$('#phone').val().substr(6,4),
		fax: '( '+$('#fax').val().substr(0,3)+' )'+$('#fax').val().substr(3,3)+'-'+$('#fax').val().substr(6,4),
		howfound: $('select#selectHearAboutUs :selected').val(),
		otherReferral: $('#otherChoice').val(),
		yrInSchool: $('select#selectYrInSchool :selected').text(),
		nmbrBeds: $('select#selectNmbrBedroom :selected').text(),
		contactMethod: $('select#selectContactMethod :selected').text(),
		comments: $('#comments').val()
	}, function(data){
		alert(data);
	});
	
};

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

$(document).ready(function(){
/*=============================================================*/
/* Top Navigation */
$('.topNav').hover(function(){
	$('#'+this.id).css('border-bottom','1px solid #000000');
}, function() {
	$('#'+this.id).css('border-bottom','none');
	$('#current').css('border-bottom','1px solid #000000');
});

/*=============================================================*/
/* Interior Text/Map to Phone */
$('.topContent').css({'background': 'url(images/texting_buttons/content-top-bg.png) no-repeat 0px 0px'}).append('<div id="interiorTxtToPhone" class="txtToPhone"></div>');
$('.noTexting').css({'background': 'url(images/content-top-bg.png) no-repeat 0px 0px'});
$('#interiorTxtToPhone').hover(function(){
		$('.topContent').css({'background': 'url(images/texting_buttons//content-top-bg.png) no-repeat 0px -157px'});
}, function(){	
		$('.topContent').css({'background': 'url(images/texting_buttons//content-top-bg.png) no-repeat 0px 0px'});	
});
$('#interiorMapToPhone').css({'background': 'url(images/texting_buttons/mapToPhone.png) no-repeat 0px 0px'})
$('#interiorMapToPhone').hover(function(){
		$('#interiorMapToPhone').css({'background': 'url(images/texting_buttons//mapToPhone.png) no-repeat 0px -75px'});
}, function(){	
		$('#interiorMapToPhone').css({'background': 'url(images/texting_buttons//mapToPhone.png) no-repeat 0px 0px'});	
});

/*=============================================================*/
/* Small Side Navigation */	
$('.sideNav img').hover(function(){
	var thisId = $(this).parent('li').attr('id');
	switch (thisId){
		case 'aptSearch':
			var src = ($('#'+thisId+' img').attr('src') === 'images/apartment-search-btn1.png')
			? 'images/apartment-search-btn11.png'
			: 'images/apartment-search-btn1.png';
		break;
		case 'contact':
			var src = ($('#'+thisId+' img').attr('src') === 'images/contact-us-btn1.png')
			? 'images/contact-us-btn11.png'
			: 'images/contact-us-btn1.png';
		break;
		case 'employment':
			var src = ($('#'+thisId+' img').attr('src') === 'images/employment-opp-btn1.png')
			? 'images/employment-opp-btn11.png'
			: 'images/employment-opp-btn1.png';
		break;
	};
	
	$('#'+thisId+' img').attr('src',src);		
});

$('.aptSearch, .noWebPage').click(function(){
		var aptArray = $(this).attr('class').split(' ');
		/*if(aptArray[1] == 'noWebPage'){*/
		if($(this).hasClass('noWebPage')){
			formAction('overview.php?cid='+this.id);
		}else{
			formAction(this.id);
		}

		

});

$('ul.sideList li').hover(function(){
		$(this).css('color','#ffff00');
}, function(){
		$(this).css('color','#ffffff');
});

$('.nav').click(function(){
	switch (this.id){
		case 'home':
			var href = 'index.php';
			break;
		case 'aptSearch':
			var href = 'apartmentSearch.php';
			break;			
		case 'contact':
		case 'contactUs':
			var href = 'contactUs.php';
			break;
		case 'employment':
			var href = 'employment.php';
			break;
		case 'aboutUs':
			var href = 'aboutUs.php';
			break;
	};
	
	formAction(href);
});


/*=============================================================*/
/* Polaroid Navigation */

$('.bottomNav li img').hover(function(){
		var src = '';
	switch ($(this).parent().attr('id')){
		case 'overview':
			var src = ($(this).attr('src') === 'images/overview-btn1.jpg')
			? 'images/overview-btn11.jpg'
			: 'images/overview-btn1.jpg';
		break;
		case 'features':
			var src = ($(this).attr('src') === 'images/feature-amenities-btn1.jpg')
			? 'images/feature-amenities-btn11.jpg'
			: 'images/feature-amenities-btn1.jpg';
		break;
		case 'floorPlan':
			var src = ($(this).attr('src') === 'images/floor-plan-btn1.jpg')
			? 'images/floor-plan-btn11.jpg'
			: 'images/floor-plan-btn1.jpg';
		break;
		case 'tour':
			var src = ($(this).attr('src') === 'images/virtual-tour-btn1.jpg')
			? 'images/virtual-tour-btn11.jpg'
			: 'images/virtual-tour-btn1.jpg';
		break;
		case 'mapsDirections':
			var src = ($(this).attr('src') === 'images/map-directions-btn1.jpg')
			? 'images/map-directions-btn11.jpg'
			: 'images/map-directions-btn1.jpg';
		break;
		case 'events':
			var src = ($(this).attr('src') === 'images/events-btn1.jpg')
			? 'images/events-btn11.jpg'
			: 'images/events-btn1.jpg';
		break;
		case 'request':
			var src = ($(this).attr('src') === 'images/request-more-info-btn1.jpg')
			? 'images/request-more-info-btn11.jpg'
			: 'images/request-more-info-btn1.jpg';
		break;
		case 'apply':
			var src = ($(this).attr('src') === 'images/apply-now-btn1.jpg')
			? 'images/apply-now-btn11.jpg'
			: 'images/apply-now-btn1.jpg';
		break;
		case 'resources':
			var src = ($(this).attr('src') === 'images/resident-resources-btn1.jpg')
			? 'images/resident-resources-btn11.jpg'
			: 'images/resident-resources-btn1.jpg';
		break;
	};
	$(this).attr('src',src);
});


$('.bottomNav li img, .faq, .payRent').click(function(){	
	formAction(this.id);	
});

/*=============================================================*/
/* Facebook, Twitter and Blog Navigation */
$('#blogs ol li img').hover(function(){
		
	switch ($(this).parent().attr('id')){
		case 'faceBook':
			var src = ($(this).attr('src') === 'images/facebook-icon1.png')
			? 'images/facebook-icon11.png'
			: 'images/facebook-icon1.png';
		break;
		case 'twitter':
			var src = ($(this).attr('src') === 'images/twitter-icon1.png')
			? 'images/twitter-icon11.png'
			: 'images/twitter-icon1.png';
		break;
		case 'youTube':
			var src = ($(this).attr('src') === 'images/youtube-icon1.png')
			? 'images/youtube-icon11.png'
			: 'images/youtube-icon1.png';
		break;
	};
	$(this).attr('src',src);
});

$('#blogs ol li img').click(function(){
		formAction(this.id);
});

/*=============================================================*/
/* Facebook, Twitter and Blog Navigation */
$('.payRent').hover(function(){
	$('.payRent img').attr('src','images/pay-rent-online-rollover.png');
}, function() {
	$('.payRent img').attr('src','images/pay-rent-online.png');
});
/*=============================================================*/
/* Virtual Tour See virtualTour.php for more js */

$('.virtualTourBtn').hover(function(){
	
	switch ($(this).attr('id')){
	case 'virtualTour':
		var src = ($(this).children().attr('src') === 'images/virtual-tour-btn.png')
			? 'images/virtual-tour-btn11.png'
			: 'images/virtual-tour-btn.png';
		break;
	case 'amenitiesTour':
		var src = ($(this).children().attr('src') === 'images/tour-our-amenities-btn.png')
			? 'images/tour-our-amenities-btn11.png'
			: 'images/tour-our-amenities-btn.png';
		break;
	}
	$(this).children().attr('src',src);
	
});


$('img.tourBtn').click(function(){
	formAction(this.id);		
});

/*=============================================================*/
/* Apartment Search */
	
$('.smMap img').hover(function(){
	var src = ($(this).attr('src') === 'images/map-icon1.png')
			? 'images/map-icon11.png'
			: 'images/map-icon1.png';
			
			$(this).attr('src',src);	
});

$('.firstContentArea, .newContentArea, .contentArea').hover(function(){
	var thisClass = $(this).attr('className');
	switch (thisClass){
		case 'firstContentArea':
			var src = ($(this).attr('src') === 'images/search-top-content-bg1.png')
			? 'images/btm-nav-bg.png'
			: 'images/search-top-content-bg1.png';
		break;
		case 'newContentArea':
			var src = ($(this).attr('src') === 'images/search-mid-content-bg2.png')
			? 'images/search-mid-content-bg22.png'
			: 'images/search-mid-content-bg2.png';
		break;
		case 'contentArea':
			var src = ($(this).attr('src') === 'images/search-mid-content-bg3.png')
			? 'images/search-mid-content-bg33.png'
			: 'images/search-mid-content-bg3.png';
		break;
	};
	
	$(this).css('backgroung-image',src);
});

/*=============================================================*/
/* Floorplan */	
$('.printFloorPlanBtn').hover(function(){
	$('.printFloorPlanBtn').css('backgroundImage','url(images/print-btn11.jpg)');
},function(){
	$('.printFloorPlanBtn').css('backgroundImage','url(images/print-btn1.jpg)');
});

$('#prntBtn').hover(function(){
	$('#prntBtn').css('backgroundImage','url(images/print-btn11.png)');
},function(){
	$('#prntBtn').css('backgroundImage','url(images/print-btn1.png)');
});

$('.printFloorPlanBtn').click(function(){
	formAction('floorplandetails.php?UTypeID='+this.id);
		
});

$('.planName').click(function() {
	
	if($('#'+this.id).children('.firstFloorPlan').val() != 'ID=0'){
		$("#fpImage").empty().append("<img src='"+imagePath+$('#'+this.id).children('.firstFloorPlan').val()+"' alt='"+$(".floorPlanName").val()+"' />")
	}else{
		$("#fpImage").empty().append("<img src='images/noFloorPlan.jpg' />");
	}
		
	//$('div.pointer img').attr('src','');
	$('div.pointer').empty();
	var id = $('#'+this.id).children('div.pointer').attr('id');
	
	$('#'+id).addClass('firstPlan');
	$('#'+id).append('<img src="images/floorplan-arrw-icon.jpg" />');
	
	
	$('.printFloorPlanBtn').attr('id',this.id+'&cid='+$('#fpCID').val());
	
	$('label.textFloorPlan').empty();
	$("label#fpName").append($('#'+this.id).children('.floorPlanName').val());
	$("label#fpBedBath").append($('#'+this.id).children('.floorPlanLayOut').val());
	$("label#fpSqFt").append($('#'+this.id).children('.floorPlanSqFt').val());
	$("label#fpRent").append($('#'+this.id).children('.floorPlanPrice').val());
	$("label#fpDetail").append($('#'+this.id).children('.floorPlanDescription').val());
	
})

/*=============================================================*/
/* Contact Us */
$('.requiredBox').blur(function(){
	$('#'+this.id).css({background: '#ffff63'});
});
	
$('select#selectHearAboutUs').change(function(){
	if($('select#selectHearAboutUs').val() == 'Other'){
		$('#other').slideDown('slow');
	}else{
		$('#otherReferral').val('');
		$('#other').slideUp('slow');
	}
});

$('#submitForm').click(function(){
		checkForm();
});

//Check to make sure only numbers are entered for phone and the string length is less or equal to 10 char.
$('.numeric').keyup( function() {
	var justInCase = $(this).val();
	
	if($(this).attr('id') == 'zip'){
		$(this).css({background: '#ffffff'});
		var strLength = 5;
	}else{
		if($(this).is('.requiredBox')){
			$(this).css({background: '#ffff63'});
		}else{
			$(this).css({background: '#ffffff'});
		}
		var strLength = 10;
	}
	var strLen = this.value.length;
	var key = this.value.substr(strLen-1,1);
	if ( isNaN(key) || key == ' ' || strLen > strLength)
	{
		str = this.value.substr(0, strLen-1);
		this.value = str;
		return false;
	}
});

$("#email").keyup(function(){
	var email = $("#email").val();		
	if(email != 0)
	{
		if(isValidEmailAddress(email))
		{		
			$("#validEmail").css({ "background-image": "url('images/validYes.png')" });		
		} else {		
			$("#validEmail").css({ "background-image": "url('images/validNo.png')" });		
		}	
	} else {	
		$("#validEmail").css({ "background-image": "none" });	
	}
});
/*=============================================================*/
/* Map & Directions */

$('#googleMapBtn').click(function(){
	$('#getDirection').slideDown('slow');
});

$('img#walkIcon').click(function(){
	$('form#getDirection').attr({ 
		action: 'http://maps.google.com/maps'
	});
        
        $('form#getDirection').submit();
		
	
});

/*=============================================================*/
/*  */
// initialize scrollable 
$("div.scrollable").scrollable({
	vertical:true, 
	size: 3
	
// use mousewheel plugin
}).mousewheel();	
	

});

