	
	function popup(link,width,height,options) {
		
		options = options ? options : {};
		
		options.width		= width;
		options.height		= height;
		options.name		= options.name!=undefined ? options.name : "wpop";
		options.toolbar		= options.toolbar!=undefined ? options.toolbar : false;
		options.location	= options.location!=undefined ? options.location : true
		options.directories	= options.directories!=undefined ? options.directories : false;
		options.status		= options.status!=undefined ? options.status : false;
		options.menubar		= options.menubar!=undefined ? options.menubar : false;
		options.scrollbars	= options.scrollbars!=undefined ? options.scrollbars : true
		options.copyhistory 	= options.copyhistory!=undefined ? options.copyhistory : false;
		options.resizable 	= options.resizable!=undefined ? options.resizable : true
		
		options.toolbar		= options.toolbar ? "yes" : "no";
		options.location	= options.location ? "yes" : "no";
		options.directories	= options.directories ? "yes" : "no";
		options.status		= options.status ? "yes" : "no";
		options.menubar		= options.menubar ? "yes" : "no";
		options.scrollbars	= options.scrollbars ? "yes" : "no";
		options.copyhistory 	= options.copyhistory ? "yes" : "no";
		options.resizable 	= options.resizable ? "yes" : "no";
		
		o = [];
		for(var i in options) {
			o.push(i + "=" + options[i]);
		};
		
		window.open(link,options.name,o.join(","));
	}
	
	function show_box(href,width,height,options) {
		
		bmr 	= $("body").css("margin-right");
		
		// TODO: not sure why 8 is the magic number, but it works
		
		$("body").css("overflow","hidden");
		$("body").css("margin-right",(scrollbar_width() + 8) + "px");
		
		wheight 		= $(window).height();
		height			= height>wheight ? wheight : height;		
		
		var options 		= options==undefined ? {} : options;
		options.href 		= href;
		options.width 		= width;
		options.height 		= height;
		options.iframe 		= options.iframe==undefined ? 1 : options.iframe;
		options.speed 		= options.speed==undefined ? 0 : options.speed;
		options.transition 	= options.transition==undefined ? "none" : options.transition;
		options.scrolling 	= options.scrolling==undefined ? true : options.scrolling;
		options.photo		= false;
		
		if(options.onClosed==undefined)
			onClosed = function() { $("body").css("margin-right",bmr).css("overflow","") }
		else {
			onclose = options.onClosed;
			
			onClosed = function() { 	onclose(); 
							$("body").css("margin-right",bmr).css("overflow","") }
		}
		
		options.onClosed = onClosed;
		
		$.fn.colorbox(options);
		
		box_index("99999999");
	}
	
	function scrollbar_width() {
		var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
		$('body').append(div);
		var w1 = $('div', div).innerWidth();
		div.css('overflow-y', 'scroll');
		var w2 = $('div', div).innerWidth();
		$(div).remove();
		return (w1 - w2);
	}	
	
	function box_index(index) {
		$("#colorbox,#cboxOverlay,#cboxWrapper").css("z-index",index);
	}
	
	function show_box_fullscreen(url) {
		show_box(url,"100%","100%");
	}
	
	function hide_box() {
		$.fn.colorbox.close();
	}
	
	function submit_button(button) {	
	
		button = new jQuery(button);
		
		name 	= button.attr("name");
		value 	= button.val();
		
		$("form").append($("<input>",{type : "hidden", value : value, name: name })).submit();
	}
	
	function submit(action,form_id) {
		submit_form(action,form_id);
	}
	
	function submit_form(action,form_id) {
		
		f = form_id ? $("#" + form_id) : $("form");
		
		if(f) {
			if(action)
				f.attr("action",action);
			f.submit();
		}
	}
	
	function submit_input(name,value,f) {
		
		if(f==undefined)
			f = $("form");
		
		if(f) {
			
			value = value==undefined ? "" : value;
			
			i = $("<input>", { type: "hidden", name: name, value: value });
			f.append(i);
			f.submit();
			i.remove();
		}
	}	
	
	function set_form_action(action,id) {
		$("#" + id).attr("action",action);
	}

	function include(file) {
		var script  = document.createElement('script');
		script.src  = file;
		script.type = 'text/javascript';
		script.defer = true;

		document.getElementsByTagName('head').item(0).appendChild(script);
	}
	
	function pp(m) { alert(m); }
	
	function cc(m) { console.log(m); }
	
	function is_defined(x) { return typeof(x) != "undefined"; } 
	
	function redirect(u,t) {
		if(t)
			window.top.location = u;
		else
			window.location = u;
	}	
	
	function rand(n) {
		return (Math.floor ( Math.random ( ) * n + 1 ));
	}
	
	function round(n,d) {
		p = Math.pow(10,d);
		return (Math.round(n * p)/p);
	}
	
	function CacheUtil() {}
	
	var preload_cache = [];
	CacheUtil.preload = function() {
		var args_len = arguments.length;

		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			preload_cache.push(cacheImage);
		}
	}	

	function Format() {}

	Format.get_currency = function(val) {
		
		if(!is_defined(Number.prototype.numberFormat)) {	
			throw "Number Format (number-functions.js) not included";
			
			return 0;
		}
	
		if(val && typeof val != "number")
			val = val.replace(/[^\d.]+/g,"");
		val = parseInt(val);
		return "$" + (val>999 ? val.numberFormat("0,0,0") : val);
	}
	
	Format.get_percent = function(value,percision) {
	
		if(!is_defined(Number.prototype.numberFormat)) {	
			throw "Number Format (number-functions.js) not included";
			return 0;
		}
		
		percision = percision==undefined ? 3 : percision;

		var a = [];
		while(a.length < percision)
			a.push("#");

		val = parseFloat(value);
		return val.numberFormat("0." + a.join("")) + "%";	
	}
	
	
	function StringUtil() {}
	
	StringUtil.get_sanitized_number = function(num) {
		num = num.toString();
		num = num.replace(/,/g,"");
		matches = num.match(/^[^\d]*([\d]+)\.?/);
		num = 0;
		if(matches)
			num = parseFloat(matches[1]);
		return num;
	}
		
	StringUtil.get_sanitized_decimal = function(num) {
		num = num.toString();			
		num = parseFloat(num.replace(/[^\d.]+/g,""));
		return num ? num : 0;
	}	
	
	StringUtil.get_dot_dot_dot = function(string,limit) {
		limit -= 3;
		return string.length>=limit ? string.substr(0, limit) + "..." : string;		
	}
	
	String.prototype.get = function(p){
	    return (match = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))) ? match[1] : false;
	}
	
	function listing_property_save_note() {
		var is_logged_in = parseInt($('#is_logged_in').val());
		if(is_logged_in){
			var pid = $('#note_container').attr('pid');
			var notes = $('#notes').val();
			$.post("/listing/dosave_property_notes",{  
			pid: pid,
			notes: notes
			}, function(data) {  
				$('#note_container').hide('slow');
			}); 
		}
		else {
			$(location).attr('href', '/user/login');
		}
	}	
	
	function include(src) {
		js_script = document.createElement("script");
		js_script.type = "text/javascript";
		js_script.src = src;
		document.getElementsByTagName("head")[0].appendChild(js_script);	
	}
