var popupHTML = '<ul id="feedbackPopupForm" class="formItems" ><li><div class="inputLabel" >What were you looking for today?<span class="requiredAsterix" >*</span></div><div class="inputDiv" ><select id="feedbackLookingFor" name="feedbackLookingFor" class="inputField inputFieldSelect {mandatory: true}" onchange="lookingForChange(this)" ><option value="" ></option><option value="Pensions" >Pensions</option><option value="Investment" >Investment</option><option value="Savings" >Savings</option><option value="Life Cover" >Life Cover</option><option value="Income Protection / Illness Cover" >Income Protection / Illness Cover</option><option value="Financial Review" >Financial Review</option><option value="Fund Prices / Performance" >Fund Prices / Performance</option><option value="Information on my plan" >Information on my plan</option><option value="Service Forms" >Service Forms</option><option value="How to Make a Complaint" >How to Make a Complaint</option><option value="Other" >Other - Specify:</option></select><div id="feedbackOtherDiv" class="hidden" ><textarea id="feedbackOtherText" name="feedbackOtherText" class="inputField inputFieldTextarea {mandatory: true, validation: [[\'alphanumericAll\']], maxlength: 1000}" ></textarea></div><div class="inputError" id="feedbackLookingForError" ></div><div class="inputError" id="feedbackOtherTextError" ></div></div></li><li><label for="feedbackMissing" >What was missing?<span class="requiredAsterix" >*</span></label><br /><textarea id="feedbackMissing" name="feedbackMissing" class="inputField inputFieldTextarea {mandatory: true, validation: [[\'alphanumericAll\']], maxlength: 1000}" ></textarea><div class="inputError" id="feedbackMissingError" ></div></li><li><label for="feedbackSuggestions" >Do you have any suggestions for our website?<span class="requiredAsterix" >*</span></label><br /><textarea id="feedbackSuggestions" name="feedbackSuggestions" class="inputField inputFieldTextarea {mandatory: true, validation: [[\'alphanumericAll\']], maxlength: 1000}" ></textarea><div class="inputError" id="feedbackSuggestionsError" ></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: [[\'email\']]}" ></input><div class="inputError" id="feedbackEmailError" ></div></li></ul>';

function popup()
{
	log(' = popup');

	var statesdemo = 
	{
		state0: {
			html: popupHTML,
			opacity: 0.4,
			useiframe: true,
			overlayspeed: 'fast', 			
			buttons:{Cancel: false, OK: true}, 
			loaded: function(){$('#feedbackLookingFor')[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($('#feedbackPopupForm')[0]))
		{
			log(' - validateForm = true');
						
			parms = 'form_id=popupFeedback' +
					'&feedbackLookingFor=' + $('#feedbackLookingFor').val() +
					'&feedbackOtherText=' + $('#feedbackOtherText').val() +
					'&feedbackMissing=' + $('#feedbackMissing').val() +
					'&feedbackSuggestions=' + $("#feedbackSuggestions").val() + 
					'&feedbackEmail=' + $("#feedbackEmail").val();
			
			$.ajax({
				type: 'POST',
				url: '/servlet/submitPopupFeedbackForm.do',
				async: true,
				data: parms,
				beforeSend: beforeAjax,
				success: successAjax,
				error: errorAjax,
				timeout: 300000
			});
		}

		return false;
	}
	else
	{
		return true;
	}
}

function beforeAjax()
{
	log('beforeAjax');
	
	$.prompt.goToState('state1');
}

function successAjax(response)
{
	log('successAjax');
	
	$('.jqimessage').html('<div class="feedbackSubmitted" >Feedback sent. Thank you.</div>');
	
}

function errorAjax()
{
	log('errorAjax');
	
	$('.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');
				
	}	
}
