var phone_field_length=0;
function TabNext(obj,event,len,next_field) {
	if(event == "down") { 
		phone_field_length=obj.value.length;
	} else if(event == "up") { 
		if(obj.value.length != phone_field_length) { 
			phone_field_length=obj.value.length;
			if(phone_field_length == len) {
				var nextfield = next_field;
				nextfield.focus();
			}
		}
	}
}
function toggleLayer(whichLayer) {
	if (document.getElementById) {
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
		}
	else if (document.all) {
// old IE browser support
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
	else if (document.layers) {
// nn4 browser support
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
		}
}

  	$(document).ready(function() {
  		function RegisterClick(MyObject) {
  			MyObject.click(function() {
  				window.location.href = "/MyListings?Mode=1";
  			});
  		}
  		
  		$(".AddToSherpa").click(function() {
  			var SelID = $(this).attr('id');
  			
  			$(this).attr("src","/Images/mysherpa.gif");
  			$(this).removeClass();
  			$(this).removeAttr('onmouseover');
  			$(this).removeAttr('onmouseout');
  			$(this).unbind();
  			RegisterClick($(this));
  			
  			if(SelID > 0) {
  				$.getJSON("/SaveListing", { AptID: SelID }, function(json,MyObject) { 
  					if(json == -1) {
  						alert("Invalid Apartment ID");
  					} 
  					if(json == -2) {
  						window.location.href = '/LoginUser';
  					}
  					if(json == 1) {
  						alert("This apartment has been added to your Sherpa account.");
  					}
  				});
  			}
  			
  		});
  		$(".AddToSherpa2").click(function() {
  			var SelID = $(this).attr('id');
  			
  			$(this).attr("class","saveon");
  			$(this).removeClass();
  			$(this).removeAttr('onmouseover');
  			$(this).removeAttr('onmouseout');
  			$(this).unbind();
  			RegisterClick($(this));
  			
  			if(SelID > 0) {
  				$.getJSON("/SaveListing", { AptID: SelID }, function(json,MyObject) { 
  					if(json == -1) {
  						alert("Invalid Apartment ID");
  					} 
  					if(json == -2) {
  						window.location.href = '/LoginUser';
  					}
  					if(json == 1) {
  						alert("This apartment has been added to your Sherpa account.");
  					}
  				});
  			}
  			
  		});
  	});