/* 
 * 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,
assessTabCount = 0, 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;

var skillReqList = new Array(), jobLocationList = new Array(),
jobTravelList = 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) {
                var data = ToggleSpecialChar(sData, 2);
                var refNo = ToggleSpecialChar(oRecord.getData("refNo"), 2);
                elCell.innerHTML = "<a href='JavaScript:;' title='Click on the " + data + " to see the details on the right' onclick='RetrieveJobDetail(" + '"' + oRecord.getData("JobID") + '"' + ");'>" + data + "</a> (Ref:" + refNo + ")";
            };
            var company = function(elCell, oRecord, oColumn, sData) {
                if(oRecord.getData("recruitmentCompany")>0){
                    elCell.innerHTML =  "* " + ToggleSpecialChar(sData, 2);
                }
                else{
                    elCell.innerHTML =  ToggleSpecialChar(sData, 2);
                }
            };
            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
                });
            });

            //print job specs button
            var jobSpecsPrintBtn = new YAHOO.widget.Button("jobSpecsPrintBtn");
            jobSpecsPrintBtn.on("click", function(){
                window.open("RecruiterJobSpecs.php", "JobSpecsPrintPreview");
            });
            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) {
                var data = ToggleSpecialChar(sData, 2);
                elCell.innerHTML = "<a href='JavaScript:;' title='Click on the " + data + " to see the details on the right."+
                "\nNo of Views: "+oRecord.getData("view")+"' "+
                "onclick='RetrieveJobDetail(" + '"' + oRecord.getData("JobID") + '"' + ");'>" + data + "</a> ";
            };
            var allsData = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = ToggleSpecialChar(sData, 2);
            };
            var status = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = JobStatus(sData);
            };

            var myColumnDefs = [
            {
                key:"refNo",
                label:"Ref No",
                formatter:allsData,
                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")+'"'+");'>" + ToggleSpecialChar(sData, 2) + "</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);
                }
            });
            //aplication print preview button
            var applicantPrintBtn = new YAHOO.widget.Button("applicantPrintBtn");
            applicantPrintBtn.on("click", function(){
                if(YAHOO.util.Dom.get("resumeID").value != ""){
                    window.open("CandidateCV.php", "PrintPreview");
                }
            });
            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")+'"'+");'>" + ToggleSpecialChar(sData, 2) + "</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
            };
        }();
    });
}

//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 allsData = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = ToggleSpecialChar(sData, 2);
            };
            var myColumnDefs = [
            {
                key:"refNo",
                label:"Ref No",
                formatter:allsData,
                sortable:true
            },
            {
                key:"title",
                label: "Title",
                formatter:allsData,
                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 =  ToggleSpecialChar(sData, 2);
                }
            };
            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 =  ToggleSpecialChar(sData, 2);
                }
            };
            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){
    var display = "none";
    if(document.getElementById(id).style.display == "none")
        display= "block";
    ToggleDisplay(id, display);
}


function rassesst(){
    if(assessTabCount == 0){
        assessTabCount = 1;
        OnClick("refreshSkillAssessment");
    }
}

//##############################################################################
//##############################################################################
//job specification
//##############################################################################
//set resume buttons
function SetJobSpecsButtons(){
    window.name = "RecruiterJobList";
    CheckSession();
    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(){
        OnClick('refreshApplicantRankList');
    });

    //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();
        }
    });

    //print job specs button
    var jobSpecsPrintBtn = new YAHOO.widget.Button("jobSpecsPrintBtn");
    jobSpecsPrintBtn.on("click", function(){
        window.open("RecruiterJobSpecs.php", "JobSpecsPrintPreview");
    });

    //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;
                if(counter<30){
                    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);
                if(counter<30){
                    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();
    CheckExpiredOrder();
}
function RetrieveCompanyConfigure()
{
    CheckSession();
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="xmlretrieveconfigure.php";
    url =url+"?configureID=1";
    try{
        xmlhttp.open("GET",url,false);
        xmlhttp.send(null);
        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);
                }
            }
        }
    } catch (e) {
        alert(xmlhttpRequestStatus(xmlhttp.status));
    }
}

//##############################################################################
//##############################################################################
function NewJobSpec()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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("jobClientName", "");
            SetCheckBox("recruitmentCompany", false);
            SetValue("jobDesc", "");
            SetValue("jobEduReq", "");
            SetValue("jobRoleNRespon", "");
            SetValue("jobStatus", "1");
            SetValue("jobSalaryID", "");
            SetInnerValue("jobStatusHeader", "");
            SetInnerValue("jobHeader", "New Job");
            SetInnerValue("jobReferenceNoHeader", "");
            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;
                SetValue(skillReqPriority, "0");
            }

            for(i=1; i<8; i++){
                var city = "jobLocationCity" + i;
                SetValue(city, "");
                var state = "jobLocationState" + i;
                SetValue(state, "");
                var country = "jobLocationCountry" + i;
                SetValue(country, "");
            }

            for(i=1; i<8; i++){
                city = "jobTravelCity" + i;
                SetValue(city, "");
                state = "jobTravelState" + i;
                SetValue(state, "");
                country = "jobTravelCountry" + i;
                SetValue(country, "");
            }

            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;
                SetValue(keyword, "");
            }
            OnClick("refreshSkillRequirementList");
            OnClick("refreshLocationList");
            OnClick("refreshTravelList");
            ToggleDisplay("JobStatusRemove", 'none');
            ToggleDisplay("JobSpecsPrint", 'none');
            ToggleDisplay("JobStatusReSubmit", 'none');
            ToggleDisplay("JobStatusPostIT", 'none');
            ToggleDisplay("SaveAsBtn", 'none');

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

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

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

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

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

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

            ToggleDisplay('applyForm','block');

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

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

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

            ToggleDisplay('applicantResumeRow','none');

            JobSpecsReadOnly(false, "block");
            ResetJobCount();
            ResetJobSave();
            ResetResumeCount();
            ignoreJobValidation = false;
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }

}

//##############################################################################
//##############################################################################
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()
{
    CheckSession();
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url="AjaxSaveJob.php";
    url =url+"?jobID="+getIDValue("jobID");
    url =url+"&title="+GetElementIDValue("jobTitle");
    url =url+"&referenceNo="+GetElementIDValue("jobReferenceNo");
    url =url+"&yearOfExperience="+getIDValue("jobYrOfExp");
    url =url+"&postingDate="+getIDValue("jobPostingDate");
    url =url+"&closingDate="+getIDValue("jobClosingDate");
    url =url+"&jobType="+getIDValue("jobType");
    url =url+"&noOfPosition="+getIDValue("jobNoOfPosition");
    url =url+"&jobStatus="+getIDValue("jobStatus");
    if(document.getElementById("recruitmentCompany").checked){
        url =url+"&recruitmentCompany="+getIDValue("recruitmentCompany");
    }else{
        url =url+"&recruitmentCompany=0";
    }
    url =url+"&clientName="+GetElementIDValue("jobClientName");
    url =url+"&saveJob="+getIDValue("SaveJob");
    url =url+ SplitText(GetElementIDValue("jobDesc"), 300, "description");
    try{
        xmlhttp.onreadystatechange=SaveJobStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    catch (e) {
        alert(xmlhttpRequestStatus(xmlhttp.status));
    }
}
function SaveJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            var jobID = "";
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                if(GetXMLNode(xmlDoc, 'refNoExist', 0, 0) != "")
                    refNoExist = true;
                else
                    refNoExist = false;

                var jobIDNode = GetXMLNode(xmlDoc, 'jobID', 0, 0);
                if(jobIDNode != null){
                    SetValue('jobID', jobIDNode);
                    ignoreJobValidation = true;
                    jobID = jobIDNode;
                }
                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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

function CheckCompanyBalance(type)
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }

}
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{
                        if(balance == -1){
                            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{
                        if(balance == -1){
                            RankingJob();
                        }else{
                            alert("No credit left! Please buy more credit!");
                            window.open("OrderRankingForm.php","orderForm","width=900,height=700,scrollbars=1");
                        }
                    }
                }
            }
        }
        else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

function showXMLNodeAlert(xmlDoc, tagName, index, index2, alertShow){
    var node = GetXMLNode(xmlDoc, tagName, index, index2);
    if(node != ""){
        if(alertShow){
            alert(node);
        }
        if(tagName == "SJSuccess" || tagName == "SAJSuccess"){
            saveJobSpec = false;
            refNoExist = false;
            OnClick("refreshJobList");
        }
        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)
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
                }

            }
            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(xmlhttpRequestStatus(xmlhttp.status));
            }
        }
    }
}
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", "");
                SetCheckBox('recruitmentCompany', false)
                SetValue("jobDesc", "");
                SetInnerValue('appApplyCounter', " (0)");
            
                if(!saveJobEduReq){
                    SetValue("jobEduReq", "");
                }
                if(!saveJobRoleNRespon){
                    SetValue("jobRoleNRespon", "");
                }
                SetValue("jobStatus", "");
                SetValue("jobSalaryID", "");
                SetValue("jobCompanyName", "");

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

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

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

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

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

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

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

                ToggleDisplay('applyForm','block');

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

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

                ToggleDisplay('jobSkillRequirementMsg','none');

                ToggleDisplay('JobStatusPostIT','none');
                ToggleDisplay('JobStatusReSubmit','none');
                ToggleDisplay('JobStatusRemove','none');
                ToggleDisplay("JobSpecsPrint", 'block');

                ToggleDisplay('SaveAllBtn','block');
                SetXMLNode(xmlDoc, "jobID", 0, 0, "jobID");
                SetXMLNode(xmlDoc, "title", 0, 0, "jobTitle");
                SetXMLNode(xmlDoc, "companyName", 0, 0, "jobCompanyName");
                var titleNode = GetXMLNode(xmlDoc, 'title', 0, 0);
                if(titleNode != null){
                    SetInnerValue('jobHeader', "Job Title: '" + titleNode + "' ");
                }
                SetXMLNode(xmlDoc, "referenceNo", 0, 0, "jobReferenceNo");
                var refNoNode = GetXMLNode(xmlDoc, 'referenceNo', 0, 0);
                if(refNoNode != null){
                    SetInnerValue('jobReferenceNoHeader', " (Ref: " + refNoNode + ") ");
                }
                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");

                var jobTypeNode = GetXMLNode(xmlDoc, 'jobType', 0, 0);
                if(jobTypeNode != null){
                    SetValue('jobTypes', JobType(jobTypeNode));
                }
                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){
                        SetCheckBox('recruitmentCompany', true);
                    }
                }
                SetValue("jobDesc", GetXMLNode(xmlDoc, 'description', 0, 0));

                if(!saveJobEduReq){
                    SetValue("jobEduReq", GetXMLNode(xmlDoc, 'educationRequirement', 0, 0));
                }
                if(!saveJobRoleNRespon){
                    SetValue("jobRoleNRespon", GetXMLNode(xmlDoc, 'roleAndRespon', 0, 0));
                }
                SetXMLNode(xmlDoc, "jobSalaryID", 0, 0, "jobSalaryID");
                SetInnerValue('appApplyCounter', " (" + GetXMLNode(xmlDoc, "appCount", 0, 0) + ")");
                SetValue("jobApplicantCount", GetXMLNode(xmlDoc, "appCount", 0, 0));

                var jStatus = GetXMLNode(xmlDoc, 'jStatus', 0, 0);
                if(jStatus != null){
                    if(jStatus == 0)
                        jStatus = 1;
                    SetInnerValue('jobStatusHeader', " Status: " + JobStatus(jStatus));
                    SetValue('jobStatus', jStatus);
                    var showTable = false;
                    var display = "block";
                    if(jStatus == "1"){
                        ignoreJobValidation = false;
                        if(document.getElementById("JobStatusPostIT") != null){
                            ToggleDisplay("JobStatusPostIT", 'block');
                        }
                    }else if(jStatus == "3"){
                        ignoreJobValidation = true;
                        if(document.getElementById("JobStatusPostIT") != null){
                            ToggleDisplay("JobStatusPostIT", 'block');
                        }
                        showTable = true;
                        display = "none";
                    }
                    else if(jStatus == "4"){
                        ignoreJobValidation = false;
                        if(document.getElementById("JobStatusReSubmit") != null){
                            ToggleDisplay("JobStatusReSubmit", 'block');
                        }
                    }else if(jStatus == "6"){
                        ignoreJobValidation = true;
                        if(document.getElementById("JobStatusRemove") != null){
                            ToggleDisplay('JobApplicant','block');
                            ToggleDisplay('jobAppTab','block');
                            ToggleDisplay("JobStatusRemove", 'block');
                        }
                        showTable = true;
                        display = "none";
                    }else if(jStatus == "7"){
                        ignoreJobValidation = true;
                        ToggleDisplay('JobApplicant','block');
                        ToggleDisplay('jobAppTab','block');
                        showTable = true;
                        display = "none";
                    }
                    JobSpecsReadOnly(showTable, display);
                }
                
                if(GetXMLNode(xmlDoc, 'ranking', 0, 0)>0){
                    ToggleDisplay('JobRankingIT','none');
                    ToggleDisplay('ApplicantList','none');
                    ToggleDisplay('ApplicantRankList','block');
                    ToggleDisplay('JobRefreshRankingIT','block');
                }else{
                    ToggleDisplay('JobRankingIT','block');
                    ToggleDisplay('ApplicantList','block');
                    ToggleDisplay('ApplicantRankList','none');
                    ToggleDisplay('JobRefreshRankingIT','none');
                }
                OnClick("jobGeneral");
                OnClick("hideApplicantResumeBtn");
                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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//Save Job detail
function UpdateJobStatus()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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);
                            ToggleDisplay("JobStatusPostIT", 'none');
                            ToggleDisplay("JobStatusReSubmit", 'none');
                            ToggleDisplay("JobStatusRemove", 'none');
                            if(btn == "Remove"){
                                ToggleDisplay("JobStatusRemove", '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));
                        }
                    }
                    OnClick("refreshJobList");
                }
            }
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//validate job detail
function validateJob(){
    OnClick("jobGeneral");
    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(){
    OnClick("jobGeneral");
    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()
{
    CheckSession();
    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+"&SaveJobEduReq="+document.getElementById("SaveJobEduReq").value;
        url =url+ SplitText(GetElementIDValue("jobEduReq"), 300, "educationRequirement");
        try{
            xmlhttp.onreadystatechange=SaveJobEduReqStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//retrieve Job education requirement
function RetrieveJobEduReq()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }

}
function RetrieveJobEduReqStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("jobEduReq", "");
                SetValue("jobEduReq", GetXMLNode(xmlDoc, 'educationRequirement', 0, 0));
            }
        }
        else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//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(){
    OnClick("jobEduTab");
    return validate("jobEduReq", "", "Please enter Job Education Requirement.");
}

//##############################################################################
//##############################################################################
//Save Job role and responsibility
function SaveJobRoleNRespon()
{
    CheckSession();
    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+"&SaveJobRoleNRespon="+document.getElementById("SaveJobRoleNRespon").value;
        url =url+ SplitText(GetElementIDValue("jobRoleNRespon"), 300, "roleAndResponsibility");
        try{
            xmlhttp.onreadystatechange=SaveJobRoleNResponStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        }
        catch (e) {
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//retrieve Job role and responsibility
function RetrieveJobRoleNRespon()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }

}
function RetrieveJobRoleNResponStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                SetValue("jobRoleNRespon", "");
                SetValue("jobRoleNRespon", GetXMLNode(xmlDoc, 'roleAndRespon', 0, 0));
            }
        }
        else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//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(){
    OnClick("jobResTab");
    return validate("jobRoleNRespon", "", "Please enter Job Roles and Responsibility.");
}

//##############################################################################
//##############################################################################
//Save Job skill requirement
function SaveJobSkillReq()
{
    CheckSession();
    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)+"="+ToggleSpecialChar(skillReq.name, 1);
            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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
    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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//retrieve job skill requirement
function RetrieveSkillRequirement()
{
    CheckSession();
    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;
    try{
        xmlhttp.onreadystatechange=RetrieveSkillRequirementStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }catch (e) {
        alert(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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(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;
                        }
                    }
                }
            }
            ToggleDisplay('updateSkillReqBtn', 'none');
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

function rsr(){
    if(jobSkillTabCount == 0){
        RetrieveExistingSkillRequirement();
        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;
    OnClick("jobSkillTab");
    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()
{
    CheckSession();
    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)+"="+ToggleSpecialChar(jobLocation.city, 1);
            url = url+"&jobLocationState"+(i+1)+"="+ToggleSpecialChar(jobLocation.state, 1);
            url = url+"&jobLocationCountry"+(i+1)+"="+jobLocation.country;
        }
        url =url+"&SaveJobLocation="+document.getElementById("SaveJobLocation").value;
        try{
            xmlhttp.onreadystatechange=SaveJobLocationStateChanged;
            xmlhttp.open("GET",url,true);
            xmlhttp.send(null);
        } catch (e) {
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
    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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

//retrieve job location
function RetrieveJobLocation()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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);
                    var locationNoNode = GetXMLNode(xmlDoc, 'locationNo', index, 0);
                    if(locationNoNode != null){
                        if(document.getElementById(jobLocationNo).innerHTML == locationNoNode){
                            SetMultipleXMLNode(xmlDoc, "city", index, "jobLocationCity");
                            SetMultipleXMLNode(xmlDoc, "state", index, "jobLocationState");
                            SetMultipleXMLNode(xmlDoc, "country", index, "jobLocationCountry");
                        }
                        
                    }
                    index++;
                }
            }
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

function rjll(){
    if(jobLocationTabCount == 0){
        jobLocationTabCount = 1;
        OnClick("refreshLocationList");
    }
}

//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.city == nextJobLocation.city && jobLocation.state == nextJobLocation.state && 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){
    OnClick(tabID);
    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()
{
    CheckSession();
    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)+"="+ToggleSpecialChar(jobTravel.city, 1);
            url = url+"&jobTravelState"+(i+1)+"="+ToggleSpecialChar(jobTravel.state, 1);
            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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

//retrieve job travel requirement
function RetrieveJobTravel()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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);
                    var travelNo = GetXMLNode(xmlDoc, 'travelNo', index, 0);
                    if(travelNo!= null){
                        if(document.getElementById(jobTravelNo).innerHTML == travelNo){
                            SetMultipleXMLNode(xmlDoc, "city", index, "jobTravelCity");
                            SetMultipleXMLNode(xmlDoc, "state", index, "jobTravelState");
                            SetMultipleXMLNode(xmlDoc, "country", index, "jobTravelCountry");
                        }
                    }
                    index++;
                }
            }
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

function rjtl(){
    if(jobTravelTabCount == 0){
        jobTravelTabCount = 1;
        OnClick("refreshTravelList");
    }
}

//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.city == nextJobTravel.city && jobTravel.state == nextJobTravel.state && 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()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

//retrieve job skill requirement
function RetrieveJobSalary()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

function RetrieveDisplayJobSalary()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
function RetrieveDisplayJobSalaryStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            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");
            }
            if(xmlDoc){
                //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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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();
    }
}

//validate job salary
function validateJobSalary(){
    OnClick("jobSalaryJTab");
    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()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

//retrieve job Tag
function RetrieveJobTag()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

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

function ral(){
    OnClick("refreshApplicantList");
    OnClick("refreshApplicantRankList");
}

//validate job tags
function validateJobTag(){
    OnClick("jobTagTab");
    return validateOneTextField("jobTagKeyword");
}

//##############################################################################
//##############################################################################
//Save as Job Detail
function SaveAsJob()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}
function SaveAsJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            xmlDoc = xmlhttp.responseXML;
            if(xmlDoc){
                var jobIDNode = GetXMLNode(xmlDoc, "jobID", 0, 0);
                if(jobIDNode != null){
                    RetrieveJobDetail(jobIDNode);
                }
                var SJSuccessNode = GetXMLNode(xmlDoc, "SJSuccess", 0, 0);
                if(SJSuccessNode != null){
                    alert(SJSuccessNode);
                }
                var SJFailNode = GetXMLNode(xmlDoc, "SJFail", 0, 0);
                if(SJFailNode != null){
                    alert(SJFailNode);
                }
            }
            OnClick("refreshJobList");
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//Save All job details
function SaveAllJob()
{
    CheckSession();
    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)
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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", "");
                SetInnerValue('ResumeHeader', "");

                SetXMLNode(xmlDoc, "passportNo", 0, 0, "ppPassportNo");
                SetXMLNode(xmlDoc, "fullName", 0, 0, "ppFullName");
                var fullNameNode = GetXMLNode(xmlDoc, "fullName", 0, 0);
                if(fullNameNode != null){
                    SetInnerValue('ResumeHeader', fullNameNode);
                }
                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 birthDateNode = GetXMLNode(xmlDoc, "birthDate", 0, 0);
                if(birthDateNode != null){
                    decodeBirthDate(birthDateNode, "ppBirthDateDay", "ppBirthDateMth");
                }
                var count = 0;
                var noOfCitizenship = GetXMLNode(xmlDoc, "noOfCitizenship", 0, 0);
                if(noOfCitizenship != null){
                    count = noOfCitizenship;
                }
                if(count>0){
                    var index = 0;
                    while(count>index){
                        var cType = GetXMLNode(xmlDoc, "cType", index, 0);
                        if(cType != null){
                            var cCountry = GetXMLNode(xmlDoc, "cCountry", index, 0);
                            if(cCountry != null){
                                var cNo = GetXMLNode(xmlDoc, "cNo", index, 0);
                                if(cType == 1){
                                    for(var i=1; i<=3; i++){
                                        if(cNo == i){
                                            var citiID ="ppCitizenship"+i;
                                            SetValue(citiID, cCountry);
                                        }
                                    }
                                }else if(cType == 2){
                                    for(i=1; i<=3; i++){
                                        if(cNo == i){
                                            var prID ="ppPR"+i;
                                            SetValue(prID, cCountry);
                                        }
                                    }
                                }else if(cType == 3){
                                    for(i=1; i<=3; i++){
                                        if(cNo == i){
                                            var wpID ="ppWorkPermit"+i;
                                            SetValue(wpID, cCountry);
                                        }
                                    }
                                }
                            }
                        }
                        index++;
                    }
                }
                var appStatus = GetXMLNode(xmlDoc, "appStatus", 0, 0);
                if(appStatus != null){
                    if(appStatus == 1){
                        ToggleDisplay('ApplicantShortList', 'block');
                        ToggleDisplay('ApplicantReject', 'block');
                    }else if(appStatus == 2){
                        ToggleDisplay('ApplicantShortList', 'none');
                        ToggleDisplay('ApplicantReject', 'block');
                    }else if(appStatus == 3){
                        ToggleDisplay('ApplicantShortList', 'block');
                        ToggleDisplay('ApplicantReject', 'none');
                    }
                }
                ToggleDisplay("applicantResumeRow", 'block');
                OnClick("personalParticularTab");
                OnClick("showApplicantResumeBtn");
                ResetResumeCount();
            }
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

function checkApply(){
    if(document.getElementById("jobID").value != ""){
        return true;
    }
    return false;
}
//##############################################################################
function ResetJobCount(){
    OnClick("jobGeneral");
    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()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
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));
                            OnClick("refreshApplicantRankList");
                            ToggleDisplay('ApplicantList','none');
                            ToggleDisplay('JobRankingIT','none');
                            ToggleDisplay('ApplicantRankList','block');
                            ToggleDisplay('JobRefreshRankingIT','block');
                        }
                    }
                    else{
                        if(GetXMLNode(xmlDoc, 'failMsg', 0, 0) != ""){
                            alert(GetXMLNode(xmlDoc, 'failMsg', 0, 0));
                        }
                    }
                }
            }
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//##############################################################################
//re-user method

//##############################################################################
//##############################################################################
//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 title="Applicant'+"'"+'s Rating" 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 status = function(elCell, oRecord, oColumn, sData) {
                var checkBox = '<input type="hidden" id="applicationStatus'+oRecord.getData('No')+'" value="'+oRecord.getData('status')+'" />';
                if(sData == 1){
                    checkBox += 'No';
                }else{
                    checkBox += 'Yes';
                }
                elCell.innerHTML =  checkBox;
            };
            var allsData = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = ToggleSpecialChar(sData, 2);
            };
            var myColumnDefs = [
            {
                key:"title",
                label: "Skill",
                formatter: allsData,
                width:150,
                sortable:true
            },
            {
                key:"priority",
                label: "Job's Priority",
                formatter: priority,
                sortable:true
            },
            {
                key:"jobLevel",
                label: "Job's Rating",
                formatter: rating,
                sortable:true
            },
            {
                key:"level",
                label: "Applicant's Rating",
                formatter: level,
                sortable:true
            },
            {
                key:"result",
                label: "Difference",
                formatter: diff,
                sortable:true
            },
            {
                key:"status",
                label: "Update Required",
                formatter: status,
                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", "status"]
            };


            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 allsData = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = ToggleSpecialChar(sData, 2);
            };
            var myColumnDefs = [
            {
                key:"title",
                label: "Skill",
                formatter: allsData,
                width:200,
                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: "13em"
            };

            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 =  ToggleSpecialChar(sData, 2);
                }
            };
            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 =  ToggleSpecialChar(sData, 2);
                }
            };
            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 allsData = function(elCell, oRecord, oColumn, sData) {
                elCell.innerHTML = ToggleSpecialChar(sData, 2);
            };
            var myColumnDefs = [
            {
                key:"keyword",
                label: "Tag",
                formatter:allsData,
                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
            };
        }();
    });
}

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

//##############################################################################
//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 GetElementIDValue(valueID);
            }
            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;
}

//##############################################################################
//retrieve latest job
function RetrieveLatestJob()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
function RetrieveLatestJobStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            document.getElementById('searchOption1').value = "";
            document.getElementById('searchCriteria1').value = "";
            OnClick('refreshJobList');
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//##############################################################################
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);
}

//##############################################################################
//udpate view counter
function UpdateViewCounter(jobID)
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }
}
function UpdateViewCounterStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//##############################################################################
function AppliedJobButton(){
    CheckSession();
    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);
    });
    //print job specs button
    var jobSpecsPrintBtn = new YAHOO.widget.Button("jobSpecsPrintBtn");
    jobSpecsPrintBtn.on("click", function(){
        window.open("RecruiterJobSpecs.php", "JobSpecsPrintPreview");
    });
}

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

//##############################################################################
//##############################################################################
function UpdateApplicantStatus(applicationID, status)
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }

}
function UpdateApplicantStatusStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            alert(xmlhttp.responseText);
            if(xmlhttp.responseText == "Applicant has been shortlisted!"){
                ToggleDisplay('ApplicantShortList', 'none');
                ToggleDisplay('ApplicantReject', 'block');
            }else if(xmlhttp.responseText == "Applicant has been rejected!"){
                ToggleDisplay('ApplicantShortList', 'block');
                ToggleDisplay('ApplicantReject', 'none');
            }
            OnClick('refreshApplicantList');
            OnClick('refreshApplicantRankList');
            OnClick("refreshAppliedJobList");
        }else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

function UpdateApplicantSkillAssessment()
{
    CheckSession();
    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;
        
        var applicationStatus = "applicationStatus"+(i+1);
        var status = "&"+applicationStatus+"="+document.getElementById(applicationStatus).value;
        if(document.getElementById(applicationStatus).value == 0){
            if(document.getElementById(applicationRating).value > 0){
                status = "&"+applicationStatus+"=1";
            }
        }
        url = url +status;
    }
    url =url+"&UpdateJobSkillAssessment=UpdateJobSkillAssessment";
    try{
        xmlhttp.onreadystatechange=UpdateApplicantSkillAssessmentStateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }catch (e) {
        alert(xmlhttpRequestStatus(xmlhttp.status));
    }

}
function UpdateApplicantSkillAssessmentStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            alert(xmlhttp.responseText);
            OnClick('refreshSkillAssessment');
            OnClick("refreshApplicantList");
            OnClick("refreshApplicantRankList");
        }
        else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

//search applicant
function SearchApplicant()
{
    CheckSession();
    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(xmlhttpRequestStatus(xmlhttp.status));
    }

}
function SearchApplicantStateChanged()
{
    if (xmlhttp.readyState==4)
    {
        if (xmlhttp.status==200){
            OnClick("refreshApplicantList");
            OnClick("refreshApplicantRankList");
        }
        else{
            alert(xmlhttpRequestStatus(xmlhttp.status));
        }
    }
}

function rappt(){
    OnClick("refreshAppliedJobList");
}
