YAHOO.namespace('squarecompare');

YAHOO.squarecompare.initWebConferencingDataTable = function(options) {

	var fields = [
	    {
	    	name: 'WebConferencingProductId',
	    	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: 'MeetingsCount',
	 		title: 'Meetings',
	   		group: 'basic',
	 		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: 'ParticipantCapacity',
	 		title: 'Participants',
	   		group: 'basic',
	 		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: 'PresentationSharing',
	 		title: 'Presentation Sharing',
	   		group: 'sharing',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'ApplicationSharing',
	 		title: 'Application Sharing',
	   		group: 'sharing',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'DesktopSharing',
	 		title: 'Desktop Sharing',
	   		group: 'sharing',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'PhoneConferencing',
	 		title: 'Phone Conferencing',
	   		group: 'conferencing',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'VoipConferencing',
	 		title: 'VOIP Conferencing',
	   		group: 'conferencing',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'VideoConferencing',
	 		title: 'Video Conferencing',
	   		group: 'conferencing',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'TextChat',
	 		title: 'Text Chat',
	   		group: 'interaction',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'Whiteboard',
	 		title: 'Whiteboard',
	   		group: 'interaction',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'PollSurvey',
	 		title: 'Poll Survey',
	   		group: 'interaction',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'FileTransfer',
	 		title: 'File Transfer',
	   		group: 'interaction',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'SwitchPresenter',
	 		title: 'Switch Presenter',
	   		group: 'interaction',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'ScheduleMeeting',
	 		title: 'Scheduler',
	   		group: 'other',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'RecordPlayback',
	 		title: 'Record Playback',
	   		group: 'other',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'AttendanceReporting',
	 		title: 'Attendee Reports',
	   		group: 'other',
	   		sortable: true,
	  		sizable: true,
	  		formatter: 'checked'
	 	},
	 	{
	 		name: 'SecureConferencing',
	 		title: 'Secure',
	   		group: 'other',
	   		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: 'meetingsCount',
	    	input: YAHOO.util.Selector.query('#filter-meetings-count')[0]
	    },
	    {
	    	paramName: 'participantCapacity',
	    	input: YAHOO.util.Selector.query('#filter-participant-capacity')[0]
	    },
	    {
	    	paramName: 'scheduleMeeting',
	    	input: YAHOO.util.Selector.query('#filter-schedule-meeting')[0]
	    },
	    {
	    	paramName: 'presentationSharing',
	    	input: YAHOO.util.Selector.query('#filter-presentation-sharing')[0]
	    },
	    {
	    	paramName: 'applicationSharing',
	    	input: YAHOO.util.Selector.query('#filter-application-sharing')[0]
	    },
	    {
	    	paramName: 'desktopSharing',
	    	input: YAHOO.util.Selector.query('#filter-desktop-sharing')[0]
	    },
	    {
	    	paramName: 'textChat',
	    	input: YAHOO.util.Selector.query('#filter-text-chat')[0]
	    },
	    {
	    	paramName: 'whiteboard',
	    	input: YAHOO.util.Selector.query('#filter-whiteboard')[0]
	    },
	    {
	    	paramName: 'pollSurvey',
	    	input: YAHOO.util.Selector.query('#filter-poll-survey')[0]
	    },
	    {
	    	paramName: 'fileTransfer',
	    	input: YAHOO.util.Selector.query('#filter-file-transfer')[0]
	    },
	    {
	    	paramName: 'phoneConferencing',
	    	input: YAHOO.util.Selector.query('#filter-phone-conferencing')[0]
	    },
	    {
	    	paramName: 'voipConferencing',
	    	input: YAHOO.util.Selector.query('#filter-voip-conferencing')[0]
	    },
	    {
	    	paramName: 'videoConferencing',
	    	input: YAHOO.util.Selector.query('#filter-video-conferencing')[0]
	    },
	    {
	    	paramName: 'switchPresenter',
	    	input: YAHOO.util.Selector.query('#filter-switch-presenter')[0]
	    },
	    {
	    	paramName: 'recordPlayback',
	    	input: YAHOO.util.Selector.query('#filter-record-playback')[0]
	    },
	    {
	    	paramName: 'attendanceReporting',
	    	input: YAHOO.util.Selector.query('#filter-attendance-reporting')[0]
	    },
	    {
	    	paramName: 'secureConferencing',
	    	input: YAHOO.util.Selector.query('#filter-secure-conferencing')[0]
	    },
	    {
	    	paramName: 'flagged',
	    	input: YAHOO.util.Selector.query('#filter-flagged input')
	    }
	];

	var dataTableOptions = YAHOO.lang.merge(options, {
		keyFieldName: 'WebConferencingProductId',
		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, 0) + '&#47;mo (' + contractMonths + ')';
		    	elLiner.innerHTML = value;
				YAHOO.util.Dom.setStyle(elLiner, 'text-align', 'right');

		    	var toolTipText = YAHOO.squarecompare.formatCurrency(monthlyFee, 0) + ' per month with a ' + contractMonths + ' month commitment or prepayment';
				YAHOO.util.Dom.addClass(elLiner, 'info-icon');
				elLiner.setAttribute('title', toolTipText);
		    }
		},
		getDataStep: 'get-web-conferencing-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);
		});
    }
};
