/*
 * Copyright 2008-2009 Palm, Inc. All rights reserved.
 */

/**
 * Constructor.
 * 
 * @param {String} url
 * @param {String} title
 * @param {Date} date this reference was created (not last visited)
 */
function UrlReference(url, title, date) {
	this.url = url;				///< The page's URL.
	this.parsedUrl = undefined;	///< Lazily created when needed.
	this.title = title;			///< The page title.
	this.date = date;			///< Date this reference was made
	this.defaultEntry = false;	///< Default entries are those that come from C&C database
	this.iconFile32 = null;		///< Full path to 32x32 pixel icon file
	this.iconFile64 = null;		///< Full path to 64x64 pixel icon file
	this.thumbnailFile = null;	///< full path to page thumbnail fail
	this.visitCount = 0;		///< The number of times this URL is visited.
	this.lastVisited = date;	///< The date this page was last visited.
	if (this.date === undefined) {
		this.date = new Date();	// Now
	}
}

/**
 * Test if a URL is equal to the one in this instance.
 *
 * http://www.foo.com == http://www.foo.com/
 * http://foo.com == http://www.foo.com
 */
UrlReference.prototype.urlRefEquals = function(urlRef) {
	
	try {
		if (urlRef.parsedUrl === undefined) {
			urlRef.parsedUrl = new Poly9.URLParser(urlRef.url);			
		}
		
		if (this.parsedUrl === undefined) {
			this.parsedUrl = new Poly9.URLParser(this.url);
		}
		return UrlUtil.urlParsedEquals(this.parsedUrl, urlRef.parsedUrl);
	}
	catch (e) {
		return false;
	}	
};


/**
 * Test if a URL is equal to the one in this instance.
 *
 * http://www.foo.com == http://www.foo.com/
 * http://foo.com == http://www.foo.com
 */
UrlReference.prototype.urlEquals = function(url) {

	if (url instanceof UrlReference) {
		return this.urlRefEquals(url);
	}

	if (this.url === url) {
		return true;
	}
	try {
		if (this.parsedUrl === undefined) {
			this.parsedUrl = new Poly9.URLParser(this.url);
		}
		return UrlUtil.urlParsedEquals(this.parsedUrl, new Poly9.URLParser(url));
	}
	catch (e) {
		return false;
	}
};


