function cfinit() {
	$('#cfname').focus();
}
function cfsend(o) {
	var p = {};
	p['n'] = $.trim($('#cfname').val());
	p['e'] = $.trim($('#cfemail').val());
	p['m'] = $.trim($('#cfmsg').val());
	if (p['n'].length < 2) {
		alert('Please enter your name.');
		$('#cfname').focus();
		return;
	}
	else if (p['e'].indexOf('@') < 1) {
		alert('Please enter your email address.');
		$('#cfemail').focus();
		return;
	}
	else if (p['m'].length < 2) {
		alert('Please enter message.');
		$('#cfmsg').focus();
		return;
	}
	p['do'] = 'contact';
	p['dm'] = _dmn;
	p['ref'] = document.referrer;
	
	wait($(o.parentNode), true);
	$('#cfwrap :input').attr('disabled', 'disabled');
	var x = $.post(_sbp, p, function (d) {
		var m = $('#cfdone');
		wait($(o.parentNode), false);
		if (x.getResponseHeader('X-AppStatus') == '1') {
			msg(m, 'Your message is sent.', false);
		}
		else {
			$('#cfwrap :input').removeAttr('disabled');
			msg(m, d, true);
		}
	});
	
}
function rginit() {
	$('#rgdomain').focus();
}
function rgsend(o) {
	var p = {};
	p['d'] = $.trim($('#rgdomain').val());
	p['n'] = $.trim($('#rgname').val());
	p['e'] = $.trim($('#rgemail').val());
	p['p'] = $.trim($('#rgphone').val());
	p['m'] = $.trim($('#rgmsg').val());
	if (p['d'].length < 4 || p['d'].indexOf('.') < 1) {
		alert('Please enter domain name.');
		$('#rgdomain').focus();
		return;
	}
	else if (p['n'].length < 2) {
		alert('Please enter your name.');
		$('#rgname').focus();
		return;
	}
	else if (p['e'].indexOf('@') < 1) {
		alert('Please enter your email address.');
		$('#rgemail').focus();
		return;
	}
	if (p['p'].length < 4) {
		alert('Please enter your phone number.');
		$('#rgphone').focus();
		return;
	}
	else if (p['m'].length < 2) {
		alert('Please enter message.');
		$('#rgmsg').focus();
		return;
	}
	p['do'] = 'r1';
	p['dm'] = _dmn;

	wait($(o.parentNode), true);
	$('#rgwrap :input').attr('disabled', 'disabled');
	var x = $.post(_sbp, p, function (d) {
		var m = $('#rgdone');
		wait($(o.parentNode), false);
		if (x.getResponseHeader('X-AppStatus') == '1') {
			msg(m, 'Your message is sent.', false);
		}
		else {
			$('#rgwrap :input').removeAttr('disabled');
			msg(m, d, true);
		}
	});

}
function ufinit() {
	$('#frmu').append('<input type="hidden" name="do" value="userform" />');
	$('#frmu input[name=txccd]').attr('maxlength', '5');
	$('#frmu input[name=txccd]').attr('autocomplete', 'off');
	$('#frmu :input:first').focus();
}
function uform() {
	$('.ff').removeClass('err');
	var e = false;
	$('#frmu :input').each(function () {
		if (!$(this).hasClass('mst')) {
			return true;
		}
		
		if (this.type.toLowerCase() == 'radio') {
			var c = $('input[name=' + this.name + ']:checked');
			if (c.size() < 1) {
				e = true;
				$('input[name=' + this.name + ']:first').parents('.ff').addClass('err');
				alert('Field must be set.');
				$('input[name=' + this.name + ']:first').focus();
				return false;
			}
		}
		else if (this.name == 'txccd') {
			if ($.trim($(this).val()).length != 5) {
				e = true;
				$(this).parents('.ff').addClass('err');
				alert('Please enter 5 character verification code.');
				this.focus();
				return false;
			}
		}
		else if ($.trim($(this).val()) == '') {
			e = true;
			$(this).parents('.ff').addClass('err');
			alert('Field must be set.');
			this.focus();
			return false;
		}
		
		return true;
	});
	
	if (e) {
		return;
	}
	
	wait($('#ubtsub'), true);
	$('#frmu').append('<input type="hid' + 'den" name="scd" value="' + scd() + '" />');
	document.forms.frmu.submit();
}
function onuserform() {
	wait($('#ubtsub'), false);
	$('#frmu :input').attr('disabled', 'disabled');
	alert(_dtx);
	if (_bck.length > 0) {
		top.location.replace(_bck);
	}
}
function erruserform(e, c) {
	wait($('#ubtsub'), false);
	$('input[name=' + c + ']:first').parents('.ff').addClass('err');
	alert(e);
	$('input[name=' + c + ']:first').focus();
}
function scd() {
	return $('#bline').attr('class');
}
function msg(o, s, e) {
	if (e) {
		o.removeClass('ok');
		o.addClass('err');
		o.text(s);
	}
	else {
		o.removeClass('err');
		o.addClass('ok');
		o.text('Your message is sent.');
	}
}
function pagereload() {
	var s = window.location.search;
	top.location.search = s;
}
function wait(o, b) {
	if (o.size() < 1) {
		return;
	}
	if (b) {
		o.children().css('visibility', 'hidden');
		o.addClass('wait');
	}
	else {
		o.removeClass('wait');
		o.children().css('visibility', 'visible');
	}
}
function isemail(s) {
	return (s.indexOf('@') > 0 && s.length > 6);
}
function answer(qid) {
	if ($('#qa_' + qid + ' div.a').is(':visible')) {
		$('#qa_' + qid + ' div.a').slideUp('fast');
		return false;
	}
	else if ($('#qa_' + qid + ' div.a').html().length > 2) {
		$('#qa_' + qid + ' div.a').slideDown('fast');
		return false;
	}
	wait($('#qa_' + qid), true);
	var x = $.post(_sbp, {'do':'faq', 'dm':_dmn, 'lng':_lng, 'qid':qid}, function (d) {
		wait($('#qa_' + qid), false);
		if (x.getResponseHeader('X-AppStatus') == '1') {
			$('#qa_' + qid + ' div.a').html(d);
		}
		else {
			$('#qa_' + qid + ' div.a').html('Failed to load answer.');
		}
		$('#qa_' + qid + ' div.a').slideDown('fast');
	});
	return false;
}

function sfinit() {
	$('#frmf').append('<input type="hidden" name="do" value="friend" />');
	$('#frmf input[name=txccd]').attr('maxlength', '5');
	$('#frmf input[name=txccd]').attr('autocomplete', 'off');
	$('#sfname').focus();
}
function ssform() {
	var f = document.forms.frmf;
	$('.ff').removeClass('err');
	
	if (!isemail($.trim($('#rcemail').val()))) {
		$('#rcemail').parents('.ff').addClass('err');
		alert('Please enter recipient email address.');
		$('#rcemail').focus();
		return;
	}
	else if ($.trim($('#txccd').val()).length != 5) {
		$('#txccd').parents('.ff').addClass('err');
		alert('Please enter 5 character verification code.');
		$('#txccd').focus();
		return;
	}
	
	wait($('#ubtsub'), true);
	$(f).append('<input type="hid' + 'den" name="scd" value="' + scd() + '" />');
	f.submit();
}
function onfriend() {
	wait($('#ubtsub'), false);
	$('#frmf :input').attr('disabled', 'disabled');
	alert('Message is sent.');
	top.location.replace(_bck);
}
function errfriend(e, c) {
	wait($('#ubtsub'), false);
	$('input[name=' + c + ']:first').parents('.ff').addClass('err');
	alert(e);
	$('input[name=' + c + ']:first').focus();
}

function filtercat(o) {
	var a = [];
	$('li input:checked', $(o).parents('ul')).each( function () { a[a.length] = $(this).val() } );
	if (a.length > 0) {
		window.location.search = '?filter=cat&item=' + a.join('-');
	}
}
function filtertag(o) {
	var a = [];
	$('li input:checked', $(o).parents('ul')).each( function () { a[a.length] = $(this).val() } );
	if (a.length > 0) {
		window.location.search = '?filter=tag&item=' + a.join('-');
	}
}


