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>');
	}
}

//Get browser info
var agt = navigator.userAgent.toLowerCase();
var submitcount=0;

is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) ||
(agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95"!=-1) ) ||

(agt.indexOf("win16")!=-1) || (agt.indexOf("16bit")!=-1) ||
(agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("windows 16-bit")!=-1) ||
(agt.indexOf("win 9x 4.90")!=-1) || (agt.indexOf("windows nt 5.")!=-1) ||
(agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1) ||
(agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1)
);
is_ie = (agt.indexOf("msie") != -1);
is_mac = (agt.indexOf("mac") != -1);
is_ok = is_mac || (agt.indexOf("windows nt 5.") != -1);

function getObj(name) {
  if (document.getElementById) {
    this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;
  }
  else if (document.all) {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  }
  else if (document.layers) {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}

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

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

  if (extraRequired) {
    if (!musiccard || !activationcode) {
        alert(alertStr);
        return false;
     }
     f.body.value += 'Music Card       : ' + musiccard + '¥n';
     f.body.value += 'コードを有効にする  : ' + activationcode + '¥n';
  }
  f.body.value += 'コメント: ' + altbody;

 f.submit();
 return true;
}

