// One character letters
t_table1 = "ABVGDEZIJKLMNOPRSTUFHCWYabvgdezijklmnoprstufhcwy'\"x";
w_table1 = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÛàáâãäåçèéêëìíîïðñòóôõöùûüúõ";

// Two character letters
t_table2 = "EHSZYOJOZHCHSHYUJUYAJAehszyojozhchshyujuyajaSzYoYoZhChShYuJuYaJa";
w_table2 = "ÝÙ¨¨Æ×ØÞÞßßýù¸¸æ÷øþþÿÿÙ¨¨Æ×ØÞÞßß";

// HTML Special characters
spec_table=new Array("&trade;","&amp;","&lt;","&gt;","&nbsp;","&copy;","&reg;");


function translitTagAware(str) 
{
 var len = str.length;
 var new_str="";

 for (i = 0; i < len; i++)
 {
  // Skip tags

  while ((i<len) && (str.substr(i,1)=="<"))
  {
      while ( (i<len) && ((c=str.substr(i,1))!=">") )
	  {
		  	new_str+=c;
		  	i++;
	  }
	  new_str+=">";
	  if (i<len-1)
	  {
		  	i++;
	  }
	  else
	  	return new_str;
  }
  
  //skip BBCode
  while ((i<len) && (str.substr(i,1)=="["))
  {
      while ((i<len) && ((c=str.substr(i,1))!="]"))
	  {
		  	new_str+=c;
		  	i++;
	  }
	  new_str+="]";
	  if (i<len-1)
	  {
		  	i++;
	  }
	  else
	  	return new_str;
  }
  
  //skip html special characters
  
  // Check for 2-character letters
  is2char=false;
  if (i < len-1) {
   for(j = 0; j < w_table2.length; j++)
   {
    if(str.substr(i, 2) == t_table2.substr(j*2,2)) {
     new_str+= w_table2.substr(j, 1);
     i++;
     is2char=true;
     break;
    }
   }
  }

  if(!is2char) {
   // Convert one-character letter
   var c = str.substr(i, 1);
   var pos = t_table1.indexOf(c);
   if (pos < 0)
    new_str+= c;
   else 
    new_str+= w_table1.substr(pos, 1);
  }
 }

 return new_str;
}
   
