jQuery.autocomplete = function(input, options) {
var me = this;
var $input = $(input).attr("autocomplete", "off");
if (options.inputClass) {
$input.addClass(options.inputClass);
}
var results = document.createElement("div");
var $results = $(results).hide().addClass(options.resultsClass).css("position", "absolute");
if( options.width > 0 ) {
$results.css("width", options.width);
}
$("body").append(results);
input.autocompleter = me;
var timeout = null;
var prev = "";
var active = -1;
var cache = {};
var keyb = false;
var hasFocus = false;
var lastKeyPressCode = null;
var mouseDownOnSelect = false;
var hidingResults = false;
function flushCache(){
cache = {};
cache.data = {};
cache.length = 0;
};
flushCache();
if( options.data != null ){
var sFirstChar = "", stMatchSets = {}, row = [];
if( typeof options.url != "string" ) {
options.cacheLength = 1;
}
for( var i=0; i < options.data.length; i++ ){
row = ((typeof options.data[i] == "string") ? [options.data[i]] : options.data[i]);
if( row[0].length > 0 ){
sFirstChar = row[0].substring(0, 1).toLowerCase();
if( !stMatchSets[sFirstChar] ) stMatchSets[sFirstChar] = [];
stMatchSets[sFirstChar].push(row);
}
}
for( var k in stMatchSets ) {
options.cacheLength++;
addToCache(k, stMatchSets[k]);
}
}
$input
.keydown(function(e) {
lastKeyPressCode = e.keyCode;
switch(e.keyCode) {
case 38: 
e.preventDefault();
moveSelect(-1);
break;
case 40: 
e.preventDefault();
moveSelect(1);
break;
case 9:  
case 13: 
if( selectCurrent() ){
$input.get(0).blur();
e.preventDefault();
}
break;
default:
active = -1;
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function(){onChange();}, options.delay);
break;
}
})
.focus(function(){
hasFocus = true;
})
.blur(function() {
hasFocus = false;
if (!mouseDownOnSelect) {
hideResults();
}
});
hideResultsNow();
function onChange() {
if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ) return $results.hide();
var v = $input.val();
if (v == prev) return;
prev = v;
if (v.length >= options.minChars) {
$input.addClass(options.loadingClass);
requestData(v);
} else {
$input.removeClass(options.loadingClass);
$results.hide();
}
};
function moveSelect(step) {
var lis = $("li", results);
if (!lis) return;
active += step;
if (active < 0) {
active = 0;
} else if (active >= lis.size()) {
active = lis.size() - 1;
}
lis.removeClass("ac_over");
$(lis[active]).addClass("ac_over");
};
function selectCurrent() {
var li = $("li.ac_over", results)[0];
if (!li) {
var $li = $("li", results);
if (options.selectOnly) {
if ($li.length == 1) li = $li[0];
} else if (options.selectFirst) {
li = $li[0];
}
}
if (li) {
selectItem(li);
return true;
} else {
return false;
}
};
function selectItem(li) {
if (!li) {
li = document.createElement("li");
li.extra = [];
li.selectValue = "";
}
var v = $.trim(li.selectValue ? li.selectValue : li.innerHTML);
input.lastSelected = v;
prev = v;
$results.html("");
$input.val(v);
hideResultsNow();
if (options.onItemSelect) {
setTimeout(function() { options.onItemSelect(li) }, 1);
}
};
function createSelection(start, end){
var field = $input.get(0);
if( field.createTextRange ){
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", end);
selRange.select();
} else if( field.setSelectionRange ){
field.setSelectionRange(start, end);
} else {
if( field.selectionStart ){
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
};
function autoFill(sValue){
if( lastKeyPressCode != 8 ){
$input.val($input.val() + sValue.substring(prev.length));
createSelection(prev.length, sValue.length);
}
};
function showResults() {
var pos = findPos(input);
var iWidth = (options.width > 0) ? options.width : $input.width();
$results.css({
width: parseInt(iWidth) + "px",
top: (pos.y + input.offsetHeight) + "px",
left: pos.x + "px"
}).show();
};
function hideResults() {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(hideResultsNow, 200);
};
function hideResultsNow() {
if (hidingResults) {
return;
}
hidingResults = true;
if (timeout) {
clearTimeout(timeout);
}
var v = $input.removeClass(options.loadingClass).val();
if ($results.is(":visible")) {
$results.hide();
}
if (options.mustMatch) {
if (!input.lastSelected || input.lastSelected != v) {
selectItem(null);
}
}
hidingResults = false;
};
function receiveData(q, data) {
if (data) {
$input.removeClass(options.loadingClass);
results.innerHTML = "";
if( !hasFocus || data.length == 0 ) return hideResultsNow();
if ($.browser.msie) {
$results.append(document.createElement('iframe'));
}
results.appendChild(dataToDom(data));
if( options.autoFill && ($input.val().toLowerCase() == q.toLowerCase()) ) autoFill(data[0][0]);
showResults();
} else {
hideResultsNow();
}
};
function parseData(data) {
if (!data) return null;
var parsed = [];
var rows = data.split(options.lineSeparator);
for (var i=0; i < rows.length; i++) {
var row = $.trim(rows[i]);
if (row) {
parsed[parsed.length] = row.split(options.cellSeparator);
}
}
return parsed;
};
function dataToDom(data) {
var ul = document.createElement("ul");
var num = data.length;
if( (options.maxItemsToShow > 0) && (options.maxItemsToShow < num) ) num = options.maxItemsToShow;
for (var i=0; i < num; i++) {
var row = data[i];
if (!row) continue;
var li = document.createElement("li");
if (options.formatItem) {
li.innerHTML = options.formatItem(row, i, num);
li.selectValue = row[0];
} else {
li.innerHTML = row[0];
li.selectValue = row[0];
}
var extra = null;
if (row.length > 1) {
extra = [];
for (var j=1; j < row.length; j++) {
extra[extra.length] = row[j];
}
}
li.extra = extra;
ul.appendChild(li);
$(li).hover(
function() { $("li", ul).removeClass("ac_over"); $(this).addClass("ac_over"); active = $("li", ul).indexOf($(this).get(0)); },
function() { $(this).removeClass("ac_over"); }
).click(function(e) { 
e.preventDefault();
e.stopPropagation();
selectItem(this)
});
}
$(ul).mousedown(function() {
mouseDownOnSelect = true;
}).mouseup(function() {
mouseDownOnSelect = false;
});
return ul;
};
function requestData(q) {
if (!options.matchCase) q = q.toLowerCase();
var data = options.cacheLength ? loadFromCache(q) : null;
if (data) {
receiveData(q, data);
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
$.get(makeUrl(q), function(data) {
data = parseData(data);
addToCache(q, data);
receiveData(q, data);
});
} else {
$input.removeClass(options.loadingClass);
}
};
function makeUrl(q) {
var sep = options.url.indexOf('?') == -1 ? '?' : '&'; 
var url = options.url + sep + "q=" + encodeURI(q);
for (var i in options.extraParams) {
url += "&" + i + "=" + encodeURI(options.extraParams[i]);
}
return url;
};
function loadFromCache(q) {
if (!q) return null;
if (cache.data[q]) return cache.data[q];
if (options.matchSubset) {
for (var i = q.length - 1; i >= options.minChars; i--) {
var qs = q.substr(0, i);
var c = cache.data[qs];
if (c) {
var csub = [];
for (var j = 0; j < c.length; j++) {
var x = c[j];
var x0 = x[0];
if (matchSubset(x0, q)) {
csub[csub.length] = x;
}
}
return csub;
}
}
}
return null;
};
function matchSubset(s, sub) {
if (!options.matchCase) s = s.toLowerCase();
var i = s.indexOf(sub);
if (i == -1) return false;
return i == 0 || options.matchContains;
};
this.flushCache = function() {
flushCache();
};
this.setExtraParams = function(p) {
options.extraParams = p;
};
this.findValue = function(){
var q = $input.val();
if (!options.matchCase) q = q.toLowerCase();
var data = options.cacheLength ? loadFromCache(q) : null;
if (data) {
findValueCallback(q, data);
} else if( (typeof options.url == "string") && (options.url.length > 0) ){
$.get(makeUrl(q), function(data) {
data = parseData(data)
addToCache(q, data);
findValueCallback(q, data);
});
} else {
findValueCallback(q, null);
}
}
function findValueCallback(q, data){
if (data) $input.removeClass(options.loadingClass);
var num = (data) ? data.length : 0;
var li = null;
for (var i=0; i < num; i++) {
var row = data[i];
if( row[0].toLowerCase() == q.toLowerCase() ){
li = document.createElement("li");
if (options.formatItem) {
li.innerHTML = options.formatItem(row, i, num);
li.selectValue = row[0];
} else {
li.innerHTML = row[0];
li.selectValue = row[0];
}
var extra = null;
if( row.length > 1 ){
extra = [];
for (var j=1; j < row.length; j++) {
extra[extra.length] = row[j];
}
}
li.extra = extra;
}
}
if( options.onFindValue ) setTimeout(function() { options.onFindValue(li) }, 1);
}
function addToCache(q, data) {
if (!data || !q || !options.cacheLength) return;
if (!cache.length || cache.length > options.cacheLength) {
flushCache();
cache.length++;
} else if (!cache[q]) {
cache.length++;
}
cache.data[q] = data;
};
function findPos(obj) {
var curleft = obj.offsetLeft || 0;
var curtop = obj.offsetTop || 0;
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
return {x:curleft,y:curtop};
}
}
jQuery.fn.autocomplete = function(url, options, data) {
options = options || {};
options.url = url;
options.data = ((typeof data == "object") && (data.constructor == Array)) ? data : null;
options.inputClass = options.inputClass || "ac_input";
options.resultsClass = options.resultsClass || "ac_results";
options.lineSeparator = options.lineSeparator || "\n";
options.cellSeparator = options.cellSeparator || "|";
options.minChars = options.minChars || 1;
options.delay = options.delay || 400;
options.matchCase = options.matchCase || 0;
options.matchSubset = options.matchSubset || 1;
options.matchContains = options.matchContains || 0;
options.cacheLength = options.cacheLength || 1;
options.mustMatch = options.mustMatch || 0;
options.extraParams = options.extraParams || {};
options.loadingClass = options.loadingClass || "ac_loading";
options.selectFirst = options.selectFirst || false;
options.selectOnly = options.selectOnly || false;
options.maxItemsToShow = options.maxItemsToShow || -1;
options.autoFill = options.autoFill || false;
options.width = parseInt(options.width, 10) || 0;
this.each(function() {
var input = this;
new jQuery.autocomplete(input, options);
});
return this;
}
jQuery.fn.autocompleteArray = function(data, options) {
return this.autocomplete(null, options, data);
}
jQuery.fn.indexOf = function(e){
for( var i=0; i<this.length; i++ ){
if( this[i] == e ) return i;
}
return -1;
};



//cluetip
(function($) { 

var $cluetip, $cluetipInner, $cluetipOuter, $cluetipTitle, $dropShadow, imgCount;
var msie6 = $.browser.msie && ($.browser.version && $.browser.version < 7 || (/5\.5|6.0/).test(navigator.userAgent));

$.fn.cluetip = function(options) {

var defaults = {
width: 275,
height: 'auto',
local: false,
hideLocal: true,
attribute: 'rel',
titleAttribute: 'title',
splitTitle: '',
showTitle: true,
cluetipClass: 'default',
hoverClass: '',
waitImage: true,
cursor: 'help',
arrows: false, 
dropShadow: true,
dropShadowSteps: 6,
sticky: false,
mouseOutClose: false,
activation: 'hover',
closePosition: 'top',
closeText: 'Close',
truncate: 0,
cluezIndex: 97,
positionBy: 'auto', 
fx: {
open: 'show',
openSpeed: '',
close: 'hide',
closeSpeed: ''
},
hoverIntent: {
sensitivity: 3,
interval: 50,
timeout: 0
},
onShow: function (ct, c){},
ajaxCache: true, 
ajaxProcess: function(data) {
data = $(data).not('style, meta, link, script, title');
return data;
},
ajaxSettings: {
dataType: 'html'
}
};

if (options && options.ajaxSettings) {
$.extend(defaults.ajaxSettings, options.ajaxSettings);
delete options.ajaxSettings;
}
if (options && options.fx) {
$.extend(defaults.fx, options.fx);
delete options.fx;
}
if (options && options.hoverIntent) {
$.extend(defaults.hoverIntent, options.hoverIntent);
delete options.hoverIntent;
}
$.extend(defaults, options);

return this.each(function() {
var cluetipContents = false;
var cluezIndex = parseInt(defaults.cluezIndex, 10)-1;
var isActive = false;

if (!$cluetip) {
$cluetipInner = $('<div id="cluetip-inner"></div>');
$cluetipTitle = $('<h3 id="cluetip-title"></h3>'); 
$cluetipOuter = $('<div id="cluetip-outer"></div>').append($cluetipInner).prepend($cluetipTitle);
$cluetip = $('<div></div>').attr({'id': 'cluetip'}).css({zIndex: defaults.cluezIndex})
.append($cluetipOuter)[insertionType](insertionElement).hide();
$('<div id="cluetip-waitimage"></div>').css({position: 'absolute', zIndex: cluezIndex-1})
.insertBefore('#cluetip').hide();
$cluetip.css({position: 'absolute', zIndex: cluezIndex});
$cluetipOuter.css({position: 'relative', zIndex: cluezIndex+1});
}
var dropShadowSteps = (defaults.dropShadow) ? +defaults.dropShadowSteps : 0;
if (!$dropShadow) {
$dropShadow = $([]);
for (var i=0; i < dropShadowSteps; i++) {
$dropShadow = $dropShadow.add($('<div></div>').css({zIndex: cluezIndex-i-1, opacity:.1, top: 1+i, left: 1+i}));
};
$dropShadow.css({position: 'absolute', backgroundColor: '#000'})
.prependTo($cluetip);
}
var $this = $(this); 
var tipAttribute = $this.attr(defaults.attribute), ctClass = defaults.cluetipClass;
if (!tipAttribute && !defaults.splitTitle) return true;
if (defaults.local && defaults.hideLocal) { $(tipAttribute).hide(); }
var tipHeight, wHeight;
var defHeight = isNaN(parseInt(defaults.height, 10)) ? 'auto' : (/\D/g).test(defaults.height) ? defaults.height : defaults.height + 'px';
var sTop, linkTop, posY, tipY, mouseY;
var tipWidth = parseInt(defaults.width, 10) + parseInt($cluetip.css('paddingLeft')) + parseInt($cluetip.css('paddingRight')) + dropShadowSteps;
if( isNaN(tipWidth) ) tipWidth = 275;
var linkWidth = this.offsetWidth;
var linkLeft, posX, tipX, mouseX, winWidth;

var tipParts;
var tipTitle = (defaults.attribute != 'title') ? $this.attr(defaults.titleAttribute) : '';
if (defaults.splitTitle) {
tipParts = tipTitle.split(defaults.splitTitle);
tipTitle = tipParts.shift();
}
var localContent;
var activate = function(event) {
isActive = true;
$cluetip.removeClass().css({width: defaults.width});
if (tipAttribute == $this.attr('href')) {
$this.css('cursor', defaults.cursor);
}
$this.attr('title','');
if (defaults.hoverClass) {
$this.addClass(defaults.hoverClass);
}
linkTop = posY = $this.offset().top;
linkLeft = $this.offset().left;
mouseX = event.pageX;
mouseY = event.pageY;
if ($this[0].tagName.toLowerCase() != 'area') {
sTop = $(document).scrollTop();
winWidth = $(window).width();
}
posX = (linkWidth > linkLeft && linkLeft > tipWidth)
|| linkLeft + linkWidth + tipWidth > winWidth 
? linkLeft - tipWidth - 0 
: linkWidth + linkLeft + 0;
if ($this[0].tagName.toLowerCase() == 'area' || defaults.positionBy == 'mouse' || linkWidth + tipWidth > winWidth) { // position by mouse
if (mouseX + 20 + tipWidth > winWidth) { 
posX = (mouseX - tipWidth - 20) >= 0 ? mouseX - tipWidth - 20 : mouseX - (tipWidth/2);
} else {
posX = mouseX + 20;
}
var pY = posX < 0 ? event.pageY + 20 : event.pageY;
}
posX < linkLeft ? $cluetip.addClass('clue-left-' + ctClass).removeClass('clue-right-' + ctClass)
: $cluetip.addClass('clue-right-' + ctClass).removeClass('clue-left-' + ctClass); 
$cluetip.css({left: (posX > 0 && defaults.positionBy != 'bottomTop') ? posX : (mouseX + (tipWidth/2) > winWidth) ? winWidth/2 - tipWidth/2 : Math.max(mouseX - (tipWidth/2),0)});
wHeight = $(window).height();
if (tipParts) {
for (var i=0; i < tipParts.length; i++){
if (i == 0) {
$cluetipInner.html(tipParts[i]);
} else { 
$cluetipInner.append('<div class="split-body">' + tipParts[i] + '</div>');
} 
};
cluetipShow(pY);
}
else if (!defaults.local && tipAttribute.indexOf('#') != 0) {
if (cluetipContents && defaults.ajaxCache) {
$cluetipInner.html(cluetipContents);
cluetipShow(pY);
}
else {
var ajaxSettings = defaults.ajaxSettings;
ajaxSettings.url = tipAttribute;
ajaxSettings.beforeSend = function() {
$cluetipOuter.children().empty();
if (defaults.waitImage) {
$('#cluetip-waitimage')
.css({top: mouseY-10, left: parseInt(posX+(tipWidth/2),10)})
.show();
}
};
ajaxSettings.error = function() {
if (isActive) {
$cluetipInner.html('<i>sorry, the contents could not be loaded</i>');
}
};
ajaxSettings.success = function(data) {
cluetipContents = defaults.ajaxProcess(data);
if (isActive) {
$cluetipInner.html(cluetipContents);
}
};
ajaxSettings.complete = function() {
imgCount = $('#cluetip-inner img').length;
if (imgCount) {
$('#cluetip-inner img').load( function(){
imgCount--;
if (imgCount<1) {
$('#cluetip-waitimage').hide();
if (isActive) cluetipShow(pY);
}
}); 
} else {
$('#cluetip-waitimage').hide();
cluetipShow(pY); 
} 
};
$.ajax(ajaxSettings);
}

} else if (defaults.local && tipAttribute.indexOf('#') == 0){
var localContent = $(tipAttribute).html();
$cluetipInner.html(localContent);
cluetipShow(pY);
}
};

var cluetipShow = function(bpY) {
$cluetip.addClass('cluetip-' + ctClass);

if (defaults.truncate) { 
var $truncloaded = $cluetipInner.text().slice(0,defaults.truncate) + '...';
$cluetipInner.html($truncloaded);
}
function doNothing() {}; //empty function
//tipTitle ? $cluetipTitle.show().html(tipTitle) : (defaults.showTitle) ? $cluetipTitle.show().html('&nbsp;') : $cluetipTitle.hide();
if (defaults.sticky) {
var $closeLink = $('<div id="cluetip-close"></div>');
(defaults.closePosition == 'bottom') ? $closeLink.appendTo($cluetipInner) : (defaults.closePosition == 'title') ? $closeLink.prependTo($cluetipTitle) : $closeLink.prependTo($cluetipInner);
$closeLink.click(function() {
cluetipClose();
return false;
});
if (defaults.mouseOutClose) {
$cluetip.hover(function() {doNothing(); }, 
function() {$closeLink.trigger('click'); });
} else {
$cluetip.unbind('mouseout');
}
}
$cluetipOuter.css({overflow: defHeight == 'auto' ? 'visible' : 'auto', height: defHeight});
tipHeight = defHeight == 'auto' ? $cluetip.outerHeight() : parseInt(defHeight,10); 
tipY = posY;
if ( (posX < mouseX && Math.max(posX, 0) + tipWidth > mouseX) || defaults.positionBy == 'bottomTop') {
tipY = posY + tipHeight > sTop + wHeight && mouseY - sTop > tipHeight + 10 ? mouseY - tipHeight - 16 : mouseY + 20;
} else if ( posY + tipHeight > sTop + wHeight ) {
tipY = (tipHeight >= wHeight) ? sTop : sTop + wHeight - tipHeight - 10;
} else if ($this.css('display') == 'block' || $this[0].tagName.toLowerCase() == 'area' || defaults.positionBy == "mouse") {
tipY = bpY - 10;
} else {
tipY = posY - defaults.dropShadowSteps;
} 
$cluetip.css({top: tipY + 'px'});
if (defaults.arrows) { // set up background positioning to align with element
var bgPos = '0 0';
var bgY = (posY - tipY - defaults.dropShadowSteps);
if ($cluetip.is('.clue-left-' + ctClass)) {
bgPos = posX >=0 ? '100% ' + bgY + 'px' : '100% 0';
} else if ($cluetip.is('.clue-right-' +ctClass)) {
bgPos = (posX >=0 && bgY > 0) ? '0 ' + bgY + 'px' : '0 0';
} 
} else {
bgPos = '0 100%';
}
$cluetip.css({backgroundPosition: bgPos});

$dropShadow.hide();
$cluetip.hide()[defaults.fx.open](defaults.fx.open != 'show' && defaults.fx.openSpeed);
if (defaults.dropShadow) $dropShadow.css({height: tipHeight, width: defaults.width}).show();
defaults.onShow($cluetip, $cluetipInner);
};
var inactivate = function() {
isActive = false;
$('#cluetip-waitimage').hide();
if (!defaults.sticky) {
cluetipClose();
};
if (defaults.hoverClass) {
$this.removeClass(defaults.hoverClass);
}
};
var cluetipClose = function() {
$cluetipOuter 
.parent()[defaults.fx.close](defaults.fx.closeSpeed).removeClass().end()
.children().empty();
if (tipTitle) {
$this.attr('title', tipTitle);
}
};

if (defaults.activation == 'click'||defaults.activation == 'toggle') {
$this.click(function(event) {
if ($cluetip.is(':hidden')) {
activate(event);
} else {
inactivate(event);
}
this.blur();
return false;
});
} else {
$this.click(function() {
if (tipAttribute == $this.attr('href')) {
return false;
}
});
if ($.fn.hoverIntent && defaults.hoverIntent) {
$this.hoverIntent({
sensitivity: defaults.hoverIntent.sensitivity,
interval: defaults.hoverIntent.interval, 
over: function(event) {activate(event);}, 
timeout: defaults.hoverIntent.timeout, 
out: function(event) {inactivate(event);}
}); 
} else {
$this.hover(function(event) {
activate(event);
}, function(event) {
inactivate(event);
});
}
}
});
};


var insertionType = 'appendTo', insertionElement = 'body';
$.cluetip = {};
$.cluetip.setup = function(options) {
if (options && options.insertionType && (options.insertionType).match(/appendTo|prependTo|insertBefore|insertAfter/)) {
insertionType = options.insertionType;
}
if (options && options.insertionElement) {
insertionElement = options.insertionElement;
}
};
})(jQuery);




//DIMENSIONS
(function($){

var height = $.fn.height,
width = $.fn.width;
$.fn.extend({
height: function() {
if ( !this[0] ) error();
if ( this[0] == window )
if ( $.browser.opera || ($.browser.safari && parseInt($.browser.version) > 520) )
return self.innerHeight - (($(document).height() > self.innerHeight) ? getScrollbarWidth() : 0);
else if ( $.browser.safari )
return self.innerHeight;
else
return $.boxModel && document.documentElement.clientHeight || document.body.clientHeight;

if ( this[0] == document ) 
return Math.max( ($.boxModel && document.documentElement.scrollHeight || document.body.scrollHeight), document.body.offsetHeight );

return height.apply(this, arguments);
},
width: function() {
if (!this[0]) error();
if ( this[0] == window )
if ( $.browser.opera || ($.browser.safari && parseInt($.browser.version) > 520) )
return self.innerWidth - (($(document).width() > self.innerWidth) ? getScrollbarWidth() : 0);
else if ( $.browser.safari )
return self.innerWidth;
else
return $.boxModel && document.documentElement.clientWidth || document.body.clientWidth;
if ( this[0] == document )
if ($.browser.mozilla) {

var scrollLeft = self.pageXOffset;
self.scrollTo(99999999, self.pageYOffset);
var scrollWidth = self.pageXOffset;
self.scrollTo(scrollLeft, self.pageYOffset);
return document.body.offsetWidth + scrollWidth;
}
else 
return Math.max( (($.boxModel && !$.browser.safari) && document.documentElement.scrollWidth || document.body.scrollWidth), document.body.offsetWidth );
return width.apply(this, arguments);
},

innerHeight: function() {
if (!this[0]) error();
return this[0] == window || this[0] == document ?
this.height() :
this.is(':visible') ?
this[0].offsetHeight - num(this, 'borderTopWidth') - num(this, 'borderBottomWidth') :
this.height() + num(this, 'paddingTop') + num(this, 'paddingBottom');
},

innerWidth: function() {
if (!this[0]) error();
return this[0] == window || this[0] == document ?
this.width() :
this.is(':visible') ?
this[0].offsetWidth - num(this, 'borderLeftWidth') - num(this, 'borderRightWidth') :
this.width() + num(this, 'paddingLeft') + num(this, 'paddingRight');
},

outerHeight: function(options) {
if (!this[0]) error();
options = $.extend({ margin: false }, options || {});
return this[0] == window || this[0] == document ?
this.height() :
this.is(':visible') ?
this[0].offsetHeight + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0) :
this.height() 
+ num(this,'borderTopWidth') + num(this, 'borderBottomWidth') 
+ num(this, 'paddingTop') + num(this, 'paddingBottom')
+ (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0);
},

outerWidth: function(options) {
if (!this[0]) error();
options = $.extend({ margin: false }, options || {});
return this[0] == window || this[0] == document ?
this.width() :
this.is(':visible') ?
this[0].offsetWidth + (options.margin ? (num(this, 'marginLeft') + num(this, 'marginRight')) : 0) :
this.width() 
+ num(this, 'borderLeftWidth') + num(this, 'borderRightWidth') 
+ num(this, 'paddingLeft') + num(this, 'paddingRight')
+ (options.margin ? (num(this, 'marginLeft') + num(this, 'marginRight')) : 0);
},

scrollLeft: function(val) {
if (!this[0]) error();
if ( val != undefined )

return this.each(function() {
if (this == window || this == document)
window.scrollTo( val, $(window).scrollTop() );
else
this.scrollLeft = val;
});


if ( this[0] == window || this[0] == document )
return self.pageXOffset ||
$.boxModel && document.documentElement.scrollLeft ||
document.body.scrollLeft;

return this[0].scrollLeft;
},

scrollTop: function(val) {
if (!this[0]) error();
if ( val != undefined )

return this.each(function() {
if (this == window || this == document)
window.scrollTo( $(window).scrollLeft(), val );
else
this.scrollTop = val;
});


if ( this[0] == window || this[0] == document )
return self.pageYOffset ||
$.boxModel && document.documentElement.scrollTop ||
document.body.scrollTop;
return this[0].scrollTop;
},

position: function(returnObject) {
return this.offset({ margin: false, scroll: false, relativeTo: this.offsetParent() }, returnObject);
},

offset: function(options, returnObject) {
if (!this[0]) error();
var x = 0, y = 0, sl = 0, st = 0,
elem = this[0], parent = this[0], op, parPos, elemPos = $.css(elem, 'position'),
mo = $.browser.mozilla, ie = $.browser.msie, oa = $.browser.opera,
sf = $.browser.safari, sf3 = $.browser.safari && parseInt($.browser.version) > 520,
absparent = false, relparent = false, 
options = $.extend({ margin: true, border: false, padding: false, scroll: true, lite: false, relativeTo: document.body }, options || {});


if (options.lite) return this.offsetLite(options, returnObject);

if (options.relativeTo.jquery) options.relativeTo = options.relativeTo[0];

if (elem.tagName == 'BODY') {


x = elem.offsetLeft;
y = elem.offsetTop;

if (mo) {
x += num(elem, 'marginLeft') + (num(elem, 'borderLeftWidth')*2);
y += num(elem, 'marginTop') + (num(elem, 'borderTopWidth') *2);
} else

if (oa) {
x += num(elem, 'marginLeft');
y += num(elem, 'marginTop');
} else

if ((ie && jQuery.boxModel)) {
x += num(elem, 'borderLeftWidth');
y += num(elem, 'borderTopWidth');
} else

if (sf3) {
x += num(elem, 'marginLeft') + num(elem, 'borderLeftWidth');
y += num(elem, 'marginTop') + num(elem, 'borderTopWidth');
}
} else {
do {
parPos = $.css(parent, 'position');

x += parent.offsetLeft;
y += parent.offsetTop;


if ((mo && !parent.tagName.match(/^t[d|h]$/i)) || ie || sf3) {

x += num(parent, 'borderLeftWidth');
y += num(parent, 'borderTopWidth');

if (mo && parPos == 'absolute') absparent = true;

if (ie && parPos == 'relative') relparent = true;
}
op = parent.offsetParent || document.body;
if (options.scroll || mo) {
do {
if (options.scroll) {

sl += parent.scrollLeft;
st += parent.scrollTop;
}


if (oa && ($.css(parent, 'display') || '').match(/table-row|inline/)) {
sl = sl - ((parent.scrollLeft == parent.offsetLeft) ? parent.scrollLeft : 0);
st = st - ((parent.scrollTop == parent.offsetTop) ? parent.scrollTop : 0);
}


if (mo && parent != elem && $.css(parent, 'overflow') != 'visible') {
x += num(parent, 'borderLeftWidth');
y += num(parent, 'borderTopWidth');
}

parent = parent.parentNode;
} while (parent != op);
}
parent = op;


if (parent == options.relativeTo && !(parent.tagName == 'BODY' || parent.tagName == 'HTML')) {

if (mo && parent != elem && $.css(parent, 'overflow') != 'visible') {
x += num(parent, 'borderLeftWidth');
y += num(parent, 'borderTopWidth');
}

if ( ((sf && !sf3) || oa) && parPos != 'static' ) {
x -= num(op, 'borderLeftWidth');
y -= num(op, 'borderTopWidth');
}
break;
}
if (parent.tagName == 'BODY' || parent.tagName == 'HTML') {

if (((sf && !sf3) || (ie && $.boxModel)) && elemPos != 'absolute' && elemPos != 'fixed') {
x += num(parent, 'marginLeft');
y += num(parent, 'marginTop');
}



if ( sf3 || (mo && !absparent && elemPos != 'fixed') || 
(ie && elemPos == 'static' && !relparent) ) {
x += num(parent, 'borderLeftWidth');
y += num(parent, 'borderTopWidth');
}
break; 
}
} while (parent);
}
var returnValue = handleOffsetReturn(elem, options, x, y, sl, st);
if (returnObject) { $.extend(returnObject, returnValue); return this; }
else { return returnValue; }
},

offsetLite: function(options, returnObject) {
if (!this[0]) error();
var x = 0, y = 0, sl = 0, st = 0, parent = this[0], offsetParent, 
options = $.extend({ margin: true, border: false, padding: false, scroll: true, relativeTo: document.body }, options || {});


if (options.relativeTo.jquery) options.relativeTo = options.relativeTo[0];

do {
x += parent.offsetLeft;
y += parent.offsetTop;
offsetParent = parent.offsetParent || document.body;
if (options.scroll) {

do {
sl += parent.scrollLeft;
st += parent.scrollTop;
parent = parent.parentNode;
} while(parent != offsetParent);
}
parent = offsetParent;
} while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML' && parent != options.relativeTo);
var returnValue = handleOffsetReturn(this[0], options, x, y, sl, st);
if (returnObject) { $.extend(returnObject, returnValue); return this; }
else { return returnValue; }
},

offsetParent: function() {
if (!this[0]) error();
var offsetParent = this[0].offsetParent;
while ( offsetParent && (offsetParent.tagName != 'BODY' && $.css(offsetParent, 'position') == 'static') )
offsetParent = offsetParent.offsetParent;
return $(offsetParent);
}
});

var error = function() {
throw "Dimensions: jQuery collection is empty";
};

var num = function(el, prop) {
return parseInt($.css(el.jquery?el[0]:el,prop))||0;
};

var handleOffsetReturn = function(elem, options, x, y, sl, st) {
if ( !options.margin ) {
x -= num(elem, 'marginLeft');
y -= num(elem, 'marginTop');
}

if ( options.border && (($.browser.safari && parseInt($.browser.version) < 520) || $.browser.opera) ) {
x += num(elem, 'borderLeftWidth');
y += num(elem, 'borderTopWidth');
} else if ( !options.border && !(($.browser.safari && parseInt($.browser.version) < 520) || $.browser.opera) ) {
x -= num(elem, 'borderLeftWidth');
y -= num(elem, 'borderTopWidth');
}
if ( options.padding ) {
x += num(elem, 'paddingLeft');
y += num(elem, 'paddingTop');
}


if ( options.scroll && (!$.browser.opera || elem.offsetLeft != elem.scrollLeft && elem.offsetTop != elem.scrollLeft) ) {
sl -= elem.scrollLeft;
st -= elem.scrollTop;
}
return options.scroll ? { top: y - st, left: x - sl, scrollTop: st, scrollLeft: sl }
: { top: y, left: x };
};

var scrollbarWidth = 0;
var getScrollbarWidth = function() {
if (!scrollbarWidth) {
var testEl = $('<div>')
.css({
width: 100,
height: 100,
overflow: 'auto',
position: 'absolute',
top: -1000,
left: -1000
})
.appendTo('body');
scrollbarWidth = 100 - testEl
.append('<div>')
.find('div')
.css({
width: '100%',
height: 200
})
.width();
testEl.remove();
}
return scrollbarWidth;
};
})(jQuery);



//hoverintent

(function($) {
$.fn.hoverIntent = function(f,g) {
var cfg = {
sensitivity: 7,
interval: 100,
timeout: 0
};
cfg = $.extend(cfg, g ? { over: f, out: g } : f );
var cX, cY, pX, pY;
var track = function(ev) {
cX = ev.pageX;
cY = ev.pageY;
};
var compare = function(ev,ob) {
ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
$(ob).unbind("mousemove",track);
ob.hoverIntent_s = 1;
return cfg.over.apply(ob,[ev]);
} else {
pX = cX; pY = cY;
ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
}
};
var delay = function(ev,ob) {
ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
ob.hoverIntent_s = 0;
return cfg.out.apply(ob,[ev]);
};
var handleHover = function(e) {
var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
if ( p == this ) { return false; }
var ev = jQuery.extend({},e);
var ob = this;
if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
if (e.type == "mouseover") {
pX = ev.pageX; pY = ev.pageY;
$(ob).bind("mousemove",track);
if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
} else {
$(ob).unbind("mousemove",track);
if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
}
};
return this.mouseover(handleHover).mouseout(handleHover);
};
})(jQuery);




function sure(cSmsg){
var agree=confirm(cSmsg);
if (agree)
return true;
else
return false;
}

function chooseMatch(cmType,cmSourceTable,cmSourceC) {

var URL = '/ajax/match_input_list_ajax.asp';
var w = 740
var h = 420
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
eval(cmType + "_window = window.open(URL + '?type=" + cmType + "&SourceTable=" + cmSourceTable + "&SourceC=" + cmSourceC + "', '" + cmType + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=" + w + ",height=" + h + ",left = " + winl + ",top = " + wint + "');");
eval(cmType + "_window.focus();");

}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=750,height=450,left = 465,top = 175');");
}

(function(jQuery) {

var self = null;

jQuery.fn.autogrow = function(o)
{	
return this.each(function() {
new jQuery.autogrow(this, o);
});
};
jQuery.autogrow = function (e, o)
{
this.options		  	= o || {};
this.dummy			  	= null;
this.interval	 	  	= null;
this.line_height	  	= this.options.lineHeight || parseInt(jQuery(e).css('line-height'));
this.min_height		  	= this.options.minHeight || parseInt(jQuery(e).css('min-height'));
this.max_height		  	= this.options.maxHeight || parseInt(jQuery(e).css('max-height'));;
this.textarea		  	= jQuery(e);

if(this.line_height == NaN)
this.line_height = 0;

// Only one textarea activated at a time, the one being used
this.init();
};

jQuery.autogrow.fn = jQuery.autogrow.prototype = {
autogrow: '1.2.2'
};

jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend;

jQuery.autogrow.fn.extend({
 
init: function() {			
var self = this;			
this.textarea.css({overflow: 'hidden', display: 'block'});
this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand() });
this.checkExpand();	
},
 
startExpand: function() {				
var self = this;
this.interval = window.setInterval(function() {self.checkExpand()}, 400);
},

stopExpand: function() {
clearInterval(this.interval);	
},

checkExpand: function() {

if (this.dummy == null)
{
this.dummy = jQuery('<div></div>');
this.dummy.css({
'font-size'  : this.textarea.css('font-size'),
'font-family': this.textarea.css('font-family'),
'width'      : this.textarea.css('width'),
'padding'    : this.textarea.css('padding'),
'line-height': this.line_height + 'px',
'overflow-x' : 'hidden',
'position'   : 'absolute',
'top'        : 0,
'left'		 : -9999
}).appendTo('body');
}

// Strip HTML tags
var html = this.textarea.val().replace(/(<|>)/g, '');

// IE is different, as per usual
if ($.browser.msie)
{
html = html.replace(/\n/g, '<BR>new');
}
else
{
html = html.replace(/\n/g, '<br>new');
}

if (this.dummy.html() != html)
{
this.dummy.html(html);	

if (this.max_height > 0 && (this.dummy.height() + this.line_height > this.max_height))
{
this.textarea.css('overflow-y', 'auto');	
}
else
{
this.textarea.css('overflow-y', 'hidden');
if (this.textarea.height() < this.dummy.height() + this.line_height || (this.dummy.height() < this.textarea.height()))
{	
this.textarea.animate({height: (this.dummy.height() + this.line_height) + 'px'}, 100);	
}
}
}
}
 
});
})(jQuery);



function bookmarkSet(bSArea,bSId) {
	var bm = document.getElementById('bm'+bSArea+bSId);
	var bmT = document.getElementById('bmT'+bSArea+bSId);
//	var favoriteCount = document.getElementById('favoriteCount');
//	var favoritedBy = document.getElementById('favoritedBy');
	
	var setTo;
	if (bm) {
		if (bm.src.indexOf('True') > 0) {
			bm.src = '/img/icons/starFalse.gif';
			bm.alt = 'Add to my favorites';
			setTo = 'False';
//			if (favoriteCount) {
//				favoriteCount.innerHTML = ((favoriteCount.innerHTML*1) - 1);
//			}
		} else {
			bm.src = '/img/icons/starTrue.gif';
			bm.alt = 'Remove from my favorites';
			setTo = 'True';
//			if (favoriteCount) {
//				favoriteCount.innerHTML = ((favoriteCount.innerHTML*1) + 1);
//			}
		}
		bm.title = bm.alt;
		if (bmT) {
			bmT.innerHTML = bm.title;
		}
		$.ajax({type: "GET",url: "/ajax/bookmarkSet.asp?area="+bSArea+"&area_c="+bSId+"&setTo="+setTo});
//		if (favoritedBy) {
//			updateFavoriteCount();
//		}
	}
}



function tagInteraction(tIType, tIMax) {
	$(":checkbox", "#chfTagContainer" + tIType)
		.each(function(){
		//this.checked = true;
		   var check = this;
		   var jlabel = jQuery("label[for='"+jQuery(check).attr("id")+"']");
		   //INITIAL CHECK
		   if (check.checked) {jlabel.addClass("checked");}
		   jlabel
			   .hover(
				   function() { jQuery(this).addClass("over"); },
				   function() { jQuery(this).removeClass("over"); }
			   )
			   // Label click state
			   .click(function(){
					//var checkedCount = $("input[name='"+jQuery(check).attr("name")+"'][checked]").length;
					var checkedCount = $(":checkbox:checked", "#chfTagContainer" + tIType).length;
					//alert(checkedCount);
					$("#chfTagContainer" + tIType).find(".maximum").hide();
					if (check.checked) {
						jlabel.removeClass("checked");
						if($.browser.msie){
							check.checked = false;
						} else {
							$(check).checked = false;
						}
					} else {
						if (checkedCount >= tIMax) {
							$("#chfTagContainer" + tIType).find(".maximum").fadeIn();
							return false;
						} else {
							jlabel.addClass("checked");
							if($.browser.msie){
								check.checked = true;
							} else {
								$(check).checked = true;
							}
						}
					}
			   });
	   });
}