function getToday() {
	var myDate = new Date();
	var d = myDate.getDate();
	var m = myDate.getMonth()+1;
	var y = myDate.getFullYear();
	var date = (d < 10 ? "0" + d : d) + '.' + (m < 10 ? "0" + m : m) + '.' + y;
	return date;
}

$(document).ready(function(){
	if(userLoggedIn) {
		$('a.addFavorites,.domainListingTable a.removeFavorites').click(function(){
			var link = $(this);
			var href = link.attr("href");
			href = href.indexOf('?') > 0 ? (href + '&ajax=1') : (href + '?ajax=1');
			
			if(link.attr("class") == "addFavorites") {
				$.get(href, null, function (data) {
					if(data != "-1"){
						link.attr("class", "removeFavorites");
						link.attr("title", "Remove from Favorites");
						href = href.replace("add=", "remove=");
						link.attr("href", href);
						$("#favoriteDomainsLink").html("Favorites <span>(" + data + ")</span>");
					}
				});
			}
			else {
				$.get(href, null, function (data) {
					if(data != "1"){
						link.attr("class", "addFavorites");
						link.attr("title", "Add to Favorites");
						href = href.replace("remove=", "add=");
						link.attr("href", href);
						$("#favoriteDomainsLink").html("Favorites <span>(" + data + ")</span>");
					}
				});
			}
			return false;
		});

		$('a.saveSearch').click(function(){
			var link = $(this);
			var href = link.attr("href");
			href = href.indexOf('?') > 0 ? (href + '&ajax=1') : (href + '?ajax=1');
			
			$.get(href, null, function (data) {
				if(data == "1"){
					link.css("display", "none");
					
					//$("#savedSearchesListing li.last").attr('class', '');
					var u = link.attr("href");
					var url = u.replace("save=&", "");
					var name = u.match(/keywords=([^&]*)/)[1];//.substring(9, u.length);
					$("#savedSearchesListing").prepend(
				'<li>' +
					'<div class="searchName"><a href="'+ url+ '">' + name + '</a></div>' +
					'<div class="searchDate">' + getToday() + '</div>'+
					'<div class="clear"><!--for.i.e.6.0--></div>'+
				'</li>');
				}
			});
			return false;
		});
	
	
	}
	
	$(document).bind('beforeReveal.facebox', function() { 
		$('select').css("display","none");
	});

	$(document).bind('close.facebox', function() { 
		$('select').css("display","block");
	});
	$('select').toChecklist({
		submitDataAsArray : false
	});

	$("#offer").number_format({
		precision: 0,
		decimal: '.',
		thousands: ',',
		'default': '',
		allow_negative: false
	});

	$("a.readmore").click(function(){
		if($(this).siblings("div").hasClass("closed")){
			$(this).siblings("div").removeClass("closed");
			$(this).siblings("div").addClass("opened");
			$(this).text("collapse");
		}
		else {
			$(this).siblings("div").removeClass("opened");
			$(this).siblings("div").addClass("closed");
			$(this).text("expand");
		}
		return false;
	});

	$("#addCommentLink").click(function(){
		$("#commentContainer").toggle(500);
		return false;
	});

});

function focusInput(text, val){
	if(text.value == val){
		text.value="";
	}
}

function focusOutInput(text, val){
	if(text.value == "")	{
		text.value=val;
	}
}

function submitInput(text, val) {
	if(text.value == val ){
		text.value = "";
		//text.focus();
		//jQuery.facebox('Please enter a keyword, phrase or a domainname!');
		//return false;
	}
	return true;
}
function confirmBuy(dn, val){
	return confirm("Are you sure you want to buy " + dn + " for " + val +"?");
}

function confirmCancel(){
	return confirm("Are you sure you want to cancel this negotiation?");
}



