function identifyBrowser(ident) {
	return ua.indexOf(ident) >= 0;
}

/*
 * This is used to obtain the latest blog-news within the footer
 */
function get_rss_feed() {
	//use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
	$.get("/apex/rss/news.xml", function(d) {
		var count = 0;
		//find each 'item' in the file and parse it
		$(d).find('entry').each(function() {
			count++;
			//name the current found item this for this particular loop run
			var $item = $(this);
			// grab the post title
			var title = $item.find('title').text();
			// grab the post's URL
			var link = $item.find('url').text();
			var result2 = "<li><a target='_blank' href='"+link+"'>"+title+"</a></li>";
			if (count < 6) {$("#news").append(result2);}  
		});
		$("#news").append("<li>See all <a target='_blank' href='http://www.apexauctions.blogspot.com/'>ApexBlog posts</a></li>");
	});
}

function ImgError(source){
	source.src = "/apex/images/missing.gif";
	source.onerror = "";
	return true;
}

/**
 * Checks to see if any check boxes from a set with a given ID are actually checked.
 * 
 * @param idToFind The start of the ID that the sought after check boxes should have.
 * @return true if there are any check boxes in the DOM that are checked AND that have an ID starting with idToFind
 */
function areAnyCheckBoxesChecked(idToFind)
{
	var checkBoxesChecked = false;
	$("input[type=checkbox][checked=true]").each(function()
	{
		// this function will be fired for each checkbox on the page that is currently checked
		// but is this one one of the checkboxes that we are looking for?
		if (this.id.indexOf(idToFind) === 0)
		{
			checkBoxesChecked = true;
		}
	});
	return checkBoxesChecked;
}

$(document).ready(function ()
{
	ua = navigator.userAgent.toLowerCase();
	download = null;
	if(identifyBrowser("firefox/0") || identifyBrowser("firefox/1") || identifyBrowser("firefox/2")) {
		download = "http://www.mozilla.com/en-US/";
		br = "Firefox";
	}
	else if (identifyBrowser("msie 6") || identifyBrowser("msie 5") || identifyBrowser("msie 4") || identifyBrowser("msie 3") || identifyBrowser("msie 2")) {
		download = "http://www.microsoft.com/windows/Internet-explorer/default.aspx";
		br = "Internet Explorer";
	}
	if (identifyBrowser("msie 6") && (download !== null)) {
		$("#wrapper_content").prepend("<div id=\"browser-warning\"><img src=\"/apex/images/warning_32.png\"> <span>You are currently using an out-dated version of Internet Explorer. Please upgrade to the latest version. <a href=\""+download+"\">latest version</a></span></div>");
	}    
	else if(download !== null) {
		$("#wrapper_content").prepend("<div id=\"browser-warning\"><img src=\"/apex/images/warning_32.png\"> <span>You are currently running an old version of "+br+" that this site does not support. Please update to the <a href=\""+download+"\">latest version</a></span></div>");
	}
	
	$(".typedCurrency").keyup(function() {
		$(this).val(currencyFormatted($(this).val().replace(/,/g,"")));
	});

	$('.youtube_link').prettyPhoto();
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	$('#createNewAccount').click(function() {
		arr = location.href.split("/");
		location.href="createAccount.htm?referer="+arr[arr.length-1];
	});
	
	$('#login').click(function() {
		arr = location.href.split("/");
		location.href="login.htm?referer="+arr[arr.length-1];
	});
	
	stripeTableRows('datatable');
	
	get_rss_feed();
});
