var my_account_link = '<a href="/account/index.php">My Account</a>';
var upgrade_link = '<a href="/account/upgrade.php">Upgrade</a>';


$(document).ready(function () {
	$(".creator").bind("mouseenter", function(e){
		$("#creator_info_ajax").html('<div style="margin-left:110px; margin-top:100px;"><img src="/img/loading.gif"></div>');
		$.get("ajax/get_creator.php", { id: $(this).attr("id") }, function(data){
			$("#creator_info_ajax").html(data);
		});
		$("#creator_info_ajax").css({top:$(this).offset().top -120 , left:$(this).offset().left - 300}).show();
	});
	$(".creator").bind("mouseleave", function(e){
		$("#creator_info_ajax").hide();
	});

	$(".showhideCategory").bind("click", function(e){
		$("#categories").toggle();
		$(".showhideCategory").toggle();
	});
	$(".showhideCountry").bind("click", function(e){
		$("#countries").toggle();
		$(".showhideCountry").toggle();
	});
	$("#logo").bind("click", function(e){
		$("#countries").toggle();
		$(".showhideCountry").toggle();
	});
	$('.bid_button_a').bind("mouseover", function(e){
		window.status='Bid on This Project'; 
	});
	$('.post_button_a').bind("mouseover", function(e){
		window.status='Post Similar Project'; 
	});
});
function show_detail(id)
{
	$("#" + id).show('normal');
	//document.getElementById(id).style.display = "block";
}
function hide_detail(id)
{
	$("#" + id).hide('normal');
	//document.getElementById(id).style.display = "none";
}

function show_all_countries(obj)
{
	$(".less").show();
	obj.style.display = "none";
}

function saveSearch(session_id)
{
	$(".hintMsg").hide();
	$(".errMsg").hide();
	$.get("ajax/check-save-search.php", { session_id: session_id },
	  function(data){
		if(data == "0")
		{
			$("#save_search_form").show();
		}else{
			$(".errMsg").html("You have already saved this search, you can see it in '" + my_account_link + "' page.");
			$(".errMsg").show();
		}
	  });
}

function doSaveSearch(session_id)
{
	$(".hintMsg").hide();
	$(".errMsg").hide();

	$.get("ajax/do-save-search.php", { session_id: session_id, title: $("#title").val() },
	  function(data){
		$("#save_search_form").hide();
		if(data == "1")
		{
			$(".hintMsg").html("You have successfully saved this search, you can see it in '" + my_account_link + "' page.");
			$(".hintMsg").show();
		}else{
			$(".errMsg").html("Errors occured when saving, please contact administrator");
			$(".errMsg").show();
		}
		
	  });
}

function doTrack(creator_id)
{
	$(".hintMsg").hide();
	$(".errMsg").hide();
	$.get("/ajax/do-tracked.php", { creator_id: creator_id },
	  function(data){
		if(data == "1")
		{
			$(".hintMsg").html("You have successfully tracked this buyer, you can see it in '" + my_account_link + "' page.");
			$(".hintMsg").show();
		}else{
			$(".errMsg").html("You have already tracked this buyer, you can see it in '" + my_account_link + "' page.");
			$(".errMsg").show();
		}
		
	  });
}