
var img_path=[];

function requestFile(fileName) {
	//alert("requestFile");
    var xmlHttpReq = createHttpRequest();

    xmlHttpReq.open("GET", fileName ,true)

    xmlHttpReq.onreadystatechange = function() {
		//alert("event:onreadystatechange:"+xmlHttpReq.readyState);
        if (xmlHttpReq.readyState==4) {
			//alert("load complete");
            var resultStr = "";
            var xmlData = xmlHttpReq.responseText;
			/*
			alert("res text="+xmlHttpReq.responseText);
			
			alert(xmlHttpReq.responseXML);
			alert(xmlData);
			var userData = xmlData.getElementsByTagName("img_path");
			
			alert(userData.length);
			
			
            for (var i = 0 ;i<userData.length ;i++) {
               img_path.push(userData[i].childNodes[0].nodeValue);
			}
			*/
			img_path = xmlData.split(",");
            //alert(img_path.length);
			n = Math.floor(Math.random()*(img_path.length-1));
			var h2_title = document.getElementsByTagName("h2")[ 0 ];
			var url_path;
			switch( document.URL){
				case "http://iroha-web.jp/":
				case "http://iroha-web.jp/index.php":
				case "http://iroha-web.jp/changemode.html":
				case "http://www.iroha-web.jp/":
				case "http://www.iroha-web.jp/index.php":
				case "http://www.iroha-web.jp/changemode.html":
					url_path = "./_common2/img/title/";
					break;
				default:
					url_path= "../_common2/img/title/";
					break;
			}
			h2_title.style.backgroundImage="url("+ url_path +img_path[n]+")";
        }
    }

    xmlHttpReq.send(null)
}

function createHttpRequest() {
    var x = null;

    //IE7,Firefox, Safari
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }

    //IE6
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        // IE5
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            x = null;
        }
    }
    return x;
}

var date2 = new Date();
var url = "http://iroha-web.jp/_common2/php/titlelist.php?"+date2.getTime();
requestFile(url);
