document.write('<script src="http://storage.tvlplus.net/js/ecl.js" type="text/javascript" ></script>');
document.write('<script src="http://storage.tvlplus.net/js/prototype.js" type="text/javascript" ></script>');

function CookieRestore() {
	if (window.confirm("車中泊場所マップの設定を復元します。現在の設定は失われ新しい設定に変わりますがよろしいですか？")) {
		var textAreaValue = document.restore.cookietext.value;
		textAreaValue = textAreaValue.replace(/¥r¥n?/g,"¥n");
		var errString = "";
		var ckCount = 0;
		var textArray = new Array();
		if (textAreaValue.match(/\n/)) {
			textArray = textAreaValue.split("\n");
		} else {
			textArray[0] = textAreaValue;
		}
		for(i=0; i<textArray.length; i++) {
			if (textArray[i]) {
				textLineArray = textArray[i].split(":::::");
				textLineArray[0] = textLineArray[0].replace(":::", "");
				if (textLineArray[0] == "SMAPC" || textLineArray[0] == "SMKST" || textLineArray[0] == "SMKML" || textLineArray[0] == "SWINS") {
					if (!textLineArray[1].match(/:::SMAPC/) && !textLineArray[1].match(/:::SMKST/) && !textLineArray[1].match(/:::SMKML/) && !textLineArray[1].match(/:::SWINS/)) {
						WriteCookie(textLineArray[0],textLineArray[1],'183');
						ckCount = ++ckCount;
					} else {
						errString = "※異常があったためCookieの更新は完了しませんでした。";
					}
				} else {
					errString = "※異常があったためCookieの更新は完了しませんでした。";
				}
			}
		}
		if (!ckCount && !errString) {
			errString = "有効なCookieが存在しませんでした。";
		}
		if (!errString && ckCount) {
			errString = "※Cookieは正常に更新されました。";
			document.getElementById("regist_form").style.backgroundColor = "#EFEFEF";
		} else {
			document.getElementById("regist_form").style.backgroundColor = "#FFB3B0";
		}
		document.getElementById("restore_msg").innerHTML = errString;
	}
}

function WriteCookie(key, value, days) {
	var str = key + "=" + escape(value) + ";";
	if (days != 0) {
		c_date = new Date();
		n = c_date.getTime() + 1000*60*60*24*days;
		c_date.setTime(n);
		kigen = c_date.toGMTString();
		str += "expires=" + kigen + ";path=/";
	}
	document.cookie = str;
}

function CreatKml(cookieAmLatlng,cookieSmkst) {
	var amLatlngArray = new Array();
	var smkstArray = new Array();
	var kmlString = "";
	if (cookieSmkst) {
		smkstArray = cookieSmkst.split("<>");
	}
	if (cookieAmLatlng) {
		kmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<kml creator=\"syachuhaku express http://syahak.tvlplus.net\" xmlns=\"http://www.opengis.net/kml/2.2\">\n<Document>\n<name>ここにドキュメントタイトルを入れて下さい</name>\n";
		amLatlngArray = cookieAmLatlng.split(":");
		for (im=0; im<amLatlngArray.length; im++) {
			if (amLatlngArray[im]) {
				stringAm = htmlspecialchars(UnescapeUTF8(smkstArray[im]).stripTags());
				LatlngAm = amLatlngArray[im].split(",");
				kmlString += "<Placemark>\n<name>" + stringAm +"</name>\n<Point>\n<coordinates>" + LatlngAm[1] + "," + LatlngAm[0] + "</coordinates>\n</Point>\n</Placemark>\n";
			}
		}
		kmlString += "</Document>\n</kml>\n";
		var objTextarea = document.getElementsByName('kmltext')[0]; 
		objTextarea.value = kmlString;
	}
}

function htmlspecialchars(ch) { 
	ch = ch.replace(/&/g,"&amp;") ;
	ch = ch.replace(/"/g,"&quot;") ;
	ch = ch.replace(/'/g,"&apos;") ;
	ch = ch.replace(/</g,"&lt;") ;
	ch = ch.replace(/>/g,"&gt;") ;
	return ch ;
}
