function ecnGetProductData(pid,callbackfunc){
	if( callbackfunc == null )
		sendGetRequest("API/GetProductData?pid=" + pid, ecnGetProductDataCB);
	else
		sendGetRequest("API/GetProductData?pid=" + pid, callbackfunc);
}

function ecnGetProductDataCB(restext){
	var product = eval('(' + restext + ')');
	var pname = document.getElementById("proshop.product.name");
	pname.innerHTML = product.name;
	var pprice = document.getElementById("proshop.product.price");
	pprice.innerHTML = product.price;
	var pcomment = document.getElementById("proshop.product.comment");
	pcomment.innerHTML = product.comment;
}

function ecnPostalCodeToAddress(pc1,pc2){
	sendGetRequest('API/PostalCodeToAddress?pc1='+pc1+'&pc2='+pc2, ecnPostalCodeToAddressCB);
}
function ecnPostalCodeToAddressCB(restext){
	var adrs = eval('(' + restext + ')');
	var prefid = document.getElementById('prefid');
	var address1 = document.getElementById('address1');
	var address2 = document.getElementById('address2');
	if (adrs.prefid != undefined) {
		prefid.value = adrs.prefid;
	} else {
		prefid.value = "0";
	}
	if (adrs.address1 != undefined) {
		address1.value = adrs.address1;
	} else {
		address1.value = "";
	}
	if (adrs.address2 != undefined) {
		address2.value = adrs.address2;
	} else {
		address2.value = "";
	}
}

function ecnPostalCodeToDeliAddress(pc1,pc2){
	sendGetRequest('API/PostalCodeToAddress?pc1='+pc1+'&pc2='+pc2, ecnPostalCodeToDeliAddressCB);
}
function ecnPostalCodeToDeliAddressCB(restext){
	var adrs = eval('(' + restext + ')');
	var prefid = document.getElementById('deliPrefId');
	var address1 = document.getElementById('deliAddress1');
	var address2 = document.getElementById('deliAddress2');
	if (adrs.prefid != undefined) {
		prefid.value = adrs.prefid;
	} else {
		prefid.value = "0";
	}
	if (adrs.address1 != undefined) {
		address1.value = adrs.address1;
	} else {
		address1.value = "";
	}
	if (adrs.address2 != undefined) {
		address2.value = adrs.address2;
	} else {
		address2.value = "";
	}
}


//汎用関数---------------------------------------------------------

function createXMLHttpRequest(){
	var xmlhttp = null;
	if(window.ActiveXObject){
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xmlhttp = null;
			}
		}
	}
	if( xmlhttp == null ){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function sendGetRequest(url,callbackfunc){
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp) {
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				callbackfunc(xmlhttp.responseText);
			}
		}
		xmlhttp.send(null);
	}
}

function sendGetRequestCommand(url){
	var xmlhttp = createXMLHttpRequest();
	if (xmlhttp) {
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				eval(xmlhttp.responseText);
			}
		}
		xmlhttp.send(null);
	}
}

//postdata = "key1=value1&key2=value2&key3=value3";
function sendPostRequestCommand(url,postdata){
	var xmlhttp = createXMLHttpRequest();
	if(!xmlhttp){
		return;
	}

	xmlhttp.open("POST", url , true);
	xmlhttp.onreadystatechange = function() {
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
			eval(xmlhttp.responseText);
		}
	}
	xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp.send(postdata);
}

//postdata = "key1=value1&key2=value2&key3=value3";
function sendPostRequest(url,postdata,callbackfunc){
	var xmlhttp = createXMLHttpRequest();
	if(!xmlhttp){
		return;
	}

	xmlhttp.open("POST", url , true);
	xmlhttp.onreadystatechange = function() {
		if( xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
			callbackfunc(xmlhttp.responseText);
		}
	}
	xmlhttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	xmlhttp.send(postdata);
}

//新規ウィンドウ　在庫・価格一覧
function OpenWin0001(pi){
    win1=window.open("pspi"+pi+".html","new0001","width=700,height=500,resizable=yes,scrollbars=yes");
}

//新規ウィンドウ　マイリストとは？
function OpenWin0002(){
    win1=window.open("guide_mylist.html","new0001","width=550,height=500,resizable=yes,scrollbars=yes");
}

//新規ウィンドウ　倉庫置きについて
function OpenWin0003(){
    win1=window.open("guide_warehouse.html","new0001","width=550,height=500,resizable=yes,scrollbars=yes");
}

// 閉じるボタン
function CloseWin(){
    window.close();
}

// リンクの処理開始
function disp(url){

if(!window.opener || window.opener.closed){ // メインウィンドウの存在をチェック
window.alert('メインウィンドウが閉じられています。サイトへアクセスしてください。'); // 存在しない場合は警告ダイアログを表示
}
else{
window.opener.location.href = url; // 存在する場合はページを切りかえる
}

}

