// JavaScript Document
function load_sugbox(str)
{
			   $.ajax({
						  type: "GET",
						  url: str,
						  cache: false,
						  beforeSend: 		function () {	 showMyBox('#ajaxLoading');		}			,
						  success: function(res){		disableMyBox('#ajaxLoading');if(!check_sug(res)){$('#ajaxSugBoxData').html(res);setup_sug_submit();showMyBox('#ajaxSugBox');}		}		,
						  error:  function() { disableMyBox('#ajaxLoading'); alert("Suggestions not available."); } 
				});
}

function check_survey_fill(ajax)
{
	 if (savePeriod(document.surveyfillform))
	 {
			$('#surveyfillform').ajaxSubmit(function (res){check_sug(res);});
     }
}

function check_sug(res)
{
	res = res.replace(/\s+/g,'');
	if (res == 'true')
	{
			alert("Thank you! Your suggestion has been submitted.");
			disableAllMyBoxes();
			return true;
	}
	if (res == 'antibot')
	{
		alert( "Please enter the correct text below !");
		change_antibot_image('on_surveys_' + $('input[name=surveyid]').val()); 
		$('input[name=antibot_input_str]').val('');
		return true;
	}
	else if (res == 'error')
	{
		alert ("Suggestions not available at this time.");
		disableAllMyBoxes();
		return true;
	}
	else if (res == 'voted')
	{
		alert ("You have already submitted a suggestion!");
		disableAllMyBoxes();
		return true;
	}
	return false;
}


function setup_sug_submit()
{
	$sff = $('#surveyfillform');
	if ($sff.length) $sff.append('<input type="hidden" name="ajax" value="1" />').submit(function(){return false;});
}

