function validate(form) {
  var orderNum = form.subject2.value;
  var localSubject = form.subject.value;
  if (orderNum){
  	if (!checkChars(orderNum)){
  		return false;
  	}
  }
  var pulldown = form.category.options[form.category.selectedIndex].value;
  // Set Local Sub Issue to the pull down text, a line feed, then the local support subject
  form.alt_category.value = form.category.options[form.category.selectedIndex].text;
  var bodytext = form.body.value;
  var fname = form.fname.value;
  var lname = form.lname.value;
  var email = form.accountname.value;
  var emailConfirm = form.accountnameConfirm.value;
  if (email != emailConfirm){
  	alert("ご入力いただいた二つのメールアドレスが一致しません");
  	return false;
  }
  var emailChk = emailCheck(form.accountname.value);
  if (!emailChk) { return false; }
  if (!pulldown || !bodytext || !fname || !lname || !emailChk) {
    alert("以下は必須項目です:¥n1. .姓、名ともご記入ください,¥n2. .有効なメールアドレスをご記入ください,¥n3. プルダウンメニューからご質問をお選びください¥n4. 詳細をご記入ください.¥n¥もう一度お試しください。 ありがとうございます。");
    return false;
  }
  else if (orderNum.length > 9) {
    alert("ご注文番号はWで始まる8桁の番号（例：W12345678）です");
    return false;
  }
  else if (bodytext.length > 3000) {
    alert("ご質問内容が長すぎます。記入しきれない場合は直接store@apple.co.jpにメールでご質問してください");
    return false;
  }
  else {
	form.submit();
    return true;
  } 
}
function checkChars(str){
	// Used to ensure the string doesn't contain characters greater than 122 (i.e. single byte only)
	for (var i = 0; i < str.length; i++) {
		A_char = str.charCodeAt(i);
		if (A_char > 122){   // lowercase standard chars
			alert('ご注文番号は半角（例：W12345678）をご使用ください');
			return false;
		}
	}
	return true;
}
function printForm(){
document.write('   <table width="600" border="0" cellpadding="0" cellspacing="0">');
document.write('	      <tr>');
document.write('			         <td valign="top" class="L11">');
document.write('						            <strong><span class="L14">問題は解決しましたか？</span></strong>');
document.write('										            <br>');
document.write('														            <br>');
document.write('問題が解決しない場合、下記フォームに必要事項をご記入の上、ご連絡ください。Apple Storeサポートより回答させていただきます。もし、特定のオーダーについてお困りであれば、ご注文番号（例：W12345678）を必ず明記してください。ご質問にはメールまたはお電話にて回答させていただきます。');
document.write('				<br>');
document.write('				<br>');
document.write('				<a name="form"> </a>');
document.write('					<form name="email" action="https://depot.info.apple.com/request/" method="POST" onsubmit="return validate(this)">');
document.write('					<table border="0" cellpadding="0" cellspacing="0" width="600" valign="TOP">');
document.write('						<tr>');
document.write('							<td width="290" height="40" align="left" valign="top" class="L11">');
document.write('							<table border="0" cellpadding="0" cellspacing="0" width="290">');
document.write('							<tr>');
document.write('							<td width="140">');
document.write('								<b>姓:<span style="color: #F00">*</span></b>');
document.write('								<br>');
document.write('								<input name="fname" type="TEXT" class="form125" value="" size="15">');
document.write('							</td>');
document.write('							<td width="3">&nbsp;</td>');
document.write('							<td width="140">');
document.write('								<b>名:<span style="color: #F00">*</span></b>');
document.write('								<br>');
document.write('								<input name="lname" type="TEXT" class="form125" value="" size="15">');
document.write('							</td>');
document.write('							</tr>');
document.write('							</table>');
document.write('							<td width="20" align="left" valign="top" class="L11">');
document.write('								<img src="http://images.apple.com/jp/store/help/elements/spacer.gif" width="20" height="1">');
document.write('							</td>');
document.write('							<td width="290" align="left" valign="top" class="L11">');
document.write('								&nbsp;');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td>');
document.write('								<b>メールアドレス:<span style="color: #F00">*</span></b>');
document.write('								<br>');
document.write('								<input name="accountname" type="TEXT" class="form250" value="" size="35">');
document.write('							</td>');
document.write('							<td width="20" align="left" valign="top" class="L11">');
document.write('								<img src="http://images.apple.com/jp/store/help/elements/spacer.gif" width="20" height="1">');
document.write('							</td>');
document.write('							<td>');
document.write('								<b>メールアドレスをもう一度ご入力ください:<span style="color: #F00">*</span></b>');
document.write('								<br>');
document.write('								<input name="accountnameConfirm" type="TEXT" class="form250" value="" size="35">');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td height="50" align="left" valign="top" class="L11">');
document.write('								<b>ご質問内容:<span style="color: #F00">*</span></b>');
document.write('								<br>');
document.write('								<select name="category" class="form250">');
document.write('								<option value="" selected>');
document.write('								-- 一つお選びください --');
document.write('								</option>');
for (i=2 ; i < printForm.arguments.length ; i=i+2) {
	j = i + 1;  // Expecting pairs of input, English and Japanese. Subject is in values 0 and 1
	document.write('								<option value="' + printForm.arguments[i] + '">');
	document.write("								" + printForm.arguments[j]);
	document.write('								</option>');
}
document.write('								</select>&nbsp;');
document.write('							</td>');
document.write('							<td align="left" valign="top" class="L11">');
document.write('								&nbsp;');
document.write('							</td>');
document.write('							<td width="290" height="50" align="left" valign="top" class="L11">');
document.write('								<b>ご注文番号:</b>');
document.write('								<br>');
document.write('								<input name="subject2" type="TEXT" class="form250" value="" size="20">');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td colspan="3" class="L11">');
document.write('								<b>詳細をご記入ください:<span style="color: #F00">*</span></b>');
document.write('								<br>');
document.write('								<textarea name="body" cols="60" rows="20" class="form600"></textarea>');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td align="left" class="L11">');
document.write('								<b><span style="color: #F00">*</span></b> 必須項目');
document.write('							</td>');
document.write('							<td align="center" colspan="3">');
document.write('								<div align="right">');
document.write('									<input type="HIDDEN" name="returnurl" value="http://www.apple.com/jp/store/help/thankyou.html">');
document.write('									<input type="HIDDEN" name="errorurl" value="http://www.apple.com/jp/store/help/error.html">');
document.write('									<input type="HIDDEN" name="subject1" value="' + printForm.arguments[0] + '">');
document.write('									<input type="HIDDEN" name="subject" value="' + printForm.arguments[1] + '">');
document.write('									<input type="HIDDEN" name="alt_category" value="">');
document.write('									<input type="HIDDEN" name="program" value="jp_store_help">');
document.write('									<a href="#" onclick="validate(document.email);"><img src="http://images.apple.com/jp/store/help/elements/sendquestion-jp.gif" width="120" height="28" border="0"></a>');
document.write('								</div>');
document.write('							</td>');
document.write('						</tr>');
document.write('					</table>');
document.write('				</form>');
document.write('			</td>');
document.write('		</tr>');
document.write('	</table>');
}

