function checkLogin(val) {
   if (document.cookie.indexOf("ACID=") == -1){
      return '';
   }
   var dc = document.cookie;
   var begin = dc.indexOf("ACID=") + 5;
	var len = dc.length;
   var end   = dc.indexOf(";", begin);
	if (end == -1) { end = dc.length; }
   if (val) {
      var str = unescape(dc.substring(begin,end));
      var array = str.split("~");
      var str = unescape(dc.substring(begin,end));
      var array = str.split("~");
      if (val == 'email') {return array[1]; }
      if (val == 'fname') {return array[2]; }
      if (val == 'lname') {return array[3]; }
		if (val == 'fullname') {return  array[2] + " " + array[3]; }
   }
   return unescape(dc.substring(begin,end));
}

function fname()    { document.write(checkLogin('fname')); }
function lname()    { document.write(checkLogin('lname')); }
function email()    { document.write(checkLogin('email')); }
function fullname() { document.write(checkLogin('fullname')); }

function printWelcome() {
	if (checkLogin('email') != ''){
		document.write('					<table width="170" border="0" cellspacing="0" cellpadding="0">');
		document.write('						<tr>');
		document.write('							<td valign="middle" class="sidebartop">');
		document.write('								<span class="G10">Welcome</span>');
		document.write('							</td>');
		document.write('						</tr>');
		document.write('						<tr>');
		document.write('							<td valign="top" class="sidebar">');
		document.write('								<span class="G10"><strong> サインインしています ');
		fullname();
		document.write('								</strong>');
		document.write('\(');
		email();
		document.write('\)\.');
		document.write('									<br>');
		document.write('									<a href="http://myinfo.apple.com">メールアドレスを更新してください。</a>');
		document.write('									<br>');
		document.write('<a href="http://signin.info.apple.com/?logout=now">サインアウト</a></span>');
		document.write('							</td>');
		document.write('						</tr>');
		document.write('						<tr>');
		document.write('							<td valign="middle" class="sidebarbtm2">');
		document.write('								<img src="http://images.apple.com/support/itunes/elements/spacer.gif" width="1" height="8">');
		document.write('							</td>');
		document.write('						</tr>');
		document.write('					</table>');
		document.write('					<br>');
	}
}

function validate(f) {
  var pulldown     = f.category[f.category.selectedIndex].value;  
  var altbody      = f.altbody.value;   
  var fname        = f.fname.value;   
  var lname        = f.lname.value;   
  var accountname  = f.accountname.value; 
  var platform     = f.platform[f.platform.selectedIndex].value;
  var itunesname   = f.itunesname.value;

  if (!pulldown || !altbody || !fname || !lname || !accountname || !platform) {
    alert("フォームを送信する前に、¥n必須なフィールドすべてに入力してください。¥n¥nお問い合わせいただきありがとうございます。");
    return false;
  }
  itunesname = itunesname ?  itunesname : '記入なし';
  f.body.value  = 'iTunes アカウント名: ' + itunesname + '¥n';
  f.body.value += 'プラットフォーム          : ' + platform + '¥n';
  f.body.value += 'コメント:¥n' + altbody;

// program defaults to itunesmac, change based on platform
  if (platform.substring(0,7) == 'Windows') {
  f.program.value = 'ituneswin_jp';
}

 f.submit();
 return true;
}

