if(!ANSW) {
  var ANSW=new Object();
}

if(!ANSW.Trigger) {
  ANSW.Trigger=new Object();
}

ANSW.Trigger.alert1=function(_1){};
ANSW.Trigger.alert2=function(_2){};
ANSW.Trigger.Init=function(_3,_4) {
  ANSW.Trigger.trigger=_3;
  ANSW.Trigger.triggerModKey=_4;
};

if(!ANSW.Trigger.altClickSupported) {
  ANSW.Trigger.isOpera=navigator.userAgent.toLowerCase().indexOf("opera")!=-1;
  ANSW.Trigger.isSafari=navigator.userAgent.toLowerCase().indexOf("khtml")!=-1;
  ANSW.Trigger.isSafari3=ANSW.Trigger.isSafari&&navigator.userAgent.toLowerCase().search("version/[3456789]")!=-1;
  ANSW.Trigger.moz=(document.all==null&&document.getElementById!=null&&document.layers==null);
  ANSW.Trigger.isIE=(document.all?true:false)&&!ANSW.Trigger.isOpera;
  ANSW.AnswerTipEnabled="unknown";
  if(typeof ANSW!="undefined"&&typeof (ANSW.b5)!="undefined") {
    ANSW.Trigger.path=ANSW.Balloon.prototype.answersURL;
    if(ANSW.Trigger.path.indexOf(":8080")!=-1)
    {
      ANSW.Trigger.path+="/answers";
    }
  }
  if(!ANSW.Trigger.trigger) {
    //STEVE CHANGE - need things to happen on mouse over, not dblclick
    //ID won't work with mouse over?
    //ANSW.Trigger.Init("dblclick","");
    //ANSW.Trigger.Init("mouseover","");
  }
  //document.addEventListener('mouseover',ActivateAnswers,false);
  if(ANSW.Trigger.moz) {
    document.addEventListener(ANSW.Trigger.trigger,function(e){window.event=e;},true);
  }
  ANSW.rangeOffset=-1;
  ANSW.rangeParent=null;
}

var deadFlag = 0;
var globalMouseEvent = null;
var globalX = 0;
var globalY = 0;
var globalTagName = null;
var globalTdId = null;
var globalIdName = null;
var globalIdValue = null;
//false when a mouseout occurs before the wait period is over(dealing with delay)
var okToActivate = 0; 
var deadMin = 1000;
var lagTime = 900
function ClearBalloonVars() {
  ANSW.b5.ClearBalloonFlag();
  deadFlag = 1;
  setTimeout("ComeAlive()",500);
}

function ComeAlive() {
  deadFlag=0;
}

function OverBalloon() {} //called OnMouseOver of a balloon
function LeaveBalloon() {} //called OnMouseOut of a balloon

//called OnMouseOut of a ? image or stat
function CloseAnswers(e) {
  document.body.style.cursor='default'
  okToActivate = 0;
}

//called OnMouseOver of a ? image or stat
function ActivateAnswers(e) {
  document.body.style.cursor='pointer'
  okToActivate = 1;
  GetStuffFromEvent(e);
  if(globalTagName == "IMG" || globalTdId == "img_stats" || globalTdId == "span_stats") {
    setTimeout("ActivateAnswers2()",lagTime);
  }
}

function ActivateAnswersViaClick(e) {
  ClearBalloonVars();
  deadFlag = 0;
  GetStuffFromEvent(e);
  okToActivate=1;
  ActivateAnswers2();
}

function GetStuffFromEvent(e) {
  if (!e) e = window.event;
  globalMouseEvent = e;
  globalX = e.clientX;
  globalY = e.clientY;
  if(ANSW.Trigger.isIE) {
    globalTagName = e.srcElement.tagName;
    globalTdId = e.srcElement.id;
  } else {
    globalTagName = e.target.tagName
    globalTdId = e.target.id;
  }
  globalIdName = document.location.toString();
  globalIdValue = document.location.toString();
  globalIdName = globalIdName.substring(globalIdName.indexOf("?")+1, globalIdName.indexOf("?")+2);
  if(globalIdName == 'r') {
    globalIdName = document.location.toString();
    globalIdName = globalIdName.substring(globalIdName.indexOf("&")+1, globalIdName.indexOf("&")+2);
  }
  globalIdValue = globalIdValue.substring(globalIdValue.indexOf("=")+1, globalIdValue.length);
}

function ActivateAnswers2() {
  if(okToActivate != 1 && deadFlag == 0) {
    return;
  }
  ANSW.Trigger.LaunchWBQuery("dummy text here" ,0 ,null, globalTdId, globalIdName, globalIdValue);
  return true;
}

ANSW.Trigger.LaunchWBQuery=function(s,fw,_1f, tdId, idName, idValue)
{
  //alert("LaunchWBQuery...\r\ns: " + s + "\r\nfw: " + fw + "\r\n_1f: " + _1f + " tdid " + tdId + " idname " + idName + " idvalue " + idValue);
  if(typeof fw=="undefined") {
    fw=-1;
  }
  if(!ANSW.answersURL) {
    ANSW.answersURL=ANSW.getJSHost();
  }
  if(typeof s=="undefined"||s==null) {
    if(typeof _1f!="undefined"&&_1f!=null&&typeof _1f.s!="undefined") {
      s=_1f.s.value;
    } else {
      s="";
    }
  }
  if(s!="") {
    if(typeof ANSW!="undefined"&&typeof (ANSW.b5)!="undefined")
    {
      //alert("ANSW and ANSW.b5 are defined");
      if(document.documentElement&&document.documentElement.scrollTop)
      {
        theTop=document.documentElement.scrollTop;
      } else {
        if(document.body) {
          theTop=document.body.scrollTop;
        }
      }
      if(document.documentElement&&document.documentElement.scrollLeft) {
        theX=document.documentElement.scrollLeft;
      } else {
        if(document.body) {
          theX=document.body.scrollLeft;
        }
      }
      if(globalY!=null) {
        //loose clientY/X from delay of mouse over ... thank god for ugly global variables
        y=theTop+globalY;
        x=theX=globalX;
      }
      
      if(ANSW.b5.isVisible()) {
        var el;
        if(!ANSW.Trigger.moz) {
          el=event.srcElement;
        } else {
          el=event.target;
        }
        var _21=ANSW.b5.getReal(el);
        if(_21.id=="AnswersBalloon") {
          x=-1;
          y=-1;
        }
      }
      //alert("ANSW.b5.FireQuery()\r\ns: " + s +"\r\ny(top): " + y + "\r\nx(left): " + x + "\r\nfw: " + fw + "\r\ntdId: " + tdId);
      ANSW.b5.FireQuery(s,y,x,fw,null,null,null, tdId, idName, idValue);

    } else {
      var sep=ANSW.answersURL.indexOf("?")<0?"?":"&";
      var _23=ANSW.answersURL+"/"+s+sep+"fw="+fw;
      var _24=window.open(_23,"GuruWnd","height=450,width=800,location,menubar,toolbar,status,resizable,scrollbars");
      if(_24) {
        _24.focus();
      } else {
        if(ANSW.Trigger.openBlockedPopupsInline) {
          location.href=_23;
        }
      }
    }
  } else {
    return false;
  }
};

ANSW.Trigger.noSelect=function() {
  if(event&&event.ctrlKey&&event.altKey) {
    return false;
  }
};

if(document.addEventListener) {
  document.addEventListener(ANSW.Trigger.trigger,ActivateAnswers,true);
  if(ANSW.Trigger.trigger=="dblclick") {
    document.addEventListener("click",onOneClick,true);
  }
} else {
  if(document.all) {
    if(ANSW.Trigger.trigger=="dblclick") {
      document.ondblclick=ActivateAnswers;
    } else {
      if(ANSW.Trigger.trigger=="click") {
        document.onclick=ActivateAnswers;
        document.onselectstart=ANSW.Trigger.noSelect;
      }
    }
  }
}

function onOneClick(_25) {
  ANSW.rangeOffset=_25.rangeOffset;
  ANSW.rangeParent=_25.rangeParent;
}

ANSW.Trigger.altClickSupported=function() {
  if(ANSW.Trigger.isOpera||(ANSW.Trigger.isSafari&&!ANSW.Trigger.isSafari3)||screen.width<=490) {
    return false;
  }
  return true;
};

ANSW.Trigger.numTries1=0;
ANSW.name;
ANSW.Trigger.showLogoIfEnabled=function(_26) {
  if(ANSW.Trigger.altClickSupported()) {
    if(typeof _26!="undefined"&&_26!=null&&_26.length>0) {
      ANSW.name=_26;
    }
    if(ANSW.AnswerTipEnabled=="unknown"&&ANSW.Trigger.numTries1++<20) {
      setTimeout(ANSW.Trigger.showLogoIfEnabled,500);
    }
    if(ANSW.AnswerTipEnabled==true) {
      ANSW.Trigger.showLogo();
    }
  }
};

ANSW.Trigger.numTries2=0;
ANSW.Trigger.showLogo=function() {
  var _27=document.getElementById("answerTipEnabled");
  if(!_27&&ANSW.Trigger.numTries2++<20) {
    setTimeout(ANSW.Trigger.showLogo,500);
  } else {
    if(_27) {
      if(ANSW.name!=null&&ANSW.name.length>0) {
        var _28=ANSW.logo.replace(/double-click_answertip.gif/,ANSW.name);
        ANSW.logo=_28;
      }
      _27.innerHTML=ANSW.logo;
    }
  }
};

String.prototype.trim=function() {
  return this.replace(/^\s+/g,"").replace(/\s+$/g,"");
};

function expandNodeToWords(_29,_2a,num) {
  var _2c=/\W+/;
  var i=0;
  var ifw=-1;
  var _2f=0;
  if(_29.length==0) {
    return "";
  }
  _29=_29.toString().trim();
  var _30=_29.split(_2c);
  for(i=0; i<_30.length; i++) {
    if(_30[i]==_2a) {
      ifw=i;
      break;
    }
  }
  if(ifw>=0) {
    _29="";
    if(ifw>=num) {
      i=ifw-num;
      ANSW.fw=num;
    } else {
      i=0;
      ANSW.fw=ifw;
    }
    if(ifw+num<=_30.length-1) {
      _2f=ifw+num;
    } else {
      _2f=_30.length-1;
    }
    for(i; i<=_2f; i++) {
      if(i!=_2f) {
        _29+=_30[i]+" ";
      } else {
        _29+=_30[i];
      }
    }
    return _29;
  } else {
    return "";
  }
}
