$(function() {
	
	$('a.printvoucher').click(function() {
		var $this = $(this);
		var tncClass = $this.parents('div.item').attr('class').replace('item ', '');
		
		var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" href="../../inc/printvoucher.css" type="text/css" media="screen,print" /></head><body>';
		html +=  '<div class="item">' + $this.parents('div.item').html() + '</div>'; //voucher html
		html += '<div class="terms">' + $('.vouchers-tnc .maintnc').html() + '</div>'; //main tnc html
		
		if (tncClass!='item') {
			html += '<div class="terms">' + $('.vouchers-tnc .'+tncClass).html() + '</div>'; //specific tnc html
		}
		
		html += '<div class="promoter">' + $('.promoter').html() + '</div>'; //promoter html
		html += '</body></html>';
		
		var printSingleVoucher = window.open('', 'printVoucher');
		printSingleVoucher.document.open();
		printSingleVoucher.document.write(html);
		printSingleVoucher.document.close();
		
		printSingleVoucher.print();
	});
	
	$('a.printallvouchers').click(function() {
		var html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" href="../../inc/printvoucher.css" type="text/css" media="screen,print" /></head><body>';
		html += $('div.item').parent().html();
		html += '</body></html>';
		
		var printAllVoucher = window.open('', 'printVoucher');
		printAllVoucher.document.open();
		printAllVoucher.document.write(html);
		printAllVoucher.document.close();
		
		printAllVoucher.print();
	});
});
