//Function to open pop up window
var mywindow = '';
function openWinLeft(theURL,winName,features,w,h) 
{			
	var winl = (screen.width-w);
	var wint = (screen.height-h)/2;
	var feature_addon = ",width="+w+",height="+h+",left="+winl +",top="+wint;
	features += feature_addon;
	
	if (!mywindow.closed && mywindow.location) 
	{
		mywindow.location.href = theURL;
	}
	else 
	{
		mywindow = window.open(theURL,winName,features);
		
		if (!mywindow.opener) mywindow.opener = self;
	}
	if (window.focus) {mywindow.focus()}
	return false;																											
}

function drawHelp(ID,imgsrc)
{
	var type = imgsrc;
	if (imgsrc == 'starburst') {
		imgsrc = "http://help.talmax.com/images/help_starburst.gif";
	}
	imgsrc = imgsrc || "http://help.talmax.com/images/help_icon.gif";
	var help_icon = document.createElement('img');
	document.write("<img src=\""+imgsrc+"\" align=\"absmiddle\" onMouseOver=\"TagToTip('help_span_"+ID+"',FADEIN, 500, OPACITY,90,WIDTH,200);\" onClick=\"openWinLeft('http://help.talmax.com/help_popup/disp_help.php?help_id="+ID+"','Help','status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1',338,screen.height);\" />");
	document.write("<span id=\"help_span_"+ID+"\" style=\"display:none;\">");
	document.write("</span>");
	
	url = "/help/get_help.php?help_id="+ID+"&type="+type;
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(response) {	
		var response = response.responseText;
		var data = response.evalJSON();		
		var span = $('help_span_' + ID);
		Element.update(span,data.tool_tip);		
	  }
	});
}

function drawHelpContents()
{
	url = "/help/get_help_contents.php";
	document.write("<style>");
	document.write("#help_contents td p{ margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px;}");
	document.write("</style>");
	document.write("<table width=\"100%\" id=\"help_contents\" border=\"0\">");
	document.write("</table>");
	
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(response) {		
		response = response.responseText;
		var data = response.evalJSON();		
				
		for (i=0;i<data.articles.length;i++)
		{
			new Insertion.Bottom("help_contents", "<tr><td colspan=\"2\"><b>"+data.articles[i].title+"</b></td></tr>");
			new Insertion.Bottom("help_contents", "<tr><td>&nbsp;</td><td><a href=\"javascript:;\" onClick=\"openWinLeft('http:/help.talmax.comhelp_popup/disp_help.php?help_id="+data.articles[i].ID+"','Help','status=0,toolbar=0,location=0,menubar=0,directories=0',328,screen.height);\" >"+data.articles[i].desc+"</a></td></tr>");
		}
	  }
	});
}
function drawHelpContents2()
{
	url = "/help/get_help_contents.php";
	document.write("<style>");
	document.write("#help_contents2 td p{ margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px;}");
	document.write("#help_articles td p{ margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px;}");	
	document.write("</style>");
	document.write("<table width=\"100%\" id=\"help_contents2\" border=\"0\"></table>");
	document.write("<div id=\"help_answer\" />");
	
	new Ajax.Request(url, {
	  method: 'get',
	  onLoading : function(){ new Insertion.Bottom("help_contents2",'<tr><td colspan="2"><p id="truhelp_loader"><img src="http:/help.talmax.com/images/ajax-loader.gif"> Loading...</p></td></tr>')},
	  onSuccess: function(response) {		
		response = response.responseText;
		var data = response.evalJSON();	
		
		$('truhelp_loader').style.display = 'none';
				
		for (i=0;i<data.articles.length;i++)
		{
			new Insertion.Bottom("help_contents2", "<tr><td style=\"width:20px;\">"+ (i+1) +") </td><td><a href=\"javascript:;\" onClick=\"getarticle("+data.articles[i].ID+")\">"+data.articles[i].title+"</a></td></tr>");			
		}
		
	  }
	});
}
function getarticle(ID)
{
	url = "/help/get_article.php?help_id="+ID;
	
	new Ajax.Request(url, {
	  method: 'get',
	  onLoading : function(){ new Insertion.Bottom("help_answer",'<p id="truhelp_loader"><img src="http:/help.talmax.com/images/ajax-loader.gif"> Loading...</p>')},
	  onSuccess: function(response) {		
		response = response.responseText;
		var data = response.evalJSON();	
		$('truhelp_loader').style.display = 'none';		
		var div = $('help_answer');
		Element.update(div,data.article);	
		
	  }
	});
}
Event.observe(window, 'load', function() {
  tt_Init();
});
