﻿function ajaxMake() {
	var ajax = false;
	if (window.XMLHttpRequest) {
		ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			ajax = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			ajax = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	return ajax;
}

/*--------------------------------------------------*/
/*	郵便番号から住所取得
/*--------------------------------------------------*/
function getAddress() {
	var ajax = ajaxMake();
	var zip1 = document.getElementById('ctl00_cphMainContent_txtCustomZipCode1').value;
	var zip2 = document.getElementById('ctl00_cphMainContent_txtCustomZipCode2').value;
	ajax.open('GET', '/js/data/getAddress.aspx?zip=' + zip1 + zip2, true);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			setAddress(ajax.responseText);
		}
	}
	ajax.send(null);
	return false;
}

function setAddress(AddressString) {
	if (AddressString != '') {
		var datAddress, aryAddress;
		datAddress = AddressString.split('&');
		document.getElementById('ctl00_cphMainContent_drpCustomPref').value = datAddress[0];
		//document.getElementById('ctl00_cphMainContent_txtCustomAddress1').value = datAddress[1];
		//document.getElementById('ctl00_cphMainContent_txtCustomAddress2').value = datAddress[2];
		// 簡易版に住所2が存在しないので、1に集約
		document.getElementById('ctl00_cphMainContent_txtCustomAddress1').value = datAddress[1] + datAddress[2];
		return true;
	} else {
		return false;
	}
}


/*--------------------------------------------------*/
/*	どこどこ都道府県を基にデータ取得
/*		type設定
/*			'car':		注目車
/*			'shop':		注目店舗
/*			'campaign':	キャンペーン
/*			'blog':		スタッフブログ
/*--------------------------------------------------*/
function getDoco(pref, type) {
	var ajax = ajaxMake();
	ajax.open('GET', '/js/data/getDoco.aspx?pref=' + pref + '&type=' + type, true);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			setDoco(ajax.responseText,type);
		}
	}
	ajax.send(null);
}

function setDoco(DocoString, type) {
	if (DocoString != '') {
		document.getElementById('doco_' + type).innerHTML = DocoString;
	}
	return false;
}

