appleidimg = new Image();
appleidimg.src = "http://images.apple.com/support/itunes/elements/appleid.gif";
aolimg = new Image();
aolimg.src = "http://images.apple.com/support/itunes/elements/aol.gif";

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 setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function setStyle(style) {
	setActiveStyleSheet(style);
}

function printForm(){
document.write('   <table width="100%" border="0" cellpadding="0" cellspacing="0">');
document.write('	      <tr>');
document.write('			         <td valign="top" class="G10">');
document.write('						            <strong><span class="L18">Still having trouble?</span></strong>');
document.write('										    <br><img src="http://images.apple.com/support/itunes/elements/blue.gif" width="100%" height="1" vspace="3"><br>');
document.write('											<br>');
document.write('				If you\'re still having trouble using the iTunes Music Store, let us know. We respond to requests in the order they are received, and will contact you within 72 hours. Be sure to include your <A HREF="http://www.info.apple.com/kbnum/n93010" TARGET="NEW">web order number</A> if you\'re having trouble with a specific purchase. For your protection, please do <B>not</B> include your credit card number in your message to us.  Your answer will be sent to your email address.');
document.write('				<br>');
document.write('				<br>');
document.write('				<a name="form"> </a>');
document.write('					<form name="email" action="http://depot.info.apple.com/request/" method="POST" onsubmit="return validate(this)">');
document.write('					<table border="0" cellpadding="0" cellspacing="0" width="400" valign="TOP">');
document.write('						<tr>');
document.write('							<td class="G10" valign="top"><b>First Name:<span class="required">*</span> </td>');
document.write('							<td><input name="fname" type="TEXT" class="form250" value="');
fname();
document.write('" size="25"></td>');
document.write('							<td>&nbsp;</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td class="G10" valign="top"><b>Last Name:<span class="required">*</span> </td>');
document.write('							<td><input name="lname" type="TEXT" class="form250" value="');
lname();
document.write('" size="25"></td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td class="G10" valign="top"><b><nobr>iTunes Account Name:<span class="required">*</span> </nobr></td>');
document.write('							<td class="G10" valign="top"><input name="accountname" type="TEXT" class="form250" value="');
email();
document.write('" size="25"</td>');
document.write('							<td id="accounttype"><img src="http://images.apple.com/support/itunes/elements/spacer.gif" height="14" width="138" name="typeimg"></td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td class="G10" valign="top"><b><nobr>Account Type:</nobr><span class="required">*</span></td>');
document.write('							<td class="G10" colspan="2"><input type="radio" name="accounttype" value="appleid" onClick="document[\'typeimg\'].src=appleidimg.src;">Apple ID <span class="G10G">(usually an email address)</span><br><input type="radio" name="accounttype" value="aol" onClick="document[\'typeimg\'].src=aolimg.src;">AOL <span class="G10G">(screen name only)</span></td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td colspan="2"><img src="http://images.apple.com/support/itunes/elements/spacer.gif" width="1" height="20"></td>');
document.write('							<td>&nbsp;</td>');
document.write('						</tr>');
document.write('					</table>');
document.write('					<table border="0" cellpadding="0" cellspacing="0" width="400" valign="TOP">');
document.write('						<tr>');
document.write('							<td height="50" align="left" valign="top" class="G10">');
document.write('								<b>Specific Request:<span class="required">*</span></b>&nbsp;');
document.write('								<br>');
document.write('								<select name="category" class="form250">');
document.write('								<option value="" selected>');
document.write('								-- Choose One --');
document.write('								</option>');
for (i=1 ; i < printForm.arguments.length ; i++) {
	document.write("								<option value=\"" + printForm.arguments[i] + "\">");
	document.write("								" + printForm.arguments[i]);
	document.write('								</option>');
}
document.write('								</select>&nbsp;');
document.write('							</td>');
document.write('							<td>');
document.write('								&nbsp;');
document.write('							</td>');
document.write('							<td align="left" valign="top" class="G10">');
document.write('								<b>Web Order Number:</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="G10" height="50">');
document.write('								<b>Country:</b><span class="required">*</span>');
document.write('<select name="programName"> <option value="ituneswin">United States</option><option value="" selected>------------</option> > <option value="itms_pan_euro_win">Austria</option> <option value="itms_pan_euro_win">Belgium</option> <option value="ITMS_CAN_Win_Eng">Canada (English)</option> <option value="ITMS_CAN_Win_FR">Canada (French)</option> <option value="ituneswin_sc">Denmark</option> <option value="itms_pan_euro_win">Finland</option> <option value="ituneswin_fr">France</option> <option value="ituneswin_de">Germany</option> <option value="itms_pan_euro_win">Greece</option> <option value="itms_pan_euro_win">Ireland</option> <option value="itms_pan_euro_win">Italy</option> <option value="itms_pan_euro_win">Luxembourg</option> <option value="itms_pan_euro_win">Netherlands</option> <option value="ituneswin_sc">Norway</option> <option value="itms_pan_euro_win">Portugal</option> <option value="itms_pan_euro_win">Spain</option> <option value="ituneswin_sc">Sweden</option> <option value="ituneswin_chfr">Switzerland (French)</option> <option value="ituneswin_chde">Switzerland (German)</option> <option value="ituneswin_uk">United Kingdom</option> <option value="ituneswin">United States</option></select>');
document.write('							<br><br>');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td colspan="3" class="G10">');
document.write('								<b>Comments:</b><span class="required">*</span>');
document.write('								<br>');
document.write('								<textarea name="body" cols="70" rows="6" class="form600"></textarea>');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td align="center" colspan="3">');
document.write('								<div align="center">');
document.write('									<input type="HIDDEN" name="returnurl" value="http://www.apple.com/support/itunes/thankyou.html">');
document.write('									<input type="HIDDEN" name="subject1" value="' + printForm.arguments[0] + '">');
document.write('									<input type="HIDDEN" name="program" value="ituneswin">');
document.write('									<input type="button" value="Submit" onClick="javascript:validate(document.email);">');
document.write('								</div>');
document.write('							</td>');
document.write('						</tr>');
document.write('					</table>');
document.write('				</form>');
document.write('			</td>');
document.write('		</tr>');
document.write('	</table>');
document.write('	<p align="left"><span class="required">*</span> <span class="G10G">Indicates required field.</p><br>');
}
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="sidebartop2">');
		document.write('								<img src="http://images.apple.com/support/itunes/elements/spacer.gif" width="1" height="6">');
		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('									<br>');
		document.write('									<strong>');
		email();
		document.write('									</strong>');
		document.write('									<br>');
		document.write('									<a href="http://myinfo.apple.com">change your info</a>');
		document.write('									<br>');
		document.write('									<br>');
		document.write('									If you\'re not ');
		fullname();
		document.write(', <a href="http://signin.info.apple.com/?logout=now">click here</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(form) {
  var pulldown     = form.category.options[form.category.selectedIndex].value;  
  var bodytext     = form.body.value;   
  var fname        = form.fname.value;   
  var lname        = form.lname.value;   
  var accountname  = form.accountname.value; 
  var accounttype;
  j=form.accounttype.length;
  for (i=0; i<j; i++){ if(form.accounttype[i].checked) var accounttype = form.accounttype[i].value }
  
  if (accountname.indexOf("@") != -1 && accounttype == "aol"){
  	alert("Do not include an '@' in your AOL screen name.\nEnter your screen name only, not your email address.");
  	return false;
  }
  
  if (pulldown == 'Redeem a Gift Certificate' && !form.subject2.value) {
    alert('If you select the Redeem a Gift Certificate\noption, you must provide the number.');
    return false;
  }
  
  if (!pulldown || !bodytext || !fname || !lname || !email || !accounttype) {
    alert("Please fill in all required fields\nbefore submitting the form. \n\nThank You!");
    return false;
  }
  var programName;
  var programName = form.programName[form.programName.selectedIndex].value;
  if (!programName) {
	  alert('You must select a country!');
	  return false;
  }
  form.program.value = programName;

	form.submit();
	return true;
}

