/** Copyright Eberhardt TRAVEL GmbH 2007-09 **/

var teaserbilder = new Array();
var zaehler = 0;
var blender = 0;
function lade_reisebilder()
{
  if(blender != 0){jQuery("#headerimage").fadeIn("slow");}
  else {blender = 1;}
  jQuery('#headerimage').attr('src', teaserbilder[zaehler]);
  zaehler++;
  if(zaehler == teaserbilder.length) {zaehler = 0;}
  setTimeout('jQuery("#headerimage").fadeOut("slow");',11200);
  setTimeout('lade_reisebilder()', 12000);
}

function del_suchbegriff(obj)
{if(obj.value == "Suchbegriff")
{obj.value='';}}
var schalter = 1;

function Fensterhoehe () {
if (window.innerHeight) {return window.innerHeight;} else if (document.body && document.body.offsetHeight)
{return document.body.offsetHeight;} else {return 0;}}

function Fensterbreite () {
if (window.innerWidth) {return window.innerWidth;} else if (document.body && document.body.offsetHeight) {
return document.body.offsetWidth;} else {return 0;}}
var teaser = new Array();
var teaser_eingeklappt = 0;
function bilder_ausblenden(neueseite, reisecode)
{
if (teaser_eingeklappt == 0)
{
jQuery('#teaser').addClass('teaser');
teaser_eingeklappt = 1;
jQuery('#aus').css('display', 'block');
jQuery('#ein').css('display', 'none');
jQuery('#teaser_reiseargument').css('height', '10px');
jQuery('#teaser_reiseargument').unbind();

if (neueseite != 1)
{ajaxAusblenden(reisecode);}
}
else
{
jQuery('#teaser').removeClass('teaser');
jQuery('#aus').css('display', 'none');
jQuery('#ein').css('display', 'block');
jQuery('#teaser_reiseargument').css('height', '109px');
func_teaser_reiseargument();
teaser_eingeklappt = 0;
if (neueseite != 1)
{ajaxAusblenden(reisecode);}
}InnenHoehe();return false;}
function ajaxAusblenden(reisecode)
{
jQuery.ajax({type: "POST",url: "reiseansicht.php",dataType: "html",
data: {module : 'reiseansicht', action: 'bilderausblenden', ausblenden: teaser_eingeklappt, reisecode: reisecode},
success: function(){}});}

function pixelentfernen(element, obj)
{
if (jQuery(obj).css(element) == 'auto')
{return 0;}
ret = jQuery(obj).css(element).substr(0, (jQuery(obj).css(element).length-2));
ret = (1*ret);
return ret;
}
var gsr_padding = 0;
function InnenHoehe()
{
fenster = Fensterhoehe();
var hoehe = 0;
jQuery( ".layout_hoehe" ).each(
function(index){
if (jQuery(this).css('display') == 'none')
{return 0;}
hoehe = hoehe + jQuery(this).height() + pixelentfernen('margin-top', this) +  pixelentfernen('margin-bottom', this) + pixelentfernen('padding-top', this) + pixelentfernen('padding-bottom', this);
});
element = '';

if(jQuery('div.kopfbild').length > 0)
{element = 'div.kopfbild';}
else if(jQuery('#reiseblock').length > 0)
{
element = '#reiseblock';
hoehe = hoehe + pixelentfernen('padding-top', '#reiseblock')+pixelentfernen('padding-bottom', '#reiseblock');
jQuery('#reiseblock').css('width', '100%');
}
else if(jQuery('div.suchergebnis').length > 0)
{element = 'div.suchergebnis';}
else if(jQuery('div.spezialsuche').length > 0)
{ element = "div.spezialsuche";
jQuery('div.spezialsuche').css('width', '100%');}
else if(jQuery('#ortsinformationen').length > 0)
{ element = "#ortsinformationen";
jQuery('#ortsinformationen').css('width', '100%');}
else if(jQuery('div.formularbereich').length > 0)
{ element = "div.formularbereich";
 jQuery('div.formularbereich').css('width', '98%');}
else if(jQuery('#kasten_mitte').length > 0)
{element = "#kasten_mitte";}
else if(jQuery('#mod').length > 0)
{element = "#mod";}
else if(jQuery('#vn_kasten_mitte').length > 0)
{element = '#vn_kasten_mitte';
jQuery('#vn_kasten_mitte form').css('width', '97%');}
hoehe = (fenster - hoehe - gsr_padding - 4)+'px';
if (element != '')
{jQuery(element).height(hoehe);}
if(jQuery('#transhotel').length>0){
jQuery('#transhotel').attr("height",(jQuery('#kasten_mitte').height()-5));
jQuery('#transhotel').attr("width",(jQuery('#kasten_mitte').width()));
}}

function galerie(reisecode, art, key)
{jQuery.ajax({
type: "POST",
url: "reiseansicht.php",
data: {action: 'bildergalerie', reisecode: reisecode, art: art, bild_id: key},
success: function(strResponse){
jQuery('#bild_extra').show().css('width', '500px', 'height', '548px', 'top', '35px');
document.getElementById("bild_extra").innerHTML = unescape(strResponse);
}});}


//Alpenbus Navi
jQuery(document).ready(function () {
jQuery('#navi_left a.top_link').click(function () {
if (jQuery.browser.msie == true && parseInt(jQuery.browser.version) < 8)
{jQuery(this).parent().children('ul').toggle();}
else
{jQuery(this).parent().children('ul').slideToggle();}
jQuery(this).toggleClass('top_link_unten');
return false;
});
jQuery('#ind').ajaxStart(function () {jQuery(this).show();});
jQuery('#ind').ajaxStop(function () {jQuery(this).hide();});

if(jQuery(window).width() < 950)
{
var v_css  = document.createElement('link');
v_css.rel = 'stylesheet'
v_css.type = 'text/css';
v_css.href = '/css/achthundert.css';
document.getElementsByTagName('head')[0].appendChild(v_css);
}});

function datecheck(datum, name)
{
dat_arr = new Array;
dat_arr = datum.split("");
tag     = dat_arr[0]+dat_arr[1];
monat   = dat_arr[2]+dat_arr[3];
var jetzt = new Date();
if(dat_arr.length != 10)
{if(dat_arr.length == 8)
{jahr    = dat_arr[4]+dat_arr[5]+dat_arr[6]+dat_arr[7];}
else if(dat_arr.length == 6)
{jahr    = "20"+dat_arr[4]+dat_arr[5];}
else if(dat_arr.length == 4)
{var jahr = jetzt.getFullYear();}
document.getElementById(name).value = tag+"."+monat+"."+jahr;
}}

function countdownwechsel(zahl, verschub)
{
if (zahl == 0) 
{ zahl = 1;
jQuery('#countdown_id').css('background-position', 0); }  
else
{ zahl = 0;
jQuery('#countdown_id').css('background-position', '-'+verschub+'px'); }
setTimeout('countdownwechsel('+zahl+','+verschub+')',8111);
}

function suchleiste() {
jQuery('#such_leiste .nav li li a').click(function() {
jQuery.ajax({type: "POST",url: this.href,data: "",dataType: "html",
beforeSend: function() {jQuery('#ind').css('display', 'block');},
success: function(htmlResponse){
document.getElementById('inhalt').innerHTML = htmlResponse;
start_function();
jQuery('#ind').css('display', 'none');
jQuery("ul.head").css("margin-bottom", "0px");
jQuery("#suche").show();
suchleiste();
InnenHoehe();
}});return false;});}

// Anker-Scroll
anchor = {
init: function(id,wert){
jQuery("a.anchorLink").click(function () {
elementClick = jQuery(this).attr("href");
destination = jQuery(elementClick).offset().top - wert;
if(wert == 999) {destination = jQuery(elementClick).offset().top - jQuery('#oben').offset().top;}
jQuery("#"+id).animate({scrollTop: destination}, 1500 );
return false;
})}}

jQuery.noConflict( );

// Make an element draggable using jQuery
var makeDraggable = function(element) {element = jQuery(element);var move = function(event) {if(element.data('mouseMove')) {
var changeX = event.clientX - element.data('mouseX');
var changeY = event.clientY - element.data('mouseY');
dr_top_element    = element.parent().css('top');
dr_height_element = element.parent().css('height');
dr_top            = dr_top_element.substr(0,(dr_top_element.length-2))*1;
dr_height         = dr_height_element.substr(0,(dr_height_element.length-2))*1;
window_height     = jQuery(window).height();
dr_left_element   = element.parent().css('left');
dr_width_element  = element.parent().css('width');
dr_left           = dr_left_element.substr(0,(dr_left_element.length-2))*1;
dr_width          = dr_width_element.substr(0,(dr_width_element.length-2))*1;
window_width      = jQuery(window).width();
if (((dr_top+changeY) > 2 || changeY > 0)
   && (window_height > (dr_height+dr_top) || changeY < 0))
{var newY = parseInt(element.parent().css('top')) + changeY;}
if (((dr_left+changeY) > 2 || changeX > 0)
   && (window_width > (dr_left+dr_width) || changeX < 0))
{var newX = parseInt(element.parent().css('left')) + changeX;}
element.parent().css('left', newX);element.parent().css('top', newY);element.data('mouseX', event.clientX);element.data('mouseY', event.clientY);
}}
element.mousedown(function(event) {
element.data('mouseMove', true);
element.data('mouseX', event.clientX);
element.data('mouseY', event.clientY);
});element.parents(':last').mouseup(function() {element.data('mouseMove', false);});element.mouseout(move);element.mousemove(move);}

/*Superfish v1.4.8 - jQuery menu widget
Copyright (c) 2008 Joel Birch
Dual licensed under the MIT and GPL licenses:
http://www.opensource.org/licenses/mit-license.php
http://www.gnu.org/licenses/gpl.html
CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
*/
;(function(jQuery){
jQuery.fn.superfish = function(op){
var sf = jQuery.fn.superfish,
c = sf.c,
$arrow = jQuery(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
over = function(){
var $$ = jQuery(this), menu = getMenu($$);
clearTimeout(menu.sfTimer);
$$.showSuperfishUl().siblings().hideSuperfishUl();},
out = function(){
var $$ = jQuery(this), menu = getMenu($$), o = sf.op;
clearTimeout(menu.sfTimer);
menu.sfTimer=setTimeout(function(){
o.retainPath=(jQuery.inArray($$[0],o.$path)>-1);
$$.hideSuperfishUl();
if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}},o.delay);},
getMenu = function($menu){
var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
sf.op = sf.o[menu.serial];
return menu;},
addArrow = function($a){$a.addClass(c.anchorClass).append($arrow.clone());};
return this.each(function() {
var s = this.serial = sf.o.length;
var o = jQuery.extend({},sf.defaults,op);
o.$path = jQuery('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
jQuery(this).addClass([o.hoverClass,c.bcClass].join(' '))
.filter('li:has(ul)').removeClass(o.pathClass);});
sf.o[s] = sf.op = o;
jQuery('li:has(ul)',this)[(jQuery.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
if (o.autoArrows) addArrow( jQuery('>a:first-child',this) );})
.not('.'+c.bcClass)
.hideSuperfishUl();
var $a = jQuery('a',this);
$a.each(function(i){
var $li = $a.eq(i).parents('li');
$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});});
o.onInit.call(this);}).each(function() {
var menuClasses = [c.menuClass];
if (sf.op.dropShadows  && !(jQuery.browser.msie && jQuery.browser.version < 7)) menuClasses.push(c.shadowClass);
jQuery(this).addClass(menuClasses.join(' '));});};

var sf = jQuery.fn.superfish;
sf.o = [];
sf.op = {};
sf.IE7fix = function(){
var o = sf.op;
if (jQuery.browser.msie && jQuery.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
this.toggleClass(sf.c.shadowClass+'-off');};
sf.c = {
bcClass     : 'sf-breadcrumb',menuClass   : 'sf-js-enabled',anchorClass : 'sf-with-ul',arrowClass  : 'sf-sub-indicator',
shadowClass : 'sf-shadow'};sf.defaults = {hoverClass: 'sfHover',pathClass: 'overideThisToUse',pathLevels: 1,delay: 300,
animation: {opacity:'show'},speed: 'normal',autoArrows: false,dropShadows : true,disableHI: false,onInit: function(){},
onBeforeShow: function(){},onShow: function(){},onHide: function(){}};jQuery.fn.extend({
hideSuperfishUl : function(){var o = sf.op,not = (o.retainPath===true) ? o.$path : '';
o.retainPath = false;var $ul = jQuery(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
.find('>ul').hide().css('visibility','hidden');o.onHide.call($ul);return this;},
showSuperfishUl : function(){var o = sf.op,sh = sf.c.shadowClass+'-off',$ul = this.addClass(o.hoverClass)
.find('>ul:hidden').css('visibility','visible');sf.IE7fix.call($ul);o.onBeforeShow.call($ul);
$ul.animate(o.animation,o.speed,function(){sf.IE7fix.call($ul);o.onShow.call($ul);});
return this;}});})(jQuery);

/*
 * jQuery Tooltip plugin 1.3
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */;(function($){var helper={},current,title,tID,IE=$.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),track=false;$.tooltip={blocked:false,defaults:{delay:200,fade:false,showURL:true,extraClass:"",top:15,left:15,id:"tooltip"},block:function(){$.tooltip.blocked=!$.tooltip.blocked;}};$.fn.extend({tooltip:function(settings){settings=$.extend({},$.tooltip.defaults,settings);createHelper(settings);return this.each(function(){$.data(this,"tooltip",settings);this.tOpacity=helper.parent.css("opacity");this.tooltipText=this.title;$(this).removeAttr("title");this.alt="";}).mouseover(save).mouseout(hide).click(hide);},fixPNG:IE?function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative');});}});}:function(){return this;},unfixPNG:IE?function(){return this.each(function(){$(this).css({'filter':'',backgroundImage:''});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){$(this)[$(this).html()?"show":"hide"]();});},url:function(){return this.attr('href')||this.attr('src');}});function createHelper(settings){if(helper.parent)return;helper.parent=$('<div id="'+settings.id+'"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();if($.fn.bgiframe)helper.parent.bgiframe();helper.title=$('h3',helper.parent);helper.body=$('div.body',helper.parent);helper.url=$('div.url',helper.parent);}function settings(element){return $.data(element,"tooltip");}function handle(event){if(settings(this).delay)tID=setTimeout(show,settings(this).delay);else
show();track=!!settings(this).track;$(document.body).bind('mousemove',update);update(event);}function save(){if($.tooltip.blocked||this==current||(!this.tooltipText&&!settings(this).bodyHandler))return;current=this;title=this.tooltipText;if(settings(this).bodyHandler){helper.title.hide();var bodyContent=settings(this).bodyHandler.call(this);if(bodyContent.nodeType||bodyContent.jquery){helper.body.empty().append(bodyContent)}else{helper.body.html(bodyContent);}helper.body.show();}else if(settings(this).showBody){var parts=title.split(settings(this).showBody);helper.title.html(parts.shift()).show();helper.body.empty();for(var i=0,part;(part=parts[i]);i++){if(i>0)helper.body.append("<br/>");helper.body.append(part);}helper.body.hideWhenEmpty();}else{helper.title.html(title).show();helper.body.hide();}if(settings(this).showURL&&$(this).url())helper.url.html($(this).url().replace('http://','')).show();else
helper.url.hide();helper.parent.addClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.fixPNG();handle.apply(this,arguments);}function show(){tID=null;if((!IE||!$.fn.bgiframe)&&settings(current).fade){if(helper.parent.is(":animated"))helper.parent.stop().show().fadeTo(settings(current).fade,current.tOpacity);else
helper.parent.is(':visible')?helper.parent.fadeTo(settings(current).fade,current.tOpacity):helper.parent.fadeIn(settings(current).fade);}else{helper.parent.show();}update();}function update(event){if($.tooltip.blocked)return;if(event&&event.target.tagName=="OPTION"){return;}if(!track&&helper.parent.is(":visible")){$(document.body).unbind('mousemove',update)}if(current==null){$(document.body).unbind('mousemove',update);return;}helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");var left=helper.parent[0].offsetLeft;var top=helper.parent[0].offsetTop;if(event){left=event.pageX+settings(current).left;top=event.pageY+settings(current).top;var right='auto';if(settings(current).positionLeft){right=$(window).width()-left;left='auto';}helper.parent.css({left:left,right:right,top:top});}var v=viewport(),h=helper.parent[0];if(v.x+v.cx<h.offsetLeft+h.offsetWidth){left-=h.offsetWidth+20+settings(current).left;helper.parent.css({left:left+'px'}).addClass("viewport-right");}if(v.y+v.cy<h.offsetTop+h.offsetHeight){top-=h.offsetHeight+20+settings(current).top;helper.parent.css({top:top+'px'}).addClass("viewport-bottom");}}function viewport(){return{x:$(window).scrollLeft(),y:$(window).scrollTop(),cx:$(window).width(),cy:$(window).height()};}function hide(event){if($.tooltip.blocked)return;if(tID)clearTimeout(tID);current=null;var tsettings=settings(this);function complete(){helper.parent.removeClass(tsettings.extraClass).hide().css("opacity","");}if((!IE||!$.fn.bgiframe)&&tsettings.fade){if(helper.parent.is(':animated'))helper.parent.stop().fadeTo(tsettings.fade,0,complete);else
helper.parent.stop().fadeOut(tsettings.fade,complete);}else
complete();if(settings(this).fixPNG)helper.parent.unfixPNG();}})(jQuery);

/**
* Copyright (c) 2008 Kelvin Luck (http://www.kelvinluck.com/)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* DatePicker including Select field for month and year
**/
(function($){$.fn.extend({renderCalendar:function(s){var dc=function(a){return document.createElement(a);};s=$.extend({},$.fn.datePicker.defaults,s);if(s.showHeader!=$.dpConst.SHOW_HEADER_NONE){var yearTbl=$('<div></div>').attr({'style':'width:100%;text-align:center;clear:both;'});s.selectMonths.val(s.dpController.displayedMonth);s.selectYears.val(s.dpController.displayedYear);s.selectYears.bind('change',function(){s.dpController.setDisplayedMonth(s.dpController.displayedMonth,$(this).val(),true);return false;});s.selectMonths.bind('change',function(){s.dpController.setDisplayedMonth($(this).val(),s.dpController.displayedYear,true);return false;});yearTbl.append(s.selectMonths);yearTbl.append(s.selectYears);var headRow=$(dc('tr'));for(var i=Date.firstDayOfWeek;i<Date.firstDayOfWeek+7;i++){var weekday=i%7;var day=Date.dayNames[weekday];headRow.append(jQuery(dc('th')).attr({'scope':'col','abbr':day,'title':day,'class':(weekday==0||weekday==6?'weekend':'weekday')}).html(s.showHeader==$.dpConst.SHOW_HEADER_SHORT?day.substr(0,1):day));}};var calendarTable=$(dc('table')).attr({'cellspacing':2,'className':'jCalendar'}).append((s.showHeader!=$.dpConst.SHOW_HEADER_NONE?$(dc('thead')).append(headRow):dc('thead')));var tbody=$(dc('tbody'));var today=(new Date()).zeroTime();var month=s.month==undefined?today.getMonth():s.month;var year=s.year||today.getFullYear();var currentDate=new Date(year,month,1);var firstDayOffset=Date.firstDayOfWeek-currentDate.getDay()+1;if(firstDayOffset>1)firstDayOffset-=7;var weeksToDraw=Math.ceil(((-1*firstDayOffset+1)+currentDate.getDaysInMonth())/7);currentDate.addDays(firstDayOffset-1);var doHover=function(firstDayInBounds){return function(){if(s.hoverClass){var $this=$(this);if(!s.selectWeek){$this.addClass(s.hoverClass);}else if(firstDayInBounds&&!$this.is('.disabled')){$this.parent().addClass('activeWeekHover');}}}};var unHover=function(){if(s.hoverClass){var $this=$(this);$this.removeClass(s.hoverClass);$this.parent().removeClass('activeWeekHover');}};var w=0;while(w++<weeksToDraw){var r=jQuery(dc('tr'));var firstDayInBounds=s.dpController?currentDate>s.dpController.startDate:false;for(var i=0;i<7;i++){var thisMonth=currentDate.getMonth()==month;var d=$(dc('td')).text(currentDate.getDate()+'').attr('className',(thisMonth?'current-month ':'other-month ')+
(currentDate.isWeekend()?'weekend ':'weekday ')+
(thisMonth&&currentDate.getTime()==today.getTime()?'today ':'')).data('datePickerDate',currentDate.asString()).hover(doHover(firstDayInBounds),unHover);r.append(d);if(s.renderCallback){s.renderCallback(d,currentDate,month,year);}
currentDate.addDays(1);}
tbody.append(r);}
calendarTable.append(tbody);return this.each(function(){$(this).empty().append(yearTbl).append(calendarTable);});},datePicker:function(s){if(!$.event._dpCache)$.event._dpCache=[];s=$.extend({},$.fn.datePicker.defaults,s);return this.each(function(){var $this=$(this);var alreadyExists=true;if(!this._dpId){this._dpId=$.event.guid++;$.event._dpCache[this._dpId]=new DatePicker(this);alreadyExists=false;}
if(s.inline){s.createButton=false;s.displayClose=false;s.closeOnSelect=false;$this.empty();}
var controller=$.event._dpCache[this._dpId];controller.init(s);if(!alreadyExists&&s.createButton){controller.button=$('<a href="#" class="dp-choose-date tipp" title="Bitte Datum w&auml;hlen">'+$.dpText.TEXT_CHOOSE_DATE+'</a>').bind('click',function(){$this.dpDisplay(this);this.blur();return false;});$this.after(controller.button);}
if(!alreadyExists&&$this.is(':text')){$this.bind('dateSelected',function(e,selectedDate,$td){this.value=selectedDate.asString();}).bind('change',function(){if(this.value!=''){var d=Date.fromString(this.value);if(d){controller.setSelected(d,true,true);}}});if(s.clickInput){$this.bind('click',function(){$this.dpDisplay();});}
var d=Date.fromString(this.value);if(this.value!=''&&d){controller.setSelected(d,true,true);}}
$this.addClass('dp-applied');s.selectYears=$('<select></select>').attr({'id':'selYears','style':'width:60px;'});var sy=controller.startDate.getFullYear();var ey=controller.endDate.getFullYear();if(sy==0){sy=$.dpConst.MIN_YEAR;}
if(ey>2020){ey=$.dpConst.MAX_YEAR;}
for(var i=sy;i<=ey;i++){var y=$('<option></option>').attr({'value':i});if(i==controller.displayedYear){y.attr({'selected':true});}
y.html(i);s.selectYears.append(y);}
s.selectMonths=$('<select></select>').attr({'id':'selMonths','style':'width:100px;'});var sm=controller.startDate.getMonth();var em=controller.endDate.getMonth();if(sm>em&&ey-sy<=1){for(var i=0;i<=em;i++){var y=$('<option></option>').attr({'value':i});if(i==controller.displayedMonth){y.attr({'selected':true});}
y.html(Date.monthNames[i]);s.selectMonths.append(y);}
for(var i=sm;i<=11;i++){var y=$('<option></option>').attr({'value':i});if(i==controller.displayedMonth){y.attr({'selected':true});}
y.html(Date.monthNames[i]);s.selectMonths.append(y);}}
else{if(ey-sy>=1){sm=0;em=11;}
for(var i=sm;i<=em;i++){var y=$('<option></option>').attr({'value':i});if(i==controller.displayedMonth){y.attr({'selected':true});}
y.html(Date.monthNames[i]);s.selectMonths.append(y);}}})},dpSetDisabled:function(s){return _w.call(this,'setDisabled',s);},dpSetStartDate:function(d){return _w.call(this,'setStartDate',d);},dpSetEndDate:function(d){return _w.call(this,'setEndDate',d);},dpGetSelected:function(){var c=_getController(this[0]);if(c){return c.getSelected();}
return null;},dpSetSelected:function(d,v,m){if(v==undefined)v=true;if(m==undefined)m=true;return _w.call(this,'setSelected',Date.fromString(d),v,m,true);},dpSetDisplayedMonth:function(m,y){return _w.call(this,'setDisplayedMonth',Number(m),Number(y),true);},dpDisplay:function(e){return _w.call(this,'display',e);},dpSetRenderCallback:function(a){return _w.call(this,'setRenderCallback',a);},dpSetPosition:function(v,h){return _w.call(this,'setPosition',v,h);},dpSetOffset:function(v,h){return _w.call(this,'setOffset',v,h);},dpClose:function(){return _w.call(this,'_closeCalendar',false,this[0]);},_dpDestroy:function(){}});var _w=function(f,a1,a2,a3,a4){return this.each(function(){var c=_getController(this);if(c){c[f](a1,a2,a3,a4);}});};function DatePicker(ele){this.ele=ele;this.displayedMonth=null;this.displayedYear=null;this.startDate=null;this.endDate=null;this.showYearNavigation=null;this.closeOnSelect=null;this.displayClose=null;this.rememberViewedMonth=null;this.selectMultiple=null;this.numSelectable=null;this.numSelected=null;this.verticalPosition=null;this.horizontalPosition=null;this.verticalOffset=null;this.horizontalOffset=null;this.button=null;this.renderCallback=[];this.selectedDates={};this.inline=null;this.context='#dp-popup';this.settings={};};$.extend(DatePicker.prototype,{init:function(s){this.setStartDate(s.startDate);this.setEndDate(s.endDate);this.setDisplayedMonth(Number(s.month),Number(s.year));this.setRenderCallback(s.renderCallback);this.showYearNavigation=s.showYearNavigation;this.closeOnSelect=s.closeOnSelect;this.displayClose=s.displayClose;this.rememberViewedMonth=s.rememberViewedMonth;this.selectMultiple=s.selectMultiple;this.numSelectable=s.selectMultiple?s.numSelectable:1;this.numSelected=0;this.verticalPosition=s.verticalPosition;this.horizontalPosition=s.horizontalPosition;this.hoverClass=s.hoverClass;this.setOffset(s.verticalOffset,s.horizontalOffset);this.inline=s.inline;this.settings=s;this.selectYears=s.selectYears;this.selectMonths=s.selectMonths;if(this.inline){this.context=this.ele;this.display();}},setStartDate:function(d){if(d){this.startDate=Date.fromString(d);}
if(!this.startDate){this.startDate=(new Date()).zeroTime();}
this.setDisplayedMonth(this.displayedMonth,this.displayedYear);},setEndDate:function(d){if(d){this.endDate=Date.fromString(d);}
if(!this.endDate){this.endDate=(new Date('12/31/2040'));}
if(this.endDate.getTime()<this.startDate.getTime()){this.endDate=this.startDate;}
this.setDisplayedMonth(this.displayedMonth,this.displayedYear);},setPosition:function(v,h){this.verticalPosition=v;this.horizontalPosition=h;},setOffset:function(v,h){this.verticalOffset=parseInt(v)||0;this.horizontalOffset=parseInt(h)||0;},setDisabled:function(s){$e=$(this.ele);$e[s?'addClass':'removeClass']('dp-disabled');if(this.button){$but=$(this.button);$but[s?'addClass':'removeClass']('dp-disabled');$but.attr('title',s?'':$.dpText.TEXT_CHOOSE_DATE);}
if($e.is(':text')){$e.attr('disabled',s?'disabled':'');}},setDisplayedMonth:function(m,y,rerender){if(this.startDate==undefined||this.endDate==undefined){return;}
var s=new Date(this.startDate.getTime());s.setDate(1);var e=new Date(this.endDate.getTime());e.setDate(1);var t;if((!m&&!y)||(isNaN(m)&&isNaN(y))){t=new Date().zeroTime();t.setDate(1);}else if(isNaN(m)){t=new Date(y,this.displayedMonth,1);}else if(isNaN(y)){t=new Date(this.displayedYear,m,1);}else{t=new Date(y,m,1)}
if(t.getTime()<s.getTime()){t=s;}else if(t.getTime()>e.getTime()){t=e;}
var oldMonth=this.displayedMonth;var oldYear=this.displayedYear;this.displayedMonth=t.getMonth();this.displayedYear=t.getFullYear();if(rerender&&(this.displayedMonth!=oldMonth||this.displayedYear!=oldYear)){this._rerenderCalendar();$(this.ele).trigger('dpMonthChanged',[this.displayedMonth,this.displayedYear]);}},setSelected:function(d,v,moveToMonth,dispatchEvents){if(d<this.startDate||d>this.endDate){return;}
var s=this.settings;if(s.selectWeek){d=d.addDays(-(d.getDay()-Date.firstDayOfWeek+7)%7);if(d<this.startDate)
{return;}}
if(v==this.isSelected(d))
{return;}
if(this.selectMultiple==false){this.selectedDates={};this.numSelected=0;$('td.selected',this.context).removeClass('selected').parent().removeClass('selectedWeek');}else if(v&&this.numSelected==this.numSelectable){return;}
if(moveToMonth&&(this.displayedMonth!=d.getMonth()||this.displayedYear!=d.getFullYear())){this.setDisplayedMonth(d.getMonth(),d.getFullYear(),true);}
this.selectedDates[d.toString()]=v;this.numSelected+=v?1:-1;var selectorString='td.'+(d.getMonth()==this.displayedMonth?'current-month':'other-month');var $td;$(selectorString,this.context).each(function(){if($(this).data('datePickerDate')==d.asString()){$td=$(this);if(s.selectWeek){$td.parent()[v?'addClass':'removeClass']('selectedWeek');}
$td[v?'addClass':'removeClass']('selected');}});$('td',this.context).not('.selected')[this.selectMultiple&&this.numSelected==this.numSelectable?'addClass':'removeClass']('unselectable');if(dispatchEvents){var s=this.isSelected(d);$e=$(this.ele);var dClone=Date.fromString(d.asString());$e.trigger('dateSelected',[dClone,$td,s]);$e.trigger('change');}},isSelected:function(d){return this.selectedDates[d.toString()];},getSelected:function(){var r=[];for(s in this.selectedDates){if(this.selectedDates[s]==true){r.push(Date.parse(s));}}
return r;},display:function(eleAlignTo){if($(this.ele).is('.dp-disabled'))return;eleAlignTo=eleAlignTo||this.ele;var c=this;var $ele=$(eleAlignTo);var eleOffset=$ele.offset();var $createIn;var attrs;var attrsCalendarHolder;var cssRules;if(c.inline){$createIn=$(this.ele);attrs={'id':'calendar-'+this.ele._dpId,'className':'dp-popup dp-popup-inline'};$('.dp-popup',$createIn).remove();cssRules={};}else{$createIn=$('body');attrs={'id':'dp-popup','className':'dp-popup'};cssRules={'top':eleOffset.top+c.verticalOffset,'left':eleOffset.left+c.horizontalOffset};var _checkMouse=function(e){var el=e.target;var cal=$('#dp-popup')[0];while(true){if(el==cal){return true;}else if(el==document){c._closeCalendar();return false;}else{el=$(el).parent()[0];}}};this._checkMouse=_checkMouse;c._closeCalendar(true);$(document).bind('keydown.datepicker',function(event){if(event.keyCode==27){c._closeCalendar();}});}
if(!c.rememberViewedMonth){var selectedDate=this.getSelected()[0];if(selectedDate){selectedDate=new Date(selectedDate);this.setDisplayedMonth(selectedDate.getMonth(),selectedDate.getFullYear(),false);}}
$createIn.append($('<div></div>').attr(attrs).css(cssRules).append($('<h2></h2>'),$('<div class="dp-nav-prev"></div>').append($('<a class="dp-nav-prev-year" href="#" title="'+$.dpText.TEXT_PREV_YEAR+'">&lt;&lt;</a>').bind('click',function(){return c._displayNewMonth.call(c,this,0,-1);}),$('<a class="dp-nav-prev-month" href="#" title="'+$.dpText.TEXT_PREV_MONTH+'">&lt;</a>').bind('click',function(){return c._displayNewMonth.call(c,this,-1,0);})),$('<div class="dp-nav-next"></div>').append($('<a class="dp-nav-next-year" href="#" title="'+$.dpText.TEXT_NEXT_YEAR+'">&gt;&gt;</a>').bind('click',function(){return c._displayNewMonth.call(c,this,0,1);}),$('<a class="dp-nav-next-month" href="#" title="'+$.dpText.TEXT_NEXT_MONTH+'">&gt;</a>').bind('click',function(){return c._displayNewMonth.call(c,this,1,0);})),$('<div></div>').attr('className','dp-calendar')).bgIframe());var $pop=this.inline?$('.dp-popup',this.context):$('#dp-popup');if(this.showYearNavigation==false){$('.dp-nav-prev-year, .dp-nav-next-year',c.context).css('display','none');}
if(this.displayClose){$pop.append($('<a href="#" id="dp-close">'+$.dpText.TEXT_CLOSE+'</a>').bind('click',function(){c._closeCalendar();return false;}));}
c._renderCalendar();$(this.ele).trigger('dpDisplayed',$pop);if(!c.inline){if(this.verticalPosition==$.dpConst.POS_BOTTOM){$pop.css('top',eleOffset.top+$ele.height()-$pop.height()+c.verticalOffset);}
if(this.horizontalPosition==$.dpConst.POS_RIGHT){$pop.css('left',eleOffset.left+$ele.width()-$pop.width()+c.horizontalOffset);}
$(document).bind('mousedown.datepicker',this._checkMouse);}},setRenderCallback:function(a){if(a==null)return;if(a&&typeof(a)=='function'){a=[a];}
this.renderCallback=this.renderCallback.concat(a);},cellRender:function($td,thisDate,month,year){var c=this.dpController;var d=new Date(thisDate.getTime());$td.bind('click',function(){var $this=$(this);if(!$this.is('.disabled')){c.setSelected(d,!$this.is('.selected')||!c.selectMultiple,false,true);if(c.closeOnSelect){c._closeCalendar();}
if(!$.browser.msie){$(c.ele).trigger('focus',[$.dpConst.DP_INTERNAL_FOCUS]);}}});if(c.isSelected(d)){$td.addClass('selected');if(c.settings.selectWeek){$td.parent().addClass('selectedWeek');}}else if(c.selectMultiple&&c.numSelected==c.numSelectable){$td.addClass('unselectable');}},_applyRenderCallbacks:function(){var c=this;$('td',this.context).each(function(){for(var i=0;i<c.renderCallback.length;i++){$td=$(this);if($td.data('datePickerDate')){c.renderCallback[i].apply(this,[$td,Date.fromString($td.data('datePickerDate')),c.displayedMonth,c.displayedYear]);}}});return;},_displayNewMonth:function(ele,m,y){if(!$(ele).is('.disabled')){this.setDisplayedMonth(this.displayedMonth+m,this.displayedYear+y,true);}
ele.blur();return false;},_rerenderCalendar:function(){this._clearCalendar();this._renderCalendar();},_renderCalendar:function(){$('h2',this.context).html('&nbsp;');$('.dp-calendar',this.context).renderCalendar($.extend({},this.settings,{month:this.displayedMonth,year:this.displayedYear,renderCallback:this.cellRender,dpController:this,hoverClass:this.hoverClass}));if(this.displayedYear==this.startDate.getFullYear()&&this.displayedMonth==this.startDate.getMonth()){$('.dp-nav-prev-year',this.context).addClass('disabled');$('.dp-nav-prev-month',this.context).addClass('disabled');$('.dp-calendar td.other-month',this.context).each(function(){var $this=$(this);if(Number($this.text())>20){$this.addClass('disabled');}});var d=this.startDate.getDate();$('.dp-calendar td.current-month',this.context).each(function(){var $this=$(this);if(Number($this.text())<d){$this.addClass('disabled');}});}else{$('.dp-nav-prev-year',this.context).removeClass('disabled');$('.dp-nav-prev-month',this.context).removeClass('disabled');var d=this.startDate.getDate();if(d>20){var st=this.startDate.getTime();var sd=new Date(st);sd.addMonths(1);if(this.displayedYear==sd.getFullYear()&&this.displayedMonth==sd.getMonth()){$('.dp-calendar td.other-month',this.context).each(function(){var $this=$(this);if(Date.fromString($this.data('datePickerDate')).getTime()<st){$this.addClass('disabled');}});}}}
if(this.displayedYear==this.endDate.getFullYear()&&this.displayedMonth==this.endDate.getMonth()){$('.dp-nav-next-year',this.context).addClass('disabled');$('.dp-nav-next-month',this.context).addClass('disabled');$('.dp-calendar td.other-month',this.context).each(function(){var $this=$(this);if(Number($this.text())<14){$this.addClass('disabled');}});var d=this.endDate.getDate();$('.dp-calendar td.current-month',this.context).each(function(){var $this=$(this);if(Number($this.text())>d){$this.addClass('disabled');}});}else{$('.dp-nav-next-year',this.context).removeClass('disabled');$('.dp-nav-next-month',this.context).removeClass('disabled');var d=this.endDate.getDate();if(d<13){var ed=new Date(this.endDate.getTime());ed.addMonths(-1);if(this.displayedYear==ed.getFullYear()&&this.displayedMonth==ed.getMonth()){$('.dp-calendar td.other-month',this.context).each(function(){var $this=$(this);if(Number($this.text())>d){$this.addClass('disabled');}});}}}
this._applyRenderCallbacks();},_closeCalendar:function(programatic,ele){if(!ele||ele==this.ele){$(document).unbind('mousedown.datepicker');$(document).unbind('keydown.datepicker');this._clearCalendar();$('#dp-popup a').unbind();$('#dp-popup').empty().remove();if(!programatic){$(this.ele).trigger('dpClosed',[this.getSelected()]);}}},_clearCalendar:function(){$('.dp-calendar td',this.context).unbind();$('.dp-calendar',this.context).empty();}});$.dpConst={SHOW_HEADER_NONE:0,SHOW_HEADER_SHORT:1,SHOW_HEADER_LONG:2,POS_TOP:0,POS_BOTTOM:1,POS_LEFT:0,POS_RIGHT:1,DP_INTERNAL_FOCUS:'dpInternalFocusTrigger',MIN_YEAR:1900,MAX_YEAR:2050};$.dpText={TEXT_PREV_YEAR:'Previous year',TEXT_PREV_MONTH:'Previous month',TEXT_NEXT_YEAR:'Next year',TEXT_NEXT_MONTH:'Next month',TEXT_CLOSE:'Close',TEXT_CHOOSE_DATE:'Choose date',HEADER_FORMAT:'mmmm yyyy'};$.dpVersion='$Id: jquery.datePicker.js 53 2009-02-19 03:46:27Z kelvin.luck $';$.fn.datePicker.defaults={month:undefined,year:undefined,showHeader:$.dpConst.SHOW_HEADER_SHORT,startDate:undefined,endDate:undefined,inline:false,renderCallback:null,createButton:true,showYearNavigation:true,closeOnSelect:true,displayClose:false,selectMultiple:false,numSelectable:Number.MAX_VALUE,clickInput:false,rememberViewedMonth:true,selectWeek:false,verticalPosition:$.dpConst.POS_TOP,horizontalPosition:$.dpConst.POS_LEFT,verticalOffset:0,horizontalOffset:0,hoverClass:'dp-hover',selectYears:$('<select></select>'),selectMonths:$('<select></select>')};function _getController(ele){if(ele._dpId)return $.event._dpCache[ele._dpId];return false;};if($.fn.bgIframe==undefined){$.fn.bgIframe=function(){return this;};};$(window).bind('unload',function(){var els=$.event._dpCache||[];for(var i in els){$(els[i].ele)._dpDestroy();}});})(jQuery);
/*
* jQuery Autocomplete plugin 1.1 * Copyright (c) 2009 Joern Zaefferer * Dual licensed under the MIT and GPL licenses: http://www.opensource.org/licenses/mit-license.php http://www.gnu.org/licenses/gpl.html
*/;(function($){$.fn.extend({autocomplete:function(urlOrData,options){var isUrl=typeof urlOrData=="string";options=$.extend({},$.Autocompleter.defaults,{url:isUrl?urlOrData:null,data:isUrl?null:urlOrData,delay:isUrl?$.Autocompleter.defaults.delay:10,max:options&&!options.scroll?10:150},options);options.highlight=options.highlight||function(value){return value;};options.formatMatch=options.formatMatch||options.formatItem;return this.each(function(){new $.Autocompleter(this,options);});},result:function(handler){return this.bind("result",handler);},search:function(handler){return this.trigger("search",[handler]);},flushCache:function(){return this.trigger("flushCache");},setOptions:function(options){return this.trigger("setOptions",[options]);},unautocomplete:function(){return this.trigger("unautocomplete");}});$.Autocompleter=function(input,options){var KEY={UP:38,DOWN:40,DEL:46,TAB:9,RETURN:13,ESC:27,COMMA:188,PAGEUP:33,PAGEDOWN:34,BACKSPACE:8};var $input=$(input).attr("autocomplete","off").addClass(options.inputClass);var timeout;var previousValue="";var cache=$.Autocompleter.Cache(options);var hasFocus=0;var lastKeyPressCode;var config={mouseDownOnSelect:false};var select=$.Autocompleter.Select(options,input,selectCurrent,config);var blockSubmit;$.browser.opera&&$(input.form).bind("submit.autocomplete",function(){if(blockSubmit){blockSubmit=false;return false;}});$input.bind(($.browser.opera?"keypress":"keydown")+".autocomplete",function(event){hasFocus=1;lastKeyPressCode=event.keyCode;switch(event.keyCode){case KEY.UP:event.preventDefault();if(select.visible()){select.prev();}else{onChange(0,true);}break;case KEY.DOWN:event.preventDefault();if(select.visible()){select.next();}else{onChange(0,true);}break;case KEY.PAGEUP:event.preventDefault();if(select.visible()){select.pageUp();}else{onChange(0,true);}break;case KEY.PAGEDOWN:event.preventDefault();if(select.visible()){select.pageDown();}else{onChange(0,true);}break;case options.multiple&&$.trim(options.multipleSeparator)==","&&KEY.COMMA:case KEY.TAB:case KEY.RETURN:if(selectCurrent()){event.preventDefault();blockSubmit=true;return false;}break;case KEY.ESC:select.hide();break;default:clearTimeout(timeout);timeout=setTimeout(onChange,options.delay);break;}}).focus(function(){hasFocus++;}).blur(function(){hasFocus=0;if(!config.mouseDownOnSelect){hideResults();}}).click(function(){if(hasFocus++>1&&!select.visible()){onChange(0,true);}}).bind("search",function(){var fn=(arguments.length>1)?arguments[1]:null;function findValueCallback(q,data){var result;if(data&&data.length){for(var i=0;i<data.length;i++){if(data[i].result.toLowerCase()==q.toLowerCase()){result=data[i];break;}}}if(typeof fn=="function")fn(result);else $input.trigger("result",result&&[result.data,result.value]);}$.each(trimWords($input.val()),function(i,value){request(value,findValueCallback,findValueCallback);});}).bind("flushCache",function(){cache.flush();}).bind("setOptions",function(){$.extend(options,arguments[1]);if("data"in arguments[1])cache.populate();}).bind("unautocomplete",function(){select.unbind();$input.unbind();$(input.form).unbind(".autocomplete");});function selectCurrent(){var selected=select.selected();if(!selected)return false;var v=selected.result;previousValue=v;if(options.multiple){var words=trimWords($input.val());if(words.length>1){var seperator=options.multipleSeparator.length;var cursorAt=$(input).selection().start;var wordAt,progress=0;$.each(words,function(i,word){progress+=word.length;if(cursorAt<=progress){wordAt=i;return false;}progress+=seperator;});words[wordAt]=v;v=words.join(options.multipleSeparator);}v+=options.multipleSeparator;}$input.val(v);hideResultsNow();$input.trigger("result",[selected.data,selected.value]);return true;}function onChange(crap,skipPrevCheck){if(lastKeyPressCode==KEY.DEL){select.hide();return;}var currentValue=$input.val();if(!skipPrevCheck&&currentValue==previousValue)return;previousValue=currentValue;currentValue=lastWord(currentValue);if(currentValue.length>=options.minChars){$input.addClass(options.loadingClass);if(!options.matchCase)currentValue=currentValue.toLowerCase();request(currentValue,receiveData,hideResultsNow);}else{stopLoading();select.hide();}};function trimWords(value){if(!value)return[""];if(!options.multiple)return[$.trim(value)];return $.map(value.split(options.multipleSeparator),function(word){return $.trim(value).length?$.trim(word):null;});}function lastWord(value){if(!options.multiple)return value;var words=trimWords(value);if(words.length==1)return words[0];var cursorAt=$(input).selection().start;if(cursorAt==value.length){words=trimWords(value)}else{words=trimWords(value.replace(value.substring(cursorAt),""));}return words[words.length-1];}function autoFill(q,sValue){if(options.autoFill&&(lastWord($input.val()).toLowerCase()==q.toLowerCase())&&lastKeyPressCode!=KEY.BACKSPACE){$input.val($input.val()+sValue.substring(lastWord(previousValue).length));$(input).selection(previousValue.length,previousValue.length+sValue.length);}};function hideResults(){clearTimeout(timeout);timeout=setTimeout(hideResultsNow,200);};function hideResultsNow(){var wasVisible=select.visible();select.hide();clearTimeout(timeout);stopLoading();if(options.mustMatch){$input.search(function(result){if(!result){if(options.multiple){var words=trimWords($input.val()).slice(0,-1);$input.val(words.join(options.multipleSeparator)+(words.length?options.multipleSeparator:""));}else{$input.val("");$input.trigger("result",null);}}});}};function receiveData(q,data){if(data&&data.length&&hasFocus){stopLoading();select.display(data,q);autoFill(q,data[0].value);select.show();}else{hideResultsNow();}};function request(term,success,failure){if(!options.matchCase)term=term.toLowerCase();var data=cache.load(term);if(data&&data.length){success(term,data);}else if((typeof options.url=="string")&&(options.url.length>0)){var extraParams={timestamp:+new Date()};$.each(options.extraParams,function(key,param){extraParams[key]=typeof param=="function"?param():param;});$.ajax({mode:"abort",port:"autocomplete"+input.name,dataType:options.dataType,url:options.url,data:$.extend({q:lastWord(term),limit:options.max},extraParams),success:function(data){var parsed=options.parse&&options.parse(data)||parse(data);cache.add(term,parsed);success(term,parsed);}});}else{select.emptyList();failure(term);}};function parse(data){var parsed=[];var rows=data.split("\n");for(var i=0;i<rows.length;i++){var row=$.trim(rows[i]);if(row){row=row.split("|");parsed[parsed.length]={data:row,value:row[0],result:options.formatResult&&options.formatResult(row,row[0])||row[0]};}}return parsed;};function stopLoading(){$input.removeClass(options.loadingClass);};};$.Autocompleter.defaults={inputClass:"ac_input",resultsClass:"ac_results",loadingClass:"ac_loading",minChars:1,delay:400,matchCase:false,matchSubset:true,matchContains:false,cacheLength:10,max:100,mustMatch:false,extraParams:{},selectFirst:true,formatItem:function(row){return row[0];},formatMatch:null,autoFill:false,width:0,multiple:false,multipleSeparator:", ",highlight:function(value,term){return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,"\\$1")+")(?![^<>]*>)(?![^&;]+;)","gi"),"<strong>$1</strong>");},scroll:true,scrollHeight:180};$.Autocompleter.Cache=function(options){var data={};var length=0;function matchSubset(s,sub){if(!options.matchCase)s=s.toLowerCase();var i=s.indexOf(sub);if(options.matchContains=="word"){i=s.toLowerCase().search("\\b"+sub.toLowerCase());}if(i==-1)return false;return i==0||options.matchContains;};function add(q,value){if(length>options.cacheLength){flush();}if(!data[q]){length++;}data[q]=value;}function populate(){if(!options.data)return false;var stMatchSets={},nullData=0;if(!options.url)options.cacheLength=1;stMatchSets[""]=[];for(var i=0,ol=options.data.length;i<ol;i++){var rawValue=options.data[i];rawValue=(typeof rawValue=="string")?[rawValue]:rawValue;var value=options.formatMatch(rawValue,i+1,options.data.length);if(value===false)continue;var firstChar=value.charAt(0).toLowerCase();if(!stMatchSets[firstChar])stMatchSets[firstChar]=[];var row={value:value,data:rawValue,result:options.formatResult&&options.formatResult(rawValue)||value};stMatchSets[firstChar].push(row);if(nullData++<options.max){stMatchSets[""].push(row);}};$.each(stMatchSets,function(i,value){options.cacheLength++;add(i,value);});}setTimeout(populate,25);function flush(){data={};length=0;}return{flush:flush,add:add,populate:populate,load:function(q){if(!options.cacheLength||!length)return null;if(!options.url&&options.matchContains){var csub=[];for(var k in data){if(k.length>0){var c=data[k];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub.push(x);}});}}return csub;}else
if(data[q]){return data[q];}else
if(options.matchSubset){for(var i=q.length-1;i>=options.minChars;i--){var c=data[q.substr(0,i)];if(c){var csub=[];$.each(c,function(i,x){if(matchSubset(x.value,q)){csub[csub.length]=x;}});return csub;}}}return null;}};};$.Autocompleter.Select=function(options,input,select,config){var CLASSES={ACTIVE:"ac_over"};var listItems,active=-1,data,term="",needsInit=true,element,list;function init(){if(!needsInit)return;element=$("<div/>").hide().addClass(options.resultsClass).css("position","absolute").appendTo(document.body);list=$("<ul/>").appendTo(element).mouseover(function(event){if(target(event).nodeName&&target(event).nodeName.toUpperCase()=='LI'){active=$("li",list).removeClass(CLASSES.ACTIVE).index(target(event));$(target(event)).addClass(CLASSES.ACTIVE);}}).click(function(event){$(target(event)).addClass(CLASSES.ACTIVE);select();input.focus();return false;}).mousedown(function(){config.mouseDownOnSelect=true;}).mouseup(function(){config.mouseDownOnSelect=false;});if(options.width>0)element.css("width",options.width);needsInit=false;}function target(event){var element=event.target;while(element&&element.tagName!="LI")element=element.parentNode;if(!element)return[];return element;}function moveSelect(step){listItems.slice(active,active+1).removeClass(CLASSES.ACTIVE);movePosition(step);var activeItem=listItems.slice(active,active+1).addClass(CLASSES.ACTIVE);if(options.scroll){var offset=0;listItems.slice(0,active).each(function(){offset+=this.offsetHeight;});if((offset+activeItem[0].offsetHeight-list.scrollTop())>list[0].clientHeight){list.scrollTop(offset+activeItem[0].offsetHeight-list.innerHeight());}else if(offset<list.scrollTop()){list.scrollTop(offset);}}};function movePosition(step){active+=step;if(active<0){active=listItems.size()-1;}else if(active>=listItems.size()){active=0;}}function limitNumberOfItems(available){return options.max&&options.max<available?options.max:available;}function fillList(){list.empty();var max=limitNumberOfItems(data.length);for(var i=0;i<max;i++){if(!data[i])continue;var formatted=options.formatItem(data[i].data,i+1,max,data[i].value,term);if(formatted===false)continue;var li=$("<li/>").html(options.highlight(formatted,term)).addClass(i%2==0?"ac_even":"ac_odd").appendTo(list)[0];$.data(li,"ac_data",data[i]);}listItems=list.find("li");if(options.selectFirst){listItems.slice(0,1).addClass(CLASSES.ACTIVE);active=0;}if($.fn.bgiframe)list.bgiframe();}return{display:function(d,q){init();data=d;term=q;fillList();},next:function(){moveSelect(1);},prev:function(){moveSelect(-1);},pageUp:function(){if(active!=0&&active-8<0){moveSelect(-active);}else{moveSelect(-8);}},pageDown:function(){if(active!=listItems.size()-1&&active+8>listItems.size()){moveSelect(listItems.size()-1-active);}else{moveSelect(8);}},hide:function(){element&&element.hide();listItems&&listItems.removeClass(CLASSES.ACTIVE);active=-1;},visible:function(){return element&&element.is(":visible");},current:function(){return this.visible()&&(listItems.filter("."+CLASSES.ACTIVE)[0]||options.selectFirst&&listItems[0]);},show:function(){var offset=$(input).offset();element.css({width:typeof options.width=="string"||options.width>0?options.width:$(input).width(),top:offset.top+input.offsetHeight,left:offset.left}).show();if(options.scroll){list.scrollTop(0);list.css({maxHeight:options.scrollHeight,overflow:'auto'});if($.browser.msie&&typeof document.body.style.maxHeight==="undefined"){var listHeight=0;listItems.each(function(){listHeight+=this.offsetHeight;});var scrollbarsVisible=listHeight>options.scrollHeight;list.css('height',scrollbarsVisible?options.scrollHeight:listHeight);if(!scrollbarsVisible){listItems.width(list.width()-parseInt(listItems.css("padding-left"))-parseInt(listItems.css("padding-right")));}}}},selected:function(){var selected=listItems&&listItems.filter("."+CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);return selected&&selected.length&&$.data(selected[0],"ac_data");},emptyList:function(){list&&list.empty();},unbind:function(){element&&element.remove();}};};$.fn.selection=function(start,end){if(start!==undefined){return this.each(function(){if(this.createTextRange){var selRange=this.createTextRange();if(end===undefined||start==end){selRange.move("character",start);selRange.select();}else{selRange.collapse(true);selRange.moveStart("character",start);selRange.moveEnd("character",end);selRange.select();}}else if(this.setSelectionRange){this.setSelectionRange(start,end);}else if(this.selectionStart){this.selectionStart=start;this.selectionEnd=end;}});}var field=this[0];if(field.createTextRange){var range=document.selection.createRange(),orig=field.value,teststring="<->",textLength=range.text.length;range.text=teststring;var caretAt=field.value.indexOf(teststring);field.value=orig;this.selection(caretAt,caretAt+textLength);return{start:caretAt,end:caretAt+textLength}}else if(field.selectionStart!==undefined){return{start:field.selectionStart,end:field.selectionEnd}}};})(jQuery);
