
// キーワード登録処理変数
var xmlHttp_keywordIns;
var urlBack_keywordIns;

// キーワード登録処理
function InsKeywordData(url,backurl,mypdid){

	if(window.confirm('キーワードを登録します。')){

		// 戻るURLの保持
		urlBack_keywordIns = backurl;

		// キーワードIDの取得
		var strIds = "";
		for(i = 0; i < arInputlist.keyword.length; i++){
			if(i != 0){
				strIds += ",";
			}
			strIds += arInputlist.keyword[i].value;
		}

		// フリーキーワードの取得
		var strNames = "";
		for(i = 0; i < arInputlist_free.keyword.length; i++){
			if(i != 0){
				strNames += ",";
			}
			strNames += arInputlist_free.keyword[i].text;
		}

		// ブラウザに対応したオブジェクトを取得
		xmlHttp_keywordIns = null;
		if(window.XMLHttpRequest){
			xmlHttp_keywordIns = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			try{
				xmlHttp_keywordIns = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				xmlHttp_keywordIns = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

		// オブジェクトの取得のチェック
		if(xmlHttp_keywordIns != null) {
			// URLの取得
			var strReqUrl = url;
			//strReqUrl = strReqUrl.replace("?", "/?");

			// データ取得完了時のイベント設定
			xmlHttp_keywordIns.onreadystatechange = eventKeywordData;
			xmlHttp_keywordIns.open("POST", strReqUrl, true);
			xmlHttp_keywordIns.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 
			xmlHttp_keywordIns.send("post_mypdid=" + mypdid + "&post_keyids=" + strIds + "&post_keynames=" + encodeURL(htmlDecode(strNames)) + "&_charset_=UTF-8");
			//xmlHttp_keywordIns.open("GET", strReqUrl, true);
			//xmlHttp_keywordIns.send(null);
		}else{
			alert("error");
		}
	}
}

// キーワード登録処理完了時
function eventKeywordData(){
	// 結果を取得した場合
	if (xmlHttp_keywordIns.readyState == 4 && xmlHttp_keywordIns.status == 200){
		// URLを更新します
		window.open(urlBack_keywordIns, '_self');
	}
}

// キーワード削除処理変数
var xmlHttp_keywordDel;
var urlBack_keywordDel;

// キーワード削除処理
function DelKeywordData(url,backurl,mypdid){
	// 戻るURLの保持
	urlBack_keywordDel = backurl;

	// キーワードIDの取得
	var strIds = "";
	var blnDel = false;
	for(i = 1; i <= document.keycheck.length; i++){
		if(!!document.keycheck['check' + i]){
			if(document.keycheck['check' + i].checked == true){
				if(!blnDel){
					blnDel = true;
				}else{
					strIds += ",";
				}
				strIds += document.keycheck['check' + i].value;
			}
		}
	}

	// フリーキーワード名の取得
	var strNames = "";
	var blnDel = false;
	for(i = 1; i <= document.keycheck.length; i++){
		if(!!document.keycheck['checkfree' + i]){
			if(document.keycheck['checkfree' + i].checked == true){
				if(!blnDel){
					blnDel = true;
				}else{
					strNames += ",";
				}
				strNames += document.keycheck['checkfree' + i].value;
			}
		}
	}

	// チェックされていない場合は動作しない
	if(strIds != "" || strNames != ""){

		// ブラウザに対応したオブジェクトを取得
		xmlHttp_keywordDel = null;
		if(window.XMLHttpRequest){
			xmlHttp_keywordDel = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			try{
				xmlHttp_keywordDel = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				xmlHttp_keywordDel = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}

		// オブジェクトの取得のチェック
		if(xmlHttp_keywordDel != null) {
			// URLの取得
			var strReqUrl = url;
			//strReqUrl = strReqUrl.replace("?", "/?");

			// データ取得完了時のイベント設定
			xmlHttp_keywordDel.onreadystatechange = eventKeywordDelData;
			xmlHttp_keywordDel.open("POST", strReqUrl, true);
			xmlHttp_keywordDel.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 
			xmlHttp_keywordDel.send("post_mypdid=" + mypdid + "&post_keyids=" + strIds + "&post_keynames=" + strNames + "&_charset_=UTF-8");
			//xmlHttp_keywordDel.open("GET", strReqUrl, true);
			//xmlHttp_keywordDel.send(null);
		}else{
			alert("error");
		}
	}
}

// キーワード削除処理完了時
function eventKeywordDelData(){
	// 結果を取得した場合
	if (xmlHttp_keywordDel.readyState == 4 && xmlHttp_keywordDel.status == 200){
		// URLを更新します
		window.open(urlBack_keywordDel, '_self');
	}
}

