//自動で戻る用
function history_back(t){
	if(t==null) t = -1;
	history.go(t);
}

//フォーム取得用
function elm(id){
	if( !!document.layers ) return document.layers[id];
	else if( !!document.all ) return document.all[id];
	else return document.getElementById(id);
}

//写真ポップアップ
var p_tid=0,p_cnt=0,p_url,p_img;
function open_photo(id,img){
	//p_url = "./detail"+num+".html";
	p_url = "./detail.php?id="+id;
	//そのまま開く(ネスケのみ)
	if( navigator.userAgent.indexOf("Netscape")>0 ){
		var pos_y = Math.floor(document.body.clientHeight/2)- 300;
		var pos_x = Math.floor(document.body.clientWidth/2) - 250;
		window.open(p_url,'p_detail','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=500,top='+pos_y+',left='+pos_x);
	}
	//画像サイズに合わせて窓を開く(ネスケ以外)
	else {
		p_img = new Image();
		with( p_img ){
			//src = "./photos/"+num+".jpg";
			src = img;
			style.position = "absolute";
			style.left = "0px";
			style.top  = "0px";
			style.display = "none";
		}
		document.body.appendChild(p_img);
		p_tid = setInterval('_loadwait()',300);
	}
	return void(0);
}
//画像サイズ取得用
function _loadwait(){
	++p_cnt;
	if( p_img.complete || p_cnt>30 ){
		p_cnt = 0;
		clearInterval(p_tid);
		var img_w=500,img_h=500;
		if( p_img.complete ){
			img_w = p_img.width;
			img_h = p_img.height;
			p_img.width - 0;
			p_img.height= 0;
		}
		var win_w = 500;
		if( img_w>800 ) win_w = 800;
		else if( img_w>500 ) win_w = img_w+48;
		var win_h = document.body.clientHeight;
		if( img_h+300<win_h ) win_h = img_h+300;
		var pos_y = Math.floor(document.body.clientHeight/2)- (win_h/2);
		var pos_x = Math.floor(document.body.clientWidth/2) - (win_w/2);
		window.open(p_url,'p_detail','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+win_w+',height='+win_h+',top='+pos_y+',left='+pos_x);
	}
}

//パスワード紛失チェック
function check_lost(){
	var tmp;
	if( (tmp=elm("id").value)=="" || tmp==elm("id").defaultValue ){
		window.alert("会員IDをご入力ください。");
		return false;
	}
	if( (tmp=elm("tel").value)=="" || tmp==elm("tel").defaultValue ){
		window.alert("登録電話番号をご入力ください。");
		return false;
	}
}

//問合せチェック
function check_mail(){
	var tmp;
	if( elm("name").value=="" ){
		window.alert("お名前をご入力ください。");
		return false;
	}
	tmp = elm("mail").value;
	tmp = tmp.replace(/\s/g,"");
	if( tmp.search(/^.+@[a-zA-Z0-9\.\_\-]+$/)<0 ){
		window.alert("メールアドレスを正しくご入力ください。");
		return false;
	}
	if( elm("body").value==elm("body").defaultValue ){
		window.alert("お問い合わせ内容をご入力ください。");
		return false;
	}
	return true;
}

//会員登録チェック
function check_regist(){
	var tmp;
	if( elm("name").value=="" ){
		window.alert("ご担当者様氏名をご入力ください。");
		return false;
	}
	tmp = elm("tel").value;
	tmp = tmp.replace(/[^0-9]/g,"");
	if( tmp.length<10 || tmp.length>11 ){
		window.alert("お電話番号を正しくご入力ください。");
		return false;
	}
	if( tmp.search(/^0[89]0/)>=0 ){
			window.alert("携帯電話は指定できません。");
		return false;
	}
	tmp = elm("fax").value;
	tmp = tmp.replace(/[^0-9]/g,"");
	if( tmp.length<10 || tmp.length>11 ){
		window.alert("ファックス番号を正しくご入力ください。");
		return false;
	}
	tmp = elm("zip").value;
	tmp = tmp.replace(/[^0-9]/g,"");
	if( tmp.length!=7 ){
		window.alert("７桁の郵便番号を正しくご入力ください。");
		return false;
	}
	if( elm("addr").value=="" ){
		window.alert("ご住所をご入力ください。");
		return false;
	}
	tmp = elm("mail").value;
	tmp = tmp.replace(/\s/g,"");
	if( tmp.search(/^.+@[a-zA-Z0-9\.\_\-]+$/)<0 ){
		window.alert("メールアドレスを正しくご入力ください。");
		return false;
	}
	if( tmp.search(/^.+@(hotmail|yahoo|[a-zA-Z0-9\.\_\-]+\.livedoor|excite|infoseek|mail\.goo|gmail)[a-zA-Z0-9\.\_\-]+$/)>=0 ){
			window.alert("フリーメールは指定できません。");
		return false;
	}
	if( tmp.search(/^.+@(docomo\.ne\.jp|ezweb\.ne.jp|.\.vodafone\.ne\.jp|jp\-.\.ne\.jp)$/)>=0 ){
			window.alert("携帯メールは指定できません。");
		return false;
	}
	if( (tmp=elm("url").value)!="" ){
		tmp = tmp.replace(/\s/g,"");
		if( tmp.search(/^http:\/\/.+/)<0 ){
			window.alert("URLをhttp://から正しくご入力ください。");
			return false;
		}
	}
	if( elm("agree").checked!=true ){
		window.alert("会員規約をお読みになり同意してください。");
		return false;
	}
}

//登録情報変更チェック
function check_change(){
	var tmp;
	if( (tmp=elm("tel").value)!="" ){
		tmp = tmp.replace(/[^0-9]/g,"");
		if( tmp.length<10 || tmp.length>11 ){
			window.alert("お電話番号を正しくご入力ください。");
			return false;
		}
		if( tmp.search(/^0[89]0/)>=0 ){
				window.alert("携帯電話は指定できません。");
			return false;
		}
	}
	if( (tmp=elm("fax").value)!="" ){
		tmp = tmp.replace(/[^0-9]/g,"");
		if( tmp.length<10 || tmp.length>11 ){
			window.alert("ファックス番号を正しくご入力ください。");
			return false;
		}
	}
	if( elm("addr").value!="" ){
		tmp = elm("zip").value;
		tmp = tmp.replace(/[^0-9]/g,"");
		if( tmp.length!=7 ){
			window.alert("７桁の郵便番号を正しくご入力ください。");
			return false;
		}
		if( elm("addr").value=="" ){
			window.alert("お届先住所をご入力ください。");
			return false;
		}
	}
	if( (tmp=elm("mail").value)!="" ){
		tmp = tmp.replace(/\s/g,"");
		if( tmp.search(/^.+@[a-zA-Z0-9\.\_\-]+$/)<0 ){
			window.alert("メールアドレスを正しくご入力ください。");
			return false;
		}
		if( tmp.search(/^.+@(hotmail|yahoo|[a-zA-Z0-9\.\_\-]+\.livedoor|excite|infoseek|mail\.goo|gmail)[a-zA-Z0-9\.\_\-]+$/)>=0 ){
				window.alert("フリーメールは指定できません。");
			return false;
		}
		if( tmp.search(/^.+@(docomo\.ne\.jp|ezweb\.ne.jp|.\.vodafone\.ne\.jp|jp\-.\.ne\.jp)$/)>=0 ){
				window.alert("携帯メールは指定できません。");
			return false;
		}
	}
	if( (tmp=elm("url").value)!="" ){
		tmp = tmp.replace(/\s/g,"");
		if( tmp.search(/^http:\/\/.+/)<0 ){
			window.alert("URLをhttp://から正しくご入力ください。");
			return false;
		}
	}
}

//写真発注チェック
function check_order(){
	var tmp;
	if( elm("name").value=="" ){
		window.alert("ご担当者様氏名をご入力ください。");
		return false;
	}
	tmp = elm("mail").value;
	tmp = tmp.replace(/\s/g,"");
	if( tmp.search(/^.+@[a-zA-Z0-9\.\_\-]+$/)<0 ){
		window.alert("メールアドレスを正しくご入力ください。");
		return false;
	}
	if( tmp.search(/^.+@(hotmail|yahoo|.+\.livedoor|excite|infoseek|mail\.goo|gmail).+$/)>=0 ){
			window.alert("フリーメールは指定できません。");
		return false;
	}
	tmp = elm("tel").value;
	tmp = tmp.replace(/[^0-9]/g,"");
	if( tmp.length<10 || tmp.length>11 ){
		window.alert("お電話番号を正しくご入力ください。");
		return false;
	}
}

//物販チェック
function check_buy(){
	var tmp;
	if( elm("name").value=="" ){
		window.alert("お名前(漢字)をご入力ください。");
		return false;
	}
	tmp = elm("kana").value;
	if( tmp.search(/^[ァ-ヶー\s]+$/)<0 ){
		window.alert("お名前(カナ)を全角カタカナでご入力ください。");
		return false;
	}
	tmp = elm("tel").value;
	tmp = tmp.replace(/[^0-9]/g,"");
	if( tmp.length<10 || tmp.length>11 ){
		window.alert("お電話番号を正しくご入力ください。");
		return false;
	}
	tmp = elm("mail").value;
	tmp = tmp.replace(/\s/g,"");
	if( tmp.search(/^.+@[a-zA-Z0-9\.\_\-]+$/)<0 ){
		window.alert("メールアドレスを正しくご入力ください。");
		return false;
	}
	tmp = elm("zip").value;
	tmp = tmp.replace(/[^0-9]/g,"");
	if( tmp.length!=7 ){
		window.alert("７桁の郵便番号を正しくご入力ください。");
		return false;
	}
	if( elm("addr").value=="" ){
		window.alert("お届先住所をご入力ください。");
		return false;
	}

	var r,p,n=0,s=0,v=0;

	if( isNaN(r=elm('item[2]').value) ) elm('item[2]').value = 0;
	if( isNaN(p=elm('item[3]').value) ) elm('item[3]').value = 0;
	var d = (elm('detail').value==elm('detail').defaultValue);

	if( p>0 && p<5 ){
		window.alert("ポストカードは５枚以上からの販売となります。");
		return false;
	}
	if( d && p>0 ){
		window.alert("ご希望のポストカードの情報をお書きください。");
		return false;
	}
	if( d && r>0 ){
		window.alert("ご希望の月間論調の情報をお書きください。");
		return false;
	}

	if( elm('item[0]').checked ) v += 15750;
	if( elm('item[1]').checked ) v += 10000;
	if( r>0 ) v += 900*r;
	if( p>0 ) v += 140*p;
	if( v<=0 ){
		window.alert("商品が一つも選ばれていません。");
		return false;
	}
	     if( p>74 ) s = 390;
	else if( p>54 ) s = 240;
	else if( p>37 ) s = 200;
	else if( p>27 ) s = 160;
	else if( p>18 ) s = 140;
	else if( p>10 ) s = 90;
	else if( p> 0 ) s = 80;
	return confirm(
		'商品： '+v+'円\n'+
		'送料： '+s+'円\n'+
		'------------------\n'+
		'合計： '+(v+s)+'円\n'+
		'お支払金額はこのようになります。'
	);
}

//イメージフォルダの削除ボタン
function image_delete(){
    document.folder.action = "myfolder.php";
    document.folder.run.value = 'delete';
    document.folder.submit();
}