
 //(C)2001 S Chalmers

function tAlert(field,str)
{

 field.value+="\n\n"+str+"\n\n";
 
  if(document.layers)
  {
   alert(str);
   document.forms['FB'].comment.focus();
  }
 
 return field.value.length;
}

function sFind(st, sub) //return end point of found string
{
 var p;

 if( (p=st.toLowerCase().indexOf(sub))!=-1 )  
   p+=st.length;

 return p;
}

function wordBoundary(s)
{
 var r=false, notAlphas=" ?/\\.,\';:-=+_\n\r";

 for(var i=0 ; i<notAlphas.length; i++)
  if(s==notAlphas.charAt(i))
   r=true;

 return r;
}

function wFound(fCount, wList, field)//returns count of words found or index+1 of first
{
 var i, j, first=-1, compStr, os, wildStart, wildEnd, found=0, startFound, endFound;

 for(i=0; i<wList.length; i++)
 {
  compStr=wList[i];

  if(compStr.charAt(compStr.length-1)=='*')
  {
   wildEnd=true;  
   compStr=compStr.substring(0,compStr.length-1);
  }
  else
   wildEnd=false;

  if(compStr.charAt(0)=='*')
  {
   wildStart=true
   compStr=compStr.substring(1,compStr.length);
  } 
  else
   wildStart=false;

  if( (os=field.toLowerCase().indexOf(compStr))!=-1 ) /*found..*/
   {       
    if(!wildStart)
    { 
      if(os==0 || wordBoundary(field.charAt(os-1)) ) /*preceding char not alpha*/
       startFound=true;        
      else
       startFound=false;
    }
    else
     startFound=true;

    if(!wildEnd)
     {
      if( wordBoundary(field.charAt(os+compStr.length)) ) //next char not alpha
       endFound=true;
      else
       endFound=false;
     }
    else
     endFound=true;

    if(startFound && endFound)
      found++;                

    if(first==-1 && found)
     first=i+1; //record index of first found 
   }   
 }

 return fCount ? found : first;
}


var startPt=0, bsTimer,lastNoted=0, projectTell=false, pcbAsk=false, 
     buildAsk=false, kitAsk=false, sellAsk=false, priceAsk=false, 
     newTechAsk=false, localeAsk=false, infoAsk=false, canMarket=false, 
     designAsk=false, lostRag=false, spanishSite=false;

var adMan1=new Array("marketi*","markete*","publici*");

var adMan2=new Array("agency", "agent", "background*", "business", "company","consultan*","firm" );

var boardNames=new Array("board", "printed", "circuit", "layout*" );

var oneOff=new Array("*assembl*", "buil*","construct", "creat*", "made","make*","making", "manuf*" );

var payment=new Array("pay","price*", "prici*","charge*","cost*","fee","the damage","set me back","how much","pay you*","remunerat*");

var willing=new Array("willing", "prepared");

var partsKit=new Array("kit*","component*","parts","bits");

var buyBuilt1=new Array( "availa*","buy", "sell*", "sale*", "purchas*", "obtain*", "order*", "stock*", "suppl*","vend*");

var buyBuilt2=new Array("apparat*","*assembled","built","complete*","device*","equipm*",
"linesim*","product","prototype","ready","simula*","tested", "unit*", "working", "card");

var newTech=new Array("isdn", "adsl","*dsl", "digital line*");

var locale1=new Array("us","u.s*", "usa", "ameri*", "united states", /*<< keep at start<<*/ "countr*","europ*", "argenti*", "*land", "*lands","austr*","brasil*","brazil*","canad*","czech*","denm*", "france","french","german*","india*","indones*","ital*", "korea*", "mexic*",  "norw*", "portug*","russia*","serbia*","*slavi*","spanish","spain","*stan","swede*","turk*","vietn*");

var locale2=new Array("compat*","convert*","adapt*","functi*","interface*","modifi*","operat*", "suita*","usab*","used","work");

var moreInfo1=new Array("send*", "post", "*mail", "receive");

var moreInfo2=new Array("info*","schematic*","diagram*","detail*","drawing*","plan*");

var lostIt=new Array("arsehol*", "asshole*", "barstard*", "bastard*", "bollock*", "bugger*", "cunt*", "get stuffed", "*fuck*", "pillock*", "prat*","prick*", "shit*", "suck*", "tosser*", "twat*", "up yours", "wanker*");

var helpWord=new Array("aid*","help*","assist*","a hand");

var designWord=new Array("design*","modif*","adapt*","convert*");

var youWord=new Array("you*");

var myProject=new Array("project","assignment");
var myCollege=new Array("student","study*","college","school","uni","university","degree","diploma");

var otherSite=["astecsup.org/project_2.html"];



function berkScan()
{
 /*** FAQ Stealth Trap ***/

 var s="", FCOUNT=true, FIRSTFOUND=false;
 var t=document.forms["FB"].elements['comment'];
 var sText=t.value,  i, j;
 
 if(startPt>sText.length)
  startPt=sText.length;

 s=sText.substring(startPt,sText.length);
 
 //window.status = startPt+ "   "+ (s.length ? s : "No Text"); 

 if(s && !projectTell)
  {
   if( wFound(FCOUNT,myProject,s)&& wFound(FCOUNT,myCollege,s))
    {
     startPt=tAlert(t,"OK - but I hope you don't claim it as your own design!\n\nBTW, IMO you're studying the wrong subject. Switch to Computer Science and earn what you're worth. Electronics is a hobby.\n\n");
     projectTell=true;
     s="";
   }
  }


 if(s && !pcbAsk)
 {
  if( sFind(s,"pcb")!=-1 || sFind(s,"p.c.b")!=-1|| wFound(FCOUNT,boardNames,s)>1 )
   {
    startPt=tAlert(t,"NO - AS I HAVE STATED CLEARLY:\n\nI HAVE NO PCBs OR PCB LAYOUT");
    pcbAsk=true;
    s="";
   }
 }

 if(s && !buildAsk)
  {
   if( wFound(FCOUNT,oneOff,s)&& wFound(FCOUNT,willing,s)&& wFound(FCOUNT,payment,s) && wFound(FCOUNT,youWord,s))
    {
     startPt=tAlert(t,"NO - I CANNOT BUILD ONE FOR YOU\nAND I DON'T KNOW OF ANYONE WHO MAY.")
     buildAsk=true;
     s="";
   }
  }


 if(s && !kitAsk)
  {
   var pk;

   if( ((pk=wFound(FCOUNT,partsKit,s)) && wFound(FCOUNT,payment,s)) 
        || 
       ( pk && wFound(FCOUNT,buyBuilt1,s)) )
    {
     startPt=tAlert(t,"THE TOTAL PRICE OF THE COMPONENTS IS SUBJECT TO REGIONAL VARIATION, THEREFORE I CANNOT PROVIDE A REALISTIC ESTIMATE.\n\nI DO NOT SUPPLY ANY COMPONENTS OR PARTS FOR THIS PROJECT.");
     kitAsk=true;
     s="";
    }
  }


 if(s && !sellAsk)
 {
  if( wFound(FCOUNT,buyBuilt1,s) && wFound(FCOUNT,buyBuilt2,s) )
    {
     startPt=tAlert(t,"I DO NOT SUPPLY COMPLETED UNITS OR KITS\n& DO NOT BUILD THEM TO ORDER.");
     sellAsk=true;
     s="";
    }
 }   

 if(s && !priceAsk)
    {
     if(wFound(FCOUNT,payment,s) && wFound(FCOUNT,buyBuilt2,s))
     {
      startPt=tAlert(t,"THIS PROJECT IS NOT FOR SALE, EITHER AS A KIT OR COMPLETED UNIT,"+" AND I DO NOT BUILD THEM TO ORDER.");
      priceAsk=true;
      s="";
     } 
    }
	

 if(s && !newTechAsk)
   { 
    if((nt=wFound(FIRSTFOUND,newTech,s))>0)
     {
      startPt=tAlert(t,"I HAVE INSUFFICIENT KNOWLEDGE OF: " +newTech[nt-1].toUpperCase());
	     newTechAsk=true;
      s="";
     }
   }
	

 if(s && !localeAsk)
   {
    var usPoint=-1;
    if(wFound(FCOUNT,locale1,s) && 
       wFound(FCOUNT,locale2,s) &&
       !((usPoint=wFound(FIRSTFOUND,locale1,s))==1 && s.indexOf('US')==-1) 
      )
     {
      startPt=tAlert(t,usPoint>5?"I CAN NOT BE CERTAIN ABOUT THE EQUIPMENT COMPATIBILITY OF OTHER COUNTRIES.\n\nNo significant problems have been reported.":"Reports suggest this unit to be compatible with U.S. equipment.");
      localeAsk=true;
      s="";
     } 
   }

  if(s && !infoAsk)
   {
    if(wFound(FCOUNT,moreInfo1,s) && wFound(FCOUNT,moreInfo2,s))
    {
     startPt=tAlert(t,"I HAVE NO FURTHER INFORMATION OTHER THAN THAT ON THIS SITE.")
     infoAsk=true;
     s="";
    }
   }

  if(s && !canMarket)
   if(wFound(FCOUNT,adMan1,s) && wFound(FCOUNT,adMan2,s))
    {
     canMarket=true;
     startPt=tAlert(t,"As a manufactured item, this unit would be self-marketing via the medium through which you discovered it.\n\nI would not consider paying for marketing services."); 
     s="";
    }

  if(s && !designAsk)
   if( wFound(FCOUNT,helpWord,s) && wFound(FCOUNT,designWord,s) && wFound(FCOUNT,youWord,s))
    {
     designAsk=true;
     startPt=tAlert(t,"I CAN NOT ASSIST WITH OTHER DESIGNS.");
     s="";
    } 

  if(s && !lostRag)
    if( (rudePos=wFound(FIRSTFOUND,lostIt,s)) >0)
     {
      lostRag=true;
      startPt=tAlert(t,"'"+lostIt[rudePos-1].toUpperCase()+"'" + " is unacceptable. Don't get tetchy with me Sunshine; It's not my fault you can't be bothered to read through the site.");
      s="";
     }
     
  if(s && !spanishSite)   
   if(wFound(FCOUNT,otherSite,s))
    {
     spanishSite=true;   
     startPt=tAlert(t,"I AM NOT ASSOCIATED WITH THAT SITE, AND AM NOT RESPONSIBLE FOR AND DID NOT SANCTION ITS CONTENT.\n\nPLEASE CONSULT ITS OWNERS.");  
     s="";
    }

  if(startPt && startPt != lastNoted)
  {
   if(lastNoted==0)
    {
     document.forms['faqNote'].theyAsked.value+=document.forms['FB'].userName.value+'\n'+document.forms['FB'].email.value+'\n';
     canSend();
    } 
   document.forms['faqNote'].theyAsked.value+=document.forms['FB'].comment.value.substring(lastNoted,startPt);
   lastNoted=startPt;
  }

  bsTimer=setTimeout("berkScan()", 1000);
}


