function changeYcrossSell()
{
 csObj = document.getElementById('ys_relatedItems');

  // get all TDs inside the body
 var csTxt = csObj.innerHTML + "";
 var csTDs = csTxt.split(new RegExp("<TD", "i"));

 // arrays to store cs item data
 var csLinks = new Array();
 var csIDs = new Array();
 var csPrices = new Array();

 for(var i=2; csTDs[i]; i++)
 { // strip newlines from text string
  csTDs[i] = csTDs[i].replace(/[\n\r\t]/g,'');

  // get a tag
  csLinks[i] = csTDs[i].replace(/.+<A/i,"<A");
  csLinks[i] = csLinks[i].replace(/<\/A.+/i,"</H3></A>");
  csLinks[i] = csLinks[i].replace(/>/,"><H3>");

  // get page ids
  csIDs[i] = csLinks[i].replace(/.html.+/i,"");
  csIDs[i] = csIDs[i].replace(/.+\//i,"");

  // get pricing information
  csPrices[i] = csTDs[i].replace(/.+<\/H4>/i,"");
  csPrices[i] = csPrices[i].replace(/<\/DIV.+/i,"");
  csPrices[i] = csPrices[i].replace(/<[^>]+>/gi,"");

  // change pricing if needed
  if(csPrices[i].match(/Sale Price/))
  {
   csPrices[i] = csPrices[i].replace(/Sale/,"<br><font style=\"color:#c00\">Sale");
  }
  else
  {
   csPrices[i] = csPrices[i].replace(/Regular Price: /,"");
  }

  // strip down A tags
  csLinks[i] = csLinks[i].replace(/\<\/H.+/i,"");
  csLinks[i] = csLinks[i].replace(/.+\>/,"");

 }

 // create new cross-sell table using this data
 var newTxt="<H2>We Also Recommend:</H2>" +
 "<table border=0 cellspacing=0 "+
 "cellpadding=0 style='font-size:12px;'>"+
 "<tr>";
 for(var i=2; csTDs[i]; i++)
 {
  newTxt += "<td align=center width=200><a href=" + csIDs[i] + ".html><img src=http://www.coolibarimages.com/Cross-sell/100x100/" + csIDs[i] + "-icon.jpg></a></td>";
 }
 newTxt += "</tr><tr valign=top>";
 for(var i=2; csTDs[i]; i++)
 {
  newTxt += "<td align=center style='padding:10px;'><A href=" + csIDs[i] + ".html>" + csLinks[i] + "<br>" + csPrices[i] + "</a></td>";
 }
 newTxt += "</tr></table>";
 csObj.innerHTML = newTxt;  
}



function checkForCrossSell()
{
 if(document.getElementById('ys_relatedItems').innerHTML.length > 100)
 {
   changeYcrossSell();
 }
 else
 {
   setTimeout("checkForCrossSell()",500);
 }
}

checkForCrossSell();
