YAHOO.namespace('squarecompare');

YAHOO.squarecompare.initOnlineRemoteDesktopDataTable = function(options) {

	var fields = [
	    {
	    	name: 'OnlineRemoteDesktopProductId',
	    	internal: true
	    },
	    {
	    	name: 'MerchantSiteId',
	    	internal: true
	    },
	    {
	    	name: 'ContractMonths',
	    	internal: true
	    },
	    {
	    	name: 'MerchantSiteListingTypeId',
	    	internal: true
	    },
	    {
	    	name: 'EnhancedListingScore',
	    	internal: true
	    },
	    {
	    	name: 'FeePerClickTypeId',
	    	internal: true
	    },
	  	{
	   		name: 'Flagged',
	   		title: '<img src="/ext/silk/icons/flag_yellow.png" width="12" height="12">',
	   		width: 12,
	   		sortable: false,
	  		sizable: false,
	  		formatter: 'flagged'
	   	},
	    {
	   		name: 'MerchantSiteName',
	   		title: 'Company',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'merchantSiteName'
	   	},
	    {
	   		name: 'PlanName',
	   		title: 'Plan',
	   		group: 'basic',
	   		sortable: true,
	  		sizable: true,
	  		maxLength: 18,
	  		formatter: 'text'
	   	},
	 	{
	 		name: 'MonthlyFee',
	 		title: 'Monthly',
	   		group: 'basic',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'monthlyFee'
	 	},
	 	{
	 		name: 'SetupFee',
	 		title: 'Setup',
	   		group: 'basic',
	 		numberDecimals: 0,
	 		numberPrefix: '$',
	 		numberSuffix: '',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'number'
	 	},
	 	{
	 		name: 'FreeTypeName',
	 		title: 'Trial',
	   		group: 'feature-a',
	   		sortable: true,
	  		sizable: true
	 	},
	 	{
	 		name: 'ComputerCount',
	 		title: 'Computers',
	   		group: 'feature-a',
	 		numberDecimals: 0,
	 		numberPrefix: '',
	 		numberSuffix: '',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'number',
	  		magicValues: {
	   			999999: 'Unlimited|Be sure to check the fine print to determine if restrictions apply to this <i>Unlimited</i> value.'
	   		}
	 	},
	 	{
	 		name: 'FileTransfer',
	 		title: 'File Transfer',
	   		group: 'feature-a',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'FileSynchronization',
	 		title: 'File Synchronization',
	   		group: 'feature-a',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'RemoteSound',
	 		title: 'Remote Sound',
	   		group: 'feature-b',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'RemotePrinting',
	 		title: 'Remote Printing',
	   		group: 'feature-b',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'RemoteChat',
	 		title: 'Remote Chat',
	   		group: 'feature-b',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'RemoteReboot',
	 		title: 'Remote Reboot',
	   		group: 'feature-b',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'HostInvitation',
	 		title: 'Host Invitation',
	   		group: 'feature-c',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'MultiMonitor',
	 		title: 'MultiMonitor',
	   		group: 'feature-c',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'PasswordEncryption',
	 		title: 'Password Encryption',
	   		group: 'feature-c',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'SecureEncryption',
	 		title: 'Secure Encryption',
	   		group: 'feature-c',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'Windows',
	 		title: 'Windows Client',
	   		group: 'os',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'Unix',
	 		title: 'Linux Client',
	   		group: 'os',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'Mac',
	 		title: 'Mac Client',
	   		group: 'os',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'MobilityAccess',
	 		title: 'Mobility Access',
	   		group: 'os',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	];

	var filterColumnInputs = YAHOO.util.Selector.query('#filter-columns input');

	var filterInputs = [
	    {
	    	paramName: 'monthlyFee',
	    	input: YAHOO.util.Selector.query('#filter-monthly-fee')[0]
	    },
	    {
	    	paramName: 'contractMonths',
	    	input: YAHOO.util.Selector.query('#filter-contract-months input')
	    },
	    {
	    	paramName: 'setupFee',
	    	input: YAHOO.util.Selector.query('#filter-setup-fee')[0]
	    },
	    {
	    	paramName: 'freeTypeIds',
	    	input: YAHOO.util.Selector.query('#filter-free-type-id input')
	    },
	    {
	    	paramName: 'computerCount',
	    	input: YAHOO.util.Selector.query('#filter-computer-count')[0]
	    },
	    {
	    	paramName: 'fileTransfer',
	    	input: YAHOO.util.Selector.query('#filter-file-transfer')[0]
	    },
	    {
	    	paramName: 'fileSynchronization',
	    	input: YAHOO.util.Selector.query('#filter-file-synchronization')[0]
	    },
	    {
	    	paramName: 'remoteSound',
	    	input: YAHOO.util.Selector.query('#filter-remote-sound')[0]
	    },
	    {
	    	paramName: 'remotePrinting',
	    	input: YAHOO.util.Selector.query('#filter-remote-printing')[0]
	    },
	    {
	    	paramName: 'remoteChat',
	    	input: YAHOO.util.Selector.query('#filter-remote-chat')[0]
	    },
	    {
	    	paramName: 'remote-reboot',
	    	input: YAHOO.util.Selector.query('#filter-remote-reboot')[0]
	    },
	    {
	    	paramName: 'hostInvitation',
	    	input: YAHOO.util.Selector.query('#filter-host-invitation')[0]
	    },
	    {
	    	paramName: 'multiMonitor',
	    	input: YAHOO.util.Selector.query('#filter-multi-monitor')[0]
	    },
	    {
	    	paramName: 'passwordEncryption',
	    	input: YAHOO.util.Selector.query('#filter-password-encryption')[0]
	    },
	    {
	    	paramName: 'secureEncryption',
	    	input: YAHOO.util.Selector.query('#filter-secure-encryption')[0]
	    },
	    {
	    	paramName: 'mobilityAccess',
	    	input: YAHOO.util.Selector.query('#filter-mobility-access')[0]
	    },
	    {
	    	paramName: 'windows',
	    	input: YAHOO.util.Selector.query('#filter-windows')[0]
	    },
	    {
	    	paramName: 'unix',
	    	input: YAHOO.util.Selector.query('#filter-unix')[0]
	    },
	    {
	    	paramName: 'mac',
	    	input: YAHOO.util.Selector.query('#filter-mac')[0]
	    }
	];

	var dataTableOptions = YAHOO.lang.merge(options, {
		keyFieldName: 'OnlineRemoteDesktopProductId',
		fields: fields,
		initialGroup: 'basic',
		filterInputs: filterInputs,
		defaultSort: {key:'MonthlyFee', dir: YAHOO.widget.DataTable.CLASS_ASC},
		customFormatters: {
			monthlyFee: function(elLiner, oRecord, oColumn, oData) {
	    		var monthlyFee = oRecord.getData('MonthlyFee');
		    	var contractMonths = oRecord.getData('ContractMonths');

		    	var value = YAHOO.squarecompare.formatCurrency(monthlyFee, 2) + '&#47;mo (' + contractMonths + ')';
		    	elLiner.innerHTML = value;
				YAHOO.util.Dom.setStyle(elLiner, 'text-align', 'right');

		    	var toolTipText = YAHOO.squarecompare.formatCurrency(monthlyFee, 2) + ' per month with a ' + contractMonths + ' month commitment or prepayment';
				YAHOO.util.Dom.addClass(elLiner, 'info-icon');
				elLiner.setAttribute('title', toolTipText);
		    }
		},
		getDataStep: 'get-online-remote-desktop-plans'
	});
	var dataTable = YAHOO.squarecompare.DataTable(dataTableOptions);

	// Listen for column group changes
    for (var i=0; i<filterColumnInputs.length; i++) {
		YAHOO.util.Event.addListener(filterColumnInputs[i], 'click', function(e) {
			dataTable.showColumnGroup(this.value);
		});
    }
};
