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> You are signed in as ');
		fullname();
		document.write('								</strong>');
		document.write('\(');
		email();
		document.write('\)\.');
		document.write('									<br>');
		document.write('									<a href="http://myinfo.apple.com">Update your email address</a>');
		document.write('									<br>');
		document.write('<a href="http://signin.info.apple.com/?logout=now">Sign out</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;
  var videoname    = f.videoname.value;
  var subject2     = f.subject2.value; // order number
  var ipodModelVal = getSelectedRadio(f.ipodModel);
  var timecodeVal  = getSelectedRadio(f.timecode);
  var min          = f.min.value;
  var sec          = f.sec.value;

  var alertMsg = "Please fill in all required fields\nbefore submitting the form. \n\nThank You!";
  var extraInfo;
  if (!pulldown || !altbody || !subject2 || !fname || !lname || !accountname || !platform) {
    alert(alertMsg);
    return false;
  }
  if (pulldown == "Video quality" && !timecodeVal) {
    alert(alertMsg);
    return false;
  }
  if (pulldown == "Video quality" && timecodeVal == 'Specific time' && (!min || !sec)) {
    alert(alertMsg);
    return false;
  }
  if (pulldown == 'Video quality' && timecodeVal == 'Specific time') {
    extraInfo = 'Location           : ' + timecodeVal + ' ' + min + ':' + sec + ' (min:sec)\n' ;
  }
  else if (timecodeVal) {
    if (!min) { min = 'NA'; }
    if (!sec) { sec = 'NA'; }
    extraInfo = 'Location           : ' + timecodeVal + ' (min:sec for reference: ' + min + ':' + sec + ')\n';
  }
  if (pulldown == "Can't transfer") {
    if (!ipodModelVal) {
       alert(alertMsg);
       return false;
    }
    extraInfo = 'iPod video model   : ' + ipodModelVal + '\n';
  }

  itunesname = itunesname ?  itunesname : 'Not provided';
  f.body.value  = 'iTunes Account Name: ' + itunesname + '\n';
  f.body.value += 'Platform           : ' + platform + '\n';
  f.body.value += 'Video Name        : ' + videoname + '\n';
  if (extraInfo) {
     f.body.value += extraInfo;
  }
  f.body.value += 'Comments:\n' + altbody;

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

 f.submit();
 return true;
}

function checkSelection(pulldown) {
    var val = pulldown[pulldown.selectedIndex].value;
    if (val == "Video quality") {
        timecode.style.display = 'block';
        ipodModel.style.display = 'none';
    }
    else if (val == "Can't transfer") {
        timecode.style.display = 'none';
        ipodModel.style.display = 'block';
    }
    else {
        timecode.style.display = 'none';
        ipodModel.style.display = 'none';
    }
}
