function getAreaString(code) {
	var areaCode = new Array("5010",   "5020",   "5030",   "5040",   "5110",   "5113",     "5114",     "5115",     "5116",       "5117",         "5120",   "5123",         "5124",       "5125",       "5310",   "5320", "2321101", "2321102");
	var areaName = new Array("中部",   "伊豆",   "東部",   "西部",   "西部",   "尾張東部", "尾張西部", "知多地域", "西三河南部", "西三河北西部", "東部",   "西三河北東部", "東三河北部", "東三河南部", "北中部", "南部", "豊田市西部", "豊田市東部");
	var prefName = new Array("静岡県", "静岡県", "静岡県", "静岡県", "愛知県", "愛知県",   "愛知県",   "愛知県",   "愛知県",     "愛知県",       "愛知県", "愛知県",       "愛知県",     "愛知県",     "三重県", "三重県", "愛知県", "愛知県");
//	var pointName = new Array("静岡",  "石廊崎", "三島",   "浜松",   "名古屋", "豊橋", "津", "尾鷲");

	for (var i = 0; i < areaCode.length; i++) {
		if (areaCode[i] == code) {
			var arr = new Array(3);//080319 19:41修正
			arr[0] = prefName[i] + " " + areaName[i];//080319 19:41修正
			arr[1] = prefName[i];//080319 19:41修正
			arr[2] = areaName[i];//080319 19:41修正
			return arr;//080319 19:41修正
		}
	}
	return "";
	
}

function getAlertName(code) {
	var alertCode = new Array(
						"00"
						, "01"
						, "02"
						, "03"
						, "04"
						, "05"
						, "06"
						, "07"
						, "08"
						, "09"
						, "10"
						, "11"
						, "12"
						, "13"
						, "14"
						, "15"
						, "16"
						, "17"
						, "18"
						, "19"
						, "20"
						, "21"
						, "22"
						, "23"
						, "24"
						, "25"
						, "26"
	);
	var alertName = new Array(
						"解除"
						, ""
						, "暴風雪警報"
						, "大雨警報"
						, "洪水警報"
						, "暴風警報"
						, "大雪警報"
						, "波浪警報"
						, "高潮警報"
						, ""
						, "大雨注意報"
						, ""
						, "大雪注意報"
						, "風雪注意報"
						, "雷注意報"
						, "強風注意報"
						, "波浪注意報"
						, "融雪注意報"
						, "洪水注意報"
						, "高潮注意報"
						, "濃霧注意報"
						, "乾燥注意報"
						, "なだれ注意報"
						, "低温注意報"
						, "霜注意報"
						, "着氷注意報"
						, "着雪注意報"
	);
	for (var i = 0; i < alertCode.length; i++) {
		if (alertCode[i] == code) {
			return alertName[i];
		}
	}
	return "";
}

function AreaAlert() {
	this.listCount = 0;
	this.code = new Array();
	this.name = new Array();

	this.getListCount = function() {
		return this.listCount;
	}
	this.setListCount = function(value) {
		this.listCount = value;
	}
	this.getCode = function() {
		return this.code;
	}
	this.setCode = function(value) {
		this.code = value;
	}
	this.getName = function() {
		return this.name;
	}
	this.setName = function(value) {
		this.name = value;
	}
}

function AreaData() {
	this.alertDate = "";
	this.code = "";
	this.name = "";
	this.areaName = "";//080319修正
	this.areaAlert = new AreaAlert();
	
	this.getAlertDate = function() {
		return this.alertDate;
	}
	this.setAlertDate = function(value) {
		this.alertDate = value;
	}
	this.getCode = function() {
		return this.code;
	}
	this.setCode = function(value) {
		this.code = value;
	}
	this.getAreaName = function() {
		return this.areaName;//080319修正
	}
	this.setAreaName = function(value) {
		this.areaName = value;//080319修正
	}
	this.getName = function() {
		return this.name;
	}
	this.setName = function(value) {
		this.name = value;
	}
	this.getAreaAlert = function() {
		return this.areaAlert;
	}
	this.setAreaAlert = function(value) {
		this.areaAlert = value;
	}
}


function WeatherAlertData() {
	this.stationCode = null;
	this.stationName = null;
	this.areaData = null;
	this.origData = null;//080320追加
	this.init = function(xml) {
		this.stationCode = "";
		this.stationName = "";
		this.areaData = new Array();
		var headerList = xml.getElementsByTagName('prodIdInfo');
		for (i = 0; i < headerList[0].childNodes.length; i++) {
			var child = headerList[0].childNodes[i];
			if (!child.tagName) {
				continue;
			}
			if (child.tagName == 'stationCode') {
				if(child.firstChild) {
					this.stationCode = child.firstChild.nodeValue;
				}
			}
			if (child.tagName == 'origStation') {
				if(child.firstChild) {
					this.stationName = child.firstChild.nodeValue;
				}
			}
		}

		var origList = xml.getElementsByTagName('origData');
		var origLen = origList.length;
		if(origLen){
			this.origData = origList[0].firstChild.nodeValue;
		}
		
		this.listCount = xml.getElementsByTagName('area').length;
		var dataList = xml.getElementsByTagName('area');
var dateFormat = new DateFormat("yyyy-MM-ddTHH:mm:ss+09:00");

		for (i = 0; i < this.listCount; i++) {
			var area = new AreaData();
			area.setCode(dataList[i].getAttribute('areaCode'));
			area.setName(getAreaString(dataList[i].getAttribute('areaCode'))[0]);//080319修正 添え字を追加
			area.setAreaName(getAreaString(dataList[i].getAttribute('areaCode'))[2]);//080319修正 添え字を追加
			for (j = 0; j < dataList[i].childNodes.length; j++) {
				var child = dataList[i].childNodes[j];
				if (!child.tagName) {
					continue;
				}
				if (child.tagName == 'alert') {
					if(child.firstChild) {
						var alert = new AreaAlert();
						var categoryCode = new Array();
						var categoryName = new Array();
						var categoryCount = 0;
						area.setAlertDate(child.getAttribute('time'));
// convert date
var data = child.getAttribute('time');
var dt = dateFormat.parse(data);
//console.log(dt);
//dt.setTime(dt.getTime() + (1000 * 60 * 60 * 9));	// add 9 hour
						area.setAlertDate((dt.getYear() + (dt.getYear() < 1000 ? 1900 : 0)) + "/" + (dt.getMonth()+1) + "/" + dt.getDate() + " " + dt.getHours() + ":" + dt.getMinutes());

						for (k = 0; k < child.childNodes.length; k++) {
							var child2 = child.childNodes[k];
							if (!child2.tagName) {
								continue;
							}
							if (child2.tagName == 'alertCategory') {
								categoryCode[categoryCount] = child2.firstChild.nodeValue;
								categoryName[categoryCount] = getAlertName(child2.firstChild.nodeValue);
								categoryCount++;
							}
						}
						alert.setListCount(categoryCount);
						alert.setCode(categoryCode);
						alert.setName(categoryName);
						area.setAreaAlert(alert);
					}
				}
			}
			this.areaData[i] = area;
		}

	}
	
	this.getListCount = function() {
		return this.areaData.length;
	}
	this.getStationCode = function() {
		return this.stationCode;
	}
	this.getStationName = function() {
		return this.stationName;
	}
	this.getOrigData = function() {
		return this.origData;
	}
	this.getAreaData = function() {
		return this.areaData;
	}
}
