/**
 * @author WEDO2
 * @Date created 2009/03/22 
 */

var objRecruitment = {
	aryData:null,
	indusId : 0,
	indusType : 0,
	clicked1 : false,
	test : 0,
	textSearch : '',
	nameCheckAll : '',
	open_expand_criteria : function (id_criteria) {
		var x = $("#li_"+id_criteria).offset().left;
		var y = $("#li_"+id_criteria).offset().top;
		x += 232;
		$(".expand").css({'display':'none'});
		$("#"+id_criteria).css({'display':'block','top':y,'left':x});
		return false;
	}
	,
	
	close_expand_criteria : function (id_criteria) {
		$("#"+id_criteria).css('display','none');
		return false;
		}
		
	,
	
	select_expand_criteria : function (hiddenI,value,name)
	{
		value = parseInt(value);
		hiddenI = jQuery.trim(hiddenI);
		name=jQuery.trim(name);
		
		if (hiddenI.length <= 0 || name.length <= 0)
		{
			return false;
		}
		$("#span_" + hiddenI).html(name);
		$("#"+hiddenI).val(value);
		//close all
		$(".expand").css('display','none');
		return false;
	}
	
	,
	
	choice_wage : function ()
	{
		var text = '';
		var min_wage = 0;
		var max_wage = 0;
		var currency = 'vnd';
		
		if($("input[name='currency']:checked").val() != 'usd')
		{
			currency = 'vnd';
		}
		else
		{
			currency = 'usd';
		}
		$("input[name='hidden_currency']").val(currency);
		min_wage = parseInt($("#min_wage").val());
		max_wage = parseInt($("#max_wage").val());
		if (min_wage)
		{
			text = 'Min: ' + min_wage + ' (' + currency + ')';
			$("input[name='min_wage']").val(min_wage);
		}
		if (max_wage)
		{
			text += ' Max: '+ max_wage + ' (' + currency + ' )';
			$("input[name='max_wage']").val(max_wage);
		}
		if (text.length > 0)
		{
			$("#span_wage").html(text);
		}
		$(".expand").css('display','none');
		return false;		
		
	}
	
	,
	
	changeTypeSearch : function (type)	
	{
		if (type != 1){
			type = 2;
		}
		$(".expand").css('display','none');
		var container = $("#ul_type_search_" + type).html();
		$("#xyz").html(container);
		//objRecruitment.test = $('input[name="typeSearch"]:radio:checked').val();
		//objRecruitment.test = type;
		//alert(objRecruitment.test);
		//alert(type);
	}

	
	, 
	// NghiaPT add Multiselect transfer function
	addIndustries : function (id1,id2,limit)
	{
		if(typeof(limit) =='undefined') {
			limit = 3;
		}
		 var arrSelect = [];
   	     var subArrSelect = [];
		 var size1 = $('#' + id1 + ' option:selected').size();
		 var size2 = 0;
		 size2 = $('#' + id2 + ' option').size();
		 if(size2 >= limit) {
			return false;
		}
		 if(size2 < limit){ 
		 	if((size1 + size2) > limit)
				$('#' + id1 + ' option:selected').each(function(i){
					if((size2 + i) < limit){
						arrSelect[i] = $(this).val(); 
					}
				});
			else
				$('#' + id1 + ' option:selected').each(function(i){
					arrSelect[i] = $(this).val();
				})	
			$('#' + id2 + ' option').each(function(i){
				subArrSelect[i] = $(this).val();
			});
			$.merge( subArrSelect, arrSelect );
			var len = subArrSelect.length;
			var tmp = ''; 
			for( var i=0; i<len ; i++)
				for( var j=i+1; j< len; j++)
					if(subArrSelect[i] > subArrSelect[j]){
						tmp = subArrSelect[i]; 
						subArrSelect[i] = subArrSelect[j];
						subArrSelect[j] = tmp;
					}
			var str = '';
			var valOpt = '';
			var textOpt = '';
			var optId2 = '';
			for(i=0; i<len; i++){
				valOpt = $('#' + id1 + ' option[value=' + subArrSelect[i] + ']').val();
				textOpt = $('#' + id1 + ' option[value=' + subArrSelect[i] + ']').text();
				optId2 += '<option value='+valOpt+'>'+textOpt+'</option>';
				$('#' + id1 + ' option[value=' + subArrSelect[i] + ']').attr('disabled',true).removeAttr('selected');
			}
			$('#' + id2).html(optId2);	
		}
	}
	
	,
	
	// remove indus
	removeIndustries : function (id1,id2,limit)
	{
		if(typeof(limit) =='undefined') {
			limit = 3;
		}	
		var arrMain = [];
	    var arrSub = []; var str='';
	    $('#' + id1 + ' option').each(function(i){
			$(this).attr("selected",'');
			arrMain[i] = $(this).val();	
		});
		$('#' + id2 + ' option:selected').each(function(i){
			arrSub[i] = $(this).val();	
		});
	    var len = arrSub.length;   
    	for(i=0; i<len; i++){
			$('#' + id1 + ' option[value=' + arrSub[i] + ']').removeAttr('disabled');
			$('#' + id2 + ' option[value=' + arrSub[i] + ']').remove(); 
		}
	}
	
	,
	
	checkSubmit : function (arr,mode){
		var len = arr.length;
		if(len){
			for(var i=0; i< len; i++){
				$('#' + arr[i] + ' option').each(function(i) {
					$(this).attr("selected", "selected");
				});
			}
		}
		if(parseInt(mode)){
			objRecruitment.submitForm('formPostJob');
		}
	},
	
	dispSalary: function(value){
		if(value==2){
			$('div#show').css('display','');
		}else{
			$('div#show').css('display','none');
		}
	}
	
	,
	switchPostJob: function(id,id_image){  
		var src = '';		
		if($('#'+id).css('display') == 'none'){
			src = $('#'+id_image).attr('src').replace("add.gif", "remove.gif");
			$('#'+id_image).attr('src',src);
			$('#'+id).css('display','');
		}
		else{
			src = $('#'+id_image).attr('src').replace("remove.gif", "add.gif");
			$('#'+id_image).attr('src',src);
			$('#'+id).css('display','none');
		}
	},
	
	getPersonContact: function(urlGet){
		
		var perId = $('select#choosen_contact :selected').val();
		//alert(perId);
		$.ajax({
			type: "POST",
			url: urlGet,
			data: 'ajax=1&perId='+perId,
			success: function(xmlhttp){	
				var objData = xmlhttp.parseJSON();
				$('#personContact').html(objData.template);
			}
		});
		return;
	},
	// NghiaPT Load Ajax 5-6-2010 //
	loadTopCompany: function(linkTo) {
		objRecruitment.loadAjax('loadingAAA','result');
		var data = 'ajax=1';
		$.ajax({
			type: "POST",
			url: linkTo,
			data: data,
			success: function(xmlhttp){	
				var objData = xmlhttp.parseJSON();
				//alert(objData.template);
				$('#loadHotCompanyMain').html(objData.template);
			}
		});
		return;
	},
	
	
	getDataAutocomplate : function ()
	{
		var firstClick = $("#firstClick").val();
		if (firstClick == 0)
		{
			$("#firstClick").val(1);
		}
		if (firstClick == 0)
		{
			//Ajax
			$.ajax({
				type	: "GET",
				url		: $("#linkGetAllKeyWordSearch").val(),
				data	: "",
				success : function (xmlhttp)
				{
					var objData = xmlhttp.parseJSON();
					aryData = objData.aryData;
					var ary = new Array();
					if (aryData != null) {
						for (var i=0; i<aryData.length; i++) {
							ary[i] = aryData[i];
						}
						$("#keywords").autocompleteArray(ary,
							{
								delay:4,
								minChars:1,
								matchSubset:1,
								//onItemSelect:selectItem,
								autoFill:false,
								maxItemsToShow:20
							}
						);
					}
				}
			});
		}
		
	}
	
	,
		
	/**
	 * @function add industry
	 * @tAuthor: tuantt
	 * @Cretate date: 27/05/2010
	 * */
	
	add_industry: function () {
		var industry_name = $('#txtName').attr('value');
		var industry_order = $('#txtOrder').attr('value');
		var industry_type = $('#seType').attr("value");
		//validate
		if (typeof(industry_name)=='undefined') {
			$('#txtName').addClass('hightlight');
			return false;
		} else {$('#txtName').removeClass('hightlight');}
		
		if (typeof(industry_order)=='undefined') {
			$('#txtOrder').addClass('hightlight');
			return false;
		} 
		else {if(industry_order != ''){
			if (isNaN(industry_order) == true) {
				alert("Số thứ tự phải là số nguyên");
				return false;
			}	
		}
		else {$('#txtOrder').removeClass('hightlight');}}
		
		var data = "txtName=" + industry_name + '&txtOrder=' + industry_order + '&rdoType=' + industry_type;
		var src = "?mod=recruitment&act=addIndustry&ajax=1";
		$.ajax({
			type: "POST",
			url: src,
			data: data,
			success: function(xmlhttp){
				var objData = xmlhttp.parseJSON();
				if ((parseInt(objData.intIsOk) > 0) || (objData.intIsOk == true)) {
					alert("Thêm mới thành công");
					location.reload();
				} else {
					alert(objData.aryErrors);
				}
			}
		});
		return;
	},
	/**
	 * @function add industry child
	 * @tAuthor: tuantt
	 * @Cretate date: 27/05/2010
	 * */
	add_industry_child : function() {
		var txtChildName = $('#txtChildName').attr('value');
		var txtChildOrder = $('#txtChildOrder').attr('value');
		if(typeof(txtChildName)=='undefined'){
			$('#txtChildName').addClass('txtChildName');
			alert("Hãy nhập tên industry");
			return;
		}else {$('#txtChildName').removeClass('hightlight');}
		
		if (typeof(txtChildOrder)=='undefined') {
			$('#txtChildOrder').addClass('hightlight');
			alert("Bạn phải nhập số thứ tự");
			return false;
		} 
		else {if(txtChildOrder != ''){
				if (isNaN(txtChildOrder) == true) {
					alert("Số thứ tự phải là số nguyên");
					return false;
				}	
			}
		}
		var data = "txtChildName="+txtChildName+"&txtChildOrder="+txtChildOrder+"&rdoTypeChild="+objRecruitment.indusType+"&parentId="+objRecruitment.indusId;

		$.ajax({
			type: "POST",
			url: "?mod=recruitment&act=addChildIndus",
			data: data,
			//dataType: "json",
			success: function(){
				location.reload();
			}
		});
		return false;
	},
	
	showOvlAddIndus : function(paren_id, type) {
		objRecruitment.indusId = paren_id;
		objRecruitment.indusType = type;
		$("#chooseCity").slideToggle("fast");
		$("#chooseCat").slideUp("fast");
		$("#chooseCatButton").removeClass("btnHmenuMoreCurrent").addClass("btnHmenuMore");
		if (paren_id.className == 'otherHover'){
			$(paren_id).removeClass("otherHover").addClass("otherCurrent");
			objRecruitment.clicked1 = true;
		}
		else{ if (objRecruitment.clicked1 == true){
				$(paren_id).removeClass("otherCurrent").addClass("other");
			}
		}	
	},
	
	/**
	 * @ acti industry
	 * author: tuantt
	 * create: 
	 * */
	actiIndus: function(id, value) {
		$.ajax({
			type: "POST",
			url: "?mod=recruitment&act=actiIndus",
			data: {id: id,
					chkActi: value
				},
			success: function() {
				location.reload();
			}
		});
		return;
	},
	
	/**
	 * @ Search changer type industry
	 * author: tuantt
	 * create: 14.06.2010
	 * */
	onSearchTypeIndus: function(seType) {
		window.location = ('?mod=recruitment&act=listIndustry&json=1&seachType='+($('#seachType').val()) );
		return;
	},
	
	/**
	 * @ changer type industry
	 * author: tuantt
	 * create: 
	 * */
	changeTypeIndus: function(id) {
		//alert($('#seType_'+id).val());
		$.ajax({
			type: "POST",
			url: "?mod=recruitment&act=changeTypeIndus",
			data: {
				id: id,
				seType: $('#seType_'+id).val()
				},
			success: function() {
				location.reload();
			}
		});
		return;
	},
	
	/**
	 * @function edit industry child
	 * @tAuthor: tuantt
	 * @Cretate date: 27/05/2010
	 * */
	editIndusName: function(id) {
		$.ajax({
			type: "POST",
			url: "?mod=recruitment&act=editIndusName",
			data: {
				id: id,
				txtIndusName: $('#txtIndusName_'+id).val(),
				txtOrder: $('#txtOrder_'+id).val()
				},
			success: function() {
				location.reload();
			}
		});
		return;
	},
	
	/**
	 * @function delete industry child
	 * @tAuthor: tuantt
	 * @Cretate date: 27/05/2010
	 * */
	delIndus: function(id) {
		if(confirm ("Nếu xóa industry này thì sẽ xóa các industry con của nó nếu có \n Bạn có chắc chắn muốn xóa industry này không? \n - Nhấn OK nếu tiếp tục xóa các lựa chọn \n - CANCEL nếu không muốn xóa nữa")) {
			$.ajax({
				type: "POST",
				url: "?mod=recruitment&act=delIndus",
				data: {id: id},
				success: function() {
					location.reload();
				}
			});
		}
		return;
	},
	
	
	/**
	 * @function acti member
	 * @tAuthor: tuantt
	 * @Cretate date: 28/05/2010
	 * */
	actiMember: function(value, url) {
		var val="";
		$("input[name='chkcheck']:checkbox:checked").each(function(){
			val+=(this.value)+"\n";
		});
		if($('#commentNotActiCompany').val()){url += "&commentNotActiCompany="+$('#commentNotActiCompany').val();}
		if(val != "") {
			$.ajax({
				type: "POST",
				url: url,
				data: {objId: val,
						status: value
					},
				success: function() {
					location.reload();
				}
			});
		}
		else
			alert("Chưa chọn mục nào ");
		return;
	},
	
	/**
	 * @function track Job
	 * @tAuthor: NghiaPT
	 * @Cretate date: 16/06/2010
	 * */
	stopGetFiles: function(url){
		var arr = [];
		$("input[name='chkcheck']:checkbox:checked").each(function(i){
			arr[i] = (this.value);
		});
		strId = arr.join(',');
		if(strId != "") {
			$.ajax({
				type: "POST",
				url: url,
				data: 'ajax=1&strId='+strId,
				success: function(obj) {	
					location.reload();
				}
			});
		}
		else
			alert(' Chưa chọn việc làm ');
	},
	delJobAjax: function(jobId){
		var url = $("#url_del_jobs").val();
		if(!jobId){
			var arr = [];
			$("input[name='chkcheck']:checkbox:checked").each(function(i){
				arr[i] = (this.value);
			});
			strId = arr.join(',');
		}else{
			strId = jobId;
		}
		if(strId) {
			r = confirm(' Bạn thực sự muốn xóa việc làm này? ');
			if(!r) return false;
			$.ajax({
				type: "POST",
				url: url,
				data: 'ajax=1&strId='+strId,
				success: function(obj) {
					location.reload();
				}
			});
		}
		else
			alert(' Chưa chọn việc làm ');
		return;	
	},
	addJobAjax: function(url){
		window.location = url;
	},
	viewCause: function(url){
		jQuery.facebox.loading();
		$.ajax({
				type: "POST",
				url: url,
				data: 'ajax=1',
				success: function(xmlhttp) {
					var objData = xmlhttp.parseJSON();
					if(objData.isOk){
						jQuery.facebox(objData.template);
					}
				}
			});
			return false;
	},
	/**
	 * @function check all member
	 * @tAuthor: tuantt
	 * @Cretate date: 30/05/2010
	 * */
	checkAll : function(chkMember){
		var checked_status = chkMember.checked; 
		$('input[name=chkcheck]').each(function(){
			this.checked=checked_status;
		});
	},
	
	/**
	 * delete member
	 * author: tuantt
	 * create date:
	 * */
	onDelMember: function(url) {
		var val="";
		var i = 0;
		//var size = $("input[name='chkcheck']:checkbox:checked").size();
		$("input[name='chkcheck']:checkbox:checked").each(function(){
			if(i == 0) {val = this.value;}
			else {val+="," + this.value;}
			i++;
		});
		
		if(val != "") {
			if(confirm ("Bạn có chắc chắn muốn xóa những lựa chọn này không? \n - Nhấn OK nếu tiếp tục xóa các lựa chọn \n - CANCEL nếu không muốn xóa nữa")) {
				$.ajax({
					type: "POST",
					url: url,
					data: {objDel: val},
					success: function() {
						location.reload();
					}
				});
			} else {location.reload();}
		}
		else
			alert("Chưa chọn mục cần xóa");
		return false;
	},
	
	/**
	 * @function edit member
	 * @tAuthor: tuantt
	 * @Cretate date: 31/05/2010
	 * */
	editMember: function(id) {
		var src = "?mod=recruitment&act=editMember&ajax=1&id="+id;
		var options = {
			success:function(responseText, statusText){
				if ((parseInt(responseText.intIsOk) > 0) || (responseText.intIsOk == true)) {
					alert("Sửa thành công");
					document.location='?mod=recruitment&act=listMember';
				} else {
					alert(responseText.aryError);
				}
				$('#frmEditMember').unbind('submit');
			},
			error: function(){
				alert("Sửa thông tin member không thành công");
				$('#frmEditMember').unbind('submit');
			},
			url:        src,
			type:      'POST',
			dataType:  'json'
		};
		$('#frmEditMember').ajaxForm(options);
	},
	
	/**
	 * @function add info cpmpany
	 * @tAuthor: tuantt
	 * @Cretate date: 01/06/2010
	 * */
	addInfoCompany: function(url, url2) {
		$('#seIndusSelected option').attr("selected", 'selected');
		//$('#rdp').attr("disabled", 'disabled');
		var options = {
			success: function(responseText, statusText){
				if ((parseInt(responseText.intIsOk) > 0) || (responseText.intIsOk == true)) {
					jQuery.facebox.loading(); //hiện trạng thái đang load
					jQuery.facebox("Thêm thông tin thành công");//dữ liệu trả ra sau khi xử lý ajax
					//sent mail
					$.ajax({
						type: "post",
						url: $('#sentMailEditCompany').val(),
						success: function() {}
					});
					document.location = url2;
				} else {
					jQuery.facebox.loading(); //hiện trạng thái đang load
					jQuery.facebox(responseText.aryError);//dữ liệu trả ra sau khi xử lý ajax
					$('#rdp').attr("disabled", '');
				}
				$('#fmAddInfoCompany').unbind('submit');
			},
			error: function(){
				jQuery.facebox.loading(); //hiện trạng thái đang load
				jQuery.facebox("Thêm thông tin không thành công");//dữ liệu trả ra sau khi xử lý ajax
				$('#rdp').attr("disabled", '');
				$('#fmAddInfoCompany').unbind('submit');
			},
			url		: 	 url,
			type	: 	"POST",
			dataType:  	'json'
		};
		$('#fmAddInfoCompany').ajaxForm(options);
		return;
	},
	
	/**
	 * @function add info ofice
	 * @tAuthor: tuantt
	 * @Cretate date: 12/08/2010
	 * */
	addOffice: function(url, url2) {
		$('.fieldCom').css('display', 'display');
		var options = {
			success: function(responseText, statusText){
				if ((parseInt(responseText.intIsOk) > 0) || (responseText.intIsOk == true)) {
					jQuery.facebox.loading(); //hiện trạng thái đang load
					jQuery.facebox("Thêm thông tin thành công");//dữ liệu trả ra sau khi xử lý ajax
					document.location = url2;
				} else {
					if(responseText.txtCountry) {
						$('#errCountry').css('display','block');
						$("#errCountry").html(responseText.txtCountry);
					} else {$('#errCountry').css('display','none');}
					if(responseText.txtName) {
						$('#errName').css('display','block');
						$("#errName").html(responseText.txtName);
					} else {$('#errName').css('display','none');}
					if(responseText.txtAddress) {
						$('#errAddress').css('display','block');
						$("#errAddress").html(responseText.txtAddress);
					} else {$('#errAddress').css('display','none');}
					if(responseText.txtTown) {
						$('#errTown').css('display','block');
						$("#errTown").html(responseText.txtTown);
					} else {$('#errTown').css('display','none');}
					if(responseText.txtCity) {
						$('#errCity').css('display','block');
						$("#errCity").html(responseText.txtCity);
					} else {$('#errCity').css('display','none');}
					if(responseText.txtWebError) {
						$('#errWeb').css('display','block');
						$("#errWeb").html(responseText.txtWebError);
					} else {$('#errWeb').css('display','none');}
					if(responseText.errorWeb) {
						$('#errWeb1').css('display','block');
						$("#errWeb1").html(responseText.errorWeb);
					} else {$('#errWeb1').css('display','none');}
					
					if(responseText.null_Ofice) {
						$('#errNullCompany').css('display','block');
						$("#errNullCompany").html(responseText.null_Ofice);
					} else {$('#errNullCompany').css('display','none');}
					if(responseText.add_Ofice) {
						$('#errNullCompany').css('display','block');
						$("#errNullCompany").html(responseText.add_Ofice);
					} else {$('#errNullCompany').css('display','none');}
					if(responseText.edit_Ofice) {
						$('#errNullCompany').css('display','block');
						$("#errNullCompany").html(responseText.edit_Ofice);
					} else {$('#errNullCompany').css('display','none');}
				}
				$('#fmAddOffice').unbind('submit');
			},
			error: function(){
				jQuery.facebox.loading(); //hiện trạng thái đang load
				jQuery.facebox("Thêm thông tin không thành công");//dữ liệu trả ra sau khi xử lý ajax
				$('#fmAddOffice').unbind('submit');
			},
			url		: 	 url,
			type	: 	"POST",
			dataType:  	'json'
		};
		$('#fmAddOffice').ajaxForm(options);
		return;
	},
	
	delOffice: function() {
		var url = $('#linkDelOffice').val();
		$.ajax({
		    type: "POST",
		    url: url,
			success: function(){
				location.reload();
		   }
		});
		return;
	},
	
	/**
	 * @function edit info cpmpany
	 * @tAuthor: tuantt
	 * @Cretate date: 03/06/2010
	 * */
	editInfoCompany: function(id) {
		$('#seIndusSelected option').attr("selected", 'selected');
		var options = {
			success: function(responseText, statusText){
				if ((parseInt(responseText.intIsOk) > 0) || (responseText.intIsOk == true)) {
					alert("Sửa thành công thông tin nhà tuyển dụng");
					document.location = "?mod=recruitment&act=listCompany";
				} else {
					alert(responseText.aryError);
				}
				$('#frmEditCompany').unbind('submit');
			},
			//~ error: function(){
				//~ alert("Sửa thông tin không thành công");
				//~ $('#frmEditCompany').unbind('submit');
			//~ },
			url		: 	"?mod=recruitment&act=editCompany&ajax=1&id="+id,
			type	: 	"POST",
			dataType:  	'json'
		};
		$('#frmEditCompany').ajaxForm(options);
		return;
	},
	
	/**
	 * @function edit country company selected
	 * @tAuthor: tuantt
	 * @Cretate date: 03/06/2010
	 * */
	editCountrySelected: function(url) {
		var data = 'id='+ $('#txtCountry').attr('value');
		$.ajax({
		    type: "POST",
		    url: url,
		    data: data,
			success: function(xmlhttp){
				var responseText = xmlhttp.parseJSON();
				GetID("dvCity").innerHTML = responseText.template;
		   }
		});
	},

	/**
	 * @function del logo company
	 * @tAuthor: tuantt
	 * @Cretate date: 16/06/2010
	 * */
	delLogo: function(id, url) {
		$.ajax({
		    type: "POST",
		    url: url,
		    data: {id: id},
			success: function(){
				location.reload();
		   }
		});
		return;
	},	
	
	/**
	 * @function acti company
	 * @tAuthor: tuantt
	 * @Cretate date: 28/05/2010
	 * */
	actiCompany: function(value, url) {
		var val="";
		$("input[name='chkcheck']:checkbox:checked").each(function(){
			val+=(this.value)+"\n";
		});
		if($('#commentNotActiCompany').val()){url += "&commentNotActiCompany="+$('#commentNotActiCompany').val();}
		if(val != "") {
			$.ajax({
				type: "POST",
				url: url,
				data: {objId: val,
						status: value
					},
				success: function(http) {
					var objData = http.parseJSON();
					var strNotOwn = '';
					var strNotActi = '';
					
					var strError = '';
					if(objData.own_not_company) {
						strNotOwn = "Các nhà tuyển dụng "+objData.own_not_company+" có own là người đang tìm việc hoặc là sinh viên nên không được active\n";
					}
					if(objData.own_notActi) {
						strNotActi = "Các nhà tuyển dụng "+objData.own_notActi+" có own chưa được kích hoạt hoặc bị admin khóa\n";
					}
					strError = strNotOwn + strNotActi;
					if(strError != '') {alert(strError);}
					location.reload();
				}
			});
		}
		else
			alert("Chưa chọn mục nào ");
		return;
	},
	/**
	 * @function edit country company selected
	 * @tAuthor: tuantt
	 * @Cretate date: 03/06/2010
	 * */
	changeSalary: function() {
		var salary = parseInt(GetID('salary_').options[GetID('salary_').selectedIndex].value);
		if (salary == 3) {
			GetID('show').style.display = 'block';
			$('#currency_unit').css('display','');
			$('#error').css('display','');
		}
		else {
			GetID('show').style.display = 'none';
			$('#currency_unit').css('display','none');
			$('#error').css('display','none');
		}
	},
	
	/**
	 * hide or show info Company or Member on template is viewCompany
	 * author: tuantt
	 * create date: 05/06/2010
	 * */
	onShowCompany: function(id,id_image){  
		if($('#'+id).css('display') == 'none'){
			if(id = "viewListJobs") {
				$('#extendsJobs').text('Thôi <<');
				$('#'+id).slideDown(100);
			}
			$('#'+id_image).attr('src', $('#'+id_image).attr('src').replace("add.gif", "remove.gif"));
			$('#'+id).slideDown(100);
		}
		else{
			if(id = "viewListJobs") {
				$('#extendsJobs').text('Xem thêm >>');
				$('#'+id).slideUp("slow");
			}
			$('#'+id_image).attr('src', $('#'+id_image).attr('src').replace("remove.gif", "add.gif"));
			$('#'+id).slideUp("slow");
		}
	},
	
	 /**
	 * Get list jobs Acti jobs
	 * author: tuantt
	 * create date: 21/06/2010
	 * */
	getListJobsOvl: function(value) {
		var val="";
		var strActi = "";
		var size = $("input[name='chkcheck']:checkbox:checked").size()-1;
		var i=0;
		//alert(value);
		$("input[name='chkcheck']:checkbox:checked").each(function(){
			if(i == size) {val+=(this.value);}
			else {val+=(this.value)+",";}
			i++;
			if($('#checkHot_'+this.value).val() == value) {
				strActi+= " - "+$('#checkActi_'+this.value).val()+"\n";
			}
		});
		if(strActi != "") {
			alert("Những tin dưới đây đã ở trạng thái này:\n"+strActi+"Bạn hãy chọn lại");
			location.reload();
			exit();
		}
		if(val != "") {
			$.ajax({
				type: "POST",
				url: "?mod=recruitment&act=listJobsActi",
				data: {objId: val,
					value: value
					},
				success: function(xmlhttp) {
					var responseText = xmlhttp.parseJSON();
					$('#listActi').css('display','block');
					$('#listOvl').css('display','block');
					GetID("listActi").innerHTML = responseText.template;
					//location.reload();
				},
				error: function() {
					alert("Lỗi");
				}
			});
		} else {
			alert("Chưa chọn tin");
			location.reload();
		}
		
		return false;
	},
	 /**
	 * Get a jobs Acti jobs
	 * author: tuantt
	 * create date: 13/08/2010
	 * */
	getAJobsOvl: function(value) {
		var jobID = $('#jobID').val();
		$.ajax({
			type: "POST",
			url: "?mod=recruitment&act=listJobsActi",
			data: {objId: jobID,
				value: value
				},
			success: function(xmlhttp) {
				var responseText = xmlhttp.parseJSON();
				$('#listActi').css('display','block');
				$('#listOvl').css('display','block');
				$('#listActi').css('position', 'fixed');
				GetID("listActi").innerHTML = responseText.template;
			},
			error: function() {
				alert("Lỗi");
			}
		});
		return false;
	},
		
	 /**
	 * close list jobs Acti jobs
	 * author: tuantt
	 * create date: 22/06/2010
	 * */
	closeListJobsOvl: function() {
		$('#listActi').css('display','none');
		$('#listOvl').css('display','none');
		location.reload();
		return false;
	},
		
	 /**
	 * Acti jobs
	 * author: tuantt
	 * create date: 08/06/2010
	 * */
	actiJobs: function(url, value) {
		var val="";
		var strActi = "";
		$("input[name='chkcheck']:checkbox:checked").each(function(){
			val+=(this.value) + "," + $('#txtstatus_'+this.value).val() + "\n";
			//alert($('#txtstatus_'+this.value).val());
			if($('#checkHot_'+this.value).val() == value) {
				strActi+= " - "+$('#checkActi_'+this.value).val()+"\n";
			}
		});
		if(strActi != "") {
			alert("Những tin dưới đây đã ở trạng thái này:\n"+strActi+"Bạn hãy chọn lại");
			location.reload();
			exit();
		}
		//alert(val);
		if(val != "") {
			$.ajax({
				type: "POST",
				url: url,
				data: {objId: val,
					status: value
					},
				success: function() {
					location.reload();
				}
			});
		} else {alert("Chưa chọn tin");}
		return;
	},
	 /**
	 * Acti jobs
	 * author: tuantt
	 * create date: 08/06/2010
	 * *
	actiJobs: function(url, value) {
		
		$.ajax({
			type: "POST",
			url: url,
			data: {objId: val,
				status: value
			},
			success: function() {
				location.reload();
			}
		});
		return;
	},
	
	/**
	 * acti jobs in Admin
	 * tuantt
	 * 13.08.2010
	 * */
	actiJobsAdmin: function(url, val) {
		var jobID = $('#jobID').val();
		var description_status = $('#txtstatus_'+jobID).val();
		if(!description_status) {description_status = "";}
		
		var hot = $("input[name=rdoHotJobs]:radio:checked").val();
		if(!hot){hot = 0;}
		$.ajax({
			type: "POST",
			url: url,
			data: {objId: jobID,
				status: val,
				description_status: description_status
				},
			success: function(xmlHtml) {
				var objData = xmlHtml.parseJSON();
				if(objData.ok == 1){
					if(val == 2) {
						$.ajax({
							type: "POST",
							url: "?mod=recruitment&act=sentMailCompanyChangerOwner",
							data: {
								jobsId: jobID
							},
							success: function() {}
						});
					}
					objRecruitment.actiAdminHotJobs(hot, jobID);
					document.location = "?mod=recruitment&act=listJobs";
				}
				else {
					alert("Công ty chưa được kích hoạt");
				}
			}
		});
		return;
	},
		
	/**
	 * onclick on language
	 * author: HieuTV
	 * create date: 11/06/2010
	 * */
	selectLanguage: function(id) {
		$.cookie("lang", id, { path: '/', expires: 7 });
		location.reload();
	},
	  
	/**
	* @function add industry selected from seListIndus to seIndus
	* @tAuthor: tuantt
	* @Cretate date: 09/06/2010
	* */
	editIndusSelected: function(selec1, selec2, value) {
		var numOption = 0;
		if(selec2 == value) {
			$('#'+selec2+' option').each(function(){
					numOption+=1;
				}
			);
			if(($('#'+selec1+' option:selected').size() + numOption) >3 ) {
				jQuery.facebox.loading(); //hiện trạng thái đang load
				jQuery.facebox("Giới hạn chỉ được chọn 3 phần tử");//dữ liệu trả ra sau khi xử lý ajax
				return;
			}
			if(numOption < 3) {
				$('#'+selec1+' option:selected').attr('selected', 'selected').clone().appendTo($('#'+selec2));
				$('#'+selec1+' option:selected').attr("disabled", 'none');
				$('#'+selec1+' option:selected').attr("selected", '');
				return;
			}
		} else	{
			$('#'+selec1+' option:selected').each(function() {
				var val = this.value;
				$('#'+selec2+' option').each(function(){
					if(this.value == val) {
						this.disabled = '';
					}
				});
			});
			$('#'+selec1+' option:selected').remove();
			return;
		}
	},
	
	/**
	 * @function acti Hot jobs
	 * @tAuthor: tuantt
	 * @Cretate date: 25/06/2010
	 * */
	actiHotJobs: function(value, url) {
		var val = "";
		var hot = "";
		var jobID = $('#jobID').val();
		if(!jobID) {
			$("input[name='chkcheck']:checkbox:checked").each(function(){
				val+=(this.value)+"\n";
				if($('#checkHot_'+this.value).val() != 2) {
					alert("Chỉ những tin tuyển dụng đã được xét duyệt mới nâng cấp thành tin hot");
					location.reload();
					exit();
				}
			});
		} else{ 
			if(jobID) {
				val = jobID;
				if($('#checkHot_'+jobID).val() != 2 && value != 0) {
					alert("Tin tuyển dụng chưa được phê duyệt");
					location.reload();
					exit();
				}
			}
		}
		//alert(jobID);
		if(val != "") {
			$.ajax({
				type: "POST",
				url: url,
				data: {objId: val,
						status: value
					},
				success: function() {
					location.reload();
				}
			});
		}
		else
			alert("Chưa chọn mục nào ");
		return;
	},
	/**
	 * @function acti Hot jobs
	 * @tAuthor: tuantt
	 * @Cretate date: 25/06/2010
	 * */
	actiAdminHotJobs: function(value, objid) {
		$.ajax({
			type: "POST",
			url: "?mod=recruitment&act=hotJobs",
			data: {objId: objid,
				status: value
			},
			success: function() {
				location.reload();
			}
		});
		return;
	},
	
	/**
	 * @function acti Feature Company
	 * @tAuthor: tuantt
	 * @Cretate date: 25/06/2010
	 * */
	actiFeatureCompany: function(url) {
		var val = "";
		var feature = '1';
		var i = 0;
		//id company checked
		var size = $("input[name='chkcheck']:checkbox:checked").size();
		$("input[name='chkcheck']:checkbox:checked").each(function(){
			if(i == (size-1)) {val+=(this.value);}
			else {val+=(this.value)+"\n";}
			i++;
		});
		if(!$("input[name='chkFeature']").val()) { feature = 0;}
		else {
			var sizeFeature = $("input[name='chkFeature']").size();
			//if(sizeFeature == 0) {alert("Bạn chưa chọn chuẩn đánh giá nào"); return;}
			$("input[name='chkFeature']").each(function(){
				feature = ((this.checked) ? '1' : '0') + feature;
			});
		}
		//alert($('#commentDelFeature').val());
		if(val != "") {
			$.ajax({
				type: "POST",
				url: url,
				data: {objId: val,
						status: feature
					},
				success: function() {
					location.reload();
				}
			});
		} else {
			alert("Chưa chọn mục nào ");
			location.reload();
		}
		return;
	},
	/**
	 * ovlFeatureCompany
	 * tuantt
	 * 18.10.2010
	 * */
	ovlFeatureCompany: function(url) {
		var size = $("input[name='chkcheck']:checkbox:checked").size();
		if(size == 0) {alert("Bạn chưa chọn công ty"); return;}
		$.ajax({
		    type: "POST",
		    url: url,
			success: function(xmlhttp){
				var responseText = xmlhttp.parseJSON();
				jQuery.facebox.loading(); //hiện trạng thái đang load
				jQuery.facebox(responseText.templates);//dữ liệu trả ra sau khi xử lý ajax
		   },
		   error: function() {
				alert("Lỗi");
			}
		});
	},
	/**
	 * ovl delete feature of company
	 * tuantt
	 * 05.01.2010
	 * */
	ovlNotActiCompany: function(url) {
		var size = $("input[name='chkcheck']:checkbox:checked").size();
		if(size == 0) {alert("Bạn chưa chọn công ty"); return;}
		$.ajax({
		    type: "POST",
		    url: url,
			success: function(xmlhttp){
				jQuery.facebox(xmlhttp);//dữ liệu trả ra sau khi xử lý ajax
		   },
		   error: function() {
				alert("Lỗi");
			}
		});
	},
	/**
	 * @function edit info jobs in admin
	 * @tAuthor: tuantt
	 * @Cretate date: 22/06/2010
	 * */
	editInfoJobsInAdmin: function(id) {
		//alert("sdfsdf");
		$('#seIndusSelected option').attr("selected", 'selected');
		$('#seFunSelected option').attr("selected", 'selected');
		$('#seCitySelected option').attr("selected", 'selected');
		//alert("jjj");
		var options = {
			success: function(responseText, statusText){
				if ((parseInt(responseText.intIsOk) > 0) || (responseText.intIsOk == true)) {
					alert("Sửa thành công thông tin tuyển dụng");
					document.location = "?mod=recruitment&act=listJobs";
				} else {
					alert(responseText.aryError);
				}
				$('#formEditJob').unbind('submit');
			},
			//~ error: function(){
				//~ alert("Sửa thông tin không thành công");
				//~ $('#frmEditCompany').unbind('submit');
			//~ },
			url		: 	"?mod=recruitment&act=editJobs&json=1&id="+id,
			type	: 	"POST",
			dataType:  	'json'
		};
		$('#formEditJob').ajaxForm(options);
		return;
	},
	
	onOrder: function(img, param, url) {
		var sort = 'ASC';
		if(img.src.lastIndexOf('templates/share/images/sortasc2.gif') == (img.src.length -'templates/share/images/sortasc2.gif'.length)) {
			sort = 'DESC';
			img.src = 'templates/share/images/sortdesc2.gif';
		}
		else {
			sort = 'ASC';
			img.src = 'templates/share/images/sortasc2.gif';
		}
		document.location=url+'&param='+param+'&sort='+sort;
		return;
	},
	
	/**
	 * add website
	 * tuantt
	 * 16.07.2010
	 * */
	onExtendsWeb: function() {
		if($("input[name='txtWebsite[]']").size() < 5) {
			$('#extendsWeb').append('<input maxlength="255" name="txtWebsite[]" id="txtWebsite" value="" class="fieldLong" type="text" style="margin-top:5px"><br>');
		} else {
			jQuery.facebox.loading(); //hiện trạng thái đang load
			jQuery.facebox("Giới hạn số lượng website công ty là 5");//dữ liệu trả ra sau khi xử lý ajax
		}
	},
	
	/**
	 * follower company 
	 * tuantt
	 * 18.08.2010
	 * */
	onFollowCompany: function() {
		var url = $('#linkFollowCompany').val();
		//alert(url);
		$.ajax({
			type: "POST",
			url: url,
			success: function() {
				location.reload();
			}
		});
	},
	
	/**
	 * not follower company 
	 * tuantt
	 * 18.08.2010
	 * */
	notFollowCompany: function() {
		var url = $('#linkNotFollowCompany').val();
		//alert(url);
		$.ajax({
			type: "POST",
			url: url,
			success: function() {
				location.reload();
			}
		});
	},
	
	/**
	 * Sent for member Confirmation Company
	 * */
	memberConfirmationCompany: function() {
		var url = $('#linkMemberConfirmationCompany').val();
		$.ajax({
			type:"POST",
			url: url,
			success: function(xmlhttp){
				var responseText = xmlhttp.parseJSON();
				jQuery.facebox.loading(); //hiện trạng thái đang load
				jQuery.facebox(responseText.template);//dữ liệu trả ra sau khi xử lý ajax
		   }
		});
		return;
	},
	/**
	 * changer admin company
	 * tuantt
	 * 28.09.2010
	 * */
	changerAdminCompany: function() {
		var url = $('#linkChangerAdminCompany').val();
		//alert(url);
		$.ajax({
		    type: "POST",
		    url: url,
			success: function(){
				alert("Thay đổi thành công");
		   },
		   error: function() {
				alert("Lỗi");
			}
		});
	 },
	
	/**
	 * delManagerCompany
	 * tuantt
	 * 28.09.2010
	 * */
	delManagerCompany: function(user_id) {
		var url = $('#linkDelManagerCompany').val();
		//alert(url);
		$.ajax({
			type:"POST",
			url: url,
			data: {user_id: user_id},
			success:function(){
				location.reload();
			}
		});
		return;
	},
	/**
	 * get info changer admin of company from form
	 * */
	getInfoChangerAdmin: function() {
		$.ajax({
				type:"POST",
				url: $('#linkCheckAdminCompany').val(),
				data: $("#changerAdmin").serialize(),
				success:function(xmlhttp){
					var aryData = xmlhttp.parseJSON();
					if (aryData.insOk == 1){
						location.reload();
					}
					else{
						alert(aryData.aryError);
					}
				}
			});
			return;
	},
	/**
	 * add manager company
	 * tuantt
	 * 23.09.2010
	 * */
	addManagerCompany: function() {
		var url = $('#linkAddManagerCompany').val();
		$.ajax({
		    type: "POST",
		    url: url,
			success: function(xmlhttp){
				//alert(xmlhttp);
				var responseText = xmlhttp.parseJSON();
				jQuery.facebox.loading(); //hiện trạng thái đang load
				jQuery.facebox(responseText.template);//dữ liệu trả ra sau khi xử lý ajax
		   },
		   error: function() {
				alert("Lỗi");
			}
		});
	},
	
	/**
	 * add a manager for company
	 * tuantt
	 * 28.09.2010
	 * **/
	 addSaveManager: function() {
		$.ajax({
				type:"POST",
				url: $('#linkSaveManagerCompany').val(),
				data: $("#addManager").serialize(),
				success:function(xmlhttp) {
					var aryData = xmlhttp.parseJSON();
					if (aryData.insOk == 1){
						location.reload();
					}
					else{
						alert(aryData.aryError);
					}
				}
			});
			return;
	 },
	/**
	 * add a manager for company
	 * tuantt
	 * 28.09.2010
	 * **/
	 saveManager: function() {
		$.ajax({
				type:"POST",
				url: $('#linkSaveManager').val(),
				success:function(xmlhttp){
					var aryData = xmlhttp.parseJSON();
					if (aryData.insOk == 1){
						alert("Xác nhận thành công");
					}
					else{
						alert(aryData.aryError);
					}
				}
			});
			return;
	 },
	
	/**
	 * not save a admin for company
	 * tuantt
	 * 28.09.2010
	 * **/
	notSaveManager: function() {
		$.ajax({
				type:"POST",
				url: $('#linkNotSaveManager').val(),
				success:function(){
					alert("Xác nhận thành công");
				}
			});
			return;
	 },
	
	getCandicate : function(){
		var urlGetCandicate = $("#url_get_candicate").val();
		var letter = $('#facebox #contentSendProfile #letterSendToRecruitment').val();
		var profileID = $('#facebox #contentSendProfile #checkProfile').val();
		var jobID = $('#jobIDSendToRecruitment').val();
		$('#facebox #blue-button-apply-job').html('<span> Ứng tuyển </span>');
		if(!profileID){ 
			alert('Chưa chọn hồ sơ');
			return false;	
		}
		//alert(urlGetCandicate); return;
		$.ajax({
			type:"POST",
			//return  false;
			url:urlGetCandicate,//rootSite+"/recruitment/getCandicate",
			data:"ajax=1&jobID="+jobID+'&letter='+letter+'&profileID='+profileID,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					objRecruitment.close();
					$('#resultAfterSave').html(aryData.template);
					
				}
			}
		});
	},
	saveJob : function(){
		var urlSaveJob = $("#url_save_job").val();
		var note = $('#facebox #noteSaveJob').val();
		var jobID = $('#jobIDSendToRecruitment').val();
		$('#facebox #blue-button-save-job').html('<span> Lưu lại </span>');
		//alert(jobID); return false;
		$.ajax({
			type:"POST",
			url:urlSaveJob,//rootSite+"/recruitment/saveJob",
			data:"ajax=1&jobID="+jobID+'&note='+note,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					objRecruitment.close();
					$('#resultAfterSaveJob').html(aryData.template);
				}
			}
		});
	},
	saveMultiJob : function(){
		var urlSaveMultiJob = $("#url_save_multi_job").val();
		var arr = [];
		$("input[name='checkJob']:checkbox:checked").each(function(i){
			arr[i] = (this.value);
		});
		var count = 0;
		count = arr.length;
		if(!count) {
			alert('Chưa chọn việc làm!');
			return false;	
		}
		var strId = arr.join(',');
		var dataStr = 'ajax=1&strId='+strId;
		//alert(strId); return false;
		$.ajax({
			type:"POST",
			url:urlSaveMultiJob,//rootSite+"/recruitment/saveMultiJobs",
			data:dataStr,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					alert('Việc làm đã được lưu.');
					//objRecruitment.checkAllBox(0);
					location.reload();
				}
			}
		});
	},
	checkAllBox : function(status,nameCheck,nameCheckAll){
		if(parseInt(status))
			$('input[name="'+nameCheck+'"]:checkbox').each(function(){
				$(this).attr('checked',true);
				$('input[name="'+nameCheckAll+'"]:checkbox').attr('checked',true);
			});
		else
			$('input[name="'+nameCheck+'"]:checkbox').each(function(){
				$(this).attr('checked',false);
				$('input[name="'+nameCheckAll+'"]:checkbox').attr('checked',false);
			});
	},
	deleteJobSave : function(saveId){
		$('#blue-button-del-save-job').html('<span> Lưu việc làm </span>');
		var urlDelJobSave = $("#url_del_job_save").val();
		$.ajax({
			type:"POST",
			url:urlDelJobSave,//rootSite+"/recruitment/deleteJobSave",
			data:"ajax=1&saveId="+saveId,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterSaveJob').html(aryData.template);
				}
			}
		});
	},
	changeOldRequire : function(oldID,displayID){
		var statusOldRequire = $('#'+oldID).val();
		if(parseInt(statusOldRequire)){
			$('#chooseOld_').css('display','inline');
			$('#getOldRequire').css('width','140px');
		}
		else{
			$('div#chooseOld_').css('display','none');
			$('#getOldRequire').css('width','252px');	
		}
	},
	followingRecruiment : function(){
		$('#facebox #agreeFollowRecruitment').html('<span>Hoàn thành</span>');
		var urlFollowingRecruit = $("#url_following_recruitment").val();
		var note = $('#facebox #contentFollowingRecruitment #noticeFollowingRecruitment').val();
		var companyID = $('#companyIDFollowing').val();
		//var htmlRmvFnc = $('#facebox agreeFollowRecruitment').html();
		
		//alert(note);
		jQuery.facebox.close();
		$.ajax({
			type:"POST",
			url:urlFollowingRecruit,//rootSite+"/recruitment/setFollowingRecruitment",
			data:"ajax=1&companyID="+companyID+'&note='+note,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterFollowingRecruitment').html(aryData.template);
				}
			}
		});
	},
	editFollow : function(id){
		var determin = 0;		
		var urlUpdateFollow = $("#url_update_follow").val();
		var note = $('#facebox #editNotice_'+id).val();
		determin = parseInt($('#determin').val());
		if(determin){
			$('#facebox #blue-button-mem-edit-follow-'+id).html("<span> Đang cập nhật </span>");
		}else
			$('#facebox #blue-button-edit-notice-'+id).html("<span> Đang cập nhật </span>");
		$.ajax({
			type:"POST",
			url:urlUpdateFollow,//rootSite+"/recruitment/updateNoteFollow",
			data:"ajax=1&id="+id+'&note='+note+'&determin='+determin,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#RecruitmentFollowing_'+id+' .custom_content').text(aryData.note);
					$('#editRecruitmentFollowing_'+id+' #editNotice_'+id).text(aryData.note);
					$('#facebox .custom_content').html(aryData.template);
					setTimeout("jQuery.facebox.close()",1250);
					//alert(aryData.template);
				}
			}
		});
	},
	notFollowingRecruitment : function(userID,companyID){
		var urlNotFollowRecruit = $("#url_not_follow_recruit").val();
		$.ajax({
			type:"POST",
			url:urlNotFollowRecruit,//rootSite+"/recruitment/setNotFollowingRecruitment",
			data:"ajax=1&companyID="+companyID+'&userID='+userID,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterFollowingRecruitment').html(aryData.template);
				}
			}
		});
	},
	submitForm : function(formID){
		$('#'+formID).submit();
	},
	displayFormJob : function(formID,formEditID){
		$('#'+formEditID).css('display','');
		$('#'+formID).css('display','none');
		//objRecruitment.checkSubmit(['industries_select','function_select','city_select'],0);
	},
	getOnePersonContact : function(personID){
		objRecruitment.loadAjax('loadingText','loadResult');
		//alert(personID + 'abc'); return false;
		var urlGetPersonCont = $("#url_get_person_cont").val();
		$.ajax({
			type:"POST",
			url:urlGetPersonCont,//rootSite+"/recruitment/getPersonContactInCompany",
			data:"ajax=1&personID="+personID,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.intOk){
					$('#personal_contact_id').attr('value',aryData.aryPerson.id);
					$('#personal_contact').attr('value',aryData.aryPerson.name);
					$('#address_contact').attr('value',aryData.aryPerson.address);
					$('#phone_contact').attr('value',aryData.aryPerson.phone);
					$('#email_contact').attr('value',aryData.aryPerson.email);
					// remove error
					$('#changeErrorPersonalContact').css('display','none');
					$('#changeErrorAddressContact').css('display','none');
					$('#changeErrorPhoneContact').css('display','none');
					$('#changeErrorEmailContact').css('display','none');
					$("#method_contact option").each(function()
					{
						if($(this).val() == parseInt(aryData.aryPerson.method))
							$('#method_contact').attr('value',aryData.aryPerson.method);	
					});
				}	
			}
		});
	},
	approval : function(followID,type){
		var urlApproval = $("#url_approval").val();
		$.ajax({
			type:"POST",
			url:urlApproval,
			//url:rootSite+"/recruitment/setStatusFollow",
			data:"ajax=1&followID="+followID+"&type="+type,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOk){
					if(!parseInt(aryData.type))
						$('#approvalFollow_'+followID).html("Đang xin phép theo <a href='javascript:objRecruitment.approval("+followID+",0)'> Cho phép | </a><a href='javascript:objRecruitment.deleteFollowing("+followID+")'> Xóa </a>");
					if(parseInt(aryData.type)==2)
						$('#approvalFollow_'+followID).html("Đã cho phép theo <a href='javascript:objRecruitment.approval("+followID+",2)'> Không cho phép | </a><a href='javascript:objRecruitment.deleteFollowing("+followID+")'> Xóa </a>");	
					if(parseInt(aryData.type) == 1)
						$('#approvalFollow_'+followID).html("Đang xin phép theo <a href='javascript:objRecruitment.approval("+
						followID+",1)'> Cho phép | </a><a href='javascript:objRecruitment.deleteFollowing("+followID+")'> Xóa </a>");
					if(parseInt(aryData.type)==3)
						$('#approvalFollow_'+followID).html("Đã cho phép theo <a href='javascript:objRecruitment.approval("+followID+",3)'> Không cho phép | </a>" +
						"<a href='javascript:objRecruitment.deleteFollowing(10)'> Xóa </a>");
				}
			}
		});	
	},
	
	/**
	 * select company
	 * tuantt
	 * 12.10.2010
	 * */
	selectCompany: function() {
		var id_company = $("#seCompany").val();
		$.ajax({
			type:"POST",
			url: $("#linkChangerCompany").val(),
			data: {id: id_company},
			success:function(){
				alert("Chú ý: Những việc làm liên quan đến Công ty sẽ đuợc thực hiện cho công ty bạn vừa chọn cho đến khi bạn chọn công ty khác!");
				document.location = $('#linkViewCompany'+id_company).val();
			}
		});
	},
	/**
	 * admin view a list jobs by active
	 * tuantt
	 * 14.10.2010
	 * */
	onListActiveJobs: function() {
		var root_site = $('#root_site').val();
		var str = "<div id='listJobs'>";
		str += "<img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin đã duyệt: <a href='?mod=recruitment&act=listJobs&viewActive=3' style='text-decoration: none; color:#0000FF'>["+$('#numJobsApprovaled').val()+"]</a>";
		str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin tạm ngưng nhận hồ sơ: <a href='?mod=recruitment&act=listJobs&viewActive=4' style='text-decoration: none; color:#0000FF'>["+$('#numJobsStop').val()+"]</a>";
		/**str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin hết hạn nhận hồ sơ: <a href='?mod=recruitment&act=listJobs&deDateExpire=1' style='text-decoration: none; color:#0000FF'>["+$('#numDeJobsDateExpire').val()+"]</a>";**/
		/**str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin hết hạn đăng: <a href='?mod=recruitment&act=listJobs&viewActive=5' style='text-decoration: none; color:#0000FF'>["+$('#numJobsEXPIRED').val()+"]</a>";**/
		str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin đã chỉnh sửa và chờ duyệt: <a href='?mod=recruitment&act=listJobs&viewActive=6' style='text-decoration: none; color:#0000FF'>["+$('#numJobsEDITEDWAITAPPROVAL').val()+"]</a>";
		str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin không hợp lệ: <a href='?mod=recruitment&act=listJobs&viewActive=7' style='text-decoration: none; color:#0000FF'>["+$('#numJobsNOTAPPROVALED').val()+"]</a>";
		/**str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Số tin chưa hoàn thành: <a href='?mod=recruitment&act=listJobs&viewActive=1' style='text-decoration: none; color:#0000FF'>["+$('#numJobsNotFinish').val()+"]</a>";**/
		/**str += "<br><img src='"+root_site+"/modules/recruitment/admin/images/category-icon.gif'> Tổng số tin tuyển dụng: <a href='?mod=recruitment&act=listJobs' style='text-decoration: none; color:#0000FF'>["+$('#numJobs').val()+"]</a>";**/
		str += "<br><div id='notList' onclick='objRecruitment.onNotListActiveJobs()'><span style='float:right; cursor:pointer; margin-right:20px'> Co lại << </span></div></div>";
		return $('#listJobs').html(str);
	},
	onNotListActiveJobs: function() {
		$('#listJobs').html("<div id='listJobs'><span style='float:right; cursor:pointer; margin-right:50px' onclick='objRecruitment.onListActiveJobs()'>Xem thêm >> </div></div>");
		return ;
	},
	/**
	 * delete following
	 * author: NghiaPT
	 * 19.10.2010
	 */
	deleteFollowing : function(id){
		var urlDelFollow = $("#url_del_follow").val();
		$.ajax({
			type:"POST",
			url:urlDelFollow,//rootSite+"/recruitment/deleteFollowing",
			data:"ajax=1&followID="+id,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				location.reload();
			}
		});
	},
	checkLogin : function(){
		var user_id = $('#user_id').val();
		if(!parseInt(user_id)){
			var formError = $('#alertNotLogin').html();
			jQuery.facebox(formError);
			$('#facebox #contentError').html('- Bạn cần đăng nhập trước khi sử dụng chức năng này.');
		}
	},
	checkCompanyActive : function(){
		var urlCheck = $("#urlCheck").val();
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:urlCheck,
			//url:rootSite+"/recruitment/checkCompanyActive",
			data:"ajax=1",
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if(!parseInt(aryData.isOk))
					jQuery.facebox(aryData.template);	
			}	
		});	
	},
	viewLetter : function(id){
		var urlViewLetter = $("#url_view_letter").val();
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:urlViewLetter,//rootSite+"/recruitment/viewLetter",
			data:"ajax=1&id="+id,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if(parseInt(aryData.isOk))
					jQuery.facebox(aryData.template);	
			}	
		});	
	},
	viewCauseDelFileApply : function(id){
		var urlViewCauseDelFileApply = $("#url_view_cause_del_file_apply").val();
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:urlViewCauseDelFileApply,//rootSite+"/recruitment/viewCauseDelFileApply",
			data:"ajax=1&id="+id,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if(parseInt(aryData.isOk))
					jQuery.facebox(aryData.template);	
			}	
		});	
	},
	processCheckBox : function(nameAll,nameEachElement){
		if($('input[name="'+nameAll+'"]:checkbox').is(':checked')){
			$('input[name='+nameEachElement+']:checkbox').each(function(){
				$(this).attr('checked',true);
			});
		}
		else{
			$('input[name='+nameEachElement+']:checkbox').each(function(){
				$(this).attr('checked',false);
			});
		}	
	},
	delFileApply : function(id){
		var urlDelApply = $("#url_del_apply").val();
		
		var title_del = $('#title_del').val();
		var desc_del = $('#content_del').val();
		/*if(!parseInt(id)){
			var arr = [];
			$("input[name='checkApply']:checkbox:checked").each(function(i){
				arr[i] = this.value;
			});
			if(arr.length){
				r = confirm('Bạn thực sự muốn xóa hồ sơ này?');
				if(!r) return false;
			}else{
				alert('Bạn chưa chọn hồ sơ!');
				return false;
			}
			id = arr.join(',');
		}*/
		//alert(title_del +'    content  '+ desc_del); return false;
		$.ajax({
			type:"POST",
			//url:rootSite+"/recruitment/delFileApply",
			url:urlDelApply,
			data:"ajax=1&id="+id+"&title_del="+title_del+"&desc_del="+desc_del,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					location.reload();
				}
			}
		});
	},
	loadData : function(id){
		var urlLoadData = $("#url_load_data").val();
		
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:urlLoadData,//rootSite+"/recruitment/formData",
			data:"ajax=1&id="+id,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if(parseInt(aryData.isOk))
					jQuery.facebox(aryData.template);	
			}
		});	
	},
	close : function(){
		jQuery.facebox.close();
	},
	turnOn : function(dataId){
		var data = $('#'+dataId).html();
		jQuery.facebox(data);
	},
	memberDelFileApply : function(id,type){
		$('#blue-button-del-apply-job').html("<span> Đã ứng tuyển | <font color='red'> Xóa </font></span>");
		var urlMemberDelFileApply = $("#url_member_del_file_apply").val();
		$.ajax({
			type:"POST",
			url:urlMemberDelFileApply,//rootSite+"/recruitment/delFileApply",
			data:"ajax=1&id="+id+"&type="+type,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					if(parseInt(aryData.type))
						$('#resultAfterSave').html(aryData.template);
				}
			}
		});
	},
	editNoteSaveJob : function(id){
		var urlNoteSaveJob = $("#url_note_save_job").val();
		var note = $('#facebox #editNoteSaveJob_'+id).val();
		$('#facebox #blue-button-save-job-'+id).html("<span> Đang cập nhật </span>");
		//alert(note); return false;
		$.ajax({
			type:"POST",
			url:urlNoteSaveJob,//rootSite+"/recruitment/updateJobSave",
			data:"ajax=1&id="+id+'&note='+note,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#viewFullNoteSave_'+id+' .custom_content').text(aryData.note);
					$('#editNoteSaveJob_'+id).text(aryData.note);
					$('#facebox .custom_content').html(aryData.template);
					setTimeout("jQuery.facebox.close()",1250);
					//$aryData.template
					//alert(aryData.template);
				}
			}
		});
	},
	deleteMultiJob : function(){
		var urlDelMultiJobs = $("#url_del_multi_jobs").val();
		var arr = [];
		$("input[name='checkJobDel']:checkbox:checked").each(function(i){
			arr[i] = this.value;
		});
		var count = 0;
		count = arr.length;
		if(!count) {
			alert('Chưa chọn việc làm!');
			return false;	
		}
		var r = confirm(' Bạn thực sự muốn xóa những việc làm này?');
		if(!r) return false;
		var strId = arr.join(',');
		var dataStr = 'ajax=1&strId='+strId;
		var rootSite = $("#rootSite").val();
		$.ajax({
			type:"POST",
			url:urlDelMultiJobs,//rootSite+"/recruitment/deleteMultiJob",
			data:dataStr,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					//objRecruitment.checkAllBox(0);
					location.reload();
				}
			}
		});
	},
	editNoteCandicate : function(id){
		var urlNoteCandidate = $("#url_note_candidate").val();
		var note = $('#facebox #editNoteCandicate_'+id).val();
		$('#facebox #blue-button-'+id).html("<span> Đang cập nhật </span>");
		$.ajax({
			type:"POST",
			url:urlNoteCandidate,//rootSite+"/recruitment/updateNoteCandicate",
			data: {
				ajax: 1, 
				id: id,
				note: note
				},
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#viewNoteCandicate_'+id+' .custom_content').text(aryData.note);
					$('#'+id+' .custom_content #editNoteCandicate_'+id).text(aryData.note);
					$('#facebox .custom_content').html(aryData.template);
					jQuery.facebox.close();
				}
			}
		});
	},
	deleteMultiCandicate : function(){
		var urlDelMultiCandidate = $("#url_del_multi_candidate").val();
		var arr = [];
		$("input[name='checkCandicateSave']:checkbox:checked").each(function(i){
			arr[i] = this.value;
		});
		var count = 0;
		count = arr.length;
		if(!count) {
			alert('Chưa chọn ứng viên!');
			return false;	
		}
		if(count==1)
			var r = confirm(' Bạn thực sự muốn xóa ứng viên này?');
		else
			var r = confirm(' Bạn thực sự muốn xóa những ứng viên này?');
		if(!r) return false;
		var strId = arr.join(',');
		var dataStr = 'ajax=1&strId='+strId;
		//alert(strId); return false;
		var rootSite = $("#rootsite").val();
		$.ajax({
			type:"POST",
			url:urlDelMultiCandidate,//rootSite+"/recruitment/deleteMultiCandicate",
			data:dataStr,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					//objRecruitment.checkAllBox(0);
					location.reload();
				}
			}
		});
	},
	saveMultiProfiles : function(){
		var urlSaveMultiProfile = $("#url_save_multi_profile").val();
		var arr = [];
		var arrPr = [];
		var i = 0;
		$("input[name='checkCandicateSave']:checkbox:checked").each(function(){
			id = (this.value);
			arr[i] = id;
			arrPr[i] = $("#profileIdd_"+id).val();
			i++;
		});
		
		//alert($("input[name='checkProfileSaves']:hidden #profileIdd_3").val());
		var count = 0;
		count = arr.length;
		if(!count) {
			alert('Chưa chọn ứng viên!');
			return false;	
		}
		var strId = arr.join(',');
		var strProId = arrPr.join(',');
		var dataStr = 'ajax=1&strId='+strId+'&strProId='+strProId;
		//alert(strId + strProId); return false;
		$.ajax({
			type:"POST",
			url:urlSaveMultiProfile,//rootSite+"/recruitment/saveMultiProfiles",
			data:dataStr,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					alert('Ứng viên đã được lưu.');
					//objRecruitment.checkAllBox(0);
					location.reload();
				}
			}
		});
	},
	loadAjax : function(waitId,dataId){
		$('#'+waitId).ajaxStart(function() {
			$('#'+dataId).hide();
			$(this).show();
		}).ajaxStop(function() {
			$(this).hide();
			$('#'+dataId).fadeIn('slow');
		});
	},
	refreshJob : function(job_id){
		var urlRefreshJob = $('#url_refresh_job').val();
		var company_id = $('#company_id').val();
		if(!parseInt(job_id) && !parseInt(company_id)){
			alert('Thông tin không hợp lệ');
			location.reload();
		};
		var dataStr = 'ajax=1&job_id='+job_id+'&company_id='+company_id;
		$.ajax({
			type:"POST",
			url:urlRefreshJob,//rootSite+"/recruitment/refreshJob",
			data:dataStr,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOk)
				{
					alert('Việc làm đã được làm mới và hiện lên đầu trang chủ và chuyên mục đăng ký. Sau 10h Bạn có thể sử dụng lại chức năng này!');
					location.reload();
				}
			}
		});
	},
	alertNotLoginViewJob : function(){
		var chkLogin = $('#userLogin').val();
		if(!parseInt(chkLogin)){
			var html = $('#alertNotLoginViewJob').html();
			jQuery.facebox(html);
		}	
	},
	loadMultiSelect : function (id1,id2){
		 var arrSub = [];
		$('#' + id2 + ' option').each(function(i){
			arrSub[i] = $(this).val();	
		});
	    var len = arrSub.length;   
    	for(i=0; i<len; i++){
			$('#' + id1 + ' option[value=' + arrSub[i] + ']').attr('disabled',true);
			//$('#' + id2 + ' option[value=' + arrSub[i] + ']').remove(); 
		}
	}
};
//}
$(document).ready(function(){
	objRecruitment.loadMultiSelect('industries_','industries_select');
	objRecruitment.loadMultiSelect('function_','function_select');
	objRecruitment.loadMultiSelect('city','city_select');
	$('#industries_').bind('keydown',function(e){
		if(e.keyCode == 13) $('#add_industries').trigger('click');
	});
	$('#industries_select').bind('keydown',function(e){
		if(e.keyCode == 13) $('#remove_industries').trigger('click');
	});
	$('#function_').bind('keydown',function(e){
		if(e.keyCode == 13) $('#add_function').trigger('click');
	});
	$('#function_select').bind('keydown',function(e){
		if(e.keyCode == 13) $('#remove_function').trigger('click');
	});
	$('#city').bind('keydown',function(e){
		if(e.keyCode == 13) $('#add_city').trigger('click');
	});
	$('#city_select').bind('keydown',function(e){
		if(e.keyCode == 13) $('#remove_city').trigger('click');
	});
	//hide all element class expand
	$(".expand").css('display','none');
	//set default form search
	var current_select_type_search = $("input[name='typeSearch']:checked").val();
	var container = $("#ul_type_search_" + current_select_type_search).html();
	$("#xyz").html(container);
	// NghiaPT add
	if(parseInt($('#postJob').val()) || parseInt($('#editJob').val())){
		if (typeof $("input#expiry_date").datepicker == 'function') {
			var rootSite = '';
			rootSite = $('#rootsite').val();
			$.datepicker.startYear = (new Date).getFullYear();
			$.datepicker.endYear= 2015;
			$('#expiry_date').datepicker({
				dateFormat: 'dd/mm/yy', showOn: 'button', 
				buttonImage: rootSite + '/modules/recruitment/templates/default/images/calendar.gif', buttonImageOnly: true, 
				monthNames:['Tháng 1','Tháng 2','Tháng 3','Tháng 4','Tháng 5','Tháng 6','Tháng 7','Tháng 8','Tháng 9','Tháng 10','Tháng 11','Tháng 12'],
				dayNamesMin:['Cn','Th2','Th3','Th4','Th5','Th6','Th7'],
				clearText: 'Xóa',closeText:'Đóng',prevText:'',nextText:'',currentText:''
			});
		}
	}	
	else
	if (typeof $("#txtYear").datepicker == 'function') {
		rootSite = $('#rootsite').val();
		$.datepicker.startYear = 1900;
		$.datepicker.endYear= (new Date).getFullYear();
		$('input#txtYear').datepicker({
			dateFormat: 'dd/mm/yy', showOn: 'button', 
			buttonImage: rootSite + '/modules/recruitment/templates/default/images/calendar.gif', buttonImageOnly: true, 
			monthNames:['Tháng 1','Tháng 2','Tháng 3','Tháng 4','Tháng 5','Tháng 6','Tháng 7','Tháng 8','Tháng 9','Tháng 10','Tháng 11','Tháng 12'],
			dayNamesMin:['Cn','Th2','Th3','Th4','Th5','Th6','Th7'],
			clearText: 'Xóa',closeText:'Đóng',prevText:'',nextText:'',currentText:''
		});
	};
	$('#keywords').keydown(function(e) {
		if( e.keyCode == 13 ) {
			e.preventDefault();
			$("#submitFormSeach").trigger('click');
		}
	});
	$('#captchaFormSearch').keydown(function(e) {
		if( e.keyCode == 13 ) {
			e.preventDefault();
			$("#submitFormSeach").trigger('click');
		}
	});
	objRecruitment.test = $('input[name="typeSearch"]:radio:checked').val();
	$('input[name="typeSearch"]:radio').bind('click',function(){
		if(parseInt($('input[name="typeSearch"]:radio:checked').val()) != parseInt(objRecruitment.test)){
			objRecruitment.textSearch = $('#keywords').val(); 
			$('#keywords').val('');
			$('#keywords').focus();
		}else{
			$('#keywords').val(objRecruitment.textSearch);
			$('#keywords').focus();
		}
	});
	
});


