function chk() {
	alert(document.email.personalized.value);
}
function validate() {
	var form = document.email;

	// Get parameter values and check for required elements
	// All forms have the following
	body = form.comments.value;
	category = form.category.options[form.category.selectedIndex].value;
	product = form.product.options[form.product.selectedIndex].value;
	serialnumber = form.serialnumber.value;
	agreementnumber = form.agreementnumber.value;
	personalized = form.personalized.value;
	os = form.os.value;
	
	if (!product) {
		alert('You must specify a product!');
		return false;
	}
	if (!category) {
		alert('You must select an option telling us how we can help!');
		return false;
	}
	if (!body) {
		alert('You must enter some comments!');
		return false;
	}

	if ((product == 'iPod' || product == 'iPod mini') && !personalized) {
		openWindow('/support/service/help/extrainfo.html','500','350');
		return false;
	}

	// This will only kick-in if an iPod is selected
	if (personalized == 'yes') {
		product = 'Personalized ' + product;
	}

	// Set body value for submittal and start appending the 'extra' information
	body = body + '\n\n--------------------- Additional Info -------------------------';

	// Not all forms have these. Check to see if the form has it, and if so, then check to
	// see if it has a value. If so, append it to the body parameter.
	if (os) {
		body = body + '\nOperating system: ' + os;
	}
	if (product) {
		body = body + '\nProduct: ' + product;
	}
	if (!serialnumber) {
		serialnumber = 'Not provided';
	}
	body = body + '\nSerial number: ' + serialnumber;

	if (!agreementnumber) {
		agreementnumber = 'Not provided';
	}
	body = body + '\nAgreement number: ' + agreementnumber;

	body = body + '\nHelp page: ' + form.helppage.value;	
	
	// If everything checks out to here, we set key parameters and then submit the form.
	// The subject1 value (the Sonar category) get the os appended if we've set it
	if (os) {
		form.subject1.value = product + ' for ' + os;
	}
	else {
		form.subject1.value = product;
	}

	// The subject shown to the user is made more descriptive than justt the subject1 value
	form.subject.value = form.subject1.value + ' (' + form.category.value + ')'

	// We set the body value to what the request processor expects
	form.body.value = body;

	// And finally, we submit
	form.submit();

	// Re-set these value so the form won't auto-submit if the user submits again
	form.personalized.value = '';
	form.os.value = '';
}

function printForm(helppage){
var pulldown = new Array(
  "Setting up Service","Setting up service",
  "Questions about Warranty","Question about warranty",
  "Paying for Out of Warranty Service","Paying for out-of-warranty service",
  "Enrolling or using an AppleCare Agreement","Enrolling or using an agreement",
  "General Feedback","General self service feedback"
);
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">Still having trouble?</span></strong>');
document.write('										            <br>');
document.write('														            <br>');

// Login check here will present a login option instead of the form if the user is not current logged in
if (!checkLogin('email')){
	document.write('If you\'re still having trouble, please ');
	document.write('<span style="color: #00f; text-decoration: underline; cursor: pointer;" onClick="login();">login</span>');
	document.write(' to send us email. Our support experts will reply to your request within 1 business day.');
	return;
}

document.write('				If you\'re still having trouble, let us know. Our support experts will reply to your request within one business day. Your answer will be sent to your registered email address, ');
email();
document.write('. To switch to another account, you will need to <a href="http://signin.info.apple.com/?logout=now">log out</a> and log back in under your alternate account name.');
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()">');
document.write('					<table border="0" cellpadding="0" cellspacing="0" width="600" valign="TOP">');
document.write('						<tr>');
document.write('							<td width="290" height="50" align="left" valign="top" class="L11">');
document.write('								<b>From:</b>');
document.write('								<br>');
document.write('<script language="javascript">fullname();</script>');
document.write('							</td>');
document.write('							<td width="20" align="left" valign="top" class="L11">');
document.write('								<img src="/support/service/help/elements/spacer.gif" width="20" height="1">');
document.write('							</td>');
document.write('							<td width="290" align="left" valign="top" class="L11">');
document.write('								<b>Registered email address:</b>');
document.write('								<br>');
document.write('<script language="javascript">email();</script>');
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>What can we help you with today?</b>');
document.write('								<br>');
document.write('								<select name="category" class="form250">');
document.write('								<option value="" selected>');
document.write('								-- Select --');
document.write('								</option>');
for (i=0 ; i < pulldown.length ; i=i+2) {
	document.write("								<option value=\"" + pulldown[i] + "\">");
	document.write("								" + pulldown[i+1]);
	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 align="left" valign="top" class="L11">');
document.write('								<b><span style="color: #f00">*</span>Please select your product:</b>');
document.write('								<br>');
document.write('								<select name="product" class="form250">');
document.write('								<option value="" selected>-- Select --</option>');
document.write('								<option value="AppleTV">AppleTV</option>');
document.write('								<option value="iPhone">iPhone</option>');
document.write('								<option value="iPod">iPod</option>');
document.write('								<option value="iPod mini">iPod mini</option>');
document.write('								<option value="iPod shuffle">iPod shuffle</option>');
document.write('								<option value="iSight">iSight</option>');
document.write('								<option value="iMac">iMac</option>');
document.write('								<option value="eMac">eMac</option>');
document.write('								<option value="iBook">iBook</option>');
document.write('								<option value="MacBook">MacBook</option>');
document.write('								<option value="MacBook Pro">MacBook Pro</option>');
document.write('								<option value="PowerBook">PowerBook</option>');
document.write('								<option value="Mac Pro">Mac Pro</option>');
document.write('								<option value="Power Mac">Power Mac</option>');
document.write('								<option value="Xsan">Xsan</option>');
document.write('								<option value="Xserve">Xserve</option>');
document.write('								</select>&nbsp;');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td height="50" align="left" valign="top" class="L11">');
document.write('								<b>Product serial number:</b>');
document.write('								<br>');
document.write('								<input type=text" name="serialnumber" class="form250">');
document.write('							</td>');
document.write('							<td align="left" valign="top" class="L11">');
document.write('								&nbsp;');
document.write('							</td>');
document.write('							<td align="left" valign="top" class="L11">');
document.write('								<b>AppleCare agreement number:</b>');
document.write('								<br>');
document.write('								<input type=text" name="agreementnumber" class="form250">');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td colspan="3" class="L11">');
document.write('								<b><span style="color: #f00">*</span>Comments</b>:');
document.write('								<br>');
document.write('								<textarea name="comments" cols="60" rows="6" class="form600"></textarea>');
document.write('							</td>');
document.write('						</tr>');
document.write('						<tr>');
document.write('							<td><span class="G10"><span style="color: #f00"><b>*</b></span> Required</span></td>');
document.write('							<td align="center" colspan="2">');
document.write('								<div align="right">');
document.write('									<input type="HIDDEN" name="fname" value="'+checkLogin('fname')+'">');
document.write('									<input type="HIDDEN" name="lname" value="'+checkLogin('lname')+'">');
document.write('									<input type="HIDDEN" name="accountname" value="'+checkLogin('email')+'">');
document.write('									<input type="HIDDEN" name="body" value="">');
document.write('									<input type="HIDDEN" name="personalized" value="">');
document.write('									<input type="HIDDEN" name="os" value="">');
document.write('									<input type="HIDDEN" name="subject" value="">');
document.write('									<input type="HIDDEN" name="subject1" value="">');
document.write('									<input type="HIDDEN" name="returnurl" value="http://www.apple.com/support/service/help/thankyou.html">');
document.write('									<input type="HIDDEN" name="helppage" value="' + helppage + '">');
document.write('									<input type="HIDDEN" name="program" value="wss_help">');
document.write('									<span style="cursor: pointer;" onClick="validate();"><img src="/support/service/help/elements/sendquestion.gif" width="120" height="28" border="0"></span>');
document.write('								</div>');
document.write('							</td>');
document.write('						</tr>');
document.write('					</table>');
document.write('				</form>');
document.write('			</td>');
document.write('		</tr>');
document.write('	</table>');
}

function checkLogin(val) {
   if (document.cookie.indexOf("ACID=") == -1){
      return 0;
   }
   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 login(){
  var myURL = location.href;
  top.location.href = 'http://signin.info.apple.com/?locationurl=' + myURL + '#form';
}

function openWindow(url, width, height) {
        window.open(url,"extrainfo",'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=yes,status=0,toolbar=no');
}

