var RentJuice = {};
Object.extend( RentJuice, {
	"Queue":{},
	Registry : {
		alphabet : $w("a b c d e f g h i j k l m n o p q r s t u v w x y z"),
		templates : {
			infoWindowHtml : new Template('<div class="infowindowhtml"><img src="#{thumbnail}" width="45" height="45"/><div class="info"><div><strong>#{address}</strong></div><span><strong>$#{rent}</strong></span><span><strong>#{bedrooms}</strong> Bds.</span><span class="last"><strong>#{bathrooms}</strong> Bths.</span></div></div>')
		},
		cityCenters : {
			"boston" : {
				latitude : "42.358924",
				longitude : "-71.057553"
			}
		},
		validations : {
			"validate-required" : /[\S]+/,
			"validate-ssn" : /[0-9]{3}-?[0-9]{2}-?[0-9]{4}|^$/,
			"validate-currency" : /\$?\s?[0-9]+(?:\.?[0-9]+)?|^$/,
			"validate-phone" : /(.*)/,
			"validate-integer" : /[0-9]+|^$/,
			'validate-email' : /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/
		},
		fields : {
			"address" : {
				"editing":'Example: "123 Main St.", "1 Union St.", etc.',
				"invalid":"You cannot add a listing without an address."
			},
			"user_address" : {
				"editing":'Example: "123 Main St.", "1 Union St.", etc.',
				"invalid":"You cannot add a listing without an address."
			},
			"city" : {
				"editing":'Example: "Boston", "Cambridge", "New York", etc.',
				"invalid":"You cannot add a listing without a city."
			},
			"state":{
				"editing":'Example: "Massachusets", "Florida", "California", etc.',
				"invalid":"You cannot add a listing without a city."
			},
			"user_city" : {
				"editing":'Example: "Boston", "Cambridge", "New York", etc.',
				"invalid":"You cannot add a listing without a city."
			},
			"unit" : {
				"editing":"Example: B102, #5, 10, etc.",
				"invalid":"Leave blank for single-family home."
			},
			"rent" : {
				"editing":"Example: $1,400, 1350.90, 970, etc.",
				"invalid":"Rent is required and must be a numeric value."
			},
			"bedrooms" : {
				"editing":"Example: 0, 2, 4, etc.",
				"invalid":"You must specify the number of bedrooms."
			},
			"bathrooms" : {
				"editing":'Example: 0.5, 1, 2.5, etc.',
				"invalid":"You must specify the number of bedrooms."
			},
			"current-tenant" : {
				"editing":"Example: \"John Smith, (212) 555-1212\"",
				"invalid":"Providing tenant information is helpful to other realtors. Please add some."
			},
			"listing-status" : {
				"editing":"This will be the initial status for this listing.",
				"invalid":""
			},
			"date-available" : {
				"editing":"Example: 0.5, 1, 2.5, etc.",
				"invalid":""
			},
			"public-title-ads" : {
				"editing":'Example: "Beautiful beach-facing apartment"',
				"invalid":''
			},
			"public-description-ads" : {
				"editing":'Example: "High ceilings, remodeled bathrooms and kitchen, awesome views!"',
				"invalid":""
			},
			"internal-private-notes" : {
				"editing":'These notes are not displayed to anyone outside the agency.',
				"invalid":""
			},
			"floor" : {
				"editing":'Example: "First floor", "1", "top", etc.',
				"invalid":""
			},
			"cross-street" : {
				"editing":'Example: "Main St.", "2nd Av.", etc.',
				"invalid":""
			},
			"approx-sq-footage" : {
				"editing":'Example: "700", "1500", etc.',
				"invalid":""
			},
			"parking-spots" : {
				"editing":'Example: "1", "Not included", "2 Tandem", etc.',
				"invalid":""
			},
			"keys" : {
				"editing":'Example: "Contact Primary Agent", "#37782", "at front desk", etc.',
				"invalid":""
			},
			"landlord_name" : {
				"editing":'Example: "John Smith", "Awesome Agency", etc.',
				"invalid":"Every landlord must have a name."
			},
			"phone" : {
				"editing":'Example: (212) 555-1212, +12125551212, 5551212, etc.',
				"invalid":""
			},
			"fax" : {
				"editing":'Example: (212) 555-1212, +12125551212, 5551212, etc.',
				"invalid":""
			},
			"email" : {
				"editing":'Example: someone@example.com, etc.',
				"invalid":""
			},
			"website" : {
				"editing":'Example: "http://www.example.com", "example.com", etc.',
				"invalid":""
			},
			"landlord_address" : {
				"editing":'Example: "123 Main St.", "1 Union St.", etc.',
				"invalid":""
			},
			"lead_name" : {
				"editing":'Example: "John Smith", "Awesome Agency", etc.',
				"invalid":"Every landlord must have a name."
			},
			"minimum-bedrooms":{
				"editing":'Example: "1", "2", "5", etc.',
				"invalid":""
			},
			"maximum-bedrooms":{
				"editing":'Example: "1", "2", "5", etc.',
				"invalid":""
			},
			"move-in-date":{
				"editing":'Example: "September, 14th", "9/14", "Sep. 14th.", etc.',
				"invalid":""
			},
			"minimum-rent":{
				"editing":'Example: "500", "1,000", etc.',
				"invalid":""
			},
			"maximum-rent":{
				"editing":'Example: "2,500", "1,000", etc.',
				"invalid":""
			},
			"email-address" : {
				"editing":'Your Email address. Example: someone@example.com, etc.',
				"invalid":"You cannot login without an email address."
			},
			"password" : {
				"editing":'Your account password.',
				"invalid":"You cannot login without a password."
			},
			"first-name":{
				"editing":'Example: "John", "Peter", etc.',
				"invalid":"Are you sure you don't have a name?"
			},
			"last-name":{
				"editing":'Example: "Smith", "Stewart", etc.',
				"invalid":"Don't have a last name?"
			},
			"phone-number":{
				"editing":'Example: (212) 555-1212, +12125551212, 5551212, etc.',
				"invalid":""
			},
			"public-brand-name":{
				"editing":'This <strong>optional</strong> name is shown in your personal advertisements, in place of your agency\'s official name.',
				"invalid":""
			},
			"zip-code":{
				"editing":'Example: "90210", "33139", "94123", etc.',
				"invalid":"ZIP Code is required."
			},
			"old-password":{
				"editing":'Please provide your old/current password for validaion.',
				"invalid":"You must provide your password."
			},
			"new-password":{
				"editing":'Type a new password.',
				"invalid":""
			},
			"re-type-new-password":{
				"editing":'Re-type your new password.',
				"invalid":""
			},
			"card-number":{
				"editing":'Your credit card number.',
				"invalid":"Your credit card number cannot be empty."
			},
			"security-code":{
				"editing":'The 3 or 4 digit security code on the back of the card.',
				"invalid":"The security code cannot be empty."
			},
			"expiration-date":{
				"editing":"Your credit card's expiration date.",
				"invalid":"The credit card expiration date cannot be empty."
			},
			"ad-header":{
				"editing":"This code is included at the top of each of your advertisements. HTML only, please.",
				"invalid":""
			},
			"ad-footer":{
				"editing":"This code is included at the bottom of each of your advertisements. HTML only, please.",
				"invalid":""
			}
		}
	},
	Classes : {},
	Cookies : {
		all : function(){
			cookies = {};
			$A(document.cookie.split('; ')).collect(function(cookie){
				valuePair = cookie.split('=');
				cookies[valuePair[0]] = valuePair[1];
			});
			return cookies;
		},
		get : function(name){
			return this.all()[name];
		},
		set : function(name,value,days){
			days = typeof days === 'undefined' ? 14 : days ;
			var date= new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = date.toGMTString();
			cookiestr = name+"="+escape (value )+";";
			if ( days > 0 ) {
				cookiestr += " expires="+expires+";";
			}
			cookiestr += " path=/";
			document.cookie = cookiestr;
		},
		remove : function(name){
			this.set(name,"",-1);
		}
	},
	Util : {
        extractStringsFromObject : function (obj) {
            for (varName in obj) {
                var varType = typeof obj[varName];
                var varValue = obj[varName];
                if (varType == 'string' || varType == 'number') {
                    RentJuice.objectValues[varName] = varValue;
                } else if (varType == 'object') {
                    RentJuice.Util.extractStringsFromObject(varValue);
                }
            }
            
        }
    }
});
Object.extend(String.prototype,{
	fitStrToPxWidth: function(targetWidth) {
		var terminator = "…";
		var stringWidth = null;
		var ruler = new Element("span",{"style":"visibility:hidden;position:absolute;"});
		$$("body")[0].insert({"bottom":ruler});
		var terminatorWidth = ruler.update( terminator ).getWidth();
		targetWidth = targetWidth + terminatorWidth;
		var stringWidth = ruler.update( this ).getWidth();
		while( stringWidth > targetWidth ) {
			output = this.substring( 0, this.length-1 );
			stringWidth = ruler.update( output ).getWidth();
		}
		output = output+terminator;
		return output;
	},
	number_format: function() {
		x = this.toString().split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
});
Object.extend(Element.Methods,{
	observers: function(element, eventNames, handler){
		element = $(element);
		$w(eventNames).each(function(eventName){
			element.observe(eventName,handler);
		});
		return element;
	},
	scrollTo: function(element, target){
		element = $(element); 
		target = $(target); 
		var x = target.x ? target.x : target.offsetLeft,
		y = target.y ? target.y : target.offsetTop;
		element.scrollLeft=x-(document.all?0:element.offsetLeft );
		element.scrollTop=y-(document.all?0:element.offsetTop);
		return element;
	},
	clone: function(element) {
		return $(element).cloneNode(true);
	},
	inViewport:function(element) {
		var top = element.offsetTop;
		var left = element.offsetLeft;
		var width = element.offsetWidth;
		var height = element.offsetHeight;
		while( element.offsetParent ) {
			element = element.offsetParent;
			top += element.offsetTop;
			left += element.offsetLeft;
		}
		return ( top >= window.pageYOffset && left >= window.pageXOffset && (top + height) <= (window.pageYOffset + window.innerHeight) && (left + width) <= (window.pageXOffset + window.innerWidth) );
	},
	fireEvent:function( element, event ) {
		if( document.createEvent ) {
			var evt = document.createEvent("HTMLEvents");
			evt.initEvent(event, true, true ); // event type,bubbling,cancelable
			return !element.dispatchEvent(evt);
		} else {
			var evt = document.createEventObject();
			return element.fireEvent('on'+event,evt)
		}
	}
});
Object.extend(Form.Element.Methods,{
	validation: function(element,options) {
		element = $(element);
		element.expression = null;
		element.error = null;
		element.preprocessor = Prototype.emptyFunction;
		element.postprocessor = Prototype.emptyFunction;
		Object.extend( element, options );
		return element;
	},
	isValid:function(element){
		if ( element.preprocessor ) {
			element.preprocessor();
			return element.expression.test( element.value );
			element.postprocessor();
		}
	}
});
Object.extend(Form.Methods,{
	isValid:function(element){
		element = $(element);
		element.errors = $A();
		element.errors = element.select("input").collect(function(input){
			return !input.isValid() ? input.error : null ;
		}).compact();
		return !element.errors.size() > 0;
	}
});
Element.addMethods();



