﻿//綜合查詢的字串.
function getJsonstring() {
    var jsonString = "{";
    $('select[id^="ddlWorkCountryCode"]').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('ddl', '');
        jsonString += '"' + thisid + '":"' + $(this).val() + '",';
    });
    $('select[id^="ddlWorkCityCode"]').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('ddl', '');
        jsonString += '"' + thisid + '":"' + $(this).val() + '",';
    });
    $('select[id^="ddlIndustry"]').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('ddl', '');
        jsonString += '"' + thisid + '":"' + $(this).val() + '",';
    });
    $('select[id^="ddlPart"]').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('ddl', '');
        jsonString += '"' + thisid + '":"' + $(this).val() + '",';
    });

    var strWorkTypeList = '';
    $('input[id^="chkWorkType"]:checked').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('chk', 'hid');
        strWorkTypeList += '"' + $('#' + thisid).val() + '",';
    });

    if (strWorkTypeList != '') {
        if (strWorkTypeList.substring(strWorkTypeList.length - 1, strWorkTypeList.length) == ',')
            strWorkTypeList = strWorkTypeList.substring(0, strWorkTypeList.length - 1);

        jsonString += '"WorkType":[' + strWorkTypeList + '],';
    }

    jsonString += '"Title":"' + ($('#txtTitle').val() == undefined ? "" : $('#txtTitle').val()) + '",';

    var strCondition = '';
    $('input[id^="chkCondition"]:checked').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('chk', 'hid');
        strCondition += '"' + $('#' + thisid).val() + '",';
    });

    if (strCondition != '') {
        if (strCondition.substring(strCondition.length - 1, strCondition.length) == ',')
            strCondition = strCondition.substring(0, strCondition.length - 1);

        jsonString += '"Condition":[' + strCondition + '],';
    }

    var strVocationList = '';
    $('input[id^="chkVocation"]:checked').each(function() {
        var thisid = this.id;
        thisid = thisid.replace('chk', 'hid');
        strVocationList += '"' + $('#' + thisid).val() + '",';
    });
    if (strVocationList != '') {
        if (strVocationList.substring(strVocationList.length - 1, strVocationList.length) == ',')
            strVocationList = strVocationList.substring(0, strVocationList.length - 1);

        jsonString += '"Vocation":[' + strVocationList + '],';
    }

    jsonString += '"AreaId":"' + ($('#aid').val() == undefined ? "" : $('#aid').val()) + '",';
    jsonString += '"CityAreaId":"' + ($('#hidCityAreaId').val() == undefined ? "" : $('#hidCityAreaId').val()) + '",';
    jsonString += '"ScienceParkId":"' + $('#hidScienceParkId').val() + '",';

    if (jsonString.substring(jsonString.length - 1, jsonString.length) == ',')
        jsonString = jsonString.substring(0, jsonString.length - 1);

    jsonString += "}";
    return jsonString;
}


//快速查詢的字串.
function getJsonstringFastSearch(parentObject) {
    var jsonString = "{";
    jsonString += '"WorkCountryCode1":"' + $('#Region', parentObject).val() + '",';
    jsonString += '"WorkCityCode1":"' + $('#City', parentObject).val() + '",';

    jsonString += '"Industry1":"' + $('#Industry', parentObject).val() + '",';
    jsonString += '"IndustrySub1":"' + $('#IndustrySub', parentObject).val() + '",';

    jsonString += '"Part1":"' + $('#Part', parentObject).val() + '",';
    jsonString += '"PartSub1":"' + $('#PartSub', parentObject).val() + '",';

    jsonString += '"Title":"' + $('#textfield', parentObject).val() + '",';

    if (jsonString.substring(jsonString.length - 1, jsonString.length) == ',')
        jsonString = jsonString.substring(0, jsonString.length - 1);

    jsonString += "}";
    return jsonString;
}

// 取得子鄕鎮
function getSubCityList(el, target) {
    var objCountry = el;
    var guidCountryId = $('#' + objCountry.id + ' :selected').val();

    $.getJSON("/Job/getCityCode?a=" + encodeURI(new Date()), { CountryId: guidCountryId }, function(data) {
        var optionHtml = '<option>請選擇鄉鎮</option>'
        $.each(data, function(index, optionData) {
            optionHtml = optionHtml + '<option value="' + optionData.Value + ' ">' + optionData.Text + '</option>'
        });
        $(target).html(optionHtml);
    });
}  
