﻿ResumeCommon = {
    EducationNum:0,
    JobExpNum:0,
    JobHonorNum:0,
    SpecSkillNum:0,
    ProjectCaseNum:0,
    GetYear: function(){
        var s;
        var i = new Date().getFullYear();
        for(;i >= 1939;i--){
            s += "<option>" + i + "</option>";
        }
        return s;
    },
    GetMonth: function(){
        var s;
        for(var i = 1;i <= 12;i++){
            s += "<option>" + i + "</option>";
        }
        return s;
    },
    InsertRow: function(tbl,tr){
        $('#'+tbl).append(tr);
    },
    DeleteRow: function(tr){
        $('#'+tr).remove();
    },
    Education: function(){
        var tid = 'EducationTr'+ResumeCommon.EducationNum;
        var tr = "<tr id='" + tid + "'><td>"
               + "<table width='100%' border='0' cellpadding='0' cellspacing='5'>" 
               + "<tr><td width='70px'>"
               + "教育时间：</td><td><select id='EducationStartYear" + ResumeCommon.EducationNum + "'>"
               + ResumeCommon.GetYear()
               + "</select>年<select id='EducationStartMonth" + ResumeCommon.EducationNum + "'>"
               + ResumeCommon.GetMonth()
               + "</select>月&nbsp;&nbsp;到&nbsp;&nbsp;"
               + "<select id='EducationEndYear" + ResumeCommon.EducationNum + "'>"
               + ResumeCommon.GetYear()
               + "</select>年<select id='EducationEndMonth" + ResumeCommon.EducationNum + "'>"
               + ResumeCommon.GetMonth()
               + "</select>月"
               + "<span style='margin-left:300px;'>"
               + "<a href='javascript:void(0)' onclick=\"ResumeCommon.DeleteRow('" + tid + "');\">删除教育</a></span></td>"
               + "</tr><tr><td>教育学校：</td><td>"
               + "<input id='EducationSchool" + ResumeCommon.EducationNum + "' type='text' class='inputbox' style='width:70%' /></td></tr>"
               + "<tr><td>最终学历：</td><td><select id='Education" + ResumeCommon.EducationNum + "'><option>博士</option><option>硕士</option><option>本科</option><option>大专</option><option>中专</option><option>高中</option><option>其他</option></select></td></tr>"
               + "<tr><td>所学专业：</td><td><input id='EducationType" + ResumeCommon.EducationNum + "' type='text' class='inputbox' style='width:70%' /></td></tr>"
               + "<tr><td><div style='position:relative;margin-top:-50px;'>专业描述：</div></td><td><textarea id='EducationDesc" + ResumeCommon.EducationNum + "' class='inputbox' style='width:70%;height:100px;'></textarea></td></tr>"
               + "</table></td></tr>";
        ResumeCommon.InsertRow("Education",tr);
        ResumeCommon.EducationNum++;
    },
    JobExp: function(){
        var tid = 'JobExpTr' + ResumeCommon.JobExpNum;
        var tr = "<tr id='" + tid + "'><td>"
               + "<table width='100%' border='0' cellpadding='0' cellspacing='5'>" 
               + "<tr><td width='70px'>"
               + "工作时间：</td><td><select id='JobExpStartYear" + ResumeCommon.JobExpNum + "'>"
               + ResumeCommon.GetYear()
               + "</select>年<select id='JobExpStartMonth" + ResumeCommon.JobExpNum + "'>"
               + ResumeCommon.GetMonth()
               + "</select>月&nbsp;&nbsp;到&nbsp;&nbsp;"
               + "<select id='JobExpEndYear" + ResumeCommon.JobExpNum + "'>"
               + ResumeCommon.GetYear()
               + "</select>年<select id='JobExpEndMonth" + ResumeCommon.JobExpNum + "'>"
               + ResumeCommon.GetMonth()
               + "</select>月"
               + "<span style='margin-left:300px;'>"
               + "<a href='javascript:void(0)' onclick=\"ResumeCommon.DeleteRow('" + tid + "');\">删除工作</a></span></td>"
               + "</tr><tr><td>公司名称：</td><td>"
               + "<input id='JobExpGongs" + ResumeCommon.JobExpNum + "' type='text' class='inputbox' style='width:70%' /></td></tr>"
               + "<tr><td>公司规模：</td><td><select id='JobExpGuim" + ResumeCommon.JobExpNum + "'><option>少于50人</option><option>50-100人</option><option>150-500人</option><option>500人以上</option></select>&nbsp;&nbsp;&nbsp;公司性质："
               + "<select id='JobExpXingz" + ResumeCommon.JobExpNum + "'>"
               + "<option>外资企业</option><option>合资企业</option><option>民营企业</option><option>国营企业</option><option>外企代表处</option><option>其他性质</option></select></td></tr>"
               + "<tr><td>所属行业：</td><td><input id='JobExpHangy" + ResumeCommon.JobExpNum + "' type='text' class='inputbox' style='width:70%' /></td></tr>"
               + "<tr><td><div style='position:relative;margin-top:-50px;'>工作描述：</div></td><td><textarea id='JobExpDesc" + ResumeCommon.JobExpNum + "' class='inputbox' style='width:70%;height:100px;'></textarea></td></tr>"
               + "</table></td></tr>";
        ResumeCommon.InsertRow("JobExp",tr);
        ResumeCommon.JobExpNum++;
    },
    JobHonor: function(){
        var tid = 'JobHonor' + ResumeCommon.JobHonorNum;
        var tr = "<tr id='" + tid + "'><td>"
               + "<table width='100%' border='0' cellpadding='0' cellspacing='5'>" 
               + "<tr><td width='70px'>"
               + "获得时间：</td><td><select id='JobHonorYear" + ResumeCommon.JobHonorNum
               + "'>" + ResumeCommon.GetYear() + "</select>年<select id='JobHonorMonth" + ResumeCommon.JobHonorNum + "'>"
               + ResumeCommon.GetMonth() + "</select>月<span style='margin-left:440px;'>"
               + "<a href='javascript:void(0)' onclick=\"ResumeCommon.DeleteRow('" + tid + "');\">删除荣誉</a></span></td></tr><tr><td>"
               + "荣誉名称：</td><td><input id='JobHonorName" + ResumeCommon.JobHonorNum + "' type='text' class='inputbox' style='width:70%' />"
               + "</td></tr>"
               + "<tr><td>"
               + "<div style='position:relative;margin-top:-50px;'>荣誉描述：</div></td><td><textarea id='JobHonorDesc" + ResumeCommon.JobHonorNum + "' class='inputbox' style='width:70%;height:100px;'></textarea>"
               + "</td></tr>"
               + "</table></td></tr>";
        ResumeCommon.InsertRow("JobHonor",tr);
        ResumeCommon.JobHonorNum++;
    },
    SpecSkill: function(){
        var tid = 'SpecSkillTr'+ResumeCommon.SpecSkillNum;
        var tr = "<tr id='" + tid + "'>"
               + "<td style='width:70px;'>" + "技能名称：</td><td><input id='SpecSkillName" + ResumeCommon.SpecSkillNum + "' type='text' class='inputbox' />"
               + "&nbsp;&nbsp;&nbsp;使用时间：<input id='SpecSkillDate" + ResumeCommon.SpecSkillNum + "' type='text' class='inputbox' style='width:50px' />个月"
               + "&nbsp;&nbsp;&nbsp;掌握程度：<select id='SpecSkillChengd" + ResumeCommon.SpecSkillNum + "'>" 
               + "<option>无</option><option>精通</option><option>熟练</option><option>一般</option><option>了解</option></select>"
               + "<span style='margin-left:160px;'><a href='javascript:void(0)' onclick=\"ResumeCommon.DeleteRow('" + tid + "');\">删除技能</a></span></td>"
               + "</tr>";
        ResumeCommon.InsertRow("SpecSkill",tr);
        ResumeCommon.SpecSkillNum++;
    },
    ProjectCase: function(){
        var tid = 'ProjectCaseTr'+ResumeCommon.ProjectCaseNum;
        var tr = "<tr id='" + tid + "'><td>"
               + "<table width='100%' border='0' cellpadding='0' cellspacing='5'>" 
               + "<tr><td width='70px'>"
               + "项目名称：</td><td><input id='ProjectCaseName" + ResumeCommon.ProjectCaseNum + "' type='text' class='inputbox' style='width:70%' /><span style='margin-left:95px;'>"
               + "<a href='javascript:void(0)' onclick=\"ResumeCommon.DeleteRow('" + tid + "');\">删除项目</a></span>"
               + "</td></tr>"
               + "<tr><td>"
               + "<div style='position:relative;margin-top:-50px;'>项目描述：</div></td><td><textarea id='ProjectCaseDesc" + ResumeCommon.ProjectCaseNum + "' class='inputbox' style='width:70%;height:100px;'></textarea>"
               + "</td></tr>"
               + "</table></td></tr>";
        ResumeCommon.InsertRow("ProjectCase",tr);
        ResumeCommon.ProjectCaseNum++;
    },
    Submit: function(){
        if($('#txtName').val() == ''){
            alert('真实姓名不能为空');
            $('#txtName').focus();
            return false;
        }
        if($('#txtVoucherNumber').val() == ''){
            alert('证件号码不能为空');
            $('#txtVoucherNumber').focus();
            return false;
        }
        if($('#txtNativePlace').val() == ''){
            alert('籍贯不能为空');
            $('#txtNativePlace').focus();
            return false;
        }
        if($('#txtDomicile').val() == ''){
            alert('现居住地不能为空');
            $('#txtDomicile').focus();
            return false;
        }
        if($('#txtHomeTelCode').val() == ''){
            alert('电话区号不能为空');
            $('#txtHomeTelCode').focus();
            return false;
        }
        if($('#txtHomeTel').val() == ''){
            alert('电话号码不能为空');
            $('#txtHomeTel').focus();
            return false;
        }
        if($('#txtModelNum').val() == ''){
            alert('手机号码不能为空');
            $('#txtModelNum').focus();
            return false;
        }
        if($('#txtQQ').val() == ''){
            alert('QQ号码不能为空');
            $('#txtQQ').focus();
            return false;
        }
        if($('#txtEmail').val() == ''){
            alert('邮箱地址不能为空');
            $('#txtEmail').focus();
            return false;
        }
        if($('#txtAdsumDate').val() == ''){
            alert('到岗时间不能为空');
            $('#txtAdsumDate').focus();
            return false;
        }
        var i = 0;
        var Education = "[";
        for(i = 0;i < ResumeCommon.EducationNum;i++){
            if(document.getElementById('EducationTr'+i) == null) continue;
            Education += "{";
            Education += "\"BeginTime\":'" + $('#EducationStartYear'+i+' option:selected').text() + "-" 
            + $('#EducationStartMonth'+i+' option:selected').text() + "',";// + "月到 " 
            Education += "\"EndTime\":'" + $('#EducationEndYear'+i+' option:selected').text() + "-"
            + $('#EducationEndMonth'+i+' option:selected').text() + "',";
            //+ $('#EducationEndYear'+i+' option:selected').text() + "年" 
            //+ $('#EducationEndMonth'+i+' option:selected').text() + "月',";
            if($('#EducationSchool'+i)){
                var EducationSchool = $('#EducationSchool'+i).val();
                if(EducationSchool == "" || EducationSchool == undefined){
                    alert('学校名称不能为空');
                    $('#EducationSchool'+i).focus();
                    return false;
                }
                Education += "\"School\":'" + EducationSchool + "',";
            }
            Education += "\"EndEdu\":'" + $('#Education'+i+' option:selected').text() + "',";
            if($('#EducationType'+i)){
                var EducationType = $('#EducationType'+i).val();
                if(EducationType == "" || EducationType == undefined){
                    alert('所学专业不能为空');
                    $('#EducationType'+i).focus();
                    return false;
                }
                Education += "\"Professional\":'" + EducationType + "',";
            }
            if($('#EducationDesc'+i)){
                var EducationDesc = $('#EducationDesc'+i).val();
                if(EducationDesc == "" || EducationDesc == undefined){
                    alert('专业描述不能为空');
                    $('#EducationDesc'+i).focus();
                    return false;
                }
                Education += "\"Desc\":'" + EducationDesc + "',";
            }
            if(Education.substr(Education.length-1,1) == ','){
                Education = Education.substring(0,Education.length-1);
            }
            Education += "},";
        }
        if(Education.substr(Education.length-1,1) == ','){
            Education = Education.substring(0,Education.length-1);
        }
        Education += ']';
        $('#hidEducation').val(Education);
        var JobExp = "[";
        for(i = 0;i < ResumeCommon.JobExpNum;i++){
            if(document.getElementById('JobExpStartYear'+i) == null) continue;
            JobExp += "{";
            JobExp += "\"BeginTime\":'" + $('#JobExpStartYear'+i+' option:selected').text() + "-" 
            + $('#JobExpStartMonth'+i+' option:selected').text() + "',";
            JobExp += "\"EndTime\":'" + $('#JobExpEndYear'+i+' option:selected').text() + "-" 
            + $('#JobExpEndMonth'+i+' option:selected').text() + "',";
            
            //+ $('#JobExpEndYear'+i+' option:selected').text() + "年" 
            //+ $('#JobExpEndMonth'+i+' option:selected').text() + "月',";
            if($('#JobExpGongs'+i)){
                var JobExpGongs = $('#JobExpGongs'+i).val();
                if(JobExpGongs == "" || JobExpGongs == undefined){
                    alert('公司不能为空');
                    $('#JobExpGongs'+i).focus();
                    return false;
                }
                JobExp += "\"Company\":'" + JobExpGongs + "',";
            }
            JobExp += "\"Guim\":'" + $('#JobExpGuim'+i+' option:selected').text() + "',";
            JobExp += "\"Xingz\":'" + $('#JobExpXingz'+i+' option:selected').text() + "',";
            if($('#JobExpHangy'+i)){
                var JobExpHangy = $('#JobExpHangy'+i).val();
                if(JobExpHangy == "" || JobExpHangy == undefined){
                    alert('公司所属行业不能为空');
                    $('#JobExpHangy'+i).focus();
                    return false;
                }
                JobExp += "\"Hangy\":'" + JobExpHangy + "',";
            }
            if($('#JobExpDesc'+i)){
                var JobExpDesc = $('#JobExpDesc'+i).val();
                if(JobExpDesc == "" || JobExpDesc == undefined){
                    alert('工作描述不能为空');
                    $('#JobExpDesc'+i).focus();
                    return false;
                }
                JobExp += "\"Desc\":'" + JobExpDesc + "',";
            }
            if(JobExp.substr(JobExp.length-1,1) == ','){
                JobExp = JobExp.substring(0,JobExp.length-1);
            }
            JobExp += "},";
        }
        if(JobExp.substr(JobExp.length-1,1) == ','){
            JobExp = JobExp.substring(0,JobExp.length-1);
        }
        JobExp += "]";
        $('#hidJobExp').val(JobExp);
        var JobHonor = '[';
        for(i = 0;i < ResumeCommon.JobHonorNum;i++){
            if(document.getElementById('JobHonorYear'+i) == null) continue;
            JobHonor += "{";
            JobHonor += "\"GetTime\":'" + $('#JobHonorYear'+i+' option:selected').text() + "-" 
            + $('#JobHonorMonth'+i+' option:selected').text() + "',";
            if($('#JobHonorName'+i)){
                var JobHonorName = $('#JobHonorName'+i).val();
                if(JobHonorName == "" || JobHonorName == "undefined"){
                    alert('荣誉名称不能为空');
                    $('#JobHonorName'+i).focus();
                    return false;
                }
                JobHonor += "\"Name\":'" + JobHonorName + "',";
            }
            if($('#JobHonorDesc'+i)){
                var JobHonorDesc = $('#JobHonorDesc'+i).val();
                if(JobHonorDesc == "" || JobHonorDesc == undefined){
                    alert('荣誉描述不能为空');
                    $('#JobHonorDesc'+i).focus();
                    return false;
                }
                JobHonor += "\"Desc\":'" + JobHonorDesc + "',";
            }
            if(JobHonor.substr(JobHonor.length-1,1) == ','){
                JobHonor = JobHonor.substring(0,JobHonor.length-1);
            }
            JobHonor += "},";
        }
        if(JobHonor.substr(JobHonor.length-1,1) == ','){
            JobHonor = JobHonor.substring(0,JobHonor.length-1);
        }
        JobHonor += ']';
        $('#hidJobHonor').val(JobHonor);
        var SpecSkill = '[';
        for(i = 0;i < ResumeCommon.SpecSkillNum;i++){
            if(document.getElementById('SpecSkillName'+i) == null) continue;
            SpecSkill += '{';
            if($('#SpecSkillName'+i)){
                var SpecSkillName = $('#SpecSkillName'+i).val();
                if(SpecSkillName == "" || SpecSkillName == undefined){
                    alert('技能名称不能为空');
                    $('#SpecSkillName'+i).focus();
                    return false;
                }
                SpecSkill += "\"SkillName\":'" + SpecSkillName + "',";
            }
            if($('#SpecSkillDate'+i)){
                var SpecSkillDate = $('#SpecSkillDate'+i).val();
                if(SpecSkillDate == "" || SpecSkillDate == undefined){
                    alert('技能使用时间不能为空');
                    $('#SpecSkillDate'+i).focus();
                    return false;
                }
                SpecSkill += "\"UseTime\":'" + SpecSkillDate + "',";
            }
            SpecSkill += "\"Chengd\":'" + $('#SpecSkillChengd'+i+' option:selected').text() + "',";
            if(SpecSkill.substr(SpecSkill.length-1,1) == ','){
                SpecSkill = SpecSkill.substring(0,SpecSkill.length-1);
            }
            SpecSkill += "},";
        }
        if(SpecSkill.substr(SpecSkill.length-1,1) == ','){
            SpecSkill = SpecSkill.substring(0,SpecSkill.length-1);
        }
        SpecSkill += ']';
        $('#hidSpecSkill').val(SpecSkill);
        var ProjectCase = '[';
        for(i = 0;i < ResumeCommon.ProjectCaseNum;i++){
            if(document.getElementById('ProjectCaseName'+i) == null) continue;
            ProjectCase += '{';
            if($('#ProjectCaseName'+i)){
                var ProjectCaseName = $('#ProjectCaseName'+i).val();
                if(ProjectCaseName == "" || ProjectCaseName == undefined){
                    alert('项目名称不能为空');
                    $('#ProjectCaseName'+i).focus();
                    return false;
                }
                ProjectCase += "\"Name\":'" + ProjectCaseName + "',";
            }
            if($('#ProjectCaseDesc'+i)){
                var ProjectCaseDesc = $('#ProjectCaseDesc'+i).val();
                if(ProjectCaseDesc == "" || ProjectCaseDesc == undefined){
                    alert('项目描述不能为空');
                    $('#ProjectCaseDesc'+i).focus();
                    return false;
                }
                ProjectCase += "\"Desc\":'" + ProjectCaseDesc + "',";
            }
            if(ProjectCase.substr(ProjectCase.length-1,1) == ','){
                ProjectCase = ProjectCase.substring(0,ProjectCase.length-1);
            }
            ProjectCase += "},";
        }
        if(ProjectCase.substr(ProjectCase.length-1,1) == ','){
            ProjectCase = ProjectCase.substring(0,ProjectCase.length-1);
        }
        ProjectCase += ']';
        $('#hidProjectCase').val(ProjectCase);
    }
};
