

$parseLast = "";
$sendLast = "";
function parseText()
{
   
    orig = _Find("message").value;
    xml = " " + orig.toLowerCase() + " ";



    if(orig==""){$sendLast="";return ajax_callback_return_js("handlers/ajax.contactus.php","");}
    if(xml==$parseLast){return;}   
    $parseLast = xml;
    
    
    // only allow alpha-numeric characters
    xml = xml.replace(/[^a-zA-Z 0-9]+/g,' ');
    
    // word list to ignore
    $bad_words = new Array("and","any","also","alot","are","ask","but","can","cant","cheer","come","could","does","for","from","get","has","have","hav","hello","hey","her","here","hi","how","its","ive","like","mate","need","never","not","our","please","someone","somehow","sorry","take","the","then","thank","that","than","they","tell","there","their","this","these","try","use","using","want","was","what","when","which","with","your","you","triblog","swimblog","runblog","rowblog","bikeblog","com","dave");
    
    // search for each of the ignore (bad) words
    for(var i in $bad_words)
    {
        regex = new RegExp("\\s+"+$bad_words[i]+"\\s+","gi");        
        regex2 = new RegExp("\\s+("+$bad_words[i]+"s)\\s+","gi");  //word with (s)
        regex3 = new RegExp("\\s+("+$bad_words[i]+"ing)\\s+","gi");  //word with ing        
        
        xml = xml.replace(regex," ");
        xml = xml.replace(regex2," ");
        xml = xml.replace(regex3," ");
    }
    
    // create an array of all the words
    final_words = xml.split(" ");
    
    // filter out short words and duplicates
    xml = " ";
    for(var i in final_words)
    {
        word = final_words[i];
        word = word.toLowerCase();
        
        if(word.length>2)
        {
            regex = new RegExp("\\s+("+word+")\\s+","gi");
            //regex2 = new RegExp("\\s+("+word+")\\s+","gi");              
            if(!xml.match(regex)) // && !xml.match(regex2))
            {
                xml += word+" ";    
            }
        }
    }
    // get rid of the leading space
    xml = xml.substring(1);    
    
    // if already sent this word list then exit
    if(xml==$sendLast){return;}
    $sendLast = xml;
    
    // if this word list is empty
    if(xml==null || xml=="" || xml==" ") {$sendLast="";return ajax_callback_return_js("handlers/ajax.contactus.php","");}
    
    // show which words are being used
    if(xml!="") {_Find("side2").innerHTML = "Searching for: "+xml+""; }
    else {_Find("side2").innerHTML = "";}
	
    // do the ajax callback
	ajax_callback_return_js("handlers/ajax.contactus.php",xml);
    
}
