	/*	* PHP Ajax AutoSuggest Jquery Plugin	* http://www.amitpatil.me/	*	* @version	* 1.0 (Dec 20 2010)	* 	* @copyright	* Copyright (C) 2010-2011 	*	* @Auther	* Amit Patil (amitpatil321@gmail.com)	* Maharashtra (India) m	*	* @license	* This file is part of PHP Ajax AutoSuggest Jquery Plugin.	* 	* PHP Ajax AutoSuggest Jquery Plugin is freeware script. you can redistribute it and/or modify	* it under the terms of the GNU Lesser General Public License as published by	* the Free Software Foundation, either version 3 of the License, or	* (at your option) any later version.	* 	* PHP Ajax AutoSuggest Jquery Plugin is distributed in the hope that it will be useful,	* but WITHOUT ANY WARRANTY; without even the implied warranty of	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	* GNU General Public License for more details.	* 	* You should have received a copy of the GNU General Public License	* along with this script.  If not, see <http://www.gnu.org/copyleft/lesser.html>.	*/ (function($){    $.fn.extend({        autoSuggest : function(options){            var defaults = {                ajaxFilePath : "",                ajaxParams   : "",                autoFill     : false,				iwidth		 : "auto",				opacity		 : "0.9",				ilimit		 : "10",				idHolder	 : "",				match		 : "starts"                                            };            options = $.extend(defaults, options);								var ajaxFilePath = options.ajaxFilePath;			var ajaxParams	 = options.ajaxParams;			var autoFill     = options.autoFill;			var width		 = options.iwidth;			var opacity		 = options.opacity;			var limit		 = options.ilimit;			var idHolder	 = options.idHolder;            		var match		 = options.match;             var pagetype		 = options.pagetype;                        			return this.each(function() {				var obj = $(this);							obj.keyup(function(event){					var p = obj;					var offset = p.offset();					var keyword = obj.val();					if(keyword.length)					 {						 if(event.keyCode != 40 && event.keyCode != 38 && event.keyCode != 13)						 {                                                   							 if(ajaxFilePath != "")							 {								 $.ajax({								   type: "POST",								   url: ajaxFilePath,								   data: "data="+keyword+"&limit="+limit+"&match="+match+"&"+ajaxParams+"&getId=1",								   success: function(responce){										if(responce != 0)									{									  var vals = responce.split("|"); 									  if(vals.length)									  {										  optionList = "<ul class=\"list\">";										  for(i=0;i<vals.length;i++)										  {											 valuenid = vals[i].split("-");											 myText = valuenid[1]; 											 myId = valuenid[0]; 											 // trim string to remove extra white spaces around the text											 myText = myText.replace(/^\s+|\s+$/g,"");											 if(match == "starts")												 // check if string starts with given characters												 myText = myText.replace( myText.match("^"+keyword), '<span class="highlighted">'+keyword+'</span>');											 else if(match == "ends")												 //alert(myText.replace(/(.*)keyword/, "<b>hi</b>"));												 myText = myText.replace (new RegExp( keyword + '$'), '<span class="highlighted">'+keyword+'</span>');											 else if(match == "contains")												 myText = myText.replace( new RegExp(keyword, "i" ), '<span class="highlighted">'+keyword+'</span>');											 if(idHolder != "" && idHolder != null)												optionList += "<li><a href=\"javascript:void(0);\" id=\""+myId+"\">"+myText+"</a></li>";											 else 														optionList += "<li><a href=\"javascript:void(0);\">"+myText+"</a></li>";										  }										  optionList += "</ul>";									  }                                                                          $(".ajax_response").remove();									  if($(".ajax_response").html() == null)									  {										  var id = obj.attr("id");										  // initialization                                                                                    var topv = "";                                                                                                                                                                    if(pagetype=='lefttour'){                                                                                    topv =  parseInt(offset.top - 235)                                                                                    leftv = 16                                                                                  } else if(pagetype=='lefthotel'){                                                                                       topv =  parseInt(offset.top - 235)                                                                                    leftv = 16                                                                                  }else if(pagetype=='righthotel'){                                                                                     topv =  23                                                                                    leftv = 0                                                                                  }else if(pagetype=='topnewhotel'){                                                                                        topv =  28                                                                                        leftv = 0                                                                                  }else if(pagetype=='activity'){																						topv =  23                                                                                    	leftv = 0                                                                                  }else if(pagetype=='festival'){																						topv =  23                                                                                    	leftv = 0                                                                                  }else if(pagetype=='health'){																						topv =  30                                                                                    	leftv = 0                                                                                  }else{                                                                                   topv =  parseInt(offset.top + obj.height() + 3)                                                                                   leftv = parseInt($("#"+id).offset().left)                                                                                  }										  $("<div class='ajax_response'></div>").insertAfter(obj)										  .css("left",leftv)                                                                                  										  .css("top",topv)										  .css("opacity",opacity)										  .html(optionList).css("display","block");										  // set responce div width                                                                                  if(pagetype=='righthotel'){                                                                                       $(".ajax_response").css("width",280);                                                                                       $(".ajax_response").css("z-index",1000);                                                                                  }if(pagetype=='festival'){                                                                                       $(".ajax_response").css("width",286);                                                                                       $(".ajax_response").css("z-index",1000);                                                                                  }else if(pagetype=='health'){																					  $(".ajax_response").css("width",172);                                                                                       $(".ajax_response").css("z-index",1000);                                                                                  }else if(pagetype=='activity'){																					  $(".ajax_response").css("width",280);                                                                                       $(".ajax_response").css("z-index",1000);                                                                                  }else if(pagetype=='topnewhotel'){																					  $(".ajax_response").css("width",220);                                                                                       $(".ajax_response").css("z-index",1000);                                                                                  }else{										  if(width == "auto")											  $(".ajax_response").css("width",parseInt(obj.width()) + 4);										  else												  $(".ajax_response").css("width",parseInt(width));                                                                                  }									  }									  else										  $(".ajax_response").html(optionList).css("display","block");									}									else									  $(".list").css("display","none");								   }								 });							 }							 else								 alert("Ajax file path not provided");						 }						 else						 {							$(".list li .selected").removeClass("selected");							switch (event.keyCode)							{							 case 40:							 {								  found = 0;								  $(".list li").each(function(){									 if($(this).attr("class") == "selected")										found = 1;								  });								  if(found == 1)								  {									var sel = $(".list li[class='selected']");									// check if his is a last element in the list									// if so then add selected class to the first element in the list									if(sel.next().text() == "")															$(".list li:first").addClass("selected");									else										sel.next().addClass("selected");									// remove class selected from previous item									sel.removeClass("selected");								  }								  else									$(".list li:first").addClass("selected");							  }							 break;							 case 38:							 {								  found = 0;								  $(".list li").each(function(){									 if($(this).attr("class") == "selected")										found = 1;								  });								  if(found == 1)								  {									var sel = $(".list li[class='selected']");									// check if his is a last element in the list									// if so then add selected class to the first element in the list									if(sel.prev().text() == "")															$(".list li:last").addClass("selected");									else										sel.prev().addClass("selected");									// remove class selected from previous item									sel.removeClass("selected");								  }								  else									$(".list li:last").addClass("selected");							 }							 break;							 case 13:								str = $(".list li[class='selected']").text();								obj.val(str);								// store id of the selected option                                                               								if(idHolder != "" && idHolder != null)									$("#"+idHolder).val($(".list li[class='selected'] a").attr("id"));								$(".list").fadeOut("fast");							 break;							}							// if autoFill option is true then fill selected value in textbox							if(autoFill)							{								str = $(".list li[class='selected']").text();								obj.val(str);							}						 }					 }					else						// if there is no character in the text field then remove the suggestion box 						$(".list").fadeOut("fast");				});			    // prevent form submission on enter key press				obj.keypress(function(event){				 if(event.keyCode == "13"){                                      if(pagetype=='lefttour'){                                             str = $(".list li[class='selected']").text();											newobj = $("#currentClickFields").val();											$("#"+newobj).val(str);											idHolder = $("#currentClickvalueFields").val();                                            $("#"+idHolder).val($("li[class='selected'] a").attr("id"));                                            id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                                                                        id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                            sr = (str.replace(/ /g,"-").toLowerCase())+"-"+id                                         //   sr =  (stringreplace(sr));                                                                                        location.href = SiteUrl+"tours/"+sr;                                      } if(pagetype=='lefthotel'){                                            str = $(".list li[class='selected']").text();											newobj = $("#currentClickFields").val();											$("#"+newobj).val(str);											idHolder = $("#currentClickvalueFields").val();                                            $("#"+idHolder).val($("li[class='selected'] a").attr("id"));                                            id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                                                                        id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                            sr = (str.replace(/ /g,"-").toLowerCase())+"-"+id                                            //sr =  (stringreplace(sr));                                                                                        location.href = SiteUrl+"hotels/"+sr;                                      }					 return false;                                 }			    });					$(".list li").live("mouseover",function () {					$(".list li[class='selected']").removeClass("selected");					$(this).addClass("selected");					// if autoFill option is true then fill selected value in textbox					if(autoFill)					{						str = $(".list li[class='selected']").text();						obj.val(str);					}				});				$(".list li").live("click",function () {					str = $(".list li[class='selected']").text();                                         newobj = $("#currentClickFields").val();                                        // alert(newobj)                                        $("#"+newobj).val(str);					//obj.val(str);					// store id of the selected option					if(idHolder != "" && idHolder != null){						//$("#"+idHolder).val($("li[class='selected'] a").attr("id"));                                                idHolder = $("#currentClickvalueFields").val();                                                $("#"+idHolder).val($("li[class='selected'] a").attr("id"))                                        }                                           currentClick = jQuery('#currentClickInput').val();                                           if(currentClick=='lefttour'){                                                                                            id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                                                                           sr = (str.replace(/ /g,"-").toLowerCase())+"-"+id                                           //  sr =  (stringreplace(sr));                                              location.href = SiteUrl+"tours/"+sr;                                         }                                                                                 if(currentClick=='lefthotel'){                                            str = $(".list li[class='selected']").text();                                                                                         $("#"+idHolder).val($("li[class='selected'] a").attr("id"));                                            id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                                                                        id = alltrim(rtrim(ltrim($("#"+idHolder).val())))                                                                                        sr = (str.replace(/ /g,"-").toLowerCase())+"-"+id                                                                                       // sr =  (stringreplace(sr));                                                                                                                                      location.href = SiteUrl+"hotels/"+sr;                                      }					$(".list").fadeOut("fast");                                        $(".ajax_response").fadeOut("fast");				});				$(document).click(function(){					if($(".list").css("display") == "block")						$(".list").fadeOut("fast");                                             $(".ajax_response").fadeOut("fast");				});				$(document).keyup(function(event){					if(event.keyCode == 9)					{						str = $(".list li[class='selected']").text();						newobj = $("#currentClickFields").val();						 $("#"+newobj).val(str);						//obj.val(str);						// store id of the selected option						if(idHolder != "" && idHolder != null)						idHolder = $("#currentClickvalueFields").val();							$("#"+idHolder).val($(".list li[class='selected'] a").attr("id"));						$(".list").fadeOut("fast");					}				});			});	    }    });	}) (jQuery); function ltrim(str){                return str.replace(/^\s+/, '');            }            function rtrim(str) {                return str.replace(/\s+$/, '');            }            function alltrim(str) {                return str.replace(/^\s+|\s+$/g, '');            }
