/*
* @filename get_suggestion.js
* @programmer Sothea Nim (snim@alcor.concordia.ca)
* @date June 2009
* @description This file is used for member called from inside of portico
*/
var thisHost=window.location.host;
var thisHostArr=thisHost.split('.');
var thisDomainAlias=thisHostArr[0];
thisDomainAlias=thisDomainAlias.match('concordia')?'www':thisDomainAlias;
var querySelector='form#conuni_search input#query';
var ConUni={
subdomain: function(){a=window.location.hostname.split('.');return a[0];},
redirect: function(url){window.location=url;},
_formatResult: function(row) {return row[0].replace(/(<.+?>)/gi, '');},
_formatItem: function(row){
if( row.length===3) return row[0] + '
'+row[1]+'
' + row[2] + "";
else if( row.length===2) return row[0] + '
' + row[1] + "";
else return row[0];
},
_autosuggestURL: function()
{
switch(readCookie($.cName))
{
case 'entire': return "/globalmk/plugins/search.suggest/concordiasitelist.php";
case 'directory': return "/globalmk/plugins/search.suggest/get_person.php";
case 'thissite':
if( window.location.hostname==='www.concordia.ca' || window.location.hostname==='www-devel.concordia.ca' || window.location.hostname==='concordia.ca' )
return "/globalmk/plugins/search.suggest/concordiasitelist4jQueryAutoSuggest.php";
return siteroot+"custom/localsitelist.php?q="+ConUni._searchQuery()+'&siteroot='+siteroot+'&utm_source='+ConUni.subdomain();
case 'newsandevents': return "/globalmk/plugins/search.suggest/empty.php";
default:
if( window.location.hostname==='www.concordia.ca' || window.location.hostname==='www-devel.concordia.ca' || window.location.hostname==='concordia.ca' )
return "/globalmk/plugins/search.suggest/concordiasitelist4jQueryAutoSuggest.php";
return siteroot+"custom/localsitelist.php?q="+ConUni._searchQuery()+'&siteroot='+siteroot+'&utm_source='+ConUni.subdomain();
}
},
_searchQuery:function(){ return jQuery(querySelector).val(); },
_autosuggest:function(){
jQuery( '.ac_results' ).remove();
jQuery( querySelector ).autocomplete( ConUni._autosuggestURL()+'?'+ConUni._searchQuery()+'&lang=en', {
minChars:2,
autoFill: false,
mustMatch: false,
matchContains: false,
scrollHeight: 220,
formatItem: ConUni._formatItem,
formatResult: ConUni._formatResult
});
}
};
function getResult(str_in, des_id)
{
var php_servant = '';
var q_str = '';
if( !(str_in === "Saisir la recherche" || str_in === "Enter your query here" ) && str_in.length > 0 && !(str_in == ' ' || str_in == '\t') )
{
if( search_for === 'li_staff' )
{
q_str = "q=" + str_in;
php_servant = "/globalmk/plugins/search.suggest/get_person.php";
}
else if( search_for === 'li_entire' )
{
q_str = "q="+str_in+'&utm_source='+thisDomainAlias;
php_servant = "/globalmk/plugins/search.suggest/concordiasitelist.php";
}
else if( search_for === 'li_thissite' )
{
q_str = "sitename="+str_in;
php_servant = ((typeof relative_path!=='undefined') ? relative_path : '/') + "custom/localsitelist.php";
}
if( php_servant.length > 0 )
{
$.ajax({
url: php_servant,
data: q_str,
dataType: "text",
cache: true,
type: "POST",
error: function(request, error) {
$("#"+des_id).empty();
$("#"+des_id).html("Sorry, but our system is temporarily down.
You can simply press ENTER to get your result.");
$('#search #suggest_hint').append('