document.onkeydown = function(e){
	var e = (e) ? e : ((event) ? event : null);
	var source = (e.target) ? e.target : ((e.srcElement) ? e.srcElement : null);
	if(e.keyCode==13){
		 if(source.name=="syohinnNm"){
		 	return fun_Productcheck();
		 }else if(source.tagName!="TEXTAREA")
		 	{return false;}
		 else if(source.readOnly==true)
		 	{return false;}
		 else if(source.disabled==true)
		 	{return false;}
	}
}

function fun_Productcheck(){
	var contextPath = document.getElementById("contextPath-data").value;
	var subShopIdDisp = document.getElementById("subShopId").value;
	var syohinnNm=document.getElementsByName("searchWord").item(0).value;
	var syohinnNmMinLen=document.forms["cmHeaderForm"].elements["prodMinLen"].value;
	var syohinnNmMaxLen=document.forms["cmHeaderForm"].elements["prodMaxLen"].value;

	syohinnNm = syohinnNm.replace("\?","");
	syohinnNm = syohinnNm.replace("\？","");
	
	if(!hasValue(syohinnNm)){
		document.getElementsByName("searchWord").item(0).value="";
		setMessage("MSG_G0034","検索語句");
	}
//	if(compareByteLength(syohinnNm, syohinnNmMaxLen) > 0 
//	|| compareByteLength(syohinnNm, syohinnNmMinLen) < 0){
//		var msg = "商品名," + syohinnNmMinLen + "," + syohinnNmMaxLen;
//		setMessage("MSG_G0040",msg);
//	}
	if(syohinnNm == "検索語句を入力"){
		setMessage("MSG_G0034","検索語句");
	}

	if(!showMessage()){
		return false;
	} else {
		var subShopId;
		var topPageFlg = document.forms["cmHeaderForm"].elements["topPageFlg"].value;

		var categoryCd = document.forms["cmHeaderForm"].elements["categoryCd"].value;
		if (categoryCd == "") {
			categoryCd = " ";

			// TOPページから呼ばれた場合
			if (topPageFlg == "1") {
				subShopId = "0";
			} else {
				subShopId = document.forms["cmHeaderForm"].elements["subShopId"].value;
			}
		} else {
			subShopId = categoryCd.substring(1,2);
		}

		var searchWord = document.forms["cmHeaderForm"].elements["searchWord"].value
		searchWord = searchWord.replace(/\?/g,"");
		searchWord = searchWord.replace(/\？/g,"");
		if(searchWord == "") searchWord = " ";

		var url = contextPath + "/cmHeaderSearchProduct/doSearchProduct";
		url += "/" + document.forms["cmHeaderForm"].elements["screenId"].value;
		url += "/" + " ";
		url += "/" + categoryCd;
		url += "/" + subShopIdDisp;
		url += "?wd=" + convSignHeader(searchWord);
		//HTTPSの場合はHTTPへ変更し遷移
		changeHttp(url);
	}
	return false;
}

function commHeadClick(method) {
	var contextPath = document.getElementById("contextPath-data").value;
	var contentScreenId = document.forms["cmHeaderForm"].elements["contentScreenId"].value;
	if(method == "doLogin"  &&
	 (contentScreenId == "shEditOrdererInfo" || contentScreenId == "shDispGSAddresseeSelect"
	 || contentScreenId == "shDispGFAddresseeSelect" || contentScreenId == "shDispSPAddresseeSelect"
	 || contentScreenId == "shEditPurchContent" || contentScreenId == "shEditAddresseeChange" 
	 || contentScreenId == "shEditClientChange" || contentScreenId == "shEditProductNumber"
	 || contentScreenId == "shEditDeliverySet" || contentScreenId == "shEditFestivalName" 
	 || contentScreenId == "shEditWrappingChange" || contentScreenId == "shEditMemoInput" 
	 || contentScreenId == "shConfirmSettlementMeth" || contentScreenId == "shDispPurchConfirm") ) {
		if (confirm("それまで入力した内容が破棄され買い物カゴ画面に戻してよろしいですか？")){
			// OKだったら、入力した内容が破棄され買い物カゴ画面に戻る。
			var url = contextPath + "/cmHeaderHeadClick/" + method;
			url += "/" + document.forms["cmHeaderForm"].elements["screenId"].value;
			url += "/" + document.forms["cmHeaderForm"].elements["subShopId"].value;
			url += "/" + document.forms["cmHeaderForm"].elements["contentScreenId"].value;
			location.href = encodeURI(url);
			return true;
		}
	}else {
		var elements = document.getElementsByName("screenId");
		for(i=0;i<elements.length;i++){
			if(elements.item(i).value == "srDispProductDetail"){
				changeDefImg();
				break;
			}
		}
		var url = contextPath + "/cmHeaderHeadClick/" + method;
		url += "/" + document.forms["cmHeaderForm"].elements["screenId"].value;
		url += "/" + document.forms["cmHeaderForm"].elements["subShopId"].value;
		if(method == "doLogin" || method == "doEditShoppingBasket" ){
			url += "/" + document.forms["cmHeaderForm"].elements["contentScreenId"].value;
		} else if(method == "doMyPage" ){
			document.forms["cmHeaderForm"].elements["contentScreenId"].value = "myPageMenu";
			url += "/" + document.forms["cmHeaderForm"].elements["contentScreenId"].value;
		} else if(method == "doKoJin" ){
			document.forms["cmHeaderForm"].elements["contentScreenId"].value = "cmKojinAgree";
			url += "/" + document.forms["cmHeaderForm"].elements["contentScreenId"].value;
		}else{
			url += "/" + "";
	 	}
		location.href = encodeURI(url);
	}
	return false;
}

function goCmDispRanking(shopId, categoryCd) {
	var contextPath = document.getElementById("contextPath-data").value;
	var url = contextPath + "/cmDispTopRanking.html?";
	document.location.href = url + "shopId=" + shopId 
								 + "&categoryCd=" + categoryCd
}

//
//function doTopLink(){
//	var contextPath = document.getElementById("contextPath-data").value;
//	var url = "cmTopPage";
//	url += "/" + document.forms["cmHeaderForm"].elements["subShopId"].value;
//	var url2 = createHttp(contextPath,url);
//	document.location.href = encodeURI(url2);
//	return false;
//}

function doTopLink(){
	var contextPath = document.getElementById("contextPath-data").value;
	var url = "";
	var url2 = createHttp(contextPath,url);
	document.location.href = encodeURI(url2);
	return false;
}

function doProductListLink(){
	var contextPath = document.getElementById("contextPath-data").value;
	var url = contextPath + "/srDispCategoryTreeLink/doSearchCategory/11100000000/1/2/1";
	document.location.href = encodeURI(url);
	return false;
}

function convSignHeader(tempStr){
	var contextPath = document.getElementById("contextPath-data").value;
	var rtnStr = "";
	rtnStr = encodeURIComponent(tempStr).replace(/\./g,"%2E");
	return rtnStr;
}

function doInquiry() {
	var contextPath = document.getElementById("contextPath-data").value;
	var url = createHttps();
	url += contextPath + "/inquiry/cmTopPage";
	document.location.href = encodeURI(url);
	return false;
}

function doBegginerLink(){
	var contextPath = document.getElementById("contextPath-data").value;
	var url = "guide/beginner/index1.html";
	backToTopForHttp(contextPath,url);
	return false;
}

function doHowToShopping(){
	var contextPath = document.getElementById("contextPath-data").value;
	var url = "guide/order/index5.html";
	backToTopForHttp(contextPath,url);
	return false;
}

function doGuide(){
	var contextPath = document.getElementById("contextPath-data").value;
	var url = "guide/index.html";
	backToTopForHttp(contextPath,url);
	return false;
}

function cmHeaderClickInquiry(subShopId) {
	var contextPath = document.getElementById("contextPath-data").value;
	var url = contextPath + "/cmHeaderChangePage/doChangeSubShop";
	url += "/" + subShopId;
	document.location.href = encodeURI(url);
	return false;
}

function doDetailSearch(){
	var subShopIdElement = document.querySelector("hidden [name=subShopId]") || document.querySelector("#subShopId");
	var contextPath = document.getElementById("contextPath-data").value;
	var url = contextPath + "/cmHeaderSearchProduct/doSearchProductDetail" + "?subShopId=" + subShopIdElement.value;
	document.location.href = encodeURI(url);
	return false;
}

//サブショップ制御
function doShopChange(category1){
	var shopCategory = 0;
	
	if(document.getElementsByName("scCode_" + category1).item(0) != null){
		shopCategory = document.getElementsByName("scCode_" + category1).item(0).value.charAt(1);
	}
	
	document.getElementById("subShopId").value = shopCategory;
}

