var michi_url = 'http://routeguide.jp/modules/spot'; 
var michi_url2 = 'http://beta.routeguide.jp/modules/spot'; 
var help_url = michi_url + '/../pico/?content_id=12&noheader=1'; 
var mukou_url = michi_url + '/../pico/index.php?content_id=16&noheader=1';

function syuuhen_parts_generate(target_url, syuuhen_uid, syuuhen_r, syuuhen_u, syuuhen_p, syuuhen_t, syuuhen_o, syuuhen_m, syuuhen_target_spot_kbn, syuuhen_target_spot_url, syuuhen_width, syuuhen_height){
    if(syuuhen_target_spot_kbn == 1){
        var syuuhen_encode_url = encodeURIComponent(location.href); 
    }else{
        var syuuhen_encode_url = encodeURIComponent(syuuhen_target_spot_url); 
    }

/*
    syuuhen_parts_str = "" +
     "<IFRAME WIDTH=\""+syuuhen_width+"\" HEIGHT=\""+syuuhen_height+"\" SRC=\"" + target_url + "/?page=syuuhen_map&url=" + syuuhen_encode_url + "&u=" + syuuhen_u + "&p=" + syuuhen_p + "&t=" + syuuhen_t + "&o=" + syuuhen_o + "&m=" + syuuhen_m + "&uid=" + syuuhen_uid + "&w=" + syuuhen_width + "&h=" + syuuhen_height + "id=\"syuuhen_map\" frameborder=\"no\" scrolling=\"no\" frameborder=\"no\" scrolling=\"no\" ></IFRAME>";
*/
    syuuhen_parts_str = "" +
     "<IFRAME WIDTH=\""+syuuhen_width+"\" HEIGHT=\""+syuuhen_height+"\" SRC=\"" + target_url + "/?page=syuuhen_map&url=" + 
      syuuhen_encode_url + "&u=" + syuuhen_u + "&p=" + syuuhen_p + "&t=" + syuuhen_t + "&o=" + syuuhen_o + "&m=" + syuuhen_m + "&uid=" + syuuhen_uid + "&w=" + syuuhen_width + "&h=" + syuuhen_height + "id=\"syuuhen_map\" frameborder=\"no\" scrolling=\"no\" frameborder=\"no\" scrolling=\"no\" ></IFRAME>";

    if(syuuhen_target_spot_url){
        document.getElementById("syuuhen_" + syuuhen_target_spot_url).innerHTML = syuuhen_parts_str;
    }else{
        document.getElementById("syuuhen_parts_wrtgde").innerHTML = syuuhen_parts_str;
    }
}

function syuuhen_parts_preview_generate(target_url, syuuhen_uid, syuuhen_r, syuuhen_u, syuuhen_p, syuuhen_t, syuuhen_o, syuuhen_m, syuuhen_target_spot_kbn, syuuhen_target_spot_url, syuuhen_width, syuuhen_height){

    var syuuhen_encode_url = encodeURIComponent(syuuhen_target_spot_url); 

    syuuhen_parts_str = "" +
     "<IFRAME WIDTH=\""+syuuhen_width+"\" HEIGHT=\""+syuuhen_height+"\" SRC=\"" + target_url + "/?page=syuuhen_map&url=" + 
      syuuhen_encode_url + "&u=" + syuuhen_u + "&p=" + syuuhen_p + "&t=" + syuuhen_t + "&o=" + syuuhen_o + "&m=" + syuuhen_m + "&uid=" + syuuhen_uid + "&w=" + syuuhen_width + "&h=" + syuuhen_height + "id=\"syuuhen_map\" frameborder=\"no\" scrolling=\"no\" frameborder=\"no\" scrolling=\"no\" ></IFRAME>";

    document.getElementById("syuuhen_parts_wrtgde").innerHTML = syuuhen_parts_str;
}


function syuuhen_include(astrFile){
    var script = document.createElement('script');
    script.src = astrFile;
    script.charset = 'utf-8';
    script.type = 'text/javascript';
    script.defer = true;
    document.getElementsByTagName('head').item(0).appendChild(script);
}


var map_dofile = michi_url + '/js/syuuhen_dummy.js';
var map_dofile2 = michi_url2 + '/js/syuuhen_dummy.js';
var map_tmrID;
var map_tmrID2;
var map_max_cnt = 10;
var map_cnt = 0;
var map_cnt2 = 0;
var map_timespan = 500;
var map_OK = 200;

function syuuhen_GetDataFromSvr() {
    if(map_cnt < map_max_cnt){
        syuuhen_include(map_dofile);

        if(syuuhen_status == map_OK){

            syuuhen_parts_generate(michi_url, syuuhen_uid, syuuhen_r, syuuhen_u, syuuhen_p, syuuhen_t, syuuhen_o, syuuhen_m, syuuhen_target_spot_kbn, syuuhen_target_spot_url, syuuhen_width, syuuhen_height);
            clearInterval(map_tmrID);
        }

        map_cnt++;
    }else{
        clearInterval(map_tmrID);
        map_tmrID2 = setInterval("syuuhen_GetDataFromSvr2()", map_timespan);
    }
}

function syuuhen_GetDataFromSvr2() {
    if(map_cnt2 < map_max_cnt){
        syuuhen_include(map_dofile2);

        if(syuuhen_status == map_OK){

            syuuhen_parts_generate(michi_url2, syuuhen_uid, syuuhen_r, syuuhen_u, syuuhen_p, syuuhen_t, syuuhen_o, syuuhen_m, syuuhen_target_spot_kbn, syuuhen_target_spot_url, syuuhen_width, syuuhen_height);
            clearInterval(map_tmrID2);
        }

        map_cnt2++;
    }else{
        clearInterval(map_tmrID2);
        maintenance_server();
    }
}

function maintenance_server(){
    var maintenance_msg = '<input type="hidden" value="maintenance">';

    if(syuuhen_target_spot_url){
        document.getElementById("syuuhen_" + syuuhen_target_spot_url).innerHTML = maintenance_msg;
    }else{
        document.getElementById("syuuhen_parts_wrtgde").innerHTML = maintenance_msg;
    }
}

function syuuhen_HttpInit(){

    //新規パラメタの存在チェック（旧パーツ対応）
    if(typeof(syuuhen_u) == "undefined") syuuhen_u = "";
    if(typeof(syuuhen_p) == "undefined") syuuhen_p = "";
    if(typeof(syuuhen_o) == "undefined") syuuhen_o = "";
    if(typeof(syuuhen_m) == "undefined") syuuhen_m = "";

    map_tmrID = setInterval("syuuhen_GetDataFromSvr()", map_timespan);
}

