var common = function(){
	var urllink = location.toString();
	var caseType = urllink.substring(urllink.lastIndexOf('\/')+1, urllink.lastIndexOf('.'));
	if(caseType.indexOf('.') == 0) caseType = 'index';
	var obj = Ext.urlDecode(urllink.substring(urllink.lastIndexOf('?')+1, urllink.length));
	var tip = null;
	var winBox = null;
	var textFields = ['username', 'userpass', 'EMail', 'userID', 'keyword'];
	var exp = {'Period': '{Year4}/{Month4}~{Year5}/{Month5}', 'Old': '', 'CName': '', 'Dept': '', 'Title': '', 'Cause': '', 'Notice': '', 'Work': ''};
	var expMust = {'CName': '公司/機構'};
	
	function changeToExtField(fields){
//		var text = (Ext.isIE) ? fields.bvalue : getAbrite(fields, 'bvalue');
		var type = (fields.type == 'text') ? 'TextField' : 'TextArea';
		var indexField = new Ext.form[type]({
			emptyClass: '', 
			emptyText: fields.value, 
			fieldClass: '',
			focusClass: '',
			id: 'ext_'+fields.id, 
			applyTo: fields.id
		});
		indexField.getEl().removeClass('x-form-text');
		indexField.getEl().removeClass('x-form-empty-field');
		var btn = Ext.get(fields).parent('table').child('input[type=image]', true);
		if(btn) Ext.get(fields).addKeyListener({key:13}, btn.onclick);
	}
	
	function changeBackColor(elt, dot, condition, num){
		num = num ? num : 0;
		var next = elt.next(condition);
		elt.dom.style.backgroundColor = dot[num];
		if(next) changeBackColor(next, dot, condition, (num+1)%2);
	}

	function getTemplate(xtpl){
		var word = (Ext.getDom(xtpl)) ? Ext.getDom(xtpl).innerHTML : xtpl;
		word = word.replace(/\%7B/g, '{').replace(/\%7D/g, '}');
		return word.replace(/TPL/g, 'tpl').replace(/ > /g, ' &gt; ').replace(/ < /g, ' &lt; ');
	}
	
	return {
		backupTpl: '',
		backupData: [],
		expData: [], 
		inxPoint: 0, 
		
		init: function(){
			for(x in textFields){
				if(!Ext.get(textFields[x])) continue;
				changeToExtField(Ext.getDom(textFields[x]));
			}
			switch(caseType){
				case 'index':
					Ext.get('apDiv1').setStyle({'padding-top': '0px', 'top': Ext.get('apDiv1').getStyle('padding-top')});
					break;
					
				case 'seekers':
					if(!obj.Type) return;
					if(obj.Type == 'update') {
						Ext.getDom('Address').value = Ext.getDom('Address').value.replace(Ext.getDom('countyText').value, '');
						Ext.getDom('Address').value = Ext.getDom('Address').value.replace(Ext.getDom('area').value, '');
					}
					if(obj.Type == 'resume'){
						var v = Ext.util.JSON.decode('['+Ext.getDom('Experience').value+']');
						for(x in v){
							if(isNaN(parseInt(x))) continue;
							this.expData.push(v[x]);
						}
						if(this.expData.length) this.changeExp(this.inxPoint, true);
						if(this.expData.length == 0){ Ext.get('prev').hide(); Ext.get('next').hide(); }
						this.tpl = getTemplate('tplList');
						var v = Ext.util.JSON.decode('['+Ext.getDom('Language').value+']');
						if(v.length){
							for(var i=0;i<v.length;i++){
								Ext.DomHelper.append('tplList', {tag: 'div', html: String.format(this.tpl, i)}, true).insertBefore('moreLang');
								for(x in v[i]) Ext.getDom(x+i).value = v[i][x];
							}
						}else{
							Ext.DomHelper.append('tplList', {tag: 'div', html: String.format(this.tpl, 0)}, true).insertBefore('moreLang');
						}
					}
					if(obj.Type == 'register' || obj.Type == 'update'){
						var settings = {
							flash_url: 'swfupload.swf', 
							upload_url: 'uploads.php',
							file_size_limit: '2 MB',
							file_types: "*.jpg;*.gif;*.png",
							file_types_description: "Image Files",
							post_params: {'fn': Ext.getDom('imgThumb').value}, 
							button_image_url: 'images/bot_btn.jpg', 
							button_placeholder_id: 'uploadBtn', 
							button_width: 63, 
							button_height: 19, 
							button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
							button_cursor: SWFUpload.CURSOR.HAND,
							button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE, 
							file_queue_error_handler: function(){alert('file queue error!!');},
							file_dialog_complete_handler: common.uploadData,
							upload_progress_handler: common.uploadProgress,
							upload_error_handler: common.uploadError,
							upload_success_handler: common.uploadSuccess,
							upload_complete_handler: common.uploadComplete
						}
						this.uploadBtn = new SWFUpload(settings);
					}
					break;
					
				case 'freshman':
					var display = Ext.query('div[class=title_a]');
					for(var i=0;i<display.length;i++){
						Ext.get(display[i]).setStyle({
							'display': 'none', 
							'visibility': 'visible'
						});
					}
					if(obj.Type == 'qa' && urllink.indexOf('#') != -1) this.openAnswer(urllink.substr(urllink.lastIndexOf('#')+1))
					if(Ext.get('faqlist')) this.standByFaq();
			}
			if(Ext.get('seekerList')){
				var c = 'table[class=hr_list_bgcolor]';
				var f = Ext.get('seekerList').first(c);
				if(f) changeBackColor(f, ['#FFFFFF', '#F5ECEE'], c);
			}
			if(Ext.get('setJobList')){
				var c = 'table[class=setList]';
				var f = Ext.get('setJobList').first(c);
				if(f) changeBackColor(f, ['#FFFFFF', '#DBDBDB'], c);
			}
			if(obj.Type == 'resume' || obj.Type == 'update' || obj.Type == 'complex'){
				if(!Ext.getDom('checklist')) return;
				var cb = Ext.util.JSON.decode('{' + Ext.getDom('checklist').value + '}');
				for(i in cb){
					if(i == 'Sex') this.needMilitary(cb[i] == '男' ? true : false);
					var multi = typeof(cb[i]) == 'string' ? [cb[i]] : cb[i];
					var rd = document.forms[0][i];
					for(var m=0;m<multi.length;m++){
						for(var j=0;j<rd.length;j++){ if(rd[j].value == multi[m]) rd[j].checked = true; }
					}
				}
				var dl = Ext.util.JSON.decode('{' + Ext.getDom('droplist').value + '}');
				for(x in dl) Ext.getDom(x).value = dl[x];
			}
		}, 
		
		uploadData: function(inx, num){
			common.uploadBtn.startUpload();
			common.uploadBtn.setButtonDisabled(true);
		},
		
		uploadProgress: function(file, complate, total){
			Ext.getDom('Photo').value = Math.round(complate/total*10000)/100+'%';
		},
		
		uploadError: function(file, code, msg){
			alert(code+': '+msg);
		},
		
		uploadSuccess: function(file, data){
			var b = Ext.query('[class=register_head_bg]')[0];
			var img = Ext.get(b).child('img') ? Ext.get(b).child('img').dom : Ext.DomHelper.append(b, {tag: 'img', id: 'photo'});
			img.src = 'uploads.php?Img='+Ext.getDom('imgThumb').value+'&ID='+Math.random();
		},
		
		uploadComplete: function(file){
			common.uploadBtn.setButtonDisabled(false);
			Ext.getDom('Photo').value = '';
		},
		
		needMilitary: function(bool){
			var rd = document.forms[0]['Military'];
			if(!rd) return;
			for(var i=0;i<rd.length;i++){
				if(rd[i].value != '免役') { rd[i].disabled = !bool; }else{ if(!bool) rd[i].checked = true; }
			}
		},
		
		standByFaq: function(){
			if(!tip) tip = Ext.DomHelper.append(Ext.getBody(), {tag: 'div', style: 'float:left;position:absolute;width:400px;'}, true);
			this.backupTpl = getTemplate('faqlist');
			Ext.get('faqlist').remove();
			Ext.getDoc().on('mouseover', this.doFaqBox, this, true);
		},
		
		openAnswer: function(target){
			var area = Ext.get(target).parent('div').next();
			var animate = area.anims ? area.anims : 'slideIn';
			area[animate]('t', {useDisplay: true, easing: 'easeNone'});
			area.anims = (animate == 'slideOut') ? 'slideIn' : 'slideOut';
		}, 
		
		doFaqBox: function(e, t, o){
			if(t.id == 'mainMap') return;
			if(e.within(Ext.get('Map2')) || e.within(tip) || e.within(Ext.get('mainMap').parent())) return;
			tip.hide();
		},
		
		showFaqData: function(uid){
			tip[uid ? 'show' : 'hide']();
			var tpl = new Ext.XTemplate(this.backupTpl);
			tip.update(tpl.apply(this.backupData[uid])).alignTo('mainMap', 'l-l');
			var a = Ext.query('a', tip.dom);
			for(x in a){
				if(isNaN(parseInt(x))) continue;
				a[x].style.color = '#FFFFFF';
			}
		},
		
		callFaqData: function(uid){
			if(!this.backupData[uid]){
				var cb = function(rspn, option){
					this.backupData[uid] = Ext.util.JSON.decode(rspn.responseText);
					this.showFaqData(uid);
				}
				var cn = new Ext.data.Connection({url:'getdata.php?Type=getFaq'}).request({
					params: {'paramID': uid}, 
					method: 'POST', success: cb, scope: this
				});
			}else{
				this.showFaqData(uid);
			}
		}, 
		
		addJob: function(uid){
			var title = Ext.query('a[href$=ID='+uid+']', Ext.getDom('jobList'))[0];
			var name = Ext.util.Format.stripTags(title ? title.innerHTML : Ext.getDom('jobList').innerHTML);
			Ext.Msg.confirm('應徵', '你確定要應徵「'+name+'」這個職缺', function(btn, text){
				if(btn != 'yes') return;
				cb = function(rspn, option){
//					alert(rspn.responseText);
					var JSON = Ext.util.JSON.decode(rspn.responseText);
					this.alertMsg(JSON[1], JSON[2], JSON[3]);
				}
				var cn = new Ext.data.Connection({url:'mail.php?Type=addJob'}).request({
					params: {'paramID': uid}, method: 'POST', success: cb, scope: this
				});
			}, this);
		},
		
		adminLogin: function(){
			var user = Ext.getCmp('ext_username').getValue();
			var pass = Ext.getCmp('ext_userpass').getValue()
			if(user == '' || pass == '') {
				this.alertMsg('error', '欄位不得為空!!');
				return;
			}
			var cb = function(rspn, option){
				var JSON = Ext.util.JSON.decode(rspn.responseText);
				if(JSON.isLogin){
					location.href = 'manager.php';
				}else{
					this.alertMsg('error', JSON.text);
				}
			}
			var cn = new Ext.data.Connection({url:'getdata.php?Type=adminLogin'}).request({
				params: {'paramID': user, 'passID': pass}, 
				method: 'POST', success: cb, scope: this
			});
		},
		
		seekerLogin: function(){
			var user = Ext.getCmp('ext_username').getValue();
			var pass = Ext.getCmp('ext_userpass').getValue()
			if(user == '' || pass == '') {
				this.alertMsg('error', '欄位不得為空!!');
				return;
			}
			var cb = function(rspn, option){
				var JSON = Ext.util.JSON.decode(rspn.responseText);
				if(JSON.isLogin){
					location.href = JSON.url;
				}else{
					this.alertMsg('error', JSON.text);
				}
			}
			var cn = new Ext.data.Connection({url:'getdata.php?Type=skLogin'}).request({
				params: {'paramID': user, 'passID': pass}, 
				method: 'POST', success: cb, scope: this
			});
		},
		
		gotoLogin: function(){
			var cb = function(rspn, option){location.href = 'seekers.php';}
			var cn = new Ext.data.Connection({url:'getdata.php?Type=rememberURI'}).request({
				params: {'paramID': urllink}, method: 'POST', success: cb, scope: this
			});
		},
		
		mailForget: function(){
			var cb = function(rspn, option){
				var html = rspn.responseText.replace('admin', 'seeker');
				if(!winBox) this.createWinMsg(html);
				winBox.show();
			}
			var cn = new Ext.data.Connection({url:'Library/forgetmail.lbi'}).request({
				scope: this, success: cb
			});
		},
		
		sendPassMail: function(type){
			alert(type);
		},
		
		alertMsg: function(title, msg, target){
			Ext.Msg.alert(title, msg, function(btn, text){
				if (btn == 'ok' && target) eval(target); 
			}, this);
		},
		
		createWinMsg: function(html){
			winBox = new Ext.Window({modal: true, headerAsText: false, shadow: true, html: html, width: 330,
    			resizable: false, closeAction: 'hide', layout:'fit', animate: true, shim: false, 
    			bodyStyle: {'padding': '0px 10px 20px 10px', 'background-color': '#FFF'}
			});
			winBox.on('show', function(p){
				winBox.center();
				if(!winBox.changeText){
					changeToExtField(Ext.getDom('userID'));
					changeToExtField(Ext.getDom('EMail'));
					winBox.changeText = true;
				}
			});
		},
		
		loginOut: function(){
//			var cn = new Ext.data.Connection({url:'getdata.php?Type=getFaq'});
		}, 
		
		searchKey: function(target){
			var key = Ext.getCmp('ext_'+target).getValue().trim();
			if(key == ''){ if(Ext.getDom(target).value == ''){this.alertMsg('error', '關鍵字不得為空!!');} return; }
			location.href = 'manager.php?Type=search&Keyword='+encodeURIComponent(key);
		},
		
		verifyCode: function(){
			if(!Ext.get('request')) return;
			if(obj.Type == 'resume'){
				this.saveExp(this.inxPoint, true);
				var len = this.expData.length;
				var years = 0;
				for(var i=0;i<len;i++){
					for(y in expMust){
						if(this.expData[i][y] == ''){
							if(i+1 == len){ 
								this.expData.splice(i, 1); 
							}else{ 
								this.changeExp((i-this.inxPoint));
								this.alertMsg('error', expMust[y]+'不得為空', 'Ext.get(\''+y+'\').focus()');
								return;
							}
						}
					}
					if(this.expData[i]) years += isNaN(parseInt(this.expData[i]['Old'])) ? 0 : parseInt(this.expData[i]['Old']);
				}
				var v = Ext.util.JSON.encode(this.expData);
				Ext.getDom('Year').value = years;
				Ext.getDom('Experience').value = v.substring(1, v.length-1);
				var i = 0; var arr = [];
				while(Ext.get('Skill'+i)){
					v = Ext.getDom('Skill'+i).value.trim().replace(/ , /g, ', ');
					i++; if(v == '') continue; arr.push(v);
				}
				Ext.getDom('Skill').value = arr.join(' , ');
				var j = 0; var arr = [];
				while(Ext.get('lang'+j)){
					v = Ext.getDom('lang'+j).value.trim();
					i = j; j++; 
					if(v == '') continue; 
					arr.push({'lang': v, 'speak': Ext.getDom('speak'+i).value, 'study': Ext.getDom('study'+i).value, 
						'write': Ext.getDom('write'+i).value, 'listen': Ext.getDom('listen'+i).value});
				}
				v = Ext.util.JSON.encode(arr);
				Ext.getDom('Language').value = v.substring(1, v.length -1);
				Ext.getDom('request').submit();
			}else{
				var cb = function(rspn, option){
					var JSON = Ext.util.JSON.decode(rspn.responseText);
					if(JSON){
						Ext.getDom('request').submit();
					}else{
						this.alertMsg('error', '該帳號已有人使用!!');
					}
				}
				if(obj.Type == 'update'){
					Ext.getDom('request').submit();
				}else{
					var cn = new Ext.data.Connection({url:'getdata.php?Type=isUser'}).request({
						params: {'paramID': Ext.getDom('Username').value}, 
						method: 'POST', success: cb, scope: this
					});
				}
			}
		}, 
		
		addExperience: function(){
			var inx = this.expData.length - this.inxPoint - 1;
			if(inx > 0) this.changeExp(inx);
			for(i in expMust){
				var target = Ext.getDom(i);
				if(target && target.value == ''){ this.alertMsg('error', expMust[i]+'不得為空', 'Ext.get(\''+i+'\').focus()'); return; }
			}
			this.saveExp(this.inxPoint);
			this.inxPoint = this.expData.length;
			Ext.get('prev').show();
		}, 
		
		changeExp: function(inx, reload){
			if(!reload) this.saveExp(this.inxPoint);
			this.inxPoint += inx;
			var data = this.expData[this.inxPoint];
			for(x in data){
				if(exp[x] != '') {
					contact = [];
					var test = exp[x].replace(/\{(\w+)\}/g , function(m, i){ contact.push(i); return i;});
					var arr = data[x].replace('~', '/').split('/');
					for(var i=0;i<arr.length;i++){ Ext.getDom(contact[i]).value = arr[i]; }
				}else{
					Ext.getDom(x).value = data[x];
				}
			}
			Ext.get('prev')[(this.inxPoint == 0 || this.expData.length == 0) ? 'hide' : 'show']();
			Ext.get('next')[(this.inxPoint == this.expData.length-1 || this.expData.length == 0) ? 'hide' : 'show']();
		},
		
		saveExp: function(inx, ncr){
			var data = {};
			for(x in exp){
				if(exp[x] != '') {
					data[x] = exp[x].replace(/\{(\w+)\}/g , function(m, i){
						var v = Ext.getDom(i).value;
						if(!ncr) Ext.getDom(i).value = '';
						return v;
					});
				}else{
					data[x] = Ext.getDom(x).value;
					if(!ncr) Ext.getDom(x).value = '';
				}
			}
			if(this.expData[inx]){ this.expData[inx] = data; }else{ this.expData.push(data); }
		}, 
		
		createDataView: function(){
			var i = 0;
			while(Ext.get('lang'+i)){
				if(Ext.getDom('lang'+i).value == '') { this.alertMsg('error', '第'+(i+1)+'行的語文不得為空', 'Ext.get(\'lang'+i+'\').focus()'); return; }
				i++;
			}
			Ext.DomHelper.append('tplList', {tag: 'div', html: String.format(this.tpl, i)}, true).insertBefore('moreLang');
		}, 
		
		complexSearch: function(){
			var condition = ''; var o = {}; var c = {}; var s = {};
			var cb = Ext.query('input:checked', Ext.getDom('request'));
			for(var i=0;i<cb.length;i++){
				if(o[cb[i].name]){ 
					o[cb[i].name] += ' or '+cb[i].name+" = '"+cb[i].value+"'"; 
					if(typeof(c[cb[i].name]) == 'string'){ c[cb[i].name] = [c[cb[i].name], cb[i].value]; } else { c[cb[i].name].push(cb[i].value); }
				} else { 
					o[cb[i].name] = cb[i].name+" = '"+cb[i].value+"'";
					c[cb[i].name] = cb[i].value;
				}
			}
			var v = Ext.util.JSON.encode(c);
			Ext.getDom('checklist').value = v.substring(1, v.length -1);
			for(v in o) condition += ' and ('+o[v]+')';
			var dl = Ext.query('select', Ext.getDom('request'));
			var arr = ['Address', 'BrithDate'];
			for(var i=0;i<dl.length;i++){
				if(dl[i].value == '') continue;
				condition += ' and '+dl[i].name+(arr.indexOf(dl[i].name) == -1 ? (" = '"+dl[i].value+"'") : (" Like '"+dl[i].value+"%'"));
				s[dl[i].name] = dl[i].value;
			}
			var v = Ext.util.JSON.encode(s);
			Ext.getDom('droplist').value = v.substring(1, v.length -1);
			if(condition == '') {
				alert('請於搜尋中填入條件!!')
				return false;
			}else{
				Ext.getDom('Condition').value = condition;
				return true;
			}
		}, 
		
		addFavorites: function(btn, uname, state){
			if(!state){ 
				this.delFavorites(btn, uname, 'addFave');
			}else{
				btn.src = 'images/bot_hr_del.png';
				btn.onclick = function(){ common.delFavorites(btn, uname); }
			}
		}, 
		
		delFavorites: function(btn, uname, state){
			var state = (state && state == 'addFave') ? state : 'delFave';
			var cb = function(rspn, option){
				if(!eval(rspn.responseText)) return;
				if(state == 'addFave'){
					this.addFavorites(btn, uname, true);
				}else{
					btn.src = 'images/bot_hr_add.png';
					btn.onclick = function(){ common.addFavorites(btn, uname); }
				}
			}
			var cn = new Ext.data.Connection({url:'getdata.php?Type='+state}).request({
				params: {'paramID': uname}, method: 'POST', success: cb, scope: this
			});
		}, 
		
		addNewJob: function(){
			if(!this.tpl) this.tpl = getTemplate('tplList');
			var tb = Ext.get('tplList').update(String.format(this.tpl, 0)).child('table');
			if(Ext.query('[id=ID_0]', Ext.getDom('setJobList')).length) return;
			if(Ext.get('setJobList').first('table')){
				tb.insertBefore(Ext.get('setJobList').first('table[class=setList]')).show(true);
			}else{
				Ext.get('setJobList').appendChild(tb).show(true);
			}
		},
		
		doJobEdit: function(objs, state){
			if(state == 'all' && Ext.query('input:checked', Ext.getDom('setJobList')).length == 0) objs.value = '';
			if(objs.value == '') return;
			if(objs.value == 'del'){
				Ext.Msg.confirm('刪除資料', '你確定要刪除這些資料!!', function(btn, text){
					if(btn == 'yes') this.runJobEdit(objs, state); 
				}, this);
			} else { this.runJobEdit(objs, state); }
		}, 
		
		runJobEdit: function(btn, state){
			var arr = []; var boxs = []; var c = 'table[class=setList]'; var v = btn.value; var s = {};
			if(state == 'all'){
				var cb = Ext.query('input:checked', Ext.getDom('setJobList'));
				for(var i=0;i<cb.length;i++){
					arr.push(cb[i].value);
					boxs.push(Ext.get(cb[i]).parent(c));
					if(v != 'del') boxs[i].child('select[id^=isDisplay]', true).value = v;
				}
			}else{
				boxs.push(Ext.get(btn).parent(c));
				var cb = boxs[0].child('input[id^=ID]');
				arr.push(cb.dom.value);
				if(v == 'save'){
					var num = cb.id.replace('ID', '');
					var cont = Ext.query('[name$='+num+']');
					for(var i=0;i<cont.length;i++){ 
						var n = cont[i].name.replace(num, '');
						if(n.indexOf('baseYear') != -1 || n.indexOf('Needs') != -1){
							if(isNaN(parseInt(cont[i].value))) {
								Ext.Msg.alert('error', '該欄位請輸入數字!!', function(btn){cont[i].select()});
								return;
							}
							cont[i].value = parseInt(cont[i].value);
						}
						s[n] = cont[i].value; 
					}
				}
			}
			if(state == 'all') btn.value = '';
			if(!arr.length) return;
			var cb = function(rspn, option){
//				alert(rspn.responseText);
				if(!eval(rspn.responseText)) return;
				if(v == 'del'){
					var first = Ext.get('setJobList').first(c);
					Ext.getDom('jobNumber').innerHTML = parseInt(Ext.getDom('jobNumber').innerHTML) - boxs.length;
					while(first){ if(boxs.indexOf(first) != -1) { first = first.next(c); } else { break; } }
					if(!first) {
						Ext.get('setJobList').remove();
					}else{
						for(var i=0;i<boxs.length;i++) boxs[i].remove();
						changeBackColor(first, ['#FFFFFF', '#DBDBDB'], c);
					}
				}else if(v == 'save' && s.ID == 0) {
					var first = Ext.get('setJobList').first(c);
					var box = Ext.query('[id$=_0]', first.dom);
					for(var i=0;i<box.length;i++){
						if(box[i].name) box[i].name = box[i].name.replace('_0', '_'+rspn.responseText);
						box[i].id = box[i].id.replace('_0', '_'+rspn.responseText);
					}
					changeBackColor(first, ['#FFFFFF', '#DBDBDB'], c);
				}
			}
			s.paramID = arr.join(',');
			s.State = v;
			var cn = new Ext.data.Connection({url:'getdata.php?Type=editJob'}).request({
				params: s, method: 'POST', success: cb, scope: this
			});
		},
		
		doWorkStatus: function(objs, state){
			if(state == 'all' && Ext.query('input:checked', Ext.getDom('seekerList')).length == 0) objs.value = '';
			if(objs.value == '') return;
			if(objs.value == 'del'){
				Ext.Msg.confirm('刪除資料', '你確定要刪除這些資料!!', function(btn, text){
					if(btn == 'yes') this.runWorkStatus(objs, state); 
				}, this);
			} else { this.runWorkStatus(objs, state); }
		}, 
		
		runWorkStatus: function(btn, state){
			var arr = []; var boxs = []; var c = 'table[class=hr_list_bgcolor]'; var v = btn.value;
			if(state == 'all'){
				var cb = Ext.query('input:checked', Ext.getDom('seekerList'));
				for(var i=0;i<cb.length;i++){
					arr.push(cb[i].value);
					boxs.push(Ext.get(cb[i]).parent(c));
					if(v != 'del') boxs[i].child('select', true).value = v;
				}
			}else{
				boxs.push(Ext.get(btn).parent(c));
				arr.push(boxs[0].child('input[id^=checkbox]').dom.value);
			}
			if(state == 'all') btn.value = '';
			if(!arr.length) return;
			var cb = function(rspn, option){
				if(!eval(rspn.responseText)) return;
				if(v == 'del'){
					var first = Ext.get('seekerList').first(c);
					Ext.getDom('seekersNumer').innerHTML = parseInt(Ext.getDom('seekersNumer').innerHTML) - boxs.length;
					while(first){ if(boxs.indexOf(first) != -1) { first = first.next(c); } else { break; } }
					if(!first) {
						Ext.get('seekerList').remove();
					}else{
						for(var i=0;i<boxs.length;i++) boxs[i].remove();
						changeBackColor(first, ['#FFFFFF', '#F5ECEE'], c);
					}
				}
			}
			var cn = new Ext.data.Connection({url:'getdata.php?Type=setSeekers'}).request({
				params: {'paramID': arr.join(','), 'State': v}, 
				method: 'POST', success: cb, scope: this
			});
		}, 
		
		addSeekerNotice: function(target){
			var cb = function(rspn, option){
				(eval(rspn.responseText)) ? this.alertMsg('success', '修改完畢!!') : this.alertMsg('error', '修改錯誤!!');
			}
			var cn = new Ext.data.Connection({url:'getdata.php?Type=setNotice'}).request({
				params: {'paramID': obj.ID, 'Notice': Ext.getDom(target).value}, 
				method: 'POST', success: cb, scope: this
			});
		}
	}
}();

Ext.onReady(common.init, common);

function changeday(y, m, d){
	var monthday = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22',
		'23','24','25','26','27','28','29','30','31'];
	y = Ext.getDom(y); m = Ext.getDom(m); d = Ext.getDom(d);
	var tmp = new Date(y.value, m.value, 0); 
//	var selectday = (getday) ? getday - 1 : theday.value - 1;
	var haveday = tmp.getDate();
	
	for (var m= 0; m < d.options.length; m++) {
		d.options[m] = null;
	}
	for (var i = 0; i < haveday; i++) {
		d.options[i] = new Option(i+1, monthday[i]);
//		if (i == selectday) d.options[i].selected = true;
	}
}