﻿$(function()
{
	$('#rec-tabs').tabs();

	// Find all the recommend links and hook them up to the dialog
	$('#dialog-recommend').dialog(
	{
		autoOpen: false,
		bgiframe: true,
		modal: true,
		title: 'Recommend this Profile',
		buttons:
		{
			'Recommend' : function() { $(this).dialog('close'); recommend(); },
			Cancel : function() { $(this).dialog('close'); }
		}
	});

	$('#dialog-recommend textarea.limited').show_char_limit(300, { status_element : '#recommend-feedback' });

	$('.recommend-link a').click(function(ev)
	{
		ev.preventDefault();
		$('#dialog-recommend').dialog('open');
	});
});

function recommend()
{
	var id = $('#listing-id').val();
	var fromListingID = $('#dialog-recommend :radio:checked').val();
	if (fromListingID == null)
		fromListingID = $('#from-listing-id').val();
	var comment = $('#rec-comment').val();

	$.ajax(
	{
		type: 'POST',
		url: '/services/user_account.asmx/MakeRecommendation',
		dataType: 'json',
		contentType: 'application/json; charset=utf-8',
		data: '{ "id" : "' + id + '", "fromListingID" : "' + fromListingID + '", "comment" : "' + comment + '" }',
		success: function(data)
		{
			$('.recommend-link').html('<span class="leftthumb">You have recommended this profile.</span>');
			$('#dialog-recommend').html('Thank you for recommending this profile.');
			$('#dialog-recommend').dialog('option', 'title', 'Profile Recommended');
			$('#dialog-recommend').dialog('option', 'buttons', { Ok : function() { $(this).dialog('close'); } });
			$('#dialog-recommend').dialog('open');
		},
		error: function(xhr)
		{
			alert(xhr.status);
		}
	});
}