var Menu = {
	show : function(dom) {
		var menu = $('ul',dom);
		$('ul',dom).css('margin-left',0);
	},
	hide : function(dom) {
		var menu = $('ul',dom);
		$('ul',dom).css('margin-left',-5000);
	}
};

function signin(form) {
	var email = jQuery.trim(form.email.value);
	var password = jQuery.trim(form.password.value);
	var error = '';
	var focus = '';
	if (email == 'Email' || email.length < 1 || !isEmail(email)) {
		error += "\n - Vui l\u00F2ng nh\u1EADp \u0111\u1ECBa ch\u1EC9 email theo \u0111\u1ECBnh d\u1EA1ng: localpart@domain.example";
		focus = 'form.email.focus();';
	}
	if (password == '*****' || password.length < 3) {
		error += "\n - M\u1EADt kh\u1EA9u c\u1EA7n d\u00E0i \u00EDt nh\u1EA5t l\u00E0 3 k\u00FD t\u1EF1.";
		if (focus == '') {
			focus = 'form.password.focus();';
		}
	}
	if (error != '') {
		alert('Th\u00F4ng b\u00E1o l\u1ED7i:' + error);
		eval(focus);
		return false;
	} else {
		try {
			form.crumb.value = hex_md5(password);
			form.password.value = '';
		} catch (ex) {
			form.crumb.value = '';
			form.password.value = password;
		}
		return true;
	}
	return false;
}

function setActiveTab(tab) {
	tab = jQuery(tab);
	var pid = tab.parent(this).attr('title');
	var cid = tab.attr('id').replace('_title', '');
	if (cid != pid) {
		if (jQuery('#' + pid).attr('id')) {
			jQuery('#' + pid).attr('class', '');
		}
		if (jQuery('#' + pid + '_title').attr('id')) {
			jQuery('#' + pid + '_title').attr('class', '');
		}
		if (jQuery('#' + cid).attr('id')) {
			jQuery('#' + cid).attr('class', 'content_current');
		}
		tab.parent(this).attr('title', cid);
		tab.attr('class', 'current');
	}
}

function unsetActiveTab(tab) {
	tab = jQuery(tab);
	tab.attr('class','');
	tab.parent(this).attr('title', '');
}

function jAjax(app, data, action, callback) {
	app = app || requestApp;
	action = action || '';
	data = data || null;

	try {
		$.ajax({
			url : 'http://' + location.host + '/' + app + '/ajax/' + action,
			cache: false,
			data : data,
			type: 'post',
			dataType : 'json',
			success : function(result) {
				if (result.sStart) {
					eval(result.sStart);
				}
				if (result.cobj) {
					jParser(result.cobj);
				}
				if (result.carr) {
					for (var i in result.carr) {
						jParser(result.carr[i]);
					}
				}
				if (result.sEnd) {
					eval(result.sEnd);
				}
				if (!isUndefined(callback) && callback) {
					eval(callback);
				}
			},
			beforeSend : function(req) {
				$('#loading').show();
			},
			complete : function(req, txt) {
				$('#loading').hide();
			}
		});
	} catch (ex) { }
	return false;
}

function jExec(url, data, callback) {
	jAjax(requestApp, data, url, callback);
}

function jParser(obj)
{
	if (obj.attr.empty == 1) {
		jQuery('#' + obj.attr.id).empty();
	}
	if (obj.value && obj.value != '') {
		if (obj.attr.append == 1) {
			jQuery('#' + obj.attr.id).append(obj.value);
		} else {
			jQuery('#' + obj.attr.id).prepend(obj.value);
		}
	}
}

function checkAll(field)
{
	for (i = 0; i < field.length; i++)
	{
		field[i].checked = true ;
	}
	return false;
}

function unCheckAll(field)
{
	for (i = 0; i < field.length; i++)
	{
		field[i].checked = false ;
	}
	return false;
}

var box = $("#box");
$(document).ready(function(){
    if ( box.css("position") == "absolute" )
    {
	    $(window).scroll(function () {
	        box.css("top", $(document).scrollTop() + "px");
	    });
	}
});