/* ヘルパー関数：　createXMLHttpRequest */
function writeLinkInLococom(linklocation, classstyle) {
    var URLREADER = new URLReader('/AjaxGetLinkinlococominfoRandom.next?linklocation=' + linklocation + '&classstyle=' + classstyle, 'GET');
    URLREADER.read();
    var GETTERTEXT = URLREADER.getText();
    document.write(GETTERTEXT);
}

function writeLinkInLococomForTown(classstyle, localtopcatecd, localmidcatecd, localbtmcatecd) {
    var URLREADER = new URLReader('/AjaxGetLinkinlococominfofortown.next?topcd=' + localtopcatecd
     + '&midcd=' + localmidcatecd + '&btmcd=' + localbtmcatecd + '&classstyle=' + classstyle, 'GET');
    URLREADER.read();
    var GETTERTEXT = URLREADER.getText();
    document.write(GETTERTEXT);
}

function clickLink(linkseq) {
    document.location.href = '/RDTClickLink.next?linkseq=' + linkseq;
}

function clickLinkForTown(linkseq) {
    document.location.href = '/RDTClickLinkForTown.next?linkseq=' + linkseq;
}

function createXMLHttpRequest() {
    if(window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("MSXML2.XMLHTTP");
    } catch(e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch(f) {
            return null;
        }
    }
}

/* 擬似クラス：　URLReader */
function URLReader(url) {
    this.url = url;
    this.complete = false;
    this.req = createXMLHttpRequest();
    if(this.req === null) {
        throw new Error("Cannot create XMLHttpRequest.");
    }
    this.req.open("GET", this.url, false);	// 同期I/O
}

/* メソッド：　read() */
URLReader.prototype.read = function() {
    this.req.send("");
    if(this.req.status == 200 && this.req.readyState == 4) {
        this.complete = true;
    } else {
        this.complete = false;
        throw new Error("Cannot read from '" + this.url + "'.");
    }
};

/* メソッド：　getText() */
URLReader.prototype.getText = function() {
    if(this.complete) {
        return this.req.responseText;
    } else {
        return null;
    }
};


