function intelliResponse(qID,aID,aCID){var me={};me.sampleQuestion=sampleQuestion='Ask it here!';me.questionID=qID;me.answerID=aID;me.answerContainer=aCID;me.sessionID='';me.askQuestion=function(){var theURL='/libraries/app/faq_client.php';var theQues=$('#'+this.questionID).val();if(theQues.length>0){if(theQues==sampleQuestion){window.alert("You need to ask your own question.");return false;}else{theQues=encodeURIComponent(theQues);me.showAsking();var params={'action':'ask','question':theQues};if(typeof(me.sessionID)!='undefined'&&me.sessionID!=''){params['sessID']=me.sessionID;}
$.ajax({'type':'post','url':theURL,'cache':false,'dataType':'json','data':params,'success':me.showAnswer});return false;}}}
me.showAsking=function(){var midX=100;var midY=100;var theDiv=$('<div style="top: '+midY+'px; left: '+midX+'px;" class="showAsking" id="askingDiv"><img src="/libraries/graphics/ajax_load/snake_circle.gif" alt="loading graphic"/> Asking...</div>');$('#'+this.answerID).empty();$('#'+this.answerID).append(theDiv);$('#'+this.answerContainer).show();}
me.showAnswer=function(data){if(typeof(me.sessionID)=='undefined'||me.sessionID==''){me.sessionID=data.sessID;}
var tmpD=$('<div></div>');for(var foo=0;foo<data.responses.length;foo++){var tmpJSON=data.responses[foo];var title=((tmpJSON.title!='')?decodeURIComponent(tmpJSON.title):"We're sorry.");var tH3=$('<div><h3>'+title+'</h3><a href="javascript://" onclick="$(\'#'+me.answerContainer+'\').hide();" class="floater">Close</a></div>');tmpD.append(tH3);var tD2=$('<div>'+decodeURIComponent(tmpJSON.body)+"</div>");tmpD.append(tD2);if(typeof(tmpJSON.related)!='undefined'){tD2=$("<div></div>");var tSelect=$('<select size="1" onchange="if (this.options[this.selectedIndex].value > 0){ $(\'#'+me.questionID+'\').val(this.options[this.selectedIndex].text); $(\'#intelli\').submit();}"></select>');$(tSelect).append($('<option value="">Try these related questions</option>'));for(var bar=0;bar<tmpJSON.related.length;bar++){$(tSelect).append($('<option value="'+decodeURIComponent(tmpJSON.related[bar].id)+'">'+decodeURIComponent(tmpJSON.related[bar].title)+'</option>'));}
tD2.append(tSelect);tmpD.append(tD2);}
if(tmpJSON.title!=''){tD2=$('<div id="ratings"></div>');tD2.append($('<b>Please rate this answer.</b><br />'));tD2.append($('<a href="javascript://" onclick="rate('+tmpJSON.id+',\''+tmpJSON.inqID+'\',0);">Poor</a>'));tD2.append(document.createTextNode(' | '));tD2.append($('<a href="javascript://" onclick="rate('+tmpJSON.id+',\''+tmpJSON.inqID+'\',25);">Mediocre</a>'));tD2.append(document.createTextNode(' | '));tD2.append($('<a href="javascript://" onclick="rate('+tmpJSON.id+',\''+tmpJSON.inqID+'\',50);">Satisfactory</a>'));tD2.append(document.createTextNode(' | '));tD2.append($('<a href="javascript://" onclick="rate('+tmpJSON.id+',\''+tmpJSON.inqID+'\',75);">Good</a>'));tD2.append(document.createTextNode(' | '));tD2.append($('<a href="javascript://" onclick="rate('+tmpJSON.id+',\''+tmpJSON.inqID+'\',100);">Excellent</a>'));tmpD.append(tD2);}}
$('#'+me.answerID).empty();$('#'+me.answerID).append(tmpD);}
me.hideAsking=function(){$('#askingDiv').parentNode.removeChild($('askingDiv'));}
me.replaceGeneric=function(){if($(this).val()==me.sampleQuestion){$(this).val('');$(this).removeClass('new');$(this).addClass('active');}}
$('#'+qID).attr('class','new');$('#'+qID).val(sampleQuestion);$('#'+qID).click(me.replaceGeneric);return me;}
function rate(qID,inqID,rVal){var theURL='/libraries/app/faq_client.php';var params={'action':'rate','respID':qID,'rVal':rVal,'inqID':encodeURIComponent(inqID)};$.ajax({'type':'post','url':theURL,'cache':false,'dataType':'json','data':params,'success':function(data){$('#ratings').empty();$('#ratings').append($('<b>Thank you for the rating.</b>'))}});}
