// *********************************************************************
// * feedbackForm.js
// *********************************************************************
function siCommentFocus( )
{
	var txtComments = document.getElementById("siFeedbackComments");
	if (txtComments)
	{
		if (txtComments.className == "siFeedbackGrey")
		{
			txtComments.className = "siFeedbackBlack";
			txtComments.value = "";
			var siFeedbackSubmit = document.getElementById("siFeedbackSubmit");
			if (siFeedbackSubmit)
			{
				siFeedbackSubmit.disabled = false;
			}
		}
	}
}

function siCommentBlur( )
{
	var txtComments = document.getElementById("siFeedbackComments");
	if (txtComments)
	{
		if (txtComments.value == "")
		{
			txtComments.className = "siFeedbackGrey";
			txtComments.value = "Please enter your ideas and feedback and click submit";
			var siFeedbackSubmit = document.getElementById("siFeedbackSubmit");
			if (siFeedbackSubmit)
			{
				siFeedbackSubmit.disabled = true;
			}
		}
	}
}

function siSubmitFeedback( )
{
	if (window.siFeedbackSent)
	{
		return;
	}
	var formArea = document.getElementById("siFeedbackAreaForm");
	if (!formArea)
	{
		return;
	}
	var thanksArea = document.getElementById("siFeedbackAreaThanks");
	if (!thanksArea)
	{
		return;
	}
	formArea.className = "siHidden";
	thanksArea.className = "siVisible";
	var titleArea = document.getElementById("siFeedbackTitle");
	if (titleArea)
	{
		titleArea.className = "siHidden";
	}
	var ajaxRequest = null;
	if (window.XMLHttpRequest)
	{
		ajaxRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		var siFeedbackForm = document.getElementById("siFeedbackForm");
		siFeedbackForm.submit();
		return;
	}
	var txtComments = document.getElementById("siFeedbackComments");
	if (!txtComments)
	{
		alert("Could not find the comments control.");
		return;
	}
	var hdnUrl = document.getElementById("siFeedbackUrl");
	if (!hdnUrl)
	{
		alert("Could not find the URL control.");
		return;
	}
	var paramString = "comment=" + encodeURIComponent(txtComments.value) + "&url=" + encodeURIComponent(hdnUrl.value)
	ajaxRequest.onreadystatechange = function() {return true;}
	ajaxRequest.open("POST", "/mail/feedbackHandler.aspx", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", paramString.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(paramString);
	window.siFeedbackSent = true;
}
window.siFeedbackSent = false;
// *********************************************************************
// * Disclaimer Support
// *********************************************************************
function siDisclaimerDisplay( )
{
	var el = document.getElementById("siDisclaimerExcerpt");
	if (el)
	{
		el.className = "siHidden";
	}

	el = document.getElementById("siDisclaimerText");
	if (el)
	{
		el.className = "siVisible";
	}
}
function siDisclaimerHide( )
{
	var el = document.getElementById("siDisclaimerExcerpt");
	if (el)
	{
		el.className = "siVisible";
	}

	el = document.getElementById("siDisclaimerText");
	if (el)
	{
		el.className = "siHidden";
	}
}

// *********************************************************************
// * New Feedback Functionality
// *********************************************************************
function FeedbackFormObject( )
{
	if (window[this.winId])
	{
		return window[this.winId];
	}
	this.feedbackForm = null;
	window[this.winId] = this;
	this.allowAnimation = true;
	this.formDisplayed = false;
}
// **********
// * Internal Properties
// **********
FeedbackFormObject.prototype.elementId = "siFeedbackAreaForm";
FeedbackFormObject.prototype.winId = "siFeedbackFormObject";
// **********
// * Class Methods
// **********
FeedbackFormObject.prototype.getElement = function( )
{
	this.feedbackForm = document.getElementById(this.elementId);
};
FeedbackFormObject.prototype.showForm = function( )
{
	if (this.allowAnimation)
	{
		var animObj = new YAHOO.util.Anim("siFeedbackAreaForm", {width: {to: 275}, height: {to: 49}},0.3);
		animObj.animate();
		this.formDisplayed = true;
	}
};
FeedbackFormObject.prototype.hideForm = function( )
{
	if (this.allowAnimation)
	{
		var animObj = new YAHOO.util.Anim("siFeedbackAreaForm", {width: {to: 0}, height: {to: 0}},0.3);
		animObj.animate();
		this.formDisplayed = false;
	}
}
FeedbackFormObject.prototype.toggleForm = function( )
{
	if (this.formDisplayed)
	{
		this.hideForm();
	}
	else
	{
		this.showForm();
	}
}
// *********************************************************************
// * Feedback Submission
// *********************************************************************
function siSubmitFeedbackAction(url, comment)
{
	var paramString = "comment=" + encodeURIComponent(comment) +
		"&url=" + encodeURIComponent(url);
	
	var ajaxRequest = null;
	if (window.XMLHttpRequest)
	{
		ajaxRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		// Nothing that we can do.  Your browser does not
		// support AJAX.
		return;
	}
	
	ajaxRequest.onreadystatechange = function() {return true;};
	ajaxRequest.open("POST", "/mail/feedbackHandler.aspx", true);
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Content-length", paramString.length);
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(paramString);
}