// *********************************************************************
// * feedbackInterceptor.js
// *
// * Copyright 2008 CCH, a Wolters Kluwer business
// *********************************************************************
function FeedbackInterceptor( )
{
	this.author = "";
	this.comment = "";
	this.id = "";
	this.rating = "";
	this.title = "";
	this.request = null; // Not that we'll use this for much.
}
FeedbackInterceptor.prototype.createParameterString = function( )
{
	return "author=" +
		encodeURIComponent(this.author) +
		"&comment=" +
		encodeURIComponent(this.comment) +
		"&solutionId=" +
		encodeURIComponent(this.id) +
		"&rating=" +
		encodeURIComponent(this.rating) +
		"&title=" +
		encodeURIComponent(this.title);
}
FeedbackInterceptor.prototype.getAuthor = function( )
{
	if (window.solutionOwner)
	{
		this.author = window.solutionOwner;
	}
	else if (window.solutionAuthor)
	{
		this.author = window.solutionAuthor;
	}
}
FeedbackInterceptor.prototype.getComment = function( )
{
	if (document.feedbackForm)
	{
		if (document.feedbackForm.comments)
		{
			this.comment = document.feedbackForm.comments.value;
		}
	}
}
FeedbackInterceptor.prototype.getId = function( )
{
	if (window.solutionId)
	{
		this.id = window.solutionId;
	}
}
FeedbackInterceptor.prototype.getParameters = function( )
{
	this.getAuthor();
	this.getComment();
	this.getId();
	this.getRating();
	this.getTitle();
}
FeedbackInterceptor.prototype.getRating = function( )
{
	var rad = document.getElementById("radVisitHelpfulYes");
	if (rad)
	{
		if (rad.checked)
		{
			this.rating = "5";
			return;
		}
	}
	rad = document.getElementById("radVisitHelpfulNo");
	if (rad)
	{
		if (rad.checked)
		{
			this.rating = "1";
			return;
		}
	}
	this.rating = 0;
}
FeedbackInterceptor.prototype.getTitle = function( )
{
	var kbTitle = document.getElementById("kbTitle");
	if (kbTitle)
	{
		if (kbTitle.textContent)
		{
			this.title = kbTitle.textContent;
		}
		else if (kbTitle.innerText)
		{
			this.title = kbTitle.innerText;
		}
	}
}
FeedbackInterceptor.prototype.startRequest = function( )
{
	if (this.request != null)
	{
		this.request.abort();
	}
	if (window.XMLHttpRequest)
	{
		this.request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		this.request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return;
	}
	this.getParameters();
	var paramString = this.createParameterString();
	this.request.onreadystatechange = function() {return true;}
	this.request.open("POST", "/mail/authorMail.aspx", true);
	this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.request.setRequestHeader("Content-length", paramString.length);
	this.request.setRequestHeader("Connection", "close");
	this.request.send(paramString);
}
function InterceptFeedback( )
{
	var interceptor = new FeedbackInterceptor();
	interceptor.startRequest();
}
function SetIntercept( )
{
	var feedbackForm = document.feedbackForm;
	if (feedbackForm)
	{
		EventAttacher(feedbackForm, "submit", InterceptFeedback);
	}
}
EventAttacher(window, "load", SetIntercept);