
var vsm_player_moved=false;var contact_dialog=null;var current_listing_id=null;var f_left=0
var contact_dialog_height=375;var contact_dialog_width=465;var lead_popup='.lead_partial';$(document).ready(function(){$(".lead_phone").keypress(isNumberKey);$("#mobileNumber").keypress(isNumberKeyNoFormat);$('#lead_partial').submit(submit_lead_via_ajax);$('#lead_partial_coupon').submit(submit_lead_via_ajax);$().mousemove(function(e){f_left=e.pageX;});$("#lead_lightbox").click(function(){$("#lead_lightbox").hide();contact_dialog.dialog("close");});});function submit_lead_via_ajax(){var form_name=$(this).attr("id");if(form_name=="lead_partial_coupon"){$(this).append('<input id="leadtype" type="hidden" value="coupon" name="leadtype" />');}
$.ajax({url:'/leads.js',type:'POST',data:$(this).serialize(),success:function(response){$(lead_popup+" .flash_notice").html(response);$(lead_popup).addClass("thank_you");$(lead_popup+" .lead_form").hide();remove_err();if(form_name=="lead_inline"){window.location.href="http://"+window.location.host+window.location.pathname+"ThankYou/";};return false;},error:function(req,status,err){var errors=eval(req.responseText);var element_name;$("#lead_partial label").each(function(){this.className=""})
$.each(errors,function(){element_selector="#lead_"+this[0]+"_"+form_name;$(element_selector).siblings("label").addClass("error");$(element_selector).siblings("label").attr("title",this[1]);});}});return false;}
function remove_err(){$(".error").removeClass("error");}
function set_lead_popup(lead_type){if(lead_type!='coupon'||lead_type=='undefined'){set_popup_dimensions(false);if(lead_popup==".lead_partial_coupon"){reset_lead_form();lead_popup=".lead_partial";}
showOverlay();}
else{set_popup_dimensions(true);if(lead_popup==".lead_partial"){reset_lead_form();lead_popup=".lead_partial_coupon";}}
hide_thank_you();}
function window_height(){var myHeight=0;if(!$.browser.msie){myHeight=window.innerHeight;}else{myHeight=document.documentElement.clientHeight;}
return myHeight}
function set_popup_dimensions(isCoupon){if(isCoupon){if($.browser.msie){contact_dialog_height=510;}
else{contact_dialog_height=500;}
contact_dialog_width=750;}
else{if($.browser.msie){contact_dialog_height=400;}
else{contact_dialog_height=375;}
contact_dialog_width=465;}}
function hide_thank_you(){$(lead_popup).removeClass("thank_you");$(lead_popup+" .flash_notice").html("");$(lead_popup).css("height",contact_dialog_height);}
function reset_lead_form(){if(contact_dialog){contact_dialog.dialog('destroy');}
contact_dialog=null;}
function setup_lead_form(self){self=self.type=='click'?$(this):self;current_listing_id=$(self).attr("listing_id");lead_phone_required=$(self).attr("lead_phone_required");set_lead_popup($(self).attr("lead_type"));if(lead_phone_required=="1"){$(".lead_phone_label").html("<em>*</em>&nbsp;Phone&nbsp;Number:");}else{$(".lead_phone_label").html("Phone&nbsp;Number:");}
$(".lead_form input[type='hidden'][id='lead_listing_id']").attr("value",current_listing_id);$(".lead_form input[type='hidden'][id='lead_phone_required']").attr("value",lead_phone_required);var occurrence_number=parseInt($(self).attr("id").split('_')[2])+1;if(occurrence_number!=NaN){$(".lead_form input[type='hidden'][id='occurrence_number']").attr("value",occurrence_number);}
$('#prop_name').html($(self).attr('prop_name'));if($(self).hasClass('special_offer')){$('#lead_form_heading').html('Current Rent Specials!');$('.lead_form input#special_offer').attr('value','true');if($('.lead_form textarea.lead_message').html()==''){$('.lead_form textarea.lead_message').html('Please tell me about your current rent specials!');}}else{$('#lead_form_heading').html('Check Availability');$('.lead_form input#special_offer').attr('value','false');}
if($(self).attr('id')=='fp_check_avail'){$('#is_featured_property').attr('value','true');}
if(contact_dialog==null){contact_dialog=$(lead_popup).dialog({modal:false,bgiframe:true,close:function(event,ui){$('#lead_lightbox').hide();},width:contact_dialog_width,height:contact_dialog_height,resizable:false,draggable:false});$(lead_popup).show();$(lead_popup+" .lead_form").show();}
else{hide_thank_you();$(lead_popup).css("height",contact_dialog_height);$(lead_popup+" .lead_form_container").show();contact_dialog.dialog("open");$(lead_popup+" .lead_form").show();}
$('#lead_first_name_lead_partial').focus();return false;}
function showOverlay(){$("#lead_lightbox").show();var height=$("body").height()>$(window).height()?$("body").height():$(window).height();$("#lead_lightbox").css('height',height);$("#lead_lightbox").css('width',$("body").width());}
function isNumberKey(evt){var charCode=(evt.which)?evt.which:evt.keyCode
if(charCode>31&&(charCode<46||charCode>57)){return false;}
formatPhone(evt,this);return true;}
function isNumberKeyNoFormat(evt){var charCode=(evt.which)?evt.which:evt.keyCode;if(charCode>31&&(charCode<46||charCode>57)){return false;}
return true;}
function formatPhone(e,obj){if(e.keyCode==9){return;}
var validchars='0123456789';p=obj.value;for(var i=p.length;i>=0;i--){if(validchars.indexOf(p.charAt(i))==-1){p=p.replace(p.charAt(i),'');}}
if(p.length>1&&p.charAt(0)!="("){p="("+p;}
if(p.length>4&&p.charAt(4)!=")"){p=p.substring(0,4)+") "+p.substring(4);}
if(p.length>5&&p.charAt(5)!=" "){p=p.substring(0,5)+" "+p.substring(5);}
if(p.length>9&&p.charAt(9)!="-"){p=p.substring(0,9)+"-"+p.substring(9);}
for(var xPos=0;xPos<p.length;xPos++){if((p.charAt(xPos)=="-")&&(xPos!=9)){p=p.substring(0,p.length-1);}}
if(p.length>14)
p=p.substring(0,14)
obj.value=p;}
function URLDecode(str){return unescape(str).replace(/\+/g,' ');}
function populateContactFormFromCookie(){form_types=["_inline","_partial","_partial_coupon"];if($.cookie('lead_details')){lead_arr=$.cookie('lead_details').split("|");lead_first_name=URLDecode(lead_arr[0]);lead_email=URLDecode(lead_arr[2]);lead_phone=URLDecode(lead_arr[3]);lead_message=URLDecode(lead_arr[5]);lead_opt_in=URLDecode(lead_arr[6]);lead_move_date_preference=URLDecode(lead_arr[7]);for(x=0;x<=form_types.length-1;x++){if($(".lead"+form_types[x]).size()>0){$("#lead_first_name_lead"+form_types[x])[0].value=lead_first_name;$("#lead_email_lead"+form_types[x])[0].value=lead_email;$("#lead_phone_lead"+form_types[x])[0].value=lead_phone;$("#lead_move_date_preferencelead"+form_types[x]).selectOptions(lead_move_date_preference,true);$("#lead_message_lead"+form_types[x])[0].value=lead_message;$("#lead_opt_in_lead"+form_types[x])[0].value=lead_opt_in;}}}}
var top_city_dialog=null;var last_search_term="";$(document).ready(function(){var form_channel=$("#channel").attr("value");if(form_channel==""||form_channel==null){$("#channel").attr("value",channel);}
setup_channel_click();channel=$('input#channel').val();if(channel==''||channel==null||channel=='rentals')channel='apartments';var el_name='li#'+channel+' > a';toggle_selection($(el_name));change_the_channel($(el_name));clear_suggest();unclear_suggest();if($('select#term').length>0){$('select#term').change(function(e){change_price_options($('select#term').val());});}
if($(".searchCitiesStatesImg").length>0){$(".searchCitiesStatesImg").click(setup_top_cities_popup);}
if($('input#user_search').length>0&&$('input#user_search').val().length==0){change_suggest_text(channel);}
$("input#user_search").focus();});function clear_suggest(){$("input#user_search").click(function(){var current_text=$('input#user_search').val();if(is_suggestion_text(current_text))
$('input#user_search').val('');});}
function is_suggestion_text(query){if(query=="City, State or Zip"||query=="College, State"||query=="Military Base, State"||query==""){return true;}
return false;}
function unclear_suggest(){$("input#user_search").blur(function(){if($('input#user_search').val()=='')
change_suggest_text(channel);});}
function change_the_channel(element){newChannel=element.parent()[0].id;if(newChannel=='corporate'){$("select#term").show();change_price_options($("select#term").attr("value"));}
else{if(!$("select#term").is(':hidden')&&lowBandwidth()){$("select#term").hide();change_price_options("Per Month");}};if(newChannel!=channel){change_suggest_text(newChannel);}
channel=newChannel;}
function setup_channel_click(){$("#search_type > li > a:not(.external)").click(function(){toggle_selection($(this));change_the_channel($(this));});}
function toggle_selection(element){var link_selected=$("#search_type > li.active");link_selected.removeClass('active');element.parent().addClass('active');}
function change_suggest_text(channel){var result='';switch(channel){case"military":result='Military Base, State';break;case"college":result='College, State';break;default:result='City, State or Zip';}
last_search_term=$('input#user_search').val;$('input#user_search').val(result);$("#channel").attr("value",newChannel);}
function change_price_options(term){jQuery("#pricerange").load("/price_ranges","term="+term);}
function setup_top_cities_popup(){if(top_city_dialog==null){top_city_dialog=$("#cities_states").dialog({modal:true,bgiframe:true,width:740,height:540,resizable:false,draggable:false});$("#cities_states").show();$("#cities_states").dialog("open");}
else{top_city_dialog.dialog("open");}
hide_dropdowns(true,"cities_states");return false;}