var aat=0
var pt=0
var mt=0

function touroku2() {
	alert("テスト")
}
function touroku() {
	mailcheck()
	if ( mt ==  0 ) {
		document.tourokuf.submit()
	} else if (mt == 1 ) {
		alert("メールアドレスを入力してください")
		document.tourokuf.email.focus()
	} else if ( mt ==  2 ) {
		alert("スペースが含まれています")
		document.tourokuf.email.focus()
	} else if ( mt ==  3 ) {
		alert("@が含まれていません")
		document.tourokuf.email.focus()
	} else if ( mt ==  4 ) {
		alert("@が" + aat + "個含まれています")
		document.tourokuf.email.focus()
	} else if ( mt ==  5 ) {
		alert(". が含まれていません")
		document.tourokuf.email.focus()
	}
}	

function mailcheck() {
	var ff = document.tourokuf.email.value
	aat=0
	pt=0
	mt=0
	if ( ff == "") {
		mt=1
	} else {
		ff = trim01( ff )
		
		if ( document.tourokuf.email.value != ff ) {
			mt=2
			document.tourokuf.email.value = ff
		} else {
			if ( aat == 0 ) {
				mt=3
				document.tourokuf.email.value = ff
			} else {
				if ( aat > 1 ) {
					mt=4
					document.tourokuf.email.value = ff
				} else {
					if ( pt == 0 ) {
						mt=5
						document.tourokuf.email.value = ff
					} else {
						mt=0
					}
				}
			}
		}
	}
}	

function check02() {
	var a99=document.tourokuf.email
    var a22="連絡用メールアドレスを50文字以内で入力してください"
    var a33="連絡先メールアドレスを入力してください"
    f=0
    check10(a99,a22,a33)
}

function check03() {
	var a99=document.tourokuf.emailk
    var a22="連絡用メールアドレス（確認の為）を50文字以内で入力してください"
    var a33="連絡先メールアドレス（確認の為）を入力してください"
    f=0
    check10(a99,a22,a33)
}

function check10(a99,a22,a33) {
    var a01=a99.value
    if (a01.length>100) {
        alert(a22)
        a99.value=a01.substring(0,50)
        a99.focus()
        f=1
        return "out"
    }

	a01=trim01(a01)

	if ((f==0) && (a01=="")) {
		alert(a33)
        a99.focus()
        f=1
        return "out"
	}

	if ( (a99.value != a01) && (f==0) ) {
		alert("スペースが含まれています")
		a99.value=a01
        a99.focus()
        f=1
        return "out"
	} else {
		if ( a01 != "") {
			if ( aat == 0 ) {
				alert("@が含まれていません")
				a99.value=a01
		        a99.focus()
		        f=1
		        return "out"
			} else {
				if ( aat > 1 ) {
					alert("@が" + aat + "個含まれています")
					a99.value=a01
			        a99.focus()
			        f=1
			        return "out"
				} else {
					if ( pt == 0 ) {
						alert(". が含まれていません")
						a99.value=a01
				        a99.focus()
				        f=1
				        return "out"
					}
				}
			}
		}
	}
}	

function check04() {
	var a01=document.tourokuf.email.value
	var a02=document.tourokuf.emailk.value
	f=0
	
	if ( a01!=a02 ) {
		alert("連絡先メールアドレスがあっていません。")
		document.tourokuf.emailk.focus()       
		f=1
		return "out"
	}
}

function check05() {
    var a01=document.tourokuf.pw.value
    f=0
    
    if (a01.length<1) {
        alert("パスワードを入力してください")
        document.tourokuf.pw.focus()       
        f=1
        return "out"
    }
}

function touroku1() {
	var a01=document.tourokuf.email.value
	var ret=""
	var ho=""
	f=0

	if (f==0) {
		ret=check01()
	}
	
	if (f==0) {
		ret=check02()
	}

	if (f==0) {
		ret=check03()
	}

	if (f==0) {
		ret=check04()
	}

	if (f==0) {
		ret=check05()
	}

	if (f==0) {
		document.tourokuf.submit()
	}
}

function trim01(bb) {
    var sl=0
    var i=0
    var j=1

	i=bb.length
	aat=0
	if ( i == 0 ) {
    return ""
	}
	else {
		for (j=0; j<i; j++) {
			if ( bb.substring(j,j+1) == " " ) {
				bb= bb.substring(0,j) + bb.substring(j+1,i)
				i--
				j--
			}
			if ( bb.substring(j,j+1) == "@" ) {
				aat++
			}
			if ( bb.substring(j,j+1) == "." ) {
				pt++
			}
		}
	}
	return bb
}
