function create_code(){
	var id1 = document.form_aff.id1.value;
	var target = document.form_aff.target.value;
	var save = document.form_aff.save.checked;
	if(!id1){
		alert('IDを入力してください');
		return;
	}else if(id1.length > 30){
		alert('IDの文字数を30文字以内にしてください');
		return;
	}else if(target.length > 30){
		alert('リンク表示先の文字数を30文字以内にしてください');
		return;
	}
	// 入力内容記録
	if(save){
		if(id1){ set_id1(id1); }
		if(target){ set_target(target); }
	}
	// コード生成
	var code = '';
	code += "<style><!--\n"
	code += "table.goods td{margin:0;padding:3px;border-bottom:1px #999999 solid;}\n"
	code += "div.g_title{margin:0 0 5px 0;padding:0;font-weight:bold;}\n"
	code += "div.g_price{margin:0;padding:0 0 10px 0;}\n"
	code += "span.g_price1{margin:0;padding:2px;color:#CC0000;font-size:13px;font-weight:bold;}\n"
	code += "span.g_price2{margin:0;padding:2px;font-size:11px;color:#666666;}\n"
	code += "div.g_capt{margin:0;padding:0;}\n"
	code += "div.g_shop{margin:0;padding:0;text-align: right;}\n"
	code += "span.g_capt2{display:none;}\n"
	code += "//--></style>\n"
	if(document.all){
		code += document.all.goods.innerHTML;
	}else{
		code += document.getElementById('goods').innerHTML;
	}
	code += '<a href="http://amstore.atools.jp/" style="color:#666666;">通販＆リンク生成 Atools</a>';
//	code = code.replace(/ title="[^"]+"/g,"");
//	code = code.replace(/ alt="[^"]+"/g,"");
	// ID置換え（単品用）
	code = code.replace(/plusi-22/ig,id1);
	// URL置き換え（一覧用）
	code = code.replace(/href=".+?\/g\/([\w]+?)"/ig,"href=\"http://www.amazon.co.jp/exec/obidos/ASIN/$1/ref=nosim/"+ id1 + "\"");
	// カートに入れる部分削除
	code = code.replace(/<form.+?<\/form>/ig,"");
	// target設定
	if(target){
		// これでは win ie が変換不可
	//	code = code.replace(/ target=".*?"/ig," target=\"" + target + "\"");
		// こちらで対応
		code = code.replace(/ target="?[^" >]*"?/ig," target=\"" + target + "\"");
	}
	// コード表示
	document.form_aff.code.value = code;
}

// cookie記録
function set_id1(id1){
	theName  = "id1";
	setDay = new Date();
	setDay.setTime(setDay.getTime()+(1000*60*60*24*365));
	expDay = setDay.toGMTString();
	document.cookie = theName + "="+escape(id1)+";path=/;expires="+expDay;
}
function set_target(target){
	theName  = "target";
	setDay = new Date();
	setDay.setTime(setDay.getTime()+(1000*60*60*24*365));
	expDay = setDay.toGMTString();
	document.cookie = theName + "="+escape(target)+";path=/;expires="+expDay;
}

// cookie呼び出し
function get_id1(){
	theName   = "id1=";
	theCookie = document.cookie+";";
	start = theCookie.indexOf(theName);
	if(start != -1){
		end = theCookie.indexOf(";",start);
		id1 = unescape(theCookie.substring(start+theName.length,end));
		document.form_aff.id1.value = id1;
	}
}
function get_target(){
	theName   = "target=";
	theCookie = document.cookie+";";
	start = theCookie.indexOf(theName);
	if(start != -1){
		end = theCookie.indexOf(";",start);
		target = unescape(theCookie.substring(start+theName.length,end));
		document.form_aff.target.value = target;
	}
}

window.onload = function(){
	get_id1();
	get_target();
};
