$(function(){
	$("a").focus(function(){this.blur()});
});
//*************************************************************************
function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.name != "checkboxall" && e.type == "checkbox" && e.disabled!=true && e.noall!=1){
			e.checked = form.checkboxall.checked;
			e.disabled = false;
		}
	}
}
//*************************************************************************
function UnSelectAll(){
	if ($("#checkboxall").attr("checked")){
		$("#checkboxall").attr("checked",false);
	}
}
//********************************************************************
function Confirm(msg) {
	if (confirm(msg)){
		return true;
	}
	else {
		return false;
	}
}
$(function(){ //登录 模拟submit
	if ($(".btn_login").length>0){
		$(".btn_login").click(function(){login()});
		$("body").bind('keyup',function(event){if(event.keyCode==13){login()}});
	}
});
$(function(){ //cookie
	if ($('#savelogin').length > 0){
		if ($.cookie('oa_savelogin')=='yes'){
			if ($.cookie('oa_username')!=''&&$.cookie('oa_username')!=null){
				$("#username").val($.cookie('oa_username'))
			}
			if ($.cookie('oa_password')!=''&&$.cookie('oa_password')!=null){
				$("#password").val($.cookie('oa_password'))
			}
			$("#savelogin").attr('checked', true)
		}
	}
});
//************************************************************
$(function(){ //显示隐藏
	if ($("#is_hidden").length>0){
		$("#is_hidden").click(function(){
			if ($("#is_hidden").attr('checked')){
				$(".is_hidden").removeClass('hidden');
				//$(".is_disabled").attr('disabled',false);
			}
			else{
				$(".is_hidden").addClass('hidden');
				//$(".is_disabled").attr('disabled',true);
			}
		});
	}
});
//************************************************************
function login(){ //登录 验证
	if ($("#username").val()==""){
		$(".msg").html("登陆用户名不允许为空！");
		$("#username").focus();
		return false;
	}
	if ($("#password").val()==""){
		$(".msg").html("登陆密码不允许为空！");
		$("#password").focus();
		return false;
	}
	$(".btn_login span").html("正在验证");
	var queryString = $("#Login").formSerialize();
	$.post("jquery.php", queryString, 
		function(data){
			switch(data.state){
				case "success":
					if ($('#savelogin').attr("checked")){
						$.cookie('oa_username', $('#username').val(), { expires: 999 });
						$.cookie('oa_password', $('#password').val(), { expires: 999 });
						$.cookie('oa_savelogin', 'yes', { expires: 999 });
					}
					else{
						$.cookie('oa_username', '', { expires: -1 });
						$.cookie('oa_password', '', { expires: -1 });
						$.cookie('oa_savelogin', '', { expires: -1 });
					}
					window.location=data.url;
					break;
				case "failure":
					$(".msg").html(data.msg);
					$("#login").clearForm();
					$(".btn_login span").html("马上登陆");
					break;
				default:
					$(".msg").html("系统故障");
					$("#login").clearForm();
					$(".btn_login span").html("马上登陆");
			}
		}
	, "json");
}

$(function(){
	$('input[type=radio][name=status]').click(function(){
		if ($(this).val() > 1) {
			$('#approve_id').show();
		} else {
			$('#approve_id').hide();
		}
	});
});
