/*
The XSL template using this code should have the following HTML tag in it. 

<div id="poll" name="poll" pagelet="pagelet_survey" onload="ksSetupVoting('poll', 'pagelet_survey');"></div>

The <div/> is the container that will house the pagelet.  The innerHTML of the <div/> will be filled using an AJAX call to ws_display.asp.

Required attributes:
	@id or @name:  code will use this to identify the <div/> to append the resulting pagelet HTML.
	@pagelet:  the name of the page in NetMaverick that will generate the pagelet HTML.
	
Optional attributes:
	@onload:  when the AJAX call is complete, whatever is in the onload will be called.
*/
$JQ(document).ready(function() {
	$JQ('div[pagelet]').each(function(index) {
		ksGetPagelet($JQ(this).attr('id'), $JQ(this).attr('pagelet'), $JQ(this).attr('onload'));
	});
});
function ksGetPagelet(pageletContainer, pagelet, onload) {
	$JQ.ajax({
		url: 'ws_display.asp?filter='+pagelet,
		type: 'GET',
		dataType: 'html',
		async: false,
		error: function() {
			$JQ('#'+pageletContainer).html('<span style="display:inline-block;color:#ff0000;font-style:italic;border:1px dotted #ff0000;padding:4px;">Error: Communication timeout for pagelet "' + pagelet + '". Please try again later!</span>');
		},
		success: function(msg){
			$JQ('#'+pageletContainer).html(msg);
		},
		complete: function() {
			if (onload != null) {
				eval(onload);
			}		
		}
	});	
}
