/*
    builded time:2012/01/17 14:20:49
    建立region, country, city 3個關連式下拉選單所含之資料
*/
var j_area_map_grp_region = {};
var j_area_map_grp_country = {};
var j_area_map_grp_city = {};

// region mapping
j_area_map_grp_region = {"RE_CHINA":"港澳大陸","RE_ASIA_N":"東北亞","RE_ASIA_ES":"東南亞","RE_ASIA_S":"南亞中東","RE_ASIA_O":"亞洲其他","RE_EUROPE":"歐洲","RE_AMERICA":"美洲","RE_OCEANIA":"大洋洲","RE_AFRICA":"非洲"};

// country mapping
j_area_map_grp_country['RE_CHINA'] = {};
j_area_map_grp_country['RE_CHINA'] = {"RE_CHINA":"全區","CN_CHINA":"中國","CN_HONG KONG":"香港","CN_MACAU":"澳門"};
j_area_map_grp_country['RE_ASIA_N'] = {};
j_area_map_grp_country['RE_ASIA_N'] = {"RE_ASIA_N":"全區","CN_JAPAN":"日本","CN_KOREA":"韓國"};
j_area_map_grp_country['RE_ASIA_ES'] = {};
j_area_map_grp_country['RE_ASIA_ES'] = {"RE_ASIA_ES":"全區","CN_THAILAND":"泰國","CN_INDONESIA":"印尼、峇里島","CN_SINGAPORE":"新加坡","CN_PHILIPPINES":"菲律賓","CN_VIETNAM":"越南","CN_MALAYSIA":"馬來西亞","CN_CAMBODIA":"柬埔寨","CN_MYANMAR":"緬甸","CN_ASIA_ES_O":"東南亞其他"};
j_area_map_grp_country['RE_ASIA_S'] = {};
j_area_map_grp_country['RE_ASIA_S'] = {"RE_ASIA_S":"全區","CN_MALDIVES":"馬爾地夫","CN_INDIA":"印度","CN_TURKEY":"土耳其","CN_ARAB":"杜拜、阿布達比","CN_NEPAL":"尼泊爾","CN_SRI LANKA":"斯里蘭卡","CN_ISRAEL":"以色列、約旦","CN_ASIA_S_O":"南亞中東其他"};
j_area_map_grp_country['RE_ASIA_O'] = {};
j_area_map_grp_country['RE_ASIA_O'] = {"RE_ASIA_O":"全區","CN_RUSSIAN":"俄羅斯"};
j_area_map_grp_country['RE_EUROPE'] = {};
j_area_map_grp_country['RE_EUROPE'] = {"RE_EUROPE":"全區","CN_FRANCE":"法國","CN_ENGLAND":"英國","CN_GERMANY":"德國","CN_SWITZERLAND":"瑞士","CN_HOLLAND":"荷蘭","CN_CZECH":"捷克、奧匈","CN_ITALY":"義大利","CN_GREECE":"希臘","CN_SPAIN":"西班牙、葡萄牙","CN_EUROPE_N":"北歐","CN_EUROPE_O":"歐洲其他"};
j_area_map_grp_country['RE_AMERICA'] = {};
j_area_map_grp_country['RE_AMERICA'] = {"RE_AMERICA":"全區","CN_AMERICA":"美國","CN_CANADA":"加拿大","CN_AMERICA_O":"南美洲、美洲其他"};
j_area_map_grp_country['RE_OCEANIA'] = {};
j_area_map_grp_country['RE_OCEANIA'] = {"RE_OCEANIA":"全區","CN_AUSTRALIA":"澳洲","CN_NEW ZEALAND":"紐西蘭","CN_GUAM":"關島","CN_PALAU":"帛琉","CN_TAHITI":"大溪地"};
j_area_map_grp_country['RE_AFRICA'] = {};
j_area_map_grp_country['RE_AFRICA'] = {"RE_AFRICA":"全區","CN_EGYPT":"埃及","CN_KENYA":"東非,肯亞","CN_SOUTH AFRICA":"南非","CN_AFRICA_O":"非洲其他"};

// city mapping
j_area_map_grp_city['RE_CHINA'] = {};
j_area_map_grp_city['RE_CHINA'] = {"RE_CHINA":"全區"};
j_area_map_grp_city['CN_CHINA'] = {};
j_area_map_grp_city['CN_CHINA'] = {"CN_CHINA":"全區","CT_SHANGHAI":"江南(上海、蘇杭)","CT_BEIJING":"華北(北京、天津)","CT_CHENGDU":"四川(成都、九寨溝)","CT_HUNAN":"湖南(張家界、三峽)","CT_GUILIN":"廣西(桂林)","CT_GUANGDONG":"廣東(珠海、深圳)","CT_YUNNAN":"雲南(昆明、麗江)","CT_GUIYANG":"貴陽(黃果樹)","CT_XIAN":"西安(新疆、絲路)","CT_HARBIN":"東北(哈爾濱)","CT_ZHENGZHOU":"河南(鄭州、洛陽)","CT_QINGDAO":"山東(青島)","CT_TIBET":"西藏(拉薩)","CT_SANYA":"海南島(三亞)","CT_XIAMEN":"福建(廈門、武夷山)","CT_CHINA_O":"港澳大陸其他"};
j_area_map_grp_city['CN_HONG KONG'] = {};
j_area_map_grp_city['CN_HONG KONG'] = {"CN_HONG KONG":"全區"};
j_area_map_grp_city['CN_MACAU'] = {};
j_area_map_grp_city['CN_MACAU'] = {"CN_MACAU":"全區"};
j_area_map_grp_city['RE_ASIA_N'] = {};
j_area_map_grp_city['RE_ASIA_N'] = {"RE_ASIA_N":"全區"};
j_area_map_grp_city['CN_JAPAN'] = {};
j_area_map_grp_city['CN_JAPAN'] = {"CN_JAPAN":"全區","CT_TOKYO":"關東(東京)","CT_OSAKA":"關西(京、阪、神)","CT_NAGOYA":"名古屋(黑部立山)","CT_HOKKAIDO":"北海道(札幌)","CT_FUKUOKA":"福岡(宮崎)","CT_OKINAWA":"琉球(沖繩)","CT_SENDAI":"東北(仙台)","CT_HIROSHIMA":"廣島 (中國、四國)"};
j_area_map_grp_city['CN_KOREA'] = {};
j_area_map_grp_city['CN_KOREA'] = {"CN_KOREA":"全區","CT_SEOUL":"首爾","CT_JEJU":"濟州","CT_PUSAN":"釜山","CT_KOREA_O":"韓國其他"};
j_area_map_grp_city['RE_ASIA_ES'] = {};
j_area_map_grp_city['RE_ASIA_ES'] = {"RE_ASIA_ES":"全區"};
j_area_map_grp_city['CN_THAILAND'] = {};
j_area_map_grp_city['CN_THAILAND'] = {"CN_THAILAND":"全區","CT_BANGKOK":"曼谷","CT_PATAYA":"芭達雅","CT_PHUKET":"普吉島","CT_KO SAMUI":"蘇美島","CT_CHIANGMAI":"清邁","CT_THAILAND_O":"泰國其他"};
j_area_map_grp_city['CN_INDONESIA'] = {};
j_area_map_grp_city['CN_INDONESIA'] = {"CN_INDONESIA":"全區","CT_BALI":"峇里島","CT_BINTAN":"民丹島","CT_INDONESIA_O":"印尼其他(雅加達)"};
j_area_map_grp_city['CN_SINGAPORE'] = {};
j_area_map_grp_city['CN_SINGAPORE'] = {"CN_SINGAPORE":"全區"};
j_area_map_grp_city['CN_PHILIPPINES'] = {};
j_area_map_grp_city['CN_PHILIPPINES'] = {"CN_PHILIPPINES":"全區","CT_CEBU":"宿霧","CT_BORACAY":"長灘島","CT_MANILA":"馬尼拉","CT_PHILIPPINES_O":"菲律賓其他"};
j_area_map_grp_city['CN_VIETNAM'] = {};
j_area_map_grp_city['CN_VIETNAM'] = {"CN_VIETNAM":"全區","CT_HANOI":"北越(河內、下龍灣)","CT_HO CHI MINH CITY":"南越(胡志明市)","CT_HOIAN":"中越(會安)"};
j_area_map_grp_city['CN_MALAYSIA'] = {};
j_area_map_grp_city['CN_MALAYSIA'] = {"CN_MALAYSIA":"全區","CT_LUMPUR":"吉隆坡","CT_PENANG":"檳城","CT_LANGKAWI":"蘭卡威","CT_SABAH":"亞庇(沙巴)","CT_MALAYSIA_O":"馬來西亞其他"};
j_area_map_grp_city['CN_CAMBODIA'] = {};
j_area_map_grp_city['CN_CAMBODIA'] = {"CN_CAMBODIA":"全區","CT_SIEMREAP":"吳哥窟","CT_PHNOMPENH":"金邊"};
j_area_map_grp_city['CN_MYANMAR'] = {};
j_area_map_grp_city['CN_MYANMAR'] = {"CN_MYANMAR":"全區"};
j_area_map_grp_city['CN_ASIA_ES_O'] = {};
j_area_map_grp_city['CN_ASIA_ES_O'] = {"CN_ASIA_ES_O":"全區"};
j_area_map_grp_city['RE_ASIA_S'] = {};
j_area_map_grp_city['RE_ASIA_S'] = {"RE_ASIA_S":"全區"};
j_area_map_grp_city['CN_MALDIVES'] = {};
j_area_map_grp_city['CN_MALDIVES'] = {"CN_MALDIVES":"全區"};
j_area_map_grp_city['CN_INDIA'] = {};
j_area_map_grp_city['CN_INDIA'] = {"CN_INDIA":"全區"};
j_area_map_grp_city['CN_TURKEY'] = {};
j_area_map_grp_city['CN_TURKEY'] = {"CN_TURKEY":"全區"};
j_area_map_grp_city['CN_ARAB'] = {};
j_area_map_grp_city['CN_ARAB'] = {"CN_ARAB":"全區"};
j_area_map_grp_city['CN_NEPAL'] = {};
j_area_map_grp_city['CN_NEPAL'] = {"CN_NEPAL":"全區"};
j_area_map_grp_city['CN_SRI LANKA'] = {};
j_area_map_grp_city['CN_SRI LANKA'] = {"CN_SRI LANKA":"全區"};
j_area_map_grp_city['CN_ISRAEL'] = {};
j_area_map_grp_city['CN_ISRAEL'] = {"CN_ISRAEL":"全區"};
j_area_map_grp_city['CN_ASIA_S_O'] = {};
j_area_map_grp_city['CN_ASIA_S_O'] = {"CN_ASIA_S_O":"全區"};
j_area_map_grp_city['RE_ASIA_O'] = {};
j_area_map_grp_city['RE_ASIA_O'] = {"RE_ASIA_O":"全區"};
j_area_map_grp_city['CN_RUSSIAN'] = {};
j_area_map_grp_city['CN_RUSSIAN'] = {"CN_RUSSIAN":"全區"};
j_area_map_grp_city['RE_EUROPE'] = {};
j_area_map_grp_city['RE_EUROPE'] = {"RE_EUROPE":"全區"};
j_area_map_grp_city['CN_FRANCE'] = {};
j_area_map_grp_city['CN_FRANCE'] = {"CN_FRANCE":"全區"};
j_area_map_grp_city['CN_ENGLAND'] = {};
j_area_map_grp_city['CN_ENGLAND'] = {"CN_ENGLAND":"全區"};
j_area_map_grp_city['CN_GERMANY'] = {};
j_area_map_grp_city['CN_GERMANY'] = {"CN_GERMANY":"全區"};
j_area_map_grp_city['CN_SWITZERLAND'] = {};
j_area_map_grp_city['CN_SWITZERLAND'] = {"CN_SWITZERLAND":"全區"};
j_area_map_grp_city['CN_HOLLAND'] = {};
j_area_map_grp_city['CN_HOLLAND'] = {"CN_HOLLAND":"全區"};
j_area_map_grp_city['CN_CZECH'] = {};
j_area_map_grp_city['CN_CZECH'] = {"CN_CZECH":"全區"};
j_area_map_grp_city['CN_ITALY'] = {};
j_area_map_grp_city['CN_ITALY'] = {"CN_ITALY":"全區"};
j_area_map_grp_city['CN_GREECE'] = {};
j_area_map_grp_city['CN_GREECE'] = {"CN_GREECE":"全區"};
j_area_map_grp_city['CN_SPAIN'] = {};
j_area_map_grp_city['CN_SPAIN'] = {"CN_SPAIN":"全區"};
j_area_map_grp_city['CN_EUROPE_N'] = {};
j_area_map_grp_city['CN_EUROPE_N'] = {"CN_EUROPE_N":"全區"};
j_area_map_grp_city['CN_EUROPE_O'] = {};
j_area_map_grp_city['CN_EUROPE_O'] = {"CN_EUROPE_O":"全區"};
j_area_map_grp_city['RE_AMERICA'] = {};
j_area_map_grp_city['RE_AMERICA'] = {"RE_AMERICA":"全區"};
j_area_map_grp_city['CN_AMERICA'] = {};
j_area_map_grp_city['CN_AMERICA'] = {"CN_AMERICA":"全區","CT_AMERICA_E":"美東(紐約、波士頓)","CT_AMERICA_W":"美西(洛杉磯、舊金山)","CT_HAWAII":"夏威夷","CT_LASVEGAS":"拉斯維加斯","CT_ALASKA":"阿拉斯加","CT_AMERICA_O":"美國其他"};
j_area_map_grp_city['CN_CANADA'] = {};
j_area_map_grp_city['CN_CANADA'] = {"CN_CANADA":"全區","CT_VANCOUVER":"加西(溫哥華)","CT_TORONTO":"加東(多倫多)","CT_CANADA_O":"加拿大其他"};
j_area_map_grp_city['CN_AMERICA_O'] = {};
j_area_map_grp_city['CN_AMERICA_O'] = {"CN_AMERICA_O":"全區"};
j_area_map_grp_city['RE_OCEANIA'] = {};
j_area_map_grp_city['RE_OCEANIA'] = {"RE_OCEANIA":"全區"};
j_area_map_grp_city['CN_AUSTRALIA'] = {};
j_area_map_grp_city['CN_AUSTRALIA'] = {"CN_AUSTRALIA":"全區","CT_AUSTRALIA_E":"東澳(雪梨、布里斯本)","CT_AUSTRALIA_W":"西澳、澳洲其他"};
j_area_map_grp_city['CN_NEW ZEALAND'] = {};
j_area_map_grp_city['CN_NEW ZEALAND'] = {"CN_NEW ZEALAND":"全區","CT_NZ_SOUTH":"南島","CT_NZ_NORTH":"北島","CT_NZ_ALL":"南+北島"};
j_area_map_grp_city['CN_GUAM'] = {};
j_area_map_grp_city['CN_GUAM'] = {"CN_GUAM":"全區"};
j_area_map_grp_city['CN_PALAU'] = {};
j_area_map_grp_city['CN_PALAU'] = {"CN_PALAU":"全區"};
j_area_map_grp_city['CN_TAHITI'] = {};
j_area_map_grp_city['CN_TAHITI'] = {"CN_TAHITI":"全區"};
j_area_map_grp_city['RE_AFRICA'] = {};
j_area_map_grp_city['RE_AFRICA'] = {"RE_AFRICA":"全區"};
j_area_map_grp_city['CN_EGYPT'] = {};
j_area_map_grp_city['CN_EGYPT'] = {"CN_EGYPT":"全區"};
j_area_map_grp_city['CN_KENYA'] = {};
j_area_map_grp_city['CN_KENYA'] = {"CN_KENYA":"全區"};
j_area_map_grp_city['CN_SOUTH AFRICA'] = {};
j_area_map_grp_city['CN_SOUTH AFRICA'] = {"CN_SOUTH AFRICA":"全區"};
j_area_map_grp_city['CN_AFRICA_O'] = {};
j_area_map_grp_city['CN_AFRICA_O'] = {"CN_AFRICA_O":"全區"};


/*
    - 用途，建立region, country, city 3個關連式下拉選單, 並挷定 .change 動作
    
    - 以下 function 使用前請先插入 jquery
    
    - 使用方式 :
    呼叫:
        jf_default_grp_region()
    或
    jf_default_grp_region('region id名稱', 'country id名稱', 'city id名稱')
*/
var jq_ver = $().jquery;

function jf_default_grp_region(_dom_region, _dom_country, _dom_city)
{
    var target_region = _dom_region || 'region';
    var target_country = _dom_country || 'country';
    var target_city = _dom_city || 'city';    

    var obj =  $('select#' + target_region);
    
    obj.find('option').remove();
    obj.append('<option value="none">請選擇洲別</option>');
    
    if(typeof(j_area_map_grp_region) == 'undefined') return false;
        
    for(var i in j_area_map_grp_region) 
        obj.append('<option value="' + i + '">' + j_area_map_grp_region[i] + '</option>');

    obj.bind('change keypress', function() {
        jf_default_grp_country(target_region, target_country, target_city);
        jf_default_grp_city(target_region, target_country, target_city);
        });

    obj = null;
    return true;
}//^


function jf_default_grp_country(_dom_region, _dom_country, _dom_city)
{
    var target_region = _dom_region || 'region';
    var target_country = _dom_country || 'country';
    var target_city = _dom_city || 'city';
    var _tmp = '';
    
    var target_parent_key = $('select#' + target_region + ' option:selected').val();
    var obj =  $('select#' + target_country);
    
    obj.find('option').remove();
    obj.append('<option value="none">請選擇國家</option>');
    
    if(typeof(j_area_map_grp_country[target_parent_key]) == 'undefined') return false;
    
    for(var i in j_area_map_grp_country[target_parent_key]) 
    {
        if(j_area_map_grp_country[target_parent_key][i] == '全區') _tmp = ' selected="selected"';
        else _tmp = '';
        obj.append('<option value="' + i + '"' + _tmp + '>' + j_area_map_grp_country[target_parent_key][i] + '</option>');
    }

    obj.bind('change keypress', function() {jf_default_grp_city(target_region, target_country, target_city);});

    obj = null;
    return true;
}//^


function jf_default_grp_city(_dom_region, _dom_country, _dom_city)
{
    var target_region = _dom_region || 'region';
    var target_country = _dom_country || 'country';
    var target_city = _dom_city || 'city';
    var _tmp = '';
    
    var target_parent_key = $('select#' + target_country + ' option:selected').val();
    var obj =  $('select#' + target_city);
    
    obj.find('option').remove();
    obj.append('<option value="none">請選擇城市</option>');
    
    
    if(typeof(j_area_map_grp_city[target_parent_key]) == 'undefined')
    {
        obj.hide();
        return false;
    }
    
    var amount = 0;
    for(var i in j_area_map_grp_city[target_parent_key]) 
    {
        if(j_area_map_grp_city[target_parent_key][i] == '全區') _tmp = ' selected="selected"';
        else _tmp = '';
        obj.append('<option value="' + i + '"' + _tmp + '>' + j_area_map_grp_city[target_parent_key][i] + '</option>');
        amount++;
    }

    
    if(amount > 1) obj.show();
    else 
    {
        obj.hide();
        //obj.find('option').eq(1).attr('selected', 'selected');
        
        if(jq_ver.indexOf('1.5') >= 0)
            obj.find('option').eq(1).attr('selected', true);
        
        if(jq_ver.indexOf('1.6') >= 0)
            obj.find('option').eq(1).prop('selected', true);

    }
    
    obj = null;
    return true;
}//^
