function ClearForm(form, confirmclear) {
	if (typeof confirmclear !== 'undefined') {
		if (typeof confirmclear !== 'string') {
			confirmclear = 'Are you sure?';
		}

		if ( ! confirm(confirmclear)) {
			return false;
		}
	}

	for (var i = 0; i < form.length; i += 1) {
		var
		isButton = false,
		type     = form[i].getAttribute('type');

		if (type) {
			isButton = type.match(/(button|submit|reset|image|hidden)/i) !== null;
		}

		if ( ! isButton) {
			form[i].value = '';

			if (form[i].nodeName.toLowerCase() === 'select') {
				form[i].selectedIndex = 0;
			}
		}
	}

	return false;
}

function CheckboxGroup() {
	var
	c       = arguments[0] || event.target,
	oncheck = onuncheck = function(){};

	switch (arguments.length) {
		case 1:
			if (typeof arguments[0]==='function') {
				onuncheck=oncheck=arguments[0];
				c=event.target;
			}
		break;
		case 2:
			if (typeof arguments[0]==='function') {
				oncheck=arguments[0];
				onuncheck=arguments[1];
				c=event.target;
			} else {
				oncheck=arguments[1];
			}
		break;
		case 3:
			oncheck=arguments[1];
			onuncheck=arguments[2];
		break;
	}

	var b = ((c.form) ? $(':checkbox',c.form) : $(':checkbox', $(c).closest('table')));

	b.attr('checked',c.checked);

	if (c.checked && typeof oncheck==='function') {
		try {
			oncheck.apply(window,[true]);
		} catch(e) {
			alert(e.message);
		}
	}

	if ( ! c.checked && typeof onuncheck === 'function') {
		try {
			oncheck.apply(window,[false]);
		} catch(e) {
			alert(e.message);
		}
	}

	return;
}

var MF_DEBUG = window.location.href.indexOf('__dbg=true') > -1;

$(document).ready(function() {
	if (MF_DEBUG) {
		$('a[href^=#]').click(function() {
			var id = this.href.substr(this.href.lastIndexOf('#'), this.href.length);

			$(id).scrollTo(0, 800);

			// var id = $(this.href.substr(this.href.lastIndexOf('#'), this.href.length))
			// if (id.length) {
			//	   $(this).scrollTo(id);
			//	   id[0].scrollIntoView();
			//	   return false;
			// }
		});
	}

	// $('form.newsl-form').submit(function() {
	// 	return false;
	// });

	$('form.newsl-form').find('input:submit').click(function() {
		var
		$this       = $(this),
		emailFilter = /^[A-Z0-9._%\-]+@[A-Z0-9.\-]+\.[A-Z]{2,4}$/i,
		emailAddr   = $this.parent().find('input[name=email]').val();

		if ( ! emailFilter.test(emailAddr)) {
			alert('Please, enter a valid e-mail address!');

			return false;
		} else {
			return true;
		}
	});
});
