var commentId = 0;
		
sendRfp = function(){
	// reset the errors
	resetErrors();
	
	// show the please wait graphic
	$("#submitting").show();
	$("#actionButton").hide();
	
	// bind the form (again and again and again!)
	$('#rfpForm').ajaxForm(); 
	
	// try to submit the form.
	$('#rfpForm').ajaxSubmit({
		success: handleResponse,
		url: '/model/remote/RemoteContactService.cfc?method=sendRfpMessage&returnFormat=json'
	});
}


handleResponse = function(data){
	var result = data;
	
	// eval the json returned
	result = eval('(' + result + ')');
	
	// check if there were errors
	if(result.errors._errorCount > 0){
		// yup
		
		// find each element with an error
		for(var element in result.errors){
			if(element != "_errorCount"){
				// display erros for this element
				displayErrors(element, result.errors[element].errors);
			}
		}
	} else {
		// nope
		messageSent(result.object);			
	}
		
	// show the please wait graphic
	$("#submitting").hide();
	$("#actionButton").show();

	return false;
}

resetErrors = function(){
	var errors = $('ul.error');
	errors.remove();
}

displayErrors = function(element, errors){
	var element = $('#' + element);
	var html = '';
	
	html += '<ul class="error">';

	for(var x = 0 ; x < errors.length ; x++){
		html += '<li>' + errors[x].message + '</li>';
	}

	html += '</ul>';
	
	element.parents("div.formfield").append(html);
	
	$('ul.error').slideDown("fast");
}

messageSent = function(){
	location.href="/contact.requestProposal.thankyou";
}
