$(document).ready(function () {
	$("a.confirm").click(function (e) {
		var a = confirm('Are you sure?');
		if (!a) {
			e.preventDefault();
			return false;
		}
	});
	$('.tabbed > .selector').tabs('> div.tab', {current:'active'});
	$('.sign-in').click(function (e) {
		e.preventDefault();
		$('#login-modal').dialog({modal:true});
		return false;
	});
	$('.mobile_number[default]').focus(function () {
		var val = this.value;
		var defa = $(this).attr('default');
		if (val.length < 2 || val == defa) {
			this.value = '+62';
		}
	}).blur(function () {
		var val = this.value;
		var defa = $(this).attr('default');
		if (val.length > 0 && val.length < 8 && val != '+62') {
			this.value = defa;
		}
		if (val.indexOf('+62') < 0) {
			if (val.substr(0, 1) == '0') {
				this.value = '+62' + val.substr(1);
			} else if (val.length > 7) {
				this.value = '+62' + val;
			} else if (val.length > 0) {
				this.value = defa;
			} else if (val == defa) {
				this.value = defa;
			} else {
				this.value = defa;
			}
		} else if (val.indexOf('+62') > 0) {
			this.value = val.substr(val.indexOf('+62'));
		} else if (val == '+62') {
			this.value = defa;
		}
	}).blur();
	$('.mobile_number:not([default])').focus(function () {
		var val = this.value;
		if (val.length < 2) {
			this.value = '+62';
		}
	}).blur(function () {
		var val = this.value;
		if (val.length > 0 && val.length < 8 && val != '+62') {
			alert('Invalid Mobile Number');
			this.focus();
			return false;
		}
		if (val.indexOf('+62') < 0) {
			if (val.substr(0, 1) == '0') {
				this.value = '+62' + val.substr(1);
			} else if (val.length > 7) {
				this.value = '+62' + val;
			} else if (val.length > 0) {
				alert('Invalid Mobile Number');
				this.value = '';
			}
		} else if (val.indexOf('+62') > 0) {
			this.value = val.substr(val.indexOf('+62'));
		} else if (val == '+62') {
			this.value = '';
		}
		if (this.value) {
			$(this).next('label').hide();
		}
		return true;
	});
	$('input:text[default]:not(.mobile_number), input:password[default], textarea[default]').focus(function (e) {
		var $this = $(this);
		var defa = $this.attr('default');
		if (this.value == defa) {
			this.value = '';
		}
	}).blur(function () {
		var $this = $(this);
		var defa = $this.attr('default');
		this.value = trim(this.value);
		if (this.value == '') {
			this.value = defa;
		}
	}).blur();
});
