// Feedback functions
// ----------------------------------------------
showFeedback = function(actionContainerID, message)
{
	if (message==null)
		{
		message = "Verifying";
		}
		
	var div = document.createElement("div");
	//div.className = "feedback-processing";
	div.className = "in-progress";
	//div.innerHTML = "Verifying&#8230;";
	div.id = "submitFeedback";
	div.style.display = "none";
	
	var imgProc = document.createElement("img")
	imgProc.src = "/images/operations-handling/indicators/in-progress.gif";
	imgProc.alt = "";
	imgProc.id = "processorImage";
	imgProc.className = "indicator";
	
	var divProc = document.createElement("div")
	divProc.className = "indicator";
	
	divProc.appendChild(imgProc)
	
	var spnText = document.createElement("span")
	spnText.id = "plain-text-message";
	spnText.innerHTML = message + "&#8230;";
	
	div.appendChild(divProc)
	div.appendChild(spnText)
	
//	                <img src="../images/operations-handling/indicators/complete.gif" class="indicator" alt="" />
//                <span class="plain-text-message">Thank you. Your message has been sent.</span>
	
	//alert(actionContainerID);
	$(actionContainerID).appendChild(div);
	
	var buttons;
	switch (BrowserDetect.browser)
	{
		case "Safari":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		case "Opera":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		case "Firefox":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		default:
			buttons = $(actionContainerID).childNodes[0].id
		break
	}
	
	Effect.Fade(buttons,
	{
		duration: 0.4,
		afterFinish:function()
		{
			Effect.Appear('submitFeedback',
			{
				duration: 0.4
			});
		}
	});
}

updateFeedbackMessage = function(message)
{
	$("plain-text-message").innerHTML = message + "&#8230;";
}

setFeedbackComplete = function(message)
{
	$("submitFeedback").className = 'process-complete';
	$("processorImage").src = "/eigcom/images/operations-handling/indicators/complete.gif";
	$("plain-text-message").innerHTML = message;
}

setFeedbackFailed = function()
{
	$("submitFeedback").className = 'in-progress error';
	$("processorImage").src = "/eigcom/images/operations-handling/indicators/complete.gif";
	//$("plain-text-message").innerHTML = 'Failed';
	
	window.setTimeout("scrollToError()",2005);
	
}

scrollToError = function()
{
var errs = document.getElementsByTagName("input")
	
	for (var i = 0;i<errs.length;i++)
		{
			if (errs[i].type=="text")
				{
			
				if (errs[i].className=="textfield error")
					{
					
					new Effect.ScrollTo(errs[i]);
					break;
					}	
				}
			
		}
}

restoreButtons = function(actionContainerID)
{
	//hide processor feedback and restore buttons
	var buttons;
	switch (BrowserDetect.browser)
	{
		case "Safari":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		case "Firefox":
			buttons = $(actionContainerID).childNodes[1].id
		break
		
		default:
			buttons = $(actionContainerID).childNodes[0].id
		break
	}
	Effect.Fade('submitFeedback',
	{
		duration: 0.4,
		afterFinish:function()
		{
			Effect.Appear(buttons,
			{
				duration: 0.4
			});
			
		}
	});
	
	window.setTimeout(function()
	{
		removeFeedback(actionContainerID)
	},1600);
}

removeFeedback = function(selectorID)
{
	var ac = $(selectorID);
	var sf = $("submitFeedback");
	ac.removeChild(sf);
}
				
cleanupFeedback = function(selectorID)
{
	window.setTimeout(function()
	{
		cleanupFeedbackInner(selectorID)
	},1000);	
}

cleanupFeedbackInner = function(selectorID)
{
	removeFeedback(selectorID);
	var selectorChildID;

	switch (BrowserDetect.browser)
	{
		case "Safari":
			selectorChildID = $(selectorID).childNodes[1].id
		break
		
		case "Firefox":
			selectorChildID = $(selectorID).childNodes[1].id
		break
		
		default:
			selectorChildID = $(selectorID).childNodes[0].id
		break
	}
	
	Effect.Appear(selectorChildID,
	{
		duration: 0
	});
}

feedbackValid = function(message1, message2)
{
	window.setTimeout(function(){updateFeedbackMessage(message1)}, 2000);
	window.setTimeout(function(){setFeedbackComplete(message2)}, 3000);
}

feedbackInvalid = function(buttonContainerID)
{
	window.setTimeout(function(){setFeedbackFailed()}, 1000);			
	window.setTimeout(function(){restoreButtons(buttonContainerID)}, 2000);
}