﻿function selectSurvey(event) 
{
	event.preventDefault;
	var IDSurvey = $j(event.currentTarget).attr('rel');
	showSurvey(IDSurvey);
}


function showSurvey(IDSurvey) 
{
	$j('#SurveyDiv').remove();

	var surveyDiv = $j('<div>', { id: 'SurveyDiv' })
	.load('/surveys/survey.aspx?IDSurvey=' + IDSurvey)
	.dialog({
		title: 'Survey',
		modal: true,
		width:700,
		buttons: {
			Close: function () { surveyDiv.remove() },
			Submit: submitSurvey
		},
		close: function () { surveyDiv.remove() }
	})
}


function submitSurvey() 
{
	$j.post(
		'/surveys/surveys_xhr.aspx',
		$j('#SurveyForm').serialize(),
		surveySubmitted
	);
}


function surveySubmitted(Data)
{
	if (Data.Success) 
	{
		$j('#LoginWelcome').remove();
		if (window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1) == 'logout.aspx')
			document.location = '/collections';
	}
}


function closeSurvey() {

}
