/**
 * 投稿フローへのpost送信処理
 * @param flg
 * 	string
 * 		投稿先
 * @param mode
 * 	string
 * 		投稿タイプ
 * 			0 input
 * 			1 check
 * 			2 complete
 * @param id
 * 	integer
 * 		クチコミor質問or回答等のID
 * @param edit
 * 	integer
 * 		編集フラグ
 * 			新規投稿 0 編集 1
 * @return
 */
function submit(flg,mode,id,edit){

	var md = null;	//モールディレクトリ
	var sd = null;	//ショップディレクトリ
	var bd = null;	//ブランドディレクトリ
	var aid = null;	//回答ID
	var type = null;//投稿モード
	var url = null;	//送信先url

	if (arguments[4] != null) md = arguments[4];
	if (arguments[5] != null) sd = arguments[5];
	if (arguments[6] != null) bd = arguments[6];
	if (arguments[7] != null) aid = arguments[7];

	if (mode == 0) {
		type = "input";
	} else if (mode = 1) {
		type = "check";
	} else if (mode = 2) {
		type = "complete";
	}

	url = createURL(flg, type, id , aid, md, sd, bd);

	addForm(type);

	sendPost(url, id, aid, edit, type);
}

/**
* 投稿フロー内でのpost送信処理
* @param id
* 	integer
* 		クチコミor質問or回答等のID
* @return
*/
function fromSubmit(type,edit,id,aid){

	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqId" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqAid" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqEdit" value="" />');
	switch (type){
	case 0 :
		document.jqInput.jqId.value = id;
		document.jqInput.jqAid.value = aid;
		document.jqInput.jqEdit.value = edit;
		document.jqInput.submit();
		break;
	case 1 :
		document.jqCheck.jqId.value = id;
		document.jqCheck.jqAid.value = aid;
		document.jqCheck.jqEdit.value = edit;
		document.jqCheck.submit();
		break;
	case 2 :
		document.jqComplete.jqId.value = id;
		document.jqComplete.jqAid.value = aid;
		document.jqComplete.jqEdit.value = edit;
		document.jqComplete.submit();
		break;
	}
	return false;
}
/**
 *
 * @param type
 * 	string
 * 		投稿タイプ
 * 			0 input
 * 			1 check
 * 			2 complete
 * @param edit
 * 		編集フラグ
 * 			新規投稿 0 編集 1
 * @param id
 * 	質問orクチコミIDなど
 * @param aid
 * 	回答ID
 * @return
 */
function reDirect(type, edit, id, aid){

	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqId" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqAid" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqEdit" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jsPost" value="1" />');

	switch (type){
	case 0 :
		document.jqInput.jqId.value = id;
		document.jqInput.jqAid.value = aid;
		document.jqInput.jqEdit.value = edit;
		document.jqInput.submit();
		break;
	case 1 :
		document.jqCheck.jqId.value = id;
		document.jqCheck.jqAid.value = aid;
		document.jqCheck.jqEdit.value = edit;
		document.jqCheck.submit();
		break;
	case 2 :
		document.jqComplete.jqId.value = id;
		document.jqComplete.jqAid.value = aid;
		document.jqComplete.jqEdit.value = edit;
		document.jqComplete.submit();
		break;
	}
	return false;
}

/**
 * 送信先URL作成関数
 * @param flg
 * @param type
 * @param id
 * @param md
 * @param sd
 * @param bd
 * @return
 */
function createURL(flg,type,id,aid,md,sd,bd) {
	var url = "https://";
	if (document.domain != null){
		url += document.domain;
	} else {
		url += "outlet-mall.jp";
	}

	switch (flg) {
	case "mr" :
		url += "/mall/" + md + "/review/" + type;
		break;
	case "sr" :
		url += "/mall/" + md + "/shop/" + sd + "/review/" + type;
		break;
	case "br" :
		url += "/brand/" + bd + "/review/" + type;
		break;
	case "mrc" :
		url += "/mall/" + md + "/review/comment/" + type;
		break;
	case "src" :
		url += "/mall/" + md + "/shop/" + sd + "/review/comment/" + type;
		break;
	case "brc" :
		url += "/brand/" + bd + "/review/comment/" + type;
		break;
	case "mq" :
		url += "/mall/" + md + "/qa/" + type;
		break;
	case "sq" :
		url += "/mall/" + md + "/shop/" + sd + "/qa/" + type;
		break;
	case "bq" :
		url += "/brand/" + bd + "/qa/" + type;
		break;
	case "ma" :
		url += "/mall/" + md + "/qa/" + type;
		break;
	case "sa" :
		url += "/mall/" + md + "/shop/" + sd + "/qa/" + type;
		break;
	case "ba" :
		url += "/brand/" + bd + "/qa/" + type;
		break;
	case "mt" :
		url += "/mall/" + md + "/qa/" + type;
		break;
	case "st" :
		url += "/mall/" + md + "/shop/" + sd + "/qa/" + type;
		break;
	case "bt" :
		url += "/brand/" + bd + "/qa/" + type;
		break;
	}
	return url;
}

/**
 * Post送信関数
 * @param url
 * 	送信先url
 * 		string
 * @param qid
 * 	クチコミor質問ID
 * 		integer
 * @param aid
 * 	回答ID
 * 		integer
 * @param edit
 * 	編集フラグ
 * 		integer 新規投稿 0 編集 1
 * @param type
 * 	投稿モード
 * 		string
 * 		入力 input
 * 		確認 check
 * 		完了 complete
 * @return
 */
function sendPost(url,id,aid,edit,type){

	switch (type){
	case "input" :
		document.jqInput.action = url;
		document.jqInput.jqId.value = id;
		document.jqInput.jqAid.value = aid;
		document.jqInput.jqEdit.value = edit;
		document.jqInput.submit();
		break;
	case "check" :
		document.jqCheck.action = url;
		document.jqCheck.jqId.value = id;
		document.jqCheck.jqAid.value = aid;
		document.jqCheck.jqEdit.value = edit;
		document.jqCheck.submit();
		break;
	case "complete" :
		document.jqComplete.action = url;
		document.jqComplete.jqId.value = id;
		document.jqComplete.jqAid.value = aid;
		document.jqComplete.jqEdit.value = edit;
		document.jqComplete.submit();
		break;
	}
	return false;
}

//JQuery用関数(※要JQueryライブラリ)
function addForm(type){
	var inputType = null;

	switch (type){
	case "input" :
		inputType = "jqInput";
		break;
	case "check" :
		inputType = "jqCheck";
		break;
	case "complete" :
		inputType = "jqComplete";
		break;
	}

	$("#footerd").after('<form name="' + inputType + '" action="" method="post" id="jqForm"></form>');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqId" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqAid" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqEdit" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jsPost" value="1" />');

}

function addHidden(){
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqId" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqAid" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jqEdit" value="" />');
	$("#jqForm").append('<input type="hidden" id="jqHidden" name="jsPost" value="1" />');

}