
/*

*/

OTS.commenter = {};

OTS.commenter.doLogin = function() {
	OTS.doLogin('comment');
}
OTS.commenter.preview = function() {
	var o = OTS.$('comment');
	if (!o) return;
	var t = o.value.replace(/\n\n/g, '</p><p>');
	t = t.replace(/\n/g, '<br />');
	/*OTS.commenter.countdown(o, 1000);*/
	/*OTS.commenter.countup(o, 1000);*/
	var obj = OTS.$('comment_live');
	if (!obj) return;
	OTS.setHTML(obj, '<div><strong>Preview:</strong><br /><span>' + t + '</span></div>');
	OTS.setStyle(obj, 'display', 'block');
}
OTS.commenter.shownum = function(n) {
	var o = OTS.$('comments_jump');
	if (!o) return;
	var s = (n == '1') ? '' : 's';
	OTS.setHTML(o, '(' + n + ') Comment' + s);
}
OTS.commenter.countdown = function(t, len) {
	if (t.value.length > len) {
		t.value = t.value.substring(0, len);
	}
	var n = len - t.value.length;
	var o = OTS.$('comments_togo');
	if (!o) return;
	OTS.setHTML(o, n + ' character' + ((n == 1) ? '' : 's') + ' left');
}
OTS.commenter.countup = function(t, len) {
	if (t.value.length > len) {
		t.value = t.value.substring(0, len);
	}
	var n = t.value.length;
	var o = OTS.$('comments_togo');
	if (!o) return;
	OTS.setHTML(o, n + ' of ' + len + 'character' + ((n == 1) ? '' : 's') + '');
}
OTS.commenter.showLang = function() {
	var o1 = OTS.$('comment_lang1');
	if (!o1) return;
	var o2 = OTS.$('comment_lang2');
	if (!o2) return;
	OTS.setStyle(o1, 'display', 'none');
	OTS.setStyle(o2, 'display', 'block');
}
OTS.commenter.showInfoPop = function(target) {
	var target = OTS.$(target);
	if (!target) return;
	if (OTS.commenter.terms == true) return;
	var o1 = OTS.$('posting_info');
	if (!o1) return;
	var html = '<div>';
	html += o1.innerHTML;
	html += '<input type="button" id="acceptBtn" name="acceptBtn" value="OK" class="fBtn" onclick="OTS.commenter.acceptInfoPop(); OTS.commenter.closeInfoPop();" />';
	html += '</div>';
	var o = OTS.$('posting_infopop');
	if (!o) {
		o = document.createElement('div');
		o.id = 'posting_infopop';
		document.body.appendChild(o);
	}
	o.innerHTML = html;
	var p = OTS.getPos(target);
	OTS.setStyle(o, 'position', 'absolute');
	OTS.setStyle(o, 'left', p.left + 'px');
	OTS.setStyle(o, 'top', p.top + 'px');
	OTS.setStyle(o, 'width', target.offsetWidth + 'px');
	target.blur();
	var b = OTS.$('acceptBtn');
	if (!b) return;
	b.focus();
}
OTS.commenter.hideInfoPop = function() {
	var o = OTS.$('posting_infopop');
	if (!o) return;
	OTS.setHTML('');
	OTS.setStyle(o, 'left', '-2000px');
}
OTS.commenter.closeInfoPop = function() {
	OTS.commenter.hideInfoPop();
	var o = OTS.$('comment');
	if (!o) return;
	o.focus();
}
OTS.commenter.acceptInfoPop = function() {
	OTS.commenter.terms = true;
}
OTS.commenter.validate = function() {
	var f = document.comment_form;
	var s = '';
	if (f.comment.value == '') s += OTS.commenterTxtObj.t1 + '<br />';
	/* Finally */
	if (s != '') {
		OTS.validateWriteErrs('comment_errors', s);
		location.href = '#comment_errors';
		return false;
	} else {
		f.submit();
	}
}
