﻿function InitializeComments(type, id) {
	if ($('commentlink')) {
		var show = new ShowLink({linkId: 'commentlink', containerId: 'commentcontainer'});
	}
	if ($('commentpost')) {
		var form = new CreativeMinds.Form({form: $('commentpost'), focusOnFirst: true, ajaxSubmit: true, reset: true});
		var commentField = new CreativeMinds.FormElement({element: $('comment')});
		commentField.AddValidation(new CreativeMinds.Validation({type: 'required', errorMessage: 'Don\'t submit an empty comment!'}));
		form.AddElement(commentField);
		
		form.addEvent('success', function(response) { alert(response);});
		form.addEvent('failure', function(message) { alert(message);});
		
		$('commentpost').type.value = type;
		$('commentpost').id.value = id;
	}
	if ($('thumbsup')) {
		var upLink = new LinkAction({link: $('thumbsup'), arguments: 'vote=up&type=' + type + '&id=' + id, action: 'Vote'});
		upLink.addEvent('success', function(response) {
			if ($('upcount')) {
				$('upcount').set('html', response);
			}
		});
		upLink.addEvent('failure', function(e) { alert(e); });
	}
	if ($('thumbsdown')) {
		var upLink = new LinkAction({link: $('thumbsdown'), arguments: 'vote=down&type=' + type + '&id=' + id, action: 'Vote'});
		upLink.addEvent('success', function(response) {
			if ($('downcount')) {
				$('downcount').set('html', response);
			}
		});
		upLink.addEvent('failure', function(e) { alert(e); });
	}
}