var popupHTML = '<ul class="formItems" ><li><label for="feedbackSuggestions" >Is there anything about the bline site you particularly like or dislike? Have you any suggestions as to how we can improve it?<span class="requiredAsterix" >*</span></label><br /><textarea id="feedbackSuggestions" name="feedbackSuggestions" class="inputField inputFieldTextarea {mandatory: true, validation: 25, maxlength: 1000}" ></textarea><div class="inputError" id="error-feedbackSuggestions" ></div></li><li><label for="feedbackSuggestions" >What is your email address?<span class="requiredAsterix" >*</span></label><br /><input type="text" id="feedbackEmail" name="feedbackEmail" maxlength="200" class="inputField inputFieldText {mandatory: true, validation: 50}" ></input><div class="inputError" id="error-feedbackEmail" ></div></li></ul>';

$().ready(function()
{

});		

function popup()
{
	log(' = popup');

	var statesdemo = 
	{
		state0: {
			html: popupHTML,
			opacity: 0.4,
			useiframe: true,
			overlayspeed: 'fast', 			
			buttons:{Cancel: false, OK: true}, 
			loaded: function(){$('#feedbackSuggestions')[0].focus(); }, 
			submit: submitFeedbackForm
		},
		state1: {
			html:'<div class="feedbackSubmitted" ><img class="waitImage" src="/img/wait.gif" /><div class="waitText">Sending feedback...</div></div>',
			buttons: {OK: true},
			focus: 1			
		}
	};
	
	$.prompt(statesdemo);
	
	initaliseValidation();
}

function submitFeedbackForm(v, m, f)
{
	log(' = submitFeedbackForm. ' + v + m + f);
	
	if(v)
	{
		if(validateForm())
		{
			log(' - validateForm = true');
						
			parms = 'form_id=popupFeedbackBline' +
					'&feedbackSuggestions=' + $("#feedbackSuggestions").val() + 
					'&feedbackEmail=' + $("#feedbackEmail").val();
			
			
			doAjax('/servlet/submitPopupFeedbackForm.do', 'Feedback', parms, beforeFeedback, successFeedback, errorFeedback);
		}

		return false;
	}
	else
	{
		return true;
	}
}

function beforeFeedback(divId)
{
	log('beforeFeedback');
	
	$.prompt.goToState('state1');
}

function successFeedback(divId,response)
{
	log('successFeedback');
	
	$('.jqimessage').html('<div class="feedbackSubmitted" >Feedback sent. Thank you.</div>');
	
}

function errorFeedback(divId, response)
{
	log('errorFeedback');
	
	$('.jqimessage').html('<div class="feedbackSubmitted" >Error sending feedback.</div>');
	
}

function lookingForChange(select)
{
	log(' = lookingForChange. select.value = ' + select.value);
	
	if(select.value == 'Other')
	{
		$('#feedbackOtherDiv').removeClass('hidden');
		$('#feedbackOtherText')[0].focus();
	}
	else
	{
		$('#feedbackOtherDiv').addClass('hidden');
				
	}	
}
