
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Inquiry Form
function validateForm(f) {

	if (document.inquiry.name.value == '') {alert('お名前を入力してください');
		document.inquiry.name.focus();
		return(false);
	}
	
	flag = 0
	for ( i = 0 ; i < document.inquiry.job.length ; i++){
    if (document.inquiry.job[i].checked){ flag = 1; }
    }
    if (!flag){
    alert('組織を選択してください');
    return(false);
	}

	if (document.inquiry.zip.value == '') {alert('郵便番号を入力してください');
		document.inquiry.zip.focus();
		return(false);
	}
	
	if(document.inquiry.prefecture.selectedIndex == 0){
		alert('都道府県を選択してください');
		document.inquiry.prefecture.focus();
		return(false);
	}

	if (document.inquiry.address.value == '') {alert('住所を入力してください');
		document.inquiry.address.focus();
		return(false);
	}
		
	if (document.inquiry.tel.value == '') { alert('電話番号を入力してください。');
		document.inquiry.tel.focus();
		return(false);
	}

	var mail1 = (document.inquiry.mailaddress.value);
	var mail2 = (document.inquiry.mailaddress2.value);
	
	if(mail1 != mail2) {
		alert("メールアドレスが異なります。");
		document.inquiry.mailaddress.focus();
		return(false);
	}

	var retVal = checkEmail(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	
	return retVal
	
}

//Request Form
function validateFormRequest(f) {

	flag = 0
	for ( i = 0 ; i < document.request.checkreport.length ; i++){
    if (document.request.checkreport[i].checked){ flag = 1; }
  }
	if (!flag){
		alert('ご希望の資料を選択してください');
		return(false);
	}	
	
	if (document.request.name.value == '') {alert('ご氏名を入力してください');
		document.request.name.focus();
		return(false);
	}
	
	if (document.request.zip.value == '') {alert('郵便番号を入力してください');
		document.request.zip.focus();
		return(false);
	}
	
	if(document.request.prefecture.selectedIndex == 0){
		alert('都道府県を選択してください');
		document.request.prefecture.focus();
		return(false);
	}

	if (document.request.address.value == '') {alert('ご住所を入力してください');
		document.request.address.focus();
		return(false);
	}

	var mail1 = (document.request.mailaddress.value);
	var mail2 = (document.request.mailaddress2.value);
	
	if(mail1 != mail2) {
		alert("メールアドレスが異なります。");
		document.request.mailaddress.focus();
		return(false);
	}
		
	var retVal = checkEmail(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	
	return retVal
	
}

function checkEmail(f,fld) {

    var s = f.elements[fld].value;
    if (s) {
	var atsymbol = "@";
	var atoffset = s.indexOf(atsymbol);
	if (atoffset == -1) {
	    alert(s + "このメールアドレスは無効です。＠が入っていません");
	    return false
	} else {
	    if (atoffset > s.lastIndexOf(".") || atoffset < s.lastIndexOf(atsymbol)) {
	        alert(s + "このメールアドレスは無効です。ドメイン名がない、あるいは＠が2個以上入っています");
	        return false
	    } else {
			var re = /[^A-Za-z0-9_@\.\-]/;
			var foundArray = re.exec(s);
			if (foundArray) {
			    if (foundArray == " ") {
				alert("メールアドレスにはスペースは使用できません")
			    } else {
				alert("メールアドレスには「" + foundArray + "」は使用できません")
			    }
			    return(false)
			} else {
			    return(true)
			}
	    }
	}	
    } else {
	alert("メールアドレスを入力して下さい");
	return(false)
    }
}

//Request Form English
function validateFormRequest_e(f) {

	flag = 0
	for ( i = 0 ; i < document.request.checkreport.length ; i++){
    if (document.request.checkreport[i].checked){ flag = 1; }
    }
    if (!flag){
    alert('Please enter required field(s)');
    return(false);
	}	
	
	if (document.request.name.value == '') {alert('Please enter required field(s)');
		document.request.name.focus();
		return(false);
	}
	
	if (document.request.zip.value == '') {alert('Please enter required field(s)');
		document.request.zip.focus();
		return(false);
	}
	
	if (document.request.address.value == '') {alert('Please enter required field(s)');
		document.request.address.focus();
		return(false);
	}

	var mail1 = (document.request.mailaddress.value);
	var mail2 = (document.request.mailaddress2.value);
	
	if(mail1 != mail2) {
		alert("The e-mail address you have entered is incorrect.");
		document.request.mailaddress.focus();
		return(false);
	}

	var retVal = checkEmail_e(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	
	return retVal
	
}

// Inquiry Form English
function validateFormInquiryE(f) {

	if (document.inquiry.name.value == '') {alert('Please enter required field(s)');
		document.inquiry.name.focus();
		return(false);
	}
	
	flag = 0
	for ( i = 0 ; i < document.inquiry.job.length ; i++){
    if (document.inquiry.job[i].checked){ flag = 1; }
    }
    if (!flag){
    alert('Please enter required field(s)');
    return(false);
	}

	if (document.inquiry.zip.value == '') {alert('Please enter required field(s)');
		document.inquiry.zip.focus();
		return(false);
	}
	
	if (document.inquiry.address.value == '') {alert('Please enter required field(s)');
		document.inquiry.address.focus();
		return(false);
	}
		
	if (document.inquiry.tel.value == '') { alert('Please enter required field(s)');
		document.inquiry.tel.focus();
		return(false);
	}

	var mail1 = (document.inquiry.mailaddress.value);
	var mail2 = (document.inquiry.mailaddress2.value);
	
	if(mail1 != mail2) {
		alert("The e-mail address you have entered is incorrect.");
		document.inquiry.mailaddress.focus();
		return(false);
	}

	var retVal = checkEmail_e(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	
	return retVal
	
}

function checkEmail_e(f,fld) {

    var s = f.elements[fld].value;
    if (s) {
	var atsymbol = "@";
	var atoffset = s.indexOf(atsymbol);
	if (atoffset == -1) {
	    alert(s + "Address not valid. '@' is missing.");
	    return false
	} else {
	    if (atoffset > s.lastIndexOf(".") || atoffset < s.lastIndexOf(atsymbol)) {
	        alert(s + "Address not valid. No domain name or there are more than one '@'.");
	        return false
	    } else {
			var re = /[^A-Za-z0-9_@\.\-]/;
			var foundArray = re.exec(s);
			if (foundArray) {
			    if (foundArray == " ") {
				alert("A space cannot be used in an e-mail address")
			    } else {
				alert("" + foundArray + " cannot be used in an e-mail address")
			    }
			    return(false)
			} else {
			    return(true)
			}
	    }
	}	
    } else {
	alert("Please enter required field(s)");
	return(false)
    }
}

//Mail Alerts1
function validateMailAlerts1(f){

	var mail1 = (document.registration.mailaddress.value);
	var mail2 = (document.registration.mailaddress2.value);
	
	if(mail1 != mail2) {
		alert("メールアドレスが異なります。");
		return(false);
	}

	
	var retVal = checkEmail(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	return retVal
}

//Mail Alerts2
function validateMailAlerts2(f){

	var retVal = checkEmail(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	return retVal
}

//Mail Alerts3
function validateMailAlerts3(f){

	var mail1 = (document.change.mailaddress2.value);
	var mail2 = (document.change.mailaddress3.value);
	
	if(mail1 != mail2) {
		alert("メールアドレスが異なります。");
		return(false);
	}

	
	var retVal = checkEmail(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	return retVal
}

//Mail Alerts English 1
function validateMailAlerts_e1(f){

	var mail1 = (document.registration.mailaddress.value);
	var mail2 = (document.registration.mailaddress2.value);
	
	if(mail1 != mail2) {
		//alert("メールアドレスが異なります。");
		alert("The e-mail address you have entered is incorrect.");
		return(false);
	}

	
	var retVal = checkEmail_e(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	return retVal
}

//Mail Alerts English 2
function validateMailAlerts_e2(f){

	var retVal = checkEmail_e(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	return retVal
}

//Mail Alerts English 3
function validateMailAlerts_e3(f){

	var mail1 = (document.change.mailaddress2.value);
	var mail2 = (document.change.mailaddress3.value);
	
	if(mail1 != mail2) {
		alert("The e-mail address you have entered is incorrect.");
		return(false);
	}

	
	var retVal = checkEmail_e(f,'mailaddress')
	if (!retVal) {
		f.mailaddress.focus()
		return(false);	
	}
	return retVal
}
