/**
 * @author WEDO2
 * @Date created 2009/03/22 
 */
var objMember = {
	startOverAt : 3,
	countClick : 0,
	urlRedirectAfterLogin : '',
	openOverlayLogin : function(strUrl) {
		jQuery.facebox.loading();
		var heightOvl = $('#facebox').height();
		var height = $(window).height();
		var top = parseFloat((height - heightOvl)/2  - 125);
		$('#facebox').css({
			'top': top+'px'
		});
		var dataStr = '';
		$.ajax({
			type: "POST",
			url: strUrl,
			data: 'ajax=1&urlRedirect='+dataStr,
			success: function(xmlhttp) {
				var objData = xmlhttp.parseJSON();
				var sTitle = objData.title;
				var template = objData.template;
				jQuery.facebox(template);
				//$('#facebox .popup .body .footer').css('display','none');
				$('#login_email').focus();
			}
		});
    },
    toggleElement : function (element)
    {
		$("#"+element).toggle();
		return false;
	}
	,
	checkLogin : function(event, strUrl, btButton) {
		var rootSite = $("#rootsite").val();
		if(btButton || event.keyCode == 13) {
			$('#btnLogin').attr('disabled',true);
			$('#btnLogin').css('background', 'url('+rootSite+'/templates/tuyendung/images/menunav/main_bottom_bg.png');
			$('#btnLogin').val('Đang xử lý ');
		}
		if (event.keyCode == 13 || event.id == 'btnLogin') {
			var token = $('#tokenLogin').val();
			var email = GetID('login_email').value;
			var strPass = GetID('login_password').value;
			//var rememberPass = GetID('remember').value;
			//var data = "email=" + email + '&password=' + strPass + '&rememberPass=' + rememberPass;
			var data = "tokenLogin=" + token + "&email=" + email + '&password=' + strPass + '&urlRedirect=' + objMember.urlRedirectAfterLogin;
			$.ajax({
				type: "POST",
				url: strUrl,
				data: data,
				success: function(xmlhttp){
					var objData = xmlhttp.parseJSON();
					if ((parseInt(objData.intOK) > 0) || (objData.intOK == true)) {
						document.location=objData.urlHome;
					} else {
						$('#btnLogin').attr('disabled', '');
						$('#btnLogin').val('Đăng nhập');
						$('#btnLogin').css('background', 'url('+rootSite+'/templates/tuyendung/images/menunav/sprite_global_v1.png) no-repeat scroll 0 -260px #3399CC');
						GetID('error').innerHTML = objData.strError;
						$('#facebox #tokenLogin').val(objData.upToken);
						//alert(objData.upToken);
					}
				}
			});
			return false;
		}
    },    
    
    checkLogout : function(sUrl, urlLogout) {
        $.ajax({
			type: "POST",
			url: sUrl,
			success: function(xmlhttp){
				document.location = urlLogout;			
			}
		});
    },
    
    onclickAddMember : function(sUrl) {
		var tmp_path = $("#tmp_path").val();
		var rootsite = $("#rootsite").val();
		$('#btRegis').css('background', 'url('+tmp_path+'/images/menunav/main_bottom_bg.png)');
		$('#btRegis').val('Đang xử lý ');
		$('#btRegis').attr('disabled', 'disabled');
		$('#frmMember').unbind('buttom');
		$.ajax({
			type: "POST",
			url: sUrl,
			data: $("#frmMember").serialize(),
			success: function(xmlhttp){
				var objData = xmlhttp.parseJSON();
				if ((parseInt(objData.intOK) > 0) || (objData.intOK == true)) {
					//redirect page
					window.location = $("#linkSuccess").val();
				} else {
					//jQuery.facebox(objData.strErrors);//dữ liệu trả ra sau khi xử lý ajax
					var errorLogin = '';
					errorLogin =  $('#noticesErrorLogin').html();
					jQuery.facebox(errorLogin);
					$('#facebox .marginTop').html(objData.strErrors);
					$('#btRegis').attr('disabled', '');
					$('#btRegis').val('Đăng ký');
					$('#btRegis').css('background', 'url('+tmp_path+'/images/menunav/nav_bg1.png)');
					$('#ValidCode').val('');
					$('img.captcha').attr("src",rootsite + '/libraries/packages/captcha/captcha.php?capt=' + objData.captchaCode);
					//$('#captchaCodeLogin').text(objData.captchaCode);
				}
			}
		});
		return false;
	},
	
	showOverlayUploadAvatar : function (title)
	{
		$('#cv_upload_avatar_header').attr("innerHTML", title);
		$("#cv_upload_avatar").modal();
		GetID('simplemodal-container').style.height='auto';
		return;
	}
	
	,
	/*
	 * @params: (string)		$type		Tên hàm ajax gọi tới controller
	 * @params:	(int)			$userId		User ID
	 * @params:	(int)			$cvId		ID của CV
	 * @params:	(int)			$cvLangId	ID ngôn ngữ của CV
	 */
	 
	showOverlayEditCv : function (type,userId,cvId,cvLangId,link)
	{
		if (!type || !userId || !cvId || !cvLangId)
		{
			return false;
		}
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"",
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				jQuery.facebox(template);
				//sent mail to friend
				$.ajax({
					type:"POST",
					url: $('#linkSentMailEditInfo').val(),
					success: function(){}
				});
			}
		});
	}
	,
	showOverlayAddEducation : function (cvLangId,link)
	{
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"cvLangId="+cvLangId,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;				
				//$('#cv_messages_error').attr("innerHTML","AAAAAAA").show();
				//$('#cv_dialog_header').attr("innerHTML", aryData.title);
				//$('#cv_dialog_content').attr('innerHTML',template);
				//$("#cv_dialog").modal();
				jQuery.facebox(template);
				if (aryData.error)
				{
					$("#cv_messages_error").attr("innerHTML",aryData.error).fadeIn("slow");
					//close span message error
					$('#cv_message_error_close').click(function(){
						$('#cv_messages_error').empty().fadeOut('slow');
					});
				}
				//GetID('simplemodal-container').style.height='380px';
				$("#select_list_univer").change(function(){
					var school_select = $("#select_list_univer").val();
					if (school_select == 0)
					{
						$("#select_other_school").show();
					}
					else
					{
						$("#select_other_school").hide();
					}
				});
			}
			});
		return false;
	}
	,
	editEducation : function (educationId,countryId,link)
	{
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"educationId="+educationId+"&countryId="+countryId,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				jQuery.facebox(template);
			}
			});
		return false;
	}
	,
	getUniOfCountry : function ()
	{
		var rootsite = $("#rootsite").val();
		var country = $("#ajax_country").val();
		if (!country)
		{
			return false;
		}
		$("#img_loading").css('display','block');
		$.ajax({
			type: "POST",
			url : $('#linkParseXMLOfCountry').val(),
			data: "country_id="+country,
			success : function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.UniverOfCountry.education)
				{
					$("#select_other_school").hide();
					var listUniver = aryData.UniverOfCountry.education;
					var count = listUniver.length;
					if (count>0)
					{
						var selectStr = '<label>Chọn tên trường</label><div><select id="select_list_univer"><option value="-1">Chọn 1 trường đại học</option>';
						for(i=0;i<count;i++)
						{
							selectStr += '<option value="'+listUniver[i].id+'">'+listUniver[i].name+'</option>';
						}
						selectStr += '<option value="0">Khác ...</option></select></div>';
						$("#listSchoolExist").empty().attr("innerHTML",selectStr).show();
						$("#select_list_univer").change(function(){
							var school_select = $("#select_list_univer").val();
							if (school_select == 0)
							{
								$("#select_other_school").show();
							}
							else
							{
								$("#select_other_school").hide();
							}
						});
					}
					
				}
				else
				{
					$("#listSchoolExist").empty().hide();
					$("#select_other_school").show();
				}
				
				$("#img_loading").css('display','none');
			}
		});		
	}
	,
	getProvinceOfCountry : function ()
	{
		var country = $("#ajax_country").val();
		if (!country)
		{
			return false;
		}
		$("#img_loading").show();
		$.ajax({
			type: "POST",
			url : $("#linkProvinceOfCountry").val(),
			data: "country_id="+country,
			success : function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.option)
				{
					$("#province").show();
					$("#province_list").attr("innerHTML",aryData.option);
					$("#img_loading").hide();
				}
				else
				{
					$("#img_loading").hide();
					$("#province_list").empty();
					$("#province").hide();
				}
			}
		});		
	}
	,
	getStartedGetProvinceOfCountry : function ()
	{
		var country = $("#country").val();
		if (!country)
		{
			return false;
		}
		$("#img_loading").show();
		$.ajax({
			type: "POST",
			url : $("#linkgetStartedGetProvinceOfCountry").val(),
			data: "country_id="+country,
			success : function (xmlhttp)
			{
			var aryData = xmlhttp.parseJSON();
			if(aryData.error==1)
				{
				$("#img_loading").hide();
				}
			else if(!aryData.error && aryData.option)
			{
				$("#province").attr("innerHTML",aryData.option);
				$("#img_loading").hide();				
			}
			else
			{
				$("#img_loading").hide();
				$("#province").empty().attr("innerHTML",'Chưa xác định');
			}
			}
		});		
	}
	,
	saveEditEducation : function (recordId,eId)
	{
		if (!recordId)
		{
			return false;
		}
		var rootsite = $("#rootsite").val();
		var countryId = $("#ajax_country").val();
		var universityId = $("#select_list_univer").val();
		var exist_school_name = $("#select_list_univer option:selected").text();
		var new_school_name = $("#new_school_name").val();
		var degree = $("#degree").val();
		var major = $("#major").val();
		var societies = $("#societies").val();
		var add_note = $("#add_note").val();
		var year_from = $("#year_from option:selected").val();
		var year_to = $("#year_to option:selected").val();
		$('.main_basic_info').css('display','none');
		$('#waiting').css('display','block');
		$.ajax({
			type: "POST",
			url : $("#linkSaveEditEducation").val(),
			data: "countryId="+countryId+"&universityId="+universityId+"&new_school_name="+new_school_name+"&degree="+degree+"&major="+major+"&societies="+societies+"&add_note="+add_note+"&year_from="+year_from+"&year_to="+year_to+"&recordId="+recordId,
			success : function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				//GetID('simplemodal-container').style.height='auto';
				
				if (aryData.error)
				{
					$('#waiting').hide();
					$('.main_basic_info').show();
					$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow'); 
					//close span message error
					$('#cv_message_error_close').click(function(){
						$('#cv_messages_error').empty().fadeOut('slow');
					});
					//return false;
				}
				if (aryData.success)
				{
					//sent mail to friend
						$.ajax({
							type:"POST",
							url: $("#linkSentMailEditInfo").val(),
							success: function(){}
						});
					//end sent mail
					jQuery.facebox.close();
					location.reload();
				}
				
			}
		});
		return false;
	}
	,
	closeModal : function (rootsite)
	{
		var new_image = $("#new_avatar_value").val();
		if(new_image)
		{
			$("#picture_avatar").attr("innerHTML",'<img src="'+rootsite+'/modules/member/images/avatars/'+new_image+'" align="left" />');
			$("#upload_area").attr("innerHTML",'<img src="'+rootsite+'/modules/member/images/avatars/'+new_image+'" align="left" />');
		}
		$.modal.close();
		return false;
	}
	,
	saveAddEducation : function (cvLangId,link)
	{
		if (!cvLangId)
		{
			return false;
		}
		
		var rootsite = $("#rootsite").val();
		var countryId = $("#ajax_country").val();
		var universityId = $("#select_list_univer").val();
		var exist_school_name = $("#select_list_univer option:selected").text();
		var new_school_name = $("#new_school_name").val();
		var degree = $("#degree").val();
		var major = $("#major").val();
		var societies = $("#societies").val();
		var add_note = $("#add_note").val();
		var year_from = $("#year_from option:selected").val();
		var year_to = $("#year_to option:selected").val();
		$('.main_basic_info').css('display','none');
		$('#waiting').css('display','block');
		$.ajax({
			type: "POST",
			url : link,
			data: "countryId="+countryId+"&universityId="+universityId+"&new_school_name="+new_school_name+"&degree="+degree+"&major="+major+"&societies="+societies+"&add_note="+add_note+"&year_from="+year_from+"&year_to="+year_to+"&cvLangId="+cvLangId,
			success : function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				//GetID('simplemodal-container').style.height='auto';
				
				if (aryData.error)
				{
					$('#waiting').hide();
					$('.main_basic_info').show();
					$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow'); 
					//close span message error
					$('#cv_message_error_close').click(function(){
						$('#cv_messages_error').fadeOut('slow');
					});
					//return false;
				}
				if (aryData.success)
				{
					//sent mail to friend
						$.ajax({
							type:"POST",
							url: $("#linksentMailEditInfo").val(),
							success: function(){}
						});
					//end sent mail
					$.modal.close();
					location.reload();
				}
				
			}
		});
		return false;
	}
	,
	editSummary : function (cvId,link)
	{
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"cvId="+cvId,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				jQuery.facebox(template);
				return false;
			}
		});
	}
	,
	/**
	 * @params:	(int)		userId		ID của user
	 * @params:	(int)		cvId		ID của CV
	 * @params:	(int)		cvLangId	ID ngôn ngữ của CV
	 */
	saveSummary : function (cvId,link)
	{
		if (!cvId)
		{
			return false;
		}
		var specialties = $("#cv_specialties").val();
		var summary = $("#cv_summary_content").val();
		$.ajax({
			type : "POST",
			url  : link,
			data : "summary=" + summary + "&specialties=" + specialties + "&cvId=" + cvId,
			success : function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.error)
				{
					$('#waiting').hide();
					$('.main_basic_info').show();
					$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow'); 
					//close span message error
					$('#cv_message_error_close').click(function(){
						$('#cv_messages_error').fadeOut('slow');
					});
					return false;
				}
				if (aryData.success)
				{
					//sent mail to friend
						$.ajax({
							type:"POST",
							url: $("#linkSentMailEditInfo").val(),
							success: function(){}
						});
					//end sent mail
					jQuery.facebox.close();
					location.reload();
				}
			}
		});
		$('.main_basic_info').css('display','none');
		$('#waiting').css('display','block');
		return false;

	}
	,
	
	saveBasicInfo : function (link)
	{
		var first_name = $("input[name='first_name']").val();
		var last_name = $("input[name='last_name']").val();
		var headline = $("input[name='headline']").val();
		var country_id = $("#sl_country option:selected").val();
		var city_id = $("#sl_city option:selected").val();
		
		/**get list industry of member**/
		var industry_size = $("#sl_industry option:selected").size();
		if(industry_size > 3) {
			jQuery.facebox("Bạn chỉ được chon tối da 3 ngành nghề mà bạn có thể làm việc");
			return;
		} else if (industry_size<=0) {
			jQuery.facebox("Bạn chưa chọn ngành nghề có thể làm việc");
			return;
		}
		var industry_id = "";
		var i=0;
		$("#sl_industry option:selected").each(function(){
			if(i==0) {industry_id+=this.value;}
			else {industry_id+=","+this.value;}
			i++;
		});
		
		$('.main_basic_info').css('display','none');
		$('#waiting').css('display','block');
		$.ajax
		({
			type : "POST",
			url  : link,
			data : "first_name=" + first_name + "&last_name=" + last_name + "&headline=" + headline + "&country_id=" + country_id + "&industry_id=" + industry_id + "&city_id=" + city_id,
			success : function (xmlhttp) {
				var aryData = xmlhttp.parseJSON();
				//GetID('simplemodal-container').style.height='auto';
				//$('#simplemodal-container').css('min-height','320px');
				if(aryData.error) {
					$('#waiting').hide();
					$('.main_basic_info').show();
					$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow');
					//close span message error
					$('#cv_message_error_close').click(function(){
						$('#cv_messages_error').fadeOut('slow');
					});
				}
				if (aryData.success){
					jQuery.facebox.close();
					location.reload();
				}
				
			}
		});
	}
	,
	addPosition : function (link,link2)
	{
		//ajax load form add/edit member-company
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"",
			success: function (xmlhttp)
			{
				
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				var title = aryData.title;
				var error = aryData.error;
				jQuery.facebox(template);
				if (aryData.error)
				{
					$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow');
					//return false;
				}
				
				//click current work
				$("#ajax_current_work").click(function(){
					//get current select status
					var status_check = $('#ajax_current_work').is(':checked');
					if (status_check == true)
					{
						$("#not_current").hide();
						$("#current").show();
					}
					else
					{
						$("#not_current").show();
						$("#current").hide();
					}
					
				});
				//save add
				$("#saveAdd").click(function(){
					var companyId = parseInt($("#select2 option:selected").val());
					
					var companyName = $("#select2 option:selected").text();
					if (isNaN(companyId) == true || (isNaN(companyId) == false && isNaN(companyName) == false))
					{
						companyId = 0;
					}
					var newCompanyName=$(".maininput").val();
					if (companyId == 0 && !newCompanyName)
					{
						newCompanyName = companyName;
					}
					var ajax_position_title = $("#ajax_position_title").val();
					var ajax_current_work = $("#ajax_current_work").is(':checked');
					if (ajax_current_work == true)
					{
						ajax_current_work = 1;
					}
					else
					{
						ajax_current_work = 0;
					}
					var choose_month_from = $("#choose_month_from").val();
					var choose_month_to = $("#choose_month_to").val();
					var year_from = $("#year_from").val();
					var year_to = $("#year_to").val();
					var description = $("#description").val();
					$('#main_basic_info').css('display','none');
					$('#waiting').css('display','block');
					$("#cv_messages_error").empty().hide();
					$.ajax({
						type:"POST",
						url:link2,
						data:"companyId="+companyId+"&newCompanyName="+newCompanyName+"&ajax_position_title="+ajax_position_title+"&ajax_current_work="+ajax_current_work+"&choose_month_from="+choose_month_from+"&choose_month_to="+choose_month_to+"&year_from="+year_from+"&year_to="+year_to+"&description="+description,
						success: function (xmlhttp)
						{
							var aryData = xmlhttp.parseJSON();
							$('#waiting').hide();
							$('#main_basic_info').show();
							if (aryData.error)
							{
								$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow');
								//close span message error
								$('#cv_message_error_close').click(function(){
									$('#cv_messages_error').fadeOut('slow');
								});
								
							}
							if(aryData.success)
							{
								//sent mail to friend
									$.ajax({
										type:"POST",
										url: $('#linkSentMailAddPosition').val(),
										success: function(){}
									});
								//end sent mail
								$.modal.close();
								location.reload();
							}																																									
						}
					});
				});
			}
		});
	},
	
	editPosition : function (id,link,link2)
	{
		if (isNaN(parseInt(id)) == true)
		{
			return false;
		}
		var rootsite = $("#rootsite").val();
		//ajax load form add/edit member-company
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"id="+id,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				var title = aryData.title;
				jQuery.facebox(template);
				//click current work
				$("#ajax_current_work").click(function(){
					//get current select status
					var status_check = $('#ajax_current_work').is(':checked');
					if (status_check == true)
					{
						$("#not_current").hide();
						$("#current").show();
					}
					else
					{
						$("#not_current").show();
						$("#current").hide();
					}
				});
				//save add
				$("#saveEdit").click(function(){
					var companyId = parseInt($("#select2 option:selected").val());
					
					var companyName = $("#select2 option:selected").text();
					if (isNaN(companyId) == true || (isNaN(companyId) == false && isNaN(companyName) == false))
					{
						companyId = 0;
					}
					var newCompanyName=$(".maininput").val();
					if (companyId == 0 && !newCompanyName)
					{
						newCompanyName = companyName;
					}
					var ajax_position_title = $("#ajax_position_title").val();
					var ajax_current_work = $("#ajax_current_work").is(':checked');
					if (ajax_current_work == true)
					{
						ajax_current_work = 1;
					}
					else
					{
						ajax_current_work = 0;
					}
					var choose_month_from = $("#choose_month_from").val();
					var choose_month_to = $("#choose_month_to").val();
					var year_from = $("#year_from").val();
					var year_to = $("#year_to").val();
					var description = $("#description").val();
					//alert(companyId); //return false;
					$('#main_basic_info').css('display','none');
					$('#waiting').css('display','block');
					$("#cv_messages_error").empty().hide();
					$.ajax({
						type:"POST",
						url:link2,//rootsite + '/member/saveEditPosition',
						data:"companyId="+companyId+"&newCompanyName="+newCompanyName+"&ajax_position_title="+ajax_position_title+"&ajax_current_work="+ajax_current_work+"&choose_month_from="+choose_month_from+"&choose_month_to="+choose_month_to+"&year_from="+year_from+"&year_to="+year_to+"&description="+description+"&id="+id,
						success: function (xmlhttp)
						{
							var aryData = xmlhttp.parseJSON();
							$('#waiting').hide();
							$('#main_basic_info').show();
							if (aryData.error)
							{
								$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow');
								//close span message error
								$('#cv_message_error_close').click(function(){
									$('#cv_messages_error').fadeOut('slow');
								});
								
							}
							if(aryData.success)
							{
								//sent mail to friend
									$.ajax({
										type:"POST",
										url: $('#linkSentMailAddPosition').val(),
										success: function(){}
									});
								//end sent mail
								jQuery.facebox.close();
								location.reload();
							}																																									
						}
					});
				});
			}
		});
	}
	,
	removePosition :function (pId,link)
	{
		if (!confirm("Bạn có chắc xóa kinh nghiệm làm việc này?"))
		{
			return false;
		}
		pId = parseInt(pId);
		if (isNaN(parseInt(pId)) == true)
		{
			return false;
		}
		var rootsite = $("#rootsite").val();
		$.ajax({
			type:"POST",
			url:link,
			data:"pId="+pId,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				alert(aryData.success);
				location.reload();
			}
		});
	}
	,
	removeEducation : function (eId,link)
	{
		if (!confirm("Bạn có chắc xóa trường này khỏi quá trình học vấn của ban?"))
		{
			return false;
		}
		
		eId = parseInt(eId);
		if (isNaN(parseInt(eId)) == true)
		{
			return false;
		}
		$.ajax({
			type:"POST",
			url:link,
			data:"eId="+eId,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				alert(aryData.success);
				location.reload();
			}
		});
	}
	,
	
	editPersonalInfo : function (link,link2)
	{
		var rootsite = $("#rootsite").val();
		//ajax load form edit
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:link,
			data:"",
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				jQuery.facebox(template);
				$("#submit").click(function(){
					var ajax_phone = $("#ajax_phone").val();
					var ajax_address = $("#ajax_address").val();
					var ajax_yahoo = $("#ajax_yahoo").val();
					var ajax_skype = $("#ajax_skype").val();
					var ajax_birthday_day = $("#choose_day").val();
					var ajax_birthday_month = $("#choose_month").val();
					var ajax_birthday_year = $("#choose_year").val();
					var ajax_marital = $("#ajax_marital option:selected").val();
					$('#main_basic_info').css('display','none');
					$('#waiting').css('display','block');
					$("#cv_messages_error").empty().hide();
					$.ajax({
						type:"POST",
						url:link2,
						data:"ajax_phone="+ajax_phone+"&ajax_address="+ajax_address+"&ajax_yahoo="+ajax_yahoo+"&ajax_skype="+ajax_skype+"&ajax_birthday_day="+ajax_birthday_day+"&ajax_birthday_month="+ajax_birthday_month+"&ajax_birthday_year="+ajax_birthday_year+"&ajax_marital="+ajax_marital,
						success: function(xmlhttp)
						{
							var aryData = xmlhttp.parseJSON();
							$('#waiting').hide();
							$('#main_basic_info').show();
							if (aryData.error)
							{
								$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow');
								//close span message error
								$('#cv_message_error_close').click(function(){
									$('#cv_messages_error').fadeOut('slow');
								});
								
							}
							if(aryData.success)
							{
								jQuery.facebox.close();
								location.reload();
							}	
						}
					});
				});
			}
		});
	}
	,
	
	editAdditionalInfo : function (link,link2)
	{
		var rootsite = $("#rootsite").val();
		jQuery.facebox.loading();
		//ajax load form edit
		$.ajax({
			type:"POST",
			url:link,
			data:"",
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				var template = aryData.template;
				var title = aryData.title;
				//$('#cv_dialog_header').attr("innerHTML", title);
				//$('#cv_dialog_content').attr('innerHTML',template);
				//$("#cv_dialog").modal();
				//$("#dialog").attr("innerHTML",template);
				jQuery.facebox(template);
				$("#submit").click(function(){
					var ajax_website = $("#ajax_website").val();
					var ajax_facebook = $("#ajax_facebook").val();
					var ajax_twitter = $("#ajax_twitter").val();
					var ajax_interests = $("#ajax_interests").val();
					var ajax_groups = $("#ajax_groups").val();
					//alert(ajax_groups);
					var ajax_awards = $("#ajax_awards").val();
					$('#main_basic_info').css('display','none');
					$('#waiting').css('display','block');
					$("#cv_messages_error").empty().hide();
					$.ajax({
						type:"POST",
						url:link2,
						data:"ajax_website="+ajax_website+"&ajax_facebook="+ajax_facebook+"&ajax_twitter="+ajax_twitter+"&ajax_interests="+ajax_interests+"&ajax_groups="+ajax_groups+"&ajax_awards="+ajax_awards,
						success: function(xmlhttp)
						{
							var aryData = xmlhttp.parseJSON();
							$('#waiting').hide();
							$('#main_basic_info').show();
							if (aryData.error)
							{
								$('#cv_messages_error').empty().hide().attr('innerHTML',aryData.error).fadeIn('slow');
								//close span message error
								$('#cv_message_error_close').click(function(){
									$('#cv_messages_error').fadeOut('slow');
								});
							}
							if(aryData.success)
							{
								//sent mail to friend
								$.ajax({
									type:"POST",
									url: $('#linkSentMailEditInfo').val(),
									data: {
										},
									success: function(){}
								});
								//end sent mail
								$.modal.close();
								location.reload();
							}	
						}
					});
				});
				
			}
		});
		//return false;
	}
	,
	checkCvLangExist : function()
	{
		var rootsite = $("#rootsite").val();
		var cvlangid = $("#cvlangid").val();
		$.ajax({
			type:"POST",
			url:rootsite+"/member/checkCvLangExist",
			data:"id="+cvlangid,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.error)
				{
					$("#cv_messages_error").attr("innerHTML",aryData.error).fadeIn("slow");
				}
				else
				{
					$("#cv_messages_error").empty().hide();
				}
				return false;
			}
		});
	}
	,
	saveBlast : function ()
	{
		objMember.disElement('share', true);
		var blastContent = jQuery.trim($("#blast").val());
		if (blastContent.length<=0)
		{
			alert("Nhập nội dung blast");
			objMember.disElement('share', false);
			return false;
		}
		//ajax save blast
		$.ajax({
			type:"post",
			url: $("#linkSaveBlast").val(),
			data:"blastContent="+blastContent,
			success:function(xmlhttp)
			{
				objMember.disElement('share', false);
				var aryData = xmlhttp.parseJSON();
				if(aryData.isOK==1)
				{
					$("#updateActiviti").prepend(aryData.template).hide().fadeIn("slow");
					$("#blast").val("");
					$(".activities_list").mouseover(function(){
						$(this).find(".delete_activities").css('display','block');
					}).mouseout(function(){
						$(this).find(".delete_activities").css('display','none');
					});
					return false;
				}
				return false;
			}
		});		
	},
	
	showDialogAddToFriend : function(addId,link)
	{
		jQuery.facebox.loading();
		addId = parseInt(addId);
		if (isNaN(parseInt(addId)) == true)
		{
			alert('Error get data!');
			jQuery.facebox.close();
			return false;
		}
		
		//show dialog option
		$.ajax({
			type:"post",
			url: link,
			data:"addId="+addId,
			success: function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if(aryData.error)
					{
					alert(aryData.error); return false;
					}
				else
					{
					jQuery.facebox(aryData.template);
					}
				return true;
			}
		});
	}
	,
	changeRelationShipSelected : function()
	{
		//get option current selected
		var current_relationship = $("#relationShipId").val();
		if (current_relationship == 0)
		{
			$("#other_relationship").show();
		}
		else
		{
			$("#other_relationship").hide();
		}
		return false;
	}
	,
	addToFriend : function (addId,link)
	{
		//disable button
		objMember.disElement('btn_submit', true);
		//get relationship id
		var relationshipId = $("#relationShipId").val();
		/*
		var relationshipName = "";
		if (relationshipId == 0)
		{
			var relationshipName=  $("#relationship_name").val();
		}
		if (relationshipId == 0 && relationshipName == "")
		{
			alert('Chọn tên mối quan hệ');
			return false;
		}
		*/
		//ajax add to friend
		// display loading popup
		jQuery.facebox.loading();
		$.ajax({
			type:"post",
			url: link,
			data:"relationshipId="+relationshipId+"&addId="+addId,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.error)
				{
					jQuery.facebox(aryData.error);
					return false;
				}
				else
				{
					jQuery.facebox(aryData.success);
					$.ajax({
						type: "post",
						url: $("#linkSentMail").val(),
						data: {addId: addId},
						success: function() {
						}
					});
					location.reload();
					return false;
				}
				
			}
		});		
	}
	,
	feedbackAddFriend : function (type,user_invite,user_accept,link)
	{
		type = parseInt(type);
		user_invite = parseInt(user_invite);
		user_accept = parseInt(user_accept);
		if (isNaN(user_invite)==true || isNaN(user_accept)==true || isNaN(type)==true)
		{
			return false;
		}
		
		//ajax
		jQuery.facebox.loading();
		$.ajax({
			type:"post",
			url:link,
			data:"user_invite="+user_invite+"&user_accept="+user_accept+"&type="+type,
			success: function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				//~ $('#cv_dialog_header').attr('innerHTML', aryData.title);
				//~ $('#cv_dialog_content').attr('innerHTML', aryData.template);
				//~ $("#cv_dialog").modal();
				
				jQuery.facebox(aryData.template);
				if(aryData.redirect)
					{
					window.location=aryData.redirect;
					}
				else
					{
					location.reload();
					}
			}
		});
		return true;
	}
	,
	confirmInvite : function (type, user_invite, user_accept, e)
	{
		user_invite = parseInt(user_invite);
		user_accept = parseInt(user_accept);
		if (isNaN(user_invite)==true || isNaN(user_accept)==true)
		{
			return false;
		}
		var rootsite = $("#rootsite").val();
		//ajax
		$.ajax({
			type:"post",
			url: $('#linkConfirmConnect').val(),
			data:"type="+type+"&userInviteId="+user_invite+"&userInvitedId="+user_accept,
			success: function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK==1)
				{
					if(aryData.type==1)
						{
						//delete notice
						if(e)
						{
							var noticeId = $(e).parents('li').attr('id');
							$.ajax({
								type:"post",
								url:rootsite+"/member/deleteNotice",
								data:"noticeId="+noticeId,
								success: function(xmlhttp)
								{
								$("#"+noticeId).slideUp();
								}
							});
						}
						//document.location=aryData.redirectUrl;
						}
				}
				else
				{
					alert('Error process data!');
					$.modal.close();
				}
				/**
				$.ajax({
					type: "post",
					url: rootsite + "/member/sentMailOk",
					data: {
						user_invite: user_invite,
						type: type
					},
					success: function() {
						return;
					}
				});
				* */
			}
		});
	}
	,
	displayPrintHTML: function() {
		var rootsite = $('#rootsite').val();
		var inf = "<link media='all' type='text/css' rel='stylesheet' href='"+rootsite+"/modules/member/templates/default/css/style.css'>";
		inf += "<a title='Print this profile' href='javascript:window.print();'>";
		inf += "<img src='"+rootsite+"/modules/member/templates/default/images/print.gif' width='25px' height='25px' style='border:0'>Print</a>";
		inf += $('#cv_intro').html() + $('#cv_container').html();
		inf += "<a title='Print this profile' href='javascript:window.print();'>";
		inf += "<img src='"+rootsite+"/modules/member/templates/default/images/print.gif' width='25px' height='25px' style='border:0'>Print</a>";
		var win = window.open("print.html", "popup", "toolbar = no, status = no, scrollbars=1");
		win.document.write(inf);
		win.document.close(); // new line
	},
	//~ displayPdfHTML: function(pdfContent) {
		//~ //alert($('.'+pdfContent).html());
		//~ //alert($('#linkPdf').val());
		//~ $.ajax({
			//~ type: 'POST',
			//~ url: $('#linkPdf').val(),
			//~ data: {data:$('.'+pdfContent).html(),},
			//~ success:function() {
				//~ alert($('.'+pdfContent).html());
				//~ alert("ok");
			//~ },
		//~ });
	//~ },
	/**
	 * show started step 1
	 * tuantt
	 * 19.10.2010
	 * */
	onChangeStarted: function(id, n) {
		var val = $(id).val();
		if(n != 0) {val = id}
		if($('#getStarted_'+val).css('display') == 'none' || n==0) {
			$('.getStarted').hide();
			$('#getStarted_'+val).show();
		} else {$('.getStarted').hide();}
		return;
	},
	/*
	 * show dialog view all friends of user
	 * longNT created date 8/7/2010
	 */
	viewAllFriend : function (userId)
	{
		userId = parseInt(userId);
		if (isNaN(userId)==true)
		{
			return false;
		}
		var rootsite = $("#rootsite").val();
		//get temp and data friends about
		
		$.ajax({
			type:"post",
			url:rootsite+"/member/getAllFriendOfUser",
			data:"userId="+userId,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				//~ $('#dialog_header').attr('innerHTML', aryData.title);
				//~ $('#dialog_content').attr('innerHTML', aryData.template);
				//~ $("#dialog").modal();
				jQuery.facebox.loading();
				jQuery.facebox(aryData.template);
			}
		});
	},
	viewAllComment : function(url,id){
		var control = $('#control').val();
		$.ajax({
			type:"POST",
			url:url,
			data:"ajax=1&discId="+id+'&control='+control,
			success:function(xmlhttp){
				var objData = xmlhttp.parseJSON();
				if(objData.control){
					$('#viewAllCommentMember_'+objData.discId).html(objData.template);
					$('#showAllCommentMember_'+objData.discId).css('display','none');
					$('#hideAllCommentMember_'+objData.discId).css('display','');
				}
				else
					$('#viewAllComment').html(objData.template);
			}
		});
	},
	sendComment : function(){
		var urlCmm = $('#urlWriteComment').val();
		var cont = $('#writeComment').val();
		var groupId = $('#groupIdC').val();
		var parentId = $('#parentIdC').val();
		if(cont){
				$.ajax({
				type:"POST",
				url:urlCmm,
				data:"ajax=1&content="+cont+'&parent_id='+parentId+'&group_id='+groupId,
				success:function(xmlhttp){
					var objData = xmlhttp.parseJSON();
					$('.listCommentAfterDel .inner').append(objData.template);
					$('#writeComment').attr('value','');
				}
			});
		}
		else {
			var obj = {message:' Chưa viết nội dung', title:'Thông báo', height:150};
			objOverlay.showAlert(obj);
		}
	},
	deleteComment : function(comment_id){
		var urlDelCmm = $('#urlDelComment').val();
		var parentId = $('#parentIdC').val();
		var groupId = $('#groupIdC').val();
		$.ajax({
				type:"POST",
				url:urlDelCmm,
				data:'ajax=1&parent_id='+parentId+'&comment_id='+comment_id,
				success:function(xmlhttp){
					var objData = xmlhttp.parseJSON();
					$('#listCommentAfterDel').html(objData.template);
				}
			});
	},
	viewDiscByMember : function(group_id,member_id){
		var urlViewMember = $('#urlViewMember').val();
		var urlGroupMember = $('#urlGroupMember').val();
		$.ajax({
				type:"POST",
				url:urlViewMember,
				data:'ajax=1&group_id='+group_id+'&member_id='+member_id+'&urlGroupMember='+urlGroupMember,
				success:function(xmlhttp){
					var objData = xmlhttp.parseJSON();
					if($('#viewCommentDiscByMember_'+objData.member_id).css('display') == 'block')
					{	
						$('#viewCommentDiscByMember_'+objData.member_id).html('');
					}
					//alert($('#viewCommentByMember_'+objData.member_id).css('display'));
					if($('#viewCommentByMember_'+objData.member_id).css('display') == 'none'){
						$('#viewCommentByMember_'+objData.member_id).css('display','');
					}
					//alert($('#hideCommentByMember_'+objData.member_id).css('display'));
					if($('#hideCommentByMember_'+objData.member_id).css('display') == 'inline'){
						$('#hideCommentByMember_'+objData.member_id).css('display','none');
					}
					if($('#viewDiscByMember_'+objData.member_id).css('display') == 'none')
						$('#viewDiscByMember_'+objData.member_id).css('display','');
					$('#viewDiscByMember_'+objData.member_id).html(objData.template);
					$('#viewDiscMemberGroup_'+objData.member_id).css('display','none');
					$('#hideDiscMemberGroup_'+objData.member_id).css('display','');
				}
			});
	},
	hideDiscByMember : function(group_id,member_id){
		$('#viewDiscByMember_'+member_id).html('');
		$('#viewDiscMemberGroup_'+member_id).css('display','');
		$('#hideDiscMemberGroup_'+member_id).css('display','none');
	},
	hideAllComment : function(url,id){
		$('#viewAllCommentMember_'+id).html('');
		$('#showAllCommentMember_'+id).css('display','');
		$('#hideAllCommentMember_'+id).css('display','none');
	},
	viewCommentByMember : function(group_id,member_id){
		var urlViewCommentMember = $('#urlViewCommentMember').val();
		var urlGroupMember = $('#urlGroupMember').val();
		$.ajax({
				type:"POST",
				url:urlViewCommentMember,
				data:'ajax=1&group_id='+group_id+'&member_id='+member_id+'&urlGroupMember='+urlGroupMember,
				success:function(xmlhttp){
					var objData = xmlhttp.parseJSON();
					if($('#viewDiscByMember_'+objData.member_id).css('display') == 'block')
						$('#viewDiscByMember_'+objData.member_id).html('');
					if($('#viewDiscMemberGroup_'+objData.member_id).css('display') == 'none'){
						$('#viewDiscMemberGroup_'+objData.member_id).css('display','');
					}
					if($('#hideDiscMemberGroup_'+objData.member_id).css('display') == 'inline'){
						$('#hideDiscMemberGroup_'+objData.member_id).css('display','none');
					}
					$('#viewCommentDiscByMember_'+member_id).html(objData.template);
					$('#viewCommentByMember_'+objData.member_id).css('display','none');
					$('#hideCommentByMember_'+objData.member_id).css('display','');
				}
			});
	},
	hideCommentByMember : function(group_id,member_id){
		$('#viewCommentDiscByMember_'+member_id).html('');
		$('#viewCommentByMember_'+member_id).css('display','');
		$('#hideCommentByMember_'+member_id).css('display','none');
	},
	
	showDialogSelectFriend : function (host,userId)
	{
		jQuery.facebox.loading();
		//window.open( host+"/member/popup?type=2", "myWindow", "status = 1, height = 500, width = 700, resizable = 1, scrollbars=1" );
		$.ajax({
			type: 'post',
			url: host,
			data: {type:2},
			success: function(xmlhttp) {
				var objData = xmlhttp.parseJSON();
				jQuery.facebox(objData.templates);
				$('.body').css('width', '650px');
				//jQuery.facebox(xmlhttp);
			}
		});
	}
	,
	closeFormComment : function (elementId)
	{
		$("#"+elementId).fadeOut("fast");
		return false;
	}
	,
	openFormComment : function (elementId)
	{
		$("#"+elementId).fadeIn("fast");
		return false;
	}
	,
	saveComment : function (areaId,btnSubmit)
	{
		objMember.disElement(btnSubmit, true);
		/*
		 * get comment content
		 */
		var contentComment = jQuery.trim($("#"+areaId).val());
		if (contentComment.length<=0)
		{
			objMember.disElement(btnSubmit, false);
			alert("Nhập nội dung comment"); return false;
		}
		
		$.ajax({			
			type:"POST",
			url: $("#linkSaveComment").val(),
			data:"areaId="+areaId+"&contentComment="+contentComment,
			success:function(xmlhttp){
				aryData = xmlhttp.parseJSON();
				$("#comment-list-"+aryData.activitiesId).append(aryData.templete).hide().fadeIn("fast");
				$(".comment textarea").val("");
				$(".comment-list").mouseover(function(){
					$(this).find(".delete").css('display','block');
				}).mouseout(function(){
					$(this).find(".delete").css('display','none');
				});
				objMember.disElement(btnSubmit, false);
				return false;
			}
		});
	}
	,
	deleteComment : function (commentId)
	{
		if (isNaN(parseInt(commentId)) == true)
		{
			return false;
		}
		$.ajax({			
			type:"POST",
			url: $("#linkactivitiesDeleteComment").val(),
			data:"commentId="+commentId,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK == 1)
				{
					$("li .comment-list-"+commentId).fadeOut("slow");
				}
				else
				{
					alert('Error delete comment!');
					return false;
				}
			}
		});
	}
	,
	deleteActivities : function (activitiesId, status)
	{
		if (isNaN(parseInt(activitiesId)) == true)
		{
			return false;
		}
		$.ajax({			
			type:"POST",
			url: $("#linkactivitiesDeleteActivities").val(),
			data:"activitiesId="+activitiesId+"&status="+status,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK == 1)
				{
					$("#activities-"+activitiesId).fadeOut("slow");
					return false;
				}
				else
				{
					alert('Error delete activities!');
					return false;
				}
			}
		});
	}
	,
	/*
	 * status: 1 none. 2:true. 3:false
	 */
	checkAll : function(chkall,eachClass,status){
		if (status==2)
		{
			$('input[class='+eachClass+']').each(function(){
				this.checked=true;
			});
			chkall.checked=true;
			return true;
		}
		if (status==3)
		{
			$('input[class='+eachClass+']').each(function(){
				this.checked=false;
			});
			chkall.checked=false;
			return true;
		}
		
		var checked_status = chkall.checked; 
		$('input[class='+eachClass+']').each(function(){
			this.checked=checked_status;
		});
	}
	,
	checkSubmitInvite : function(eachClass)
	{
		var check=false;
		$('input[class='+eachClass+']:checkbox:checked').each(function(){
			if (this.checked)
			{
				check=true;
				return true;
			}
		});
		if (check==true)
		{
			return true;
		}
		else
		{
			alert('Bạn chưa chọn người được gửi thư mời');
			return false;
		}
		
	}
	,
	getRecommendByRelation : function(relationName)
	{
		if (!relationName)
		{
			return false;
		}
		$("#recommend_container").css('opacity','0.4');
		$.ajax({			
			type:"POST",
			url:$('#linkRecommendRelation').val(),
			data:"relationName="+relationName,
			success:function(xmlhttp){
				$("#recommend_container").css('opacity','1');
				//alert(xmlhttp); return false;
				var aryData = xmlhttp.parseJSON();
				if (aryData.template)
				{
					$("#recommend_container").empty().attr('innerHTML',aryData.template);
					return false;
				}
				else
				{
					$("#recommend_container").attr('innerHTML','<p>Chưa có đánh giá nào cho mối quan hệ này</p>');
					return false;
				}
			}
			
		});
		
		return false;
	},
	
	/**
	 * order member
	 * tuantt
	 * 27.08.2010
	 * */
	onOrder: function(img, param, url) {
		var sort = 'ASC';
		if(img.src.lastIndexOf('administrator/templates/share/images/sortasc2.gif') == (img.src.length -'administrator/templates/share/images/sortasc2.gif'.length)) {
			sort = 'DESC';
			img.src = 'administrator/templates/share/images/sortdesc2.gif';
		}
		else {
			sort = 'ASC';
			img.src = 'administrator/templates/share/images/sortasc2.gif';
		}
		document.location=url+'/param/'+param+'/sort/'+sort;
		return;
	}
	,
	hiddenSuggestConnect : function (elementId)
	{
		$("#"+elementId).hide();
		return false;
	}
	,
	showOverlayAddConnect : function (userId,element, link)
	{
		
		var result = this.showDialogAddToFriend(userId, link);
		
		if (result)
		{
			alert(result);
			$("#"+element).remove();
		}
	},
	/** NghiaPT 
		desc: save profile 
		date: 30/10/2010
	**/
	saveCandicate : function(){
		var urlSaveCandicate = $("#url_save_candicate").val();
		var userID =  $('#userId').val();
		var profileID = $('#profileId').val();
		var note = $('#noticeSaveToRecruitment').val();
		$('#facebox #blue-button-save-profile').html('<span> Hoàn thành </span>');
		//alert(note); return false;
		$.ajax({
			type:"POST",
			url:urlSaveCandicate,//rootsite+"/member/saveCandicate",
			data:"ajax=1&userID="+userID+'&profileID='+profileID+'&note='+note,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterSaveComplete').html(aryData.template);
					jQuery.facebox.close();
				}
			}
		});
	},
	deleteProfileSave : function(id){
		$('#blue-button-del-save-profile').html('<span> Đã được lưu | <font color="red"> Xóa </font></span>');
		var urlDeleteProfileSave = $("#url_delete_profile_save").val();
		var userID =  $('#userId').val();
		var profileID = $('#profileId').val();
		$.ajax({
			type:"POST",
			url:urlDeleteProfileSave,//rootsite+"/member/deleteProfileSave",
			data:"ajax=1&userID="+userID+'&profileID='+profileID+'&saveId='+id,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterSaveComplete').html('<a id="blue-button" class="blue-button pcb" href="javascript:void(0);">'
						+ "<span onclick='objMember.dataSaveProfile();'> Lưu hồ sơ </span></a>");
					
					//<a href="#" onclick="objMember.dataSaveProfile(); return false;"> Lưu lại </a>');
				}
			}
		});
		return location.reload();
	},
	dataSaveProfile : function(){
		var urlDataSaveProfile = $("#url_data_save_profile").val();
		var profileID = $('#profileId').val();
		var headline = $('#nameProfile').val();
		//alert(urlDataSaveProfile); return false;
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:urlDataSaveProfile,//rootSite+"/member/dataSaveProfile",
			data:"ajax=1"+'&id='+profileID+'&nameProfile='+headline,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				var data = aryData.template;
				if(parseInt(aryData.isOk))
					jQuery.facebox(data);
			}	
		});	
	},
	/** NghiaPT 
		desc: recruitment following member
		date: 30/10/2010
	**/
	getDataFollowingMember : function(){		
		var urlGetDataFollowingMember = $("#url_get_data_following_member").val();
		var userId = $('#userId').val();
		var name= $('#nameMember').val();
		jQuery.facebox.loading();
		$.ajax({
			type:"POST",
			url:urlGetDataFollowingMember,//rootSite+"/member/dataFollow",
			data:"ajax=1"+'&userID='+userId+'&nameMember='+name,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				var data = aryData.template;
				if(parseInt(aryData.isOk))
					jQuery.facebox(data);
			}	
		});	
	
	},
	followingMember : function(){
		var urlFollowingMember = $("#url_following_member").val();
		var userID = $('#userId').val();
		var note = $('#facebox #following #contentFollowingMember #noticeFollowingMember').val();
		$('#facebox #blue-button-following-member').html('<span> Hoàn thành </span>');
		//alert(note+userID); return false;
		$.ajax({
			type:"POST",
			url:urlFollowingMember,//rootsite+"/member/setFollowingMember",
			data:"ajax=1&userID="+userID+'&note='+note,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterFollowingMember').html('<a id="blue-button-del-follow-member" class="blue-button pcb" href="javascript:void(0);">'
					+ '<span onclick="javascript:objMember.deleteFollow('+aryData.followId+');"> Đang xin theo | <font color=\'red\'> Xóa </font></span>');
					
					//<span>Đang xin theo </span>' 
					//+ '<a href="javascript:objMember.deleteFollow('+aryData.followId+');"> Không theo </a>');
					jQuery.facebox.close();
				}
			}
		});
	},
	deleteFollow : function(id){
		var urlDeleteFollow = $("#url_delete_follow").val();
		$('#blue-button-del-follow-member').html("<span>Đang xin theo | <font color='red'> Xóa </font></span>");
		$.ajax({
			type:"POST",
			url:urlDeleteFollow,//rootsite+"/member/deleteFollowing",
			data:"ajax=1&followID="+id,
			success:function(xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if (aryData.isOK)
				{
					$('#resultAfterFollowingMember').html('<a id="blue-button-following-member" class="blue-button pcb" href="javascript:void(0);">'
					+'<span onclick="objMember.getDataFollowingMember();"> Lưu ghi chú và xin theo </span></a>');
					
					
					//'<a href="#" onclick="objMember.getDataFollowingMember(); return false;"> Theo </a>');
				}
			}
		});
	},
	/*
	 * @param  userId: Danh sách bạn bè của người này
	 * @param  userViewId: Người xem ID
	 */
	blockFriendOfUser : function (userId,userViewId)
	{
		if(isNaN(parseInt(userId))==true || isNaN(parseInt(userViewId))==true)
				{
			alert('Error process!');
				}
		jQuery.facebox.loading();
		//ajax here
		$.ajax
		({
			type:"POST",
			url:$("#dialogBlockFriendList").val(),
			data:"userId="+userId+"&userViewId="+userViewId,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				jQuery.facebox(aryData.template);
				
			}
		});
	},
	ajaxLoadDetailContact : function(userId)
	{
		
		if(isNaN(parseInt(userId))==true)
			{
			alert('Error Process');
			}
			
		//ajax here
		$("#detail_contact").css('display','none');
		$("#loading").css('display','block');
		$.ajax
		({
			type:"POST",
			url: $("#linkGetFullMemberInfo").val(),
			data:"userId="+userId,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				$("#detail_contact").attr('innerHTML',aryData.template);
				$("#detail_contact").css('display','block');
				$("#loading").css('display','none');
			}
		});
	},
	submitFormUniversity : function(idForm){
		$('#'+idForm).submit();
	}
	,
	noticeReadmore : function()
	{
		var rootsite = $("#rootsite").val();
		var numberShow = parseInt($("#notice_number_show").val());
		if(isNaN(numberShow)==true || !numberShow)
			{
			numberShow=10;
			$("#notice_number_show").val(10);
			}
		if(numberShow)
		{
			$("#notice_loading").show();
			$.ajax
			({
				type:"POST",
				url:rootsite+"/member/ajaxOlderNotice",
				data:"curentNumber="+numberShow,
				success: function (xmlhttp)
				{
					var aryData = xmlhttp.parseJSON();
					if(aryData.isOK==1)
						{
						$("#notice_container").append(aryData.template);
						//update notice_number_show
						$("#notice_number_show").val(aryData.notice_number_show);
						}
					else
						{
						$("#notice_container").append(aryData.template);
						$("#notice_read_more").remove();
						}
					$("#notice_loading").hide();
				}			
			});
		}
		
	}
	,
	activitiesReadmore : function(filter)
	{
		var rootsite = $("#rootsite").val();
		var numberShow = parseInt($("#activities_number_show").val());
		//if(parseInt(filter)!=2) filter=1;
		if(numberShow && rootsite)
		{
			$("#notice_loading").show();
			$.ajax
			({
				type:"POST",
				url: $("#linkAjaxOlderActivities").val(),
				data:"curentNumber="+numberShow+"&filter="+filter+"&id_member="+$('#id_member').val(),
				success: function (xmlhttp)
				{
				var aryData = xmlhttp.parseJSON();
				if(aryData.isOK==1)
				{
				$("#ul_list_activities").append(aryData.template);
				//update notice_number_show
				$("#activities_number_show").val(aryData.activities_num_show);
				//show icon delete activities
				    $(".activities_list").mouseover(function(){
						$(this).find(".delete_activities").css('display','block');
					}).mouseout(function(){
						$(this).find(".delete_activities").css('display','none');
					});
				}
				else
				{
				$("#ul_list_activities").append(aryData.template);
				$("#notice_read_more").remove();
				}
				$("#notice_loading").hide();
				}
			});
		}
	}
	,
	savePublicUrl : function ()
	{
		objMember.disElement('savePP', true);
		//$("#savePP").attr('disabled',true);
		$("#image_loading").show();
		var data = $("#public_url").val();
		var rootsite = $("#rootsite").val();
		//ajax
		$.ajax
		({
			type:"POST",
			url: $("#linkSavePublicUrl").val(),
			data:"data="+data,
			success: function (xmlhttp)
			{
				var aryData = xmlhttp.parseJSON();
				if(aryData.error==1)
					{
					$("#cv_messages").empty().hide();
					$("#cv_messages_error").attr('innerHTML',aryData.messages);
					$("#cv_messages_error").show();
					//close span message error
					$('#cv_message_error_close').click(function(){
						$('#cv_messages_error').fadeOut('slow');
					});
					}
				if(aryData.success == 1)
					{
					$("#current_url").attr('innerHTML','<a target="_bank" href="'+aryData.linkCV+'">'+aryData.linkCV+'</a>');
					$("#cv_messages_error").empty().hide();
					$("#cv_messages").attr('innerHTML',aryData.messages);
					$("#cv_messages").show();	
					$('#cv_message_error_close').click(function(){
						$('#cv_messages').fadeOut('slow');
					});
					}
				objMember.disElement('savePP', false)
				$("#image_loading").hide();				
			}			
		});
	}
	,
	disElement : function(element,value)
	{
		$("#"+element).attr('disabled',value);
		return true;
	}
	,
	customProfilePart : function(e)
	{
		var value=e.value;
    	if(e.checked==true)
		{
    		$("#image_"+value).css('display','block');
		}
    	if(e.checked==false)
    	{
    		$("#image_"+value).css('display','none');
    	}
	}
	,
	saveSettingProfile : function()
	{
		$("#btn_save_profile").attr('disabled',true);
		$("#image_loading_2").show();
		return true;
	},
	
	/**
	 * setting mail
	 * tuantt
	 * 01.10.2010
	 * */
	settingEmail: function() {
		$.ajax ({
			type:"POST",
			url: $('#linkSetMail').val(),
			data: $('#fmSetMail').serialize(),
			success: function (){
			}			
		});
	}
	,
	facebox : function ()
	{
		$("#dialog").attr("innerHTML",'Hello faceBox');
		return true;
	},
	//sent cv to friend
	onCompose: function(){
		$('#sentMessage').submit();
	},
	onSaveCV: function(id){
		if(id == 0) {objMember.dataSaveProfile();}
		else {
			objMember.deleteProfileSave(id);
			location.reload();
		}
		return;
	}
	
	,
	//changer status work of memebr
	onStatusWork: function(status_work){
		jQuery.facebox.loading();
		$.ajax({
			type: 'post',
			url: $('#linkChangerStatusWork').val(),
			data: {status_work: $('#'+status_work).val()},
			success: function(xmlhttp) {
				var objData = xmlhttp.parseJSON;
				if(!objData.error) {
					jQuery.facebox.loading();
					jQuery.facebox('Bạn đã thay đổi thành công trạng thái công việc của bạn');
					location.reload();
				} else {
					jQuery.facebox(objData.error);
				}
			}
		});
		return;
	},
	onListFunction: function() {
		jQuery.facebox.loading();
		$.ajax({
			type: 'post',
			url: $('#linkFunction').val(),
			success: function(xmlhttp) {
				if(xmlhttp) {
					jQuery.facebox.loading();
					jQuery.facebox(xmlhttp);
				} else {
					jQuery.facebox('Không thể kết nối tới server');
				}
			}
		});
		return;
	},
	onChangerFunction: function() {
		/**get list industry of member*/
		var industry_size = $("#seListIndus option:selected").size();
		if(industry_size > 3) {
			jQuery.facebox("Bạn chỉ được chon tối da 3 ngành nghề mà bạn có thể làm việc");
			return;
		} else if (industry_size<=0) {
			jQuery.facebox("Bạn chưa chọn ngành nghề có thể làm việc");
			return;
		}
		var function_id = "";
		var i=0;
		$("#seListIndus option:selected").each(function(){
			if(i==0) {function_id+=this.value;}
			else {function_id+=","+this.value;}
			i++;
		});
		if(!function_id || function_id == 0) {return jQuery.facebox('Bạn chưa chọn ngành ngề tương ứng');}
		
		$.ajax({
			type: 'post',
			url: $('#linkChangerFunction').val(),
			data: {function_id: function_id},
			success: function() {
				objMember.onStatusWork('status_work_1');
			}
		});
		return;
	},
	fillData: function(fName, lName, email) {
		$('#fname').val(fName);
		$('#lname').val(lName);
		$('#email').val(email);
		jQuery.facebox.close();
	},
	
	/**
	 * block seach my friend
	 * tuantt
	 * 17.11.2010
	 * */
	filterFriend: function(url) {
		this.selectFriendForSeach();
		$.ajax ({
			type: 'post',
			url: url,
			data: {
				ajax: 1,
				keySeach: $('#keySeachFriend').val(),
				total: $('#total').val()
			},
			success: function(xmlHtml) {
				var objPHP = xmlHtml.parseJSON();
				if(objPHP.intOK > 0) {
					$('#list_contact').html(objPHP.template);
				}
			}
		});
	},
	/**
	 * block seach my friend by type
	 * type = 1 : company
	 * tupe = 2 : education
	 * tuantt
	 * 18.11.2010
	 * */
	filterFriendByType: function(nameCompany, education_id, type) {
		$.ajax ({
			type: 'post',
			url: $('#linkContact').val(),
			data: {
				ajax: 1,
				objName: nameCompany,
				education_id: education_id,
				keyType: type
			},
			success: function(xmlHtml) {
				var objPHP = xmlHtml.parseJSON();
				if(objPHP.intOK > 0) {
					$('#list_contact').html(objPHP.template);
				}
			}
		});
	},
	selectFriendForSeach: function() {
		$('#selectFriendForSeach').css('display', 'block');
		$.ajax ({
			type: 'post',
			url: $('#linkSelectFriendForSeach').val(),
			data: {
				keySeach: $('#keySeachFriend').val()
			},
			success: function(xmlHtml) {
				var objPHP = xmlHtml.parseJSON();
				if(objPHP.intOK > 0) {
					$('#selectFriendForSeach').html(objPHP.template);
				}
			}
		});
	},
	
	onSeachFriend: function(url) {
		$.ajax ({
			type: 'post',
			url: url,
			data: $('#frmSeachFriend').serialize(),
			success: function(xmlHtml) {
				var objPHP = xmlHtml.parseJSON();
				if(objPHP.intOK > 0) {
					$('#list_contact').html(objPHP.template);
				}
			}
		});
	},
	onSeachByCompany: function(url, txtCompany) {
		$.ajax ({
			type: 'post',
			url: url,
			data: {txtCompany: txtCompany},
			success: function(xmlHtml) {
				var objPHP = xmlHtml.parseJSON();
				if(objPHP.intOK > 0) {
					$('#list_contact').html(objPHP.template);
				}
			}
		});
	},
	onSeachByEdu: function(url, seEdu) {
		$.ajax ({
			url: url,
			data: {seEdu: seEdu},
			success: function(xmlHtml) {
				var objPHP = xmlHtml.parseJSON();
				if(objPHP.intOK > 0) {
					$('#list_contact').html(objPHP.template);
				}
			}
		});
	},
	onSentInviteFriend: function(urlCheck, url) {
		var txtEmail = $('#emailInvite').val();
		var txtContent = $('#txtContent').val();
		$.ajax ({
			type: 'post',
			url: urlCheck,
			data: {txtEmail: txtEmail},
			success: function(http) {
				var data = http.parseJSON();
				if(data.intOk == 1) {
					$.ajax ({
						type: 'post',
						url: url,
						data: {
							txtEmail: txtEmail,
							txtContent : txtContent
						},
						success: function() {
							jQuery.facebox("Hệ thống đã gửi tới bạn của bạn một email mời kết nối");
						}
					});
				} else {
					jQuery.facebox(data.error);
				}
			}
		});
		
	},
	close : function(){
		jQuery.facebox.close();
	},
	readFormForgot : function(){
		$('#formLogin').css('display','none');
		$('#formForgotPass').css('display','block');
		$('#emailForgotPass').focus();
		$('#facebox #formLogin').css('display','none');
		$('#facebox #formForgotPass').css('display','block');
		$('#facebox .popup .body #emailForgotPass').focus();
	},
	forgotPass : function(){
		var rootSite = $('#rootsite').val();
		$('#btnForgotPass').attr('disabled',true);
		$('#btnForgotPass').css('background', 'url('+rootSite+'/templates/tuyendung/images/menunav/main_bottom_bg.png');
		$('#btnForgotPass').val('Đang xử lý ');
		var email = '';
		email = $('#emailForgotPass').val();
		var token = $('#token').val();
		$.ajax({
			type:"POST",
			url: $("#linkForgotPass").val(),
			data:"ajax=1&email="+email+"&token="+token,
			success:function(xmlhttp){
				var aryData = xmlhttp.parseJSON();
				if(!parseInt(aryData.error)) {
					var html= aryData.codeSuccess;
					objMember.turnOn(html);   
					$('#facebox .popup .body .footer').css('display','none');
					var heightOvl = $('#facebox').height();
					var height = $(window).height();
					var top = parseFloat((height - heightOvl - 50)/2);
					$('#facebox').css({
						'top': top+'px'
					});
					setTimeout("objMember.close()",10000);
					//jQuery.facebox.close();
				} else {
					$('#facebox #token').val(aryData.upToken);
					$('#facebox #errorReturn').text(aryData.codeError);
				}
				$('#btnForgotPass').removeAttr('disabled');
				$('#btnForgotPass').val('Gửi mật khẩu');
				$('#btnForgotPass').css('background', 'url('+rootSite+'/modules/member/template/default/images/sprite_global_v1.png) no-repeat scroll 0 -260px #3399CC');
			}
		});
	},
	turnOn : function(html){
		jQuery.facebox(html);
	},
	goBackUrl : function(){
		window.history.back(-1);
	},
	submitForm : function(form_id){
		$('#'+form_id).submit();
	},
	disableBtn : function(btn_id,form_id){
		$('#'+btn_id).attr('disabled',true);
		objMember.submitForm(form_id);
	},
	/**
	 * get list comment for activities
	 * tuantt
	 * 15.12.2010
	 * */
	getListComment: function(listId, url, key, total) {
		$("#comment"+key).show();
		$.ajax({
			type: "post",
			url: url,
			data: {listId: listId,
					key: key,
					total: total
				},
			success:function(xmlhttp){
				$('#listComment'+key).html(xmlhttp);
				$("#comment"+key).hide();
			}
		});
	},
	getListCityByCountry: function(id_country, id_city){
		$.ajax({
			type: "post",
			url: $('#linkGtListCityByCountry').val(),
			data: {id_country: $(id_country).val(),
					id_city: id_city
				},
			success:function(xmlhttp){
				$('#changetCity').html(xmlhttp);
			}
		});
	},
	submitForgot : function(e,idForm){
		if(e.keyCode == 13) $('#'+idForm).submit();
	},
	changerTypeConnect : function(url){
		$.ajax({
			type: "post",
			url: url,
			data: {type: $('#changerConnect').val()},
			success:function(xmlhttp){
				location.reload();
			}
		});
	}
};

$(document).ready(function(){
	//close message
	$('#cv_message_error_close').click(function(){
		$('#cv_messages_error').fadeOut('slow');
		$('#cv_messages').fadeOut('slow');
	});
	//close warning
	$('#warning_close_label').click(function(){
		$('#warning').fadeOut('slow');
	});
	//edit blast
	var foo = function()
	{
		$("#btn_save_blast").click(function(){
			alert('click');
			});
	}
	
	$("#div_blast").bind('click',function(){
		$("#div_blast").hide();
		$("#div_textarea").show();
		$("#textarea_blast").focus();
		var t=setTimeout("foo()",2000);
		return true;
	});
	$("#textarea_blast").bind('blur',function(){
		$("#div_blast").css('display','block');
		//$("#div_textarea").hide();	
		return true;
	});
	//$("#menuList ul,#menuList ul").hover( function() { $(this).addClass("ovlListMenu"); }, function() { $(this).removeClass("ovlListMenu"); } ); 
	/*
	 * show icon delete comment on hover
	 */
    $(".comment-list").mouseover(function(){
		$(this).find(".delete").css('display','block');
	}).mouseout(function(){
		$(this).find(".delete").css('display','none');
	});
	/*
	 * show icon delete activities on hover
	 */
    $(".activities_list").mouseover(function(){
		$(this).find(".delete_activities").css('display','block');
	}).mouseout(function(){
		$(this).find(".delete_activities").css('display','none');
	});
	//custom cv part
    $("#custom_cv input[type='checkbox']").click(function()
    	{
    	objMember.customProfilePart(this);
    	return true;
    	}	
    );
    //close message
    $("#cv_message_close").click(function(){
    	$(this).parents('[id$=cv_messages_error]').fadeOut();
    	$(this).parents('[id$=cv_messages]').fadeOut();
    });
	if($('#forgotPassStart').val()){
		var html= $('#messageForgotPass').html();
		objMember.turnOn(html);
		$('#facebox .popup .body #emailForgotPass').focus();
		//$('#facebox .popup .body .footer').css('display','none');
		var heightOvl = $('#facebox').height();
		var height = $(window).height();
		var top = parseFloat((height - heightOvl - 100)/2);
		$('#facebox').css({
			'top': top+'px'
		});
		setTimeout("objMember.close()",20000);
	}
   
	/** tuantt begin fix ie6 **/
	if (parseFloat(navigator.appVersion.split("MSIE")[1]) == 6) {
		$("#mainViewCom li").hover(
			function () {
				if($(this).children('ul').css("display") != "block") {
					$(this).children('ul').css("display", "block");
				} else {
					$(this).children('ul').css("display", "none");
				}
			}
		);
		$(".status li").hover(
			function () {
				if($(this).children('.status_work').css("display") != "block") {
					$(this).children('.status_work').css("display", "block");
				} else {
					$(this).children('.status_work').css("display", "none");
				}
			}
		);
	}
	/** End fix ie6 **/
	// NghiaPT add 07/12
	// redirect url when login
	var urlRedirectAfterLogin = '';
	objMember.urlRedirectAfterLogin = window.location.toString();	
	if(parseInt($('#modChangePass').val())){
		$('#current_password').val('');
		$('#current_password').focus();
		$('#confirm_new_password').bind('keypress',function(e){
			if(e.keyCode == 13) $('#submit_form').trigger('click');
		});
	}
	/*$('#emailForgotPass').bind('keydown',function(e){
		alert('test');
		if(e.keyCode == 13) $('#btnForgotPass').trigger('click');
	});*/
	$('#frmMember').submit(function() {
		alert('test');
		//get user input and create random number
		//var input = ($(this).serialize());
		//var rand = Math.random();

		//submit post to check.php and reload image
		/*$.post('check.php', input, function(data) {
			$('div.result').html(data);
			$('img.captcha').attr("src", 'captcha.php?' + rand);
		});*/

		//return false;
		//});
	});
});

