function QS_locateDynamicPosition (obj) { //--- Find the current position of an object on the page var curL = 0; var curT = 0; if (obj.offsetParent) { curL = obj.offsetLeft curT = obj.offsetTop while (obj = obj.offsetParent) { curL += obj.offsetLeft curT += obj.offsetTop } } return [curL, curT]; // return as array } function QS_XHTTPRequest_Tags (url, handler) { //--- Send an HTTP request if (window.XMLHttpRequest) { tagReq = new XMLHttpRequest (); tagReq.onreadystatechange = handler; tagReq.open ("GET", url, true); tagReq.send (null); } else if (window.ActiveXObject) { tagReq = new ActiveXObject ("Microsoft.XMLHTTP"); if (tagReq) { tagReq.onreadystatechange = handler; tagReq.open ("GET", url, true); tagReq.send (); } } } function QS_connectWord (whichWord) { //--- Connects the selected word to the partial word whichField = document.getElementById ('QS_CourseName'); whichField.focus (); //--- Get the caret position if (document.selection) { range = document.selection.createRange (); range.moveStart ('character', -whichField.value.length); CaretPos = range.text.length; } else if ((whichField.selectionStart) || (whichField.selectionStart == '0')) { CaretPos = whichField.selectionStart; } lastComma = whichField.value.substr (0, CaretPos).lastIndexOf (','); if (lastComma == -1) { lastComma = 0; } inclSpaces = ''; findSpaces = lastComma; while ((findSpaces <= whichField.value.length) && ((whichField.value.substr (findSpaces, 1) == ',') || (whichField.value.substr (findSpaces, 1) == ' '))) { inclSpaces += whichField.value.substr (findSpaces, 1); findSpaces++; } whichField.value = whichField.value.substr (0, lastComma) + inclSpaces + whichWord + whichField.value.substr (CaretPos, whichField.value.length - CaretPos); //--- Reset caret if (whichField.setSelectionRange) { whichField.focus (); whichField.setSelectionRange (CaretPos + whichWord.length - (CaretPos - lastComma) + inclSpaces.length, CaretPos + whichWord.length - (CaretPos - lastComma) + inclSpaces.length); } else if (whichField.createTextRange) { range = whichField.createTextRange (); range.collapse (true); range.moveEnd ('character', CaretPos + whichWord.length - (CaretPos - lastComma) + inclSpaces.length); range.moveStart ('character', CaretPos + whichWord.length - (CaretPos - lastComma) + inclSpaces.length); range.select (); } document.getElementById ('QS_NameSuggestions').style.visibility = 'hidden'; } function QS_showPopup () { //--- Loads the most recent tags returned from the server if (tagReq.readyState == 4) { switch (tagReq.status) { case 200: //--- Display response text var tagLinks = ""; var hasError = tagReq.responseXML.getElementsByTagName ("error"); if (hasError.length) { document.getElementById ('QS_NameSuggestions').innerHTML = "Could not download tag list."; break; } else { var tagList = tagReq.responseXML.getElementsByTagName ("products")[0].getElementsByTagName ("product"); } if (tagList.length) { tagLinks = "
We suggest the following courses:
"; tagLinks += ""; for (i = 0; i < tagList.length; i++) { productcode = tagList[i].getElementsByTagName ("productcode")[0].firstChild.nodeValue.toString (); productname = tagList[i].getElementsByTagName ("productname")[0].firstChild.nodeValue.toString (); seoname = tagList[i].getElementsByTagName ("seoname")[0].firstChild.nodeValue.toString (); tagLinks += ""; } tagLinks += "
" + (i + 1) + ". " + productname + "
"; if (tagList.length >= 10) { tagLinks += ""; tagLinks += ""; tagLinks += "
See all results...
"; } } else { document.getElementById ('QS_NameSuggestions').style.visibility = 'hidden'; } if (tagLinks != "") { textAreaObjPos = QS_locateDynamicPosition (document.getElementById ('QS_CourseName')); document.getElementById ('QS_NameSuggestions').innerHTML = tagLinks; document.getElementById ('QS_NameSuggestions').style.width = (document.getElementById ('QS_CourseName').offsetWidth + 70) + 'px'; document.getElementById ('QS_NameSuggestions').style.top = (textAreaObjPos[1] + document.getElementById ('QS_CourseName').offsetHeight - 3) + 'px'; document.getElementById ('QS_NameSuggestions').style.left = (textAreaObjPos[0] - 40) + 'px'; document.getElementById ('QS_NameSuggestions').style.visibility = 'visible'; } break; default: document.getElementById ('QS_NameSuggestions').innerHTML = "Could not download tag list."; break; break; } } } function QS_hidePopup () { //--- Hides the tags popup document.getElementById ('QS_NameSuggestions').style.visibility = 'hidden'; } function QS_lookupWord (event, whichField) { //--- Function to lookup words var keyPressed = (event.keyCode ? event.keyCode : event.which); if (keyPressed == 27) { document.getElementById ('QS_NameSuggestions').style.visibility = 'hidden'; whichField.blur (); return false; //--- encodeURIComponent } //--- Ignore commas and semi-colons if ((keyPressed == 186) || (keyPressed == 188)) { return false; } if (document.selection) { range = document.selection.createRange (); range.moveStart ('character', -whichField.value.length); CaretPos = range.text.length; } else if ((whichField.selectionStart) || (whichField.selectionStart == '0')) { CaretPos = whichField.selectionStart; } lastComma = whichField.value.substr (0, CaretPos).lastIndexOf (','); if (lastComma == -1) { lastComma = 0; } newWord = whichField.value.substr ((lastComma ? lastComma + 1 : 0), CaretPos - (lastComma ? lastComma + 1 : 0)).replace (/^\s+/, ''); if ((newWord != '') && (newWord.length > 2) && (newWord != lastWord)) { QS_XHTTPRequest_Tags ("pagebuilder/components/intec/component-course-search-xml.php?ProductName=" + encodeURIComponent (newWord) + "", QS_showPopup); lastWord = newWord; } else { QS_hidePopup (); return false; } } var lastWord = '';