function adminComponent(id){
	Component.call(this, id);
	
};

$.extend( adminComponent.prototype, Component.prototype, {
	editMode:false,
	enterToUpdateOrAddOrRemoveMode : function(name){
//		$("button[name='"+name+"Up']").attr("disabled", true);
//		$("button[name='"+name+"Down']").attr("disabled", true);
		$("a[name='"+name+"Up']").attr("customizedDisabled", true);
		$("a[name='"+name+"Down']").attr("customizedDisabled", true);
		
		$("div[name='manageQuestion']").attr("customizedDisabled", true);
//		$("button[name='"+name+"Save']").attr("disabled", false);
		$("a[name='"+name+"Save']").attr("customizedDisabled", false);
		
//		$("button[name='faqBackToCate']").attr("disabled",true);
		$("a[name='faqBackToCate']").attr("customizedDisabled",true);
		
		$("button[name='clientSetupListAll']").attr("disabled", true);
		$("button[name='clientSetupListActive']").attr("disabled", true);
		$("button[name='clientSetupListInactive']").attr("disabled", true);
		
		if($("button[name='"+name+"Eng']").attr('style') != "" && $("button[name='"+name+"Eng']").attr('style') != undefined){
			$("button[name='"+name+"Eng']").attr({style:"", disabled: true});
		}
		if($("button[name='"+name+"Zh-HK']").attr('style')!="" && $("button[name='"+name+"Zh-HK']").attr('style')!=undefined){
			$("button[name='"+name+"Zh-HK']").attr({style:"", disabled: true});
		}
		if($("button[name='"+name+"Zh-CN']").attr('style')!="" && $("button[name='"+name+"Zh-CN']").attr('style')!=undefined){
			$("button[name='"+name+"Zh-CN']").attr({style:"", disabled: true});
		}
		this.editMode=true;
		this.buttonColorDisable();
		//$("a[page]").hide();
	},
	enterToUpOrDownMode : function(name) {
//		$("button[name='"+name+"Add']").attr("disabled", true);
//		$("button[name='"+name+"Edit']").attr("disabled", true);
//		$("button[name='"+name+"Remove']").attr("disabled", true);
		$("a[name='"+name+"Add']").attr("customizedDisabled", true);
		$("a[name='"+name+"Edit']").attr("customizedDisabled", true);
		$("a[name='"+name+"Remove']").attr("customizedDisabled", true);
		$("div[name='manageQuestion']").attr("customizedDisabled", true);
		
//		$("button[name='faqBackToCate']").attr("disabled",true);
		$("a[name='faqBackToCate']").attr("customizedDisabled",true);

//		$("button[name='"+name+"Save']").attr("disabled", false);
		$("a[name='"+name+"Save']").attr("customizedDisabled", false);
		if($("button[name='"+name+"Eng']").attr('style') != "" && $("button[name='"+name+"Eng']").attr('style') != undefined){
			$("button[name='"+name+"Eng']").attr({style:"", disabled: true});
		}
		if($("button[name='"+name+"Zh-HK']").attr('style')!="" && $("button[name='"+name+"Zh-HK']").attr('style')!=undefined){
			$("button[name='"+name+"Zh-HK']").attr({style:"", disabled: true});
		}
		if($("button[name='"+name+"Zh-CN']").attr('style')!="" && $("button[name='"+name+"Zh-CN']").attr('style')!=undefined){
			$("button[name='"+name+"Zh-CN']").attr({style:"", disabled: true});
		}
		this.editMode=true;
		this.buttonColorDisable();
	},
	outOfUpdateOrAddOrRemoveMode : function(name){
//		$("button[name='"+name+"Save']").attr("disabled", true);
		$("a[name='"+name+"Save']").attr("customizedDisabled", true);
		$("div[name='manageQuestion']").attr("customizedDisabled", false);

//		$("button[name='faqBackToCate']").attr("disabled",false);
		$("a[name='faqBackToCate']").attr("customizedDisabled", false);
		
//		$("button[name='"+name+"Up']").attr("disabled", false);
//		$("button[name='"+name+"Down']").attr("disabled", false);
		$("a[name='"+name+"Up']").attr("customizedDisabled", false);
		$("a[name='"+name+"Down']").attr("customizedDisabled", false);
		
		$("button[name='clientSetupListAll']").attr("disabled", false);
		$("button[name='clientSetupListActive']").attr("disabled", false);
		$("button[name='clientSetupListInactive']").attr("disabled", false);
		
		this.editMode=false;
		if($("button[name='"+name+"Eng']").is(':disabled')){
			$("button[name='"+name+"Eng']").attr("disabled", false);
			$("button[name='"+name+"Eng']").attr("style","background:#737173");
		}
		if($("button[name='"+name+"Zh-HK']").is(':disabled')){
			$("button[name='"+name+"Zh-HK']").attr("disabled", false);
			$("button[name='"+name+"Zh-HK']").attr("style","background:#737173");
		}
		if($("button[name='"+name+"Zh-CN']").is(':disabled')){
			$("button[name='"+name+"Zh-CN']").attr("disabled", false);
			$("button[name='"+name+"Zh-CN']").attr("style","background:#737173");
		}
		
		this.buttonColorDisable();
		
		//$("a[page]").show();
	},
	buttonColorDisable : function() {
		//$("body").find("[disabled]").each(function() {
//		$("button").each(function() {
//			//var abc = $(this).attr("disabled");
//			$(this).removeClass();
//			//$(this).addClass("buttonDisabled");
//			
//		});

		$("button:disabled").each(function() {
			//var abc = $(this).attr("disabled");
			$(this).removeClass();
			$(this).addClass("buttonDisabled");
			
			if($(this).attr("name") == "manageQuestion") {
				$(this).find("td").removeClass();
				$(this).find("td").addClass("questionBtnDisabled");
			}
			
		});
		$("button:enabled").each(function() {
			//var abc = $(this).attr("disabled");
			$(this).removeClass();
			if($(this).attr("name") == "manageQuestion") {
				$(this).find("td").removeClass();
				$(this).find("td").addClass("questionButton");
			}
			//$(this).addClass("buttonDisabled");
			
		});
		
		$("div[customizedDisabled]").each(function() {			
			if($(this).attr("name") == "manageQuestion") {
				var checked = $(this).attr("customizedDisabled");
				if(checked == "true") {
					$(this).removeClass();
					$(this).addClass("doubleLineGreyButton");
				} else {
					$(this).removeClass();
					$(this).addClass("doubleLineButton");
				}
			}
			
		});
		
		$("a[customizedDisabled]").each(function(){
			var checked = $(this).attr("customizedDisabled");
			if(checked == "true") {
				$(this).removeClass("redDivButton").addClass("greyDivButton");
				if($(this).is("[editMode]")) {
					$(this).addClass("editMode");
				}
			} else if (checked == "false") {
				$(this).removeClass("greyDivButton").addClass("redDivButton");
				if($(this).is("[editMode]")) {
					$(this).removeClass("editMode");
				}
			}
		});
		
		//var abc = $("button").attr("msgid");
	},
	changeMode : function(name){
		var status = $("[status='delete']").length + $("[status='add']").length + $("[status='update']").length;
		if(status==0){
			this.outOfUpdateOrAddOrRemoveMode(name);
		} else {
			this.enterToUpdateOrAddOrRemoveMode(name);
		}
	},
	adminUpdateOrDeleteMode : function(name, action, url, data, id, div) {
		var self = this;

		return self.render(
				url,
				div + id,
				data
		).done(function(){
			$("#"+div + id).attr("status" , action);
			self.enterToUpdateOrAddOrRemoveMode(name);
		});
	},
	/**
	* @param step clicked tr's customized attribute
	* @param action   up or down
	*/
	upDownMethod : function(name, step, action, prev){
		var targetStep,
		step = parseInt(step),
		dtd = $.Deferred();
	
		this.enterToUpOrDownMode(name);
		
		if (action == "up") {
			targetStep = step - 1;
		} else if (action == "down") {
			targetStep = step + 1;
		} else {
			return;
		}

		var sourceHtml = $("#" + prev + " [step=" + step + "]").html();
		
		if($("#" + prev + " [step=" + targetStep + "]").length == 0){
			return;
		}
		
		var targetHtml = $("#" + prev + " [step=" + targetStep + "]").html();

		$("#" + prev + " [step=" + targetStep + "]").empty();
		$("#" + prev + " [step=" + targetStep + "]").append(sourceHtml);

		if ($("#" + prev + " [step=" + targetStep + "]").find("[isBackground='true']").length) {
			$("#" + prev + " [step=" + targetStep + "]").css({
				"background" : "yellow"
			});
		} else {
			$("#" + prev + " [step=" + targetStep + "]").attr({
				"style" : ""
			});
		}

		$("#" + prev + " [step=" + step + "]").empty();
		$("#" + prev + " [step=" + step + "]").append(targetHtml);

		if ($("#" + prev + " [step=" + step + "]").find("[isBackground='true']").length) {
			$("#" + prev + " [step=" + step + "]").css({
				"background" : "yellow"
			});
		} else {
			$("#" + prev + " [step=" + step + "]").attr({
				"style" : ""
			});
		}
		$("#" + prev).attr("hasUpDown",true);
		dtd.resolve();
		return dtd;
	},
	adminCancelMethod : function(name, url, data, id, div){
		var self = this;
		this.editMode=false;
		return this.render(
				url,
				div + id ,
				data
		).done(function(){
			$("#"+div + id).attr("status" , "");
			self.changeMode(name);
		});
	}
	
	
}); 

adminComponent.prototype.constructor = adminComponent;

