/**
 * @author Fabien
 */

/**
 * Survey
 */
var zResult;
	
function validateSurvey()
{
	var sId = $F('surveyId');
	var aAnswers = [];
	$$('#surveyDiv input').each(function(inp) {
		if(inp.checked) {
			aAnswers.push(inp.value);
		}
	});
	if (aAnswers.length < 1) {
		alert("Please select an answer...");
	}
	else {
		$('submitSurveyArea').update('<img src="/Assets/wait16trans.gif" />');
		
		new Ajax.Request("http://www.mba-exchange.com/Ajax/HomeSurvey.php", {
			parameters: {
				request: $H({
					method: 'submitAnswer',
					params: [sId, aAnswers]
				}).toJSON()
			},
			onSuccess: function(r) {
				if (r.responseJSON.success) {
					$('submitSurveyArea').update("Thank you, you can see the current results above.");
					
					$H(r.responseJSON.data).each(function(pair) {
						$('answer_' + pair.key).insert({
							top: new Element('span').addClassName('percent').update(pair.value.percent)
						});
						$('progressBar_' + pair.key).setStyle({
							width: pair.value.percent
						});
						$('progressBar_' + pair.key).show();
					});
				}
			}
		});
	}
}



/**
 * Slide Teaser
 */
var actualTeaser = 1;

var autoWay = 'forward';
var intervalLoop = null;

function moveBackward(stopAutoloop)
{
	if((intervalLoop != null) && (stopAutoloop)) {
		intervalLoop.stop();
	}
	if (actualTeaser > 1) {
		new Effect.Move('tblTeasersContainer', {
			x: 468,
			y: 0,
			mode: 'relative',
			duration: .5
		});
		actualTeaser--;
	}
	return false;
}
function moveForward(stopAutoloop)
{
	if((intervalLoop != null) && (stopAutoloop)) {
		intervalLoop.stop();
	}
	if (actualTeaser < nbTeasers) {
		new Effect.Move('tblTeasersContainer', {
			x: -468,
			y: 0,
			mode: 'relative',
			duration: .5
		});
		actualTeaser++;
	}
	return false;
}
function moveTeaser(t)
{
	if(intervalLoop != null) {
		intervalLoop.stop();
	}
	var delta = (actualTeaser-t);
	new Effect.Move('tblTeasersContainer', {
		x: (468*delta),
		y: 0,
		mode: 'relative'
	});
	actualTeaser = t;
	return false;
}

function autoSlideTeaser()
{
	if (autoWay == 'forward') {
		if (actualTeaser == nbTeasers) {
			autoWay = 'backward';
			moveBackward();
		}
		else {
			moveForward();
		}
	}
	else {
		if(autoWay == 'backward') {
			if(actualTeaser == 1) {
				autoWay = 'forward';
				moveForward();
			}
			else {
				moveBackward();
			}
		}
	}
}


/**
 * Online Sessions
 */
function clearEmail(id)
{
	if($('email_'+id).value == 'email address') {
		$('email_'+id).value = '';
	}
}


/**
 * Featured Cpy
 */
function moveSlider(container)
{
	var moveTo = (-1) * (parseInt($(container).getWidth())/2);
	var actualPosLeft = $(container).style.left.substr(0, ($(container).style.left.length-2));
	
	if (actualPosLeft > moveTo) {
		$(container).setStyle({
			left: (actualPosLeft - 2) + 'px'
		});
		window.setTimeout(function() {
			moveSlider(container);
		}, 50);
	}
	else {
		$(container).setStyle({
			left: '0px'
		});
		moveSlider(container);
	}
}



/**
 * Login Top
 */
function clearLogEmail()
{
	if($('sLogEmail').value == 'Email') {
		$('sLogEmail').value = '';
	}
}

function clearLogPassword()
{
	if($('sLogPass').value == 'Password') {
		$('sLogPass').value = '';
	}
}

