if (typeof objCategory == 'undefined') {
    
var objCategory = {
	clicked1 : false,
	cateId : 0,
	moduleId : 0,
	menuId : 0,

	addCategory : function() {
		// we want to store the values from the form input box, then send via ajax below
		var cateName = $('#txtName').attr('value');
		var order_id = $('#txtOrder').attr('value');
		var moduleId = $('#moduleId').attr('value');
		//validate
		if (typeof(cateName)=='undefined') {
			$('#txtName').addClass('hightlight');
			return false;
		} else $('#txtName').removeClass('hightlight');
		
		if (typeof(order_id)=='undefined') {
			$('#txtOrder').addClass('hightlight');
			return false;
		} 
		else if(order_id != ''){
			if (isNaN(order_id) == true) {
				alert("Số thứ tự phải là số nguyên");
				return false;
			}	
		}
		else $('#txtOrder').removeClass('hightlight');
		
		/*if (typeof(moduleId)=='undefined') {
			$('#moduleId').addClass('hightlight');
			return false;
		} else $('#moduleId').removeClass('hightlight');*/
			
		var data = "cateName=" + cateName + '&order_id=' + order_id + '&moduleId=' + $('#module_id').attr("value");
			//data += "&sectionId=" + GetID('sectionId').options[GetID('sectionId').selectedIndex].value;
		
		$.ajax({
			type: "POST",
			url: "?mod=category&act=addCategory",
			data: data,
			success: function(){
				alert("Thêm mới thành công");
				document.location='?mod=category&act=listAll&moduleId='+$('#module_id').attr("value");
			}
		});
		return false;
	},

	delCate : function(cateId) {
		if (!confirm('Nếu xóa category này thì sẽ thực hiện xóa hết category con\nBạn có chắc chắn xoá Category này không?')) return;
		var data = "cateId="+cateId;
		$.ajax({
			type: "POST",
			url: "?mod=category&act=delCategory",
			data: data,
			success: function(){
				document.location='?mod=category&act=listAll&moduleId='+$('#module_id').attr("value");
			}
		});
		return false;
	},
	
	editCate : function(cateId) {
		var cateName = $('#txtCateName_'+cateId).attr('value');
		var orderId = $('#txtOrder_'+cateId).attr('value');
		var data = "cateName="+cateName+"&orderId="+orderId+"&cateId="+cateId;
			//data += "&sectionId=" + GetID('sectionId_'+cateId).options[GetID('sectionId_'+cateId).selectedIndex].value;

		$.ajax({
			type: "POST",
			url: "?mod=category&act=editCategory",
			data: data,
			success: function(){
				document.location='?mod=category&act=listAll&moduleId='+$('#module_id').attr("value");
			}
		});
		return false;
	},

	addCateChild : function() {
		var cateChildName = $('#cateChildName').attr('value');
		if(typeof(cateChildName)=='undefined'){
			alert("Hãy nhập tên category");
			return;
		}
		var data = "cateChildName="+cateChildName+"&moduleId="+objCategory.moduleId+"&parentId="+objCategory.cateId;
			//data += "&sectionId=" + GetID('sectionIdChild').options[GetID('sectionIdChild').selectedIndex].value;

		$.ajax({
			type: "POST",
			url: "?mod=category&act=addChildCate",
			data: data,
			//dataType: "json",
			success: function(){
				document.location='?mod=category&act=listAll&moduleId='+$('#module_id').attr("value");
			}
		});
		return false;
	},

	ovlMoveCate : function(cateId, moduleId) {
		var data = "cateId="+cateId+"&moduleId="+moduleId;

		$.ajax({
			type: "POST",
			url: "?mod=system&act=listAllCategory",
			data: data,
			//dataType: "json",
			success: function(){
				$("#test").fadeIn();
				//alert($("#test").innerHTML);
				//document.location='?mod=system&act=listCategory';
			}
		});
		return false;
	},

	//code for overlay
	showOvlAddCate : function(value, modId) {
		objCategory.cateId = value;
		objCategory.moduleId = modId;
		$("#chooseCity").slideToggle("fast");
		$("#chooseCat").slideUp("fast");
		$("#chooseCatButton").removeClass("btnHmenuMoreCurrent").addClass("btnHmenuMore");
		if (value.className == 'otherHover'){
			$(value).removeClass("otherHover").addClass("otherCurrent");
			objCategory.clicked1 = true;
		}
		else if (objCategory.clicked1 == true){
			$(value).removeClass("otherCurrent").addClass("other");
		}	
	},

	showOvlAddMenu : function(value) {
		objCategory.menuId = value;
		$('#menuChildName').attr('value', '');
		$("#chooseCity").slideToggle("fast");
		$("#chooseCat").slideUp("fast");
		$("#chooseCatButton").removeClass("btnHmenuMoreCurrent").addClass("btnHmenuMore");
		if (value.className == 'otherHover'){
			$(value).removeClass("otherHover").addClass("otherCurrent");
			objCategory.clicked1 = true;
		}
		else if (objCategory.clicked1 == true){
			$(value).removeClass("otherCurrent").addClass("other");
		}	
	},
	
	fn_click_boxClose : function() {
		$("#chooseCity").slideUp("fast");
		$("#chooseCat").slideUp("fast");
		$("#chooseCatButton").addClass("btnHmenuMore").removeClass("btnHmenuMoreCurrent");
		$("#chooseCityButton").removeClass("otherCurrent").addClass("other");	
	},
	
	fn_over_boxClose : function(value) {
		$(value).css({cursor:"pointer"});
	},

	fn_out_boxClose : function(value) {
		$(value).css({cursor:"none"});
	},

	checkActiveCate : function(obj) {
		var statusCheck = document.getElementById(obj.id).checked;
		var strId = obj.id;
		if(statusCheck == true)
			statusCheck = 1;
		else
			statusCheck = 0;
		var data = "strId="+strId+"&statusCheck="+statusCheck;
		$.ajax({
			type: "POST",
			url: "?mod=category&act=setActiveCate",
			data: data,
			success: function(){
				document.location='?mod=category&act=listAll&moduleId='+$('#module_id').attr("value");
			}
		});
		return false;
	},
	
	addCategoryClient : function() {
		// we want to store the values from the form input box, then send via ajax below
		var cateName = $('#txtName').attr('value');
		var order_id = $('#txtOrder').attr('value');
		var moduleId = $('#module_id').attr('value');
		
		//validate
		if (typeof(cateName)=='undefined') {
			$('#txtName').addClass('hightlight');
			return false;
		} else $('#txtName').removeClass('hightlight');
		
		if (typeof(order_id)=='undefined') {
			$('#txtOrder').addClass('hightlight');
			return false;
		} 
		else if(order_id != ''){
			if (isNaN(order_id) == true) {
				alert("Số thứ tự phải là số nguyên");
				return false;
			}	
		}
		else $('#txtOrder').removeClass('hightlight');
		
		/*if (typeof(moduleId)=='undefined') {
			$('#moduleId').addClass('hightlight');
			return false;
		} else $('#moduleId').removeClass('hightlight');*/
			
		var data = "cateName=" + cateName + '&order_id=' + order_id + '&moduleId=' + $('#module_id').attr("value");
			//data += "&sectionId=" + GetID('sectionId').options[GetID('sectionId').selectedIndex].value;
		var url = $('#addCategoryUrl').val();
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			success: function(){
				alert("Thêm mới thành công");
				document.location.reload();
			}
		});
		return false;
	},

	delCateClient : function(cateId) {
		if (!confirm('Nếu xóa category này thì sẽ thực hiện xóa hết category con\nBạn có chắc chắn xoá Category này không?')) return;
		var data = "cateId="+cateId;
		var url = $('#delCategoryUrl').val();
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			success: function(){
				document.location = $('#listCategoryUrl').val();
			}
		});
		return false;
	},
	
	editCateClient : function(cateId) {
		var cateName = $('#txtCateName_'+cateId).attr('value');
		var orderId = $('#txtOrder_'+cateId).attr('value');
		var data = "cateName="+cateName+"&orderId="+orderId+"&cateId="+cateId;
			//data += "&sectionId=" + GetID('sectionId_'+cateId).options[GetID('sectionId_'+cateId).selectedIndex].value;
		var url = $('#editCategoryUrl').val();
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			success: function(){
				document.location = $('#listCategoryUrl').val();
			}
		});
		return false;
	},
	
	addCateChildClient : function() {
		var cateChildName = $('#cateChildName').attr('value');
		if(typeof(cateChildName)=='undefined'){
			alert("Hãy nhập tên category");
			return;
		}
		var data = "cateChildName="+cateChildName+"&moduleId="+objCategory.moduleId+"&parentId="+objCategory.cateId;
			//data += "&sectionId=" + GetID('sectionIdChild').options[GetID('sectionIdChild').selectedIndex].value;
		var url = $('#addChildCateUrl').val();
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			//dataType: "json",
			success: function(){
				document.location = $('#listCategoryUrl').val();
			}
		});
		return false;
	},
	
	//code for overlay
	showOvlAddCateClient : function(value, modId) {
		objCategory.cateId = value;
		objCategory.moduleId = modId;
		$("#chooseCity").slideToggle("fast");
		$("#chooseCat").slideUp("fast");
		$("#chooseCatButton").removeClass("btnHmenuMoreCurrent").addClass("btnHmenuMore");
		if (value.className == 'otherHover'){
			$(value).removeClass("otherHover").addClass("otherCurrent");
			objCategory.clicked1 = true;
		}
		else if (objCategory.clicked1 == true){
			$(value).removeClass("otherCurrent").addClass("other");
		}	
	},
	
	fn_click_boxCloseClient : function() {
		$("#chooseCity").slideUp("fast");
		$("#chooseCat").slideUp("fast");
		$("#chooseCatButton").addClass("btnHmenuMore").removeClass("btnHmenuMoreCurrent");
		$("#chooseCityButton").removeClass("otherCurrent").addClass("other");	
	},
	
	fn_over_boxCloseClient : function(value) {
		$(value).css({cursor:"pointer"});
	},

	fn_out_boxCloseClient : function(value) {
		$(value).css({cursor:"none"});
	},
	
	checkActiveCateClient : function(obj) {
		var statusCheck = document.getElementById(obj.id).checked;
		var strId = obj.id;
		if(statusCheck == true)
			statusCheck = 1;
		else
			statusCheck = 0;
		var data = "strId="+strId+"&statusCheck="+statusCheck;
		var url = $('#setActiveCateUrl').val();
		$.ajax({
			type: "POST",
			url: url,
			data: data,
			success: function(){
				document.location = $('#listCategoryUrl').val();
			}
		});
		return false;
	},
	
	/*
	 * showCate
	 * - Đóng, mở thư mục tree.
	 * @param String menuId : wrapper menu id 
	 * @param String baseId : id of parent folder, 
	 * 							our folders tree has contruct: cate_1{cate_1_1, cate_1_2}, cate_2{cate_2_1, cate_2_2..}..
	 * 							every element has prefix "cate_1_" will be affected when click on "cate_1" folder
	 * @author: Vannt
	 * @created: 12 Jan 2011
	 */
	showCate : function(menuId, baseId) {
				
		var curStatus = $("#" + menuId + " div[id^='"+baseId+"_']").eq(0).css('display');
		// Nếu folder hiện tại đang ở trạng thái đóng, thì mở folders children gần nhất 
		if (curStatus == 'none' || ($("#" + menuId + " div[id^='" + baseId +"_']").length == 0)) {
			$('#' + menuId + ' div').filter(function() {
				var regex = new RegExp('^' + baseId + '_' + '\\d+$'); // Tìm những div có id mở đầu bằng baseId_
				return this.id.match(regex);
			}).each(function(){ 
					// Nếu folder có folder con, set icon thành đóng 
					if($("#" + menuId + " div[id^='"+this.id+"_']").length > 0) {
						$("#" + menuId + " div[id='" + this.id +"'] span[class^='folder-icon']").attr('class', 'folder-icon folder-close');
					} else {
						// Nếu folder là nhỏ nhất, set icon thành mở 
						$("#" + menuId + " div[id='" + this.id +"'] span[class^='folder-icon']").attr('class', 'folder-icon folder-open');
					}
					$(this).show();
				});
			// set icon folder hiện tại thành mở 
			$("#" + menuId + " div[id='" + baseId +"'] span[class^='folder-icon']").attr('class', 'folder-icon folder-open');
		} else {
			// set icon folder hiện tại thành đóng 
			$("#" + menuId + " div[id='" + baseId +"'] span[class^='folder-icon']").attr('class', 'folder-icon folder-close');
			$("#" + menuId + " div[id^='"+baseId+"_']").hide();
		}
	},
	
	/*
	 * getFolder
	 * - get choiced folder after choice facebox folders.
	 * @param: String objDisplayId : id of textfield display result after choice folder
	 * @param : objDOM obj : current click folder
	 */ 
	getFolder : function (folderId, folderName) {
		$("input[name='id_cate']").val(folderId);
		$("input[name='cate_name']").val(folderName);
		jQuery.facebox.close();
	}
};
}

