/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var jobGeneralTabCount = 1, jobEducationTabCount = 0, jobResponseTabCount = 0,
jobSkillTabCount = 0, jobLocationTabCount = 0, jobTravelTabCount = 0,
jobSalaryTabCount = 0, jobTagTabCount = 0, jobSaveAll = false, jobSaveMsg = false,
ppTabCount = 1, eduHisTabCount = 0, empHisTabCount = 0, skillInvTabCount = 0,
ptTabCount = 0, peTabCount = 0, awardTabCount = 0, refereeTabCount = 0,
avaTabCount = 0, salaryTabCount = 0, rTagTabCount = 0, assessTabCount = 0,
resumeSaveAll = false, refNoExist = false, retrieveJob = false,
retrieveJobID = "", goToURL = false, goToLink = "", ignoreJobValidation = false;

var saveJobSpec = false, saveJobEduReq = false, saveJobRoleNRespon = false,
saveJobSkillReq = false, saveJobLocation = false, saveJobTravel = false,
saveJobSalaryReq = false, saveJobTag = false, saveProExp = false;

var skillReqList = new Array(), skillInvList = new Array(),
proExpList = new Array(), jobLocationList = new Array(),
jobTravelList = new Array(), eduHisList = new Array(),
empHisList = new Array(), proTrainingList = new Array(),
awardList = new Array(), refereeList = new Array();

var postit = true, configure = 0, updateJobStatus = false,
jobSkillReqCount = 0, jobRankingCount = 0, ignoreSkillReqCheck = false;

//##############################################################################
//index table
function getIndexJobList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var formatURL = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='JavaScript:;' title='Click on the " + sData + " to see the details on the right' onclick='RetrieveJobDetail(" + '"' + oRecord.getData("JobID") + '"' + ");'>" + sData + "</a> (Ref:"+oRecord.getData("refNo")+ ")";
            };
            var company = function(elCell, oRecord, oColumn, sData) {
                if(oRecord.getData("recruitmentCompany")>0){
                    elCell.innerHTML =  "* " + sData;
                }
                else{
                    elCell.innerHTML =  sData;
                }
            };
            var myColumnDefs = [
//                {
//                    key:"refNo",
//                    label:"Ref No",
//                    sortable:true,
//                    width: 50
//                },
                {
                    key:"Title",
                    sortable:true,
                    formatter:formatURL,
                    width: 185
                },
                {
                    key:"Company",
                    sortable:true,
                    formatter:company,
                    width: 185
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmljoblist.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "job",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "Title", "Company", "JobID", "refNo", "recruitmentCompany"]
            };


            var Myconf = {
//                sortedBy: {
//                    key:'refNo',
//                    dir:YAHOO.widget.DataTable.CLASS_ASC
//                },
                height: "20em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("xpath", myColumnDefs, myDataSource, Myconf);

            var applyJob = new YAHOO.widget.Button("applyJob");
            applyJob.on("click", function(){});

            var refreshJobListBtn = new YAHOO.widget.Button("refreshJobList");
            refreshJobListBtn.on("click", function() {
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//recruiter table
function getRecruiterJobList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var formatURL = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='JavaScript:;' title='Click on the " + sData + " to see the details on the right."+
                    "\nNo of Views: "+oRecord.getData("view")+"' "+
                    "onclick='RetrieveJobDetail(" + '"' + oRecord.getData("JobID") + '"' + ");'>" + sData + "</a> ";
            };
            var status = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = JobStatus(sData);
            };

            var myColumnDefs = [
                {
                    key:"refNo",
                    label:"Ref No",
                    sortable:true,
                    width: 50
                },
                {
                    key:"Title",
                    sortable:true,
                    formatter:formatURL,
                    width: 120
                },
                {
                    key:"Status",
                    sortable:true,
                    formatter:status,
                    width: 45
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlrecruiterjoblist.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "job",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "Title", "Status", "JobID", "view", "refNo"]
            };

            var myConf = {
                sortedBy: {
                    key:'refNo',
                    dir:YAHOO.widget.DataTable.CLASS_ASC
                },
                height: "23em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("xxpath", myColumnDefs, myDataSource, myConf);

            //refresh job list btn
            var refreshBtn = new YAHOO.widget.Button("refreshJobList");
            refreshBtn.on("click", function() {
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDTY: myDataTable
            };
        }();
    });
}

//##############################################################################
//Applicant table
function getApplicantList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var formatURL = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='JavaScript:;' onclick='RetrieveApplicantResume(" +'"'+oRecord.getData("JobSeekerID") + '",' + '"'+oRecord.getData("ApplicationID")+'"'+");'>" + sData + "</a> ";
            };
            var status = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = JobAppStatus(sData);
            };
            var myColumnDefs = [
                {
                    key:"No",
                    sortable:true,
                    width: 30
                },
                {
                    key:"Name",
                    sortable:true,
                    width: 100,
                    formatter: formatURL
                },
                {
                    key:"Status",
                    sortable:true,
                    width: 70,
                    formatter: status
                },
                {
                    key:"availability",
                    label:"Availability",
                    sortable:true,
                    width: 90
                },
                {
                    key:"cldSalary",
                    label:"Last Drawn Salary",
                    sortable:true,
                    width: 150
                }
            ];
            
            var myDataSource = new YAHOO.util.DataSource("xmlapplicantlist.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "job",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "Name", "JobSeekerID", "ApplicationID", "Status", "availability", "cldSalary"]
            };

            var Myconf = {
                sortedBy: {
                    key:'No',
                    dir:YAHOO.widget.DataTable.CLASS_ASC
                },
                height: "13em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("ApplicantList", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshApplicantList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            //update application short list button
            var applicantShortListBtn = new YAHOO.widget.Button("applicantShortListBtn");
            applicantShortListBtn.on("click", function(){
                if(YAHOO.util.Dom.get("resumeID").value != ""){
                    UpdateApplicantStatus(YAHOO.util.Dom.get("applicationID").value,YAHOO.util.Dom.get("shortListStatus").value);
                }
            });
            //update aplication reject button
            var applicantRejectBtn = new YAHOO.widget.Button("applicantRejectBtn");
            applicantRejectBtn.on("click", function(){
                if(YAHOO.util.Dom.get("resumeID").value != ""){
                    UpdateApplicantStatus(YAHOO.util.Dom.get("applicationID").value,YAHOO.util.Dom.get("rejectStatus").value);
                }
            });
            var searchApplicantGoBtn = new YAHOO.widget.Button("searchApplicantGo");
            searchApplicantGoBtn.on("click", function(){
                SearchApplicant();
            });
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}
function getApplicantRankList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var formatURL = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='JavaScript:;' onclick='RetrieveApplicantResume(" +'"'+oRecord.getData("JobSeekerID") + '",' + '"'+oRecord.getData("ApplicationID")+'"'+");'>" + sData + "</a> ";
            };
            var status = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = JobAppStatus(sData);
            };
            var myColumnDefs = [
                {
                    key:"No",
                    label:"Rank",
                    sortable:true,
                    width: 30
                },
                {
                    key:"Name",
                    sortable:true,
                    width: 100,
                    formatter: formatURL
                },
                {
                    key:"Status",
                    sortable:true,
                    width: 70,
                    formatter: status
                },
                {
                    key:"availability",
                    label:"Availability",
                    sortable:true,
                    width: 90
                },
                {
                    key:"cldSalary",
                    label:"Last Drawn Salary",
                    sortable:true,
                    width: 150
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlapplicantlist.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "job",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "Name", "JobSeekerID", "ApplicationID", "Status", "availability", "cldSalary"]
            };

            var Myconf = {
                sortedBy: {
                    key:'No',
                    dir:YAHOO.widget.DataTable.CLASS_ASC
                },
                height: "13em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("ApplicantRankList", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshApplicantRankList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applied job table
function getAppliedJobList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var formatURL = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = "<a href='JavaScript:;' title='Click on the " + sData + " to see the details on the right' onclick='RetrieveJobDetail(" + '"' + oRecord.getData("JobID") + '"' + ");'>" + sData +"</a> (Ref:"+oRecord.getData("refNo")+ ")";
            };
            var company = function(elCell, oRecord, oColumn, sData) {
                if(oRecord.getData("recruitmentCompany")>0){
                    elCell.innerHTML =  "* " + sData;
                }else{
                    elCell.innerHTML =  sData;
                }
            };
            var status = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = JobAppStatus(sData);
            };
            var myColumnDefs = [
//                {
//                    key:"refNo",
//                    label:"Ref No",
//                    width:50,
//                    sortable:true
//                },
                {
                    key:"title",
                    label: "Title",
                    width:125,
                    formatter:formatURL,
                    sortable:true
                },
                {
                    key:"company",
                    label: "Company",
                    width:145,
                    sortable:true,
                    formatter:company,
                    resizeable : true
                },
                {
                    key:"status",
                    label: "Status",
                    formatter:status,
                    width:60,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlappliedjoblist.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "job",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "title", "company", "status", "JobID", "refNo", "recruitmentCompany"]
            };


            var Myconf = {
//                sortedBy: {
//                    key:'refNo',
//                    dir:YAHOO.widget.DataTable.CLASS_ASC
//                },
                height: "20em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appliedJobList", myColumnDefs, myDataSource, Myconf);

            //refresh job list btn
            var refreshBtn = new YAHOO.widget.Button("refreshAppliedJobList");
            refreshBtn.on("click", function() {
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//application list table
function getApplicationList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var status = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = JobAppStatus(sData);
            };
            var myColumnDefs = [
                {
                    key:"refNo",
                    label:"Ref No",
                    sortable:true
                },
                {
                    key:"title",
                    label: "Title",
                    sortable:true
                },
                {
                    key:"status",
                    label: "Status",
                    formatter:status,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlappliedjoblistforcompany.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "job",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "title", "status", "refNo"]
            };


            var Myconf = {
                sortedBy: {
                    key:'refNo',
                    dir:YAHOO.widget.DataTable.CLASS_ASC
                },
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appliedJobList", myColumnDefs, myDataSource, Myconf);

            //refresh job list btn
            var refreshBtn = new YAHOO.widget.Button("refreshAppliedJobList");
            refreshBtn.on("click", function() {
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//job location table
function getLocationList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var checkEmpty = function(elCell, oRecord, oColumn, sData) {
                if(sData == ""){
                    elCell.innerHTML = "N/A";
                }else{
                    elCell.innerHTML =  sData;
                }
            };
            var myColumnDefs = [
                {
                    key:"city",
                    label: "City",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"state",
                    label: "State",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"country",
                    label: "Country",
                    width:150,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievejoblocation.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "location",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "city", "state", "country"]
            };


            var Myconf = {
                height: "12em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("JobLocationList", myColumnDefs, myDataSource, Myconf);

            var JobLocation = new YAHOO.widget.Button("refreshLocationList");
            JobLocation.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });
            
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//job travel table
function getTravelList()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var checkEmpty = function(elCell, oRecord, oColumn, sData) {
                if(sData == ""){
                    elCell.innerHTML = "N/A";
                }
                else{
                    elCell.innerHTML =  sData;
                }
            };
            var myColumnDefs = [
                {
                    key:"city",
                    label: "City",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"state",
                    label: "State",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"country",
                    label: "Country",
                    width:150,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievejobtravel.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "travel",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "city", "state", "country"]
            };


            var Myconf = {
                height: "12em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("JobTravelList", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshTravelList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//hide/show advance search
function switchAdvancedSearch(id){
    if(document.getElementById(id).style.display =="none"){
        document.getElementById(id).style.display = "block";
    }
    else{
        document.getElementById(id).style.display = "none";
    }
}

//##############################################################################
//##############################################################################
//Resume
//##############################################################################
//set resume buttons
function setResumeButtons(){
    ResetResumeCount();
    RetrievePersonal();

    //##############################################################################
    //save personal particular
    var SavePersonalParticularBtn = new YAHOO.widget.Button("SavePersonalParticular");
    SavePersonalParticularBtn.on("click", function(){
        if(validatePersonalParitcular()){
            UpdatePersonalParticular();
        }
    });

    //save as job button
    var resumeSaveAllBtn = new YAHOO.widget.Button("resumeSaveAll");
    resumeSaveAllBtn.on("click", function() {
        SaveAllResume();
    });

    //##############################################################################
    //education history
    var SaveEducationHistoryBtn = new YAHOO.widget.Button("SaveEducationHistory");
    SaveEducationHistoryBtn.on("click", function() {
        if(validateEduHistory("ehSchName","ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr")){
            UpdateEduHistoryList();
            SaveEducationHistory();
        }
    });

    var updateEducationHistoryBtn = new YAHOO.widget.Button("updateEducationHistory");
    updateEducationHistoryBtn.on("click", function() {
        document.getElementById("educationHistoryTable").style.display = "none";
        document.getElementById("educationHistoryForm").style.display = "block";
    });

    //    var EducationHistoryPrevBtn = new YAHOO.widget.Button("EducationHistoryPrev");
    //    EducationHistoryPrevBtn.on("click", function() {
    //        if(YAHOO.util.Dom.get("educationHistoryCounter").value > 8){
    //            if(validateEduHistory("ehSchName","ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr")){
    //                SaveEducationHistory();
    //                YAHOO.util.Dom.get("educationHistoryCounter").value = parseInt(YAHOO.util.Dom.get("educationHistoryCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("educationHistoryCounter").value) - 7;
    //                addEduHistRow(counter, "ehEducationNo", "ehSchName", "ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr");
    //                RetrieveEducationHistory();
    //            }
    //        }
    //    });
    //
    //    var EducationHistoryNextBtn = new YAHOO.widget.Button("EducationHistoryNext");
    //    EducationHistoryNextBtn.on("click", function() {
    //        if(validateRows("ehSchName", "") && validateRows("ehSchCity", "") &&
    //            validateRows("ehSchCountry", "") && validateRows("ehEduLvl", "") &&
    //            validateRows("ehGradYr", "")){
    //            if(validateEduHistory("ehSchName","ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr")){
    //                SaveEducationHistory();
    //                var counter = parseInt(YAHOO.util.Dom.get("educationHistoryCounter").value);
    //                YAHOO.util.Dom.get("educationHistoryCounter").value = counter + 7;
    //                addEduHistRow(counter, "ehEducationNo", "ehSchName", "ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr");
    //                RetrieveEducationHistory();
    //            }
    //        }
    //    });

    //##############################################################################
    //employment history
    var SaveEmploymentHistoryBtn = new YAHOO.widget.Button("SaveEmploymentHistory");
    SaveEmploymentHistoryBtn.on("click", function() {
        if(validateEmpHistory("empCompanyName","empJobTitle","empStartDateMth",
        "empStartDateYr", "empStartDate", "empEndDateMth", "empEndDateYr",
        "empEndDate", "empDesc")){
            UpdateEmpHistoryList();
            SaveEmploymentHistory();
        }
    });

    var updateEmploymentHistoryBtn = new YAHOO.widget.Button("updateEmploymentHistory");
    updateEmploymentHistoryBtn.on("click", function() {
        document.getElementById("employmentHistoryTable").style.display = "none";
        document.getElementById("employmentHistoryForm").style.display = "block";
    });

    //    var EmploymentHistoryPrevBtn = new YAHOO.widget.Button("EmploymentHistoryPrev");
    //    EmploymentHistoryPrevBtn.on("click", function() {
    //        if(YAHOO.util.Dom.get("employmentHistoryCounter").value > 8){
    //            if(validateEmpHistory("empCompanyName","empJobTitle","empStartDateMth",
    //                "empStartDateYr", "empStartDate", "empEndDateMth", "empEndDateYr",
    //                "empEndDate", "empTab")){
    //                SaveEmploymentHistory();
    //                YAHOO.util.Dom.get("employmentHistoryCounter").value = parseInt(YAHOO.util.Dom.get("employmentHistoryCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("employmentHistoryCounter").value) - 7;
    //                addEmpHistRow(counter, "empNo", "empCompanyName", "empJobTitle",
    //                    "empStartDateMth", "empStartDateYr", "empEndDateMth", "empEndDateYr");
    //                RetrieveEducationHistory();
    //            }
    //        }
    //    });
    //
    //    var EmploymentHistoryNextBtn = new YAHOO.widget.Button("EmploymentHistoryNext");
    //    EmploymentHistoryNextBtn.on("click", function() {
    //        if(validateRows("empCompanyName", "") && validateRows("empJobTitle", "") &&
    //            validateRows("empStartDateMth", "") && validateRows("empStartDateYr", "") &&
    //            validateRows("empEndDateMth", "") && validateRows("empEndDateYr", "")){
    //            if(validateEmpHistory("empCompanyName","empJobTitle","empStartDateMth",
    //                "empStartDateYr", "empStartDate", "empEndDateMth", "empEndDateYr",
    //                "empEndDate", "empTab")){
    //                SaveEmploymentHistory();
    //                var counter = parseInt(YAHOO.util.Dom.get("employmentHistoryCounter").value);
    //                YAHOO.util.Dom.get("employmentHistoryCounter").value = counter + 7;
    //                addEmpHistRow(counter, "empNo", "empCompanyName", "empJobTitle",
    //                    "empStartDateMth", "empStartDateYr", "empEndDateMth", "empEndDateYr");
    //                RetrieveEducationHistory();
    //            }
    //        }
    //    });

    //##############################################################################
    //skill inventory
    var SaveSkillInvBtn = new YAHOO.widget.Button("SaveSkillInv");
    SaveSkillInvBtn.on("click", function() {
        if(validateSkillInventory("skillInvName", "skillInvRating", "skillInvForm")){
            UpdateSkillInvList();
            if(validateSkillInvDuplicate()){
                SaveSkillInv();
            }
        }
    });
        
    var updateSkillInvBtn = new YAHOO.widget.Button("updateSkillInv");
    updateSkillInvBtn.on("click", function() {
        document.getElementById("skillInvTable").style.display = "none";
        document.getElementById("skillInvForm").style.display = "block";
    });
        
    var SkillInventoryPrevBtn = new YAHOO.widget.Button("SkillInventoryPrev");
    SkillInventoryPrevBtn.on("click", function() {
        if(YAHOO.util.Dom.get("skillInvCounter").value > 8){
            if(validateSkillInventory("skillInvName", "skillInvRating", "skillInvForm")){
                UpdateSkillInvList();
                YAHOO.util.Dom.get("skillInvCounter").value = parseInt(YAHOO.util.Dom.get("skillInvCounter").value) - 7;
                var counter = parseInt(YAHOO.util.Dom.get("skillInvCounter").value) - 7;
                DisplaySkillInv(counter);
            }
        }
    });
        
    var SkillInventoryNextBtn = new YAHOO.widget.Button("SkillInventoryNext");
    SkillInventoryNextBtn.on("click", function() {
        if(validateRadioRows("skillInvName", "skillInvRating", "skillInvForm", null)){
            if(validateSkillInventory("skillInvName", "skillInvRating", "skillInvForm")){
                UpdateSkillInvList();
                var counter = parseInt(YAHOO.util.Dom.get("skillInvCounter").value);
                YAHOO.util.Dom.get("skillInvCounter").value = counter + 7;
                DisplaySkillInv(counter);
            }
        }
    });

    //##############################################################################
    //professional Training
    var SaveProfessionalBtn = new YAHOO.widget.Button("SaveProfessional");
    SaveProfessionalBtn.on("click", function() {
        if(validateProTraining("profTraining", "profProvider", "profYr")){
            UpdateProTrainingList();
            SaveProfessionalTraining();
        }
    });

    var updateProTrainingBtn = new YAHOO.widget.Button("updateProTraining");
    updateProTrainingBtn.on("click", function() {
        document.getElementById("professionalTrainingTable").style.display = "none";
        document.getElementById("professionalTrainingForm").style.display = "block";
    });

    //    var ProTrainingPrevBtn = new YAHOO.widget.Button("ProTrainingPrev");
    //    ProTrainingPrevBtn.on("click", function() {
    //        if(YAHOO.util.Dom.get("proTrainingCounter").value > 8){
    //            if(validateProTraining("profTraining", "profProvider", "profYr")){
    //                SaveProfessionalTraining();
    //                YAHOO.util.Dom.get("proTrainingCounter").value = parseInt(YAHOO.util.Dom.get("proTrainingCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("proTrainingCounter").value) - 7;
    //                addProTrainRow(counter, "profTrainingNo", "profTraining", "profProvider", "profYr")
    //                RetrieveProfessionalTraining();
    //            }
    //        }
    //    });
    //
    //    var ProTrainingNext = new YAHOO.widget.Button("ProTrainingNext");
    //    ProTrainingNext.on("click", function() {
    //        if(validateRows("profTraining", "") && validateRows("profProvider", "") && validateRows("profYr", "yyyy") ){
    //            if(validateProTraining("profTraining", "profProvider", "profYr")){
    //                SaveProfessionalTraining();
    //                var counter = parseInt(YAHOO.util.Dom.get("proTrainingCounter").value);
    //                YAHOO.util.Dom.get("proTrainingCounter").value = counter + 7;
    //                addProTrainRow(counter, "profTrainingNo", "profTraining", "profProvider", "profYr")
    //                RetrieveProfessionalTraining();
    //            }
    //        }
    //    });

    //##############################################################################
    //project experience
    var SaveProjectExpBtn = new YAHOO.widget.Button("SaveProjectExp");
    SaveProjectExpBtn.on("click", function() {
        if(validateProExp("projectTitle","projectRole","projectStartDateMth",
        "projectStartDateYr", "projectStartDate", "projectEndDateMth",
        "projectEndDateYr", "projectEndDate", "projectClient", "projectDesc")){
            UpdateProExpList();
            SaveProjectExperience();
        }
    });

    var updateProjectExpBtn = new YAHOO.widget.Button("updateProjectExp");
    updateProjectExpBtn.on("click", function() {
        document.getElementById("projectExperienceTable").style.display = "none";
        document.getElementById("projectExperienceForm").style.display = "block";
    });

    var ProExpPrevBtn = new YAHOO.widget.Button("ProExpPrev");
    ProExpPrevBtn.on("click", function() {
        if(YAHOO.util.Dom.get("proExpCounter").value > 8){
            if(validateProExp("projectTitle","projectRole","projectStartDateMth",
            "projectStartDateYr", "projectStartDate", "projectEndDateMth",
            "projectEndDateYr", "projectEndDate", "projectClient", "projectDesc")){
                UpdateProExpList();
                YAHOO.util.Dom.get("proExpCounter").value = parseInt(YAHOO.util.Dom.get("proExpCounter").value) - 7;
                var counter = parseInt(YAHOO.util.Dom.get("proExpCounter").value) - 7;
                DisplayProExp(counter);
            }
        }
    });

    var ProExpNextBtn = new YAHOO.widget.Button("ProExpNext");
    ProExpNextBtn.on("click", function() {
        if(validateRows("projectTitle", "") && validateRows("projectRole", "") &&
            validateRows("projectStartDateMth", "") && validateRows("projectStartDateYr", "yyyy") &&
            validateRows("projectEndDateMth", "") && validateRows("projectEndDateYr", "yyyy") &&
            validateRows("projectClient", "") && validateRows("projectDesc", "")){
            if(validateProExp("projectTitle","projectRole","projectStartDateMth",
            "projectStartDateYr", "projectStartDate", "projectEndDateMth",
            "projectEndDateYr", "projectEndDate", "projectClient", "projectDesc")){
                UpdateProExpList();
                var counter = parseInt(YAHOO.util.Dom.get("proExpCounter").value);
                YAHOO.util.Dom.get("proExpCounter").value = counter + 7;
                DisplayProExp(counter);
            }
        }
    });

    //##############################################################################
    //award
    var SaveAwardBtn = new YAHOO.widget.Button("SaveAward");
    SaveAwardBtn.on("click", function() {
        if(validateAward("awardTitle", "awardBy", "awardYr")){
            UpdateAwardList();
            SaveAward();
        }
                
    });

    var updateAwardBtn = new YAHOO.widget.Button("updateAward");
    updateAwardBtn.on("click", function() {
        document.getElementById("awardTable").style.display = "none";
        document.getElementById("awardForm").style.display = "block";
    });

    //    var AwardPrevBtn = new YAHOO.widget.Button("AwardPrev");
    //    AwardPrevBtn.on("click", function() {
    //        if(YAHOO.util.Dom.get("awardCounter").value > 8){
    //            if(validateAward("awardTitle", "awardBy", "awardYr")){
    //                SaveAward();
    //                YAHOO.util.Dom.get("awardCounter").value = parseInt(YAHOO.util.Dom.get("awardCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("awardCounter").value) - 7;
    //                addAwardRow(counter, "awardNo", "awardTitle", "awardBy", "awardYr");
    //                RetrieveAward();
    //            }
    //
    //        }
    //    });
    //
    //    var AwardNextBtn = new YAHOO.widget.Button("AwardNext");
    //    AwardNextBtn.on("click", function() {
    //        if(validateRows("awardTitle", "") && validateRows("awardBy", "") && validateRows("awardYr", "yyyy")){
    //            if(validateAward("awardTitle", "awardBy", "awardYr")){
    //                SaveAward();
    //                var counter = parseInt(YAHOO.util.Dom.get("awardCounter").value);
    //                YAHOO.util.Dom.get("awardCounter").value = counter + 7;
    //                addAwardRow(counter, "awardNo", "awardTitle", "awardBy", "awardYr");
    //                RetrieveAward();
    //            }
    //        }
    //    });

    //##############################################################################
    //referee
    var SaveRefereeBtn = new YAHOO.widget.Button("SaveReferee");
    SaveRefereeBtn.on("click", function() {
        if(validateReferee("refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown")){
            UpdateRefereeList();
            SaveReferee();
        }
    });

    var updateRefereeBtn = new YAHOO.widget.Button("updateReferee");
    updateRefereeBtn.on("click", function() {
        document.getElementById("refereeInformationTable").style.display = "none";
        document.getElementById("refereeInformationForm").style.display = "block";
    });

    //    var RefereePrevBtn = new YAHOO.widget.Button("RefereePrev");
    //    RefereePrevBtn.on("click", function() {
    //        if(YAHOO.util.Dom.get("refereeCounter").value > 8){
    //            if(validateReferee("refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown")){
    //                SaveReferee();
    //                YAHOO.util.Dom.get("refereeCounter").value = parseInt(YAHOO.util.Dom.get("refereeCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("refereeCounter").value) - 7;
    //                addRefereeRow(counter, "refNo", "refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown");
    //                RetrieveReferee();
    //            }
    //        }
    //    });
    //
    //    var RefereeNextBtn = new YAHOO.widget.Button("RefereeNext");
    //    RefereeNextBtn.on("click", function() {
    //        if(validateRows("refName", "") && validateRows("refEmail", "") &&
    //            validateRows("refTel", "") && validateRows("refRelationship", "") &&
    //            validateRows("refPeriodKnown", "yyyy")){
    //            if(validateReferee("refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown")){
    //                SaveReferee();
    //                var counter = parseInt(YAHOO.util.Dom.get("refereeCounter").value);
    //                YAHOO.util.Dom.get("refereeCounter").value = counter + 7;
    //                addRefereeRow(counter, "refNo", "refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown");
    //                RetrieveReferee();
    //            }
    //        }
    //    });
            
    //##############################################################################
    //availability
    var SaveAvailBtn = new YAHOO.widget.Button("SaveAvail");
    SaveAvailBtn.on("click", function() {
        if(validateAvail("availabilityRadio", "availabilityForm", false)){
            SaveAvailability();
        }
    });

    //##############################################################################
    //salary inventory
    var SaveSalaryBtn = new YAHOO.widget.Button("SaveSalary");
    SaveSalaryBtn.on("click", function() {
        if(validateSalaryInv()){
            SaveSalaryInv();
        }
    });

    //##############################################################################
    //    //tag
    //    var SaveResumeTagBtn = new YAHOO.widget.Button("SaveResumeTag");
    //    SaveResumeTagBtn.on("click", function() {
    //        if(validateOneTextField("resumeTagKeyword")){
    //            SaveResumeTag();
    //        }
    //    });
    //
    //    var updateResumeTagBtn = new YAHOO.widget.Button("updateResumeTag");
    //    updateResumeTagBtn.on("click", function() {
    //        document.getElementById("resumeTagTable").style.display = "none";
    //        document.getElementById("resumeTagForm").style.display = "block";
    //    });
    //
    //    var resumeTagPrevBtn = new YAHOO.widget.Button("resumeTagPrev");
    //    resumeTagPrevBtn.on("click", function() {
    //        if(YAHOO.util.Dom.get("resumeTagCounter").value > 8){
    //            if(validateOneTextField("resumeTagKeyword")){
    //                SaveResumeTag();
    //                YAHOO.util.Dom.get("resumeTagCounter").value = parseInt(YAHOO.util.Dom.get("resumeTagCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("resumeTagCounter").value) - 7;
    //                addTagRow(counter, "resumeTagNo", "resumeTagKeyword");
    //                RetrieveResumeTag();
    //            }
    //        }
    //    });
    //
    //    var resumeTagNextBtn = new YAHOO.widget.Button("resumeTagNext");
    //    resumeTagNextBtn.on("click", function() {
    //        if(validateRows("resumeTagKeyword", "")){
    //            if(validateOneTextField("resumeTagKeyword")){
    //                SaveResumeTag();
    //                var counter = parseInt(YAHOO.util.Dom.get("resumeTagCounter").value);
    //                YAHOO.util.Dom.get("resumeTagCounter").value = counter + 7;
    //                addTagRow(counter, "resumeTagNo", "resumeTagKeyword");
    //                RetrieveResumeTag();
    //            }
    //        }
    //    });

}

//##############################################################################
//##############################################################################
//Retrieve Personal Particular
function RetrievePersonal()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievepersonal.php";
    url =url+"?jobSeekerID="+document.getElementById("jobSeekerID").value;
    try{
        xmlhttp.onreadystatechange=RetrievePersonalStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrievePersonalStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc=xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("resumeID", "");
                SetValue("personalParticularID", "");
                SetValue("ppPassportNo", "");
                SetValue("ppFullName", "");
                SetValue("ppBirthDate", "");
                SetValue("ppBirthDateDay", "dd");
                SetValue("ppBirthDateMth", "");
                SetValue("ppAddress", "");
                SetValue("ppUnitNo", "");
                SetValue("ppCity", "");
                SetValue("ppState", "");
                SetValue("ppCountry", "");
                SetValue("ppPostalCode", "");
                SetValue("ppContactNo", "");
                SetValue("ppEmail", "");
            
                SetXMLNode(xmlDoc, "resumeID", 0, 0, "resumeID");
                SetXMLNode(xmlDoc, "personalParticularID", 0, 0, "personalParticularID");
                SetXMLNode(xmlDoc, "passportNo", 0, 0, "ppPassportNo");
                SetXMLNode(xmlDoc, "fullName", 0, 0, "ppFullName");
                SetXMLNode(xmlDoc, "address", 0, 0, "ppAddress");
                SetXMLNode(xmlDoc, "unitNo", 0, 0, "ppUnitNo");
                SetXMLNode(xmlDoc, "city", 0, 0, "ppCity");
                SetXMLNode(xmlDoc, "state", 0, 0, "ppState");
                SetXMLNode(xmlDoc, "postalCode", 0, 0, "ppPostalCode");
                SetXMLNode(xmlDoc, "country", 0, 0, "ppCountry");
                SetXMLNode(xmlDoc, "contactNo", 0, 0, "ppContactNo");
                SetXMLNode(xmlDoc, "email", 0, 0, "ppEmail");
                if(xmlDoc.getElementsByTagName("birthDate")[0] != null){
                    if(xmlDoc.getElementsByTagName("birthDate")[0].childNodes[0] != null){
                        decodeBirthDate(xmlDoc.getElementsByTagName("birthDate")[0].childNodes[0].nodeValue, "ppBirthDateDay", "ppBirthDateMth");
                    }
                }
                var count = 0;
                if(xmlDoc.getElementsByTagName("noOfCitizenship")[0] != null){
                    if(xmlDoc.getElementsByTagName("noOfCitizenship")[0].childNodes[0] != null){
                        count = xmlDoc.getElementsByTagName("noOfCitizenship")[0].childNodes[0].nodeValue;
                    }
                }
                var index = 0;
                while(count>index){
                    if(xmlDoc.getElementsByTagName("cType")[index] != null){
                        if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0] != null){
                            if(xmlDoc.getElementsByTagName("cCountry")[index] != null){
                                if(xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0] != null){
                                    if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0].nodeValue == 1){
                                        for(var i=1; i<=3; i++){
                                            if(xmlDoc.getElementsByTagName("cNo")[index].childNodes[0].nodeValue == i){
                                                var citiID ="ppCitizenship"+i;
                                                document.getElementById(citiID).value =
                                                    xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0].nodeValue;
                                            }
                                        }
                                    }
                                    else if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0].nodeValue == 2){
                                        for(i=1; i<=3; i++){
                                            if(xmlDoc.getElementsByTagName("cNo")[index].childNodes[0].nodeValue == i){
                                                var prID ="ppPR"+i;
                                                document.getElementById(prID).value =
                                                    xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0].nodeValue;
                                            }
                                        }
                                    }
                                    else if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0].nodeValue == 3){
                                        for(i=1; i<=3; i++){
                                            if(xmlDoc.getElementsByTagName("cNo")[index].childNodes[0].nodeValue == i){
                                                var wpID ="ppWorkPermit"+i;
                                                document.getElementById(wpID).value =
                                                    xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0].nodeValue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    index++;
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//update personal particular
function UpdatePersonalParticular()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxUpdatePersonal.php";
    url =url+"?personalParticularID="+document.getElementById("personalParticularID").value;
    url =url+"&fullName="+document.getElementById("ppFullName").value;
    url =url+"&passportNo="+document.getElementById("ppPassportNo").value;
    url =url+"&address="+document.getElementById("ppAddress").value;
    url =url+"&unitNo="+document.getElementById("ppUnitNo").value;
    url =url+"&state="+document.getElementById("ppState").value;
    url =url+"&city="+document.getElementById("ppCity").value;
    url =url+"&postalCode="+document.getElementById("ppPostalCode").value;
    url =url+"&birthDate="+document.getElementById("ppBirthDate").value;
    url =url+"&country="+document.getElementById("ppCountry").value;
    url =url+"&contactNo="+document.getElementById("ppContactNo").value;
    url =url+"&email="+document.getElementById("ppEmail").value;
    url =url+"&citizenship1="+document.getElementById("ppCitizenship1").value;
    url =url+"&citizenship2="+document.getElementById("ppCitizenship2").value;
    url =url+"&citizenship3="+document.getElementById("ppCitizenship3").value;
    url =url+"&pr1="+document.getElementById("ppPR1").value;
    url =url+"&pr2="+document.getElementById("ppPR2").value;
    url =url+"&pr3="+document.getElementById("ppPR3").value;
    url =url+"&workPermit1="+document.getElementById("ppWorkPermit1").value;
    url =url+"&workPermit2="+document.getElementById("ppWorkPermit2").value;
    url =url+"&workPermit3="+document.getElementById("ppWorkPermit3").value;
    try{
        xmlhttp.onreadystatechange=UpdatePersonalParticularStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function UpdatePersonalParticularStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1")
                    alert("Resume Saved!");
                else
                    alert("Save Resume Failed. Please try again.");
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//validate personal particular
function validatePersonalParitcular(){
    document.getElementById("ppTab").click();
    var validation = false;
    if(validate("ppFullName", "", "Please enter your Full Name.")){
        //if(validate("ppPassportNo", "", "Please enter ID or Passport Number.")){
        if(document.getElementById('ppBirthDateDay').value!="dd" || document.getElementById('ppBirthDateMth').value!=""){
            if(validate("ppBirthDateDay", "dd", "Please enter Birthday in (dd) format.") && validate("ppBirthDateDay", "", "Please enter Birthday in (dd) format.")){
                if(validateNumber('ppBirthDateDay', 'Please enter Birthday in numeric only.')){
                    if(validate("ppBirthDateMth", "", "Please select the month of your Birthday.")){
                        if(validateBirthDate("ppBirthDateDay", "ppBirthDateMth", "ppBirthDate")){
                            validation = true;
                        }
                    }
                }
            }
        }
        else{
            validation = true;
        }
        if(validation){
            validation = false;
            //            if(validate("ppAddress", "", "Please enter your contact address.")){
            if(validate("ppCountry", "", "Please select a country.")){
                if(document.getElementById('ppContactNo')!=""){
                    if(validate("ppContactNo", "", "Please enter your contact number including country and area code.")){
                        if(validateNumber('ppContactNo', 'Please enter your contact number including country and area code. Only numbers accepted.')){
                            validation = true;
                        }
                    }
                }else{
                    validation = true;
                }
            }
            //            }
        }
        if(validation){
            if(validateEmail("ppEmail")){
                return true;
            }
        }
        //}
    }
    return false;
}
//end

//##############################################################################
//##############################################################################
//Save education history
function SaveEducationHistory()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveEduHistory.php"; 
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&educationHistoryCount="+eduHisList.length;
    for(var i=0;i<eduHisList.length;i++)
    {
        var eduHis = eduHisList[i];
        url = url+"&ehSchName"+(i+1)+"="+eduHis.school;
        url = url+"&ehSchCity"+(i+1)+"="+eduHis.city;
        url = url+"&ehSchCountry"+(i+1)+"="+eduHis.country;
        url = url+"&ehEduLvl"+(i+1)+"="+eduHis.level;
        url = url+"&ehGradYr"+(i+1)+"="+eduHis.year;
    }
    url =url+"&SaveEducationHistory="+document.getElementById("SaveEducationHistory").value;
    try{
        xmlhttp.onreadystatechange=SaveEducationHistoryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveEducationHistoryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("educationHistoryTable").style.display = "block";
                    document.getElementById("educationHistoryForm").style.display = "none";
                }
                else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshEducationHistoryList").click();
            
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve education history
function RetrieveEducationHistory()
{
    showResumeTab("education");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveeducation.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&educationHistoryCounter="+document.getElementById("educationHistoryCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveEducationHistoryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveEducationHistoryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                eduHisList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "educationCount", 0, 0);
                while(index<count){
                    var school = GetXMLNode(xmlDoc, "schoolName", index, 0);
                    var city = GetXMLNode(xmlDoc, "schoolCity", index, 0);
                    var country = GetXMLNode(xmlDoc, "schoolCountry", index, 0);
                    var year = GetXMLNode(xmlDoc, "gradYear", index, 0);
                    var level = GetXMLNode(xmlDoc, "eduLvl", index, 0);
                    var eduHis = new EducationHistory(school, city, country, level, year);
                    eduHisList[index] = eduHis;
                    index++;
                }
                YAHOO.util.Dom.get("educationHistoryCounter").value=8;
                addEduHistRow(1, "ehEducationNo", "ehSchName", "ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr");
                for(var i = 0; i < 7; i++) {
                    eduHis =  eduHisList[i];
                    if(eduHis){
                        var ehSchName = "ehSchName" + parseInt(i+1);
                        var ehSchCity = "ehSchCity" + parseInt(i+1);
                        var ehSchCountry = "ehSchCountry" + parseInt(i+1);
                        var ehGradYr = "ehGradYr" + parseInt(i+1);
                        var ehEduLvl = "ehEduLvl" + parseInt(i+1);
                        document.getElementById(ehSchName).value = eduHis.school;
                        document.getElementById(ehSchCity).value = eduHis.city;
                        document.getElementById(ehSchCountry).value = eduHis.country;
                        document.getElementById(ehGradYr).value = eduHis.year;
                        document.getElementById(ehEduLvl).value = eduHis.level;
                    }
                }
            }
            document.getElementById("refreshEducationHistoryList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function reh(){
    if(eduHisTabCount == 0){
        RetrieveEducationHistory();
    }
}

function reht(){
    if(eduHisTabCount == 0){
        eduHisTabCount = 1;
        document.getElementById("refreshEducationHistoryList").click();
    }
}

//add education history
function addEduHistRow(nextNo, no, name, city, country, eduLvl, gradYr){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var nameID = name + i + "";
        var cityID = city + i + "";
        var countryID = country + i + "";
        var eduLvlID = eduLvl + i + "";
        var gradYrID = gradYr + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(nameID).value = "";
        document.getElementById(cityID).value = "";
        document.getElementById(countryID).value = "";
        document.getElementById(eduLvlID).value = "";
        document.getElementById(gradYrID).value = "yyyy";
        nextNo++;
    }
}

//validate education history
function validateEduHistory(schNameID, cityID, countryID, eduLvlID, gradYrID){
    document.getElementById("eduTab").click();
    var result = false;
    for(var i=1;i<=7;i++){
        var schName = schNameID+i;
        var city = cityID+i;
        var country = countryID+i;
        var eduLvl = eduLvlID+i;
        var gradYr = gradYrID+i;
        if(document.getElementById(schName).value!="" || document.getElementById(city).value!="" ||
            document.getElementById(country).value!="" || document.getElementById(eduLvl).value!="" ||
            document.getElementById(gradYr).value!="yyyy"){
            if(validate(schName, "", "Please enter the school campus name.")){
                if(validate(city, "", "Please enter the city of the school campus.")){
                    if(validate(country, "", "Please select the country of the school campus.")){
                        if(validate(eduLvl, "", "Please enter the level (Grade 12, BScEE, etc) attained from this school.")){
                            if(validate(gradYr, "yyyy", "Please enter the year (yyyy) of graduation.")){
                                if(isYear(gradYr)){
                                    var d = new Date();
                                    if(document.getElementById(gradYr).value <= d.getYear()){
                                        result = true;
                                    }
                                    else{
                                        document.getElementById(gradYr).focus();
                                        alert("Invalid Year!");
                                        result = false;
                                        break;
                                    }
                                }
                                else{
                                    result = false;
                                    break;
                                }
                            }
                            else{
                                result = false;
                                break;
                            }
                        }
                        else{
                            result = false;
                            break;
                        }
                    }
                    else{
                        result = false;
                        break;
                    }
                }
                else{
                    result = false;
                    break;
                }
            }else{
                result = false;
                break;
            }
        }
        else{
            result = true;
        }
    }
    if(result){
        result = false;
        if(validateFourTextField(schNameID, cityID, countryID, eduLvlID)){
            result = true;
        }

    }
    return result;
}

//update Education History list
function UpdateEduHistoryList(){
    var count = parseInt(document.getElementById('educationHistoryCounter').value - 8);
    for(var no = 0; no<7; no++){
        var ehSchNameID = "ehSchName"+(no+1);
        var ehSchCityID = "ehSchCity"+(no+1);
        var ehSchCountryID = "ehSchCountry"+(no+1);
        var ehEduLvlID = "ehEduLvl"+(no+1);
        var ehGradYrID = "ehGradYr"+(no+1);

        var eduHis = eduHisList[count];
        if(eduHis){
            eduHis.school = document.getElementById(ehSchNameID).value;
            eduHis.city = document.getElementById(ehSchCityID).value;
            eduHis.country = document.getElementById(ehSchCountryID).value;
            eduHis.level = document.getElementById(ehEduLvlID).value;
            eduHis.year = document.getElementById(ehGradYrID).value;
            eduHisList[count] = eduHis;
            count++;
        }else{
            if(document.getElementById(ehSchNameID).value!="" && document.getElementById(ehSchCityID).value!="" &&
                document.getElementById(ehSchCountryID).value!="" &&  document.getElementById(ehEduLvlID).value!="" &&
                document.getElementById(ehGradYrID).value!="yyyy"){
                var school = document.getElementById(ehSchNameID).value;
                var city = document.getElementById(ehSchCityID).value;
                var country = document.getElementById(ehSchCountryID).value;
                var level = document.getElementById(ehEduLvlID).value;
                var year = document.getElementById(ehGradYrID).value;
                var eduHisTemp = new EducationHistory(school, city, country, level, year); 
                eduHisList[count] = eduHisTemp;
                count++;
            }
        }
    }
}

//delete Education History row by index
function DeleteEduHistoryRow(noID){
    UpdateEduHistoryList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    eduHisList.splice(no, 1);
    alert("Education record deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("educationHistoryCounter").value - 7);
    DisplayEduHistory(counter);
}

//display Education History from list
function DisplayEduHistory(counter){
    addEduHistRow(counter, "ehEducationNo", "ehSchName", "ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr");
    for (var i = 0; i < 7; i++) {
        var eduHis =  eduHisList[counter-1];
        if(eduHis){
            var ehSchNameID = "ehSchName"+(i+1);
            var ehSchCityID = "ehSchCity"+(i+1);
            var ehSchCountryID = "ehSchCountry"+(i+1);
            var ehEduLvlID = "ehEduLvl"+(i+1);
            var ehGradYrID = "ehGradYr"+(i+1);

            document.getElementById(ehSchNameID).value = eduHis.school;
            document.getElementById(ehSchCityID).value = eduHis.city;
            document.getElementById(ehSchCountryID).value = eduHis.country;
            document.getElementById(ehEduLvlID).value = eduHis.level;
            document.getElementById(ehGradYrID).value = eduHis.year;
            counter++;
        }
        else{
            break;
        }
    }
}

//##############################################################################
//##############################################################################
//Save employment history
function SaveEmploymentHistory()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveEmpHistory.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&employmentHistoryCount="+empHisList.length;
    for(var i=0;i<empHisList.length;i++)
    {
        var empHis = empHisList[i];
        url = url+"&empCompanyName"+(i+1)+"="+empHis.company;
        url = url+"&empJobTitle"+(i+1)+"="+empHis.title;
        url = url+"&empStartDate"+(i+1)+"="+empHis.startDate;
        url = url+"&empEndDate"+(i+1)+"="+empHis.endDate;
        url = url+"&empDesc"+(i+1)+"="+empHis.description;
    }
    url =url+"&SaveEmploymentHistory="+document.getElementById("SaveEmploymentHistory").value;
    try{
        xmlhttp.onreadystatechange=SaveEmploymentHistoryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveEmploymentHistoryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("employmentHistoryTable").style.display = "block";
                    document.getElementById("employmentHistoryForm").style.display = "none";
                }
                else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshEmploymentHistoryList").click();
            
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve education history
function RetrieveEmploymentHistory()
{
    showResumeTab("employment");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveemployment.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&employmentHistoryCounter="+document.getElementById("employmentHistoryCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveEmploymentHistoryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveEmploymentHistoryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                empHisList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "employmentCount", 0, 0);
                while(index<count){
                    var company = GetXMLNode(xmlDoc, "companyName", index, 0);
                    var title = GetXMLNode(xmlDoc, "jobTitle", index, 0);
                    var startDate = GetXMLNode(xmlDoc, "startDate", index, 0);
                    var endDate = GetXMLNode(xmlDoc, "endDate", index, 0);
                    var description = GetXMLNode(xmlDoc, "description", index, 0);
                    var empHis = new EmploymentHistory(company, title, startDate, endDate, description);
                    empHisList[index] = empHis;
                    index++;
                }
                YAHOO.util.Dom.get("employmentHistoryCounter").value=8;
                addEmpHistRow(1, "empNo", "empCompanyName", "empJobTitle", "empStartDateMth",
                "empStartDateYr", "empEndDateMth", "empEndDateYr", "empDesc");
                for(var i = 0; i < 7; i++) {
                    empHis =  empHisList[i];
                    if(empHis){
                        var empCompanyName = "empCompanyName" + (i+1);
                        var empJobTitle = "empJobTitle" + (i+1);
                        var empStartDate = "empStartDate" + (i+1);
                        var empEndDate = "empEndDate" + (i+1);
                        var empDesc = "empDesc" + (i+1);
                        document.getElementById(empCompanyName).value = empHis.company;
                        document.getElementById(empJobTitle).value = empHis.title;
                        document.getElementById(empStartDate).value = empHis.startDate;
                        document.getElementById(empEndDate).value = empHis.endDate;
                        document.getElementById(empDesc).value = empHis.description;

                        var startDateMth = "empStartDateMth"+(i+1);
                        var startDateYr = "empStartDateYr"+(i+1);
                        var endDateMth = "empEndDateMth"+(i+1);
                        var endDateYr = "empEndDateYr"+(i+1);

                        decodeMthYr(empHis.startDate, startDateMth, startDateYr);
                        decodeMthYr(empHis.endDate, endDateMth, endDateYr);
                    }
                }
            
            }
    
            document.getElementById("refreshEmploymentHistoryList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function remp(){
    if(empHisTabCount == 0){
        RetrieveEmploymentHistory();
    }
}

function rempt(){
    if(empHisTabCount == 0){
        empHisTabCount = 1;
        document.getElementById("refreshEmploymentHistoryList").click();
    }
}

function directToEmpDetail(empFormID, no){
    if(validateEmpHistory("empCompanyName","empJobTitle","empStartDateMth",
    "empStartDateYr", "empStartDate", "empEndDateMth", "empEndDateYr",
    "empEndDate", "empTab")){

        var nameID = "empCompanyName"+no;
        var titleID = "empJobTitle"+no;
        var startDateID = "empStartDate"+no;
        var endDateID = "empEndDate"+no;

        if(document.getElementById(nameID).value !="" && document.getElementById(titleID).value !="" &&
            document.getElementById(startDateID).value !="" && document.getElementById(endDateID).value !=""){

            var name = "empDescCompanyName"+no;
            var title = "empDescJobTitle"+no;
            var startDate = "empDescStartDate"+no;
            var endDate = "empDescEndDate"+no;

            document.getElementById(name).value = document.getElementById(nameID).value;
            document.getElementById(title).value = document.getElementById(titleID).value;
            document.getElementById(startDate).value = document.getElementById(startDateID).value;
            document.getElementById(endDate).value = document.getElementById(endDateID).value;

            document.getElementById(empFormID).submit();
        }
    }
}

//add employment history
function addEmpHistRow(nextNo, no, company, title, startMth, startYr, endMth, endYr, desc){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var companyID = company + i + "";
        var titleID = title + i + "";
        var startMthID = startMth + i + "";
        var startYrID = startYr + i + "";
        var endMthID = endMth + i + "";
        var endYrID = endYr + i + "";
        var descID = desc + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(companyID).value = "";
        document.getElementById(titleID).value = "";
        document.getElementById(startMthID).value = "";
        document.getElementById(startYrID).value = "yyyy";
        document.getElementById(endMthID).value = "";
        document.getElementById(endYrID).value = "yyyy";
        document.getElementById(descID).value = "";
        nextNo++;
    }
}

//validate employment history
function validateEmpHistory(company, title, startMth, startYr, startDate, endMth, endYr, endDate, desc){
    var result=false;
    document.getElementById("empTab").click();
    //if(validateOneTextField(company)){
    for(var i=1;i<=7;i++){
        var companyID = company+i;
        var titleID = title+i;
        var startMthID = startMth+i;
        var startYrID = startYr+i;
        var startDateID = startDate+i;
        var endMthID = endMth+i;
        var endYrID = endYr+i;
        var endDateID = endDate+i;
        var descID = desc+i;
        if(document.getElementById(companyID).value!="" || document.getElementById(titleID).value!="" ||
            document.getElementById(startMthID).value!="" || document.getElementById(startYrID).value!="yyyy" ||
            document.getElementById(endMthID).value!="" || document.getElementById(endYrID).value!="yyyy" ||
            document.getElementById(descID).value!=""){
            if(validate(companyID, "", "Please enter company name.")){
                if(validate(titleID, "", "Please enter job title.")){
                    if(validateMthYrDates(startMthID, startYrID, startDateID, endMthID, endYrID, endDateID)){
                        if(validate(descID, "", "Please enter employment brief description.")){
                            result=true;
                        }
                        else{
                            result = false;
                            break;
                        }
                    }
                    else{
                        result = false;
                        break;
                    }
                }else{
                    result = false;
                    break;
                }
            }else{
                result = false;
                break;
            }
        }
        else{
            result = true;
        }
    }
    //}
    return result;
}

function validateMthYrDates(startMth, startYr, startDate, endMth, endYr, endDate){
    var d = new Date();
    if(document.getElementById(startMth).value != ""){
        if(document.getElementById(startYr).value != "yyyy"){
            if(document.getElementById(startYr).value <= d.getYear()){
                if(validateMthYr(startMth, startYr, startDate)){
                    if(document.getElementById(endMth).value != ""){
                        if(document.getElementById(endYr).value != "yyyy"){
                            if(document.getElementById(endYr).value <= d.getYear()){
                                if(validateMthYr(endMth, endYr, endDate)){
                                    if(document.getElementById(startYr).value == document.getElementById(endYr).value){
                                        if(convertMth(document.getElementById(startMth).value,"num")<convertMth(document.getElementById(endMth).value,"num")){
                                            return true;
                                        }else{
                                            document.getElementById(endMth).focus();
                                            alert("End month must be later than start month.");
                                            return false;
                                        }
                                    }
                                    else if(document.getElementById(startYr).value < document.getElementById(endYr).value){
                                        return true;
                                    }else{
                                        document.getElementById(endYr).focus();
                                        alert("End year must be later than start year.");
                                        return false;
                                    }
                                }
                                else{
                                    return false;
                                }
                            }
                            else{

                                document.getElementById(startYr).focus();
                                alert("Invalid Year!");
                                return false;
                            }
                        }
                        else{
                            document.getElementById(endYr).focus();
                            alert("Please enter end year.");
                            return false;
                        }
                    }
                    else{
                        document.getElementById(endMth).focus();
                        alert("Please select end month.");
                        return false;
                    }
                }
                else{
                    return false;
                }
            }
            else{
                document.getElementById(startYr).focus();
                alert("Invalid Year!");
                return false;
            }
        }else{
            document.getElementById(startYr).focus();
            alert("Please enter start year.");
            return false;
        }

    }else{
        document.getElementById(startMth).focus();
        alert("Please select start month.");
        return false;
    }
    return true;
}

//Employment History Description
function SetEmpDescButton(){
    window.resizeTo(890,550);

    var SaveEduDescBtn = new YAHOO.widget.Button("SaveEduDesc");
    SaveEduDescBtn.on("click", function(){
        SaveEmpHisDesc();
    });

    var CloseBtn = new YAHOO.widget.Button("CloseBtn");
    CloseBtn.on("click", function(){
        window.close();
    });
}

function SaveEmpHisDesc()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveEmpHistory.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&companyName="+document.getElementById('empCompanyName').value;
    url =url+"&jobTitle="+document.getElementById('empJobTitle').value;
    url =url+"&startDate="+document.getElementById('empStartDate').value;
    url =url+"&endDate="+document.getElementById('empEndDate').value;
    url =url+"&desc="+document.getElementById('desc').value;
    url =url+"&empNo="+document.getElementById('empNo').value;
    try{
        xmlhttp.onreadystatechange=SaveEmpHisDescStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function SaveEmpHisDescStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            alert(xmlhttp.responseText);
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//update Employment History list
function UpdateEmpHistoryList(){
    var count = parseInt(document.getElementById('employmentHistoryCounter').value - 8);
    for(var no = 0; no<7; no++){
        var companyNameID = "empCompanyName"+(no+1);
        var jobTitleID = "empJobTitle"+(no+1);
        var startDateID = "empStartDate"+(no+1);
        var endDateID = "empEndDate"+(no+1);
        var empDescID = "empDesc"+(no+1);
        var empHis = empHisList[count];
        if(empHis){
            empHis.company = document.getElementById(companyNameID).value;
            empHis.title = document.getElementById(jobTitleID).value;
            empHis.startDate = document.getElementById(startDateID).value;
            empHis.endDate = document.getElementById(endDateID).value;
            empHis.description = document.getElementById(empDescID).value;
            empHisList[count] = empHis;
            count++;
        }
        else{
            if(document.getElementById(companyNameID).value!="" && document.getElementById(jobTitleID).value!="" &&
                document.getElementById(startDateID).value!="" &&  document.getElementById(endDateID).value!="" &&
                document.getElementById(empDescID).value!=""){
                var company = document.getElementById(companyNameID).value;
                var title = document.getElementById(jobTitleID).value;
                var startDate = document.getElementById(startDateID).value;
                var endDate = document.getElementById(endDateID).value;
                var empDesc = document.getElementById(empDescID).value;
                var empHisTemp = new EmploymentHistory(company, title, startDate, endDate, empDesc);
                empHisList[count] = empHisTemp;
                count++;
            }
        }
    }
}

//delete employment History row by index
function DeleteEmpHistoryRow(noID){
    UpdateEmpHistoryList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    empHisList.splice(no, 1);
    alert("Employment history record deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("employmentHistoryCounter").value - 7);
    DisplayEmpHistory(counter);
}

//display employment History from list
function DisplayEmpHistory(counter){
    addEmpHistRow(counter, "empNo", "empCompanyName", "empJobTitle",
    "empStartDateMth", "empStartDateYr", "empEndDateMth", "empEndDateYr", "empDesc");
    for (var i = 0; i < 7; i++) {
        var empHis =  empHisList[counter-1];
        if(empHis){
            var empCompanyNameID = "empCompanyName"+(i+1);
            var empJobTitleID = "empJobTitle"+(i+1);
            var empStartDateID = "empStartDate"+(i+1);
            var empEndDateID = "empEndDate"+(i+1);
            var empDescID = "empDesc"+(i+1);

            document.getElementById(empCompanyNameID).value = empHis.company;
            document.getElementById(empJobTitleID).value = empHis.title;
            document.getElementById(empStartDateID).value = empHis.startDate;
            document.getElementById(empEndDateID).value = empHis.endDate;
            document.getElementById(empDescID).value = empHis.description;
            
            var startDateMth = "empStartDateMth"+(i+1);
            var startDateYr = "empStartDateYr"+(i+1);
            var endDateMth = "empEndDateMth"+(i+1);
            var endDateYr = "empEndDateYr"+(i+1);

            decodeMthYr(empHis.startDate, startDateMth, startDateYr);
            decodeMthYr(empHis.endDate, endDateMth, endDateYr);
            counter++;
        }
        else{
            break;
        }
    }
}

//##############################################################################
//##############################################################################
//retrieve job skill inventory
function RetrieveSkillInventory()
{
    showResumeTab("skill");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveskillinventory.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&skillInvCounter="+document.getElementById("skillInvCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveSkillInventoryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveSkillInventoryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                skillInvList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "skillCount", 0, 0);
                while(index<count){
                    var name = GetXMLNode(xmlDoc, "name", index, 0);
                    var level = GetXMLNode(xmlDoc, "level", index, 0);
                    var skillInv = new SkillInventory(name, level);
                    skillInvList[index] = skillInv;
                    index++;
                }
                YAHOO.util.Dom.get("skillInvCounter").value=8;
                addSkillRow(1, "skillInvNo", "skillInvName", "", "skillInvRating", "skillInvForm");
                for(var i = 0; i < 7; i++) {
                    skillInv =  skillInvList[i];
                    if(skillInv){
                        var skillInvName = "skillInvName" + parseInt(i+1);
                        var skillInvRating = "skillInvRating" + parseInt(i+1);
                        document.getElementById(skillInvName).value = skillInv.name;
                        for(ind=0; ind < document['forms']['skillInvForm'][skillInvRating].length; ind++){
                            if(document['forms']['skillInvForm'][skillInvRating][ind].value == skillInv.level)
                                document['forms']['skillInvForm'][skillInvRating][ind].checked = true;
                        }
                    }
                }
            }
            document.getElementById("refreshSkillInventoryList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//Save skill inventory
function SaveSkillInv()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveSkillInv.php";
    url = url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&skillInvCount="+skillInvList.length;
    for(var i=0; i<skillInvList.length; i++)
    {
        var skillInv = skillInvList[i];
        url = url+"&skillInvName"+(i+1)+"="+skillInv.name;
        url = url+"&skillInvRating"+(i+1)+"="+skillInv.level;

    }
    url = url+"&SaveSkillInv="+document.getElementById("SaveSkillInv").value;
    try{
        xmlhttp.onreadystatechange=SaveSkillInvStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveSkillInvStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("skillInvTable").style.display = "block";
                    document.getElementById("skillInvForm").style.display = "none";
                } else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshSkillInventoryList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rsi(){
    if(skillInvTabCount == 0){
        RetrieveSkillInventory();
    }
}

function rsit(){
    if(skillInvTabCount == 0){
        skillInvTabCount = 1;
        document.getElementById("refreshSkillInventoryList").click();
    }
}

//update skill inventory list
function UpdateSkillInvList(){
    var count = parseInt(document.getElementById('skillInvCounter').value-8);
    for(var no = 0; no<7; no++){
        var skillNameID = "skillInvName"+(no+1);
        var ratingID = "skillInvRating"+(no+1);

        var skillInv = skillInvList[count];
        if(skillInv){
            skillInv.name = document.getElementById(skillNameID).value;
            for(var ind=0; ind < document["forms"]["skillInvForm"][ratingID].length; ind++){
                if(document["forms"]["skillInvForm"][ratingID][ind].checked){
                    skillInv.level = document["forms"]["skillInvForm"][ratingID][ind].value;
                    break;
                }
            }
            skillInvList[count] = skillInv;
            count++;
        }
        else{
            if(document.getElementById(skillNameID).value!=""){
                var name = document.getElementById(skillNameID).value;
                for(ind=0; ind < document["forms"]["skillInvForm"][ratingID].length; ind++){
                    if(document["forms"]["skillInvForm"][ratingID][ind].checked){
                        var level = document["forms"]["skillInvForm"][ratingID][ind].value;
                        break;
                    }
                }
                var skillInvTemp = new SkillInventory(name, level);
                skillInvList[count] = skillInvTemp;
                count++;
            }
        }
    }
}

//delete skill inventory row by index
function DeleteSkillInvRow(noID){
    UpdateSkillInvList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    skillInvList.splice(no, 1);
    alert("Skill record deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("skillInvCounter").value - 7);
    DisplaySkillInv(counter);
}

//display skill inventory from list
function DisplaySkillInv(counter){
    addSkillRow(counter, "skillInvNo", "skillInvName", "", "skillInvRating", "skillInvForm");
    for (var i = 0; i < 7; i++) {
        var skillInv =  skillInvList[counter-1];
        if(skillInv){
            var skillInvName = "skillInvName" + (i+1);
            var skillInvRating = "skillInvRating" + (i+1);
            document.getElementById(skillInvName).value = skillInv.name;
            for(var ind=0; ind < document['forms']['skillInvForm'][skillInvRating].length; ind++){
                if(document['forms']['skillInvForm'][skillInvRating][ind].value == skillInv.level)
                    document['forms']['skillInvForm'][skillInvRating][ind].checked = true;
            }
            counter++;
        }
        else{
            break;
        }
    }
}

function validateSkillInvDuplicate(){
    var result = false;
    if(skillInvList.length>0){
        for(var i=0;i<skillInvList.length;i++){
            var skillInv = skillInvList[i];
            for(var ind=0;ind<skillInvList.length;ind++){
                var nextSkillInv = skillInvList[ind];
                if(i != ind){
                    if(skillInv.name == nextSkillInv.name){
                        alert("Please enter a unique record. Do not create duplicate.");
                        result = false;
                        break;
                    }else{
                        result = true;
                    }
                }else{
                    result = true;
                }
            }
            if(!result){
                break;
            }
        }
    }
    else{
        result = true;
    }
    return result;
}

//validate skill inventory
function validateSkillInventory(skillName, rating, formID){
    document.getElementById("skillTab").click();
    var result = false;
    for(var i=1; i<8; i++){
        var skillNameID = skillName + i;
        var form = formID;
        var radioID = rating + i;
        if(document.getElementById(skillNameID).value != "" || validateRadio(form, radioID)){
            if(validate(skillNameID, "", "Please enter your skill.")){
                if(validateRadio(form, radioID)){
                    result = true;
                }
                else{
                    alert("Please select a rating from 1 to 5.");
                    result = false;
                    break;
                }
            }
            else{
                result = false;
                break;
            }
        }
        else{
            result = true;
        }
    }

    return result;
}

//##############################################################################
//##############################################################################
//Save professional training
function SaveProfessionalTraining()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveProTraining.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&proTrainingCount="+proTrainingList.length;
    for(var i=0;i<proTrainingList.length;i++)
    {
        var proTraining = proTrainingList[i];
        url = url+"&profTraining"+(i+1)+"="+proTraining.training;
        url = url+"&profProvider"+(i+1)+"="+proTraining.provider;
        url = url+"&profYr"+(i+1)+"="+proTraining.year;
    }
    url =url+"&SaveProfessional="+document.getElementById("SaveProfessional").value;
    try{
        xmlhttp.onreadystatechange=SaveProfessionalTrainingStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveProfessionalTrainingStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("professionalTrainingTable").style.display = "block";
                    document.getElementById("professionalTrainingForm").style.display = "none";
                }
                else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshProTrainingList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve professional training
function RetrieveProfessionalTraining()
{
    showResumeTab("training");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveprotraining.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&proTrainingCounter="+document.getElementById("proTrainingCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveProfessionalTrainingStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveProfessionalTrainingStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                proTrainingList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "trainingCount", 0, 0);
                while(index<count){
                    var training = GetXMLNode(xmlDoc, "training", index, 0);
                    var provider = GetXMLNode(xmlDoc, "provider", index, 0);
                    var year = GetXMLNode(xmlDoc, "year", index, 0);
                    var proTraining = new ProfessioanlTraining(training, provider, year);
                    proTrainingList[index] = proTraining;
                    index++;
                }
                YAHOO.util.Dom.get("proTrainingCounter").value=8;
                addProTrainRow(1, "profTrainingNo", "profTraining", "profProvider", "profYr");
                for(var i = 0; i < 7; i++) {
                    proTraining =  proTrainingList[i];
                    if(proTraining){
                        var profTraining = "profTraining" + parseInt(i+1);
                        var profProvider = "profProvider" + parseInt(i+1);
                        var profYr = "profYr" + parseInt(i+1);
                        document.getElementById(profTraining).value = proTraining.training;
                        document.getElementById(profProvider).value = proTraining.provider;
                        document.getElementById(profYr).value = proTraining.year;
                    }
                }
            }
            document.getElementById("refreshProTrainingList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rpt(){
    if(ptTabCount == 0){
        RetrieveProfessionalTraining();
    }
}

function rptt(){
    if(ptTabCount == 0){
        ptTabCount = 1;
        document.getElementById("refreshProTrainingList").click();
    }
}

//add professional training
function addProTrainRow(nextNo, no, training, provider, year){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var trainingID = training + i + "";
        var providerID = provider + i + "";
        var yearID = year + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(trainingID).value = "";
        document.getElementById(providerID).value = "";
        document.getElementById(yearID).value = "yyyy";
        nextNo++;
    }
}

//validate professional training
function validateProTraining(training, provider, year){
    document.getElementById("trainingTab").click();
    var result = false;
    var d = new Date();
    if(validateOneTextField(training)){
        for(var i=1;i<=7;i++){
            var trainingID = training+i;
            var providerID = provider+i;
            var yearID = year+i;
            if(document.getElementById(trainingID).value!="" || document.getElementById(providerID).value!="" ||
                document.getElementById(yearID).value!="yyyy"){
                if(validate(trainingID, "", "Please enter training title.")){
                    if(validate(providerID, "", "Please enter training provider name.")){
                        if(validate(yearID, "yyyy", "Please enter the year (yyyy) of training.")){
                            if(isYear(yearID)){
                                if(document.getElementById(yearID).value <= d.getYear()){
                                    result = true;
                                }
                                else{
                                    document.getElementById(yearID).focus();
                                    alert("Please enter the year (yyyy) of training.");
                                    result = false;
                                    break;
                                }
                            }
                            else{
                                result = false;
                                break;
                            }
                        }
                        else{
                            result = false;
                            break;
                        }
                    }
                    else{
                        result = false;
                        break;
                    }
                }
                else{
                    result = false;
                    break;
                }
            }else{
                result = true;
            }
        }
    }
    return result;
}

//update professional training list
function UpdateProTrainingList(){
    var count = parseInt(document.getElementById('proTrainingCounter').value - 8);
    for(var no = 0; no<7; no++){
        var profTrainingID = "profTraining"+(no+1);
        var profProviderID = "profProvider"+(no+1);
        var profYrID = "profYr"+(no+1);
        var proTraining = proTrainingList[count];
        if(proTraining){
            proTraining.company = document.getElementById(profTrainingID).value;
            proTraining.title = document.getElementById(profProviderID).value;
            proTraining.startDate = document.getElementById(profYrID).value;
            proTrainingList[count] = proTraining;
            count++;
        }
        else{
            if(document.getElementById(profTrainingID).value!="" &&
                document.getElementById(profProviderID).value!="" &&
                document.getElementById(profYrID).value!="yyyy"){
                var training = document.getElementById(profTrainingID).value;
                var provider = document.getElementById(profProviderID).value;
                var year = document.getElementById(profYrID).value;
                var proTrainingTemp = new ProfessioanlTraining(training, provider, year);
                proTrainingList[count] = proTrainingTemp;
                count++;
            }
        }
    }
}

//delete professional training row by index
function DeleteProTrainingRow(noID){
    UpdateProTrainingList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    proTrainingList.splice(no, 1);
    alert("Training Deleted!");
    var counter = parseInt(YAHOO.util.Dom.get("proTrainingCounter").value - 7);
    DisplayProTraining(counter);
}

//display professional training from list
function DisplayProTraining(counter){
    addProTrainRow(counter, "profTrainingNo", "profTraining", "profProvider", "profYr");
    for (var i = 0; i < 7; i++) {
        var proTraining =  proTrainingList[counter-1];
        if(proTraining){
            var profTrainingID = "profTraining"+(i+1);
            var profProviderID = "profProvider"+(i+1);
            var profYrID = "profYr"+(i+1);

            document.getElementById(profTrainingID).value = proTraining.training;
            document.getElementById(profProviderID).value = proTraining.provider;
            document.getElementById(profYrID).value = proTraining.year;
            counter++;
        }
        else{
            break;
        }
    }
}

//##############################################################################
//##############################################################################
//Save project experience
function SaveProjectExperience()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveProExp.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&proExpCount="+proExpList.length;
    for(var i=0; i<proExpList.length; i++)
    {
        var proExp = proExpList[i];
        url = url+"&projectTitle"+(i+1)+"="+proExp.title;
        url = url+"&projectRole"+(i+1)+"="+proExp.role;
        url = url+"&projectStartDate"+(i+1)+"="+proExp.startDate;
        url = url+"&projectEndDate"+(i+1)+"="+proExp.endDate;
        url = url+"&projectClient"+(i+1)+"="+proExp.client;
        url = url+"&projectDescription"+(i+1)+"="+proExp.description;

    }
    url =url+"&SaveProjectExp="+document.getElementById("SaveProjectExp").value;
    try{
        xmlhttp.onreadystatechange=SaveProjectExperienceStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveProjectExperienceStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    saveProExp = false;
                    document.getElementById("projectExperienceTable").style.display = "block";
                    document.getElementById("projectExperienceForm").style.display = "none";
                }
                else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshProjectExpList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve project experience
function RetrieveProjectExperience()
{
    showResumeTab("project");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveproexp.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&proExpCounter="+document.getElementById("proExpCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveProjectExperienceStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveProjectExperienceStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                proExpList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "projectCount", 0, 0);
                while(index<count){
                    var title = GetXMLNode(xmlDoc, "title", index, 0);
                    var role = GetXMLNode(xmlDoc, "role", index, 0);
                    var startDate = GetXMLNode(xmlDoc, "startDate", index, 0);
                    var endDate = GetXMLNode(xmlDoc, "endDate", index, 0);
                    var client = GetXMLNode(xmlDoc, "client", index, 0);
                    var description = GetXMLNode(xmlDoc, "description", index, 0);
                    var proExp = new ProjectExperience(title, role, startDate, endDate, client, description);
                    proExpList[index] = proExp;
                    index++;
                }
                YAHOO.util.Dom.get("proExpCounter").value=8;
                addProExpRow(1, "proNo", "projectTitle", "projectRole", "projectStartDateMth" ,
                "projectStartDateYr", "projectEndDateMth", "projectEndDateYr", "projectClient", "projectDesc");
                for(var i = 0; i < 7; i++) {
                    proExp =  proExpList[i];
                    if(proExp){
                        var projectTitleID = "projectTitle"+(i+1);
                        var projectRoleID = "projectRole"+(i+1);
                        var projectStartDateID = "projectStartDate"+(i+1);
                        var projectEndDateID = "projectEndDate"+(i+1);
                        var projectClientID = "projectClient"+(i+1);
                        var projectDescID = "projectDesc"+(i+1);

                        document.getElementById(projectTitleID).value = proExp.title;
                        document.getElementById(projectRoleID).value = proExp.role;
                        document.getElementById(projectStartDateID).value = proExp.startDate;
                        document.getElementById(projectEndDateID).value = proExp.endDate;
                        document.getElementById(projectClientID).value = proExp.client;
                        document.getElementById(projectDescID).value = proExp.description;

                        var startDateMth = "projectStartDateMth"+(i+1);
                        var startDateYr = "projectStartDateYr"+(i+1);
                        var endDateMth = "projectEndDateMth"+(i+1);
                        var endDateYr = "projectEndDateYr"+(i+1);

                        decodeMthYr(proExp.startDate, startDateMth, startDateYr);
                        decodeMthYr(proExp.endDate, endDateMth, endDateYr);
                    }
                }
            }
            document.getElementById("refreshProjectExpList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rpe(){
    if(peTabCount == 0){
        RetrieveProjectExperience();
    }
}

function rpet(){
    if(peTabCount == 0){
        peTabCount = 1;
        document.getElementById("refreshProjectExpList").click();
    }
}

//update project experience list
function UpdateProExpList(){
    var count = parseInt(document.getElementById('proExpCounter').value-8);
    for(var no = 0; no<7; no++){
        var projectTitleID = "projectTitle"+(no+1);
        var projectRoleID = "projectRole"+(no+1);
        var projectStartDateID = "projectStartDate"+(no+1);
        var projectEndDateID = "projectEndDate"+(no+1);
        var projectClientID = "projectClient"+(no+1);
        var projectDescID = "projectDesc"+(no+1);

        var proExp = proExpList[count];
        if(proExp){
            proExp.title = document.getElementById(projectTitleID).value;
            proExp.role = document.getElementById(projectRoleID).value;
            proExp.startDate = document.getElementById(projectStartDateID).value;
            proExp.endDate = document.getElementById(projectEndDateID).value;
            proExp.client = document.getElementById(projectClientID).value;
            proExp.description = document.getElementById(projectDescID).value;
            proExpList[count] = proExp;
            count++;
        }
        else{
            if(document.getElementById(projectTitleID).value!="" && document.getElementById(projectRoleID).value!="" &&
                document.getElementById(projectStartDateID).value!="" &&  document.getElementById(projectEndDateID).value!="" &&
                document.getElementById(projectClientID).value!="" && document.getElementById(projectDescID).value!=""){
                var title = document.getElementById(projectTitleID).value;
                var role = document.getElementById(projectRoleID).value;
                var startDate = document.getElementById(projectStartDateID).value;
                var endDate = document.getElementById(projectEndDateID).value;
                var client = document.getElementById(projectClientID).value;
                var description = document.getElementById(projectDescID).value;
                var proExpTemp = new ProjectExperience(title, role, startDate, endDate, client, description);
                proExpList[count] = proExpTemp;
                count++;
            }
        }
    }
}

//delete project experience row by index
function DeleteProExpRow(noID){
    UpdateProExpList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    proExpList.splice(no, 1);
    alert("Project record deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("proExpCounter").value - 7);
    DisplayProExp(counter);
}

//display project experience from list
function DisplayProExp(counter){
    addProExpRow(counter, "proNo", "projectTitle", "projectRole", "projectStartDateMth" ,
    "projectStartDateYr", "projectEndDateMth", "projectEndDateYr", "projectClient", "projectDesc");
    for (var i = 0; i < 7; i++) {
        var proExp =  proExpList[counter-1];
        if(proExp){
            var projectTitleID = "projectTitle"+(i+1);
            var projectRoleID = "projectRole"+(i+1);
            var projectStartDateID = "projectStartDate"+(i+1);
            var projectEndDateID = "projectEndDate"+(i+1);
            var projectClientID = "projectClient"+(i+1);
            var projectDescID = "projectDesc"+(i+1);

            document.getElementById(projectTitleID).value = proExp.title;
            document.getElementById(projectRoleID).value = proExp.role;
            document.getElementById(projectStartDateID).value = proExp.startDate;
            document.getElementById(projectEndDateID).value = proExp.endDate;
            document.getElementById(projectClientID).value = proExp.client;
            document.getElementById(projectDescID).value = proExp.description;

            var startDateMth = "projectStartDateMth"+(i+1);
            var startDateYr = "projectStartDateYr"+(i+1);
            var endDateMth = "projectEndDateMth"+(i+1);
            var endDateYr = "projectEndDateYr"+(i+1);

            decodeMthYr(proExp.startDate, startDateMth, startDateYr);
            decodeMthYr(proExp.endDate, endDateMth, endDateYr);

            counter++;
        }
        else{
            break;
        }
    }
}

function validateProExpDuplicate(){
    var result = false;
    if(proExpList.length>0){
        for(var i=0;i<proExpList.length;i++){
            var proExp = proExpList[i];
            for(var ind=0;ind<proExpList.length;ind++){
                var nextProExp = proExpList[ind];
                if(i != ind){
                    if(proExp.title == nextProExp.title){
                        alert("Please enter a unique record. Do not create duplicate.");
                        result = false;
                        break;
                    }
                    else{
                        result = true;
                    }
                }
                else{
                    result = true;
                }
            }
            if(!result){
                break;
            }
        }
    }else{
        result = true;
    }
    return result; 
}

function directToProExpDetail(proExpFormID, no){
    if(!saveProExp){
        UpdateProExpList();
        var counter = parseInt(document.getElementById('proExpCounter').value - 8);
        var index = parseInt(counter + no);
        if(validateProExp("projectTitle","projectRole","projectStartDateMth",
        "projectStartDateYr", "projectStartDate", "projectEndDateMth",
        "projectEndDateYr", "projectEndDate", "projectClient")){

            var proExp = proExpList[index];
            var i = parseInt(no) + 1;
            var proNo = "projectDescNo"+i;
            var title = "projectDescTitle"+i;
            var role = "projectDescRole"+i;
            var startDate = "projectDescStartDate"+i;
            var endDate = "projectDescEndDate"+i;
            var client = "projectDescClient"+i;
            var description = "projectDescDescription"+i;

            alert(proExp.description);
            document.getElementById(proNo).value = index+1;
            document.getElementById(title).value = proExp.title;
            document.getElementById(role).value = proExp.role;
            document.getElementById(startDate).value = proExp.startDate;
            document.getElementById(endDate).value = proExp.endDate;
            document.getElementById(client).value = proExp.client;
            document.getElementById(description).value = proExp.description;

            document.getElementById(proExpFormID).submit();

            document.getElementById("refreshProjectExpList").click();
            document.getElementById("projectExperienceTable").style.display = "block";
            document.getElementById("projectExperienceForm").style.display = "none";
        }
    }
    else{
        alert("Please save the project detail first before you can move on to the description.")
    }
}

//add project experience
function addProExpRow(nextNo, no, title, role, startMth, startYr, endMth, endYr, client, desc){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var titleID = title + i + "";
        var roleID = role + i + "";
        var startMthID = startMth + i + "";
        var startYrID = startYr + i + "";
        var endMthID = endMth + i + "";
        var endYrID = endYr + i + "";
        var clientID = client + i + "";
        var descID = desc + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(titleID).value = "";
        document.getElementById(roleID).value = "";
        document.getElementById(startMthID).value = "";
        document.getElementById(startYrID).value = "yyyy";
        document.getElementById(endMthID).value = "";
        document.getElementById(endYrID).value = "yyyy";
        document.getElementById(clientID).value = "";
        document.getElementById(descID).value = "";
        nextNo++;
    }
}

//validate project experience
function validateProExp(project, role, startMth, startYr, startDate, endMth, endYr, endDate, client, desc){
    document.getElementById("projectTab").click();
    var result = false;
    if(validateOneTextField(project)){
        for(var i=1;i<=7;i++){
            var projectID = project+i;
            var roleID = role+i;
            var startMthID = startMth+i;
            var startYrID = startYr+i;
            var startDateID = startDate+i;
            var endMthID = endMth+i;
            var endYrID = endYr+i;
            var endDateID = endDate+i;
            var clientID = client+i;
            var descID = desc+i;
            if(document.getElementById(projectID).value!="" || document.getElementById(roleID).value!="" ||
                document.getElementById(startMthID).value!="" || document.getElementById(startYrID).value!="yyyy" ||
                document.getElementById(endMthID).value!="" || document.getElementById(endYrID).value!="yyyy" ||
                document.getElementById(clientID).value!="" || document.getElementById(descID).value!=""){
                if(validate(projectID, "", "Please enter project title.")){
                    if(validate(roleID, "", "Please enter your role.")){
                        if(validateMthYrDates(startMthID, startYrID, startDateID, endMthID, endYrID, endDateID)){
                            if(validate(clientID, "", "Please enter client name.")){
                                if(validate(descID, "", "Please enter project brief description.")){
                                    result = true;
                                }
                                else{
                                    result = false;
                                    break;
                                }
                            }
                            else{
                                result = false;
                                break;
                            }
                        }
                        else{
                            result = false;
                            break;
                        }
                    }
                    else{
                        result = false;
                        break;
                    }
                }
                else{
                    result = false;
                    break;
                }
            }
            else{
                result = true;
            }
        }
    }
    return result;
}

//Project Experience Description
function SetProExpDescButton(){
    window.resizeTo(890,550);

    var SaveProExpDescBtn = new YAHOO.widget.Button("SaveProExpDesc");
    SaveProExpDescBtn.on("click", function(){
        SaveProExpDesc();
    });

    var CloseBtn = new YAHOO.widget.Button("CloseBtn");
    CloseBtn.on("click", function(){
        window.close();
    });
}

function SaveProExpDesc()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveProExp.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&projectTitle="+document.getElementById('projectTitle').value;
    url =url+"&projectRole="+document.getElementById('projectRole').value;
    url =url+"&projectStartDate="+document.getElementById('projectStartDate').value;
    url =url+"&projectEndDate="+document.getElementById('projectEndDate').value;
    url =url+"&projectClient="+document.getElementById('projectClient').value;
    url =url+"&desc="+document.getElementById('desc').value;
    url =url+"&proNo="+document.getElementById('proNo').value;
    try{
        xmlhttp.onreadystatechange=SaveProExpDescStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function SaveProExpDescStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            alert(xmlhttp.responseText);
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
//##############################################################################
//Save award
function SaveAward()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveAward.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&awardCount="+awardList.length;
    for(var i=0;i<awardList.length;i++)
    {
        var award = awardList[i];
        url = url+"&awardTitle"+(i+1)+"="+award.title;
        url = url+"&awardBy"+(i+1)+"="+award.awardBy;
        url = url+"&awardYr"+(i+1)+"="+award.year;
    }
    url =url+"&SaveAward="+document.getElementById("SaveAward").value;
    try{
        xmlhttp.onreadystatechange=SaveAwardStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveAwardStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("awardTable").style.display = "block";
                    document.getElementById("awardForm").style.display = "none";
                }
                else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshAwardList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve award
function RetrieveAward()
{
    showResumeTab("award");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveaward.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&awardCounter="+document.getElementById("awardCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveAwardStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveAwardStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                awardList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "awardCount", 0, 0);
                while(index<count){
                    var title = GetXMLNode(xmlDoc, "title", index, 0);
                    var awardBy = GetXMLNode(xmlDoc, "awardBy", index, 0);
                    var year = GetXMLNode(xmlDoc, "year", index, 0);
                    var award = new Award(title, awardBy, year);
                    awardList[index] = award;
                    index++;
                }
                YAHOO.util.Dom.get("awardCounter").value=8;
                addAwardRow(1, "awardNo", "awardTitle", "awardBy", "awardYr");
                for(var i = 0; i < 7; i++) {
                    award =  awardList[i];
                    if(award){
                        var awardTitleID = "awardTitle"+(i+1);
                        var awardByID = "awardBy"+(i+1);
                        var awardYrID = "awardYr"+(i+1);

                        document.getElementById(awardTitleID).value = award.title;
                        document.getElementById(awardByID).value = award.awardBy;
                        document.getElementById(awardYrID).value = award.year;
                    }
                }
            }
            document.getElementById("refreshAwardList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function ra(){
    if(awardTabCount == 0){
        RetrieveAward();
    }
}

function rat(){
    if(awardTabCount == 0){
        awardTabCount = 1;
        document.getElementById("refreshAwardList").click();
    }
}

//add award
function addAwardRow(nextNo, no, title, awardBy, year){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var titleID = title + i + "";
        var awardByID = awardBy + i + "";
        var yearID = year + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(titleID).value = "";
        document.getElementById(awardByID).value = "";
        document.getElementById(yearID).value = "yyyy";
        nextNo++;
    }
}

//validate award
function validateAward(title, awardBy, year){
    document.getElementById("awardTab").click();
    var result = false;
    var d = new Date();
    if(validateTwoTextField(title, year)){
        for(var i=1;i<=7;i++){
            var titleID = title+i;
            var awardByID = awardBy+i;
            var yearID = year+i;
            if(document.getElementById(titleID).value!="" || document.getElementById(awardByID).value!="" ||
                document.getElementById(yearID).value!="yyyy"){
                if(validate(titleID, "", "Please enter training title.")){
                    if(validate(awardByID, "", "Please enter the awarding organization name.")){
                        if(validate(yearID, "yyyy", "Please enter the year (yyyy) of award.")){
                            if(isYear(yearID)){
                                if(document.getElementById(yearID).value <= d.getYear()){
                                    result = true;
                                }else{
                                    document.getElementById(yearID).focus();
                                    alert("Please enter the year (yyyy) of award.");
                                    result = false;
                                    break;
                                }
                            }
                            else{
                                result = false;
                                break;
                            }
                        }
                        else{
                            result = false;
                            break;
                        }
                    }
                    else{
                        result = false;
                        break;
                    }
                }else{
                    result = false;
                    break;
                }
            }else{
                result = true;
            }
        }
    }
    return result;
}

//update Award list
function UpdateAwardList(){
    var count = parseInt(document.getElementById('awardCounter').value-8);
    for(var no = 0; no<7; no++){
        var awardTitleID = "awardTitle"+(no+1);
        var awardByID = "awardBy"+(no+1);
        var awardYrID = "awardYr"+(no+1);

        var award = awardList[count];
        if(award){
            award.title = document.getElementById(awardTitleID).value;
            award.awardBy = document.getElementById(awardByID).value;
            award.year = document.getElementById(awardYrID).value;
            awardList[count] = award;
            count++;
        }else{
            if(document.getElementById(awardTitleID).value!="" &&
                document.getElementById(awardByID).value!="" &&
                document.getElementById(awardYrID).value!="yyyy"){
                var title = document.getElementById(awardTitleID).value;
                var awardBy = document.getElementById(awardByID).value;
                var year = document.getElementById(awardYrID).value;
                var awardTemp = new Award(title, awardBy, year);
                awardList[count] = awardTemp;
                count++;
            }
        }
    }
}

//delete award row by index
function DeleteAwardRow(noID){
    UpdateProExpList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    awardList.splice(no, 1);
    alert("Award Deleted!");
    var counter = parseInt(YAHOO.util.Dom.get("awardCounter").value - 7);
    DisplayAward(counter);
}

//display Award from list
function DisplayAward(counter){
    addAwardRow(counter, "awardNo", "awardTitle", "awardBy", "awardYr");
    for (var i = 0; i < 7; i++) {
        var award =  awardList[counter-1];
        if(award){
            var awardTitleID = "awardTitle"+(i+1);
            var awardByID = "awardBy"+(i+1);
            var awardYrID = "awardYr"+(i+1);

            document.getElementById(awardTitleID).value = award.title;
            document.getElementById(awardByID).value = award.awardBy;
            document.getElementById(awardYrID).value = award.year;
            counter++;
        }
        else{
            break;
        }
    }
}

//##############################################################################
//##############################################################################
//Save referee
function SaveReferee()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveReferee.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&refereeCount="+refereeList.length;
    for(var i=0;i<refereeList.length;i++)
    {
        var referee = refereeList[i];
        url = url+"&refName"+(i+1)+"="+referee.referee;
        url = url+"&refEmail"+(i+1)+"="+referee.email;
        url = url+"&refTel"+(i+1)+"="+referee.tel;
        url = url+"&refRelationship"+(i+1)+"="+referee.relationship;
        url = url+"&refPeriodKnown"+(i+1)+"="+referee.knownSince;
    }
    url =url+"&SaveReferee="+document.getElementById("SaveReferee").value;
    try{
        xmlhttp.onreadystatechange=SaveRefereeStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveRefereeStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("refereeInformationTable").style.display = "block";
                    document.getElementById("refereeInformationForm").style.display = "none";
                } else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshRefereeList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve referee
function RetrieveReferee()
{
    showResumeTab("referee");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievereferee.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&refereeCounter="+document.getElementById("refereeCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveRefereeStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveRefereeStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                refereeList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "refereeCount", 0, 0);
                while(index<count){
                    var refereeName = GetXMLNode(xmlDoc, "name", index, 0);
                    var email = GetXMLNode(xmlDoc, "email", index, 0);
                    var tel = GetXMLNode(xmlDoc, "contactNo", index, 0);
                    var relationship = GetXMLNode(xmlDoc, "relationship", index, 0);
                    var knownSince = GetXMLNode(xmlDoc, "periodKnown", index, 0);
                    var referee = new Referee(refereeName, email, tel, relationship, knownSince);
                    refereeList[index] = referee;
                    index++;
                }
                YAHOO.util.Dom.get("refereeCounter").value=8;
                addRefereeRow(1, "refNo", "refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown");
                for(var i = 0; i < 7; i++) {
                    referee =  refereeList[i];
                    if(referee){
                        var refNameID = "refName"+(i+1);
                        var refEmailID = "refEmail"+(i+1);
                        var refTelID = "refTel"+(i+1);
                        var refRelationshipID = "refRelationship"+(i+1);
                        var refPeriodKnownID = "refPeriodKnown"+(i+1);

                        document.getElementById(refNameID).value = referee.referee;
                        document.getElementById(refEmailID).value = referee.email;
                        document.getElementById(refTelID).value = referee.tel;
                        document.getElementById(refRelationshipID).value = referee.relationship;
                        document.getElementById(refPeriodKnownID).value = referee.knownSince;
                    }
                }
            }
            document.getElementById("refreshRefereeList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rr(){
    if(refereeTabCount == 0){
        RetrieveReferee();
    }
}

function rrt(){
    if(refereeTabCount == 0){
        refereeTabCount = 1;
        document.getElementById("refreshRefereeList").click();
    }
}

//add referee
function addRefereeRow(nextNo, no, name, email, tel, relationship, periodKnown){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var nameID = name + i + "";
        var emailID = email + i + "";
        var telID = tel + i + "";
        var relationshipID = relationship + i + "";
        var periodKnownID = periodKnown + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(nameID).value = "";
        document.getElementById(emailID).value = "";
        document.getElementById(telID).value = "";
        document.getElementById(relationshipID).value = "";
        document.getElementById(periodKnownID).value = "yyyy";
        nextNo++;
    }
}

//validate referee
function validateReferee(referee, email, tel, relationship, knownSince){
    document.getElementById("refereeTab").click();
    var result = false;
    var d = new Date();
    if(validateOneTextField(referee) && validateOneTextField(email)){
        for(var i=1;i<=7;i++){
            var refereeID = referee+i;
            var emailID = email+i;
            var telID = tel+i;
            var relationshipID = relationship+i;
            var knownSinceID = knownSince+i;
            if(document.getElementById(refereeID).value!="" || document.getElementById(emailID).value!="" ||
                document.getElementById(telID).value!="" || document.getElementById(relationshipID).value!="" ||
                document.getElementById(knownSinceID).value!="yyyy"){
                if(validate(refereeID, "", "Please enter referee name.")){
                    if(validateEmail(emailID)){
                        if(validate(telID, "", "Please enter referee contact number including country and area code.")){
                            if(validateNumber(telID, "Please enter telephone number in numeric only.")){
                                if(validate(relationshipID, "", "Please enter your relationship with the referee.")){
                                    if(validate(knownSinceID, "", "Please enter the year (yyyy) since you know your referee.")){
                                        if(validateNumber(knownSinceID, 'Please enter the year (yyyy) since you know your referee.')){
                                            if(document.getElementById(knownSinceID).value <= d.getYear()){
                                                result = true;
                                            }
                                            else{
                                                document.getElementById(knownSinceID).focus();
                                                alert("Please enter the year (yyyy) since you know your referee.");
                                                break;
                                            }
                                        }else{
                                            break;
                                        }
                                    }else{
                                        break;
                                    }
                                }
                                else{
                                    break;
                                }
                            }else{
                                break;
                            }
                        }
                        else{
                            break;
                        }
                    }
                    else{
                        break;
                    }
                }
                else{
                    break;
                }
            }
            else{
                result = true;
            }
        }
    }
    if(result){
        return result;
    }
    return false;
}

//update Referee list
function UpdateRefereeList(){
    var count = parseInt(document.getElementById('refereeCounter').value-8);
    for(var no = 0; no<7; no++){
        var refNameID = "refName"+(no+1);
        var refEmailID = "refEmail"+(no+1);
        var refTelID = "refTel"+(no+1);
        var refRelationshipID = "refRelationship"+(no+1);
        var refPeriodKnownID = "refPeriodKnown"+(no+1);

        var referee = refereeList[count];
        if(referee){
            referee.referee = document.getElementById(refNameID).value;
            referee.email = document.getElementById(refEmailID).value;
            referee.tel = document.getElementById(refTelID).value;
            referee.relationship = document.getElementById(refRelationshipID).value;
            referee.knownSince = document.getElementById(refPeriodKnownID).value;
            refereeList[count] = referee;
            count++;
        }else{
            if(document.getElementById(refNameID).value!="" && document.getElementById(refEmailID).value!="" &&
                document.getElementById(refTelID).value!="" && document.getElementById(refRelationshipID).value!=""&&
                document.getElementById(refPeriodKnownID).value!="yyyy"){
                var refereeName = document.getElementById(refNameID).value;
                var email = document.getElementById(refEmailID).value;
                var tel = document.getElementById(refTelID).value;
                var relationship = document.getElementById(refRelationshipID).value;
                var knownSince = document.getElementById(refPeriodKnownID).value;
                var refereeTemp = new Referee(refereeName, email, tel, relationship, knownSince);
                refereeList[count] = refereeTemp;
                count++;
            }
        }
    }
}

//delete Referee row by index
function DeleteRefereeRow(noID){
    UpdateRefereeList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    refereeList.splice(no, 1);
    alert("Referee Deleted!");
    var counter = parseInt(YAHOO.util.Dom.get("refereeCounter").value - 7);
    DisplayReferee(counter);
}

//display Referee from list
function DisplayReferee(counter){
    addRefereeRow(counter, "refNo", "refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown");
    for (var i = 0; i < 7; i++) {
        var referee =  refereeList[counter-1];
        if(referee){
            var refNameID = "refName"+(i+1);
            var refEmailID = "refEmail"+(i+1);
            var refTelID = "refTel"+(i+1);
            var refRelationshipID = "refRelationship"+(i+1);
            var refPeriodKnownID = "refPeriodKnown"+(i+1);

            document.getElementById(refNameID).value = referee.referee;
            document.getElementById(refEmailID).value = referee.email;
            document.getElementById(refTelID).value = referee.tel;
            document.getElementById(refRelationshipID).value = referee.relationship;
            document.getElementById(refPeriodKnownID).value = referee.knownSince;
            counter++;
        }
        else{
            break;
        }
    }
}

//##############################################################################
//##############################################################################
//Save availability
function SaveAvailability()
{
    var save = true;
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveAvailability.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    for(var ind=0; ind < document["forms"]["availabilityForm"]["availabilityRadio"].length; ind++){
        if(document["forms"]["availabilityForm"]["availabilityRadio"][ind].checked){
            var choice = document["forms"]["availabilityForm"]["availabilityRadio"][ind].value;
            if(choice == 1){
                url = url+"&availabilityChoice=1";
            }
            else if(choice == 2){
                if(validateAvailabilityChoice2()){
                    url = url+"&availabilityChoice=2";
                    url = url+"&availNoticePeriodNo="+document.getElementById("availNoticePeriodNo").value;
                    url = url+"&availNoticePeriodType="+document.getElementById("availNoticePeriodType").value;
                }else{
                    save = false;
                }
            }else if(choice == 3){
                if(validateAvailabilityChoice3()){
                    url = url+"&availabilityChoice=3";
                    url = url+"&availAfterDate="+document.getElementById("availAfterDate").value;
                }else{
                    save = false;
                }
            }
            else if(choice == 4){
                if(validateAvailabilityChoice4()){
                    url = url+"&availabilityChoice=4";
                    url = url+"&availFromDate="+document.getElementById("availFromDate").value;
                    url = url+"&availToDate="+document.getElementById("availToDate").value;
                }else{
                    save = false;
                }
            }
            else if(choice == 5){
                url = url+"&availabilityChoice=5";
            }
            break;
        }
    }
    url =url+"&SaveAvail="+document.getElementById("SaveAvail").value;
    if(save){
        try{
            xmlhttp.onreadystatechange=SaveAvailabilityStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}
function SaveAvailabilityStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                } else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve availability
function RetrieveAvailability()
{
    showResumeTab("availability");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveavailability.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    try{
        xmlhttp.onreadystatechange=RetrieveAvailabilityStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveAvailabilityStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                for(var ind=0; ind < document["forms"]["availabilityForm"]["availabilityRadio"].length; ind++){
                    document["forms"]["availabilityForm"]["availabilityRadio"][ind].checked = false;
                }
                SetValue("availAfterDay", "dd");
                SetValue("availAfterMth", "");
                SetValue("availAfterYr", "yyyy");
                SetValue("availAfterDate", "");

                SetValue("availFromDay", "dd");
                SetValue("availFromMth", "");
                SetValue("availFromYr", "yyyy");
                SetValue("availFromDate", "");

                SetValue("availToDay", "dd");
                SetValue("availToMth", "");
                SetValue("availToYr", "yyyy");
                SetValue("availToDate", "");
                SetValue("availNoticePeriodNo", "");
                SetValue("availNoticePeriodType", "0");

                SetXMLNode(xmlDoc, "noticeNo", 0, 0, "availNoticePeriodNo");
                SetXMLNode(xmlDoc, "noticeType", 0, 0, "availNoticePeriodType");
                SetRadioXMLNode(xmlDoc, "aType", 0, 0, "availabilityRadio", "availabilityForm");

                SetXMLNode(xmlDoc, "afterDate", 0, 0, "availAfterDate");
                SetDateXMLNode(xmlDoc, "afterDate", 0, 0, "availAfterDay", "availAfterMth", "availAfterYr");

                SetXMLNode(xmlDoc, "fromDate", 0, 0, "availFromMth");
                SetDateXMLNode(xmlDoc, "fromDate", 0, 0, "availFromDay", "availFromMth", "availFromYr");

                SetXMLNode(xmlDoc, "toDate", 0, 0, "availToDate");
                SetDateXMLNode(xmlDoc, "toDate", 0, 0, "availToDay", "availToMth", "availToYr");

            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function ravai(){
    if(avaTabCount == 0){
        RetrieveAvailability();
    }
}

//validate availability
function validateAvail(radio, form, showMsg){
    document.getElementById("availTab").click();
    var result = false;
    var selected = false;
    for(var ind=0; ind < document["forms"][form][radio].length; ind++){
        if(document["forms"][form][radio][ind].checked){
            var choice = document["forms"][form][radio][ind].value;
            if(choice == 1){
                result = true;
            }else if(choice == 2){
                if(validateAvailabilityChoice2()){
                    result = true;
                }
                else{
                    result = false;
                }
            }
            else if(choice == 3){
                if(validateAvailabilityChoice3()){
                    result = true;
                }
                else{
                    result = false;
                }
            }else if(choice == 4){
                if(validateAvailabilityChoice4()){
                    result = true;
                }
                else{
                    result = false;
                }
            }
            else if(choice == 5){
                result = true;
            }
            break;
        }
    }
    if(showMsg && !selected){
        alert("Please select a options.");
    }

    return result;
}

function validateAvailabilityChoice2(){
    if(!validate("availNoticePeriodNo", "", "Please enter your notice period.") ||
        !validate("availNoticePeriodType", "0", "Please select either weeks or months.") ){
        return false;
    }
    if(!isInteger(document.getElementById('availNoticePeriodNo').value)){
        alert("Please enter notice period in numeric (0 or more).");
        return false;
    }
    return true;
}

function validateAvailabilityChoice3(){
    if(!validate("availAfterDay", "dd", "Please enter day in (dd) format.") ||
        !validate("availAfterDay", "", "Please enter day in (dd) format.") ||
        !validate("availAfterMth", "", "Please select a month.") ||
        !validate("availAfterYr", "yyyy", "Please enter a year in (yyyy) format.") ||
        !validate("availAfterYr", "", "Please enter a year in (yyyy) format.") ||
        !isYear('availAfterYr') ||
        !validateDate("availAfterDay", "availAfterMth", "availAfterYr", "availAfterDate")){
        return false;
    }
    if(!isInteger(document.getElementById('availAfterDay').value)){
        alert("please enter day in numeric");
        return false;
    }
    return true;
}

function validateAvailabilityChoice4(){
    if(!validate("availFromDay", "dd", "Please enter day in (dd) format.") ||
        !validate("availFromDay", "", "Please enter day in (dd) format.") ||
        !validate("availFromMth", "", "Please select a month.") ||
        !validate("availFromYr", "yyyy", "Please enter a year in (yyyy) format.") ||
        !validate("availFromYr", "", "Please enter a year in (yyyy) format.") ||
        !validateDate("availFromDay", "availFromMth", "availFromYr", "availFromDate")){
        return false;
    }
    if(!validate("availToDay", "dd", "Please enter day in (dd) format.") ||
        !validate("availToDay", "", "Please enter day in (dd) format.") ||
        !validate("availToMth", "", "Please select a month.") ||
        !validate("availToYr", "yyyy", "Please enter a year in (yyyy) format.") ||
        !validate("availToYr", "", "Please enter a year in (yyyy) format.") ||
        !validateDate("availToDay", "availToMth", "availToYr", "availToDate")){
        return false;
    }
    if(!CompareDates(document.getElementById("availFromDate").value, 
    document.getElementById("availToDate").value,
    "Available TO Date must be later than Available FROM Date")){
        return false;
    }
    return true;
}

//##############################################################################
//##############################################################################
//Save availability
function SaveSalaryInv()
{
    var radioList = new Array("ESCommissionRadio","ESBonusRadio","ESShareOptionRadio",
    "LDSCommissionRadio", "LDSBonusRadio", "LDSShareOptionRadio");

    var salaryInvIDList = new Array("ESBHrCurrency", "ESBHrFrom", "ESBHrTo", "ESBDayCurrency",
    "ESBDayFrom", "ESBDayTo", "ESBMthCurrency", "ESBMthFrom", "ESBMthTo", "ESBYrCurrency",
    "ESBYrFrom","ESBYrTo", "LDSCurrency", "LDSFrom", "LDSTo" ,"LDSType");

    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveSalaryInventory.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    for(var i=0; i < salaryInvIDList.length; i++){
        url =url+"&"+salaryInvIDList[i]+"="+document.getElementById(salaryInvIDList[i]).value;
    }
    for( i=0; i < radioList.length; i++){
        for(var ind=0; ind < document["forms"]["salaryInventoryForm"][radioList[i]].length; ind++){
            if(document["forms"]["salaryInventoryForm"][radioList[i]][ind].checked){
                url =url+"&"+radioList[i]+"="+document["forms"]["salaryInventoryForm"][radioList[i]][ind].value;
                break;
            }
            else{
                url =url+"&"+radioList[i]+"=0";
            }
        }
    }
    url =url+"&SaveSalary="+document.getElementById("SaveSalary").value;
    try{
        xmlhttp.onreadystatechange=SaveSalaryInvStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function SaveSalaryInvStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                } else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve job skill requirement
function RetrieveSalaryInv()
{
    showResumeTab("salary");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievesalaryinventory.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&retrieveSalaryInv=retrieveSalaryInv";
    try{
        xmlhttp.onreadystatechange=RetrieveSalaryInvStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveSalaryInvStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("ESBHrCurrency", "");
                SetValue("ESBHrFrom", "");
                SetValue("ESBHrTo", "");

                SetValue("ESBDayCurrency", "");
                SetValue("ESBDayFrom", "");
                SetValue("ESBDayTo", "");

                SetValue("ESBMthCurrency", "");
                SetValue("ESBMthFrom", "");
                SetValue("ESBMthTo", "");

                SetValue("ESBYrCurrency", "");
                SetValue("ESBYrFrom", "");
                SetValue("ESBYrTo", "");

                SetValue("LDSCurrency", "");
                SetValue("LDSFrom", "");
                SetValue("LDSTo", "");
                SetValue("LDSType", "");

                var optionID = ["ESCommissionRadio", "ESBonusRadio", "ESShareOptionRadio",
                    "LDSCommissionRadio", "LDSBonusRadio", "LDSShareOptionRadio"];

                for(var i=0;i<optionID.length;i++){
                    for(var ind=0; ind < document["forms"]["salaryInventoryForm"][optionID[i]].length; ind++){
                        document["forms"]["salaryInventoryForm"][optionID[i]][ind].checked = false;
                    }
                }

                var x = xmlDoc.getElementsByTagName("salaryInventory");
                for (i=0;i<x.length;i++)
                {
                    if(x[i].getElementsByTagName("salaryType")[0]!= null){
                        if(x[i].getElementsByTagName("salaryType")[0].childNodes[0] != null){
                            var salaryType = x[i].getElementsByTagName("salaryType")[0].childNodes[0].nodeValue;
                            if(salaryType == 1){
                                SetRadioXMLNode(x[i], "commission", 0, 0, "ESCommissionRadio", "salaryInventoryForm");
                                SetRadioXMLNode(x[i], "bonus", 0, 0, "ESBonusRadio", "salaryInventoryForm");
                                SetRadioXMLNode(x[i], "shareOption", 0, 0, "ESShareOptionRadio", "salaryInventoryForm");

                                var xx =x[i].getElementsByTagName("basicSalary");
                                for (ind=0;ind<xx.length;ind++){
                                    var baseType = getRateType(xx[ind].getElementsByTagName("baseType")[0].childNodes[0].nodeValue);
                                    SetXMLNode(xx[ind], "currency", 0, 0, "ESB"+baseType+"Currency");
                                    SetPriceXMLNode(xx[ind], "baseFrom", 0, 0, "ESB"+baseType+"From");
                                    SetPriceXMLNode(xx[ind], "upTo", 0, 0, "ESB"+baseType+"To");
                                }
                            }
                            else if(salaryType == 2){
                                SetRadioXMLNode(x[i], "commission", 0, 0, "LDSCommissionRadio", "salaryInventoryForm");
                                SetRadioXMLNode(x[i], "bonus", 0, 0, "LDSBonusRadio", "salaryInventoryForm");
                                SetRadioXMLNode(x[i], "shareOption", 0, 0, "LDSShareOptionRadio", "salaryInventoryForm");

                                xx =x[i].getElementsByTagName("basicSalary");
                                for (ind=0;ind<xx.length;ind++){
                                    SetXMLNode(xx[ind], "baseType", 0, 0, "LDSType");
                                    SetXMLNode(xx[ind], "currency", 0, 0, "LDSCurrency");
                                    SetPriceXMLNode(xx[ind], "baseFrom", 0, 0, "LDSFrom");
                                    SetPriceXMLNode(xx[ind], "upTo", 0, 0, "LDSTo");
                                }
                            }
                        }
                    }
                }
            }

        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rsali(){
    if(salaryTabCount == 0){
        RetrieveSalaryInv();
    }
}

//validate salary inventory
function validateSalaryInv(){
    var result = true;
    //    var checkRadio = false;
    var typeList = new Array("Hr", "Day", "Mth", "Yr");

    for(var i=0; i < typeList.length; i++){
        var currency = "ESB"+typeList[i]+"Currency";
        var from = "ESB"+typeList[i]+"From";
        var to = "ESB"+typeList[i]+"To";
        if(document.getElementById(currency).value!="" || document.getElementById(from).value!="" ||
            document.getElementById(to).value!=""){
            //checkRadio = true;
            if(validate(currency, "", "Please select currency.")){
                if(validatePrice(from, "Please enter valid salary.")){
                    if(validatePrice(to, "Please enter valid salary.")){
                        result = true;
                    }
                    else{
                        result = false;
                        break;
                    }
                }
                else{
                    result = false;
                    break;
                }
            }
            else{
                result = false;
                break;
            }
        }
    }
    if(result){
        //        if(checkRadio){
        //            var esRadioList = new Array("ESCommissionRadio","ESBonusRadio","ESShareOptionRadio");
        //            var radioMsgList = new Array("commission","bonus","share options");
        //            for(i=0; i < esRadioList.length; i++){
        //                var num = 0;
        //                for(var ind=0; ind < document["forms"]["salaryInventoryForm"][esRadioList[i]].length; ind++){
        //                    if(!document["forms"]["salaryInventoryForm"][esRadioList[i]][ind].checked){
        //                        num++;
        //                    }
        //                }
        //                if(num == 2){
        //                    alert("Please select expected salary's "+radioMsgList[i]+" options");
        //                    result = false;
        //                    break;
        //                }
        //            }
        //        }
        if(result){
            //            checkRadio = false;
            if(document.getElementById("LDSCurrency").value!="" || document.getElementById("LDSFrom").value!="" ||
                document.getElementById("LDSTo").value!="" ||  document.getElementById("LDSType").value!=""){
                result = false;
                //checkRadio = true;
                if(validate("LDSCurrency", "", "Please select currency.")){
                    if(validatePrice("LDSFrom", "Please enter valid salary.")){
                        if(validatePrice("LDSTo", "Please enter valid salary.")){
                            if(validate("LDSType", "", "Please select salary type.")){
                                result = true;
                            }
                        }
                    }
                }
            }
            //            if(checkRadio){
            //                var ldsList = new Array("LDSCommissionRadio", "LDSBonusRadio", "LDSShareOptionRadio");
            //                for(i=0; i < ldsList.length; i++){
            //                    num = 0;
            //                    for(ind=0; ind < document["forms"]["salaryInventoryForm"][ldsList[i]].length; ind++){
            //                        if(!document["forms"]["salaryInventoryForm"][ldsList[i]][ind].checked){
            //                            num++;
            //                        }
            //                    }
            //                    if(num == 2){
            //                        alert("Please select last drawn salary's "+radioMsgList[i]+" options");
            //                        result = false;
            //                        break;
            //                    }
            //                }
            //            }
        }
        //        if(!checkRadio){
        //            result = false;
        //        }
    }
    return result;
}

//##############################################################################
//##############################################################################
//Save Resume Tag
function SaveResumeTag()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveResumeTag.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url = url+"&resumeTagCounter="+document.getElementById("resumeTagCounter").value;
    for(var i=0;i<7;i++)
    {
        var keyword = "resumeTagKeyword"+(i+1);
        url = url+"&resumeTagKeyword"+(i+1)+"="+document.getElementById(keyword).value;
    }
    url =url+"&SaveResumeTag="+document.getElementById("SaveResumeTag").value;
    try{
        xmlhttp.onreadystatechange=SaveResumeTagStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function SaveResumeTagStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!resumeSaveAll){
                if(xmlhttp.responseText=="1"){
                    alert("Resume Saved!");
                    document.getElementById("resumeTagTable").style.display = "block";
                    document.getElementById("resumeTagForm").style.display = "none";
                }
                else{
                    alert("Save Resume Failed. Please try again.");
                }
            }
            document.getElementById("refreshResumeTagList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve resume Tag
function RetrieveResumeTag()
{
    showResumeTab("tag");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveresumetag.php";
    url =url+"?resumeID="+document.getElementById("resumeID").value;
    url =url+"&resumeTagCounter="+document.getElementById("resumeTagCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveResumeTagStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveResumeTagStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                for(var i=1; i<8; i++){
                    var keyword = "resumeTagKeyword" + i;
                    document.getElementById(keyword).value="";
                }
                var index=0;
                while(index<7){
                    var jobTagNo = "resumeTagNo" + (index+1);
                    if(xmlDoc.getElementsByTagName("tagNo")[index]!= null){
                        if(xmlDoc.getElementsByTagName("tagNo")[index].childNodes[0] != null){
                            var tagNo = xmlDoc.getElementsByTagName("tagNo")[index].childNodes[0].nodeValue;
                            if(document.getElementById(jobTagNo).innerHTML == tagNo){
                                if(xmlDoc.getElementsByTagName("keyword")[index]!= null){
                                    if(xmlDoc.getElementsByTagName("keyword")[index].childNodes[0] != null){
                                        keyword = "resumeTagKeyword" + (index+1);
                                        document.getElementById(keyword).value=
                                            xmlDoc.getElementsByTagName("keyword")[index].childNodes[0].nodeValue;
                                    }
                                }
                            }
                        }
                    }
                    index++;
                }
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rrtag(){
    if(rTagTabCount == 0){
        RetrieveResumeTag();
        document.getElementById("refreshResumeTagList").click();
    }
}

//##############################################################################
//##############################################################################
//Save All Resume detail
function SaveAllResume()
{
    resumeSaveAll = true;
    var saveMsg = false;
    if(ppTabCount == 1){
        if(validatePersonalParitcular()){
            UpdatePersonalParticular();
            saveMsg = true;
        }
        else{
            saveMsg = false;
        }
    }
    if(eduHisTabCount == 1){
        if(saveMsg){
            if(validateEduHistory("ehSchName","ehSchCity", "ehSchCountry", "ehEduLvl", "ehGradYr")){
                UpdateEduHistoryList();
                SaveEducationHistory();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(empHisTabCount == 1){
        if(saveMsg){
            if(validateEmpHistory("empCompanyName","empJobTitle","empStartDateMth",
            "empStartDateYr", "empStartDate", "empEndDateMth", "empEndDateYr",
            "empEndDate", "empDesc")){
                UpdateEmpHistoryList();
                SaveEmploymentHistory();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(skillInvTabCount == 1){
        if(saveMsg){
            if(validateSkillInventory("skillInvName", "skillInvRating", "skillInvForm")){
                UpdateSkillInvList();
                if(validateSkillInvDuplicate()){
                    SaveSkillInv();
                    saveMsg = true;
                }else{
                    saveMsg = false;
                }
            }else{
                saveMsg = false;
            }
        }
    }
    if(ptTabCount == 1){
        if(saveMsg){
            if(validateProTraining("profTraining", "profProvider", "profYr")){
                UpdateProTrainingList();
                SaveProfessionalTraining();
                saveMsg = true;
            }else{
                saveMsg = false;
            }
        }
    }
    if(peTabCount == 1){
        if(saveMsg){
            if(validateProExp("projectTitle","projectRole","projectStartDateMth",
            "projectStartDateYr", "projectStartDate", "projectEndDateMth",
            "projectEndDateYr", "projectEndDate", "projectClient", "projectDesc")){
                UpdateProExpList();
                SaveProjectExperience();
                saveMsg = true;
            }else{
                saveMsg = false;
            }
        }
    }
    if(awardTabCount == 1){
        if(saveMsg){
            if(validateAward("awardTitle", "awardBy", "awardYr")){
                UpdateAwardList();
                SaveAward();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(refereeTabCount == 1){
        if(saveMsg){
            if(validateReferee("refName", "refEmail", "refTel", "refRelationship", "refPeriodKnown")){
                UpdateRefereeList();
                SaveReferee();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(avaTabCount == 1){
        if(saveMsg){
            if(validateAvail("availabilityRadio", "availabilityForm",false)){
                SaveAvailability();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(salaryTabCount == 1){
        if(saveMsg){
            document.getElementById("salaryTab").click();
            if(validateSalaryInv()){
                SaveSalaryInv();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(rTagTabCount == 1){
        if(saveMsg){
            document.getElementById("tagsTab").click();
            if(validateOneTextField("resumeTagKeyword")){
                SaveResumeTag();
                saveMsg = true;
            }
            else{
                saveMsg = false;
            }
        }
    }
    if(saveMsg){
        alert("Resume Saved!");
        resumeSaveAll = false;
    }

}

function rappt(){
    document.getElementById("refreshAppliedJobList").click();
}

function rassesst(){
    if(assessTabCount == 0){
        assessTabCount = 1;
        document.getElementById("refreshSkillAssessment").click();
    }
}

//##############################################################################
//##############################################################################
//job specification
//##############################################################################
//set resume buttons
function SetJobSpecsButtons(){

    var Gobtn = new YAHOO.widget.Button("searchCriteria");
    Gobtn.on("click", function(){
        SearchJob();
    });

    //save job button
    var SaveBtn = new YAHOO.widget.Button("SaveJob");
    SaveBtn.on("click", function() {
        if(validateJob()){
            SaveJob();
        }
    });

    //save as job button
    var SaveAllBtn = new YAHOO.widget.Button("SaveAllJob");
    SaveAllBtn.on("click", function() {
        SaveAllJob();
    });

    //save as job button
    var SaveAsBtn = new YAHOO.widget.Button("SaveAsJob");
    SaveAsBtn.on("click", function() {
        if(validateJob()){
            SaveAsJob();
        }
    });

    //update job status to post it button
    var jobStatusPostITBtn = new YAHOO.widget.Button("jobStatusPostITBtn");
    jobStatusPostITBtn.on("click", function(){
        if(YAHOO.util.Dom.get("jobID").value != ""){
            if(validatePostItJob()){
                postit = false;
                updateJobStatus = true;
                SaveAllJob();
            }
        }
    });

    //rank it button
    var jobRankingBtn = new YAHOO.widget.Button("jobRankingBtn");
    jobRankingBtn.on("click", function(){
        if(YAHOO.util.Dom.get("jobID").value != ""){
            if(parseInt(document.getElementById('jobApplicantCount').value)<jobRankingCount){
                alert("Total candidate is lower than "+jobRankingCount+". We recommend you to wait for more candidate to apply to this job before ranking it.");
            }
            CheckExpiredOrder();
            CheckCompanyBalance("ranking");
        }
    });
    //refresh rank it button
    var jobRefreshRankingBtn = new YAHOO.widget.Button("jobRefreshRankingBtn");
    jobRefreshRankingBtn.on("click", function(){
        document.getElementById('refreshApplicantRankList').click();
    });

    //update job status to re-submit button
    var jobStatusReSubmitBtn = new YAHOO.widget.Button("jobStatusReSubmitBtn");
    jobStatusReSubmitBtn.on("click", function(){
        if(YAHOO.util.Dom.get("jobID").value != ""){
            UpdateJobStatus();
        }
    });

    //update job status to remove button
    var jobStatusRemoveBtn = new YAHOO.widget.Button("jobStatusRemoveBtn");
    jobStatusRemoveBtn.on("click", function(){
        if(YAHOO.util.Dom.get("jobID").value != ""){
            if(confirm("A job specification will be removed from posting."+
                "That is, it will no longer be visible to job seekers. "+
                "Please confirm to remove this job posting.")) UpdateJobStatus();
        }
    });

    //save job education requirement button
    var eduReqBtn = new YAHOO.widget.Button("SaveJobEduReq");
    eduReqBtn.on("click", function(){
        SaveJobEduReq();
    });

    //save job roles and responsibility button
    var roleNResponBtn = new YAHOO.widget.Button("SaveJobRoleNRespon");
    roleNResponBtn.on("click", function(){
        SaveJobRoleNRespon();
    });

    //save job skill requirement button
    var saveSkillBtn = new YAHOO.widget.Button("SaveJobSkillReq");
    saveSkillBtn.on("click", function(){
        if(validateJobSkillReq()){
            UpdateSkillReqList();
            if(validateJobSkillDuplicate()){
                SaveJobSkillReq();
            }
        }
    });

    //skill requirement previous button
    var skillPrevBtn = new YAHOO.widget.Button("jobSkillReqPrev");
    skillPrevBtn.on("click", function(){
        if(YAHOO.util.Dom.get("jobSkillReqCounter").value > 8){
            if(validateJobSkillReq()){
                UpdateSkillReqList();
                YAHOO.util.Dom.get("jobSkillReqCounter").value = parseInt(YAHOO.util.Dom.get("jobSkillReqCounter").value) - 7;
                var counter = parseInt(YAHOO.util.Dom.get("jobSkillReqCounter").value) - 7;
                DisplaySkillReq(counter);
            }
        }
    });

    //skill requirement next button
    var skillNextBtn = new YAHOO.widget.Button("jobSkillReqNext");
    skillNextBtn.on("click", function(){
        if(validateRadioRows("skillReqName", "skillReqRating", "skillReqForm", "skillReqPriority")){
            if(validateJobSkillReq()){
                UpdateSkillReqList();
                var counter = parseInt(YAHOO.util.Dom.get("jobSkillReqCounter").value);
                YAHOO.util.Dom.get("jobSkillReqCounter").value = counter + 7;
                DisplaySkillReq(counter);
            }
        }
    });

    //save job location button
    var saveLocationBtn = new YAHOO.widget.Button("SaveJobLocation");
    saveLocationBtn.on("click", function(){
        if(validateLocation("jobLocationCity", "jobLocationState", "jobLocationCountry", "jobLocationTab")){
            UpdateJobLocationList();
            if(validateJobLocationDuplicate()){
                SaveJobLocation();
            }
        }
    
        
    });

    //    //job location previous button
    //    var locationPrevBtn = new YAHOO.widget.Button("jobLocationPrev");
    //    locationPrevBtn.on("click", function(){
    //        if(YAHOO.util.Dom.get("jobLocationCounter").value > 8){
    //            if(validateLocation("jobLocationCity", "jobLocationState", "jobLocationCountry", "jobLocationTab")){
    //                SaveJobLocation();
    //                YAHOO.util.Dom.get("jobLocationCounter").value = parseInt(YAHOO.util.Dom.get("jobLocationCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("jobLocationCounter").value) - 7;
    //                addLocationRow(counter, "jobLocationNo", "jobLocationCity", "jobLocationState", "jobLocationCountry");
    //                RetrieveJobLocation();
    //            }
    //        }
    //    });
    //
    //    //job location next button
    //    var locationNextBtn = new YAHOO.widget.Button("jobLocationNext");
    //    locationNextBtn.on("click", function(){
    //        if(validateRows("jobLocationCountry", "") && validateLocation("jobLocationCity", "jobLocationState", "jobLocationCountry", "jobLocationTab")){
    //            SaveJobLocation();
    //            var counter = parseInt(YAHOO.util.Dom.get("jobLocationCounter").value);
    //            YAHOO.util.Dom.get("jobLocationCounter").value = counter + 7;
    //            addLocationRow(counter, "jobLocationNo", "jobLocationCity", "jobLocationState", "jobLocationCountry");
    //            RetrieveJobLocation();
    //
    //        }
    //    });

    //save job travel requirement button
    var saveTravelBtn = new YAHOO.widget.Button("SaveJobTravel");
    saveTravelBtn.on("click", function(){
        if(validateLocation("jobTravelCity", "jobTravelState", "jobTravelCountry", "jobTravelTab")){
            UpdateJobTravelList();
            if(validateJobTravelDuplicate()){
                SaveJobTravel();
            }
        }
    });

    //    //job travel requirement previous button
    //    var TravelPrevBtn = new YAHOO.widget.Button("jobTravelPrev");
    //    TravelPrevBtn.on("click", function(){
    //        if(YAHOO.util.Dom.get("jobTravelCounter").value > 8){
    //            if(validateLocation("jobTravelCity", "jobTravelState", "jobTravelCountry", "jobTravelTab")){
    //                SaveJobTravel();
    //                YAHOO.util.Dom.get("jobTravelCounter").value = parseInt(YAHOO.util.Dom.get("jobTravelCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("jobTravelCounter").value) - 7;
    //                addLocationRow(counter, "jobTravelNo", "jobTravelCity", "jobTravelState", "jobTravelCountry");
    //                RetrieveJobTravel();
    //            }
    //        }
    //    });
    //
    //    //job travel requirement next button
    //    var TravelNextBtn = new YAHOO.widget.Button("jobTravelNext");
    //    TravelNextBtn.on("click", function(){
    //        if(validateRows("jobTravelCountry", "") && validateLocation("jobTravelCity", "jobTravelState", "jobTravelCountry", "jobTravelTab")){
    //            SaveJobTravel();
    //            var counter = parseInt(YAHOO.util.Dom.get("jobTravelCounter").value);
    //            YAHOO.util.Dom.get("jobTravelCounter").value = counter + 7;
    //            addLocationRow(counter, "jobTravelNo", "jobTravelCity", "jobTravelState", "jobTravelCountry");
    //            RetrieveJobTravel();
    //        }
    //
    //    });

    //save job Salary
    var SaveJobSalaryBtn = new YAHOO.widget.Button("SaveJobSalary");
    SaveJobSalaryBtn.on("click", function(){
        if(validateJobSalary()){
            SaveJobSalary();
        }
    });

    //    //save job tag button
    //    var saveTagBtn = new YAHOO.widget.Button("SaveJobTag");
    //    saveTagBtn.on("click", function(){
    //        if(validateJobTag()){
    //            SaveJobTag();
    //        }
    //    });

    //    //job location previous button
    //    var tagPrevBtn = new YAHOO.widget.Button("jobTagPrev");
    //    tagPrevBtn.on("click", function(){
    //        if(YAHOO.util.Dom.get("jobTagCounter").value > 8){
    //            if(validateJobTag()){
    //                SaveJobTag();
    //                YAHOO.util.Dom.get("jobTagCounter").value = parseInt(YAHOO.util.Dom.get("jobTagCounter").value) - 7;
    //                var counter = parseInt(YAHOO.util.Dom.get("jobTagCounter").value) - 7;
    //                addTagRow(counter, "jobTagNo", "jobTagKeyword");
    //                RetrieveJobTag();
    //            }
    //        }
    //    });
    //
    //    //job location next button
    //    var tagNextBtn = new YAHOO.widget.Button("jobTagNext");
    //    tagNextBtn.on("click", function(){
    //        if(validateRows("jobTagKeyword", "")){
    //            if(validateJobTag()){
    //                SaveJobTag();
    //                var counter = parseInt(YAHOO.util.Dom.get("jobTagCounter").value);
    //                YAHOO.util.Dom.get("jobTagCounter").value = counter + 7;
    //                addTagRow(counter, "jobTagNo", "jobTagKeyword");
    //                RetrieveJobTag();
    //            }
    //        }
    //    });

    var NewJob = new YAHOO.widget.Button("NewJob");
    NewJob.on("click", function(){
        if(!ignoreJobValidation){
            if(!saveJobSpec && !saveJobEduReq && !saveJobRoleNRespon &&
                !saveJobSkillReq && !saveJobLocation && !saveJobTravel &&
                !saveJobSalaryReq && !saveJobTag){
                NewJobSpec();
            }
            else{
                if(confirm("Job Specs not save! Save now?")) {
                    SaveAllJob();
                }else{
                    if(confirm("Discard current job info?")){
                        NewJobSpec();
                    }
                }
            }
        }else{
            NewJobSpec();
        }
    });
    RetrieveCompanyConfigure();
    //    alert("To view the candidates, please select a job and click on the Candidate tab.");
    CheckExpiredOrder();
}

function RetrieveCompanyConfigure()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveconfigure.php";
    url =url+"?configureID=1";
    try{
        xmlhttp.onreadystatechange=RetrieveCompanyConfigureStateChanged;
        xmlhttp.open("GET",url,false);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function RetrieveCompanyConfigureStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                jobSkillReqCount = GetXMLNode(xmlDoc, 'minSkill', 0, 0);
                jobRankingCount =  GetXMLNode(xmlDoc, 'minCandidate', 0, 0);
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
//##############################################################################
function NewJobSpec(){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="ClearJobID.php";
    try{
        xmlhttp.onreadystatechange=NewJobSpecStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function NewJobSpecStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            SetValue("jobID", "");
            SetValue("jobTitle", "");
            SetValue("jobReferenceNo", "");
            SetValue("jobYrOfExp", "");
            SetValue("jobPostingDay", "dd");
            SetOptionValue("jobPostingMth", 0, true);
            SetValue("jobPostingYr", "yyyy");
            SetValue("jobPostingDate", "");
            SetValue("jobClosingDay", "dd");
            SetOptionValue("jobClosingMth", 0, true);
            SetValue("jobClosingYr", "yyyy");
            SetValue("jobClosingDate", "");
            SetOptionValue("jobType", 0, true);
            SetValue("jobTypes", "");
            SetValue("jobNoOfPosition", "");
            //        SetValue("jobWebsite", "");
            SetValue("jobClientName", "");
            if(document.getElementById('recruitmentCompany')!=null){
                document.getElementById('recruitmentCompany').checked = false;
            }
            SetValue("jobDesc", "");
            SetValue("jobEduReq", "");
            SetValue("jobRoleNRespon", "");
            SetValue("jobStatus", "1");
            SetValue("jobSalaryID", "");

            YAHOO.util.Dom.get("jobStatusHeader").innerHTML = "";
            YAHOO.util.Dom.get("jobHeader").innerHTML = "New Job";
            YAHOO.util.Dom.get("jobReferenceNoHeader").innerHTML = "";
            for(var i=1; i<8; i++){
                var skillReqName = "skillReqName" + i;
                document.getElementById(skillReqName).value="";
                var skillReqRating = "skillReqRating" + i;
                for(var ind=0; ind < document["forms"]["skillReqForm"][skillReqRating].length; ind++){
                    document["forms"]["skillReqForm"][skillReqRating][ind].checked = false;
                }
                var skillReqPriority = "skillReqPriority" + i;
                document.getElementById(skillReqPriority).value="0";
            }

            for(i=1; i<8; i++){
                var city = "jobLocationCity" + i;
                document.getElementById(city).value="";
                var state = "jobLocationState" + i;
                document.getElementById(state).value="";
                var country = "jobLocationCountry" + i;
                document.getElementById(country).value="";
            }

            for(i=1; i<8; i++){
                city = "jobTravelCity" + i;
                document.getElementById(city).value="";
                state = "jobTravelState" + i;
                document.getElementById(state).value="";
                country = "jobTravelCountry" + i;
                document.getElementById(country).value="";
            }

            SetValue("JSBHrCurrency", "");
            SetValue("JSBHrFrom", "");
            SetValue("JSBHrTo", "");
            SetValue("JSBDayCurrency", "");
            SetValue("JSBDayFrom", "");
            SetValue("JSBDayTo", "");
            SetValue("JSBMthCurrency", "");
            SetValue("JSBMthFrom", "");
            SetValue("JSBMthTo", "");
            SetValue("JSBYrCurrency", "");
            SetValue("JSBYrFrom", "");
            SetValue("JSBYrTo", "");

            var optionID = ["JSCarRadio", "JSAccomodationRadio", "JSRelocationBenefitsRadio",
                "JSCommissionRadio", "JSBonusRadio", "JSShareOptionRadio"];

            for( i=0;i<optionID.length;i++){
                for( ind=0; ind < document["forms"]["jobSalaryForm"][optionID[i]].length; ind++){
                    document["forms"]["jobSalaryForm"][optionID[i]][ind].checked = false;
                }
            }

            for( i=1; i<8; i++){
                var keyword = "jobTagKeyword" + i;
                document.getElementById(keyword).value="";
            }
            document.getElementById("refreshSkillRequirementList").click();
            document.getElementById("refreshLocationList").click();
            document.getElementById("refreshTravelList").click();
            document.getElementById("JobStatusRemove").style.display = "none";
            document.getElementById("JobStatusReSubmit").style.display = "none";
            document.getElementById("JobStatusPostIT").style.display = "none";
            document.getElementById("SaveAsBtn").style.display = "none";

            setDisplay('JobApplicant','none');
            setDisplay('jobAppTab','none');
            
            setDisplay('jobGeneralTable','block');
            setDisplay('jobGeneralMsg','none');

            setDisplay('jobEduTable','block');
            setDisplay('jobEduMsg','none');

            setDisplay('jobRoleNResponseTable','block');
            setDisplay('jobRoleNResponseMsg','none');

            setDisplay('jobLocationForm','block');
            setDisplay('jobLocationMsg','none');

            setDisplay('jobTravelForm','block');
            setDisplay('jobTravelMsg','none');

            setDisplay('jobSalaryForm','block');
            setDisplay('jobSalaryMsg','none');

            setDisplay('applyForm','block');

            setDisplay('skillRequirementForm','block');
            setDisplay('jobSkillRequirementMsg','none');

            setDisplay('jobSalaryForm','block');
            setDisplay('jobSalaryMsg','none');

            setDisplay('jobSkillRequirementMsg','none');
            setDisplay('SaveAllBtn','block');

            setDisplay('applicantResumeRow','none');

            JobSpecsReadOnly(false, "block");
            ResetJobCount();
            ResetJobSave();
            ResetResumeCount();
            ignoreJobValidation = false;
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }

}

//##############################################################################
//##############################################################################
function CheckSaveJobToURL(link){
    if(!ignoreJobValidation){
        if(saveJobSpec || saveJobEduReq || saveJobRoleNRespon ||
            saveJobSkillReq || saveJobLocation || saveJobTravel ||
            saveJobSalaryReq || saveJobTag){
            if(confirm("Job Specs not save! Save now?")) {
                goToURL = true;
                goToLink = link;
                SaveAllJob();
            }
            else{
                if(confirm("Discard current job info?")){
                    goToPage(link);
                }
            }
        }else{
            goToPage(link);
        }
    }
    else{
        goToPage(link);
    }
}
function goToPage(link){
    if(link == "account"){
        window.location = "Account.php";
    }else if(link == "employer"){
        window.location="Employers.php";
    }else if(link == "jobs"){
        window.location="RecruiterJobList.php";
    }else if(link == "logout"){
        window.location = "Logout.php";
    }else if(link == "transaction"){
        window.location = "CompanyTransaction.php";
    }else if(link == "candidate"){
        window.location="CandidatePage.php";
    }
}

//##############################################################################
//##############################################################################
//Save Job detail
function SaveJob()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveJob.php";

    url =url+"?jobID="+document.getElementById("jobID").value;
    url =url+"&title="+document.getElementById("jobTitle").value;
    url =url+"&referenceNo="+document.getElementById("jobReferenceNo").value;
    url =url+"&yearOfExperience="+document.getElementById("jobYrOfExp").value;
    url =url+"&postingDate="+document.getElementById("jobPostingDate").value;
    url =url+"&closingDate="+document.getElementById("jobClosingDate").value;
    url =url+"&jobType="+document.getElementById("jobType").value;
    url =url+"&noOfPosition="+document.getElementById("jobNoOfPosition").value;
    url =url+"&description="+ReplaceLineBreak(document.getElementById("jobDesc").value);
    url =url+"&jobStatus="+document.getElementById("jobStatus").value;
    if(document.getElementById("recruitmentCompany").checked){
        url =url+"&recruitmentCompany="+document.getElementById("recruitmentCompany").value;
    }else{
        url =url+"&recruitmentCompany=0";
    }
    url =url+"&clientName="+document.getElementById("jobClientName").value;
    url =url+"&saveJob="+document.getElementById("SaveJob").value;
    try{
        xmlhttp.onreadystatechange=SaveJobStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function SaveJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            var jobID = "";
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                if(xmlDoc.getElementsByTagName("refNoExist")[0]!= null){
                    if(xmlDoc.getElementsByTagName("refNoExist")[0].childNodes[0] != null){
                        if(xmlDoc.getElementsByTagName("refNoExist")[0].childNodes[0].nodeValue != ""){
                            refNoExist = true;
                        }
                        else{
                            refNoExist = false;
                        }
                    }
                }
                if(xmlDoc.getElementsByTagName("jobID")[0]!= null){
                    if(xmlDoc.getElementsByTagName("jobID")[0].childNodes[0] != null){
                        document.getElementById('jobID').value = xmlDoc.getElementsByTagName("jobID")[0].childNodes[0].nodeValue;
                        ignoreJobValidation = true;
                        jobID = xmlDoc.getElementsByTagName("jobID")[0].childNodes[0].nodeValue;
                    }
                }
                if(!jobSaveAll){
                    if(!refNoExist){
                        showXMLNodeAlert(xmlDoc, "SJSuccess", 0, 0, postit);
                        showXMLNodeAlert(xmlDoc, "SJFail", 0, 0, postit);
                        showXMLNodeAlert(xmlDoc, "SAJSuccess", 0, 0, postit);
                        showXMLNodeAlert(xmlDoc, "SAJFail", 0, 0, postit);
                        RetrieveJobDetail(jobID);
                    }else{
                        refNoExist = false;
                        showXMLNodeAlert(xmlDoc, "refNoExist", 0, 0, postit);
                    }
                }else{
                    if(jobEducationTabCount == 1 && saveJobEduReq && jobSaveMsg){
                        SaveJobEduReq();
                    }
                    if(jobResponseTabCount == 1 && saveJobRoleNRespon && jobSaveMsg){
                        SaveJobRoleNRespon();
                    }
                    if(jobSkillTabCount == 1 && saveJobSkillReq && jobSaveMsg){
                        if(validateJobSkillReq()){
                            UpdateSkillReqList();
                            if(validateJobSkillDuplicate()){
                                SaveJobSkillReq();
                                jobSaveMsg = true;
                            }
                            else{
                                jobSaveMsg = false;
                            }
                        }
                        else{
                            jobSaveMsg = false;
                        }

                    }
                    if(jobLocationTabCount == 1 && saveJobLocation && jobSaveMsg){
                        if(validateLocation("jobLocationCity", "jobLocationState", "jobLocationCountry", "jobLocationTab")){
                            UpdateJobLocationList();
                            if(validateJobLocationDuplicate()){
                                SaveJobLocation();
                                jobSaveMsg = true;
                            }else{
                                jobSaveMsg = false;
                            }
                        }
                        else{
                            jobSaveMsg = false;
                        }

                    }
                    if(jobTravelTabCount == 1 && saveJobTravel && jobSaveMsg){
                        if(validateLocation("jobTravelCity", "jobTravelState", "jobTravelCountry", "jobTravelTab")){
                            UpdateJobTravelList();
                            if(validateJobTravelDuplicate()){
                                SaveJobTravel();
                                jobSaveMsg = true;
                            }else{
                                jobSaveMsg = false;
                            }
                        }
                        else{
                            jobSaveMsg = false;
                        }

                    }
                    if(jobSalaryTabCount == 1 && saveJobSalaryReq && jobSaveMsg){
                        if(validateJobSalary()){
                            SaveJobSalary();
                            jobSaveMsg = true;
                        }
                        else{
                            jobSaveMsg = false;
                        }

                    }
                    if(jobTagTabCount == 1 && saveJobTag && jobSaveMsg){
                        if(validateJobTag()){
                            SaveJobTag();
                            jobSaveMsg = true;
                        }
                        else{
                            jobSaveMsg = false;
                        }
                    }
                    if(jobSaveMsg){
                        ResetJobCount();
                        ResetJobSave();
                        if(goToURL){
                            goToPage(goToLink);
                        }
                        if(!refNoExist && !updateJobStatus){
                            alert("Job specification saved successfully.");
                            if(retrieveJob){
                                RetrieveJobDetail(retrieveJobID);
                                retrieveJob = false;
                                retrieveJobID = "";
                            }else{
                                RetrieveJobDetail(jobID);
                                if(!ignoreSkillReqCheck){
                                    if(skillReqList.length<jobSkillReqCount){
                                        alert("It is recommended that you should have more than "+jobSkillReqCount
                                            +" competencies in order to improve the accuracy of the ranking. Please enter more competencies.");
                                    }
                                }
                                else{
                                    ignoreSkillReqCheck = false;
                                }
                            }
                        }
                        if(updateJobStatus){
                            var confirmPosting = true;
                            if(skillReqList.length<jobSkillReqCount){
                                if(!confirm("Your job competencies are below the recommended number. Do you want to proceed to post?")){
                                    confirmPosting = false;
                                }
                            }
                            if(confirmPosting){
                                CheckExpiredOrder();
                                CheckCompanyBalance("posting");
                            }
                        }
                    }
                    showXMLNodeAlert(xmlDoc, "SJSuccess", 0, 0, false);
                    showXMLNodeAlert(xmlDoc, "SAJSuccess", 0, 0, false);
                    showXMLNodeAlert(xmlDoc, "refNoExist", 0, 0, true);
                    jobSaveAll = false;
                }
                if(!postit){
                    postit = true;
                }
                ignoreJobValidation = false;
            }
            //            if(jobID==""){
            //                alert("Save Job Failed. Please try again.");
            //            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function CheckCompanyBalance(type){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievecompanybalance.php";
    url =url+"?type="+type;
    url =url+"&jobID="+document.getElementById("jobID").value;
    url =url+"&jobStatus="+document.getElementById("jobStatus").value;
    try{
        xmlhttp.onreadystatechange=CheckCompanyBalanceStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function CheckCompanyBalanceStateChanged() {
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                var type = GetXMLNode(xmlDoc, 'type', 0, 0);
                var balance = GetXMLNode(xmlDoc, 'balance', 0, 0);
                if(type == "posting"){
                    if(balance>0){
                        if(confirm("Your posting balance is "+balance+". Please confirm to post this job.")) {
                            UpdateJobStatus();
                        }
                    }else{
                        alert("No credit left! Please buy more credit!");
                        window.open("OrderForm.php","orderForm","width=900,height=700,scrollbars=1");
                    }
                }else if(type == "ranking"){
                    if(balance>0){
                        if(confirm("Your ranking balance is "+balance+". Please confirm to rank this job.")) {
                            RankingJob();
                        }
                    }else{
                        alert("No credit left! Please buy more credit!");
                        window.open("OrderRankingForm.php","orderForm","width=900,height=700,scrollbars=1");
                    }
                }
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function showXMLNodeAlert(xmlDoc, tagName, index, index2, alertShow){
    if(xmlDoc.getElementsByTagName(tagName)[index]!= null){
        if(xmlDoc.getElementsByTagName(tagName)[index].childNodes[index2] != null){
            if(xmlDoc.getElementsByTagName(tagName)[index].childNodes[index2].nodeValue != ""){
                if(alertShow){
                    alert(xmlDoc.getElementsByTagName(tagName)[index].childNodes[index2].nodeValue);
                }
                if(tagName == "SJSuccess" || tagName == "SAJSuccess"){
                    saveJobSpec = false;
                    refNoExist = false;
                    document.getElementById("refreshJobList").click();
                }
                if(tagName == "refNoExist"){
                    jobSaveMsg = false;
                }
                if(tagName == "JSSuccess"){
                    saveJobSalaryReq = false;
                }
            }
        }
    }
}

//save job general check
function sjgc(){
    if(!saveJobSpec){
        saveJobSpec = true;
    }
}

//retrieve job detail by jobID
function RetrieveJobDetail(jobID){
    if(jobID!=""){
        if(!ignoreJobValidation){
            if(!saveJobSpec && !saveJobEduReq && !saveJobRoleNRespon &&
                !saveJobSkillReq && !saveJobLocation && !saveJobTravel &&
                !saveJobSalaryReq && !saveJobTag){

                xmlhttp=GetXmlHttpObject();
                if (xmlhttp==null)
                {
                    alert ("Browser does not support HTTP Request");
                    return;
                }
                var url="xmlretrievejobdetail.php";
                url =url+"?jobID="+jobID;
                try{
                    xmlhttp.onreadystatechange=RetrieveJobDetailStateChanged;
                    xmlhttp.open("GET",url,true);
                    xmlhttp.send(null);
                }catch (e) {
                    alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
                }

            }
            else{
                if(confirm("Job Specs not save. Save now?")) {
                    ignoreSkillReqCheck = true;
                    retrieveJob = true;
                    retrieveJobID = jobID;
                    SaveAllJob();
                }else{
                    if(confirm("Discard current job info?")) {
                        ResetJobCount();
                        ResetJobSave();
                        RetrieveJobDetail(jobID);
                    }
                }
            }
        }else{
            xmlhttp=GetXmlHttpObject();
            if (xmlhttp==null)
            {
                alert ("Browser does not support HTTP Request");
                return;
            }
            url="xmlretrievejobdetail.php";
            url =url+"?jobID="+jobID;
            try{
                xmlhttp.onreadystatechange=RetrieveJobDetailStateChanged;
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);
            } catch (e) {
                alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
            }
        }
    }
}
function RetrieveJobDetailStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("jobID", "");
                SetValue("jobTitle", "");
                SetValue("jobReferenceNo", "");
                SetValue("jobYrOfExp", "");
                SetValue("jobPostingDay", "dd");
                SetOptionValue("jobPostingMth", 0, true);
                SetValue("jobPostingYr", "yyyy");
                SetValue("jobPostingDate", "");
                SetValue("jobClosingDay", "dd");
                SetOptionValue("jobClosingMth", 0, true);
                SetValue("jobClosingYr", "yyyy");
                SetValue("jobClosingDate", "");
                SetOptionValue("jobType", 0, true);
                SetValue("jobTypes", "");
                SetValue("jobNoOfPosition", "");
                SetValue("jobClientName", "");
                if(document.getElementById('recruitmentCompany')!=null){
                    document.getElementById('recruitmentCompany').checked=false;
                }
                //            SetValue("jobWebsite", "");
                SetValue("jobDesc", "");
                if(document.getElementById('appApplyCounter')!=null){
                    document.getElementById('appApplyCounter').innerHTML = " (0)";
                }
            
                if(!saveJobEduReq){
                    SetValue("jobEduReq", "");
                }
                if(!saveJobRoleNRespon){
                    SetValue("jobRoleNRespon", "");
                }
                SetValue("jobStatus", "");
                SetValue("jobSalaryID", "");
                SetValue("jobCompanyName", "");

                setDisplay('JobApplicant','none');
                setDisplay('jobAppTab','none');
            
                setDisplay('applicantResumeRow','none');

                setDisplay('jobGeneralTable','block');
                setDisplay('jobGeneralMsg','none');

                setDisplay('jobEduTable','block');
                setDisplay('jobEduMsg','none');

                setDisplay('jobRoleNResponseTable','block');
                setDisplay('jobRoleNResponseMsg','none');

                setDisplay('jobLocationForm','block');
                setDisplay('jobLocationTable','block');
                setDisplay('jobLocationMsg','none');

                setDisplay('jobTravelForm','block');
                setDisplay('jobTravelTable','block');
                setDisplay('jobTravelMsg','none');

                setDisplay('jobSalaryForm','block');
                setDisplay('jobSalaryMsg','none');

                setDisplay('applyForm','block');

                setDisplay('skillRequirementForm','block');
                setDisplay('jobSkillRequirementMsg','none');

                setDisplay('jobSalaryForm','block');
                setDisplay('jobSalaryMsg','none');

                setDisplay('jobSkillRequirementMsg','none');

                setDisplay('JobStatusPostIT','none');
                setDisplay('JobStatusReSubmit','none');
                setDisplay('JobStatusRemove','none');

                setDisplay('SaveAllBtn','block');
                SetXMLNode(xmlDoc, "jobID", 0, 0, "jobID");
                SetXMLNode(xmlDoc, "title", 0, 0, "jobTitle");
                SetXMLNode(xmlDoc, "companyName", 0, 0, "jobCompanyName");
                if(xmlDoc.getElementsByTagName("title")[0]!= null){
                    if(xmlDoc.getElementsByTagName("title")[0].childNodes[0] != null){
                        YAHOO.util.Dom.get("jobHeader").innerHTML =
                            "Job Title: '"+xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue+"' ";
                    }
                }
                SetXMLNode(xmlDoc, "referenceNo", 0, 0, "jobReferenceNo");
                if(xmlDoc.getElementsByTagName("referenceNo")[0] != null){
                    if(xmlDoc.getElementsByTagName("referenceNo")[0].childNodes[0] != null){
                        YAHOO.util.Dom.get("jobReferenceNoHeader").innerHTML =
                            " (Ref: "+xmlDoc.getElementsByTagName("referenceNo")[0].childNodes[0].nodeValue+") ";
                    }
                }
                if(GetXMLNode(xmlDoc, "yearOfExperience", 0, 0)>0){
                    SetXMLNode(xmlDoc, "yearOfExperience", 0, 0, "jobYrOfExp");
                }
                SetXMLNode(xmlDoc, "postingDate", 0, 0, "jobPostingDate");
                SetDateXMLNode(xmlDoc, "postingDate", 0, 0, "jobPostingDay", "jobPostingMth", "jobPostingYr");
                SetXMLNode(xmlDoc, "closingDate", 0, 0, "jobClosingDate");
                SetDateXMLNode(xmlDoc, "closingDate", 0, 0, "jobClosingDay", "jobClosingMth", "jobClosingYr");
                SetXMLNode(xmlDoc, "jobType", 0, 0, "jobType");

                if(xmlDoc.getElementsByTagName("jobType")[0] != null){
                    if(xmlDoc.getElementsByTagName("jobType")[0].childNodes[0] != null){
                        if(document.getElementById("jobTypes")!=null){
                            document.getElementById("jobTypes").value=
                                JobType(xmlDoc.getElementsByTagName("jobType")[0].childNodes[0].nodeValue);
                        }
                    }
                }
                if(GetXMLNode(xmlDoc, "noOfPosition", 0, 0)>0){
                    SetXMLNode(xmlDoc, "noOfPosition", 0, 0, "jobNoOfPosition");
                }
                SetXMLNode(xmlDoc, "clientName", 0, 0, "jobClientName");
                if(document.getElementById('recruitmentCompany')!=null){
                    if(GetXMLNode(xmlDoc, 'recruitmentCompany', 0, 0) == 1){
                        document.getElementById('recruitmentCompany').checked=true;
                    }
                }
                //            SetXMLNode(xmlDoc, "websiteURL", 0, 0, "jobWebsite");
                SetValue("jobDesc", ReplaceRetrievedLineBreak(GetXMLNode(xmlDoc, 'description', 0, 0)));

                if(!saveJobEduReq){
                    SetValue("jobEduReq", ReplaceRetrievedLineBreak(GetXMLNode(xmlDoc, 'educationRequirement', 0, 0)));
                }
                if(!saveJobRoleNRespon){
                    SetValue("jobRoleNRespon", ReplaceRetrievedLineBreak(GetXMLNode(xmlDoc, 'roleAndRespon', 0, 0)));
                }
                SetXMLNode(xmlDoc, "jobSalaryID", 0, 0, "jobSalaryID");

                if(document.getElementById('appApplyCounter')!=null){
                    document.getElementById('appApplyCounter').innerHTML = " (" + GetXMLNode(xmlDoc, "appCount", 0, 0) + ")";
                }
                SetValue("jobApplicantCount", GetXMLNode(xmlDoc, "appCount", 0, 0));

                if(xmlDoc.getElementsByTagName("jStatus")[0] != null){
                    if(xmlDoc.getElementsByTagName("jStatus")[0].childNodes[0] != null){
                        var jStatus = xmlDoc.getElementsByTagName("jStatus")[0].childNodes[0].nodeValue
                        if(YAHOO.util.Dom.get("jobStatusHeader")!=null){
                            YAHOO.util.Dom.get("jobStatusHeader").innerHTML = " Status: " + JobStatus(jStatus);
                        }
                        if(document.getElementById("jobStatus") != null){
                            document.getElementById("jobStatus").value = jStatus;
                        }
                        var showTable = false;
                        var display = "block";
                        if(jStatus == "1"){
                            ignoreJobValidation = false;
                            if(document.getElementById("JobStatusPostIT") != null){
                                document.getElementById("JobStatusPostIT").style.display = "block";
                            }
                        }else if(jStatus == "3"){
                            ignoreJobValidation = true;
                            if(document.getElementById("JobStatusPostIT") != null){
                                document.getElementById("JobStatusPostIT").style.display = "block";
                            }
                            showTable = true;
                            display = "none";
                        }
                        else if(jStatus == "4"){
                            ignoreJobValidation = false;
                            if(document.getElementById("JobStatusReSubmit") != null){
                                document.getElementById("JobStatusReSubmit").style.display = "block";
                            }
                        }else if(jStatus == "6"){
                            ignoreJobValidation = true;
                            if(document.getElementById("JobStatusRemove") != null){
                                setDisplay('JobApplicant','block');
                                setDisplay('jobAppTab','block');
                                document.getElementById("JobStatusRemove").style.display = "block";
                            }
                            showTable = true;
                            display = "none";
                        }else if(jStatus == "7"){
                            ignoreJobValidation = true;
                            setDisplay('JobApplicant','block');
                            setDisplay('jobAppTab','block');
                            showTable = true;
                            display = "none";
                        }
                        JobSpecsReadOnly(showTable, display);
                    }
                }
                if(GetXMLNode(xmlDoc, 'ranking', 0, 0)>0){
                    setDisplay('JobRankingIT','none');
                    setDisplay('ApplicantList','none');
                    setDisplay('ApplicantRankList','block');
                    setDisplay('JobRefreshRankingIT','block');
                }else{
                    setDisplay('JobRankingIT','block');
                    setDisplay('ApplicantList','block');
                    setDisplay('ApplicantRankList','none');
                    setDisplay('JobRefreshRankingIT','none');
                }

                //            if(document.getElementById("SaveAsBtn")!=null){
                //                document.getElementById("SaveAsBtn").style.display = "block";
                //            }
                YAHOO.util.Dom.get("jobGeneral").click();
                if(!saveJobSpec && !saveJobEduReq && !saveJobRoleNRespon &&
                    !saveJobSkillReq && !saveJobLocation && !saveJobTravel &&
                    !saveJobSalaryReq && !saveJobTag){
                    ResetJobCount();
                    ResetJobSave();
                }
                if(xmlDoc.getElementsByTagName("jobID")[0]!= null){
                    if(xmlDoc.getElementsByTagName("jobID")[0].childNodes[0] != null){
                        UpdateViewCounter(xmlDoc.getElementsByTagName("jobID")[0].childNodes[0].nodeValue);
                    }
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function setDisplay(id,display){
    if(document.getElementById(id)!=null){
        document.getElementById(id).style.display = display;
    }
}

//Save Job detail
function UpdateJobStatus()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxUpdateJobStatus.php";
    url =url+"?jobID="+document.getElementById("jobID").value;
    url =url+"&jobStatus="+document.getElementById("jobStatus").value;
    try{
        xmlhttp.onreadystatechange=UpdateJobStatusStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function UpdateJobStatusStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                var jobPosting = GetXMLNode(xmlDoc, 'jobPosting', 0, 0);
                if(jobPosting != "" && jobPosting == 0){
                    var ack = GetXMLNode(xmlDoc, 'ack', 0, 0);
                    if(ack == "Success"){
                        if(GetXMLNode(xmlDoc, 'successMsg', 0, 0) != ""){
                            alert(GetXMLNode(xmlDoc, 'successMsg', 0, 0));
                        }
                        if(GetXMLNode(xmlDoc, 'jobStatus', 0, 0) != ""){
                            var jobStatus = GetXMLNode(xmlDoc, 'jobStatus', 0, 0);
                            document.getElementById("jobStatus").value = jobStatus;
                            if(jobStatus == "Posted" || jobStatus == "Removed" || jobStatus == "Approved"){
                                JobSpecsReadOnly(true, "none");
                            }else{
                                JobSpecsReadOnly(false, "block");
                            }
                        }
                        if(GetXMLNode(xmlDoc, 'btn', 0, 0) != ""){
                            var btn = GetXMLNode(xmlDoc, 'btn', 0, 0);
                            document.getElementById("JobStatusPostIT").style.display = "none";
                            document.getElementById("JobStatusReSubmit").style.display = "none";
                            document.getElementById("JobStatusRemove").style.display = "none";
                            if(btn == "Remove"){
                                document.getElementById("JobStatusRemove").style.display = "block";
                            }
                        }
                        if(GetXMLNode(xmlDoc, 'jobID', 0, 0) != ""){
                            RetrieveJobDetail(GetXMLNode(xmlDoc, 'jobID', 0, 0));
                        }
                    }
                    else{
                        if(GetXMLNode(xmlDoc, 'failMsg', 0, 0) != ""){
                            alert(GetXMLNode(xmlDoc, 'failMsg', 0, 0));
                        }
                    }
                    document.getElementById("refreshJobList").click();
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//validate job detail
function validateJob(){
    document.getElementById("jobGeneral").click();
    if(validate("jobTitle", "", "Please enter job title.")){
        if(validate("jobReferenceNo", "", "Please enter job reference number.")){
            if(document.getElementById("jobYrOfExp").value!="" &&
                !isInteger(document.getElementById("jobYrOfExp").value)){
                alert("Please enter the number of year experience in numeric only.");
                return false;
            }
            if(document.getElementById("jobPostingDay").value!="dd" ||
                document.getElementById("jobPostingMth").value!="Jan" ||
                document.getElementById("jobPostingYr").value!="yyyy" ){
                if(!validate("jobPostingDay", "dd", "Please enter posting day in (dd) format.") ||
                    !validate("jobPostingDay", "", "Please enter posting day in (dd) format.") ||
                    !validate("jobPostingMth", "", "Please select a posting month.") ||
                    !validate("jobPostingYr", "yyyy", "Please enter a posting year in (yyyy) format.") ||
                    !validate("jobPostingYr", "", "Please enter a posting year in (yyyy) format.") ||
                    !validateDate("jobPostingDay", "jobPostingMth", "jobPostingYr", "jobPostingDate")){
                    return false;
                }
            }
            if(document.getElementById("jobClosingDay").value!="dd" ||
                document.getElementById("jobClosingMth").value!="Jan" ||
                document.getElementById("jobClosingYr").value!="yyyy" ){
                if(!validate("jobClosingDay", "dd", "Please enter closing day in (dd) format.") ||
                    !validate("jobClosingDay", "", "Please enter closing day in (dd) format.") ||
                    !validate("jobClosingMth", "", "Please select a closing month.") ||
                    !validate("jobClosingYr", "yyyy", "Please enter a closing year in (yyyy) format.") ||
                    !validate("jobClosingYr", "", "Please enter a closing year in (yyyy) format.") ||
                    !validateDate("jobClosingDay", "jobClosingMth", "jobClosingYr", "jobClosingDate")){
                    return false;
                }
            }
            if(document.getElementById("jobPostingDay").value!="dd" || document.getElementById("jobPostingMth").value!="Jan" ||
                document.getElementById("jobPostingYr").value!="yyyy"  ||  document.getElementById("jobClosingDay").value!="dd" ||
                document.getElementById("jobClosingMth").value!="Jan" || document.getElementById("jobClosingYr").value!="yyyy" ){
                if(!CompareDates(document.getElementById("jobPostingDate").value, document.getElementById("jobClosingDate").value,
                "Closing date must be later than Posting date.")){
                    return false;
                }

            }
            if(document.getElementById("jobNoOfPosition").value!="" && !isInteger(document.getElementById("jobNoOfPosition").value)){
                alert("Please enter the number of position in number format.");
                document.getElementById("jobNoOfPosition").focus();
                return false;
            }else if(document.getElementById("jobNoOfPosition").value!="" && document.getElementById("jobNoOfPosition").value<=0){
                alert("Number of job positions must be at least 1.");
                document.getElementById("jobNoOfPosition").focus();
                return false;
            }
            return true;
        }
    }
    return false;
}

function validatePostItJob(){
    document.getElementById("jobGeneral").click();
    if(validate("jobTitle", "", "Please enter job title.")){
        if(validate("jobReferenceNo", "", "Please enter job reference number.")){
            if(!isInteger(document.getElementById("jobYrOfExp").value)){
                alert("Please enter the number of year experience in number format.");
                return false;
            }
            if(!validate("jobPostingDay", "dd", "Please enter posting day in (dd) format.") ||
                !validate("jobPostingDay", "", "Please enter posting day in (dd) format.") ||
                !validate("jobPostingMth", "", "Please select a posting month.") ||
                !validate("jobPostingYr", "yyyy", "Please enter a posting year in (yyyy) format.") ||
                !validate("jobPostingYr", "", "Please enter a posting year in (yyyy) format.") ||
                !validateDate("jobPostingDay", "jobPostingMth", "jobPostingYr", "jobPostingDate")){
                return false;
            }
            if(!validate("jobClosingDay", "dd", "Please enter closing day in (dd) format.") ||
                !validate("jobClosingDay", "", "Please enter closing day in (dd) format.") ||
                !validate("jobClosingMth", "", "Please select a closing month.") ||
                !validate("jobClosingYr", "yyyy", "Please enter a closing year in (yyyy) format.") ||
                !validate("jobClosingYr", "", "Please enter a closing year in (yyyy) format.") ||
                !validateDate("jobClosingDay", "jobClosingMth", "jobClosingYr", "jobClosingDate")){
                return false;
            }

            if(!isInteger(document.getElementById("jobNoOfPosition").value)){
                alert("Please enter the number of position in number format.");
                document.getElementById("jobNoOfPosition").focus();
                return false;
            }else if(document.getElementById("jobNoOfPosition").value<=0){
                alert("Number of job positions must be at least 1.");
                document.getElementById("jobNoOfPosition").focus();
                return false;
            }
            return true;
        }
    }
    return false;
}

//##############################################################################
//##############################################################################
//Save Job education requirement
function SaveJobEduReq()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobEduReq.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url =url+"&educationRequirement="+ReplaceLineBreak(document.getElementById("jobEduReq").value);
        url =url+"&SaveJobEduReq="+document.getElementById("SaveJobEduReq").value;
        try{
            xmlhttp.onreadystatechange=SaveJobEduReqStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }else{
        if(validateJob()){
            SaveJob();
        }
    }
}
function SaveJobEduReqStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!jobSaveAll){
                if(xmlhttp.responseText == "1"){
                    alert("Job specification saved successfully.");
                }
                else{
                    alert("Save Job Failed. Please try again.");
                }
            }
            if(xmlhttp.responseText == "1"){
                saveJobEduReq = false;
                RetrieveJobEduReq();
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve Job education requirement
function RetrieveJobEduReq(){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobdetail.php";
    url =url+"?jobID="+document.getElementById('jobID').value;
    try{
        xmlhttp.onreadystatechange=RetrieveJobEduReqStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function RetrieveJobEduReqStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("jobEduReq", "");
                SetValue("jobEduReq", ReplaceRetrievedLineBreak(GetXMLNode(xmlDoc, 'educationRequirement', 0, 0)));
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//save job education requirement check
function sjerc(){
    if(!saveJobEduReq){
        saveJobEduReq = true;
    }
}

//job education requirement tab
function rjer(){
    if(jobEducationTabCount == 0){
        showJobTab("education");
    }
}

//validate job education requirement
function validateJobEduReq(){
    document.getElementById("jobEduTab").click();
    return validate("jobEduReq", "", "Please enter Job Education Requirement.");
}

//##############################################################################
//##############################################################################
//Save Job role and responsibility
function SaveJobRoleNRespon()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobRoleNRespon.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url =url+"&roleAndResponsibility="+ReplaceLineBreak(document.getElementById("jobRoleNRespon").value);
        url =url+"&SaveJobRoleNRespon="+document.getElementById("SaveJobRoleNRespon").value;
        try{
            xmlhttp.onreadystatechange=SaveJobRoleNResponStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }else{
        if(validateJob()){
            SaveJob();
        }
    }

}
function SaveJobRoleNResponStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!jobSaveAll){
                if(xmlhttp.responseText == "1"){
                    alert("Job specification saved successfully.");
                }else{
                    alert("Save Job Failed. Please try again.");
                }
            }
            if(xmlhttp.responseText == "1"){
                saveJobRoleNRespon = false;
                RetrieveJobRoleNRespon();
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//retrieve Job role and responsibility
function RetrieveJobRoleNRespon(){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobdetail.php";
    url =url+"?jobID="+document.getElementById('jobID').value;
    try{
        xmlhttp.onreadystatechange=RetrieveJobRoleNResponStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function RetrieveJobRoleNResponStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("jobRoleNRespon", "");
                SetValue("jobRoleNRespon", ReplaceRetrievedLineBreak(GetXMLNode(xmlDoc, 'roleAndRespon', 0, 0)));
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//save job role and responsibility check
function sjrrc(){
    if(!saveJobRoleNRespon){
        saveJobRoleNRespon = true;
    }
}

//job role and responsibility
function rjrr(){
    if(jobResponseTabCount == 0){
        showJobTab('response');
    }
}

//validate job role and responsibility
function validateJobResponse(){
    document.getElementById("jobResTab").click();
    return validate("jobRoleNRespon", "", "Please enter Job Roles and Responsibility.");
}


//##############################################################################
//##############################################################################
//Save Job skill requirement
function SaveJobSkillReq()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobSkillReq.php";
        url = url+"?jobID="+document.getElementById("jobID").value;
        url = url+"&jobSkillReqCount="+skillReqList.length;
        for(var i=0; i<skillReqList.length; i++)
        {
            var skillReq = skillReqList[i];
            url = url+"&skillReqName"+(i+1)+"="+skillReq.name;
            url = url+"&skillReqPriority"+(i+1)+"="+skillReq.priority;
            url = url+"&skillReqRating"+(i+1)+"="+skillReq.level;

        }
        url = url+"&SaveJobSkillReq="+document.getElementById("SaveJobSkillReq").value;
        try{
            xmlhttp.onreadystatechange=SaveJobSkillReqStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }else{
        if(validateJob()){
            SaveJob();
        }
    }
}
function SaveJobSkillReqStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!jobSaveAll){
                if(xmlhttp.responseText == "1"){
                    alert("Job specification saved successfully.");
                }else{
                    alert("Save Job Failed. Please try again.");
                }
            }
            if(xmlhttp.responseText == "1"){
                saveJobSkillReq = false;
                if(!ignoreSkillReqCheck){
                    if(skillReqList.length<jobSkillReqCount){
                        alert("It is recommended that you should have more than "+jobSkillReqCount
                            +" competencies in order to improve the accuracy of the ranking. Please enter more competencies.");
                    }
                }else{
                    ignoreSkillReqCheck = false;
                }
                RetrieveSkillRequirement();
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}
//retrieve job skill requirement
function RetrieveSkillRequirement()
{
    showJobTab("skill");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobskillrequirement.php";
    url =url+"?jobID="+document.getElementById("jobID").value;
    url =url+"&skillReqCounter="+document.getElementById("jobSkillReqCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveSkillRequirementStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveSkillRequirementStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                skillReqList = new Array();
                var index=0;
                var count = GetXMLNode(xmlDoc, "skillCount", 0, 0);
                while(index<count){
                    //var skillNo = GetXMLNode(xmlDoc, "skillNo", index, 0);
                    var name = GetXMLNode(xmlDoc, "title", index, 0);
                    var priority = GetXMLNode(xmlDoc, "priority", index, 0);
                    var level = GetXMLNode(xmlDoc, "level", index, 0);
                    var skillReq = new SkillRequirement(name, priority, level);
                    skillReqList[index] = skillReq;
                    index++;
                }
                YAHOO.util.Dom.get("jobSkillReqCounter").value=8;
                addSkillRow(1, "skillReqNo", "skillReqName", "skillReqPriority", "skillReqRating", "skillReqForm");
                for(var i = 0; i < 7; i++) {
                    skillReq =  skillReqList[i];
                    if(skillReq){
                        var skillReqName = "skillReqName" + parseInt(i+1);
                        var skillReqPriority = "skillReqPriority" + parseInt(i+1);
                        var skillReqRating = "skillReqRating" + parseInt(i+1);
                        document.getElementById(skillReqName).value = skillReq.name;
                        document.getElementById(skillReqPriority).value = skillReq.priority;
                        for(ind=0; ind < document['forms']['skillRequirementForm'][skillReqRating].length; ind++){
                            if(document['forms']['skillRequirementForm'][skillReqRating][ind].value == skillReq.level)
                                document['forms']['skillRequirementForm'][skillReqRating][ind].checked = true;
                        }
                    }
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rsr(){
    if(jobSkillTabCount == 0){
        RetrieveSkillRequirement();
    }
}

//save job skill requirement check
function sjsrc(){
    if(!saveJobSkillReq){
        saveJobSkillReq = true;
    }
}

//update skill requirement list
function UpdateSkillReqList(){
    var count = parseInt(document.getElementById('jobSkillReqCounter').value-8);
    for(var no = 0; no<7; no++){
        var skillNameID = "skillReqName"+(no+1);
        var priorityID = "skillReqPriority"+(no+1);
        var ratingID = "skillReqRating"+(no+1);

        var skillReq = skillReqList[count];
        if(skillReq){
            skillReq.name = document.getElementById(skillNameID).value;
            skillReq.priority = document.getElementById(priorityID).value;
            for(var ind=0; ind < document["forms"]["skillReqForm"][ratingID].length; ind++){
                if(document["forms"]["skillReqForm"][ratingID][ind].checked){
                    skillReq.level = document["forms"]["skillReqForm"][ratingID][ind].value;
                    break;
                }
            }
            skillReqList[count] = skillReq;
            count++;
        }else{
            if(document.getElementById(skillNameID).value!="" && document.getElementById(priorityID).value!=0){
                var name = document.getElementById(skillNameID).value;
                var priority = document.getElementById(priorityID).value;
                for(ind=0; ind < document["forms"]["skillReqForm"][ratingID].length; ind++){
                    if(document["forms"]["skillReqForm"][ratingID][ind].checked){
                        var level = document["forms"]["skillReqForm"][ratingID][ind].value;
                        break;
                    }
                }
                var skillReqTemp = new SkillRequirement(name, priority, level);
                skillReqList[count] = skillReqTemp;
                count++;
            }
        }
    }
}

//delete skill requirement row by index
function DeleteSkillReqRow(skillNoID){
    UpdateSkillReqList();
    var skillNo = parseInt(document.getElementById(skillNoID).innerHTML)-1;
    skillReqList.splice(skillNo, 1);
    alert("Skill requirement deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("jobSkillReqCounter").value - 7);
    DisplaySkillReq(counter);
}

//display skill requirement from list
function DisplaySkillReq(counter){
    addSkillRow(counter, "skillReqNo", "skillReqName", "skillReqPriority", "skillReqRating", "skillReqForm");
    for (var i = 0; i < 7; i++) {
        var skillReq =  skillReqList[counter-1];
        if(skillReq){
            var skillReqName = "skillReqName" + (i+1);
            var skillReqPriority = "skillReqPriority" + (i+1);
            var skillReqRating = "skillReqRating" + (i+1);
            document.getElementById(skillReqName).value = skillReq.name;
            document.getElementById(skillReqPriority).value = skillReq.priority;
            for(var ind=0; ind < document['forms']['skillRequirementForm'][skillReqRating].length; ind++){
                if(document['forms']['skillRequirementForm'][skillReqRating][ind].value == skillReq.level)
                    document['forms']['skillRequirementForm'][skillReqRating][ind].checked = true;
            }

            counter++;
        }else{
            break;
        }
    }
}

function validateJobSkillDuplicate(){
    var result = false;
    if(skillReqList.length>0){
        for(var i=0;i<skillReqList.length;i++){
            var skillReq = skillReqList[i];
            for(var ind=0;ind<skillReqList.length;ind++){
                var nextSkillReq = skillReqList[ind];
                if(i != ind){
                    if(skillReq.name == nextSkillReq.name){
                        alert("Please enter a unique record. Do not create duplicate.");
                        result = false;
                        break;
                    }else{
                        result = true;
                    }
                }else{
                    result = true;
                }
            }
            if(!result){
                break;
            }
        }
    }else{
        result = true;
    }
    return result;
}

//validate job skill requirement
function validateJobSkillReq(){
    var result = false;
    document.getElementById("jobSkillTab").click();
    var checkEmptyID = 0;
    for(var i=1; i<8; i++){
        var skillNameID = "skillReqName" + i + "";
        var skillPriorityID = "skillReqPriority" + i + "";
        var form = "skillReqForm";
        var radioID = "skillReqRating" + i + "";
        if(document.getElementById(skillNameID).value != "" || document.getElementById(skillPriorityID).value != "0" || validateRadio(form, radioID)){
            if(validate(skillNameID, "", "Please enter the job skill requirement.")){
                if(validate(skillPriorityID, "0", "Please select the priority of this job skill requirement.")){
                    if(validateRadio(form, radioID)){
                        if(checkEmptyID>0){
                            skillNameID = "skillReqName" + checkEmptyID + "";
                            document.getElementById(skillNameID).focus();
                            alert("Please do not leave empty field in between.");
                            result = false;
                        }else{
                            result = true;
                        }
                    }else{
                        alert("Please select a rating for this skill requirement.");
                        result = false;
                        break;
                    }
                }
                else{
                    result = false;
                    break;
                }
            }
            else{
                result = false;
                break;
            }
        }else{
            if(checkEmptyID==0){
                checkEmptyID = i;
            }
            result = true;
        }
    }

    return result;
}
//end of skill requirement

//##############################################################################
//##############################################################################
//Save Job skill requirement
function SaveJobLocation()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobLocation.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url = url+"&jobLocationCount="+jobLocationList.length;
        for(var i=0; i<jobLocationList.length; i++)
        {
            var jobLocation = jobLocationList[i];
            url = url+"&jobLocationCity"+(i+1)+"="+jobLocation.city;
            url = url+"&jobLocationState"+(i+1)+"="+jobLocation.state;
            url = url+"&jobLocationCountry"+(i+1)+"="+jobLocation.country;
        }
        url =url+"&SaveJobLocation="+document.getElementById("SaveJobLocation").value;
        try{
            xmlhttp.onreadystatechange=SaveJobLocationStateChanged;
            xmlhttp.open("GET",url,false);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
    else{
        if(validateJob()){
            SaveJob();
        }
    }
}
function SaveJobLocationStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!jobSaveAll){
                if(xmlhttp.responseText == "1"){
                    alert("Job specification saved successfully.");
                }
                else{
                    alert("Save Job Failed. Please try again.");
                }
            }
            if(xmlhttp.responseText == "1"){
                saveJobLocation = false;
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//save job location check
function sjlc(){
    if(!saveJobLocation){
        saveJobLocation = true;
    }
}

//retrieve job location
function RetrieveJobLocation()
{
    showJobTab("location");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejoblocation.php";
    url =url+"?jobID="+document.getElementById("jobID").value;
    url =url+"&jobLocationCounter="+document.getElementById("jobLocationCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveJobLocationStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveJobLocationStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                for(var i=1; i<8; i++){
                    var city = "jobLocationCity" + i;
                    document.getElementById(city).value="";
                    var state = "jobLocationState" + i;
                    document.getElementById(state).value="";
                    var country = "jobLocationCountry" + i;
                    document.getElementById(country).value="";
                }
                var index=0;
                while(index<7){
                    var jobLocationNo = "jobLocationNo" + (index+1);
                    if(xmlDoc.getElementsByTagName("locationNo")[index]!= null){
                        if(xmlDoc.getElementsByTagName("locationNo")[index].childNodes[0] != null){
                            var locationNo = xmlDoc.getElementsByTagName("locationNo")[index].childNodes[0].nodeValue;
                            if(document.getElementById(jobLocationNo).innerHTML == locationNo){
                                SetMultipleXMLNode(xmlDoc, "city", index, "jobLocationCity");
                                SetMultipleXMLNode(xmlDoc, "state", index, "jobLocationState");
                                SetMultipleXMLNode(xmlDoc, "country", index, "jobLocationCountry");
                            }
                        }
                    }
                    index++;
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rjl(){
    if(jobLocationTabCount == 0){
        RetrieveJobLocation();
    }
}

function rjll(){
    if(jobLocationTabCount == 0){
        jobLocationTabCount = 1;
        document.getElementById("refreshLocationList").click();
    }
}

//update job location list
function UpdateJobLocationList(){
    var count = parseInt(document.getElementById('jobLocationCounter').value-8);
    for(var no = 0; no<7; no++){
        var jobLocationCityID = "jobLocationCity"+(no+1);
        var jobLocationStateID = "jobLocationState"+(no+1);
        var jobLocationCountryID = "jobLocationCountry"+(no+1);

        var jobLocation = jobLocationList[count];
        if(jobLocation){
            jobLocation.city = document.getElementById(jobLocationCityID).value;
            jobLocation.state = document.getElementById(jobLocationStateID).value;
            jobLocation.country = document.getElementById(jobLocationCountryID).value;
            jobLocationList[count] = jobLocation;
            count++;
        }else{
            if(document.getElementById(jobLocationCountryID).value!=""){
                var city = document.getElementById(jobLocationCityID).value;
                var state = document.getElementById(jobLocationStateID).value;
                var country = document.getElementById(jobLocationCountryID).value;
                var jobLocationTemp = new JobLocation(city, state, country);
                jobLocationList[count] = jobLocationTemp;
                count++;
            }
        }
    }
}

//delete job location row by index
function DeleteJobLocationRow(noID){
    UpdateJobLocationList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    jobLocationList.splice(no, 1);
    alert("Job location record deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("jobLocationCounter").value - 7);
    DisplayJobLocation(counter);
}

//display job location from list
function DisplayJobLocation(counter){
    addLocationRow(counter, "jobLocationNo", "jobLocationCity", "jobLocationState", "jobLocationCountry");
    for (var i = 0; i < 7; i++) {
        var jobLocation =  jobLocationList[counter-1];
        if(jobLocation){
            var jobLocationCityID = "jobLocationCity"+(i+1);
            var jobLocationStateID = "jobLocationState"+(i+1);
            var jobLocationCountryID = "jobLocationCountry"+(i+1);
            document.getElementById(jobLocationCityID).value = jobLocation.city;
            document.getElementById(jobLocationStateID).value = jobLocation.state;
            document.getElementById(jobLocationCountryID).value = jobLocation.country;
            counter++;
        }else{
            break;
        }
    }
}

function validateJobLocationDuplicate(){
    var result = false;
    if(jobLocationList.length>0){
        for(var i=0;i<jobLocationList.length;i++){
            var jobLocation = jobLocationList[i];
            for(var ind=0;ind<jobLocationList.length;ind++){
                var nextJobLocation = jobLocationList[ind];
                if(i != ind){
                    if(jobLocation.country == nextJobLocation.country){
                        alert("Please enter a unique record. Do not create duplicate.");
                        result = false;
                        break;
                    }else{
                        result = true;
                    }
                }else{
                    result = true;
                }
            }
            if(!result){
                break;
            }
        }
    }else{
        result = true;
    }
    return result;
}

//validate location
function validateLocation(cityID, stateID, countryID, tabID){
    document.getElementById(tabID).click();
    var result = true;
    for(var i=1; i<=7; i++){
        var city = cityID + i;
        var state = stateID + i;
        var country = countryID + i;
        if(document.getElementById(city).value!="" || document.getElementById(state).value!="" || document.getElementById(country).value!=""){
            if(!validateText(country, "", "Please select a country")){
                result = false;
                break;
            }
        }
    }
    return result;
}

//##############################################################################
//##############################################################################
//Save Job travel requirement
function SaveJobTravel()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobTravel.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url = url+"&jobTravelCount="+jobTravelList.length;
        for(var i=0; i<jobTravelList.length; i++)
        {
            var jobTravel = jobTravelList[i];
            url = url+"&jobTravelCity"+(i+1)+"="+jobTravel.city;
            url = url+"&jobTravelState"+(i+1)+"="+jobTravel.state;
            url = url+"&jobTravelCountry"+(i+1)+"="+jobTravel.country;
        }
        url =url+"&SaveJobTravel="+document.getElementById("SaveJobTravel").value;
        try{
            xmlhttp.onreadystatechange=SaveJobTravelStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }else{
        if(validateJob()){
            SaveJob();
        }
    }
}
function SaveJobTravelStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!jobSaveAll){
                if(xmlhttp.responseText == "1"){
                    alert("Job specification saved successfully.");
                }else{
                    alert("Save Job Failed. Please try again.");
                }
            }
            if(xmlhttp.responseText == "1"){
                saveJobTravel = false;
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//save job travel check
function sjtc(){
    if(!saveJobTravel){
        saveJobTravel = true;
    }
}

//retrieve job travel requirement
function RetrieveJobTravel()
{
    showJobTab("travel");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobtravel.php";
    url =url+"?jobID="+document.getElementById("jobID").value;
    url =url+"&jobTravelCounter="+document.getElementById("jobTravelCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveJobTravelStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveJobTravelStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                for(var i=1; i<8; i++){
                    var city = "jobTravelCity" + i;
                    document.getElementById(city).value="";
                    var state = "jobTravelState" + i;
                    document.getElementById(state).value="";
                    var country = "jobTravelCountry" + i;
                    document.getElementById(country).value="";
                }
                var index=0;
                while(index<7){
                    var jobTravelNo = "jobTravelNo" + (index+1);
                    if(xmlDoc.getElementsByTagName("travelNo")[index]!= null){
                        if(xmlDoc.getElementsByTagName("travelNo")[index].childNodes[0] != null){
                            var travelNo = xmlDoc.getElementsByTagName("travelNo")[index].childNodes[0].nodeValue;
                            if(document.getElementById(jobTravelNo).innerHTML == travelNo){
                                SetMultipleXMLNode(xmlDoc, "city", index, "jobTravelCity");
                                SetMultipleXMLNode(xmlDoc, "state", index, "jobTravelState");
                                SetMultipleXMLNode(xmlDoc, "country", index, "jobTravelCountry");
                            }
                        }
                    }
                    index++;
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rjt(){
    if(jobTagTabCount == 0){
        RetrieveJobTravel();
    }
}

function rjtl(){
    if(jobTagTabCount == 0){
        jobTagTabCount = 1;
        document.getElementById("refreshTravelList").click();
    }
}

//update job Travel list
function UpdateJobTravelList(){
    var count = parseInt(document.getElementById('jobTravelCounter').value-8);
    for(var no = 0; no<7; no++){
        var jobTravelCityID = "jobTravelCity"+(no+1);
        var jobTravelStateID = "jobTravelState"+(no+1);
        var jobTravelCountryID = "jobTravelCountry"+(no+1);

        var jobTravel = jobTravelList[count];
        if(jobTravel){
            jobTravel.city = document.getElementById(jobTravelCityID).value;
            jobTravel.state = document.getElementById(jobTravelStateID).value;
            jobTravel.country = document.getElementById(jobTravelCountryID).value;
            jobTravelList[count] = jobTravel;
            count++;
        }else{
            if(document.getElementById(jobTravelCountryID).value!=""){
                var city = document.getElementById(jobTravelCityID).value;
                var state = document.getElementById(jobTravelStateID).value;
                var country = document.getElementById(jobTravelCountryID).value;
                var jobTravelTemp = new TravelRequirement(city, state, country);
                jobTravelList[count] = jobTravelTemp;
                count++;
            }
        }
    }
}

//delete job Travel row by index
function DeleteJobTravelRow(noID){
    UpdateJobTravelList();
    var no = parseInt(document.getElementById(noID).innerHTML)-1;
    jobTravelList.splice(no, 1);
    alert("Job travel requirement record deleted.");
    var counter = parseInt(YAHOO.util.Dom.get("jobTravelCounter").value - 7);
    DisplayJobTravel(counter);
}

function validateJobTravelDuplicate(){
    var result = false;
    if(jobTravelList.length>0){
        for(var i=0;i<jobTravelList.length;i++){
            var jobTravel = jobTravelList[i];
            for(var ind=0;ind<jobTravelList.length;ind++){
                var nextJobTravel = jobTravelList[ind];
                if(i != ind){
                    if(jobTravel.country == nextJobTravel.country){
                        alert("Please enter a unique record. Do not create duplicate.");
                        result = false;
                        break;
                    }else{
                        result = true;
                    }
                }else{
                    result = true;
                }
            }
            if(!result){
                break;
            }
        }
    }else{
        result = true;
    }
    return result;
}

//display job Travel from list
function DisplayJobTravel(counter){
    addLocationRow(counter, "jobTravelNo", "jobTravelCity", "jobTravelState", "jobTravelCountry");
    for (var i = 0; i < 7; i++) {
        var jobTravel =  jobTravelList[counter-1];
        if(jobTravel){
            var jobTravelCityID = "jobTravelCity"+(i+1);
            var jobTravelStateID = "jobTravelState"+(i+1);
            var jobTravelCountryID = "jobTravelCountry"+(i+1);
            document.getElementById(jobTravelCityID).value = jobTravel.city;
            document.getElementById(jobTravelStateID).value = jobTravel.state;
            document.getElementById(jobTravelCountryID).value = jobTravel.country;
            counter++;
        }else{
            break;
        }
    }
}

//##############################################################################
//##############################################################################
//Save Job Salary
function SaveJobSalary()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobSalary.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url =url+"&jobSalaryID="+document.getElementById("jobSalaryID").value;
        url =url+"&hourlyCurrency="+document.getElementById("JSBHrCurrency").value;
        url =url+"&hourlyFrom="+document.getElementById("JSBHrFrom").value;
        url =url+"&hourlyUpTo="+document.getElementById("JSBHrTo").value;
        url =url+"&dailyCurrency="+document.getElementById("JSBDayCurrency").value;
        url =url+"&dailyFrom="+document.getElementById("JSBDayFrom").value;
        url =url+"&dailyUpTo="+document.getElementById("JSBDayTo").value;
        url =url+"&monthlyCurrency="+document.getElementById("JSBMthCurrency").value;
        url =url+"&monthlyFrom="+document.getElementById("JSBMthFrom").value;
        url =url+"&monthlyUpTo="+document.getElementById("JSBMthTo").value;
        url =url+"&yearlyCurrency="+document.getElementById("JSBYrCurrency").value;
        url =url+"&yearlyFrom="+document.getElementById("JSBYrFrom").value;
        url =url+"&yearlyUpTo="+document.getElementById("JSBYrTo").value;

        url =url+"&commission="+getSelectedRadioBtnValue("jobSalaryForm", "JSCommissionRadio");
        url =url+"&shareOption="+getSelectedRadioBtnValue("jobSalaryForm", "JSShareOptionRadio");
        url =url+"&car="+getSelectedRadioBtnValue("jobSalaryForm", "JSCarRadio");
        url =url+"&bonus="+getSelectedRadioBtnValue("jobSalaryForm", "JSBonusRadio");
        url =url+"&accomodation="+getSelectedRadioBtnValue("jobSalaryForm", "JSAccomodationRadio");
        url =url+"&relocationBenefit="+getSelectedRadioBtnValue("jobSalaryForm", "JSRelocationBenefitsRadio");
        url =url+"&SaveJobSalary="+document.getElementById("SaveJobSalary").value;
        try{
            xmlhttp.onreadystatechange=SaveJobSalaryStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        }
        catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }else{
        if(validateJob()){
            SaveJob();
        }
    }
}
function SaveJobSalaryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                if(xmlDoc.getElementsByTagName("jobSalaryID")[0]!= null){
                    if(xmlDoc.getElementsByTagName("jobSalaryID")[0].childNodes[0] != null){
                        document.getElementById('jobSalaryID').value =
                            xmlDoc.getElementsByTagName("jobSalaryID")[0].childNodes[0].nodeValue;
                    }
                }
                if(!jobSaveAll){
                    showXMLNodeAlert(xmlDoc, "JSSuccess", 0, 0, true);
                    showXMLNodeAlert(xmlDoc, "JSFail", 0, 0, true);
                }
            }

        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//save job salary requirement check
function sjsalaryrc(){
    if(!saveJobSalaryReq){
        saveJobSalaryReq = true;
    }
}

//retrieve job skill requirement
function RetrieveJobSalary()
{
    showJobTab("salary");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobsalary.php";
    url =url+"?jobSalaryID="+document.getElementById("jobSalaryID").value;
    url =url+"&retrieveJobSalary=retrieveJobSalary";
    try{
        xmlhttp.onreadystatechange=RetrieveJobSalaryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveJobSalaryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("JSBHrCurrency", "");
                SetValue("JSBHrFrom", "");
                SetValue("JSBHrTo", "");
                SetValue("JSBDayCurrency", "");
                SetValue("JSBDayFrom", "");
                SetValue("JSBDayTo", "");
                SetValue("JSBMthCurrency", "");
                SetValue("JSBMthFrom", "");
                SetValue("JSBMthTo", "");
                SetValue("JSBYrCurrency", "");
                SetValue("JSBYrFrom", "");
                SetValue("JSBYrTo", "");

                var optionID = ["JSCarRadio", "JSAccomodationRadio", "JSRelocationBenefitsRadio",
                    "JSCommissionRadio", "JSBonusRadio", "JSShareOptionRadio"];

                for(var i=0;i<optionID.length;i++){
                    for(var ind=0; ind < document["forms"]["jobSalaryForm"][optionID[i]].length; ind++){
                        document["forms"]["jobSalaryForm"][optionID[i]][ind].checked = false;
                    }
                }
                //start retrieving
                var noOfJobSalaryRate = 0;
                if(xmlDoc.getElementsByTagName("noOfJobSalaryRate")[0]!= null){
                    if(xmlDoc.getElementsByTagName("noOfJobSalaryRate")[0].childNodes[0] != null){
                        noOfJobSalaryRate = xmlDoc.getElementsByTagName("noOfJobSalaryRate")[0].childNodes[0].nodeValue;
                    }
                }
                var index=0;
                while(index < noOfJobSalaryRate){
                    if(xmlDoc.getElementsByTagName("rateType")[index]!= null){
                        if(xmlDoc.getElementsByTagName("rateType")[index].childNodes[0] != null){
                            var rateType = xmlDoc.getElementsByTagName("rateType")[index].childNodes[0].nodeValue;
                            var type = getRateType(rateType);
                            if(type!=""){
                                SetXMLNode(xmlDoc, "currency", index, 0, "JSB"+type+"Currency");
                                SetPriceXMLNode(xmlDoc, "rateFrom", index, 0, "JSB"+type+"From");
                                SetPriceXMLNode(xmlDoc, "upTo", index, 0, "JSB"+type+"To");
                            }
                        }
                    }
                    index++;
                }
                var optionNameTag = ["car", "accomodation", "relocationBenefits", "commission",
                    "bonus", "shareOption"];
                for(i=0;i<optionNameTag.length;i++){
                    if(xmlDoc.getElementsByTagName(optionNameTag[i])[0]!= null){
                        if(xmlDoc.getElementsByTagName(optionNameTag[i])[0].childNodes[0] != null){
                            for(ind=0; ind < document["forms"]["jobSalaryForm"][optionID[i]].length; ind++){
                                if(document["forms"]["jobSalaryForm"][optionID[i]][ind].value == xmlDoc.getElementsByTagName(optionNameTag[i])[0].childNodes[0].nodeValue){
                                    document["forms"]["jobSalaryForm"][optionID[i]][ind].checked = true;
                                }
                            }
                        }
                    }
                }
            
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rjs(){
    if(jobSalaryTabCount == 0){
        RetrieveJobSalary();
    }
}

function RetrieveDisplayJobSalary()
{
    showJobTab("salary");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobsalary.php";
    url =url+"?jobSalaryID="+document.getElementById("jobSalaryID").value;
    url =url+"&retrieveJobSalary=retrieveJobSalary";
    try{
        xmlhttp.onreadystatechange=RetrieveDisplayJobSalaryStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveDisplayJobSalaryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                var optionID = ["carBenefits", "accomodationBenefits", "relocationBenefits", "commissionOthers",
                    "bonusOthers", "shareOptionOthers"];
                SetInnerValue("HrSalary", "Unspecified");
                SetInnerValue("DaySalary", "Unspecified");
                SetInnerValue("MthSalary", "Unspecified");
                SetInnerValue("YrSalary", "Unspecified");
                for(var i=0;i<optionID.length;i++){
                    SetInnerValue(optionID[i], "Unspecified");
                }

                //start retrieving
                var noOfJobSalaryRate = 0;
                if(xmlDoc.getElementsByTagName("noOfJobSalaryRate")[0]!= null){
                    if(xmlDoc.getElementsByTagName("noOfJobSalaryRate")[0].childNodes[0] != null){
                        noOfJobSalaryRate = xmlDoc.getElementsByTagName("noOfJobSalaryRate")[0].childNodes[0].nodeValue;
                    }
                }
                var index=0;
                while(index < noOfJobSalaryRate){
                    if(xmlDoc.getElementsByTagName("rateType")[index]!= null){
                        if(xmlDoc.getElementsByTagName("rateType")[index].childNodes[0] != null){
                            var rateType = xmlDoc.getElementsByTagName("rateType")[index].childNodes[0].nodeValue;
                            var type = getRateType(rateType);
                            if(type!=""){
                                var currency = GetXMLNode(xmlDoc, "currency", index, 0);
                                var id = type+"Salary";
                                if(currency!=""){
                                    var from = GetPriceXMLNode(xmlDoc, "rateFrom", index, 0);
                                    var to = GetPriceXMLNode(xmlDoc, "upTo", index, 0);
                                    document.getElementById(id).innerHTML =currency + " $" + from + " to $"+ to;
                                }else{
                                    document.getElementById(id).innerHTML = "Unspecified";
                                }
                            }
                        }
                    }
                    index++;
                }
                var optionNameTag = ["car", "accomodation", "relocationBenefits", "commission",
                    "bonus", "shareOption"];
                for(i=0;i<optionNameTag.length;i++){
                    if(xmlDoc.getElementsByTagName(optionNameTag[i])[0]!= null){
                        if(xmlDoc.getElementsByTagName(optionNameTag[i])[0].childNodes[0] != null){
                            document.getElementById(optionID[i]).innerHTML =
                                Benefits(xmlDoc.getElementsByTagName(optionNameTag[i])[0].childNodes[0].nodeValue);
                        }
                    }
                }

            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function Benefits(no){
    if(no == 1){
        return "Yes";
    }else if(no == 2){
        return "No";
    }else if(no == 3){
        return "N/A";
    }
    return "Unspecified";
}

function rjsl(){
    if(jobSalaryTabCount == 0){
        jobSalaryTabCount = 1;
        RetrieveDisplayJobSalary();
    }
}

//get rate type
function getRateType(rateType){
    var type = "";
    if(rateType == "1"){
        type = "Hr";
    }else if(rateType == "2"){
        type = "Day";
    }else if(rateType == "3"){
        type = "Mth";
    }else if(rateType == "4"){
        type = "Yr";
    }
    return type;
}

//validate job salary
function validateJobSalary(){
    document.getElementById("jobSalaryJTab").click();
    if(validateJobSalaryRate("JSBHrCurrency", "JSBHrFrom", "JSBHrTo", "hourly") &&
        validateJobSalaryRate("JSBDayCurrency", "JSBDayFrom", "JSBDayTo", "daily") &&
        validateJobSalaryRate("JSBMthCurrency", "JSBMthFrom", "JSBMthTo", "monthly") &&
        validateJobSalaryRate("JSBYrCurrency", "JSBYrFrom", "JSBYrTo", "yearly")){
        return true;
    }
    return false;
}

function validateJobSalaryRate(currencyID, fromID, upToID, msgType){
    var result = false;
    if(document.getElementById(currencyID).value!="" || document.getElementById(fromID).value!="" || document.getElementById(upToID).value!="") {
        if(validate(currencyID, "", "Please select "+msgType+" currency.")){
            if(validate(fromID, "", "Please enter "+msgType+" salary range.")){
                if(validatePrice(fromID, "Please enter "+msgType+" salary range in (E.g. 10.00)")){
                    if(validate(upToID, "", "Please enter "+msgType+" salary range.")){
                        if(validatePrice(upToID, "Please enter "+msgType+" salary range in (E.g. 10.00)")){
                            result = true;
                        }
                    }
                }
            }
        }
    }else{
        result = true;
    }
    return result;
}

//##############################################################################
//##############################################################################
//Save Job Tag
function SaveJobTag()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveJobTag.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url = url+"&jobTagCounter="+document.getElementById("jobTagCounter").value;
        for(var i=0;i<7;i++)
        {
            var keyword = "jobTagKeyword"+(i+1);
            url = url+"&jobTagKeyword"+(i+1)+"="+document.getElementById(keyword).value;
        }
        url =url+"&SaveJobTag="+document.getElementById("SaveJobTag").value;
        try{
            xmlhttp.onreadystatechange=SaveJobTagStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }else{
        if(validateJob()){
            SaveJob();
        }
    }
}
function SaveJobTagStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(!jobSaveAll){
                if(xmlhttp.responseText == "1"){
                    alert("Job specification saved successfully.");
                }else{
                    alert("Save Job Failed. Please try again.");
                }
            }
            if(xmlhttp.responseText == "1"){
                saveJobTag = false;
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//save job tag check
function sjtagc(){
    if(!saveJobTag){
        saveJobTag = true;
    }
}

//retrieve job Tag
function RetrieveJobTag()
{
    showJobTab("tag");
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrievejobtag.php";
    url =url+"?jobID="+document.getElementById("jobID").value;
    url =url+"&jobTagCounter="+document.getElementById("jobTagCounter").value;
    try{
        xmlhttp.onreadystatechange=RetrieveJobTagStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveJobTagStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                for(var i=1; i<8; i++){
                    var keyword = "jobTagKeyword" + i;
                    document.getElementById(keyword).value="";
                }
                var index=0;
                while(index<7){
                    var jobTagNo = "jobTagNo" + (index+1);
                    if(xmlDoc.getElementsByTagName("tagNo")[index]!= null){
                        if(xmlDoc.getElementsByTagName("tagNo")[index].childNodes[0] != null){
                            var tagNo = xmlDoc.getElementsByTagName("tagNo")[index].childNodes[0].nodeValue;
                            if(document.getElementById(jobTagNo).innerHTML == tagNo){
                                if(xmlDoc.getElementsByTagName("keyword")[index]!= null){
                                    if(xmlDoc.getElementsByTagName("keyword")[index].childNodes[0] != null){
                                        keyword = "jobTagKeyword" + (index+1);
                                        document.getElementById(keyword).value=
                                            xmlDoc.getElementsByTagName("keyword")[index].childNodes[0].nodeValue;
                                    }
                                }
                            }
                        }
                    }
                    index++;
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function rjtag(){
    if(jobTagTabCount == 0){
        RetrieveJobTag();
    }
}

function ral(){
    document.getElementById("refreshApplicantList").click();
    document.getElementById("refreshApplicantRankList").click();
}

//validate job tags
function validateJobTag(){
    document.getElementById("jobTagTab").click();
    return validateOneTextField("jobTagKeyword");
}

//##############################################################################
//##############################################################################
//Save as Job Detail
function SaveAsJob()
{
    if(document.getElementById("jobID").value != ""){
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
        var url="AjaxSaveAsJob.php";
        url =url+"?jobID="+document.getElementById("jobID").value;
        url =url+"&jobSalaryID="+document.getElementById("jobSalaryID").value;
        url =url+"&saveAsJob="+document.getElementById("SaveAsJob").value;
        try{
            xmlhttp.onreadystatechange=SaveAsJobStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}
function SaveAsJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                if(xmlDoc.getElementsByTagName("jobID")[0]!= null){
                    if(xmlDoc.getElementsByTagName("jobID")[0].childNodes[0] != null){
                        RetrieveJobDetail(xmlDoc.getElementsByTagName("jobID")[0].childNodes[0].nodeValue);
                    }
                }
                if(xmlDoc.getElementsByTagName("SJSuccess")[0]!= null){
                    if(xmlDoc.getElementsByTagName("SJSuccess")[0].childNodes[0] != null){
                        if(xmlDoc.getElementsByTagName("SJSuccess")[0].childNodes[0].nodeValue != ""){
                            alert(xmlDoc.getElementsByTagName("SJSuccess")[0].childNodes[0].nodeValue);
                        }
                    }
                }
                if(xmlDoc.getElementsByTagName("SJFail")[0]!= null){
                    if(xmlDoc.getElementsByTagName("SJFail")[0].childNodes[0] != null){
                        if(xmlDoc.getElementsByTagName("SJFail")[0].childNodes[0].nodeValue != ""){
                            alert(xmlDoc.getElementsByTagName("SJFail")[0].childNodes[0].nodeValue);
                        }
                    }
                }
            }
            document.getElementById("refreshJobList").click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
//##############################################################################
//Save All job details
function SaveAllJob()
{
    jobSaveAll = true;
    if(jobGeneralTabCount == 1){
        if(validateJob()){
            jobSaveMsg = true;
            SaveJob();
        }else{
            jobSaveMsg = false;
            jobSaveAll = false;
        }
    }else{
        jobSaveAll = false;
    }
}


//##############################################################################
//##############################################################################
//Retrieve Applicant Resume
function RetrieveApplicantResume(jobSeekerID, applicationID)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveapplicantresume.php";
    url =url+"?retrieveApplicationResume=retrieveApplicationResume";
    url =url+"&personalParticular=personalParticular";
    url =url+"&jobSeekerID="+jobSeekerID;
    url =url+"&applicationID="+applicationID;
    try{
        xmlhttp.onreadystatechange=RetrieveApplicantResumeStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveApplicantResumeStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc=xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("ppPassportNo", "");
                SetValue("ppFullName", "");
                SetValue("ppAddress", "");
                SetValue("ppUnitNo", "");
                SetValue("ppCity", "");
                SetValue("ppState", "");
                SetValue("ppCountry", "");
                SetValue("ppPostalCode", "");
                SetValue("ppContactNo", "");
                SetValue("ppEmail", "");
                document.getElementById("ResumeHeader").innerHTML="";

                SetXMLNode(xmlDoc, "passportNo", 0, 0, "ppPassportNo");
                SetXMLNode(xmlDoc, "fullName", 0, 0, "ppFullName");
                if(xmlDoc.getElementsByTagName("fullName")[0] != null){
                    if(xmlDoc.getElementsByTagName("fullName")[0].childNodes[0] != null){
                        document.getElementById("ResumeHeader").innerHTML=
                            xmlDoc.getElementsByTagName("fullName")[0].childNodes[0].nodeValue;
                    }
                }
                SetXMLNode(xmlDoc, "applicationID", 0, 0, "applicationID");
                SetXMLNode(xmlDoc, "applicationID", 0, 0, "applicationID");
                SetXMLNode(xmlDoc, "resumeID", 0, 0, "resumeID");
                SetXMLNode(xmlDoc, "address", 0, 0, "ppAddress");
                SetXMLNode(xmlDoc, "unitNo", 0, 0, "ppUnitNo");
                SetXMLNode(xmlDoc, "city", 0, 0, "ppCity");
                SetXMLNode(xmlDoc, "state", 0, 0, "ppState");
                SetXMLNode(xmlDoc, "postalCode", 0, 0, "ppPostalCode");
                SetXMLNode(xmlDoc, "country", 0, 0, "ppCountry");
                SetXMLNode(xmlDoc, "contactNo", 0, 0, "ppContactNo");
                SetXMLNode(xmlDoc, "email", 0, 0, "ppEmail");
                SetXMLNode(xmlDoc, "country", 0, 0, "ppCountry");
                SetXMLNode(xmlDoc, "birthDate", 0, 0, "ppBirthdate");
                var count = 0;
                if(xmlDoc.getElementsByTagName("noOfCitizenship")[0] != null){
                    if(xmlDoc.getElementsByTagName("noOfCitizenship")[0].childNodes[0] != null){
                        count = xmlDoc.getElementsByTagName("noOfCitizenship")[0].childNodes[0].nodeValue;
                    }
                }
                if(count>0){
                    var index = 0;
                    while(count>index){
                        if(xmlDoc.getElementsByTagName("cType")[index] != null){
                            if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0] != null){
                                if(xmlDoc.getElementsByTagName("cCountry")[index] != null){
                                    if(xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0] != null){
                                        if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0].nodeValue == 1){
                                            for(var i=1; i<=3; i++){
                                                if(xmlDoc.getElementsByTagName("cNo")[index].childNodes[0].nodeValue == i){
                                                    var citiID ="ppCitizenship"+i;
                                                    document.getElementById(citiID).value =
                                                        xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0].nodeValue;
                                                }
                                            }
                                        }else if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0].nodeValue == 2){
                                            for(i=1; i<=3; i++){
                                                if(xmlDoc.getElementsByTagName("cNo")[index].childNodes[0].nodeValue == i){
                                                    var prID ="ppPR"+i;
                                                    document.getElementById(prID).value =
                                                        xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0].nodeValue;
                                                }
                                            }
                                        }else if(xmlDoc.getElementsByTagName("cType")[index].childNodes[0].nodeValue == 3){
                                            for(i=1; i<=3; i++){
                                                if(xmlDoc.getElementsByTagName("cNo")[index].childNodes[0].nodeValue == i){
                                                    var wpID ="ppWorkPermit"+i;
                                                    document.getElementById(wpID).value =
                                                        xmlDoc.getElementsByTagName("cCountry")[index].childNodes[0].nodeValue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        index++;
                    }
                }
            }
            if(xmlDoc.getElementsByTagName("appStatus")[0] != null){
                if(xmlDoc.getElementsByTagName("appStatus")[0].childNodes[0] != null){
                    if(xmlDoc.getElementsByTagName("appStatus")[0].childNodes[0].nodeValue == 1){
                        document.getElementById('ApplicantShortList').style.display = "block";
                        document.getElementById('ApplicantReject').style.display = "block";
                    }else if(xmlDoc.getElementsByTagName("appStatus")[0].childNodes[0].nodeValue == 2){
                        document.getElementById('ApplicantShortList').style.display = "none";
                        document.getElementById('ApplicantReject').style.display = "block";
                    }else if(xmlDoc.getElementsByTagName("appStatus")[0].childNodes[0].nodeValue == 3){
                        document.getElementById('ApplicantShortList').style.display = "block";
                        document.getElementById('ApplicantReject').style.display = "none";
                    }
                }
            }
            document.getElementById("applicantResumeRow").style.display = "block";
            document.getElementById("personalParticularTab").click();
            ResetResumeCount();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function checkApply(){
    if(document.getElementById("jobID").value != ""){
        return true;
    }
    return false;
}

//##############################################################################
function ResetJobCount(){
    document.getElementById("jobGeneral").click();
    jobGeneralTabCount = 1;
    jobEducationTabCount = 0;
    jobResponseTabCount = 0;
    jobSkillTabCount = 0;
    jobLocationTabCount = 0;
    jobTravelTabCount = 0;
    jobSalaryTabCount = 0;
    jobTagTabCount = 0;
}

function ResetJobSave(){
    saveJobSpec = false;
    saveJobEduReq = false;
    saveJobRoleNRespon = false;
    saveJobSkillReq = false;
    saveJobLocation = false;
    saveJobTravel = false;
    saveJobSalaryReq = false;
    saveJobTag = false;
}

function showJobTab(tab){
    if(tab == "education"){
        jobEducationTabCount = 1;
    }else if(tab == "response"){
        jobResponseTabCount = 1;
    }else if(tab == "skill"){
        jobSkillTabCount = 1;
    }else if(tab == "location"){
        jobLocationTabCount = 1;
    }else if(tab == "travel"){
        jobTravelTabCount = 1;
    }else if(tab == "salary"){
        jobSalaryTabCount = 1;
    }else if(tab == "tag"){
        jobTagTabCount = 1;
    }
}

//##############################################################################
function RankingJob(){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxRankingJob.php";
    url =url+"?jobID="+document.getElementById("jobID").value;
    try{
        xmlhttp.onreadystatechange=RankingJobStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RankingJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                var jobRanking = GetXMLNode(xmlDoc, 'jobRanking', 0, 0);
                if(jobRanking != "" && jobRanking == 0){
                    var ack = GetXMLNode(xmlDoc, 'ack', 0, 0);
                    if(ack == "Success"){
                        if(GetXMLNode(xmlDoc, 'successMsg', 0, 0) != ""){
                            alert(GetXMLNode(xmlDoc, 'successMsg', 0, 0));
                            document.getElementById("refreshApplicantRankList").click();
                            setDisplay('ApplicantList','none');
                            setDisplay('JobRankingIT','none');
                            setDisplay('ApplicantRankList','block');
                            setDisplay('JobRefreshRankingIT','block');
                        }
                    }
                    else{
                        if(GetXMLNode(xmlDoc, 'failMsg', 0, 0) != ""){
                            alert(GetXMLNode(xmlDoc, 'failMsg', 0, 0));
                        }
                    }
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}


//##############################################################################
//##############################################################################
//re-user method
//##############################################################################
function validateRadioRows(name, radio, form, priority){
    var result = true;
    for(var i=1; i<8; i++){
        var id = name + i + "";
        var radioID = radio + i + "";
        if(document.getElementById(id).value == ""){
            result = false;
            break;
        }
        if(priority!=null){
            var priorityID = priority + i + "";
            if(document.getElementById(priorityID).value == ""){
                result = false;
                break;
            }
        }
        if(document["forms"][form]!=null){
            if(document["forms"][form][radioID]!=null){
                var radioGrp = document["forms"][form][radioID];
                for(var ind=0; ind < radioGrp.length; ind++){
                    if (radioGrp[ind].checked) {
                        result = true;
                        break;
                    }else{
                        result = false;
                    }
                }
            }
        }
    }
    return result;
}

//##############################################################################
function validateRows(name, value){
    var result = true;
    for(var i=1; i<8; i++){
        var id = name + i + "";
        if(document.getElementById(id).value == value){
            result = false;
            break;
        }
    }
    return result;
}

//##############################################################################
//add skill row
function addSkillRow(nextNo, no, name, priority, radio, form){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var nameID = name + i + "";
        if(priority!=""){
            var priorityID = priority + i + "";
        }
        var radioID = radio + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(nameID).value = "";
        if(priority!=""){
            document.getElementById(priorityID).value = "0";
        }
        for(var ind=0; ind < document["forms"][form][radioID].length; ind++){
            document["forms"][form][radioID][ind].checked = false;
        }
        nextNo++;
    }
}

//##############################################################################
//add job location row
function addLocationRow(nextNo, no, city, state, country){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var cityID = city + i + "";
        var stateID = state + i + "";
        var countryID = country + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(cityID).value = "";
        document.getElementById(stateID).value = "";
        document.getElementById(countryID).value = "";
        nextNo++;
    }
}

//##############################################################################
//add tag row
function addTagRow(nextNo, no, keyword){
    for(var i=1; i<8; i++){
        var id = no + i + "";
        var keywordID = keyword + i + "";
        document.getElementById(id).innerHTML = nextNo;
        document.getElementById(keywordID).value = "";
        nextNo++;
    }
}

//##############################################################################
//##############################################################################
//types
function JobType(no){
    var type = "";
    if(no == 1){
        type= "Permanent";
    }else if(no == 2){
        type= "Contract";
    }
    return type;
}

function JobStatus(no) {
    var result = "";
    if(no == 1) {
        result = "Draft";
    }else  if(no == 2) {
        result = "Pending";
    }else  if(no == 3) {
        result = "Approved";
    }else  if(no == 4) {
        result = "Rejected";
    }else  if(no == 5) {
        result = "Re-Submit";
    }else  if(no == 6) {
        result = "Posted";
    }else  if(no == 7) {
        result = "Removed";
    }
    return result;
}

function JobAppStatus(no) {
    var result = "";
    if(no == 1) {
        result = "New";
    }else  if(no == 2) {
        result = "Shortlisted";
    }else  if(no == 3) {
        result = "Rejected";
    }
    return result;
}

function CheckPriority(no){
    if(no == 1){
        return "Low";
    }else if(no == 2){
        return "Medium";
    }else if(no == 3){
        return "High";
    }
    return "";
}

function CheckRating(no){
    if(no == 0){
        return "N/A";
    }else if(no == 1){
        return "Entry";
    }else if(no == 2){
        return "Good";
    }else if(no == 3){
        return "Average";
    }else if(no == 4){
        return "Competent";
    }else if(no == 5){
        return "Expert";
    }
    return "";
}

function CheckDiff(no){
    if(no == 0){
        return "Qualify";
    }else if(no > 0){
        return "Over Qualify";
    }else if(no < 0){
        return "Below Average";
    }
    return "";
}

//##############################################################################
//##############################################################################
//applicant education history table
function getApplicantEduHistory()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var myColumnDefs = [
                {
                    key:"schoolName",
                    label: "School",
                    sortable:true
                },
                {
                    key:"schoolCity",
                    label: "City",
                    sortable:true
                },
                {
                    key:"schoolCountry",
                    label: "Country",
                    sortable:true
                },
                {
                    key:"eduLvl",
                    label: "Level",
                    sortable:true
                },
                {
                    key:"gradYear",
                    label: "Year",
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveeducation.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "education",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "schoolName", "schoolCity", "schoolCountry", "eduLvl", "gradYear"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appEducationHistory", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshEducationHistoryList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });
            
            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applicant employment history table
function getApplicantEmpHistory()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var description = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  "<span title='Job Description: \n"+oRecord.getData("description")+"'>"+sData+"</span>";
            };
            var myColumnDefs = [
                {
                    key:"companyName",
                    label: "Company",
                    formatter: description,
                    sortable:true
                },
                {
                    key:"jobTitle",
                    label: "Job Title",
                    sortable:true
                },
                {
                    key:"startDate",
                    label: "Start Date",
                    sortable:true
                },
                {
                    key:"endDate",
                    label: "End Date",
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveemployment.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "employment",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "companyName", "jobTitle", "startDate", "endDate", "description"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appEmploymentHistory", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshEmploymentHistoryList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applicant skill inventory table
function getApplicantSkillInv()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var rating = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  CheckRating(sData);
            };
            var myColumnDefs = [
                {
                    key:"name",
                    label: "Skill",
                    sortable:true
                },
                {
                    key:"level",
                    label: "Rating",
                    formatter: rating,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveskillinventory.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "skillInv",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "name", "level"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appSkillInventory", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshSkillInventoryList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//application professional training table
function getApplicantProTraining()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var myColumnDefs = [
                {
                    key:"training",
                    label: "Training",
                    sortable:true
                },
                {
                    key:"provider",
                    label: "Provider",
                    sortable:true
                },
                {
                    key:"year",
                    label: "Year",
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveprotraining.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "professionalTraining",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "training", "year", "provider"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appProTraining", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshProTrainingList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applicant project experience table
function getApplicantProjectExp()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var description = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  "<span title='Project Description: \n"+oRecord.getData("description")+"'>"+sData+"</span>";
            };

            var myColumnDefs = [
                {
                    key:"title",
                    label: "Project",
                    formatter: description,
                    sortable:true
                },
                {
                    key:"role",
                    label: "Role",
                    sortable:true
                },
                {
                    key:"startDate",
                    label: "Start Date",
                    sortable:true,
                    width:60
                },
                {
                    key:"endDate",
                    label: "End Date",
                    sortable:true,
                    width:60
                },
                {
                    key:"client",
                    label: "Client",
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveproexp.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "projectExperience",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "title", "role", "startDate", "endDate", "client", "description"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appProjectExp", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshProjectExpList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applicant award table
function getApplicantAward(){
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var myColumnDefs = [
                {
                    key:"title",
                    label: "Title",
                    sortable:true
                },
                {
                    key:"awardBy",
                    label: "Awards By",
                    sortable:true
                },
                {
                    key:"year",
                    label: "Year",
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveaward.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "award",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "title", "awardBy", "year"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appAward", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshAwardList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applicant referee table
function getApplicantReferee(){
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var myColumnDefs = [
                {
                    key:"name",
                    label: "Referee",
                    sortable:true
                },
                {
                    key:"email",
                    label: "Email",
                    sortable:true
                },
                {
                    key:"contactNo",
                    label: "Tel",
                    sortable:true
                },
                {
                    key:"relationship",
                    label: "Relationship",
                    sortable:true
                },
                {
                    key:"periodKnown",
                    label: "Known Since",
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievereferee.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "referee",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "name", "email", "contactNo", "relationship", "periodKnown"]
            };


            var Myconf = {
                height: "17em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appReferee", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshRefereeList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//resume tag table
function getResumeTag()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var myColumnDefs = [
                {
                    key:"keyword",
                    label: "Tag",
                    width:100,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveresumetag.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "tag",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "keyword"]
            };


            var Myconf = {
                height: "18em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("resumeTagList", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshResumeTagList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//applicant skill assessment table
function getApplicantSkillAssessment()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var rating = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  CheckRating(sData) + " ("+sData+")";
            };
            var level = function(elCell, oRecord, oColumn, sData) {
                document.getElementById('jobSkillAssessmentCount').value = oRecord.getData('No');
                var ratingList = new Array("N/A", "Entry", "Good", "Average", "Competent", "Expert");
                var str = '<select id="applicationRating'+oRecord.getData('No')+'">';
                for(var i=0; i<ratingList.length;i++){
                    if(i==sData){
                        str = str+'<option selected value="'+i+'">'+ratingList[i] + " ("+i+")"+'</option>';
                    }else{
                        str = str+'<option value="'+i+'">'+ratingList[i] + " ("+i+")"+'</option>';
                    }
                }
                str = str+ '</select>';
                elCell.innerHTML = str;
            };
            var diff = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  CheckDiff(sData) + " ("+sData+")";
            };
            var priority = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  CheckPriority(sData) + " ("+sData+")";
            };
            var myColumnDefs = [
                {
                    key:"title",
                    label: "Skill",
                    sortable:true
                },
                {
                    key:"priority",
                    label: "Job Priority",
                    formatter: priority,
                    sortable:true
                },
                {
                    key:"jobLevel",
                    label: "Job Rating",
                    formatter: rating,
                    sortable:true
                },
                {
                    key:"level",
                    label: "Rating",
                    formatter: level,
                    sortable:true
                },
                {
                    key:"result",
                    label: "Difference",
                    formatter: diff,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrieveskillassessment.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "skillAssessment",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "title", "level", "result", "jobLevel", "priority"]
            };


            var Myconf = {
                height: "14em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("appSkillAssessment", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshSkillAssessment");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });
            var udpateBtn = new YAHOO.widget.Button("updateSkillAssessment");
            udpateBtn.on("click", function(){
                UpdateApplicantSkillAssessment();
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//job skill requirement table
function getJobSkillRequirement()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var rating = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  CheckRating(sData);
            };
            var priority = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML =  CheckPriority(sData);
            };
            var myColumnDefs = [
                {
                    key:"title",
                    label: "Skill",
                    width:300,
                    sortable:true
                },
                {
                    key:"priority",
                    label: "Priority",
                    formatter: priority,
                    sortable:true
                },
                {
                    key:"level",
                    label: "Rating",
                    formatter: rating,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievejobskillrequirement.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "skillRequirement",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "title", "priority", "level"]
            };


            var Myconf = {
                height: "16em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("jobSkillRequirement", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshSkillRequirementList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//job location table
function getJobLocation()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var checkEmpty = function(elCell, oRecord, oColumn, sData) {
                if(sData == ""){
                    elCell.innerHTML = "N/A";
                }else{
                    elCell.innerHTML =  sData;
                }
            };
            var myColumnDefs = [
                {
                    key:"city",
                    label: "City",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"state",
                    label: "State",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"country",
                    label: "Country",
                    width:150,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievejoblocation.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "location",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "city", "state", "country"]
            };


            var Myconf = {
                height: "16em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("JobLocationList", myColumnDefs, myDataSource, Myconf);

            var JobLocation = new YAHOO.widget.Button("refreshLocationList");
            JobLocation.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//job travel table
function getJobTravel()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var checkEmpty = function(elCell, oRecord, oColumn, sData) {
                if(sData == ""){
                    elCell.innerHTML = "N/A";
                }else{
                    elCell.innerHTML =  sData;
                }
            };
            var myColumnDefs = [
                {
                    key:"city",
                    label: "City",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"state",
                    label: "State",
                    width:100,
                    formatter:checkEmpty,
                    sortable:true
                },
                {
                    key:"country",
                    label: "Country",
                    width:150,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievejobtravel.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "travel",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "city", "state", "country"]
            };


            var Myconf = {
                height: "16em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("JobTravelList", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshTravelList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//job tag table
function getJobTag()
{
    YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.XHR_XML = function() {
            var myColumnDefs = [
                {
                    key:"keyword",
                    label: "Tag",
                    width:100,
                    sortable:true
                }
            ];

            var myDataSource = new YAHOO.util.DataSource("xmlretrievejobtag.php");
            myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            myDataSource.useXPath = true;
            myDataSource.responseSchema = {
                metaFields: {
                    rootatt:"/myroot/@rootatt"
                },
                resultNode: "tag",
                fields: [{
                        key:"No",
                        locator:"@No",
                        parser:"number"
                    }, "keyword"]
            };


            var Myconf = {
                height: "18em"
            };

            var myDataTable = new YAHOO.widget.ScrollingDataTable("JobTagList", myColumnDefs, myDataSource, Myconf);

            var btn = new YAHOO.widget.Button("refreshTagList");
            btn.on("click", function(){
                myDataTable.showTableMessage("Loading...");
                myDataTable.getDataSource().sendRequest('', {
                    success: myDataTable.onDataReturnInitializeTable,
                    scope: myDataTable
                });
            });

            return {
                oDS: myDataSource,
                oDT: myDataTable
            };
        }();
    });
}

//##############################################################################
//##############################################################################
//Switch between table and form
function ToggleBetweenTableAndForm(tableID, formID, tableBtn, condition){
    if(condition){
        if(document.getElementById(formID) != null && document.getElementById(tableID) != null){
            document.getElementById(formID).style.display = 'none';
            document.getElementById(tableID).style.display = 'block';
            if(tableBtn!=null){
                YAHOO.util.Dom.get(tableBtn).click();
            }
        }
    }else{
        if(document.getElementById(formID) != null && document.getElementById(tableID) != null){
            document.getElementById(formID).style.display = 'block';
            document.getElementById(tableID).style.display = 'none';
        }
    }
}


//##############################################################################
function SetOptionValue(id, index, value){
    if(document.getElementById(id)!=null){
        document.getElementById(id).options[index].selected = value;
    }
}

//##############################################################################
//##############################################################################
//search job
function SearchJob(){
    var so1 = null;
    var sc1 = getSearchCriteria("searchOption1", "searchCriteria1", "status1");
    if(sc1 != null){
        var scs1 = null;
        so1 = document.getElementById("searchOption1").value;
        RetrieveSearchCriteria(so1, sc1);
    }
    //    var so2 = null;
    //    var sc2 = getSearchCriteria("searchOption2", "searchCriteria2");
    //    if(sc2 != null){
    //        so2 = document.getElementById("searchOption3").value;
    //    }
    //    var so3 = null;
    //    var sc3 = getSearchCriteria("searchOption3", "searchCriteria3");
    //    if(sc3 != null){
    //        so3 = document.getElementById("searchOption3").value;
    //    }
    //    var so4 = null;
    //    var sc4 = getSearchCriteria("searchOption4", "searchCriteria4");
    //    if(sc4 != null){
    //        so4 = document.getElementById("searchOption4").value;
    //    }
}

//##############################################################################
function getSearchCriteria(optionID, valueID, statusID){
    if(document.getElementById(optionID)!=null){
        if(document.getElementById(optionID).value != ""){
            if(document.getElementById(valueID).value != ""){
                return document.getElementById(valueID).value;
            }else{
                if(document.getElementById(optionID).value == "Status"){
                    if(document.getElementById(statusID) != null){
                        if(document.getElementById(statusID).value == "0"){
                            alert("Please select a status.")
                        }else{
                            return document.getElementById(statusID).value;
                        }
                    }
                }else{
                    alert("Please enter search criteria.")
                }
            }
        }else{
            alert("Please select a criteria option.")
        }
    }
    return null;
}

//##############################################################################
function getSelectedRadioBtnValue(form, tagName){
    for(var ind=0; ind < document['forms'][form][tagName].length; ind++){
        if(document['forms'][form][tagName][ind].checked){
            return document['forms'][form][tagName][ind].value;
        }
    }
    return "";
}

//##############################################################################
//retrieve latest job
function RetrieveLatestJob(){

    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxViewLatest.php";
    try{
        xmlhttp.onreadystatechange=RetrieveLatestJobStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveLatestJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            document.getElementById('searchOption1').value = "";
            document.getElementById('searchCriteria1').value = "";
            document.getElementById('refreshJobList').click();
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
//retrieve search criteria
function RetrieveSearchCriteria(so1, sc1)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSearchJob.php";
    url =url+"?search=search";
    if(so1!=null){
        url =url+"&searchOption1="+so1;
        url =url+"&searchCriteria1="+sc1;
       
    }

    //    if(so2!=null){
    //        url =url+"&searchOption2="+so2;
    //        url =url+"&searchCriteria2="+sc2;
    //    }
    //    if(so3!=null){
    //        url =url+"&searchOption3="+so3;
    //        url =url+"&searchCriteria3="+sc3;
    //    }
    //    if(so4!=null){
    //        url =url+"&searchOption4="+so4;
    //        url =url+"&searchCriteria4="+sc4;
    //    }
    try{
        xmlhttp.onreadystatechange=RetrieveSearchCriteriaStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function RetrieveSearchCriteriaStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            if(document.getElementById('refreshAppliedJobList')!=null){
                document.getElementById('refreshAppliedJobList').click();
            }
            if(document.getElementById('refreshJobList')!=null){
                document.getElementById('refreshJobList').click();
            }
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
function ResetResumeCount(){
    ppTabCount = 1;
    eduHisTabCount = 0;
    empHisTabCount = 0;
    skillInvTabCount = 0;
    ptTabCount = 0;
    peTabCount = 0;
    awardTabCount = 0;
    refereeTabCount = 0;
    avaTabCount = 0;
    salaryTabCount = 0;
    rTagTabCount = 0;
    assessTabCount = 0;
}

function showResumeTab(tab){
    if(tab == "personal"){
        ppTabCount = 1;
    }else if(tab == "education"){
        eduHisTabCount = 1;
    }else if(tab == "employment"){
        empHisTabCount = 1;
    }
    else if(tab == "skill"){
        skillInvTabCount = 1;
    }else if(tab == "training"){
        ptTabCount = 1;
    }
    else if(tab == "project"){
        peTabCount = 1;
    }else if(tab == "award"){
        awardTabCount = 1;
    }else if(tab == "referee"){
        refereeTabCount = 1;
    }else if(tab == "availability"){
        avaTabCount = 1;
    }else if(tab == "salary"){
        salaryTabCount = 1;
    }else if(tab == "tag"){
        rTagTabCount = 1;
    }
}

//##############################################################################
function JobSpecsReadOnly(showTable, display){
    toggleJobSpecsToReadWrite(showTable, display);
    ToggleBetweenTableAndForm("skillRequirementTable", "skillRequirementForm", "refreshSkillRequirementList", showTable);
    ToggleBetweenTableAndForm("jobLocationTable", "jobLocationForm", "refreshLocationList", showTable);
    ToggleBetweenTableAndForm("jobTravelTable", "jobTravelForm", "refreshTravelList", showTable);
    ToggleBetweenTableAndForm("jobTagTable", "jobTagForm", "refreshTagList", showTable);
}
function toggleJobSpecsToReadWrite(readonly, display){
    var oppDisplay = "none";
    if(display == "none"){
        oppDisplay = "block";
    }
    checkReadOnly('jobTitle', readonly, null, null);
    checkReadOnly('jobReferenceNo', readonly, null, null);
    checkReadOnly('jobYrOfExp', readonly, null, null);

    checkReadOnly('jobPostingDay', readonly, null, null);
    checkReadOnly('jobPostingMth', null, readonly, null);
    checkReadOnly('jobPostingYr', readonly, null, null);

    checkReadOnly('jobClosingDay', readonly, null, null);
    checkReadOnly('jobClosingMth', null, readonly, null);
    checkReadOnly('jobClosingYr', readonly, null, null);

    checkReadOnly('jobType', null, readonly, null);
    checkReadOnly('jobNoOfPosition', readonly, null, null);
    checkReadOnly('jobWebsite', readonly, null, null);
    checkReadOnly('jobDesc', readonly, null, null);

    checkReadOnly('jobEduReq', readonly, null, null);

    checkReadOnly('jobRoleNRespon', readonly, null, null);

    checkReadOnly('SaveJobDetailBtn', null, null, display);
    checkReadOnly('JobDetailBR', null, null, oppDisplay);
    checkReadOnly('SaveJobEduReqBtn', null, null, display);
    checkReadOnly('JobEduReqBR', null, null, oppDisplay);
    checkReadOnly('SaveJobRoleNResponBtn', null, null, display);
    checkReadOnly('obRoleNResponBR', null, null, oppDisplay);

    //job salary
    checkReadOnly('JSBHrCurrency', null, readonly, null);
    checkReadOnly('JSBHrFrom', readonly, null, null);
    checkReadOnly('JSBHrTo', readonly, null, null);

    checkReadOnly('JSBDayCurrency', null, readonly, null);
    checkReadOnly('JSBDayFrom', readonly, null, null);
    checkReadOnly('JSBDayTo', readonly, null, null);

    checkReadOnly('JSBMthCurrency', null, readonly, null);
    checkReadOnly('JSBMthFrom', readonly, null, null);
    checkReadOnly('JSBMthTo', readonly, null, null);

    checkReadOnly('JSBYrCurrency', null, readonly, null);
    checkReadOnly('JSBYrFrom', readonly, null, null);
    checkReadOnly('JSBYrTo', readonly, null, null);
    
    toggleRadioButton("jobSalaryForm", "JSCarRadio", readonly);
    toggleRadioButton("jobSalaryForm", "JSAccomodationRadio", readonly);
    toggleRadioButton("jobSalaryForm", "JSRelocationBenefitsRadio", readonly);

    toggleRadioButton("jobSalaryForm", "JSCommissionRadio", readonly);
    toggleRadioButton("jobSalaryForm", "JSBonusRadio", readonly);
    toggleRadioButton("jobSalaryForm", "JSShareOptionRadio", readonly);

    checkReadOnly('SaveJobSalaryBtn', null, null, display);
    checkReadOnly('JobSalaryBR', null, null, oppDisplay);
    checkReadOnly('SaveAllBtn', null, null, display);
}

//##############################################################################
function toggleResumeToReadWrite(readonly, display){
    checkReadOnly('ppFullName', readonly, null, null);
    checkReadOnly('ppContactNo', readonly, null, null);
    checkReadOnly('ppEmail', readonly, null, null);
    checkReadOnly('ppPassportNo', readonly, null, null);
    checkReadOnly('ppBirthDateDay', readonly, null, null);
    checkReadOnly('ppBirthDateMth', null, readonly, null);
    checkReadOnly('ppAddress', readonly, null, null);
    checkReadOnly('ppUnitNo', readonly, null, null);
    checkReadOnly('ppCity', readonly, null, null);
    checkReadOnly('ppState', readonly, null, null);
    checkReadOnly('ppCountry', null, readonly, null);
    checkReadOnly('ppPostalCode', readonly, null, null);

    checkReadOnly('SavePersonalParticularBtn', null, null, display);
}

//##############################################################################
function toggleRadioButton(formID, nameTag, disable){
    if(document['forms'][formID]!=null){
        if(document['forms'][formID][nameTag]!=null){
            for(var ind=0; ind < document['forms'][formID][nameTag].length; ind++){
                document['forms'][formID][nameTag][ind].disabled = disable;
            }
        }
    }
}
function checkReadOnly(id, readonly, disable, display){
    if(document.getElementById(id)!=null){
        if(readonly!=null){
            document.getElementById(id).readOnly = readonly;
        }else if(display != null){
            document.getElementById(id).style.display = display;
        }
        else if(disable != null){
            document.getElementById(id).disabled = disable;
        }
    }
}

//##############################################################################
function addOptions(id, value){
    var opt = document.createElement("option");
    document.getElementById(id).options.add(opt);
    opt.text = value;
    opt.value =value;
}

//##############################################################################
//udpate view counter
function UpdateViewCounter(jobID)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxUpdateViewCounter.php";
    url =url+"?jobID="+jobID;
    try{
        xmlhttp.onreadystatechange=UpdateViewCounterStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function UpdateViewCounterStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################

function AppliedJobButton(){
    var Gobtn = new YAHOO.widget.Button("searchCriteria");
    Gobtn.on("click", function(){
        SearchJob();
    });
    var ViewAllbtn = new YAHOO.widget.Button("searchCriteriaViewAll");
    ViewAllbtn.on("click", function(){
        RetrieveSearchCriteria(null, null);
    });
}

function checkSelectedStatus(optionID, inputID, dropDownID){
    if(document.getElementById(optionID).value == "Status"){
        document.getElementById(inputID).style.display = 'none';
        document.getElementById(dropDownID).style.display = 'block';
    }else {
        document.getElementById(inputID).style.display = 'block';
        document.getElementById(dropDownID).style.display = 'none';
    }
}

//##############################################################################
//##############################################################################

function UpdateApplicantStatus(applicationID, status){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxUpdateApplicantStatus.php";
    url =url+"?applicationID="+applicationID;
    url =url+"&applicationStatus="+status;
    try{
        xmlhttp.onreadystatechange=UpdateApplicantStatusStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function UpdateApplicantStatusStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            alert(xmlhttp.responseText);
            if(xmlhttp.responseText == "Applicant has been shortlisted!"){
                document.getElementById('ApplicantShortList').style.display = "none";
                document.getElementById('ApplicantReject').style.display = "block";
                document.getElementById('refreshApplicantList').click();
                document.getElementById('refreshApplicantRankList').click();
            }else if(xmlhttp.responseText == "Applicant has been rejected!"){
                document.getElementById('ApplicantShortList').style.display = "block";
                document.getElementById('ApplicantReject').style.display = "none";
                document.getElementById('refreshApplicantList').click();
                document.getElementById('refreshApplicantRankList').click();
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

function UpdateApplicantSkillAssessment(){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxUpdateJobSkillAssessment.php";
    url =url+"?applicationID="+document.getElementById('applicationID').value;
    url =url+"&jobID="+document.getElementById('jobID').value;
    for(var i=0;i<document.getElementById('jobSkillAssessmentCount').value; i++){
        var applicationRating = "applicationRating"+(i+1);
        url =url+"&"+applicationRating+"="+document.getElementById(applicationRating).value;
    }
    url =url+"&UpdateJobSkillAssessment=UpdateJobSkillAssessment";
    try{
        xmlhttp.onreadystatechange=UpdateApplicantSkillAssessmentStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function UpdateApplicantSkillAssessmentStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            alert(xmlhttp.responseText);
            document.getElementById('refreshSkillAssessment').click();
            document.getElementById("refreshApplicantList").click();
            document.getElementById("refreshApplicantRankList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
//##############################################################################
function DeleteRow(type, no, counterID, ID){
    var actualNo = parseInt(document.getElementById(counterID).value - 8) + parseInt(no);
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxDeleteRow.php";
    url =url+"?id="+document.getElementById(ID).value;
    url =url+"&type="+type;
    url =url+"&no="+actualNo;
    try{
        xmlhttp.onreadystatechange=DeleteRowStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    } catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }
}
function DeleteRowStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                if(xmlDoc.getElementsByTagName('msg')[0]!= null){
                    if(xmlDoc.getElementsByTagName('msg')[0].childNodes[0] != null){
                        if(xmlDoc.getElementsByTagName('msg')[0].childNodes[0].nodeValue != ""){
                        
                            alert(xmlDoc.getElementsByTagName('msg')[0].childNodes[0].nodeValue);
                        
                            if(xmlDoc.getElementsByTagName('type')[0]!= null){
                                if(xmlDoc.getElementsByTagName('type')[0].childNodes[0] != null){
                                    var type = xmlDoc.getElementsByTagName('type')[0].childNodes[0].nodeValue;
                                    if(type == "SkillReq"){
                                        RetrieveSkillRequirement();
                                    }else if(type == "JobLocation"){
                                        RetrieveJobLocation();
                                    }else if(type == "JobTravel"){
                                        RetrieveJobTravel();
                                    }else if(type == "EduHistory"){
                                        RetrieveEducationHistory();
                                    }else if(type == "EmpHistory"){
                                        RetrieveEmploymentHistory();
                                    }else if(type == "SkillInv"){
                                        RetrieveSkillInventory();
                                    }else if(type == "ProTraining"){
                                        RetrieveProfessionalTraining();
                                    }else if(type == "ProjectExp"){
                                        RetrieveProjectExperience();
                                    }else if(type == "Award"){
                                        RetrieveAward();
                                    }else if(type == "Referee"){
                                        RetrieveReferee();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}

//##############################################################################
//##############################################################################
//delete row by index
function DeleteSelectedRow(noID, arrayList){
    var no = document.getElementById(noID).innerHTML;
    var deleted = false;
    var tempArray = new Array();
    var index = 0;
    for(var i=0; i<arrayList.length; i++){
        var object = arrayList[i];
        if(object.no != no){
            if(deleted){
                object.no = no;
                no++;
            }
            tempArray[index] = object;
            index++;
        }else{
            deleted = true;
        }
    }
    return tempArray;
}

//##############################################################################
//##############################################################################
//objects
//skill requirement object
function SkillRequirement(name, priority, level){
    this.name = name;
    this.priority = priority;
    this.level = level;
}

//job location object
function JobLocation(city,state,country){

    this.city = city;
    this.state = state;
    this.country = country;
}

//travel Requirement object
function TravelRequirement(city,state,country){
    this.city = city;
    this.state = state;
    this.country = country;
}

//education history object
function EducationHistory(school, city, country, level, year){
    this.school = school;
    this.city = city;
    this.country = country;
    this.level = level;
    this.year = year;

}

//employment history object
function EmploymentHistory(company, title, startDate, endDate, description){
    this.company = company;
    this.title = title;
    this.startDate = startDate;
    this.endDate = endDate;
    this.description = description;
}

//skill inventory object
function SkillInventory(name, level){
    this.name = name;
    this.level = level;
}

//professional training object
function ProfessioanlTraining(training, provider, year){
    this.training = training;
    this.provider = provider;
    this.year = year;
}

//project experience object
function ProjectExperience(title, role, startDate, endDate, client, description){
    this.title = title;
    this.role = role;
    this.startDate = startDate;
    this.endDate = endDate;
    this.client = client;
    this.description = description;
}

//award object
function Award(title, awardBy, year){
    this.title = title;
    this.awardBy = awardBy;
    this.year = year;
}

//award object
function Referee(referee, email, tel, relationship, knownSince){
    this.referee = referee;
    this.email = email;
    this.tel = tel;
    this.relationship = relationship;
    this.knownSince = knownSince;
}

//search applicant
function SearchApplicant(){
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSearchApplicant.php";
    url =url+"?searchApplicantCriteria="+document.getElementById('searchApplicantCriteria').value;
    try{
        xmlhttp.onreadystatechange=SearchApplicantStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }catch (e) {
        alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
    }

}
function SearchApplicantStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            document.getElementById("refreshApplicantList").click();
            document.getElementById("refreshApplicantRankList").click();
        }
        else{
            alert("Sorry for the inconvenience caused. The server is down. Please try again later.");
        }
    }
}
