$(document).ready(function() {
	$("select[multiple=multiple], select[multiple=true]").not(".noselect").multiselect({
		show: ["slide", { direction: "up" }, "slow"],
		hide: ["slide", { direction: "up" }, "slow"],
		height: 400
	}).multiselectfilter({label:""});
	
	var pagesize = 50;
	c_ps = get_cookie("pagesize");
	if (c_ps != "") {
		$(".pagesize").val(c_ps);
		pagesize = c_ps;
	}
	
	$(".layout_table").attr("cellspacing", 0);
	
	//If the pager ID is present, chain the tablesorterPager method
	if(document.getElementById("pager")){
		$(".layout_table").not(".nosort").tablesorter({
			textExtraction: function(node) {
				if (node.title != "") {
					return node.title;
				} else if ($("abbr", node).length == 1) {
					return $("abbr", node).text();
				} else {
					val = node.innerHTML.replace(/,/g, "");
					if (is_numeric(val)) {
						return parseFloat(val) + "";
					} else {
						return val;
					}
				}
			}
		}).tablesorterPager({
			container: $("#pager"),
			size: pagesize
		}).tablesorterFilter({
			filterContainer: $("#quicksearch")
			//filterColumns: [0, 1, 2, 3],
		});
		
		$(".pagesize").change(function() {
			set_cookie("pagesize", this.value);
		});
		
		$(".layout_table .header").click(function() {
			$("#pager .first").click();
		});
	}else{
		$(".layout_table").not(".nosort").tablesorter({
			textExtraction: function(node) {
				if (node.title != "") {
					return node.title;
				} else if ($("abbr", node).length == 1) {
					return $("abbr", node).text();
				} else {
					val = node.innerHTML.replace(/,/g, "");
					if (is_numeric(val)) {
						return parseFloat(val) + "";
					} else {
						return val;
					}
				}
			}
		}).tablesorterFilter({
			filterContainer: $("#quicksearch")
			//filterColumns: [0, 1, 2, 3],
		});
	}
	
	if (!$("#reporttype2").is(":checked")) {
		$("#adunitsbox").hide();
	}

	$(".datepicker").datepicker({
		showOn: "button",
		buttonImage: "/images/calendar.gif",
		buttonImageOnly: true,
		dateFormat: "yy-mm-dd"
	});
	
	$(".button, button[type=submit]").button();

	$("#quicksearch").click(function() {
		if (this.value == "") {
			$(this).keyup();
			$("#pager .first").click();
		}
	});
	
	$(".exportcsv").html("Export CSV").click(function() {
		if ($("#report_form").length == 0) {
			$("body").append('<form method="post" action="/scripts/post_csv.php" id="report_form" target="_blank"><input type="hidden" name="data" id="report_data" /></form>');
		}
		old_pagesize = $(".pagesize").val();
		$(".pagesize").val(10000).change();
		csv = $(".layout_table").table2CSV({ delivery: "value" });
		$("#report_data").val(csv);
		$("#report_form").submit();
		$(".pagesize").val(old_pagesize).change();
	});
	
	//Bulk actions dialog
	$("#with-selected").change(function(){
	   var bulkTarget = $(this).attr('rel');
	   var chosenOption = $("option:selected", this).attr("rel");
	   if(chosenOption != undefined && $('.bulk:checked').length > 0){ 
	   $.alerts.propertyName = 'Yes';
	   jConfirm("You are about to "+chosenOption+" multiple "+bulkTarget+" at once. Are you sure you want to do this?", "Bulk Action Confirm", function(r){
			if(r == true){
				$("#bulk-action-form").submit();
			}else{
				return false;
			}
		});
	   }
	});
	
	$(".bulk").click(function(e) {
	   e.stopPropagation();
	});
	
	//But not from span tags
	$(".layout_table tr").delegate("span", "click", function() {
	  return false;
	});
	
	$("#select-all").click(function() {
		$("#quicksearch").blur();
		$(".bulk:visible").each( function() {
			$(this).click();
		})
	});
	
	//Change chart views
	$(".chart-view-wrap a").click(function() {
		showchart = $(this).attr("title").split("Show ");
		showchart = showchart[1].replace(/ /gi, "_") + "Div";
		$("#all-charts div").each(function() {
			if($(this).attr('id') != showchart) {
				$(this).hide();
			}
			$('#' + showchart).show();
		});
		return false;
	});
	
	//Tooltip
	$('.chart-view-wrap a[title], .edit-field[title]').qtip({
		style: {
		  classes: 'ui-tooltip-dark'
		},
		position: {
		  my: 'bottom center',
		  at: 'top center',
		  adjust: {
			 y: -3
		  }
	   }
	});

	$('.preview-wrapper').delegate('#banner-ad-preview', 'mouseover', function(event) {
		$(this).qtip({
		  overwrite: false,
		  content: {
			text: $('.banner-preview')
		  },
		  show: {
			 event: event.type,
			 ready: true
		  },
		  style: {
			  classes: 'ui-tooltip-light'
			},
			position: {
			  my: 'left center',
			  at: 'right center'
		   }
		});
	});
	
	if ($("#ad_format_select").length > 0) {
		var initialVal = $("#ad_format_select option:selected").val();

		$(".banner-preview").html(idToBanner(initialVal));
		$("#ad_format_select").change(function() {
			if ($(this).val() != '30') {
				$('.preview-wrapper').show();
				$('.flex-wrapper').hide();
			}
				$(".banner-preview").html(idToBanner($(this).val())); 
		});
	}
	
	function idToBanner(id){
		switch (id) {
				case '1': //300 x 100 Small Rectangle
				  return '<img src="/usercp/images/banner_previews/300x100_fallback.png" />';
				  break;
				case '6': //300 x 250 Medium Rectangle
				  return '<img src="/usercp/images/banner_previews/300x250_fallback.png" />';
				  break;
				case '11': //300 x 250 Medium Rectangle / 300x600 Hybrid
				  return '<img src="/usercp/images/banner_previews/300x250_hybrid_fallback.png" />';
				  break;
				case '5': //336 x 280 Large Rectangle
				  return '<img src="/usercp/images/banner_previews/336x280_fallback.png" />';
				  break;
				case '16': //728 x 90 Leaderboard
				  return '<img src="/usercp/images/banner_previews/728x90_fallback.png" />';
				  break;
				case '19': //160 x 600 Wide Skyscraper
				  return '<img src="/usercp/images/banner_previews/160x600_fallback.png" />';
				  break;
				case '30': //1 x 1 Flextitial
				  $('.preview-wrapper').hide();
				  $('.flex-wrapper').html('( <a href="http://www.tonefuse.com/demos.php" target="_blank"><img src="/usercp/images/icon_eye.png" title="Click For Preview" alt="Preview Flextital" valign="middle" /></a> )').show();
				  break;
			}
	}
});

function is_numeric (mixed_var) {
    return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}

function change_dates(str) {
	switch (str) {
		case 'Today':
			ldate = new Date();
			hdate = new Date();
			break;
		case 'Yesterday':
			ldate = (new Date()).dateAdd("d", -1);
			hdate = (new Date()).dateAdd("d", -1);
			break;
		case 'Last 7 Days':
			ldate = (new Date()).dateAdd("d", -7);
			hdate = (new Date()).dateAdd("d", -1);
			break;
		case 'Last 30 Days':
			ldate = (new Date()).dateAdd("d", -30);
			hdate = (new Date()).dateAdd("d", -1);
			break;
		case 'This Month':
			thedate = new Date();
			thedate.setDate(1);
			ldate = thedate;
			hdate = (new Date());
			break;
		case 'Last Month':
			thedate = (new Date()).dateAdd("m", -1);
			thedate.setDate(1);
			ldate = thedate;
			thedate = new Date();
			thedate.setDate(1);
			hdate = thedate.dateAdd("d", -1);
			break;
		case 'This Year':
			thedate = new Date();
			thedate.setDate(1);
			thedate.setMonth(0);
			ldate = thedate;
			hdate = new Date();
			break;
		case 'Last Year':
			thedate = (new Date()).dateAdd("yyyy", -1);
			thedate.setDate(1);
			thedate.setMonth(0);
			ldate = thedate;
			thedate = new Date();
			thedate.setDate(31);
			thedate.setMonth(11);
			hdate = thedate.dateAdd("yyyy", -1);
			break;
		case 'Last 365 Days':
			ldate = (new Date()).dateAdd("d", -365);
			hdate = (new Date()).dateAdd("d", -1);
			break;
	}
	$("#date_from").val(date_format_mysql(ldate));
	$("#date_to").val(date_format_mysql(hdate));
}

function date_format_mysql(dt) {
	return dt.getFullYear() + "-" + twodig(dt.getMonth() + 1) + "-" + twodig(dt.getDate());
}

function twodig(str) {
	return ("" + str).length > 1 ? str : "0" + str;
}
 
function dateAddExtension(p_Interval, p_Number) { 
    var thing = new String();
 
    p_Number = new Number(p_Number); 
    switch(p_Interval.toLowerCase()) {  
        case "yyyy": {// year 
            this.setFullYear(this.getFullYear() + p_Number);
            break; 
        } 
        case "q": {        // quarter 
            this.setMonth(this.getMonth() + (p_Number*3)); 
            break; 
        } 
        case "m": {        // month 
            this.setMonth(this.getMonth() + p_Number); 
            break; 
        } 
        case "y":        // day of year 
        case "d":        // day 
        case "w": {        // weekday 
            this.setDate(this.getDate() + p_Number); 
            break; 
        } 
        case "ww": {    // week of year 
            this.setDate(this.getDate() + (p_Number*7)); 
            break; 
        } 
        case "h": {        // hour 
            this.setHours(this.getHours() + p_Number); 
            break; 
        } 
        case "n": {        // minute 
            this.setMinutes(this.getMinutes() + p_Number); 
            break; 
        } 
        case "s": {        // second 
            this.setSeconds(this.getSeconds() + p_Number); 
            break; 
        } 
        case "ms": {        // second 
            this.setMilliseconds(this.getMilliseconds() + p_Number); 
            break; 
        } 
        default: { 
            //throws an error so that the coder can see why he effed up and 
            //a list of elegible letters. 
            throw    "The first parameter must be a string from this list: \n" + 
                    "yyyy, q, m, y, d, w, ww, h, n, s, or ms. You passed: " + p_Interval; 
            return false; 
        } 
    } 
    return this; 
} 
Date.prototype.dateAdd = dateAddExtension;

function toggleAdUnits(str) {
	if (str == "none")
		$("#adunitsbox").hide("fast");
	else
		$("#adunitsbox").show("slow");
}

function set_cookie(c_name, value, expiredays)	{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" + escape(value) + ";path=/" + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";domain=." + top.location.host.replace(/www\./i, "");
}

function get_cookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) { 
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return '';
}

// jQuery insert at caret plugin
jQuery.fn.extend({insertAtCaret:function(a){return this.each(function(){if(document.selection)this.focus(),sel=document.selection.createRange(),sel.text=a,this.focus();else if(this.selectionStart||this.selectionStart=="0"){var b=this.selectionStart,c=this.selectionEnd,d=this.scrollTop;this.value=this.value.substring(0,b)+a+this.value.substring(c,this.value.length);this.focus();this.selectionStart=b+a.length;this.selectionEnd=b+a.length;this.scrollTop=d}else this.value+=a,this.focus()})}});

// Metadata - jQuery plugin for parsing metadata from elements
(function(b){b.extend({metadata:{defaults:{type:"class",name:"metadata",cre:/({.*})/,single:"metadata"},setType:function(a,b){this.defaults.type=a;this.defaults.name=b},get:function(a,h){var c=b.extend({},this.defaults,h);if(!c.single.length)c.single="metadata";var d=b.data(a,c.single);if(d)return d;var d="{}",g=function(a){if(typeof a!="string")return a;return a=eval("("+a+")")};if(c.type=="html5"){var f={};b(a.attributes).each(function(){var a=this.nodeName;if(a.match(/^data-/))a=a.replace(/^data-/,"");else return!0;f[a]=g(this.nodeValue)})}else{if(c.type=="class"){var e=c.cre.exec(a.className);e&&(d=e[1])}else if(c.type=="elem"){if(!a.getElementsByTagName)return;e=a.getElementsByTagName(c.name);e.length&&(d=b.trim(e[0].innerHTML))}else a.getAttribute!=void 0&&(e=a.getAttribute(c.name))&&(d=e);f=g(d.indexOf("{")<0?"{"+d+"}":d)}b.data(a,c.single,f);return f}}});b.fn.metadata=function(a){return b.metadata.get(this[0],a)}})(jQuery);

// table2CSV Plugin
jQuery.fn.table2CSV=function(c){function i(a){var b=a.join("");a.length>0&&b!=""&&(a=a.join(c.separator),f[f.length]=a)}function g(a){var b=RegExp(/["]/g),a=a.replace(b,"\u201c"),b=RegExp(/\<[^\<]+\>/g),a=a.replace(b,"");if(a=="")return"";return'"'+a+'"'}function j(a){var b=window.open("","csv","height=400,width=600");b.document.write("<html><head><title>CSV</title>");b.document.write("</head><body >");b.document.write('<textArea cols=70 rows=15 wrap="off" >');b.document.write(a);b.document.write("</textArea>");b.document.write("</body></html>");b.document.close();return!0}var c=jQuery.extend({separator:",",header:[],delivery:"popup"},c),f=[],d=c.header.length,e=[];if(d>0)for(var h=0;h<d;h++)e[e.length]=g(c.header[h]);else $(this).filter(":visible").find("th").each(function(){$(this).css("display")!="none"&&(e[e.length]=g($(this).html()))});i(e);$(this).find("tr").each(function(){var a=[];$(this).filter(":visible").find("td").each(function(){$(this).css("display")!="none"&&(a[a.length]=g($(this).html()))});i(a)});return c.delivery=="popup"?(d=f.join("\n"),j(d)):d=f.join("\n")};

// tablesorter Plugin (modified for filter)
// http://www.justinbritten.com/work/2008/08/tablesorter-filter-results-based-on-search-string/
(function($){$.extend({tablesorter:new function(){var k=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'.',debug:false};function benchmark(s,d){log(s+": "+(new Date().getTime()-d.getTime())+"ms")}this.benchmark=benchmark;function log(s){if(console!==undefined&&console.debug!==undefined){console.log(s)}else{alert(s)}}function buildParserCache(a,b){if(a.config.debug){var c=""}var d=a.tBodies[0].rows;if(a.tBodies[0].rows[0]){var e=[],cells=d[0].cells,l=cells.length;for(var i=0;i<l;i++){var p=false;if($.metadata&&($(b[i]).metadata()&&$(b[i]).metadata().sorter)){p=getParserById($(b[i]).metadata().sorter)}else if((a.config.headers[i]&&a.config.headers[i].sorter)){p=getParserById(a.config.headers[i].sorter)}if(!p){p=detectParserForColumn(a,cells[i])}if(a.config.debug){c+="column:"+i+" parser:"+p.id+"\n"}e.push(p)}}if(a.config.debug){log(c)}return e};function detectParserForColumn(a,b){var l=k.length;for(var i=1;i<l;i++){if(k[i].is($.trim(getElementText(a.config,b)),a,b)){return k[i]}}return k[0]}function getParserById(a){var l=k.length;for(var i=0;i<l;i++){if(k[i].id.toLowerCase()==a.toLowerCase()){return k[i]}}return false}function buildCache(a){if(a.config.debug){var b=new Date()}var d=(a.tBodies[0]&&a.tBodies[0].rows.length)||0,totalCells=(a.tBodies[0].rows[0]&&a.tBodies[0].rows[0].cells.length)||0,k=a.config.parsers,cache={row:[],normalized:[]};for(var i=0;i<d;++i){var c=a.tBodies[0].rows[i],cols=[];cache.row.push($(c));for(var j=0;j<totalCells;++j){cols.push(k[j].format(getElementText(a.config,c.cells[j]),a,c.cells[j]))}cols.push(i);cache.normalized.push(cols);cols=null};if(a.config.debug){benchmark("Built cache for "+d+" rows",b)}return cache};function getElementText(a,b){if(!b)return"";var t="";if(a.textExtraction=="simple"){if(b.childNodes[0]&&b.childNodes[0].hasChildNodes()){t=b.childNodes[0].innerHTML}else{t=b.innerHTML}}else{if(typeof(a.textExtraction)=="function"){t=a.textExtraction(b)}else{t=$(b).text()}}return t}function appendToTable(a,b){if(a.config.debug){var d=new Date()}var c=b,r=c.row,n=c.normalized,totalRows=n.length,tableBody=$(a.tBodies[0]),rows=[];if(totalRows>0){var e=(n[0].length-1);for(var i=0;i<totalRows;i++){rows.push(r[n[i][e]]);if(!a.config.appender){var o=r[n[i][e]];var l=o.length;for(var j=0;j<l;j++){tableBody[0].appendChild(o[j])}}}}if(a.config.appender){a.config.appender(a,rows)}rows=null;if(a.config.debug){benchmark("Rebuilt table",d)}applyWidget(a);setTimeout(function(){$(a).trigger("sortEnd")},0)};function buildHeaders(b){if(b.config.debug){var c=new Date()}var d=($.metadata)?true:false,tableHeadersRows=[];for(var i=0;i<b.tHead.rows.length;i++){tableHeadersRows[i]=0};$tableHeaders=$("thead th",b);$tableHeaders.each(function(a){this.count=0;this.column=a;this.order=formatSortingOrder(b.config.sortInitialOrder);if(checkHeaderMetadata(this)||checkHeaderOptions(b,a))this.sortDisabled=true;if(!this.sortDisabled){$(this).addClass(b.config.cssHeader)}b.config.headerList[a]=this});if(b.config.debug){benchmark("Built headers",c);log($tableHeaders)}return $tableHeaders};function checkCellColSpan(a,b,d){var e=[],r=a.tHead.rows,c=r[d].cells;for(var i=0;i<c.length;i++){var f=c[i];if(f.colSpan>1){e=e.concat(checkCellColSpan(a,headerArr,d++))}else{if(a.tHead.length==1||(f.rowSpan>1||!r[d+1])){e.push(f)}}}return e};function checkHeaderMetadata(a){if(($.metadata)&&($(a).metadata().sorter===false)){return true};return false}function checkHeaderOptions(a,i){if((a.config.headers[i])&&(a.config.headers[i].sorter===false)){return true};return false}function applyWidget(a){var c=a.config.widgets;var l=c.length;for(var i=0;i<l;i++){getWidgetById(c[i]).format(a)}}function getWidgetById(a){var l=widgets.length;for(var i=0;i<l;i++){if(widgets[i].id.toLowerCase()==a.toLowerCase()){return widgets[i]}}};function formatSortingOrder(v){if(typeof(v)!="Number"){i=(v.toLowerCase()=="desc")?1:0}else{i=(v==(0||1))?v:0}return i}function isValueInArray(v,a){var l=a.length;for(var i=0;i<l;i++){if(a[i][0]==v){return true}}return false}function setHeadersCss(b,c,d,e){c.removeClass(e[0]).removeClass(e[1]);var h=[];c.each(function(a){if(!this.sortDisabled){h[this.column]=$(this)}});var l=d.length;for(var i=0;i<l;i++){h[d[i][0]].addClass(e[d[i][1]])}}function fixColumnWidth(a,b){var c=a.config;if(c.widthFixed){var d=$('<colgroup>');$("tr:first td",a.tBodies[0]).each(function(){d.append($('<col>').css('width',$(this).width()))});$(a).prepend(d)}}function updateHeaderSortCount(a,b){var c=a.config,l=b.length;for(var i=0;i<l;i++){var s=b[i],o=c.headerList[s[0]];o.count=s[1];o.count++}}function multisort(a,b,d){if(a.config.debug){var f=new Date()}var g="var sortWrapper = function(a,b) {",l=b.length;for(var i=0;i<l;i++){var c=b[i][0];var h=b[i][1];var s=(getCachedSortType(a.config.parsers,c)=="text")?((h==0)?"sortText":"sortTextDesc"):((h==0)?"sortNumeric":"sortNumericDesc");var e="e"+i;g+="var "+e+" = "+s+"(a["+c+"],b["+c+"]); ";g+="if("+e+") { return "+e+"; } ";g+="else { "}var j=d.normalized[0].length-1;g+="return a["+j+"]-b["+j+"];";for(var i=0;i<l;i++){g+="}; "}g+="return 0; ";g+="}; ";eval(g);d.normalized.sort(sortWrapper);if(a.config.debug){benchmark("Sorted "+b.toString(),f)}return d};function sortText(a,b){return((a<b)?-1:((a>b)?1:0))};function sortTextDesc(a,b){return((b<a)?-1:((b>a)?1:0))};function sortNumeric(a,b){return a-b};function sortNumericDesc(a,b){return b-a};function getCachedSortType(a,i){return a[i].type};this.construct=function(g){return this.each(function(){if(!this.tHead||!this.tBodies)return;var d,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,g);d=$(this);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);this.config.cache=cache;var f=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){d.trigger("sortStart");var b=(d[0].tBodies[0]&&d[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&b>0){var c=$(this);var i=this.column;this.order=this.count++%2;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j<a.length;j++){if(a[j][0]!=i){config.sortList.push(a[j])}}}config.sortList.push([i,this.order])}else{if(isValueInArray(i,config.sortList)){for(var j=0;j<config.sortList.length;j++){var s=config.sortList[j],o=config.headerList[s[0]];if(s[0]==i){o.count=s[1];o.count++;s[1]=o.count%2}}}else{config.sortList.push([i,this.order])}};setTimeout(function(){setHeadersCss(d[0],$headers,config.sortList,f);appendToTable(d[0],multisort(d[0],config.sortList,cache))},1);return false}}).mousedown(function(){if(config.cancelSelection){this.onselectstart=function(){return false};return false}});d.bind("update",function(){this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this)}).bind("sorton",function(e,a){$(this).trigger("sortStart");config.sortList=a;var b=config.sortList;updateHeaderSortCount(this,b);setHeadersCss(this,$headers,b,f);appendToTable(this,multisort(this,b,cache))}).bind("appendCache",function(){appendToTable(this,cache)}).bind("applyWidgetId",function(e,a){getWidgetById(a).format(this)}).bind("applyWidgets",function(){applyWidget(this)});if($.metadata&&($(this).metadata()&&$(this).metadata().sortlist)){config.sortList=$(this).metadata().sortlist}if(config.sortList.length>0){d.trigger("sorton",[config.sortList])}applyWidget(this)})};this.addParser=function(b){var l=k.length,a=true;for(var i=0;i<l;i++){if(k[i].id.toLowerCase()==b.id.toLowerCase()){a=false}}if(a){k.push(b)}};this.addWidget=function(a){widgets.push(a)};this.formatFloat=function(s){var i=parseFloat(s);return(isNaN(i))?0:i};this.formatInt=function(s){var i=parseInt(s);return(isNaN(i))?0:i};this.isDigit=function(s,a){var b='\\'+a.decimal;var c='/(^[+]?0('+b+'0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)'+b+'(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*'+b+'0+$)/';return RegExp(c).test($.trim(s))};this.clearTableBody=function(a){if($.browser.msie){function empty(){while(this.firstChild)this.removeChild(this.firstChild)}empty.apply(a.tBodies[0])}else{a.tBodies[0].innerHTML=""}}}});$.fn.extend({tablesorter:$.tablesorter.construct});var m=$.tablesorter;m.addParser({id:"text",is:function(s){return true},format:function(s){return $.trim(s.toLowerCase())},type:"text"});m.addParser({id:"digit",is:function(s,a){var c=a.config;return $.tablesorter.isDigit(s,c)},format:function(s){return $.tablesorter.formatFloat(s)},type:"numeric"});m.addParser({id:"currency",is:function(s){return/^[£$€?.]/.test(s)},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g),""))},type:"numeric"});m.addParser({id:"ipAddress",is:function(s){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s)},format:function(s){var a=s.split("."),r="",l=a.length;for(var i=0;i<l;i++){var b=a[i];if(b.length==2){r+="0"+b}else{r+=b}}return $.tablesorter.formatFloat(r)},type:"numeric"});m.addParser({id:"url",is:function(s){return/^(https?|ftp|file):\/\/$/.test(s)},format:function(s){return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//),''))},type:"text"});m.addParser({id:"isoDate",is:function(s){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s)},format:function(s){return $.tablesorter.formatFloat((s!="")?new Date(s.replace(new RegExp(/-/g),"/")).getTime():"0")},type:"numeric"});m.addParser({id:"percent",is:function(s){return/\%$/.test($.trim(s))},format:function(s){return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g),""))},type:"numeric"});m.addParser({id:"usLongDate",is:function(s){return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/))},format:function(s){return $.tablesorter.formatFloat(new Date(s).getTime())},type:"numeric"});m.addParser({id:"shortDate",is:function(s){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);},format:function(s,table){var c=table.config;s=s.replace(/\-/g,"/");if(c.dateFormat=="us"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2")}else if(c.dateFormat=="uk"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1")}else if(c.dateFormat=="dd/mm/yy"||c.dateFormat=="dd-mm-yy"){s=s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3")}return $.tablesorter.formatFloat(new Date(s).getTime())},type:"numeric"});m.addParser({id:"time",is:function(s){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s)},format:function(s){return $.tablesorter.formatFloat(new Date("2000/01/01 "+s).getTime())},type:"numeric"});m.addParser({id:"metadata",is:function(s){return false},format:function(s,a,b){var c=a.config,p=(!c.parserMetadataName)?'sortValue':c.parserMetadataName;return $(b).metadata()[p]},type:"numeric"});m.addWidget({id:"zebra",format:function(a){if(a.config.debug){var b=new Date()}$("tr:visible",a.tBodies[0]).filter(':even').removeClass(a.config.widgetZebra.css[1]).addClass(a.config.widgetZebra.css[0]).end().filter(':odd').removeClass(a.config.widgetZebra.css[0]).addClass(a.config.widgetZebra.css[1]);if(a.config.debug){$.tablesorter.benchmark("Applied Zebra widget",b)}}})})(jQuery);

//Tablesorter pager
(function(d){d.extend({tablesorterPager:new function(){function k(a){var b=a.config;if(!b.pagerPositionSet&&b.positionFixed)b=a.config,a=d(a),a.offset&&b.container.css({top:a.offset().top+a.height()+"px",position:""}),b.pagerPositionSet=!0}function l(a){var b=a.config;b.page=b.totalPages-1;e(a)}function e(a){var b=a.config;if(b.page<0||b.page>b.totalPages-1)b.page=0;f(a,b.rowsCopy)}function f(a,b){var c=a.config,g=b.length,g=c.page*c.size,h=g+c.size;if(h>b.length)h=b.length;var e=d(a.tBodies[0]);
d.tablesorter.clearTableBody(a);for(var i=g;i<h;i++){for(var f=b[i],g=f.length,j=0;j<g;j++)e[0].appendChild(f[j]);d(".button").button()}k(a,e);d(a).trigger("applyWidgets");c.page>=c.totalPages&&l(a);d(c.cssPageDisplay,c.container).val(c.page+1+c.seperator+c.totalPages)}this.appender=function(a,b){var c=a.config;c.rowsCopy=b;c.totalRows=b.length;c.totalPages=Math.ceil(c.totalRows/c.size);f(a,b)};this.defaults={size:10,offset:0,page:0,totalRows:0,totalPages:0,container:null,cssNext:".next",cssPrev:".prev",
cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",seperator:"/",positionFixed:!0,appender:this.appender};this.construct=function(a){return this.each(function(){config=d.extend(this.config,d.tablesorterPager.defaults,a);var b=this,c=config.container;d(this).trigger("appendCache");config.size=parseInt(d(".pagesize",c).val());d(config.cssFirst,c).click(function(){b.config.page=0;e(b);return!1});d(config.cssNext,c).click(function(){var a=b.config;a.page++;if(a.page>=
a.totalPages-1)a.page=a.totalPages-1;e(b);return!1});d(config.cssPrev,c).click(function(){var a=b.config;a.page--;if(a.page<=0)a.page=0;e(b);return!1});d(config.cssLast,c).click(function(){l(b);return!1});d(config.cssPageSize,c).change(function(){var a=parseInt(d(this).val()),c=b.config;c.size=a;c.totalPages=Math.ceil(c.totalRows/c.size);c.pagerPositionSet=!1;e(b);k(b);return!1})})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery);

// Tablesorter filter
(function(c){c.extend({tablesorterFilter:new function(){function m(b){if(b.config.debug)var h=new Date;for(var a=[],e=[],f=0;f<b.config.filter.length;f++){var d=b.config.filter[f],i=c(d.filterContainer);e[f]=d.filterColumns;i=jQuery.trim(i.val()).replace(/\s+/g," ");if(i.length!=0){var j=/^([a-z]+):(.+)/.exec(i);if(j!==null)for(var l=j[1],i=j[2],j=0;j<d.columns.length;j++)if(d.columns[j].indexOf(l)===0){d.filterColumns=[j];break}l=d.filterCaseSensitive;a.push({caseSensitive:l,words:l?i.split(" "):i.toLowerCase().split(" "),findStr:d.filterColumns?"td:eq("+d.filterColumns.join("),td:eq(")+")":"",filterFunction:d.filterFunction})}d.filterColumns=e[f]}for(var k=a.length,e=k==0?function(){var a=jQuery(this);g[g.length]=a}:function(){for(var c=jQuery(this),b=0;b<k;b++)if(!a[b].filterFunction((a[b].findStr?c.find(a[b].findStr):c).text(),a[b].words,a[b].caseSensitive))return!0;g[g.length]=c},d=b.config.cache.row,g=[],i=d.length,f=0;f<i;f++)d[f].each(e);c.tablesorter.clearTableBody(b);e=g.length;for(f=0;f<e;f++)c(b.tBodies[0]).append(g[f]);c(b).trigger("update");g.length&&(c(b).trigger("appendCache"),c(b).trigger("sorton",[b.config.sortList]));b.config.debug&&c.tablesorter.benchmark("Apply filter:",h);c(b).trigger("filterEnd");return b}this.defaults={filterContainer:"#filter-box",filterClearContainer:"#filter-clear-button",filterColumns:null,filterCaseSensitive:!1,filterWaitTime:500,filterFunction:function(b,c,a){b=a?b:b.toLowerCase();for(a=0;a<c.length;a++)if(c[a].charAt(0)=="-"){if(b.indexOf(c[a].substr(1))!=-1)return!1}else if(b.indexOf(c[a])==-1)return!1;return!0},columns:[]};this.construct=function(){var b=arguments;return this.each(function(){this.config.filter=Array(b.length);var h=this.config;h.filter=Array(b.length);for(var a=0;a<b.length;a++)h.filter[a]=c.extend(this.config.filter[a],c.tablesorterFilter.defaults,b[a]);for(var e=this,f=Array(b.length),a=0;a<b.length;a++){var d=c(h.filter[a].filterContainer);if(d.length)d[0].filterIndex=a;d.keyup(function(b,a){var d=this.filterIndex;void 0!==a&&c(this).val(a);var k=this;if(k.keyCode==13||void 0!==a)var g=1,n=!0;else g=h.filter[d].filterWaitTime||500,n=!1;clearTimeout(f[d]);f[d]=setTimeout(function(){var c=k.value;if(c!=k.lastValue||n)k.lastValue=c,m(e)},g);return!1});if(h.filter[a].filterClearContainer&&(d=c(h.filter[a].filterClearContainer),d.length))d[0].filterIndex=a,d.click(function(){var b=c(h.filter[this.filterIndex].filterContainer);b.val("");b[0].lastValue="";m(e);b[0].type!="hidden"&&b.focus()})}c(e).bind("doFilter",function(){m(e)});c(e).bind("clearFilter",function(){if(e.config.debug)var b=new Date;for(var a=0;a<e.config.filter.length;a++)c(e.config.filter[a].filterContainer).val("").get(0).lastValue="";var d=e.config.cache.row;c.tablesorter.clearTableBody(e);for(a=0;a<d.length;a++)c(e.tBodies[0]).append(d[a]);c(e).trigger("update");c(e).trigger("appendCache");c(e).trigger("sorton",[e.config.sortList]);e.config.debug&&c.tablesorter.benchmark("Clear filter:",b);c(e).trigger("filterCleared")})})}}});c.fn.extend({tablesorterFilter:c.tablesorterFilter.construct})})(jQuery);

//In place field editing
(function($){$.fn.editable=function(target,options){if('disable'==target){$(this).data('disabled.editable',true);return;}
if('enable'==target){$(this).data('disabled.editable',false);return;}
if('destroy'==target){$(this).unbind($(this).data('event.editable')).removeData('disabled.editable').removeData('event.editable');return;}
var settings=$.extend({},$.fn.editable.defaults,{target:target},options);var plugin=$.editable.types[settings.type].plugin||function(){};var submit=$.editable.types[settings.type].submit||function(){};var buttons=$.editable.types[settings.type].buttons||$.editable.types['defaults'].buttons;var content=$.editable.types[settings.type].content||$.editable.types['defaults'].content;var element=$.editable.types[settings.type].element||$.editable.types['defaults'].element;var reset=$.editable.types[settings.type].reset||$.editable.types['defaults'].reset;var callback=settings.callback||function(){};var onedit=settings.onedit||function(){};var onsubmit=settings.onsubmit||function(){};var onreset=settings.onreset||function(){};var onerror=settings.onerror||reset;if(settings.tooltip){$(this).attr('title',settings.tooltip);}
settings.autowidth='auto'==settings.width;settings.autoheight='auto'==settings.height;return this.each(function(){var self=this;var savedwidth=$(self).width();var savedheight=$(self).height();$(this).data('event.editable',settings.event);if(!$.trim($(this).html())){$(this).html(settings.placeholder);}
$(this).bind(settings.event,function(e){if(true===$(this).data('disabled.editable')){return;}
if(self.editing){return;}
if(false===onedit.apply(this,[settings,self])){return;}
e.preventDefault();e.stopPropagation();if(settings.tooltip){$(self).removeAttr('title');}
if(0==$(self).width()){settings.width=savedwidth;settings.height=savedheight;}else{if(settings.width!='none'){settings.width=settings.autowidth?$(self).width():settings.width;}
if(settings.height!='none'){settings.height=settings.autoheight?$(self).height():settings.height;}}
if($(this).html().toLowerCase().replace(/(;|")/g,'')==settings.placeholder.toLowerCase().replace(/(;|")/g,'')){$(this).html('');}
self.editing=true;self.revert=$(self).html();$(self).html('');var form=$('<form />');if(settings.cssclass){if('inherit'==settings.cssclass){form.attr('class',$(self).attr('class'));}else{form.attr('class',settings.cssclass);}}
if(settings.style){if('inherit'==settings.style){form.attr('style',$(self).attr('style'));form.css('display',$(self).css('display'));}else{form.attr('style',settings.style);}}
var input=element.apply(form,[settings,self]);var input_content;if(settings.loadurl){var t=setTimeout(function(){input.disabled=true;content.apply(form,[settings.loadtext,settings,self]);},100);var loaddata={};loaddata[settings.id]=self.id;if($.isFunction(settings.loaddata)){$.extend(loaddata,settings.loaddata.apply(self,[self.revert,settings]));}else{$.extend(loaddata,settings.loaddata);}
$.ajax({type:settings.loadtype,url:settings.loadurl,data:loaddata,async:false,success:function(result){window.clearTimeout(t);input_content=result;input.disabled=false;}});}else if(settings.data){input_content=settings.data;if($.isFunction(settings.data)){input_content=settings.data.apply(self,[self.revert,settings]);}}else{input_content=self.revert;}
content.apply(form,[input_content,settings,self]);input.attr('name',settings.name);buttons.apply(form,[settings,self]);$(self).append(form);plugin.apply(form,[settings,self]);$(':input:visible:enabled:first',form).focus();if(settings.select){input.select();}
input.keydown(function(e){if(e.keyCode==27){e.preventDefault();reset.apply(form,[settings,self]);}});var t;if('cancel'==settings.onblur){input.blur(function(e){t=setTimeout(function(){reset.apply(form,[settings,self]);},500);});}else if('submit'==settings.onblur){input.blur(function(e){t=setTimeout(function(){form.submit();},200);});}else if($.isFunction(settings.onblur)){input.blur(function(e){settings.onblur.apply(self,[input.val(),settings]);});}else{input.blur(function(e){});}
form.submit(function(e){if(t){clearTimeout(t);}
e.preventDefault();if(false!==onsubmit.apply(form,[settings,self])){if(false!==submit.apply(form,[settings,self])){if($.isFunction(settings.target)){var str=settings.target.apply(self,[input.val(),settings]);$(self).html(str);self.editing=false;callback.apply(self,[self.innerHTML,settings]);if(!$.trim($(self).html())){$(self).html(settings.placeholder);}}else{var submitdata={};submitdata[settings.name]=input.val();submitdata[settings.id]=self.id;if($.isFunction(settings.submitdata)){$.extend(submitdata,settings.submitdata.apply(self,[self.revert,settings]));}else{$.extend(submitdata,settings.submitdata);}
if('PUT'==settings.method){submitdata['_method']='put';}
$(self).html(settings.indicator);var ajaxoptions={type:'POST',data:submitdata,dataType:'html',url:settings.target,success:function(result,status){if(ajaxoptions.dataType=='html'){$(self).html(result);}
self.editing=false;callback.apply(self,[result,settings]);if(!$.trim($(self).html())){$(self).html(settings.placeholder);}},error:function(xhr,status,error){onerror.apply(form,[settings,self,xhr]);}};$.extend(ajaxoptions,settings.ajaxoptions);$.ajax(ajaxoptions);}}}
$(self).attr('title',settings.tooltip);return false;});});this.reset=function(form){if(this.editing){if(false!==onreset.apply(form,[settings,self])){$(self).html(self.revert);self.editing=false;if(!$.trim($(self).html())){$(self).html(settings.placeholder);}
if(settings.tooltip){$(self).attr('title',settings.tooltip);}}}};});};$.editable={types:{defaults:{element:function(settings,original){var input=$('<input type="hidden"></input>');$(this).append(input);return(input);},content:function(string,settings,original){$(':input:first',this).val(string);},reset:function(settings,original){original.reset(this);},buttons:function(settings,original){var form=this;if(settings.submit){if(settings.submit.match(/>$/)){var submit=$(settings.submit).click(function(){if(submit.attr("type")!="submit"){form.submit();}});}else{var submit=$('<button type="submit" />');submit.html(settings.submit);}
$(this).append(submit);}
if(settings.cancel){if(settings.cancel.match(/>$/)){var cancel=$(settings.cancel);}else{var cancel=$('<button type="cancel" />');cancel.html(settings.cancel);}
$(this).append(cancel);$(cancel).click(function(event){if($.isFunction($.editable.types[settings.type].reset)){var reset=$.editable.types[settings.type].reset;}else{var reset=$.editable.types['defaults'].reset;}
reset.apply(form,[settings,original]);return false;});}}},text:{element:function(settings,original){var input=$('<input />');if(settings.width!='none'){input.width(settings.width);}
if(settings.height!='none'){input.height(settings.height);}
input.attr('autocomplete','off');$(this).append(input);return(input);}},textarea:{element:function(settings,original){var textarea=$('<textarea />');if(settings.rows){textarea.attr('rows',settings.rows);}else if(settings.height!="none"){textarea.height(settings.height);}
if(settings.cols){textarea.attr('cols',settings.cols);}else if(settings.width!="none"){textarea.width(settings.width);}
$(this).append(textarea);return(textarea);}},select:{element:function(settings,original){var select=$('<select />');$(this).append(select);return(select);},content:function(data,settings,original){if(String==data.constructor){eval('var json = '+data);}else{var json=data;}
for(var key in json){if(!json.hasOwnProperty(key)){continue;}
if('selected'==key){continue;}
var option=$('<option />').val(key).append(json[key]);$('select',this).append(option);}
$('select',this).children().each(function(){if($(this).val()==json['selected']||$(this).text()==$.trim(original.revert)){$(this).attr('selected','selected');}});}}},addInputType:function(name,input){$.editable.types[name]=input;}};$.fn.editable.defaults={name:'value',id:'id',type:'text',width:'auto',height:'auto',event:'click.editable',onblur:'cancel',loadtype:'GET',loadtext:'Loading...',placeholder:'Click to edit',loaddata:{},submitdata:{},ajaxoptions:{}};})(jQuery);

/*
 * jQuery MultiSelect UI Widget 1.12pre
 * Copyright (c) 2011 Eric Hynds
 *
 * http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
 *
 * Depends:
 *   - jQuery 1.4.2+
 *   - jQuery UI 1.8 widget factory
 *
 * Optional:
 *   - jQuery UI effects
 *   - jQuery UI position utility
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */
(function(d){var i=0;d.widget("ech.multiselect",{options:{header:!0,height:175,minWidth:225,classes:"",checkAllText:"Check all",uncheckAllText:"Uncheck all",noneSelectedText:"Select options",selectedText:"# selected",selectedList:0,show:"",hide:"",autoOpen:!1,multiple:!0,position:{}},_create:function(){var a=this.element.hide(),b=this.options;this.speed=d.fx.speeds._default;this._isOpen=!1;a=(this.button=d('<button type="button"><span class="ui-icon ui-icon-triangle-2-n-s"></span></button>')).addClass("ui-multiselect ui-widget ui-state-default ui-corner-all").addClass(b.classes).attr({title:a.attr("title"), "aria-haspopup":!0,tabIndex:a.attr("tabIndex")}).insertAfter(a);(this.buttonlabel=d("<span />")).html(b.noneSelectedText).appendTo(a);var a=(this.menu=d("<div />")).addClass("ui-multiselect-menu ui-widget ui-widget-content ui-corner-all").addClass(b.classes).insertAfter(a),c=(this.header=d("<div />")).addClass("ui-widget-header ui-corner-all ui-multiselect-header ui-helper-clearfix").appendTo(a);(this.headerLinkContainer=d("<ul />")).addClass("ui-helper-reset").html(function(){return b.header===!0?  '<li><a class="ui-multiselect-all" href="#"><span class="ui-icon ui-icon-check"></span><span>'+b.checkAllText+'</span></a></li><li><a class="ui-multiselect-none" href="#"><span class="ui-icon ui-icon-closethick"></span><span>'+b.uncheckAllText+"</span></a></li>":typeof b.header==="string"?"<li>"+b.header+"</li>":""}).append('<li class="ui-multiselect-close"><a href="#" class="ui-multiselect-close"><span class="ui-icon ui-icon-circle-close"></span></a></li>').appendTo(c);(this.checkboxContainer=d("<ul />")).addClass("ui-multiselect-checkboxes ui-helper-reset").appendTo(a); this._bindEvents();this.refresh(!0);b.multiple||a.addClass("ui-multiselect-single")},_init:function(){this.options.header===!1&&this.header.hide();this.options.multiple||this.headerLinkContainer.find(".ui-multiselect-all, .ui-multiselect-none").hide();this.options.autoOpen&&this.open();this.element.is(":disabled")&&this.disable()},refresh:function(a){var b=this.options,c=this.menu,e=this.checkboxContainer,h=[],f=[],g=this.element.attr("id")||i++;this.element.find("option").each(function(a){d(this); var e=this.parentNode,c=this.innerHTML,i=this.title,m=this.value,a=this.id||"ui-multiselect-"+g+"-option-"+a,j=this.disabled,l=this.selected,k=["ui-corner-all"];e.tagName.toLowerCase()==="optgroup"&&(e=e.getAttribute("label"),d.inArray(e,h)===-1&&(f.push('<li class="ui-multiselect-optgroup-label"><a href="#">'+e+"</a></li>"),h.push(e)));j&&k.push("ui-state-disabled");l&&!b.multiple&&k.push("ui-state-active");f.push('<li class="'+(j?"ui-multiselect-disabled":"")+'">');f.push('<label for="'+a+'" title="'+ i+'" class="'+k.join(" ")+'">');f.push('<input id="'+a+'" name="multiselect_'+g+'" type="'+(b.multiple?"checkbox":"radio")+'" value="'+m+'" title="'+c+'"');l&&(f.push(' checked="checked"'),f.push(' aria-selected="true"'));j&&(f.push(' disabled="disabled"'),f.push(' aria-disabled="true"'));f.push(" /><span>"+c+"</span></label></li>")});e.html(f.join(""));this.labels=c.find("label");this._setButtonWidth();this._setMenuWidth();this.button[0].defaultValue=this.update();a||this._trigger("refresh")},update:function(){var a= this.options,b=this.labels.find("input"),c=b.filter(":checked"),e=c.length,a=e===0?a.noneSelectedText:d.isFunction(a.selectedText)?a.selectedText.call(this,e,b.length,c.get()):/\d/.test(a.selectedList)&&a.selectedList>0&&e<=a.selectedList?c.map(function(){return this.title}).get().join(", "):a.selectedText.replace("#",e).replace("#",b.length);this.buttonlabel.html(a);return a},_bindEvents:function(){function a(){b[b._isOpen?"close":"open"]();return!1}var b=this,c=this.button;c.find("span").bind("click.multiselect", a);c.bind({click:a,keypress:function(a){switch(a.which){case 27:case 38:case 37:b.close();break;case 39:case 40:b.open()}},mouseenter:function(){c.hasClass("ui-state-disabled")||d(this).addClass("ui-state-hover")},mouseleave:function(){d(this).removeClass("ui-state-hover")},focus:function(){c.hasClass("ui-state-disabled")||d(this).addClass("ui-state-focus")},blur:function(){d(this).removeClass("ui-state-focus")}});this.header.delegate("a","click.multiselect",function(a){if(d(this).hasClass("ui-multiselect-close"))b.close(); else b[d(this).hasClass("ui-multiselect-all")?"checkAll":"uncheckAll"]();a.preventDefault()});this.menu.delegate("li.ui-multiselect-optgroup-label a","click.multiselect",function(a){a.preventDefault();var c=d(this),f=c.parent().nextUntil("li.ui-multiselect-optgroup-label").find("input:visible:not(:disabled)"),g=f.get(),c=c.parent().text();b._trigger("beforeoptgrouptoggle",a,{inputs:g,label:c})!==!1&&(b._toggleChecked(f.filter(":checked").length!==f.length,f),b._trigger("optgrouptoggle",a,{inputs:g, label:c,checked:g[0].checked}))}).delegate("label","mouseenter.multiselect",function(){d(this).hasClass("ui-state-disabled")||(b.labels.removeClass("ui-state-hover"),d(this).addClass("ui-state-hover").find("input").focus())}).delegate("label","keydown.multiselect",function(a){a.preventDefault();switch(a.which){case 9:case 27:b.close();break;case 38:case 40:case 37:case 39:b._traverse(a.which,this);break;case 13:d(this).find("input")[0].click()}}).delegate('input[type="checkbox"], input[type="radio"]', "click.multiselect",function(a){var c=d(this),f=this.value,g=this.checked,i=b.element.find("option");this.disabled||b._trigger("click",a,{value:f,text:this.title,checked:g})===!1?a.preventDefault():(c.attr("aria-selected",g),i.each(function(){if(this.value===f)(this.selected=g)?this.setAttribute("selected","selected"):this.removeAttribute("selected");else if(!b.options.multiple)this.selected=!1}),b.options.multiple||(b.labels.removeClass("ui-state-active"),c.closest("label").toggleClass("ui-state-active", g),b.close()),b.element.trigger("change"),setTimeout(d.proxy(b.update,b),10))});d(document).bind("mousedown.multiselect",function(a){b._isOpen&&!d.contains(b.menu[0],a.target)&&!d.contains(b.button[0],a.target)&&a.target!==b.button[0]&&b.close()});d(this.element[0].form).bind("reset.multiselect",function(){setTimeout(function(){b.update()},10)})},_setButtonWidth:function(){var a=this.element.outerWidth(),b=this.options;if(/\d/.test(b.minWidth)&&a<b.minWidth)a=b.minWidth;this.button.width(a)},_setMenuWidth:function(){var a= this.menu,b=this.button.outerWidth()-parseInt(a.css("padding-left"),10)-parseInt(a.css("padding-right"),10)-parseInt(a.css("border-right-width"),10)-parseInt(a.css("border-left-width"),10);a.width(b||this.button.outerWidth())},_traverse:function(a,b){var c=d(b),e=a===38||a===37,c=c.parent()[e?"prevAll":"nextAll"]("li:not(.ui-multiselect-disabled, .ui-multiselect-optgroup-label)")[e?"last":"first"]();c.length?c.find("label").trigger("mouseover"):(c=this.menu.find("ul:last"),this.menu.find("label")[e?  "last":"first"]().trigger("mouseover"),c.scrollTop(e?c.height():0))},_toggleCheckbox:function(a,b){return function(){!this.disabled&&(this[a]=b);b?this.setAttribute("aria-selected",!0):this.removeAttribute("aria-selected")}},_toggleChecked:function(a,b){var c=b&&b.length?b:this.labels.find("input"),e=this;c.each(this._toggleCheckbox("checked",a));this.update();var h=c.map(function(){return this.value}).get();this.element.find("option").each(function(){!this.disabled&&d.inArray(this.value,h)>-1&&e._toggleCheckbox("selected", a).call(this)});c.length&&this.element.trigger("change")},_toggleDisabled:function(a){this.button.attr({disabled:a,"aria-disabled":a})[a?"addClass":"removeClass"]("ui-state-disabled");this.menu.find("input").attr({disabled:a,"aria-disabled":a}).parent()[a?"addClass":"removeClass"]("ui-state-disabled");this.element.attr({disabled:a,"aria-disabled":a})},open:function(){var a=this.button,b=this.menu,c=this.speed,e=this.options;if(!(this._trigger("beforeopen")===!1||a.hasClass("ui-state-disabled")||this._isOpen)){var h= b.find("ul:last"),f=e.show,g=a.position();d.isArray(e.show)&&(f=e.show[0],c=e.show[1]||this.speed);h.scrollTop(0).height(e.height);d.ui.position&&!d.isEmptyObject(e.position)?(e.position.of=e.position.of||a,b.show().position(e.position).hide().show(f,c)):b.css({top:g.top+a.outerHeight(),left:g.left}).show(f,c);this.labels.eq(0).trigger("mouseover").trigger("mouseenter").find("input").trigger("focus");a.addClass("ui-state-active");this._isOpen=!0;this._trigger("open")}},close:function(){if(this._trigger("beforeclose")!== !1){var a=this.options,b=a.hide,c=this.speed;d.isArray(a.hide)&&(b=a.hide[0],c=a.hide[1]||this.speed);this.menu.hide(b,c);this.button.removeClass("ui-state-active").trigger("blur").trigger("mouseleave");this._isOpen=!1;this._trigger("close")}},enable:function(){this._toggleDisabled(!1)},disable:function(){this._toggleDisabled(!0)},checkAll:function(){this._toggleChecked(!0);this._trigger("checkAll")},uncheckAll:function(){this._toggleChecked(!1);this._trigger("uncheckAll")},getChecked:function(){return this.menu.find("input").filter(":checked")}, destroy:function(){d.Widget.prototype.destroy.call(this);this.button.remove();this.menu.remove();this.element.show();return this},isOpen:function(){return this._isOpen},widget:function(){return this.menu},_setOption:function(a,b){var c=this.menu;switch(a){case "header":c.find("div.ui-multiselect-header")[b?"show":"hide"]();break;case "checkAllText":c.find("a.ui-multiselect-all span").eq(-1).text(b);break;case "uncheckAllText":c.find("a.ui-multiselect-none span").eq(-1).text(b);break;case "height":c.find("ul:last").height(parseInt(b, 10));break;case "minWidth":this.options[a]=parseInt(b,10);this._setButtonWidth();this._setMenuWidth();break;case "selectedText":case "selectedList":case "noneSelectedText":this.options[a]=b;this.update();break;case "classes":c.add(this.button).removeClass(this.options.classes).addClass(b)}d.Widget.prototype._setOption.apply(this,arguments)}})})(jQuery); 

/*
 * jQuery MultiSelect UI Widget Filtering Plugin 1.3
 * Copyright (c) 2011 Eric Hynds
 *
 * http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
 *
 * Depends:
 *   - jQuery UI MultiSelect widget
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
*/
(function(c){var f=/[\-\[\]{}()*+?.,\\^$|#\s]/g;c.widget("ech.multiselectfilter",{options:{label:"Filter:",width:null,placeholder:"Enter keywords"},_create:function(){var e;var a=this,b=this.options,d=this.instance=c(this.element).data("multiselect");this.header=d.menu.find(".ui-multiselect-header").addClass("ui-multiselect-hasfilter");e=this.wrapper=c('<div class="ui-multiselect-filter">'+(b.label.length?b.label:"")+'<input placeholder="'+b.placeholder+'" type="search"'+(/\d/.test(b.width)?'style="width:'+ b.width+'px"':"")+" /></div>").prependTo(this.header),b=e;this.inputs=d.menu.find('input[type="checkbox"], input[type="radio"]');this.input=b.find("input").bind({keydown:function(a){a.which===13&&a.preventDefault()},keyup:c.proxy(a._handler,a),click:c.proxy(a._handler,a)});this.updateCache();d._toggleChecked=function(b,d){var e=d&&d.length?d:this.labels.find("input"),i=this,e=e.not(a.instance._isOpen?":disabled, :hidden":":disabled").each(this._toggleCheckbox("checked",b));this.update();var j=e.map(function(){return this.value}).get(); this.element.find("option").filter(function(){!this.disabled&&c.inArray(this.value,j)>-1&&i._toggleCheckbox("selected",b).call(this)})};c(document).bind("multiselectrefresh",function(){a.updateCache();a._handler()})},_handler:function(a){var b=c.trim(this.input[0].value.toLowerCase()),d=this.rows,g=this.inputs,h=this.cache;if(b){d.hide();var e=RegExp(b.replace(f,"\\$&"),"gi");this._trigger("filter",a,c.map(h,function(a,b){return a.search(e)!==-1?(d.eq(b).show(),g.get(b)):null}))}else d.show();this.instance.menu.find(".ui-multiselect-optgroup-label").each(function(){var a= c(this);a[a.nextUntil(".ui-multiselect-optgroup-label").filter(":visible").length?"show":"hide"]()})},updateCache:function(){this.rows=this.instance.menu.find(".ui-multiselect-checkboxes li:not(.ui-multiselect-optgroup-label)");this.cache=this.element.children().map(function(){var a=c(this);this.tagName.toLowerCase()==="optgroup"&&(a=a.children());return a.map(function(){return this.innerHTML.toLowerCase()}).get()}).get()},widget:function(){return this.wrapper},destroy:function(){c.Widget.prototype.destroy.call(this); this.input.val("").trigger("keyup");this.wrapper.remove()}})})(jQuery);

// qTip2 - Pretty powerful tooltips
// http://craigsworks.com/projects/qtip2/
"use strict",function(a,b,c){function A(b){var c=this,d=b.elements,e=d.tooltip,f=".bgiframe-"+b.id;a.extend(c,{init:function(){d.bgiframe=a('<iframe class="ui-tooltip-bgiframe" frameborder="0" tabindex="-1" src="javascript:\'\';"  style="display:block; position:absolute; z-index:-1; filter:alpha(opacity=0); -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";"></iframe>'),d.bgiframe.appendTo(e),e.bind("tooltipmove"+f,c.adjust)},adjust:function(){var a=b.get("dimensions"),c=b.plugins.tip,f=d.tip,g,h;h=parseInt(e.css("border-left-width"),10)||0,h={left:-h,top:-h},c&&f&&(g=c.corner.precedance==="x"?["width","left"]:["height","top"],h[g[1]]-=f[g[0]]()),d.bgiframe.css(h).css(a)},destroy:function(){d.bgiframe.remove(),e.unbind(f)}}),c.init()}function z(c){var f=this,g=c.options.show.modal,h=c.elements,i=h.tooltip,j="#qtip-overlay",k=".qtipmodal",l=k+c.id,m="is-modal-qtip",o;c.checks.modal={"^show.modal.(on|blur)$":function(){f.init(),h.overlay.toggle(i.is(":visible"))}},a.extend(f,{init:function(){if(!g.on)return f;o=f.create(),i.attr(m,d).unbind(k).unbind(l).bind("tooltipshow"+k+" tooltiphide"+k,function(a,b,c){f[a.type.replace("tooltip","")](a,c)}).bind("tooltipfocus"+k,function(a,b,c){o[0].style.zIndex=c-1}).bind("tooltipblur"+k,function(b){a("["+m+"]:visible").not(i).last().qtip("focus",b)}),g.escape&&a(b).unbind(l).bind("keydown"+l,function(a){a.keyCode===27&&i.hasClass(n)&&c.hide(a)}),g.blur&&h.overlay.unbind(l).bind("click"+l,function(a){i.hasClass(n)&&c.hide(a)});return f},create:function(){var c=a(j);if(c.length){h.overlay=c;return c}o=h.overlay=a("<div />",{id:j.substr(1),css:{position:"absolute",top:0,left:0,display:"none"},mousedown:function(){return e}}).appendTo(document.body),a(b).unbind(k).bind("resize"+k,function(){o.css({height:Math.max(a(b).height(),a(document).height()),width:Math.max(a(b).width(),a(document).width())})}).trigger("resize");return o},toggle:function(b,c,j){if(b&&b.isDefaultPrevented())return f;var k=g.effect,l=c?"show":"hide",n=a("["+m+"]:visible").not(i),p;o||(o=f.create());if(o.is(":animated")&&!c||!c&&n.length)return f;c&&h.overlay.css("cursor",g.blur?"pointer":""),o.stop(d,e),a.isFunction(k)?k.call(o,c):k===e?o[l]():o.fadeTo(parseInt(j,10)||90,c?.7:0,function(){c||a(this).hide()});return f},show:function(a,b){return f.toggle(a,d,b)},hide:function(a,b){return f.toggle(a,e,b)},destroy:function(){var d=o;d&&(d=a("["+m+"]").not(i).length<1,d?(h.overlay.remove(),a(b).unbind(k)):h.overlay.unbind(k+c.id));return i.removeAttr(m).unbind(k)}}),f.init()}function y(b,g){function v(a){var b=a.precedance==="y",c=n[b?"width":"height"],d=n[b?"height":"width"],e=a.string().indexOf("center")>-1,f=c*(e?.5:1),g=Math.pow,h=Math.round,i,j,k,l=Math.sqrt(g(f,2)+g(d,2)),m=[p/f*l,p/d*l];m[2]=Math.sqrt(g(m[0],2)-g(p,2)),m[3]=Math.sqrt(g(m[1],2)-g(p,2)),i=l+m[2]+m[3]+(e?0:m[0]),j=i/l,k=[h(j*d),h(j*c)];return{height:k[b?0:1],width:k[b?1:0]}}function u(b){var c=k.titlebar&&b.y==="top",d=c?k.titlebar:k.content,e=a.browser.mozilla,f=e?"-moz-":a.browser.webkit?"-webkit-":"",g=b.y+(e?"":"-")+b.x,h=f+(e?"border-radius-"+g:"border-"+g+"-radius");return parseInt(d.css(h),10)||parseInt(l.css(h),10)||0}function t(a,b,c){b=b?b:a[a.precedance];var d=k.titlebar&&a.y==="top",e=d?k.titlebar:k.content,f="border-"+b+"-width",g=parseInt(e.css(f),10);return(c?g||parseInt(l.css(f),10):g)||0}function s(f,g,h,l){if(k.tip){var n=a.extend({},i.corner),o=h.adjusted,p=b.options.position.adjust.method.split(" "),q=p[0],r=p[1]||p[0],s={left:e,top:e,x:0,y:0},t,u={},v;i.corner.fixed!==d&&(q==="shift"&&n.precedance==="x"&&o.left&&n.y!=="center"?n.precedance=n.precedance==="x"?"y":"x":q==="flip"&&o.left&&(n.x=n.x==="center"?o.left>0?"left":"right":n.x==="left"?"right":"left"),r==="shift"&&n.precedance==="y"&&o.top&&n.x!=="center"?n.precedance=n.precedance==="y"?"x":"y":r==="flip"&&o.top&&(n.y=n.y==="center"?o.top>0?"top":"bottom":n.y==="top"?"bottom":"top"),n.string()!==m.corner&&(m.top!==o.top||m.left!==o.left)&&i.update(n,e)),t=i.position(n,o),t.right!==c&&(t.left=-t.right),t.bottom!==c&&(t.top=-t.bottom),t.user=Math.max(0,j.offset);if(s.left=q==="shift"&&!!o.left)n.x==="center"?u["margin-left"]=s.x=t["margin-left"]-o.left:(v=t.right!==c?[o.left,-t.left]:[-o.left,t.left],(s.x=Math.max(v[0],v[1]))>v[0]&&(h.left-=o.left,s.left=e),u[t.right!==c?"right":"left"]=s.x);if(s.top=r==="shift"&&!!o.top)n.y==="center"?u["margin-top"]=s.y=t["margin-top"]-o.top:(v=t.bottom!==c?[o.top,-t.top]:[-o.top,t.top],(s.y=Math.max(v[0],v[1]))>v[0]&&(h.top-=o.top,s.top=e),u[t.bottom!==c?"bottom":"top"]=s.y);k.tip.css(u).toggle(!(s.x&&s.y||n.x==="center"&&s.y||n.y==="center"&&s.x)),h.left-=t.left.charAt?t.user:q!=="shift"||s.top||!s.left&&!s.top?t.left:0,h.top-=t.top.charAt?t.user:r!=="shift"||s.left||!s.left&&!s.top?t.top:0,m.left=o.left,m.top=o.top,m.corner=n.string()}}var i=this,j=b.options.style.tip,k=b.elements,l=k.tooltip,m={top:0,left:0,corner:""},n={width:j.width,height:j.height},o={},p=j.border||0,q=".qtip-tip",r=a("<canvas />")[0].getContext;i.corner=f,i.mimic=f,i.position={},b.checks.tip={"^position.my|style.tip.(corner|mimic|border)$":function(){i.init()||i.destroy(),b.reposition()},"^style.tip.(height|width)$":function(){n={width:j.width,height:j.height},i.create(),i.update(),b.reposition()},"^content.title.text|style.(classes|widget)$":function(){k.tip&&i.update()}},a.extend(i,{init:function(){var b=i.detectCorner()&&(r||a.browser.msie);b&&(i.create(),i.update(),l.unbind(q).bind("tooltipmove"+q,s));return b},detectCorner:function(){var a=j.corner,c=b.options.position,f=c.at,g=c.my.string?c.my.string():c.my;if(a===e||g===e&&f===e)return e;a===d?i.corner=new h.Corner(g):a.string||(i.corner=new h.Corner(a),i.corner.fixed=d);return i.corner.string()!=="centercenter"},detectColours:function(){var c,d,e,f=k.tip.css({backgroundColor:"",border:""}),g=i.corner,h=g[g.precedance],m="border-"+h+"-color",p="border"+h.charAt(0)+h.substr(1)+"Color",q=/rgba?\(0, 0, 0(, 0)?\)|transparent/i,r="background-color",s="transparent",t="ui-tooltip-fluid",u=a(document.body).css("color"),v=b.elements.content.css("color"),w=k.titlebar&&(g.y==="top"||g.y==="center"&&f.position().top+n.height/2+j.offset<k.titlebar.outerHeight(1)),x=w?k.titlebar:k.content;l.addClass(t),d=f.css(r)||s,e=f[0].style[p];if(!d||q.test(d))o.fill=x.css(r),q.test(o.fill)&&(o.fill=l.css(r)||d);if(!e||q.test(e)){o.border=l.css(m);if(q.test(o.border)||o.border===u)o.border=x.css(m),o.border===v&&(o.border=e)}a("*",f).add(f).css(r,s).css("border",""),l.removeClass(t)},create:function(){var b=n.width,c=n.height,d;k.tip&&k.tip.remove(),k.tip=a("<div />",{"class":"ui-tooltip-tip"}).css({width:b,height:c}).prependTo(l),r?a("<canvas />").appendTo(k.tip)[0].getContext("2d").save():(d='<vml:shape coordorigin="0,0" style="display:inline-block; position:absolute; behavior:url(#default#VML);"></vml:shape>',k.tip.html(p?d+=d:d))},update:function(b,c){var g=k.tip,l=g.children(),m=n.width,q=n.height,s="px solid ",u="px dashed transparent",w=j.mimic,y=Math.round,z,A,B,C,D;b||(b=i.corner),w===e?w=b:(w=new h.Corner(w),w.precedance=b.precedance,w.x==="inherit"?w.x=b.x:w.y==="inherit"?w.y=b.y:w.x===w.y&&(w[b.precedance]=b[b.precedance])),z=w.precedance,i.detectColours(),p=o.border==="transparent"||o.border==="#123456"?0:j.border===d?t(b,f,d):j.border,B=x(w,m,q),D=v(b),g.css(D),b.precedance==="y"?C=[y(w.x==="left"?p:w.x==="right"?D.width-m-p:(D.width-m)/2),y(w.y==="top"?D.height-q:0)]:C=[y(w.x==="left"?D.width-m:0),y(w.y==="top"?p:w.y==="bottom"?D.height-q-p:(D.height-q)/2)],r?(l.attr(D),A=l[0].getContext("2d"),A.restore(),A.save(),A.clearRect(0,0,3e3,3e3),A.translate(C[0],C[1]),A.beginPath(),A.moveTo(B[0][0],B[0][1]),A.lineTo(B[1][0],B[1][1]),A.lineTo(B[2][0],B[2][1]),A.closePath(),A.fillStyle=o.fill,A.strokeStyle=o.border,A.lineWidth=p*2,A.lineJoin="miter",A.miterLimit=100,A.stroke(),A.fill()):(B="m"+B[0][0]+","+B[0][1]+" l"+B[1][0]+","+B[1][1]+" "+B[2][0]+","+B[2][1]+" xe",C[2]=p&&/^(r|b)/i.test(b.string())?parseFloat(a.browser.version,10)===8?2:1:0,l.css({antialias:""+(w.string().indexOf("center")>-1),left:C[0]-C[2]*Number(z==="x"),top:C[1]-C[2]*Number(z==="y"),width:m+p,height:q+p}).each(function(b){var c=a(this);c.attr({coordsize:m+p+" "+(q+p),path:B,fillcolor:o.fill,filled:!!b,stroked:!b}).css({display:p||b?"block":"none"}),!b&&p>0&&c.html()===""&&c.html('<vml:stroke weight="'+p*2+'px" color="'+o.border+'" miterlimit="1000" joinstyle="miter"  style="behavior:url(#default#VML); display:inline-block;" />')})),c!==e&&i.position(b)},position:function(b){var c=k.tip,f={},g=Math.max(0,j.offset),h,l,m;if(j.corner===e||!c)return e;b=b||i.corner,h=b.precedance,l=v(b),m=[b.x,b.y],h==="x"&&m.reverse(),a.each(m,function(a,c){var e,i;c==="center"?(e=h==="y"?"left":"top",f[e]="50%",f["margin-"+e]=-Math.round(l[h==="y"?"width":"height"]/2)+g):(e=t(b,c,d),i=u(b),f[c]=a?t(b,c):g+(i>e?i:0))}),f[b[h]]-=l[h==="x"?"width":"height"],c.css({top:"",bottom:"",left:"",right:"",margin:""}).css(f);return f},destroy:function(){k.tip&&k.tip.remove(),l.unbind(q)}}),i.init()}function x(a,b,c){var d=Math.ceil(b/2),e=Math.ceil(c/2),f={bottomright:[[0,0],[b,c],[b,0]],bottomleft:[[0,0],[b,0],[0,c]],topright:[[0,c],[b,0],[b,c]],topleft:[[0,0],[0,c],[b,c]],topcenter:[[0,c],[d,0],[b,c]],bottomcenter:[[0,0],[b,0],[d,c]],rightcenter:[[0,0],[b,e],[0,c]],leftcenter:[[b,0],[b,c],[0,e]]};f.lefttop=f.bottomright,f.righttop=f.bottomleft,f.leftbottom=f.topright,f.rightbottom=f.topleft;return f[a.string()]}function w(b){var c=this,f=b.elements.tooltip,g=b.options.content.ajax,h=".qtip-ajax",i=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,j=d;b.checks.ajax={"^content.ajax":function(a,b,d){b==="ajax"&&(g=d),b==="once"?c.init():g&&g.url?c.load():f.unbind(h)}},a.extend(c,{init:function(){g&&g.url&&f.unbind(h)[g.once?"one":"bind"]("tooltipshow"+h,c.load);return c},load:function(d,h){function p(a,c,d){b.set("content.text",c+": "+d),n()}function o(c){l&&(c=a("<div/>").append(c.replace(i,"")).find(l)),b.set("content.text",c),n()}function n(){m&&(f.css("visibility",""),h=e)}if(d&&d.isDefaultPrevented())return c;var j=g.url.indexOf(" "),k=g.url,l,m=g.once&&!g.loading&&h;m&&f.css("visibility","hidden"),j>-1&&(l=k.substr(j),k=k.substr(0,j)),a.ajax(a.extend({success:o,error:p,context:b},g,{url:k}));return c}}),c.init()}function v(b,c){var i,j,k,l,m=a(this),n=a(document.body),o=this===document?n:m,p=m.metadata?m.metadata(c.metadata):f,q=c.metadata.type==="html5"&&p?p[c.metadata.name]:f,v=m.data(c.metadata.name||"qtipopts");try{v=typeof v==="string"?(new Function("return "+v))():v}catch(w){s("Unable to parse HTML5 attribute data: "+v)}l=a.extend(d,{},g.defaults,c,typeof v==="object"?t(v):f,t(q||p)),p&&a.removeData(this,"metadata"),j=l.position,l.id=b;if("boolean"===typeof l.content.text){k=m.attr(l.content.attr);if(l.content.attr!==e&&k)l.content.text=k;else return e}j.container===e&&(j.container=n),j.target===e&&(j.target=o),l.show.target===e&&(l.show.target=o),l.show.solo===d&&(l.show.solo=n),l.hide.target===e&&(l.hide.target=o),l.position.viewport===d&&(l.position.viewport=j.container),j.at=new h.Corner(j.at),j.my=new h.Corner(j.my);if(a.data(this,"qtip"))if(l.overwrite)m.qtip("destroy");else if(l.overwrite===e)return e;a.attr(this,"title")&&(a.attr(this,r,a.attr(this,"title")),this.removeAttribute("title")),i=new u(m,l,b,!!k),a.data(this,"qtip",i),m.bind("remove.qtip",function(){i.destroy()});return i}function u(c,p,q,s){function L(c,d,e,f){f=parseInt(f,10)!==0;var g=".qtip-"+q,h={show:c&&p.show.target[0],hide:d&&p.hide.target[0],tooltip:e&&u.rendered&&A.tooltip[0],content:e&&u.rendered&&A.content[0],container:f&&p.position.container[0]===v?document:p.position.container[0],window:f&&b};u.rendered?a([]).pushStack(a.grep([h.show,h.hide,h.tooltip,h.container,h.content,h.window],function(a){return typeof a==="object"})).unbind(g):c&&p.show.target.unbind(g+"-create")}function K(d,f,h,j){function D(a){z.is(":visible")&&u.reposition(a)}function C(a){if(z.hasClass(l))return e;clearTimeout(u.timers.inactive),u.timers.inactive=setTimeout(function(){u.hide(a)},p.hide.inactive)}function y(b){if(z.hasClass(l))return e;var c=a(b.relatedTarget||b.target),d=c.closest(m)[0]===z[0],f=c[0]===r.show[0];clearTimeout(u.timers.show),clearTimeout(u.timers.hide);if(n.target==="mouse"&&d||p.hide.fixed&&(/mouse(out|leave|move)/.test(b.type)&&(d||f))){b.stopPropagation(),b.preventDefault();return e}p.hide.delay>0?u.timers.hide=setTimeout(function(){u.hide(b)},p.hide.delay):u.hide(b)}function x(a){if(z.hasClass(l))return e;r.show.trigger("qtip-"+q+"-inactive"),clearTimeout(u.timers.show),clearTimeout(u.timers.hide);var b=function(){u.show(a)};p.show.delay>0?u.timers.show=setTimeout(b,p.show.delay):b()}var k=".qtip-"+q,n=p.position,r={show:p.show.target,hide:p.hide.target,container:n.container[0]===v?a(document):n.container,doc:a(document)},s={show:a.trim(""+p.show.event).split(" "),hide:a.trim(""+p.hide.event).split(" ")},t=a.browser.msie&&parseInt(a.browser.version,10)===6,w;h&&(p.hide.fixed&&(r.hide=r.hide.add(z),z.bind("mouseover"+k,function(){z.hasClass(l)||clearTimeout(u.timers.hide)})),n.target==="mouse"&&n.adjust.mouse&&p.hide.event&&z.bind("mouseleave"+k,function(a){(a.relatedTarget||a.target)!==r.show[0]&&u.hide(a)}),z.bind("mouseenter"+k,function(a){u[a.type==="mouseenter"?"focus":"blur"](a)}),z.bind("mouseenter"+k+" mouseleave"+k,function(a){z.toggleClass(o,a.type==="mouseenter")})),f&&("number"===typeof p.hide.inactive&&(r.show.bind("qtip-"+q+"-inactive",C),a.each(g.inactiveEvents,function(a,b){r.hide.add(A.tooltip).bind(b+k+"-inactive",C)})),/mouse(over|enter)/i.test(p.show.event)&&!/mouse(out|leave)/i.test(p.hide.event)&&r.hide.bind("mouseleave"+k,function(a){clearTimeout(u.timers.show)}),a.each(s.hide,function(b,c){var d=a.inArray(c,s.show),e=a(r.hide);d>-1&&e.add(r.show).length===e.length||c==="unfocus"?(r.show.bind(c+k,function(a){z.is(":visible")?y(a):x(a)}),delete s.show[d]):r.hide.bind(c+k,y)})),d&&(a.each(s.show,function(a,b){r.show.bind(b+k,x)}),"number"===typeof p.hide.distance&&r.show.bind("mousemove"+k,function(a){var b=B.origin||{},c=p.hide.distance,d=Math.abs;b&&(d(a.pageX-b.pageX)>=c||d(a.pageY-b.pageY)>=c)&&u.hide(a)})),j&&((n.adjust.resize||n.viewport)&&a(a.event.special.resize?n.viewport:b).bind("resize"+k,D),(n.viewport||t&&z.css("position")==="fixed")&&a(n.viewport).bind("scroll"+k,D),/unfocus/i.test(p.hide.event)&&r.doc.bind("mousedown"+k,function(b){var d=a(b.target);d.parents(m).length===0&&d.add(c).length>1&&z.is(":visible")&&!z.hasClass(l)&&u.hide(b)}),p.hide.leave&&/mouseleave|mouseout/i.test(p.hide.event)&&a(b).bind("blur"+k+" mouse"+(p.hide.leave.indexOf("frame")>-1?"out":"leave")+k,function(a){a.relatedTarget||u.hide(a)}),n.target==="mouse"&&r.doc.bind("mousemove"+k,function(a){n.adjust.mouse&&!z.hasClass(l)&&z.is(":visible")&&u.reposition(a||i)}))}function J(b,d){function g(a){function c(c){(b=b.not(this)).length===0&&(u.redraw(),u.reposition(B.event),a())}var b;if((b=f.find("img:not([height]):not([width])")).length===0)return c.call(b);b.each(function(a,b){(function d(){var e=u.timers.img;if(b.height&&b.width){clearTimeout(e[a]);return c.call(b)}e[a]=setTimeout(d,20)})()})}var f=A.content;b=b||p.content.text;if(!u.rendered||!b)return e;a.isFunction(b)&&(b=b.call(c,u)||""),b.jquery&&b.length>0?f.empty().append(b.css({display:"block"})):f.html(b),u.rendered<0?z.queue("fx",g):(y=0,g(a.noop));return u}function I(b){var d=A.title;if(!u.rendered||!b)return e;a.isFunction(b)&&(b=b.call(c,u)||""),b.jquery&&b.length>0?d.empty().append(b.css({display:"block"})):d.html(b),u.redraw(),u.rendered&&z.is(":visible")&&u.reposition(B.event)}function H(a){var b=A.button,c=A.title;if(!u.rendered)return e;a?(c||G(),F()):b.remove()}function G(){var b=w+"-title";A.titlebar&&E(),A.titlebar=a("<div />",{"class":j+"-titlebar "+(p.style.widget?"ui-widget-header":"")}).append(A.title=a("<div />",{id:b,"class":j+"-title","aria-atomic":d})).insertBefore(A.content),p.content.title.button?F():u.rendered&&u.redraw()}function F(){var b=p.content.title.button,c=typeof b==="string",d=c?b:"Close tooltip";A.button&&A.button.remove(),b.jquery?A.button=b:A.button=a("<a />",{"class":"ui-state-default "+(p.style.widget?"":j+"-icon"),title:d,"aria-label":d}).prepend(a("<span />",{"class":"ui-icon ui-icon-close",html:"&times;"})),A.button.appendTo(A.titlebar).attr("role","button").hover(function(b){a(this).toggleClass("ui-state-hover",b.type==="mouseenter")}).click(function(a){z.hasClass(l)||u.hide(a);return e}).bind("mousedown keydown mouseup keyup mouseout",function(b){a(this).toggleClass("ui-state-active ui-state-focus",b.type.substr(-4)==="down")}),u.redraw()}function E(){A.title&&(A.titlebar.remove(),A.titlebar=A.title=A.button=f,u.reposition())}function D(){var a=p.style.widget;z.toggleClass(k,a),A.content.toggleClass(k+"-content",a),A.titlebar&&A.titlebar.toggleClass(k+"-header",a),A.button&&A.button.toggleClass(j+"-icon",!a)}function C(a){var b=0,c,d=p,e=a.split(".");while(d=d[e[b++]])b<e.length&&(c=d);return[c||p,e.pop()]}var u=this,v=document.body,w=j+"-"+q,x=0,y=0,z=a(),A,B;u.id=q,u.rendered=e,u.elements=A={target:c},u.timers={img:[]},u.options=p,u.checks={},u.plugins={},u.cache=B={event:{},target:f,disabled:e,attr:s},u.checks.builtin={"^id$":function(b,c,f){var h=f===d?g.nextid:f,i=j+"-"+h;h!==e&&h.length>0&&!a("#"+i).length&&(z[0].id=i,A.content[0].id=i+"-content",A.title[0].id=i+"-title")},"^content.text$":function(a,b,c){J(c)},"^content.title.text$":function(a,b,c){if(!c)return E();!A.title&&c&&G(),I(c)},"^content.title.button$":function(a,b,c){H(c)},"^position.(my|at)$":function(a,b,c){"string"===typeof c&&(a[b]=new h.Corner(c))},"^position.container$":function(a,b,c){u.rendered&&z.appendTo(c)},"^(show|hide).(event|target|fixed|delay|inactive)$":function(a,b,c,d,e){var f=[1,0,0];f[e[1]==="show"?"push":"unshift"](0),L.apply(u,f),K.apply(u,[1,1,0,0])},"^show.ready$":function(){u.rendered?u.show():u.render(1)},"^style.classes$":function(b,c,d){a.attr(z[0],"class",j+" qtip ui-helper-reset "+d)},"^style.widget|content.title":D,"^events.(render|show|move|hide|focus|blur)$":function(b,c,d){z[(a.isFunction(d)?"":"un")+"bind"]("tooltip"+c,d)}},a.extend(u,{render:function(b){if(u.rendered)return u;var f=p.content.title.text,g=a.Event("tooltiprender");a.attr(c[0],"aria-describedby",w),z=A.tooltip=a("<div/>",{id:w,"class":j+" qtip ui-helper-reset "+p.style.classes,width:p.style.width||"",role:"alert","aria-live":"polite","aria-atomic":e,"aria-describedby":w+"-content","aria-hidden":d}).toggleClass(l,B.disabled).data("qtip",u).appendTo(p.position.container).append(A.content=a("<div />",{"class":j+"-content",id:w+"-content","aria-atomic":d})),u.rendered=-1,y=1,f&&(G(),I(f)),J(),u.rendered=d,D(),a.each(p.events,function(b,c){a.isFunction(c)&&z.bind(b==="toggle"?"tooltipshow tooltiphide":"tooltip"+b,c)}),a.each(h,function(){this.initialize==="render"&&this(u)}),K(1,1,1,1),z.queue("fx",function(a){g.originalEvent=B.event,z.trigger(g,[u]),y=0,u.redraw(),(p.show.ready||b)&&u.show(B.event),a()});return u},get:function(a){var b,c;switch(a.toLowerCase()){case"dimensions":b={height:z.outerHeight(),width:z.outerWidth()};break;case"offset":b=h.offset(z,p.position.container);break;default:c=C(a.toLowerCase()),b=c[0][c[1]],b=b.precedance?b.string():b}return b},set:function(b,c){function m(a,b){var c,d,e;for(c in k)for(d in k[c])if(e=(new RegExp(d,"i")).exec(a))b.push(e),k[c][d].apply(u,b)}var g=/^position\.(my|at|adjust|target|container)|style|content|show\.ready/i,h=/^content\.(title|attr)|style/i,i=e,j=e,k=u.checks,l;"string"===typeof b?(l=b,b={},b[l]=c):b=a.extend(d,{},b),a.each(b,function(c,d){var e=C(c.toLowerCase()),f;f=e[0][e[1]],e[0][e[1]]="object"===typeof d&&d.nodeType?a(d):d,b[c]=[e[0],e[1],d,f],i=g.test(c)||i,j=h.test(c)||j}),t(p),x=y=1,a.each(b,m),x=y=0,z.is(":visible")&&u.rendered&&(i&&u.reposition(p.position.target==="mouse"?f:B.event),j&&u.redraw());return u},toggle:function(b,c){function l(){b?(a.browser.msie&&z[0].style.removeAttribute("filter"),z.css("overflow","")):z.css({display:"",visibility:"",width:"",opacity:"",left:"",top:""})}if(!u.rendered)if(b)u.render(1);else return u;var d=b?"show":"hide",g=p[d],h=z.is(":visible"),j,k;(typeof b).search("boolean|number")&&(b=!h);if(h===b)return u;if(c){if(/over|enter/.test(c.type)&&/out|leave/.test(B.event.type)&&c.target===p.show.target[0]&&z.has(c.relatedTarget).length)return u;B.event=a.extend({},c)}k=a.Event("tooltip"+d),k.originalEvent=c?B.event:f,z.trigger(k,[u,90]);if(k.isDefaultPrevented())return u;a.attr(z[0],"aria-hidden",!b),b?(B.origin=a.extend({},i),u.focus(c),a.isFunction(p.content.text)&&J(),u.reposition(c),g.solo&&a(m,g.solo).not(z).qtip("hide",k)):(clearTimeout(u.timers.show),delete B.origin,u.blur(c)),z.stop(0,1),a.isFunction(g.effect)?(g.effect.call(z,u),z.queue("fx",function(a){l(),a()})):g.effect===e?(z[d](),l.call(z)):z.fadeTo(90,b?1:0,l),b&&g.target.trigger("qtip-"+q+"-inactive");return u},show:function(a){return u.toggle(d,a)},hide:function(a){return u.toggle(e,a)},focus:function(b){if(!u.rendered)return u;var c=a(m),d=parseInt(z[0].style.zIndex,10),e=g.zindex+c.length,f=a.extend({},b),h,i;z.hasClass(n)||(i=a.Event("tooltipfocus"),i.originalEvent=f,z.trigger(i,[u,e]),i.isDefaultPrevented()||(d!==e&&(c.each(function(){this.style.zIndex>d&&(this.style.zIndex=this.style.zIndex-1)}),c.filter("."+n).qtip("blur",f)),z.addClass(n)[0].style.zIndex=e));return u},blur:function(b){var c=a.extend({},b),d;z.removeClass(n),d=a.Event("tooltipblur"),d.originalEvent=c,z.trigger(d,[u]);return u},reposition:function(c,d){if(!u.rendered||x)return u;x=1;var f=p.position.target,g=p.position,k=g.my,l=g.at,m=g.adjust,n=m.method.split(" "),o=z.outerWidth(),q=z.outerHeight(),r=0,s=0,t=a.Event("tooltipmove"),w=z.css("position")==="fixed",y=g.viewport.jquery?g.viewport:a(b),A={left:0,top:0},C=(u.plugins.tip||{}).corner,D={horizontal:n[0],vertical:n[1]||n[0],tip:p.style.tip||{},left:function(a){var b=D.horizontal==="shift",c=y.offset.left+y.scrollLeft,d=k.x==="left"?o:k.x==="right"?-o:-o/2,e=l.x==="left"?r:l.x==="right"?-r:-r/2,f=D.tip.width+D.tip.border*2||0,g=C&&C.precedance==="x"&&!b?f:0,h=c-a-g,i=a+o-y.width-c+g,j=d-(k.precedance==="x"||k.x===k.y?e:0),n=k.x==="center";b?(g=C&&C.precedance==="y"?f:0,j=(k.x==="left"?1:-1)*d-g,A.left+=h>0?h:i>0?-i:0,A.left=Math.max(y.offset.left+(g&&C.x==="center"?D.tip.offset:0),a-j,Math.min(Math.max(y.offset.left+y.width,a+j),A.left))):(h>0&&(k.x!=="left"||i>0)?A.left-=j+(n?0:2*m.x):i>0&&(k.x!=="right"||h>0)&&(A.left-=n?-j:j+2*m.x),A.left!==a&&n&&(A.left-=m.x),A.left<c&&-A.left>i&&(A.left=a));return A.left-a},top:function(a){var b=D.vertical==="shift",c=y.offset.top+y.scrollTop,d=k.y==="top"?q:k.y==="bottom"?-q:-q/2,e=l.y==="top"?s:l.y==="bottom"?-s:-s/2,f=D.tip.height+D.tip.border*2||0,g=C&&C.precedance==="y"&&!b?f:0,h=c-a-g,i=a+q-y.height-c+g,j=d-(k.precedance==="y"||k.x===k.y?e:0),n=k.y==="center";b?(g=C&&C.precedance==="x"?f:0,j=(k.y==="top"?1:-1)*d-g,A.top+=h>0?h:i>0?-i:0,A.top=Math.max(y.offset.top+(g&&C.x==="center"?D.tip.offset:0),a-j,Math.min(Math.max(y.offset.top+y.height,a+j),A.top))):(h>0&&(k.y!=="top"||i>0)?A.top-=j+(n?0:2*m.y):i>0&&(k.y!=="bottom"||h>0)&&(A.top-=n?-j:j+2*m.y),A.top!==a&&n&&(A.top-=m.y),A.top<0&&-A.top>i&&(A.top=a));return A.top-a}};if(f==="mouse")l={x:"left",y:"top"},c=c&&(c.type==="resize"||c.type==="scroll")?B.event:!m.mouse&&B.origin?B.origin:i&&(m.mouse||!c||!c.pageX)?{pageX:i.pageX,pageY:i.pageY}:c,A={top:c.pageY,left:c.pageX};else{f==="event"&&(c&&c.target&&c.type!=="scroll"&&c.type!=="resize"?f=B.target=a(c.target):f=B.target),f=a(f).eq(0);if(f.length===0)return u;f[0]===document||f[0]===b?(r=f.width(),s=f.height(),f[0]===b&&(A={top:!w||h.iOS?y.scrollTop():0,left:!w||h.iOS?y.scrollLeft():0})):f.is("area")&&h.imagemap?A=h.imagemap(f,l):f[0].namespaceURI==="http://www.w3.org/2000/svg"&&h.svg?A=h.svg(f,l):(r=f.outerWidth(),s=f.outerHeight(),A=h.offset(f,g.container,w)),A.offset&&(r=A.width,s=A.height,A=A.offset),A.left+=l.x==="right"?r:l.x==="center"?r/2:0,A.top+=l.y==="bottom"?s:l.y==="center"?s/2:0}A.left+=m.x+(k.x==="right"?-o:k.x==="center"?-o/2:0),A.top+=m.y+(k.y==="bottom"?-q:k.y==="center"?-q/2:0),y.jquery&&f[0]!==b&&f[0]!==v&&D.vertical+D.horizontal!=="nonenone"?(y={elem:y,height:y[(y[0]===b?"h":"outerH")+"eight"](),width:y[(y[0]===b?"w":"outerW")+"idth"](),scrollLeft:y.scrollLeft(),scrollTop:y.scrollTop(),offset:y.offset()||{left:0,top:0}},A.adjusted={left:D.horizontal!=="none"?D.left(A.left):0,top:D.vertical!=="none"?D.top(A.top):0}):A.adjusted={left:0,top:0},z.attr("class",function(b,c){return a.attr(this,"class").replace(/ui-tooltip-pos-\w+/i,"")}).addClass(j+"-pos-"+k.abbreviation()),t.originalEvent=a.extend({},c),z.trigger(t,[u,A,y.elem||y]);if(t.isDefaultPrevented())return u;delete A.adjusted,d===e||isNaN(A.left)||isNaN(A.top)||!a.isFunction(g.effect)?z.css(A):a.isFunction(g.effect)&&(g.effect.call(z,u,a.extend({},A)),z.queue(function(b){a(this).css({opacity:"",height:""}),a.browser.msie&&this.style.removeAttribute("filter"),b()})),x=0;return u},redraw:function(){if(u.rendered<1||p.style.width||y)return u;var b=j+"-fluid",c=p.position.container,d,e,f,g;y=1,z.css("width","").addClass(b),e=z.width()+(a.browser.mozilla?1:0),f=z.css("max-width")||"",g=z.css("min-width")||"",d=(f+g).indexOf("%")>-1?c.width()/100:0,f=(f.indexOf("%")>-1?d:1)*parseInt(f,10)||e,g=(g.indexOf("%")>-1?d:1)*parseInt(g,10)||0,e=f+g?Math.min(Math.max(e,g),f):e,z.css("width",Math.round(e)).removeClass(b),y=0;return u},disable:function(b){var c=l;"boolean"!==typeof b&&(b=!z.hasClass(c)&&!B.disabled),u.rendered?(z.toggleClass(c,b),a.attr(z[0],"aria-disabled",b)):B.disabled=!!b;return u},enable:function(){return u.disable(e)},destroy:function(){var b=c[0],d=a.attr(b,r);u.rendered&&(z.remove(),a.each(u.plugins,function(){this.destroy&&this.destroy()})),clearTimeout(u.timers.show),clearTimeout(u.timers.hide),L(1,1,1,1),a.removeData(b,"qtip"),d&&(a.attr(b,"title",d),c.removeAttr(r)),c.removeAttr("aria-describedby").unbind(".qtip");return c}})}function t(b){var c;if(!b||"object"!==typeof b)return e;"object"!==typeof b.metadata&&(b.metadata={type:b.metadata});if("content"in b){if("object"!==typeof b.content||b.content.jquery)b.content={text:b.content};c=b.content.text||e,!a.isFunction(c)&&(!c&&!c.attr||c.length<1||"object"===typeof c&&!c.jquery)&&(b.content.text=e),"title"in b.content&&("object"!==typeof b.content.title&&(b.content.title={text:b.content.title}),c=b.content.title.text||e,!a.isFunction(c)&&(!c&&!c.attr||c.length<1||"object"===typeof c&&!c.jquery)&&(b.content.title.text=e))}"position"in b&&("object"!==typeof b.position&&(b.position={my:b.position,at:b.position})),"show"in b&&("object"!==typeof b.show&&(b.show.jquery?b.show={target:b.show}:b.show={event:b.show})),"hide"in b&&("object"!==typeof b.hide&&(b.hide.jquery?b.hide={target:b.hide}:b.hide={event:b.hide})),"style"in b&&("object"!==typeof b.style&&(b.style={classes:b.style})),a.each(h,function(){this.sanitize&&this.sanitize(b)});return b}function s(){var c=b.console;return c&&(c.error||c.log||a.noop).apply(c,arguments)}var d=!0,e=!1,f=null,g,h,i,j="ui-tooltip",k="ui-widget",l="ui-state-disabled",m="div.qtip."+j,n=j+"-focus",o=j+"-hover",p="-31000px",q="_replacedByqTip",r="oldtitle";g=a.fn.qtip=function(b,h,i){var j=(""+b).toLowerCase(),k=f,l=j==="disable"?[d]:a.makeArray(arguments).slice(1,10),m=l[l.length-1],n=this[0]?a.data(this[0],"qtip"):f;if(!arguments.length&&n||j==="api")return n;if("string"===typeof b){this.each(function(){var b=a.data(this,"qtip");if(!b)return d;m&&m.timeStamp&&(b.cache.event=m);if(j!=="option"&&j!=="options"||!h)b[j]&&b[j].apply(b[j],l);else if(a.isPlainObject(h)||i!==c)b.set(h,i);else{k=b.get(h);return e}});return k!==f?k:this}if("object"===typeof b||!arguments.length){n=t(a.extend(d,{},b));return g.bind.call(this,n,m)}},g.bind=function(b,c){return this.each(function(f){function p(b){function c(){o.render(typeof b==="object"||i.show.ready),k.show.unbind(l.show),k.hide.unbind(l.hide)}if(o.cache.disabled)return e;o.cache.event=a.extend({},b),i.show.delay>0?(clearTimeout(o.timers.show),o.timers.show=setTimeout(c,i.show.delay),l.show!==l.hide&&k.hide.bind(l.hide,function(){clearTimeout(o.timers.show)})):c()}var i,k,l,m=!b.id||b.id===e||b.id.length<1||a("#"+j+"-"+b.id).length?g.nextid++:b.id,n=".qtip-"+m+"-create",o=v.call(this,m,b);if(o===e)return d;i=o.options,a.each(h,function(){this.initialize==="initialize"&&this(o)}),k={show:i.show.target,hide:i.hide.target},l={show:a.trim(""+i.show.event).replace(/ /g,n+" ")+n,hide:a.trim(""+i.hide.event).replace(/ /g,n+" ")+n},/mouse(over|enter)/i.test(l.show)&&!/mouse(out|leave)/i.test(l.hide)&&(l.hide+=" mouseleave"+n),k.show.bind(l.show,p),(i.show.ready||i.prerender)&&p(c)})},h=g.plugins={Corner:function(a){a=(""+a).replace(/([A-Z])/," $1").replace(/middle/gi,"center").toLowerCase(),this.x=(a.match(/left|right/i)||a.match(/center/)||["inherit"])[0].toLowerCase(),this.y=(a.match(/top|bottom|center/i)||["inherit"])[0].toLowerCase(),this.precedance=a.charAt(0).search(/^(t|b)/)>-1?"y":"x",this.string=function(){return this.precedance==="y"?this.y+this.x:this.x+this.y},this.abbreviation=function(){var a=this.x.substr(0,1),b=this.y.substr(0,1);return a===b?a:a==="c"||a!=="c"&&b!=="c"?b+a:a+b}},offset:function(c,d,e){function l(a,b){f.left+=b*a.scrollLeft(),f.top+=b*a.scrollTop()}var f=c.offset(),g=d,i=0,j=document.body,k;if(g){do{if(g[0]===j)break;g.css("position")!=="static"&&(k=g.position(),f.left-=k.left+(parseInt(g.css("borderLeftWidth"),10)||0),f.top-=k.top+(parseInt(g.css("borderTopWidth"),10)||0),i++)}while(g=g.offsetParent());(d[0]!==j||i>1)&&l(d,1),(h.iOS<4.1&&h.iOS>3.1||!h.iOS&&e)&&l(a(b),-1)}return f},iOS:parseFloat((""+(/CPU.*OS ([0-9_]{1,3})|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent)||[0,""])[1]).replace("undefined","3_2").replace("_","."))||e,fn:{attr:function(b,c){if(this.length){var d=this[0],e="title",f=a.data(d,"qtip");if(b===e){if(arguments.length<2)return a.attr(d,r);if(typeof f==="object"){f&&f.rendered&&f.options.content.attr===e&&f.cache.attr&&f.set("content.text",c),a.fn["attr"+q].apply(this,arguments),a.attr(d,r,a.attr(d,e));return this.removeAttr(e)}}}},clone:function(b){var c=a([]),d="title",e;e=a.fn["clone"+q].apply(this,arguments).filter("[oldtitle]").each(function(){a.attr(this,d,a.attr(this,r)),this.removeAttribute(r)}).end();return e},remove:a.ui?f:function(b,c){a(this).each(function(){c||(!b||a.filter(b,[this]).length)&&a("*",this).add(this).each(function(){a(this).triggerHandler("remove")})})}}},a.each(h.fn,function(b,c){if(!c)return d;var e=a.fn[b+q]=a.fn[b];a.fn[b]=function(){return c.apply(this,arguments)||e.apply(this,arguments)}}),a(document).bind("mousemove.qtip",function(a){i={pageX:a.pageX,pageY:a.pageY,type:"mousemove"}}),g.version="nightly",g.nextid=0,g.inactiveEvents="click dblclick mousedown mouseup mousemove mouseleave mouseenter".split(" "),g.zindex=15e3,g.defaults={prerender:e,id:e,overwrite:d,content:{text:d,attr:"title",title:{text:e,button:e}},position:{my:"top left",at:"bottom right",target:e,container:e,viewport:e,adjust:{x:0,y:0,mouse:d,resize:d,method:"flip flip"},effect:d},show:{target:e,event:"mouseenter",effect:d,delay:90,solo:e,ready:e},hide:{target:e,event:"mouseleave",effect:d,delay:0,fixed:e,inactive:e,leave:"window",distance:e},style:{classes:"",widget:e,width:e},events:{render:f,move:f,show:f,hide:f,toggle:f,focus:f,blur:f}},h.ajax=function(a){var b=a.plugins.ajax;return"object"===typeof b?b:a.plugins.ajax=new w(a)},h.ajax.initialize="render",h.ajax.sanitize=function(a){var b=a.content,c;b&&"ajax"in b&&(c=b.ajax,typeof c!=="object"&&(c=a.content.ajax={url:c}),"boolean"!==typeof c.once&&c.once&&(c.once=!!c.once))},a.extend(d,g.defaults,{content:{ajax:{loading:d,once:d}}}),h.imagemap=function(b,c){function l(a,b){var d=0,e=1,f=1,g=0,h=0,i=a.width,j=a.height;while(i>0&&j>0&&e>0&&f>0){i=Math.floor(i/2),j=Math.floor(j/2),c.x==="left"?e=i:c.x==="right"?e=a.width-i:e+=Math.floor(i/2),c.y==="top"?f=j:c.y==="bottom"?f=a.height-j:f+=Math.floor(j/2),d=b.length;while(d--){if(b.length<2)break;g=b[d][0]-a.offset.left,h=b[d][1]-a.offset.top,(c.x==="left"&&g>=e||c.x==="right"&&g<=e||c.x==="center"&&(g<e||g>a.width-e)||c.y==="top"&&h>=f||c.y==="bottom"&&h<=f||c.y==="center"&&(h<f||h>a.height-f))&&b.splice(d,1)}}return{left:b[0][0],top:b[0][1]}}var d=b.attr("shape").toLowerCase(),e=b.attr("coords").split(","),f=[],g=a('img[usemap="#'+b.parent("map").attr("name")+'"]'),h=g.offset(),i={width:0,height:0,offset:{top:1e10,right:0,bottom:0,left:1e10}},j=0,k=0;h.left+=Math.ceil((g.outerWidth()-g.width())/2),h.top+=Math.ceil((g.outerHeight()-g.height())/2);if(d==="poly"){j=e.length;while(j--)k=[parseInt(e[--j],10),parseInt(e[j+1],10)],k[0]>i.offset.right&&(i.offset.right=k[0]),k[0]<i.offset.left&&(i.offset.left=k[0]),k[1]>i.offset.bottom&&(i.offset.bottom=k[1]),k[1]<i.offset.top&&(i.offset.top=k[1]),f.push(k)}else f=a.map(e,function(a){return parseInt(a,10)});switch(d){case"rect":i={width:Math.abs(f[2]-f[0]),height:Math.abs(f[3]-f[1]),offset:{left:f[0],top:f[1]}};break;case"circle":i={width:f[2]+2,height:f[2]+2,offset:{left:f[0],top:f[1]}};break;case"poly":a.extend(i,{width:Math.abs(i.offset.right-i.offset.left),height:Math.abs(i.offset.bottom-i.offset.top)}),c.string()==="centercenter"?i.offset={left:i.offset.left+i.width/2,top:i.offset.top+i.height/2}:i.offset=l(i,f.slice()),i.width=i.height=0}i.offset.left+=h.left,i.offset.top+=h.top;return i},h.tip=function(a){var b=a.plugins.tip;return"object"===typeof b?b:a.plugins.tip=new y(a)},h.tip.initialize="render",h.tip.sanitize=function(a){var b=a.style,c;b&&"tip"in b&&(c=a.style.tip,typeof c!=="object"&&(a.style.tip={corner:c}),/string|boolean/i.test(typeof c.corner)||(c.corner=d),typeof c.width!=="number"&&delete c.width,typeof c.height!=="number"&&delete c.height,typeof c.border!=="number"&&c.border!==d&&delete c.border,typeof c.offset!=="number"&&delete c.offset)},a.extend(d,g.defaults,{style:{tip:{corner:d,mimic:e,width:6,height:6,border:d,offset:0}}}),h.svg=function(b,c){var d=a(document),e=b[0],f={width:0,height:0,offset:{top:1e10,left:1e10}},g,h,i,j,k;if(e.getBBox&&e.parentNode){g=e.getBBox(),h=e.getScreenCTM(),i=e.farthestViewportElement||e;if(!i.createSVGPoint)return f;j=i.createSVGPoint(),j.x=g.x,j.y=g.y,k=j.matrixTransform(h),f.offset.left=k.x,f.offset.top=k.y,j.x+=g.width,j.y+=g.height,k=j.matrixTransform(h),f.width=k.x-f.offset.left,f.height=k.y-f.offset.top,f.offset.left+=d.scrollLeft(),f.offset.top+=d.scrollTop()}return f},h.modal=function(a){var b=a.plugins.modal;return"object"===typeof b?b:a.plugins.modal=new z(a)},h.modal.initialize="render",h.modal.sanitize=function(a){a.show&&(typeof a.show.modal!=="object"?a.show.modal={on:!!a.show.modal}:typeof a.show.modal.on==="undefined"&&(a.show.modal.on=d))},a.extend(d,g.defaults,{show:{modal:{on:e,effect:d,blur:d,escape:d}}}),h.bgiframe=function(b){var c=a.browser,d=b.plugins.bgiframe;if(a("select, object").length<1||(!c.msie||c.version.charAt(0)!=="6"))return e;return"object"===typeof d?d:b.plugins.bgiframe=new A(b)},h.bgiframe.initialize="render"}(jQuery,window)

// jQuery image upload extension
jQuery.extend({createUploadIframe:function(a,c){var b="jUploadFrame"+a;if(window.ActiveXObject){
var e=document.createElement('iframe');e.setAttribute("id", b);e.setAttribute("name", b);
if(typeof c=="boolean")e.src="javascript:false";else if(typeof c=="string")e.src=c}else{e=document.createElement("iframe");e.id=b;e.name=b}e.style.position="absolute";e.style.top="-1000px";e.style.left="-1000px";document.body.appendChild(e);return e},createUploadForm:function(a,c){var b="jUploadForm"+a,e="jUploadFile"+a;b=$('<form  action="" method="POST" name="'+b+'" id="'+b+'" enctype="multipart/form-data"></form>');var g=$("#"+c),d=$(g).clone();$(g).attr("id",e);$(g).before(d);$(g).appendTo(b);$(b).css("position","absolute");$(b).css("top","-1200px");$(b).css("left","-1200px");$(b).appendTo("body");return b},ajaxFileUpload:function(a){a=jQuery.extend({},jQuery.ajaxSettings,a);var c=(new Date).getTime(),b=jQuery.createUploadForm(c,a.fileElementId);jQuery.createUploadIframe(c,a.secureuri);var e="jUploadFrame"+c;c="jUploadForm"+c;a.global&&!jQuery.active++&&jQuery.event.trigger("ajaxStart");var g=false,d={};a.global&&jQuery.event.trigger("ajaxSend",[d,a]);var i=function(j){var f=document.getElementById(e);try{if(f.contentWindow){d.responseText=f.contentWindow.document.body?f.contentWindow.document.body.innerHTML:null;d.responseXML=f.contentWindow.document.XMLDocument?f.contentWindow.document.XMLDocument:f.contentWindow.document}else if(f.contentDocument){d.responseText=f.contentDocument.document.body?f.contentDocument.document.body.innerHTML:null;d.responseXML=f.contentDocument.document.XMLDocument?f.contentDocument.document.XMLDocument:f.contentDocument.document}}catch(k){jQuery.handleError(a,d,null,k)}if(d||j=="timeout"){g=true;var h;try{h=j!="timeout"?"success":"error";if(h!="error"){var l=jQuery.uploadHttpData(d,a.dataType);a.success&&a.success(l,h);a.global&&jQuery.event.trigger("ajaxSuccess",[d,a])}else jQuery.handleError(a,d,h)}catch(m){h="error";jQuery.handleError(a,d,h,m)}a.global&&jQuery.event.trigger("ajaxComplete",[d,a]);a.global&&!--jQuery.active&&jQuery.event.trigger("ajaxStop");a.complete&&a.complete(d,h);jQuery(f).unbind();setTimeout(function(){try{$(f).remove();$(b).remove()}catch(n){jQuery.handleError(a,d,null,n)}},100);d=null}};a.timeout>0&&setTimeout(function(){g||i("timeout")},a.timeout);try{b=$("#"+c);$(b).attr("action",a.url);$(b).attr("method","POST");$(b).attr("target",e);if(b.encoding)b.encoding="multipart/form-data";else b.enctype="multipart/form-data";$(b).submit()}catch(o){jQuery.handleError(a,d,null,o)}window.attachEvent?document.getElementById(e).attachEvent("onload",i):document.getElementById(e).addEventListener("load",i,false);return{abort:function(){}}},uploadHttpData:function(a,c){var b=!c;b=c=="xml"||b?a.responseXML:a.responseText;c=="script"&&jQuery.globalEval(b);c=="json"&&eval("data = "+b);c=="html"&&jQuery("<div>").html(b).evalScripts();return b}});

(function($){$.alerts={verticalOffset:-75,horizontalOffset:0,repositionOnResize:true,overlayOpacity:.50,overlayColor:'#000',draggable:false,okButton:'OK',cancelButton:'Cancel',dialogClass:null,alert:function(message,title,callback){if(title==null)title='Alert';$.alerts._show(title,message,null,'alert',function(result){if(callback)callback(result);});},confirm:function(message,title,callback){if(title==null)title='Confirm';$.alerts._show(title,message,null,'confirm',function(result){if(callback)callback(result);});},prompt:function(message,value,title,callback){if(title==null)title='Prompt';$.alerts._show(title,message,value,'prompt',function(result){if(callback)callback(result);});},_show:function(title,msg,value,type,callback){$.alerts._hide();$.alerts._overlay('show');$("BODY").append('<div id="popup_container">'+'<h1 id="popup_title"></h1>'+'<div id="popup_content">'+'<div id="popup_message"></div>'+'</div>'+'</div>');if($.alerts.dialogClass)$("#popup_container").addClass($.alerts.dialogClass);var pos=($.browser.msie&&parseInt($.browser.version)<=6)?'absolute':'fixed';$("#popup_container").css({position:pos,zIndex:99999,padding:0,margin:0});$("#popup_title").text(title);$("#popup_content").addClass(type);$("#popup_message").text(msg);$("#popup_message").html($("#popup_message").text().replace(/\n/g,'<br />'));$("#popup_container").css({minWidth:$("#popup_container").outerWidth(),maxWidth:$("#popup_container").outerWidth()});$.alerts._reposition();$.alerts._maintainPosition(true);switch(type){case'alert':$("#popup_message").after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /></div>');$("#popup_ok").click(function(){$.alerts._hide();callback(true);});$("#popup_ok").focus().keypress(function(e){if(e.keyCode==13||e.keyCode==27)$("#popup_ok").trigger('click');});break;case'confirm':$("#popup_message").after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /> <input type="button" value="'+$.alerts.cancelButton+'" id="popup_cancel" /></div>');$("#popup_ok").click(function(){$.alerts._hide();if(callback)callback(true);});$("#popup_cancel").click(function(){$.alerts._hide();if(callback)callback(false);});$("#popup_ok").focus();$("#popup_ok, #popup_cancel").keypress(function(e){if(e.keyCode==13)$("#popup_ok").trigger('click');if(e.keyCode==27)$("#popup_cancel").trigger('click');});break;case'prompt':$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="'+$.alerts.okButton+'" id="popup_ok" /> <input type="button" value="'+$.alerts.cancelButton+'" id="popup_cancel" /></div>');$("#popup_prompt").width($("#popup_message").width());$("#popup_ok").click(function(){var val=$("#popup_prompt").val();$.alerts._hide();if(callback)callback(val);});$("#popup_cancel").click(function(){$.alerts._hide();if(callback)callback(null);});$("#popup_prompt, #popup_ok, #popup_cancel").keypress(function(e){if(e.keyCode==13)$("#popup_ok").trigger('click');if(e.keyCode==27)$("#popup_cancel").trigger('click');});if(value)$("#popup_prompt").val(value);$("#popup_prompt").focus().select();break;}
if($.alerts.draggable){try{$("#popup_container").draggable({handle:$("#popup_title")});$("#popup_title").css({cursor:'move'});}catch(e){}}},_hide:function(){$("#popup_container").remove();$.alerts._overlay('hide');$.alerts._maintainPosition(false);},_overlay:function(status){switch(status){case'show':$.alerts._overlay('hide');$("BODY").append('<div id="popup_overlay"></div>');$("#popup_overlay").css({position:'absolute',zIndex:99998,top:'0px',left:'0px',width:'100%',height:$(document).height(),background:$.alerts.overlayColor,opacity:$.alerts.overlayOpacity});break;case'hide':$("#popup_overlay").remove();break;}},_reposition:function(){var top=(($(window).height()/2)-($("#popup_container").outerHeight()/2))+$.alerts.verticalOffset;var left=(($(window).width()/2)-($("#popup_container").outerWidth()/2))+$.alerts.horizontalOffset;if(top<0)top=0;if(left<0)left=0;if($.browser.msie&&parseInt($.browser.version)<=6)top=top+$(window).scrollTop();$("#popup_container").css({top:top+'px',left:left+'px'});$("#popup_overlay").height($(document).height());},_maintainPosition:function(status){if($.alerts.repositionOnResize){switch(status){case true:$(window).bind('resize',$.alerts._reposition);break;case false:$(window).unbind('resize',$.alerts._reposition);break;}}}}
jAlert=function(message,title,callback){$.alerts.alert(message,title,callback);}
jConfirm=function(message,title,callback){$.alerts.confirm(message,title,callback);};jPrompt=function(message,value,title,callback){$.alerts.prompt(message,value,title,callback);};})(jQuery);

//TinyBox Modal
TINY={};TINY.box=function(){var j,m,b,g,v,p=0;return{show:function(o){v={opacity:70,close:1,animate:1,fixed:1,mask:1,maskid:'',boxid:'',topsplit:2,url:0,post:0,height:0,width:0,html:0,iframe:0};for(s in o){v[s]=o[s]}if(!p){j=document.createElement('div');j.className='tbox';p=document.createElement('div');p.className='tinner';b=document.createElement('div');b.className='tcontent';m=document.createElement('div');m.className='tmask';g=document.createElement('div');g.className='tclose';g.v=0;document.body.appendChild(m);document.body.appendChild(j);j.appendChild(p);p.appendChild(b);m.onclick=g.onclick=TINY.box.hide;window.onresize=TINY.box.resize}else{j.style.display='none';clearTimeout(p.ah);if(g.v){p.removeChild(g);g.v=0}}p.id=v.boxid;m.id=v.maskid;j.style.position=v.fixed?'fixed':'absolute';if(v.html&&!v.animate){p.style.backgroundImage='none';b.innerHTML=v.html;b.style.display='';p.style.width=v.width?v.width+'px':'auto';p.style.height=v.height?v.height+'px':'auto'}else{b.style.display='none';if(!v.animate&&v.width&&v.height){p.style.width=v.width+'px';p.style.height=v.height+'px'}else{p.style.width=p.style.height='100px'}}if(v.mask){this.mask();this.alpha(m,1,v.opacity)}else{this.alpha(j,1,100)}if(v.autohide){p.ah=setTimeout(TINY.box.hide,1000*v.autohide)}else{document.onkeyup=TINY.box.esc}},fill:function(c,u,k,a,w,h){if(u){if(v.image){var i=new Image();i.onload=function(){w=w||i.width;h=h||i.height;TINY.box.psh(i,a,w,h)};i.src=v.image}else if(v.iframe){this.psh('<iframe src="'+v.iframe+'" width="'+v.width+'" frameborder="0" height="'+v.height+'"></iframe>',a,w,h)}else{var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');x.onreadystatechange=function(){if(x.readyState==4&&x.status==200){p.style.backgroundImage='';TINY.box.psh(x.responseText,a,w,h)}};if(k){x.open('POST',c,true);x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(k)}else{x.open('GET',c,true);x.send(null)}}}else{this.psh(c,a,w,h)}},psh:function(c,a,w,h){if(typeof c=='object'){b.appendChild(c)}else{b.innerHTML=c}var x=p.style.width,y=p.style.height;if(!w||!h){p.style.width=w?w+'px':'';p.style.height=h?h+'px':'';b.style.display='';if(!h){h=parseInt(b.offsetHeight)}if(!w){w=parseInt(b.offsetWidth)}b.style.display='none'}p.style.width=x;p.style.height=y;this.size(w,h,a)},esc:function(e){e=e||window.event;if(e.keyCode==27){TINY.box.hide()}},hide:function(){TINY.box.alpha(j,-1,0,3);document.onkeypress=null;if(v.closejs){v.closejs()}},resize:function(){TINY.box.pos();TINY.box.mask()},mask:function(){m.style.height=this.total(1)+'px';m.style.width=this.total(0)+'px'},pos:function(){var t;if(typeof v.top!='undefined'){t=v.top}else{t=(this.height()/v.topsplit)-(j.offsetHeight/2);t=t<20?20:t}if(!v.fixed&&!v.top){t+=this.top()}j.style.top=t+'px';j.style.left=typeof v.left!='undefined'?v.left+'px':(this.width()/2)-(j.offsetWidth/2)+'px'},alpha:function(e,d,a){clearInterval(e.ai);if(d){e.style.opacity=0;e.style.filter='alpha(opacity=0)';e.style.display='block';TINY.box.pos()}e.ai=setInterval(function(){TINY.box.ta(e,a,d)},20)},ta:function(e,a,d){var o=Math.round(e.style.opacity*100);if(o==a){clearInterval(e.ai);if(d==-1){e.style.display='none';e==j?TINY.box.alpha(m,-1,0,2):b.innerHTML=p.style.backgroundImage=''}else{if(e==m){this.alpha(j,1,100)}else{j.style.filter='';TINY.box.fill(v.html||v.url,v.url||v.iframe||v.image,v.post,v.animate,v.width,v.height)}}}else{var n=a-Math.floor(Math.abs(a-o)*.5)*d;e.style.opacity=n/100;e.style.filter='alpha(opacity='+n+')'}},size:function(w,h,a){if(a){clearInterval(p.si);var wd=parseInt(p.style.width)>w?-1:1,hd=parseInt(p.style.height)>h?-1:1;p.si=setInterval(function(){TINY.box.ts(w,wd,h,hd)},20)}else{p.style.backgroundImage='none';if(v.close){p.appendChild(g);g.v=1}p.style.width=w+'px';p.style.height=h+'px';b.style.display='';this.pos();if(v.openjs){v.openjs()}}},ts:function(w,wd,h,hd){var cw=parseInt(p.style.width),ch=parseInt(p.style.height);if(cw==w&&ch==h){clearInterval(p.si);p.style.backgroundImage='none';b.style.display='block';if(v.close){p.appendChild(g);g.v=1}if(v.openjs){v.openjs()}}else{if(cw!=w){p.style.width=(w-Math.floor(Math.abs(w-cw)*.6)*wd)+'px'}if(ch!=h){p.style.height=(h-Math.floor(Math.abs(h-ch)*.6)*hd)+'px'}this.pos()}},top:function(){return document.documentElement.scrollTop||document.body.scrollTop},width:function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},height:function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},total:function(d){var b=document.body,e=document.documentElement;return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))}}}();
