///レシピの別窓
function RecipeOpen(HomeUrl,recipeNo){
    var recipeWindow = HomeUrl+"recipe/?mode=another&no="+recipeNo;
    var opnW = window.open(recipeWindow,"レシピ","scrollbars=yes,width=710,height=600");
    opnW.focus();
}

function RecipePrevieOpen(HomeUrl,GoodsNo){
    var genre= document.recipeForm.recipeGenre.value;
    var recipeWindow = HomeUrl+"recipe/?mode=previe&Gno="+GoodsNo+"&genre="+genre+"&p=recipe";
    var opnW = window.open(recipeWindow,"レシピ","scrollbars=yes,width=700,height=400");
    opnW.focus();
}

function PrevieOpen(HomeUrl,ShopNo){
    var area = document.goodsForm.area.value;
    var PrevieWindow = HomeUrl+"goods/preview.php?shopno="+ShopNo+"&area="+area;
    var opnW = window.open(PrevieWindow,"プレビュ","scrollbars=yes,width=700,height=500");
    opnW.focus();
}


function OpenSource(HomeUrl){
    var sourceWindow = HomeUrl+"top/source.php";
    var opnW = window.open(sourceWindow,"貼り付けソース","scrollbars=yes,width=680,height=500");
    opnW.focus();
}

function AskWindow(to_top){
    var opnW = window.open(to_top+"top/ask.php","ASK","width=650,height=400");
    opnW.focus();
}

function OpenHelp(){
    var opnW = window.open("../shop/help.php","HELP","scrollbars=yes,width=825,height=500");
    opnW.focus();
}


function RuleWindow(){
    var opnW = window.open("../register/rule.php?check=regi","RULE","scrollbars=yes,width=420,height=500");
    opnW.focus();
}

function OpenRule(ForRule){
    var opnW = window.open(ForRule,"RULE","scrollbars=yes,width=420,height=500");
    opnW.focus();
}


function sendedFrom(httpsUrl,openNo,wNo,encode_name){
	openUrl = httpsUrl+"?mode=WindowSended&openNo="+openNo+"&wNo="+wNo+"&entryName="+encode_name;
    var opnW = window.open(openUrl,"SENDED","toolbar=yes,width=680,height=500");
    opnW.focus();
}


function notAgree(){
	var opnW = window.opener.document.tempRegister.check.value = "";//
}

function ruleCheck(){
	var opnW = window.opener.document.tempRegister.check.value = "agree";//
	var form="";
	form += '<form  name="ruleForm" id="ruleForm" onsubmit="window.close();">';
	form += ' <input type="submit" value="閉じる"  /></form>';
	
	document.getElementById("form").innerHTML = form//親へデータ移動
}


function presentMailCheck(){
	var presentAddress = document.entryForm.presentAddress.value;
	var data = presentAddress.match(/^\S+@\S+\.\S+$/);
	var error = "";
	if (!data) {
		error += "メールアドレスが正しくありません\n";
	}
	if(error){
		alert(error);  return false;
	}
}

function entryMailCheck(){
	var mailMagAddress = document.mailMagEntryForm.mailMagAddress.value;
	var data = mailMagAddress.match(/^\S+@\S+\.\S+$/);
	var error = "";
	if (!data) {
		error += "メールアドレスが正しくありません\n";
	}
	if(error){
		alert(error);  return false;
	}
}



function entryCheck(){
	var entryName = document.entryForm2.entryName.value;
	var error = "";
	if (!entryName) {
		error = "エントリーネームをご入力下さい\n";
	}else{
		var entryNamelength = 0; 
		for (var ni = 0; ni < entryName.length; ni++) {
			var nc = entryName.charCodeAt(ni); 
			// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff 
			// Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3 
			if ( (nc >= 0x0 && nc < 0x81) || (nc == 0xf8f0) || (nc >= 0xff61 && nc < 0xffa0) || (nc >= 0xf8f1 && nc < 0xf8f4)) { 
				entryNamelength += 1; 
			} else { 
				entryNamelength += 2; 
			} 
		} 
		
		if(entryNamelength > 20){
			error += "エントリーネームは全角10字以内で、現在 "+entryNamelength/2+"文字\n";
		}
	
	}
	
	
	if(error){
		alert(error);  return false;
	}
	
	
}



function mailCheck(){
	var txt = document.tempRegister.registerMail.value;
	var data = txt.match(/^\S+@\S+\.\S+$/);
	var error = "";
	if (!data) {
		error += "メールアドレスが正しくありません\n";
	}
	
	var check = document.tempRegister.check.value;
	
	if(check != "agree"){
		error += "登録する場合は必ず利用規約を読み、同意をして下さい\n";
	}
	if(error){
		alert(error);
		return false;
	}
}

function cMailCheck(){
	var txt = document.tempRegister.correctMail.value;
	var data = txt.match(/^\S+@\S+\.\S+$/);
	var error = "";
	if (!data) {
		error += "メールアドレスが正しくありません\n";
	}
	if(error){
		alert(error);
		return false;
	}
}

function shopCheck(){
	var shopname = document.shopRegisterForm.shopname.value;
	var shoparea = document.shopRegisterForm.shoparea.value;
	var shopuri = document.shopRegisterForm.shopuri.value;
	var shopid = document.shopRegisterForm.shopid.value;
	var passwordLnength = document.shopRegisterForm.password.value.length;
	var error = "";
	
	if (!shopname) {
		error += "店舗名が入力されてません\n";
	}else{
		var shopnamelength = 0; 
		for (var ni = 0; ni < shopname.length; ni++) {
			var nc = shopname.charCodeAt(ni); 
			// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff 
			// Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3 
			if ( (nc >= 0x0 && nc < 0x81) || (nc == 0xf8f0) || (nc >= 0xff61 && nc < 0xffa0) || (nc >= 0xf8f1 && nc < 0xf8f4)) { 
				shopnamelength += 1; 
			} else { 
				shopnamelength += 2; 
			} 
		} 
		
		if(shopnamelength > 60){
			error += "店舗名は全角30字以内で、現在 "+shopnamelength/2+"文字\n";
		}
	}
	
	if (shoparea == "都道府県") {
		error += "都道府県を選択して下さい\n";
	}
	var uriCheck1 = shopuri.match(/^http:\/\//);
    if(!uriCheck1){
		error += "ショップＵＲＬはhttp://から始めてください\n";
	}
	
	var uriCheck2 = shopuri.match(/\/$/);
    if(!uriCheck2){
		error += "ショップＵＲＬはindex.html等を除き　'　/　'　で終えて下さい\n";
	}
	
	if (!shopid) {
		error += "ShopIDが入力されてません\n";
	}else{
		var shopidlength = 0; 
		for (var i = 0; i < shopid.length; i++) {
			var c = shopid.charCodeAt(i); 
			// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff 
			// Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3 
			if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) { 
				shopidlength += 1; 
			} else { 
				shopidlength += 2; 
			} 
		} 
		
		if(shopidlength > 20){
			error += "Ｓｈｏｐ ＩＤは全角10字以内で、現在 "+shopidlength/2+"文字\n";
		}
	}
	
    if(passwordLnength<6){
		error += "パスワードは6～10文字です\n";
	}
	
	if(error){
		alert(error);
		return false;
	}
}



/*グッズの入力チェック*/
function goodsCheck(){
	var error = "";
	
	var area = document.goodsForm.area.value;//商品産地
	if (area === 'area') {
		error += "商品産地が選択されてません\n";
	}
	
	var goodsname = document.goodsForm.goodsname.value;//商品名
	if (!goodsname) {
		error += "商品名が入力されてません\n";
	}else if(goodsname === '商品の名前を30文字以内でご入力下さい。'){
		error += "商品名が入力されてません\n";
	}
	
	var goodspr = document.goodsForm.goodspr.value;//商品PR
	if (!goodspr) {
		error += "商品ＰＲが入力されてません\n";
	}else{
		var goodspr = document.goodsForm.goodspr.value;//商品PR
		if(goodspr.length > 200){
			error += "商品ＰＲは200文字以内でお願いします\n現在"+goodspr.length+"文字です\n";
		
		}
	}
	var seasonStart = document.goodsForm.seasonStart.value;
	var seasonFinish = document.goodsForm.seasonFinish.value;
	if((seasonStart) && (seasonStart != 9999)){
		var seasonFinish = document.goodsForm.seasonFinish.value;
		if(!seasonFinish){
			error += "旬・オススメ時期の終わりを指定して下さい\n";
		}
	}else if(seasonStart){
		if(seasonFinish){
			error += "旬・オススメ時期の始まりを指定して下さい\n";
		}
	}else if(seasonFinish){
		error += "旬・オススメ時期の始まりを指定して下さい\n";
	}
	
	var price = document.goodsForm.price.value;//商品価格
	var pricecomm = document.goodsForm.pricecomm.value;//商品価格コメント
	if(price){
		if (price.match(/[\D]/g)){
			error += "商品価格は半角数字のみで入力して下さい\n";
		}
	}else{
		if(pricecomm === '価格に付足す事があればご入力下さい。'){
			error += "商品価格をご入力下さい\n";
		}
	}
	

	
	var genre1 = document.goodsForm.genre1.selectedIndex;//ジャンル
	if (genre1 <= "0") {
		error += "登録カテゴリ１を選択して下さい\n";
	}else{
		var category1;
		for (var i = 0; i < document.goodsForm.category1.length; i++){
			if(document.goodsForm.category1[i].checked == true){
				category1 = document.goodsForm.category1[i].value;
			}
		}
		if (!category1) {
			error += "登録カテゴリ１の詳細を選択して下さい\n";
		}
	}

	var genre2 = document.goodsForm.genre2.selectedIndex;//ジャンル
	if (genre2 != "0") {
		var category2;
		for (var i = 0; i < document.goodsForm.category2.length; i++){
			if(document.goodsForm.category2[i].checked == true){
				category2 = document.goodsForm.category1[i].value;
			}
		}
		if (!category2) {
			error += "登録カテゴリ２を選択した場合は詳細も選択して下さい\n";
		}
	}

	
	var goodsuri = document.goodsForm.goodsuri.value;//商品URI
	if ((!goodsuri) || (goodsuri === '登録しているショップURL以下のURLのみ登録可')) {
		error += "商品ＵＲＬは必ず入力して下さい\n";
	}else{
		var goodsuri = document.goodsForm.goodsuri.value;//入力URI
		var shopuri = document.goodsForm.shopuri.value;//shopURI
		var baseuri = document.goodsForm.baseuri.value;//登録URI
		sh = new RegExp(shopuri, "i");
		ba = new RegExp(baseuri, "i");
		if( (!sh.exec(goodsuri)) && (!ba.exec(goodsuri))){
			error += "登録したショップＵＲＬが含まれないＵＲＬは登録出来きません\n";
			error += "商品の紹介ページがサブドメインの場合はページ下の問い合せよりご相談下さい\n";
		}
	}


	if(error){
		alert(error);
		return false;
	}else{
	   if(confirm("プレビュで表示内容を確認しましたか？\nよろしいければこの内容で登録します。")){ return true }{ return false }
	}
	
}


///レシピプレビュー
function RecipePrevie(){
	var recipeNo = window.opener.document.recipeForm.recipeNo.value;

	//レシピ名
	var recipeTitle = window.opener.document.recipeForm.recipeTitle.value;
	if(recipeTitle !== 'レシピのタイトルを30文字以内でご入力下さい。'){
		document.getElementById("recipeTitleH3").innerHTML = recipeTitle;
	}

	//旧イメージファイル名
	var beforeImage = window.opener.document.recipeForm.beforeImage.value;
	var beforeWidth = window.opener.document.recipeForm.beforeWidth.value;
	var beforeHeight = window.opener.document.recipeForm.beforeHeight.value;

	//仮保存イメージファイル名
	var imageFile = window.opener.document.recipeForm.imageFile.value;
	var imageWidth = window.opener.document.recipeForm.imageWidth.value;
	var imageHeight = window.opener.document.recipeForm.imageHeight.value;

	if(imageFile){
		var imag_html = '<img src="../'+imageFile+'" alt="'+recipeTitle+'" width="'+imageWidth+'" height="'+imageHeight+'" />';
	}else if(beforeImage){
		var imag_html = '<img src="../recipeImage/'+recipeNo+"/"+beforeImage+'" alt="'+recipeTitle+'" width="'+beforeWidth+'" height="'+beforeHeight+'" />';
	}else{
		var imag_html = '<img src="../goodsimage/noImage.gif" alt="イメージ画像はございません" width="200" height="200" />';
	}
	document.getElementById("recipeImage").innerHTML = imag_html;
	
	
	//レシピ紹介
	var recipePresentation = window.opener.document.recipeForm.recipePresentation.value;
	if(recipePresentation  !== 'このレシピを200文字以内で簡単にご紹介下さい。'){
		document.getElementById("presentation").innerHTML = recipePresentation ;
	}
	
	//材料　分量
	var ingredientAmount = window.opener.document.recipeForm.ingredientAmount.value;
	
	var ingredientTable = "";
	if(ingredientAmount !== '何人分など目安を15文字以内で'){
		var ingredientAmountHtml = '<span>('+ingredientAmount+')</span>';
	}else{
		var ingredientAmountHtml = '';
	}
	ingredientTable += '<table id="ingredientTable" summary="材料"><tr><th colspan="2"><span class="ing">材料</span><span class="amo">'+ingredientAmountHtml +'</span></th></tr>'
	
	for(var ii=1; ii<=30; ii++){
		var ingredient = window.opener.document.getElementById("ingredient"+ii).value;
		var amount = window.opener.document.getElementById("amount"+ii).value;
		if(ingredient){
			if(amount){
				ingredientTable += '<tr><td><p class="ingP">'+ingredient+'</p></td><td><p class="amoP">'+amount+'</p></td></tr>'
			}else{
				ingredientTable += '<tr><td colspan="2" class="index"><p>'+ingredient+'</p></td></tr>'
			}
		}
	}
	
	ingredientTable += '</table>';

	document.getElementById("ingredient").innerHTML = ingredientTable ;
	
	
	//プロセス
	var proNo = 0;
	var processTable = '<h4><span>作り方</span></h4><table id="process" summary="作り方">';
	for(var pi=1; pi<=20; pi++){
		var process = window.opener.document.getElementById("process"+pi).value;
		var Pimage = window.opener.document.getElementById("Pimage"+pi).value;
		if(process){
			proNo++;
			if(Pimage){
				var PiSrc = "../"+Pimage;
				processTable += '<tr><td class="proNo">【'+proNo+'】</td><td class="proText">'+process+'</td><td class="Pimage"><p><img src="'+PiSrc+'" width="102" height="76" /></p></td></tr>'
			}else{
				processTable += '<tr><td class="proNo">【'+proNo+'】</td><td class="proText" colspan="2">'+process+'</td></tr>';
			}
		}
	}
	processTable += '</table>';
	document.getElementById("recipeProcess").innerHTML = processTable;
	
	
	//アドバイス
	var recipeAdvice = window.opener.document.recipeForm.recipeAdvice.value;
	
	if(recipeAdvice !== '美味しく作るコツやポイントなどなど、なにかアドバイスがあればご入力下さい。'){
		document.getElementById("advice").innerHTML = '<h4><span>ＰＯＩＮＴ</span></h4><p>'+recipeAdvice+'</p>';

	}

	
}

///登録商品プレビュー
function GoodsPreview(){
	//商品名
	var goodsname = window.opener.document.goodsForm.goodsname.value;
	if(goodsname !== '商品の名前を30文字以内でご入力下さい。'){
		document.getElementById("goodsname").innerHTML = goodsname;
	}

	//旧イメージファイル名
	var beforeImage = window.opener.document.goodsForm.beforeImage.value;
	var beforeWidth = window.opener.document.goodsForm.beforeWidth.value;
	var beforeHeight = window.opener.document.goodsForm.beforeHeight.value;

	//仮保存イメージファイル名
	var imageFile = window.opener.document.goodsForm.imageFile.value;
	var imageWidth = window.opener.document.goodsForm.imageWidth.value;
	var imageHeight = window.opener.document.goodsForm.imageHeight.value;

	if(imageFile){
		var imag_html = '<img src="../'+imageFile+'" alt="'+goodsname+'" width="'+imageWidth+'" height="'+imageHeight+'" />';
	}else if(beforeImage){
		var imag_html = '<img src="../goodsimage/'+beforeImage+'" alt="'+goodsname+'" width="'+beforeWidth+'" height="'+beforeHeight+'" />';
	}else{
		var imag_html = '<img src="../goodsimage/noImage.gif" alt="イメージ画像はございません" width="200" height="200" />';
	}
	document.getElementById("goodsImgBlock").innerHTML = imag_html;
	
	//商品PR
	var goodspr = window.opener.document.goodsForm.goodspr.value;
	if(goodspr !== '商品のＰＲを200文字以内でご入力下さい。'){
		goodspr = goodspr.replace(/\r\n/g,'<br />');
		goodspr = goodspr.replace(/(\n|\r)/g,'<br />');
		$("#goodspr").html(goodspr);
	}


	//商品価格表示部分
	var price = window.opener.document.goodsForm.price.value;//商品価格
	var pricecomm = window.opener.document.goodsForm.pricecomm.value;//価格コメント
	var formatPrice="";
	if(price){
		var formatPrice = myFormatNumber(price)+"円　";//関数でカンマ付け
	}
	
	var previewPrice = formatPrice;
	
	if((pricecomm) && (pricecomm !== '価格に付足す事があればご入力下さい。')){
		previewPrice = formatPrice+pricecomm;
	}

	document.getElementById("price").innerHTML = previewPrice;

	//商品URI
	var goodsuri = window.opener.document.goodsForm.goodsuri.value;
	if(goodsuri !== '登録しているショップURL以下のURLのみ登録可'){
		var goodsuri_link='<a href=\"'+goodsuri+'\" target="_blank"><span>'+goodsuri+'</span></a>';
		document.getElementById("goodsurl").innerHTML = goodsuri_link;
	}
 	//支払い方法取得
	var payment= new Array();
	for (var i = 0; i < window.opener.document.goodsForm.elements.length; i++){
		if ((window.opener.document.goodsForm.elements[i].name=='payment[]') && (window.opener.document.goodsForm.elements[i].checked)){
			payment.push(window.opener.document.goodsForm.elements[i].value);
		}
	}
	document.getElementById("payment").innerHTML = payment.join(' / ');
	
	//送料
	var postage = window.opener.document.goodsForm.postage.value;
	document.getElementById("postage").innerHTML = postage;

	var shoppr = window.opener.document.goodsForm.shoppr.value;
	document.getElementById("shopPr").innerHTML = shoppr;
	
	

}


/*数字のカンマづけ*/
function myFormatNumber(x) { // 引数の例としては 95839285734.3245
    var s = "" + x; // 確実に文字列型に変換する。例では "95839285734.3245"
    var p = s.indexOf("."); // 小数点の位置を0オリジンで求める。例では 11
    if (p < 0) { // 小数点が見つからなかった時
        p = s.length; // 仮想的な小数点の位置とする
    }
    var r = s.substring(p, s.length); // 小数点の桁と小数点より右側の文字列。例では ".3245"
    for (var i = 0; i < p; i++) { // (10 ^ i) の位について
        var c = s.substring(p - 1 - i, p - 1 - i + 1); // (10 ^ i) の位のひとつの桁の数字。例では "4", "3", "7", "5", "8", "2", "9", "3", "8", "5", "9" の順になる。
        if (c < "0" || c > "9") { // 数字以外のもの(符合など)が見つかった
            r = s.substring(0, p - i) + r; // 残りを全部付加する
            break;
        }
        if (i > 0 && i % 3 == 0) { // 3 桁ごと、ただし初回は除く
            r = "," + r; // カンマを付加する
        }
        r = c + r; // 数字を一桁追加する。
    }
    return r; // 例では "95,839,285,734.3245"
}


function IppinCheck(period){
	var com = period+"の週に「注目の逸品」へ掲載します。\nよろしいですか？";
	if(confirm(com)){ return true }{ return false }

}

function IppinCansell(){
	if(confirm("「注目の逸品」への掲載を取り消しますか？")){ return true }{ return false }

}
function selectRecipeGoods(){
	var error = "";
	var forRecipeGoodsindex = document.recipeFrom.forRecipeGoods.selectedIndex;
	var forRecipeGoods = document.recipeFrom.forRecipeGoods.options[forRecipeGoodsindex].value;
	
	if(!forRecipeGoods){
		error +="レシピ登録商品を選択して下さい\n";
	}
	if(error){
		alert(error);
		return false;
	}
}


function PresentGoodsCheck(){
	var error = "";
	var pre_listindex = document.presentFrom.pre_list.selectedIndex;
	var pre_list = document.presentFrom.pre_list.options[pre_listindex].value;
	
	if(!pre_list){
		error +="プレゼント商品を選択して下さい\n";
	}
	
	var rule= new Array();
	for (var i = 0; i < document.presentFrom.elements.length; i++){
		if ((document.presentFrom.elements[i].name=='pre_rule[]') && (document.presentFrom.elements[i].checked)){
			rule.push(document.presentFrom.elements[i].value);
		}
	}
	
	if(rule[0] != "yes"){
		error +="規約に同意するにチェックを入れてください";
	}
	if(error){
		alert(error);
		return false;
	}
	

}

function PresentGoodsInputCheck(){
	var winner = document.presentFrom.winner.value;
	
	var error = "";
	if(!winner){
		error += "当選者数をご入力ください\n";
	}else{
		wc = winner.match(/\D/g);
		if(wc){
			error += "当選者数は半角英数字でお願いします\n";
		}

	}
	
	var present_pr = document.presentFrom.present_pr.value;
	
	if(present_pr === 'プレゼント商品の説明を100文字以内でお願いします（改行は反映されません）'){
		error += "プレゼント商品の説明をご入力ください\n";
	}else{
		var present_prlength = 0; 
		for (var i = 0; i < present_pr.length; i++) {
			var c = present_pr.charCodeAt(i); 
			// Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff 
			// Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3 
			if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) { 
				present_prlength += 1; 
			} else { 
				present_prlength += 2; 
			} 
		} 
	
		if(present_prlength > 200){
			error += "プレゼント商品の説明はで全角100文字以内で\n現在"+present_prlength/2+"文字です\n";
		}
	}

	if(error){
		alert(error);
		return false;
	}

}

function PresentFinal(){
	if(confirm("この内容でプレゼントを実施します\n以降プレゼント内容の変更は出来ません\nよろしいですか？")){ return true }{ return false }
}

function DeleteCheck(shopName){
	comment = shopName +"で登録してある全てのデータを削除しますがよろしいですか"
	if(confirm(comment)){ return true }{ return false }
}


function WinnerCheck(){
	var error = "";
	
	var realName = document.winnerInputForm.realName.value;
	if(!realName){	error += "氏名をご入力下さい\n";	}
	
	var code1 = document.winnerInputForm.code1.value;
	var code2 = document.winnerInputForm.code2.value;
	if((!code1) || (!code2)){
		error += "郵便番号をご入力下さい\n";
	}else{
		var code1length = 0; 
		for (var i1 = 0; i1 < code1.length; i1++) {
			var c1 = code1.charCodeAt(i1); 
			if ( (c1 >= 0x0 && c1 < 0x81) || (c1 == 0xf8f0) || (c1 >= 0xff61 && c1 < 0xffa0) || (c1 >= 0xf8f1 && c1< 0xf8f4)) { 
				code1length += 1; 
			} else { 
				code1length += 2; 
			} 
		} 
		if(code1length !=3 ){
			error += "郵便番号の前半は３桁です\n";
		}
		
		var code2length = 0; 
		for (var i2 = 0; i2 < code2.length; i2++) {
			var c2 = code2.charCodeAt(i2); 
			if ( (c2 >= 0x0 && c2 < 0x81) || (c2 == 0xf8f0) || (c2 >= 0xff61 && c2 < 0xffa0) || (c2 >= 0xf8f1 && c2< 0xf8f4)) { 
				code2length += 1; 
			} else { 
				code2length += 2; 
			} 
		} 
		if(code2length !=4 ){
			error += "郵便番号の後半は４桁です\n";
		}
	}


	var saddressArea = document.winnerInputForm.addressArea.selectedIndex;
	var addressArea = document.winnerInputForm.addressArea.options[saddressArea].value;
	if(addressArea == "都道府県"){
			error += "都道府県を選択して下さい\n";
	}


	var winnerAddress = document.winnerInputForm.winnerAddress.value;
	if(!winnerAddress){	error += "住所をご入力下さい\n";	}
	
	var winnerTel= document.winnerInputForm.winnerTel.value;
	if(!winnerTel){	error += "電話番号をご入力下さい\n";	}

	if(error){
		alert(error);
		return false;
	}
	
}



//配送先
function selectDelivery(DeliveryData){
//	var Delivery = DeliveryData.split("=>");
	
	alert(DeliveryData);

}


//配送先フォームチェック
function SendInputCheck(){
	var error = "";
	
	var sendTime = document.winnerInputForm.sendTime.value;
	if(!sendTime){	error += "発送日時をご入力下さい\n";	}

	var sendName = document.winnerInputForm.sendName.value;
	if(!sendName){	error += "送付先宛名をご入力下さい\n";	}
	
	var sendAddress = document.winnerInputForm.sendAddress.value;
	if(!sendAddress){	error += "送付先住所をご入力下さい\n";	}
	
	var sendTel= document.winnerInputForm.sendTel.value;
	if(!sendTel){	error += "送付先電話番号をご入力下さい\n";	}
	
	
	var sdelivery = document.winnerInputForm.delivery.selectedIndex;
	var delivery = document.winnerInputForm.delivery.options[sdelivery].value;
	if(!delivery){
			error += "配送業者を選択して下さい\n";
	}else if(delivery == "その他"){
		var deliname= document.winnerInputForm.deliname.value;
		var deliurl= document.winnerInputForm.deliurl.value;
		if(!deliname){	error += "配送業者をご入力下さい\n";	}
		if(!deliurl){	error += "問い合わせ先をご入力下さい\n";	}
	}

	var inquiry = document.winnerInputForm.inquiry.value;
	if(!inquiry){	error += "問い合わせ番号をご入力下さい\n";	}


	if(error){
		alert(error);
		return false;
	}
	
}


/***商品登録***/
//商品写真UP
//ＯＰＥＮ写真ＵＰ
function IMAGEUP_WINDOW(shopNo){
    var imageWindow = "imageup.php?type=goods&shopno="+shopNo;
    window.open(imageWindow,"IMAGE","width=400,height=250");

}

function updateGoodsImage(){
	var file = document.imageUp.file.value;
	var width = document.imageUp.width.value;
	var height = document.imageUp.height.value;
	
	window.opener.document.goodsForm.imageFile.value = "tempimage/"+file;
	window.opener.document.goodsForm.imageWidth.value = width;
	window.opener.document.goodsForm.imageHeight.value = height;
	
	window.opener.document.getElementById("goodsImgBlock").innerHTML = '<img src="../tempimage/'+file+'" width="'+width+'"  height="'+height+'" />';
	window.opener.document.goodsForm.ImageUp.value = "写真変更";
	window.close();
}

/***レシピ****/
//レシピ完成写真ＵＰＦＯＲＭ
function RecipeImageUp(goodsNo){
    var imageWindow = "imageup.php?type=recipe&goodsNo="+goodsNo;
    window.open(imageWindow,"IMAGE","width=400,height=250");

}

//レシピ写真ＵＰ
function updateRecipeImage(){
	var file = document.imageUp.file.value;
	var width = document.imageUp.width.value;
	var height = document.imageUp.height.value;
	
	window.opener.document.recipeForm.imageFile.value = "tempimage/"+file;
	window.opener.document.recipeForm.imageWidth.value = width;
	window.opener.document.recipeForm.imageHeight.value = height;
	
	window.opener.document.getElementById("recipeImage").innerHTML = '<img src="../tempimage/'+file+'" width="'+width+'"  height="'+height+'" />';
	window.opener.document.recipeForm.ImageUp.value = "写真変更";
	window.close();
}

//プロセス
function ProcessImage(goodsNo,processNo){
    var imageWindow = "imageup.php?type=process&goodsNo="+goodsNo+"&processNo="+processNo;
    window.open(imageWindow,"PROCESS"+processNo,"width=400,height=250");
    return false;
}



function updateProcessImage(){
	var file = document.imageUp.file.value;
	var processNo = document.imageUp.processNo.value;
	var goodsNo = document.imageUp.goodsNo.value;
	
	window.opener.document.getElementById("Pimage"+processNo).value = "tempimage/"+file;
	
	var inHtml = '<img src="../tempimage/'+file+'" width="68"  height="51" />';
	inHtml += '<input type="button" value="キャンセル" onclick="CancelImage('+goodsNo+','+processNo+')"  onkeypress="CancelImage('+goodsNo+','+processNo+')" title="別ウィンドウが開きます" />';
	window.opener.document.getElementById("PI"+processNo).innerHTML = inHtml;
	window.close();
}

function CancelImage(goodsNo,processNo){

	document.getElementById("Pimage"+processNo).value = "";
	var inHtml = '<img src="../core/image/other/processImage.gif" width="68"  height="51" />';
	inHtml += '<input type="button" value="写真UP" onclick="ProcessImage('+goodsNo+','+processNo+')"  onkeypress="ProcessImage('+goodsNo+','+processNo+')" title="別ウィンドウが開きます" />';
	document.getElementById("PI"+processNo).innerHTML = inHtml;

}


//入力数確認
function ShowLength(content,valueData,limit){
	if(valueData.length <= limit){
		var printcount = "（あと" +(limit-valueData.length)+"文字）";
		document.getElementById(content).style.color="rgb(152,152,152)";
	}else{
		var printcount = "（" +(valueData.length-limit)+"文字オーバー）";
		document.getElementById(content).style.color="rgb(255,0,0)";
	}
	document.getElementById(content).innerHTML = printcount;
}


function ShowLength2(content,valueData,limit){
	if((valueData.length <= limit ) &&(valueData.length >= limit - 50)){
		var printcount = "（あと" +(limit-valueData.length)+"文字）";
		document.getElementById(content).style.color="rgb(152,152,152)";
	}else if(valueData.length >= limit ){
		var printcount = "（" +(valueData.length-limit)+"文字オーバー）";
		document.getElementById(content).style.color="rgb(255,0,0)";
	}
	
	if(printcount){
		document.getElementById(content).innerHTML = printcount;
	}else{
		document.getElementById(content).innerHTML = "";
	}
}


function RecipeCheck(){
	var error = "";
	
	var titleBase = document.recipeForm.titleBase.value;
	var recipeTitle = document.recipeForm.recipeTitle.value;
	
	if(titleBase == recipeTitle){
		error += "タイトルをご入力下さい\n";
	}
	
	var titleCheck = document.recipeForm.titleCheck.value;
	
	if(titleCheck === "error"){
		error += "同じ商品で同じ名前のレシピがあります\n";
	}

	
	var presentationBase = document.recipeForm.presentationBase.value;
	var recipePresentation = document.recipeForm.recipePresentation.value;
	
	if(recipePresentation === presentationBase){
		error += "レシピ紹介をご入力下さい\n";
	}else if(recipePresentation.length > 200){
		error += "レシピの紹介は200文字以内でお願いします\n";
	}
	
	
	var recipeGenre = document.recipeForm.recipeGenre.value;
	if(!recipeGenre){
		error += "料理の種類を選択して下さい\n";
	}
	
	
	
	var seasonStart = document.recipeForm.seasonStart.value;
	var seasonFinish = document.recipeForm.seasonFinish.value;
	if((seasonStart) && (seasonStart != 9999)){
		var seasonFinish = document.recipeForm.seasonFinish.value;
		if(!seasonFinish){
			error += "旬・オススメ時期の終わりを指定して下さい\n";
		}
	}else if(seasonStart){
		if(seasonFinish){
			error += "旬・オススメ時期の始まりを指定して下さい\n";
		}
	}else if(seasonFinish){
		error += "旬・オススメ時期の始まりを指定して下さい\n";
	}
	
	for(var ii=1; ii<30; ii++){
		var amount = document.getElementById("amount"+ii).value;
		var ingredient = document.getElementById("ingredient"+ii).value;
		if((amount) && (ingredient)){
			var ingredientCheck = "OK"; break;
		}
	}
	
	if(ingredientCheck !== "OK"){
		error += "必ず一つは材料と分量をご入力下さい\n";
	}
	
	
	
	var process = document.recipeForm.process1.value;
	if(!process){
		error += "作り方は１番目から一手順以上ご入力下さい\n";
	}
	
	var recipeAdvice = document.recipeForm.recipeAdvice.value;
	if(recipeAdvice.length > 1000){
		error += "アドバイスは1000文字以内でお願いします\n";
	}
	
	if(error){
		alert(error);
		return false;
	}
}



function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			((anchor.getAttribute("rel") == "external nofollow") || (anchor.getAttribute("rel") == "nofollow external") || (anchor.getAttribute("rel") == "external")))
			anchor.target = "_blank";
	}
}

/////配送業者
function selectDelivery(){
	var sdelivery = document.winnerInputForm.delivery.selectedIndex;
	var delivery = document.winnerInputForm.delivery.options[sdelivery].value;

	var deliveryArray = delivery.split("=>");
	
	
	if(!deliveryArray[0]){
		document.getElementById("delicom").innerHTML ="配送業者を選択して下さい";
		if(document.getElementById("delisub")){
			var delisub = document.getElementById("delisub");
			var delisub_parent=delisub.parentNode;
			delisub_parent.removeChild(delisub);
		}
	}else{
		//delicomの後にdeliurlのDIVを作成
		if(!document.getElementById("delisub")){
			var delicom_block= document.getElementById("delicom");
			var pNode = document.createElement('p');
			pNode.id = "delisub";
			delicom_block.parentNode.insertBefore(pNode,delicom_block.nextSibling);
		}
		
		if(deliveryArray[0] === "その他"){
			document.getElementById("delicom").innerHTML ="配送業者と問い合わせ先のURLや電話番号をご入力下さい"
			var input_html = "";
			input_html += '配送業者名';
			input_html += '<input type="text" name="deliname" id="deliname" value="" tabindex="6" />';
			input_html += '問い合わせ先';
			input_html += '<input type="text" name="deliurl" id="deliurl" value="" tabindex="7" />';
			document.getElementById("delisub").innerHTML = input_html;
		}else{
			document.getElementById("delicom").innerHTML = deliveryArray[0]+"の問い合わせURL";
			var input_html = "";
			input_html += '<a href="'+deliveryArray[1]+'" target="_blank" class="durl">'+deliveryArray[1]+'</a>';
			input_html += '<input type="hidden" name="deliurl" id="deliurl" value="'+deliveryArray[1]+'" tabindex="7" />';
			document.getElementById("delisub").innerHTML = input_html;
		}
	}
}

//配送先フォームチェック
function SendInputCheck(){
	var error = "";
	
	var sendTime = document.winnerInputForm.sendTime.value;
	if(!sendTime){	error += "発送日時をご入力下さい\n";	}

	var sendName = document.winnerInputForm.sendName.value;
	if(!sendName){	error += "送付先宛名をご入力下さい\n";	}
	
	var sendAddress = document.winnerInputForm.sendAddress.value;
	if(!sendAddress){	error += "送付先住所をご入力下さい\n";	}
	
	var sendTel= document.winnerInputForm.sendTel.value;
	if(!sendTel){	error += "送付先電話番号をご入力下さい\n";	}
	
	
	var sdelivery = document.winnerInputForm.delivery.selectedIndex;
	var delivery = document.winnerInputForm.delivery.options[sdelivery].value;
	if(!delivery){
			error += "配送業者を選択して下さい\n";
	}else if(delivery == "その他"){
		var deliname= document.winnerInputForm.deliname.value;
		var deliurl= document.winnerInputForm.deliurl.value;
		if(!deliname){	error += "配送業者をご入力下さい\n";	}
		if(!deliurl){	error += "問い合わせ先をご入力下さい\n";	}
	}

	var inquiry = document.winnerInputForm.inquiry.value;
	if(!inquiry){	error += "問い合わせ番号をご入力下さい\n";	}


	if(error){
		alert(error);
		return false;
	}
	
}



function AskWindow(to_top){
    window.open(to_top+"top/ask.php","ASK","width=650,height=400");
}
