$(document).ready(function() {
	$('button#customerService').click(function() {
		resetLabels();
		$('.hlerror').removeClass().addClass('input-text');
			$.ajax({
			type:'post',
			cache:false,
			context: this,
			data:{
				firstname:$("input[name='firstname']").val(),
				lastname:$("input[name='lastname']").val(),
				csemail:$("input[name='csemail']").val(),
				question:$("textarea[name='question']").val()
				},
			dataType:'json',
			url:'/com/Ajax/FormsAjax.cfc?method=CustomerService',
			success: function(data,textStatus,httpRequest) {
					if(data.STATUS == 'ok') {
						$('#cs-contact-form form').get(0).reset();
				} else {
					resetLabels();
					for(itm in data) {
						if(data[itm].STATUS != 'ok') {
							var toi = '';
							toi = $('[name=' + itm.toLowerCase() + ']').attr('type');
							if(toi == 'text'){toi = 'input';}
							$(toi + '[name=' + itm.toLowerCase() + ']').addClass('hlerror');
							$('label[for=' + itm.toLowerCase() + ']').append('<span class="error-text">' + data[itm].REASON + '</span>');
						}
					}
					$('.hlerror:first').focus();
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				var result = { XMLHttpRequest:XMLHttpRequest, textStatus:textStatus, errorThrown:errorThrown };
				Broadway.error.send({subject:'Ajax UI Error',msg:'- Ajax UI error in /views/MyAccount/js/index.js : myAccount',obj:result});
			}
		});
	});

function resetLabels(){
	$('label[for=firstname]').removeClass('error-text');
		$('label[for=firstname]').html('First:');
		$('label[for=lastname]').removeClass('error-text');
		$('label[for=lastname]').html('Last:');
		$('label[for=csemail]').removeClass('error-text');
		$('label[for=csemail]').html('Email:');
		$('label[for=question]').removeClass('error-text');
		$('label[for=question]').html('Question or Comment:');
}
});
