/**
 *	CResume Class
 *	Create @ 2008-03-25 by liuqixing
 */
function CResume()
{
	var m_oThis	= this;
	var m_oLang	= {};

	this.setLang = function( oLang )
	{
		m_oLang = oLang;
	};

	this.eduAddNew = function()
	{
		$sw( "id_tr_edu_buttons", false );
		$sw( "id_tr_edu_panel", true );
		$sw( "id_tr_edu_content", false );

		$swt( "id_edu_school", "" );
		$swt( "id_edu_major", "" );
		$swt( "id_edu_desc", "" );
	};
	this.eduDelete = function()
	{
		var i;
		var oSel	= $( "id_edu_list" );
		if ( vw_get_selected_num( "id_edu_list" ) )
		{
			oSel.options[ oSel.selectedIndex ] = null;

			updateSelectDataToInput( $( "id_edu_list" ), "id_edu_info" );
		}
	};
	this.eduSave = function()
	{
		var edu_time_start	= $gwt( "id_edu_time_start_y" ) + "-" + $gwt( "id_edu_time_start_m" ) + "-" + $gwt( "id_edu_time_start_d" );
		var edu_time_end	= $gwt( "id_edu_time_end_y" ) + "-" + $gwt( "id_edu_time_end_m" ) + "-" + $gwt( "id_edu_time_end_d" );
		var edu_school		= $gwt( "id_edu_school" );
		var edu_major		= $gwt( "id_edu_major" );
		var edu_degree		= $gwt( "id_edu_degree" );
		var edu_desc		= $gwt( "id_edu_desc" ).replace( /\r\n/, "" );

		$swt( "id_edu_school_hint", "" );
		$swt( "id_edu_major_hint", "" );
		$swt( "id_edu_degree_hint", "" );

		if ( '' == edu_school )
		{
			$swt( "id_edu_school_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			return;
		}
		if ( '' == edu_major )
		{
			$swt( "id_edu_major_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			return;
		}
		if ( '' == edu_degree )
		{
			$swt( "id_edu_degree_hint", lib_get_followhinthtml( "err", m_oLang['system_please_select'], 300 ) );
			return;
		}
		
		var sText	= edu_time_start + " ~ " + edu_time_end + "    " + edu_school;
		var sValue	= edu_time_start + " ~ " + edu_time_end + "    " + edu_school + " --- " + edu_major + " --- " + edu_degree + " --- " + edu_desc;
		var oSel	= $( "id_edu_list" );

		oSel.options[ oSel.length ] = new Option( sText, sValue );
		
		updateSelectDataToInput( $( "id_edu_list" ), "id_edu_info" );

		//	关闭窗口
		m_oThis.eduCancel();
	};
	this.eduCancel = function()
	{
		$sw( "id_tr_edu_buttons", true );
		$sw( "id_tr_edu_panel", false );
		$sw( "id_tr_edu_content", true );
	};
	

	this.wepAddNew = function()
	{
		$sw( "id_tr_wep_buttons", false );
		$sw( "id_tr_wep_panel", true );
		$sw( "id_tr_wep_content", false );

		$swt( "id_wep_company", "" );
		$swt( "id_wep_department", "" );
		$swt( "id_wep_job_title", "" );
		$swt( "id_wep_desc", "" );
	};
	this.wepDelete = function()
	{
		var i;
		var oSel	= $( "id_wep_list" );
		if ( vw_get_selected_num( "id_wep_list" ) )
		{
			oSel.options[ oSel.selectedIndex ] = null;
			
			updateSelectDataToInput( $( "id_wep_list" ), "id_wep_info" );
		}
	};
	this.wepSave = function()
	{
		var wep_time_start	= $gwt( "id_wep_time_start_y" ) + "-" + $gwt( "id_wep_time_start_m" ) + "-" + $gwt( "id_wep_time_start_d" );
		var wep_time_end	= $gwt( "id_wep_time_end_y" ) + "-" + $gwt( "id_wep_time_end_m" ) + "-" + $gwt( "id_wep_time_end_d" );
		var wep_company		= $gwt( "id_wep_company" );
		var wep_industry	= $gwt( "id_wep_industry" );
		var wep_company_type	= $gwt( "id_wep_company_type" );
		var wep_department	= $gwt( "id_wep_department" );
		var wep_job_title	= $gwt( "id_wep_job_title" );
		var wep_desc		= $gwt( "id_wep_desc" ).replace( /\r\n/, "" );;

		$swt( "id_wep_company_hint", "" );
		$swt( "id_wep_industry_hint", "" );
		$swt( "id_wep_company_type_hint", "" );
		$swt( "id_wep_department_hint", "" );
		$swt( "id_wep_job_title_hint", "" );

		if ( '' == wep_company )
		{
			$swt( "id_wep_company_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			return;
		}
		if ( '' == wep_industry || '--Please Select--' == wep_industry )
		{
			$swt( "id_wep_industry_hint", lib_get_followhinthtml( "err", m_oLang['system_please_select'], 300 ) );
			return;
		}
		if ( '' == wep_company_type || '--Please Select--' == wep_industry )
		{
			$swt( "id_wep_company_type_hint", lib_get_followhinthtml( "err", m_oLang['system_please_select'], 300 ) );
			return;
		}
		if ( '' == wep_department )
		{
			$swt( "id_wep_department_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			return;
		}
		if ( '' == wep_job_title )
		{
			$swt( "id_wep_job_title_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			return;
		}
		
		var sText	= wep_time_start + " ~ " + wep_time_end + "    " + wep_company;
		var sValue	= wep_time_start + " ~ " + wep_time_end + "    " + wep_company + " --- " + wep_industry + " --- " + wep_company_type + " --- " + wep_department + " --- " + wep_job_title + " --- " + wep_desc;
		var oSel	= $( "id_wep_list" );

		oSel.options[ oSel.length ] = new Option( sText, sValue );

		updateSelectDataToInput( $( "id_wep_list" ), "id_wep_info" );

		//	关闭窗口
		m_oThis.wepCancel();
	};
	this.wepCancel = function()
	{
		$sw( "id_tr_wep_buttons", true );
		$sw( "id_tr_wep_panel", false );
		$sw( "id_tr_wep_content", true );
	};
	

	//	submit resume
	this.submitResumeAddForm = function( oBtn )
	{
		var oFrm = oBtn.form;
		var callbackProc =
		{
			postfrm : function( sText, vArglist )
			{
				try
				{
					var oRes = lib_get_evalvalue( sText );
					if ( oRes )
					{
						if ( 1 == oRes['result'] )
						{	
							if ( 'addnew' == oRes['vdata']['op'] )
							{
								alert( "Congratulations, the resume was submited successfully!" );
								if ( 'resume_submit.php' == oRes['vdata']['fp'] )
								{
									vw_rd( '/resume_submit.php?status=complete' );
								}
								else
								{
									vw_rd( '/system/resume_list.php' );
								}
							}
							else if ( 'modify' == oRes['vdata']['op'] )
							{
								alert( "Congratulations, the resume was updated successfully!" );
								//window.location.reload();
							}

						}
						else
						{
							alert( oRes['error'] );
						}
					}
				}
				catch(error)
				{
					lib_process_error( error.description, "excep" );
				}

				$ew( oBtn, true );
			}
		}

		$swt( "id_rm_first_name_hint", "" );
		$swt( "id_rm_last_name_hint", "" );
		$swt( "id_rm_id_number_hint", "" );
		$swt( "id_rm_work_exp_hint", "" );
		$swt( "id_rm_residency_hint", "" );
		$swt( "id_rm_email_hint", "" );
		$swt( "id_rm_edu_info_hint", "" );
		$swt( "id_rm_wep_info_hint", "" );
		

		var nw_title	= vw_trim( $gwt( oFrm.nw_title ) );
		var nw_content	= vw_trim( $gwt( oFrm.nw_content ) );

		var rm_first_name	= vw_trim( $gwt( oFrm.rm_first_name ) );
		var rm_last_name	= vw_trim( $gwt( oFrm.rm_last_name ) );
		
		var rm_birthday		= $gwt( oFrm.rm_birthday_y ) + "-" + $gwt( oFrm.rm_birthday_m ) + "-" + $gwt( oFrm.rm_birthday_d );
		$swt( "id_rm_birthday", rm_birthday );

		var rm_nation		= vw_trim( $gwt( oFrm.rm_nation ) );
		var rm_hukou		= vw_trim( $gwt( oFrm.rm_hukou ) );
		var rm_id_number	= vw_trim( $gwt( oFrm.rm_id_number ) );
		var rm_id_type	= vw_trim( $gwt( oFrm.rm_first_name ) );

		var rm_salary		= vw_trim( $gwt( oFrm.rm_salary ) );
		var rm_currency		= vw_trim( $gwt( oFrm.rm_currency ) );
		var rm_work_exp		= vw_trim( $gwt( oFrm.rm_work_exp ) );
		var rm_residency	= vw_trim( $gwt( oFrm.rm_residency ) );

		var rm_tel_home		= $gwt( oFrm.rm_tel_home_nat ) + "-" + $gwt( oFrm.rm_tel_home_city ) + "-" + $gwt( oFrm.rm_tel_home_num );
		$swt( "id_rm_tel_home", rm_tel_home );
		
		var rm_tel_work		= $gwt( oFrm.rm_tel_work_nat ) + "-" + $gwt( oFrm.rm_tel_work_city ) + "-" + $gwt( oFrm.rm_tel_work_num ) + "-" + $gwt( oFrm.rm_tel_work_ext );
		$swt( "id_rm_tel_work", rm_tel_work );
		
		var rm_tel_mob		= $gwt( oFrm.rm_tel_mob_nat ) + "-" + $gwt( oFrm.rm_tel_mob_num );
		$swt( "id_rm_tel_mob", rm_tel_mob );

		var rm_email	= vw_trim( $gwt( oFrm.rm_email ) );
		var rm_address	= vw_trim( $gwt( oFrm.rm_address ) );
		var rm_zip	= vw_trim( $gwt( oFrm.rm_zip ) );
		var rm_homepage_psl	= vw_trim( $gwt( oFrm.rm_homepage_psl ) );
		var rm_edu_info		= vw_trim( $gwt( oFrm.rm_edu_info ) );
		var rm_wep_info		= vw_trim( $gwt( oFrm.rm_wep_info ) );

		if ( '' == rm_first_name )
		{
			$swt( "id_rm_first_name_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_rm_first_name" );
			return;
		}
		if ( '' == rm_last_name )
		{
			$swt( "id_rm_last_name_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_rm_last_name" );
			return;
		}
		if ( '' == rm_id_number )
		{
			$swt( "id_rm_id_number_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_rm_id_number" );
			return;
		}
		if ( '' == rm_work_exp )
		{
			$swt( "id_rm_work_exp_hint", lib_get_followhinthtml( "err", m_oLang['system_please_select'], 300 ) );
			$swf( "id_rm_work_exp" );
			return;
		}
		if ( '' == rm_residency )
		{
			$swt( "id_rm_residency_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_rm_residency" );
			return;
		}
		if ( '' == rm_email || ! vw_is_email( rm_email ) )
		{
			$swt( "id_rm_email_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_rm_email" );
			return;
		}
		if ( '' == rm_edu_info )
		{
			$swt( "id_rm_edu_info_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_edu_list" );
			return;
		}
		if ( '' == rm_wep_info )
		{
			$swt( "id_rm_wep_info_hint", lib_get_followhinthtml( "err", m_oLang['system_please_input'], 300 ) );
			$swf( "id_wep_list" );
			return;
		}
		
		$ew( oBtn, false );

		var ajax = new CVwAjax();
		ajax.HttpPostForm( "id_frm_resume_edit", "/system/ajax_resume.php", callbackProc, null );
	};

	//
	//	删除一条记录
	//
	this.deleteResume = function( oBtn )
	{
		if ( GetSelNum() > 0 )
		{
			if ( confirm( "Are you sure you want to delete the selected items(s)?" ) )
			{
				var oInput = document.getElementsByTagName("input");
				var i = 0;
				var strIdList = "";
				for ( i = 0; i < oInput.length; i++ )
				{
					if ( "id_chk" == oInput[i].id )
					{
						if ( oInput[i].checked )
						{
							strIdList += oInput[i].value + ",";
						}
					}
				}

				lib_http_get_response
				(
					"/system/ajax_resume.php?op=delete&rm_idlist=" + strIdList,
					30*1000, false,
					function( sText, vArglist )
					{
						alert( "Congratulations, the resume was deleted successfully!" );
						window.location.reload();
					}
				);
			}
		}
		else
		{
			alert( "Please select one or more items." );
		}
	};

	this.SetCheckAll = function( obj )
	{
		if ( obj )
		{
			var bChk = obj.checked;
			var oInput = document.getElementsByTagName("input");
			var i = 0;
			for ( i = 0; i < oInput.length; i++ )
			{
				if ( "id_chk" == oInput[i].id )
				{
					if ( bChk != oInput[i].checked )
					{
						oInput[i].click();
					}
				}
			}
		}
	};

	function GetSelNum()
	{
		var oInput = document.getElementsByTagName("input");
		var i = 0;
		var nSeled = 0;
		for ( i = 0; i < oInput.length; i++ )
		{
			if ( "id_chk" == oInput[i].id )
			{
				if ( oInput[i].checked )
				{
					nSeled ++;
				}
			}
		}
		return nSeled;
	}
	
	function updateSelectDataToInput( oSel, sTagInputId )
	{
		var i;
		var sStr	= "";
		for ( i = 0; i < oSel.options.length; i ++ )
		{
			sStr += oSel.options[ i ].value + "\r\n";
		}
		$swt( sTagInputId, sStr );
	}
}