//*****************************************************************************
//* @Title: Feedback Panel for EBA Components trials
//* @File: ebafpanel.inc
//* @Author: EBA_DC\awhite
//* @Date: 03/29/2006 14:43:00 PM
//* @Purpose: A mechanism to log and transmit debug and feedback information
//*			  back to EBA
//* @Notes: None
//*****************************************************************************

function EBAFeedbackPanel(objName, EBAProductName, EBAProductVer, SurveyLink)
{
	var objref = this;
	var intervalId;

	this.clearForm = function()
	{
		setTimeout('document.getElementById(\'EBADebugFormDiv\').style.display = \'none\'; document.getElementById(\'EBADebugFormCompleteDiv\').style.display = \'block\';', 1);
	}
	
	this.toggle = function()
	{
		if (this.FeedbackPanelState)
		{
			this.clear();
			this.collapse();			

		} else
		{
			this.clear();					
			this.expand();
		}
		clearTimeout(this.bumpId);
	}

	this.populate = function()
	{
		var CommentsFieldHeight = 105;
		var PanelContents = '<table cellpadding=0 cellspacing=0 width="' + this.DefaultWidth + '" style="margin: 0px; padding: 0px; font-family: Trebuchet MS, Tahoma, Verdana, Arial; font-size: 14px; color: #666666;">';
		PanelContents += '<tr><td style="padding-left: 25px; padding-right: 28px; padding-top: 90px; cursor: default; margin: 0px;" height=150 valign=top>';
		PanelContents += '<div id=EBADebugFormCompleteDiv style="display: none;">Your feedback has been sent.<br><br>Thanks for participating! Feel free to submit more feedback later.<br><br><button style="width: 80px; height: 25px;  margin-top: 15px; cursor: pointer;" onclick="' + objName + '.toggle()">Close</button></div><div id=EBADebugFormDiv>';
		PanelContents += 'Be part of the conversation! Help us build a better solution by sending us your comments and debug data. Send as many and as often as you like!<br><br>All fields are optional.<br><br>';
		if (this.SurveyLink.length > 3)
		{
			PanelContents += 'Also, fill out our optional <a href="' + this.SurveyLink + '" target="_blank"><img src="http://developer.ebusiness-apps.com/images/fpanel/extlink.gif" border=0 width=13 height=7> feedback survey</a> to contribute your thoughts to the process!<br><br>';
			CommentsFieldHeight = 53;
		}

		PanelContents += '<font color=#000000><b>Email:</b></font> <input type="text" maxlength="100" name="Email" style="width:200px; height:18px; margin-bottom:0px;  font-family: Trebuchet MS, Tahoma; font-size: 14px; border: 1px dotted #CCCCCC; color: #333333;"><br><br>';
		PanelContents += '<font color=#000000><b>Comments, suggested features, or bugs encountered:</b></font><br><textarea name="Comments" style="width:250px; height:' + CommentsFieldHeight + 'px; font-family: Trebuchet MS, Tahoma; font-size: 14px; border: 1px dotted #CCCCCC; color: #333333;"></textarea><br>';
		PanelContents += '<input type=Checkbox name="SendDebug" style=" border: 0px solid #666666;" checked> <font color=#000000><b>Send debug information!</b></font> <a href="#" onclick="alert(document.EBADebugForm[\'EBADebugInfoData\'].value)">[View it]</a><br>';
		PanelContents += '<input type=submit name="SubmitForm" value="Submit" style="width: 80px; height: 25px;  margin-top: 15px; cursor: pointer;  border: 1px solid #666666;">&nbsp;';
		PanelContents += '<button style="width: 80px; height: 25px;  margin-top: 15px; cursor: pointer; border: 1px solid #666666;" onclick="' + objName + '.toggle()">Cancel</button>';				
		PanelContents += '</div>';				
		PanelContents += '</td></tr>';
		PanelContents += '</table>';
		PanelContents += '<img src="http://developer.ebusiness-apps.com/images/fpanel/collapsepanel.gif" width=129 height=129 style="position: absolute; top: ' + (parseInt(this.DefaultHeight)-130) + 'px; left: ' + (parseInt(this.DefaultWidth)-130) + 'px;" onclick="' + objName + '.toggle()">';
		

		
		this.feedbackPanel.innerHTML = PanelContents;		
	}
	
	this.clear = function()
	{
		this.feedbackPanel.innerHTML = '&nbsp;';	
	}

	this.collapse = function()
	{
		if (Math.round(this.CurrentWidth) > Math.round(this.CollapseWidth))
		{
			this.CurrentWidth = this.CurrentWidth-((this.CurrentWidth-this.CollapseWidth)/5);
			this.CurrentHeight = this.CurrentHeight-((this.CurrentHeight-this.CollapseHeight)/5);
			this.feedbackPanel.style.width = this.CurrentWidth + 'px';
			this.feedbackPanel.style.height = this.CurrentHeight + 'px';
			this.feedbackPanel.style.opacity = (this.DefaultOpacity+(this.CurrentWidth/this.DefaultWidth)*(1-this.DefaultOpacity));
			this.feedbackPanel.style.filter = 'alpha(opacity=' + ((this.DefaultOpacity+(this.CurrentWidth/this.DefaultWidth)*(1-this.DefaultOpacity))*100) + ')';
			
			this.intervalId = setTimeout(function() {objref.collapse()}, 20);
			
		} else
		{
			clearTimeout(this.intervalId);
			this.feedbackPanel.innerHTML = '<img src="http://developer.ebusiness-apps.com/images/fpanel/expandpanel.gif" style="padding: 0px; margin: 0px; position: absolute; top: 10px; left: 10px;">';
			this.feedbackPanel.onmousedown = function() {objref.toggle()};
			this.FeedbackPanelState = false;

		}
	}
	
	this.expand = function()
	{
		if (Math.round(this.CurrentWidth) < Math.round(this.DefaultWidth))
		{
			this.CurrentWidth = this.CurrentWidth+((this.DefaultWidth-this.CurrentWidth)/5);
			this.CurrentHeight = this.CurrentHeight + ((this.DefaultHeight-this.CurrentHeight)/5);
			this.feedbackPanel.style.width = this.CurrentWidth + 'px';
			this.feedbackPanel.style.height = this.CurrentHeight + 'px';
			this.feedbackPanel.style.opacity = (this.DefaultOpacity+(this.CurrentWidth/this.DefaultWidth)*(1-this.DefaultOpacity));
			this.feedbackPanel.style.filter = 'alpha(opacity=' + ((this.DefaultOpacity+(this.CurrentWidth/this.DefaultWidth)*(1-this.DefaultOpacity))*100) + ')';
			this.intervalId = setTimeout(function() {objref.expand()}, 20);
			
		} else
		{
			clearTimeout(this.intervalId);
			this.FeedbackPanelState = true;
			this.feedbackPanel.onmousedown = '';					
			this.populate();

		}
	}
	
	this.appendDebugInfo = function(DebugString)
	{
		document.EBADebugForm['EBADebugInfoData'].value += '[' + (this.DebugLine++) + '] ' + DebugString + '\n';			
	}
	
	this.checkPermission = function()
	{
		if (!document.EBADebugForm['SendDebug'].checked)
		{
			document.EBADebugForm['EBADebugInfoData'].value = 'Permission to transmit debug not given.';
		}
		
	}
	
	this.appear = function()
	{
		
		if (this.InitOpacity < this.DefaultOpacity)
		{
			this.InitOpacity += 0.05;
			setTimeout(function() {objref.appear()}, 75);
		
		} else
		{
		
			this.InitOpacity = this.DefaultOpacity;
			
			this.bumpId = setTimeout(function() {objref.bump()}, 5000);
		
		}
		
		this.feedbackPanel.style.opacity = this.InitOpacity;
		this.feedbackPanel.style.filter = 'alpha(opacity=' + (this.InitOpacity*100) + ')';	
		
	}
	
	this.bump = function()
	{
	
		if (this.BumpIndex < 100)
		{
			
			this.BumpIndex += 5;
			this.CurrentWidth = ((this.BumpIndex / 100) * this.BumpDistance) + this.CollapseWidth;
			this.CurrentHeight = ((this.BumpIndex / 100) * this.BumpDistance) + this.CollapseHeight;
			
			this.CurrentWidth = this.CollapseWidth+(this.BumpDistance*Math.sin((this.BumpIndex/100)*3.1415927));
			this.CurrentHeight = this.CollapseHeight+(this.BumpDistance*Math.sin((this.BumpIndex/100)*3.1415927));
			this.feedbackPanel.style.width = this.CurrentWidth + 'px';
			this.feedbackPanel.style.height = this.CurrentHeight + 'px';
			this.feedbackPanel.style.opacity = (this.DefaultOpacity+(Math.sin((this.BumpIndex/100)*3.1415927))*(1-this.DefaultOpacity));
			this.feedbackPanel.style.filter = 'alpha(opacity=' + ((this.DefaultOpacity+(Math.sin((this.BumpIndex/100)*3.1415927))*(1-this.DefaultOpacity))*100) + ')';
			
			document.getElementById('eba_expandPanel').style.top = 10 + (Math.sin((this.BumpIndex/100)*3.1415927)*this.BumpDistance)+ 'px';
			document.getElementById('eba_expandPanel').style.left = 10 + (Math.sin((this.BumpIndex/100)*3.1415927)*this.BumpDistance)+ 'px';
			
			if (this.BumpIndex < 100)
			{
				this.bumpId = setTimeout(function() {objref.bump()}, 20);
			} else { this.BumpIndex = 0; this.bumpId = setTimeout(function() {objref.bump()}, 45000);}
		
		} 

	}
	
	var PanelDiv = '<iframe frameborder=0 id=EBAFormPostIframe name=EBAFormPostIframe style="width:1px; height: 1px; position: absolute; top: 1px; left: 1px; padding: 0px;"></iframe><img src="http://developer.ebusiness-apps.com/images/fpanel/panelback.gif" width=1 height=1 style="position: absolute; top:0px; left:0px;"><img id="eba_collapsePanel" src="http://developer.ebusiness-apps.com/images/fpanel/collapsepanel.gif" width=1 height=1 style="position: absolute; top:1px; left:1px;"><form method=post onsubmit="' + objName + '.checkPermission(); ' + objName + '.clearForm(); " action="http://labs.ebusiness-apps.com/ebafeedback/feedbacksubmit.asp" target="EBAFormPostIframe" id=EBADebugForm name=EBADebugForm style="margin: 0px; padding: 0px;"><input type=hidden name=EBADebugInfoData value=""><div id=\'EBAFeedbackPanelDiv\' onmousedown=\'' + objName + '.toggle()\' style="z-index: 5000; background-image: url(\'http://developer.ebusiness-apps.com/images/fpanel/panelback.gif\');  background-position: bottom right; width: 140px; height: 140px; position: absolute; top: 0px; left: 1px; cursor: pointer; font-family: Trebuchet MS, Tahoma, Verdana, Arial; font-size: 14px; color: #666666; margin: 0px; padding: 0px;"><img id="eba_expandPanel" src="http://developer.ebusiness-apps.com/images/fpanel/expandpanel.gif" style="padding: 0px; position: absolute; top: 10px; left: 10px; margin: 0px;"></div></form>';
	this.feedbackContainer = document.createElement('div');
	this.feedbackContainer.innerHTML = PanelDiv;
	this.feedbackContainer.setAttribute('id', 'EBAFeedbackContainerDiv');
	this.feedbackContainer.object = this;
	document.getElementsByTagName('body').item(0).appendChild(this.feedbackContainer);
	
	this.feedbackPanel = document.getElementById('EBAFeedbackPanelDiv');
	
	this.FeedbackPanelState = false;
	this.DefaultWidth = 434;
	this.DefaultHeight = 473;
	this.CollapseWidth = 140;
	this.CollapseHeight = 140;	
	this.CurrentWidth = 140;
	this.CurrentHeight = 140;
	this.DefaultOpacity = 0.9;
	this.InitOpacity = 0.0;
	this.SurveyLink = SurveyLink;
	this.PanelVersion = 1.01;
	this.DebugLine = 0;
	this.BumpIndex = 0;
	this.BumpDistance = 40;	

	this.feedbackPanel.style.opacity = this.InitOpacity;
	this.feedbackPanel.style.filter = 'alpha(opacity=' + (this.InitOpacity*100) + ')';			

	this.appendDebugInfo('Product Name: ' + EBAProductName);
	this.appendDebugInfo('Product Version: ' + EBAProductVer);
	this.appendDebugInfo('Current URL: ' + window.location.href);
	this.appendDebugInfo('appCodeName: ' + navigator.appCodeName);
	this.appendDebugInfo('appName: ' + navigator.appName);
	this.appendDebugInfo('appMinorVersion : ' + navigator.appMinorVersion );
	this.appendDebugInfo('appVersion : ' + navigator.appVersion );
	this.appendDebugInfo('cookieEnabled : ' + navigator.cookieEnabled );
	this.appendDebugInfo('platform  : ' + navigator.platform  );
	this.appendDebugInfo('cpuClass  : ' + navigator.cpuClass  );			
	this.appendDebugInfo('userAgent   : ' + navigator.userAgent   );
	
	setTimeout(function() {objref.appear()}, 10);
}
