function printRatingForm(title, text, captionSubmit, feedbackTitle, feedbackText, grades)
{
  if (!window.s_prop10)
  {
    return;
  }

  _printFormTop(title);
  document.writeln('<div><b>' + _esc(text) + '</b></div><br />');

  document.writeln('<table border="0" cellpadding="0" cellspacing="0">');

  for (var i = 0; i < grades.length; ++i)
  {
    if (!grades[i] || grades[i].length < 2)
    {
      continue;
    }

    var caption = grades[i][0];
    var value = grades[i][1];
    
    document.writeln('  <tr>');
    document.writeln('   <td valign="top">');
    document.writeln('     <input type="radio" name="grade" value="' + _esc(value) + '" />');
    document.writeln('   </td>');
    document.writeln('   <td>');
    document.writeln('     ' + _esc(caption));
    document.writeln('   </td>');
  }

  document.writeln('</table>');
  document.writeln('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
  document.writeln('  <tr>');
  document.writeln('    <td width="100%">&nbsp;</td>');
  document.writeln('    <td>');
  document.writeln('      <input type="hidden" name="prop10" value="' + window.s_prop10 + '" />');
  document.writeln('      <input type="submit" class="primButton" name="submit" value="'
                          + _esc(captionSubmit) + ' &raquo;" onclick="return _ratingSubmit(\''
                          + _esc(feedbackTitle) + "', '"
                          + _esc(feedbackText) + "')\" />");
  document.writeln('    <td>');
  document.writeln('  </tr>');
  document.writeln('</table>');  
  _printFormBottom();
}


function printFeedbackForm(title, text)
{
  _printFormTop(title);
  document.writeln('<div><b>' + _esc(text) + '</b><div><br />');
  _printFormBottom();
}


function _printFormTop(title)
{
  document.writeln('<form name="ratingForm" action="" method="post">');
  document.writeln('<table border="0" cellpadding="0" cellspacing="0" width="100%">');
  document.writeln('  <tr>');
  document.writeln('    <td valign="top" colspan="3"><h2 class="bold" id="rating_title">' + _esc(title) + '</h2></td>');
  document.writeln('  </tr>');
  document.writeln('  <tr class="decoration">');
  document.writeln('    <td class="theme" colspan="3"><img src="http://welcome.hp-ww.com/img/s.gif" width="1" height="4" alt=""></td>');
  document.writeln('  </tr>');
  document.writeln('  <tr class="colorE7E7E7bg">');
  document.writeln('    <td colspan="3"><img src="http://welcome.hp-ww.com/img/s.gif" width="1" height="10" alt=""></td>');
  document.writeln('  </tr>');
  document.writeln('  <tr class="colorE7E7E7bg">');
  document.writeln('    <td width="10" style="width: 10px; "><img width="10" src="http://welcome.hp-ww.com/img/s.gif" /></td>');
  document.writeln('    <td width="100%" valign="top" id="rating_content"><div>');
}


function _printFormBottom()
{
  document.writeln('    </div></td>');
  document.writeln('    <td width="10" style="width: 10px"><img width="10" src="http://welcome.hp-ww.com/img/s.gif" /></td>');
  document.writeln('  </tr>');
  document.writeln('  <tr class="colorE7E7E7bg">');
  document.writeln('    <td colspan="3"><img src="http://welcome.hp-ww.com/img/s.gif" width="1" height="10" alt=""></td>');
  document.writeln('  </tr>');
  document.writeln('</table>');
  document.writeln('</form>');
}


function _esc(text)
{
  text = '' + text;
  text = text.replace("<", '&lt;');
  text = text.replace(">", '&gt;');
  text = text.replace("&", '&amp;');
  text = text.replace('"', '&quot;');
  text = text.replace("'", '&apos;');
  text = text.replace('\n', '<br />');
  return text;
}

function _ratingSubmit(feedbackTitle, feedbackText)
{
  var req = null;

  if (window.ActiveXObject)
  {
    req = new ActiveXObject('Microsoft.XMLHTTP');
  }
  else if (window.XMLHttpRequest)
  {
    req = new XMLHttpRequest();
  }
  else
  {
    return true;
  }
  
  var prop10 = window.s_prop10;
  var gradeObjs = document.ratingForm.grade;
  var grade = null;

  for (var i = 0; i < gradeObjs.length; ++i)
  {
    if (gradeObjs[i].checked)
    {
      grade = gradeObjs[i].value;
      break;
    }
  }

  var ratingTitleElem = document.getElementById('rating_title');
  var ratingContentElem = document.getElementById('rating_content');

  if (!prop10 || grade === null || grade === null || !ratingTitleElem
      || !ratingContentElem)
  {
    return false;
  }

  var contentHeight = ratingContentElem.offsetHeight;
  ratingTitleElem.removeChild(ratingTitleElem.childNodes[0]);
  ratingTitleElem.appendChild(document.createTextNode(feedbackTitle));
  ratingContentElem.removeChild(ratingContentElem.childNodes[0]);
  var node = document.createElement('b');
  ratingContentElem.height = contentHeight;
  node.appendChild(document.createTextNode(feedbackText));
  ratingContentElem.appendChild(node);

  //req.onreadystatechange = processReqChange;
  var url = 'http://newpiece.hp.21torr.com/ratings/ratings.php?prop10=' + prop10 + '&grade=' + grade;
  url = '/ratings/ratings.php?prop10=' + prop10 + '&grade=' + grade;
  req.open('GET', url, true);
  req.send('')

  return false;
}
