var surv=
{
	curr: null,
	next: function()
	{
		var n=surv.curr.next('.page');
		if( n.length)
		{	surv.curr.fadeOut('fast',function()
			{	surv.curr = n;
				n.fadeIn('fast');
			});
		}

	},
	setImg:function(im)
	{
		$('#survey #imgResult img').attr('src',im);
	}
};
function mySurveyDomReady()
{
	// Survey popup
	$('.surveyLink').click(function(){
		RQDebug('Survey popup click');
		var pp=$("#survey");
		pp.find('.isChecked').removeClass('isChecked').find('.boxOn').removeClass('boxOn');
		var pgs =pp.find('.page');
		pgs.hide();
		surv.curr =pgs.first();
		surv.curr.show()
		pp.fadeIn('slow');
	});


	$('#survey .btnClose, #survey .btnSurveyClose').click(function() {$("#survey").fadeOut('fast').hide();} );

	$('#survey .box').mousedown(function(){
		if( !$(this).is('.boxOn'))
		{	$(this).siblings('.boxOn').removeClass('boxOn');
			$(this).addClass('boxOn');
			$(this).parents('.Q').addClass('isChecked').attr('id',"q"+$(this).attr('id'));
		}
	});
	
	$('.btnSurveyPage').click(function()
	{	if( surv.curr)
		{	var qs = surv.curr.find('.Q');
			if( qs.length && qs.not('.isChecked').length)
				alert("Please make sure you checked one box per question. ");
			else
			{
				if( $(this).is(".btnSurveySubmit"))
				{	// make a list of the answers and send it to the survey
					var qs="";
					$('#survey .Q').each(function(index){
						qs+=(qs?"|":"")+$(this).attr('id');
					});
					var vars ="action=newSurveyReport&id="+$('#survey').attr('className')+"&reps="+qs;
					RQAjaxCallPlugin('ListSurveys',vars,function(m,e){
						if( !e) eval(m);
						surv.next();
					})
				}
				else
					surv.next();

			}
		
		}
	});
}
