function AttachEvent(elementObj, eventName, eventHandlerFunctionName) {
    if (elementObj.addEventListener) { // Non-IE browsers
        elementObj.addEventListener(eventName, function(e) { eventHandlerFunctionName(elementObj); e.preventDefault(); }, false);
    }
    else if (elementObj.attachEvent) { // IE 6+
        elementObj.attachEvent('on' + eventName, function(e) { eventHandlerFunctionName(elementObj); e.returnValue = false;});
    }
    else { /* Older browsers so flag */ }
}

var preLoad = new Array();
var existingImage;
var browser = "";

function LoadEvents() {

    if(window.XMLHttpRequest) {
        if(window.ActiveXObject) {
            browser = "ie7";
        }
        else {
            browser = "mozilla";
        }
    }
    else {
        browser = "ie6";
    }

    var dashColumns = getElementsByClass('dashColumn');
    for(i = 0; i < dashColumns.length; i ++) {
        AttachEvent(dashColumns[i], 'mouseover', dashColumnOver);
        AttachEvent(dashColumns[i], 'mouseout', dashColumnOut);
    }

    var frontBullets = getElementsByClass('frontBullet');
    for(i = 0; i < frontBullets.length; i ++) {
        AttachEvent(frontBullets[i], 'mouseover', dashColumnOver);
        AttachEvent(frontBullets[i], 'mouseout', dashColumnOut);
    }

    if(dashMessageElement = document.getElementById('dashMessage')) {
        removeMessageTimer = window.setTimeout('removeMessage()', 4000);
    }

    if(document.getElementById('unmanned')) {
        vcInteractive();
        AttachEvent(document, 'mousemove', vcInteractive);

        vcRefresh();
        AttachEvent(document, 'mousemove', vcRefresh);
    }

    //window.onresize = windowResized;
    //windowResized();
    pngFix();

    sweetTitles.init();

	// Jquery Stuff
	$(document).ready(function() {
		$('.menuDrop').hover(function() {
			$(this).find('.menuDropMenu').slideToggle('fast')
		}, function() {
			$(this).find('.menuDropMenu').slideToggle('fast')
		});


		$('.helpHover').hover(function() {

			if(browser != 'ie6') {
				$(this).parents('.formItem').css('position', 'relative');
				$('.dashForm .formItem .helpHoverDiv').css('right', '0px').css('bottom', '0px');
			}

			$('#'+this.id+'_hover').css('opacity', '.95');
			$('#'+this.id+'_hover').show();

			if(browser == 'ie6') {
				if($('#'+this.id+'_hover').height() >= 200) {
					var newOffset = Math.round($('#'+this.id+'_hover').height()/2);
					$('#'+this.id+'_hover').css('margin-top', '-'+newOffset+'px');
				}
			}
			else {
				if($('#'+this.id+'_hover').height() >= 200) {
					var newOffset = Math.round($('#'+this.id+'_hover').height()/2);
					if($(this).offset().top + newOffset > ($('body').height()-250)) {
						$('#'+this.id+'_hover').css('bottom', '0px');
					}
					else {
						$('#'+this.id+'_hover').css('bottom', '-'+(newOffset)+'px');
					}
				}
			}
		}, function() {
			$(this).parents('.formItem').css('position', 'static');
			$('#'+this.id+'_hover').hide();
		});

		if($(".tabs").length > 0) {
			$(".tabs").each(function(index) {
				$(this).tabs({
					cookie: { expires: 0 },
					load: function(event, ui) { loadButtonHovers(); },
					select: function(event, ui) {
						if($(ui.tab).attr('followUrl')) {
							location.href = $(ui.tab).attr('followUrl');
							return false;
						}
						return true;
					}

				});
			});

			window.setTimeout(function() {
				$('.tabs').css('visibility', 'visible');
				$(".dashForm .tabs").tabs('select', 0);
				$(".dashForm .tabs").tabs('select', 2);
				$(".dashForm .tabs").tabs('select', 0);
			}, 500);
		}

		// if(typeof(ignoreLoadButtonHovers) == 'undefined') {
			loadButtonHovers();
		// }

		$('.helpHoverIcon').hover(function() {
			$(this).attr('id')
			$('#'+$(this).attr('id')+'_hover').show();
		}, function() {
			$('#'+$(this).attr('id')+'_hover').hide();
		});

		$(".popupText").dialog({
			width: 500,
			modal: true,
			buttons: {
				'Close': function() {
					$(this).dialog('close');
				}
			}
		});

		$('.lu-menu').each(function () {
			var menuElement = this;
			$(menuElement).menu({
				content: $(menuElement).next().html(), // grab content from this page
				showSpeed: 100
			});
		});
		
		$('.calOption').click(function() {

			var calOptionText = $(this).text();
			if(calOptionText == 'Today') {
				$(this).siblings('input').datepicker("setDate", '+0d');
				$(this).siblings('input').change();
			}
			else if(calOptionText == 'Tomorrow') {
				$(this).siblings('input').datepicker("setDate", '+1d');
				$(this).siblings('input').change();
			}
			else if(calOptionText == '7 Days') {
				$(this).siblings('input').datepicker("setDate", '+7d');
				$(this).siblings('input').change();
			}
			else if(calOptionText == '30 Days') {
				$(this).siblings('input').datepicker("setDate", '+30d');
				$(this).siblings('input').change();
			}
			else if(calOptionText == '1 Year') {
				$(this).siblings('input').datepicker("setDate", '+1y -1d');
				$(this).siblings('input').change();
			}
			else if(calOptionText == '2 Years') {
				$(this).siblings('input').datepicker("setDate", '+2y -1d');
				$(this).siblings('input').change();
			}

			return false;
		});

	});
}

function loadButtonHovers() {
	//all hover and click logic for buttons
	$(".fg-button:not(.ui-state-disabled)")
	.hover(
		function(){
			$(this).addClass("ui-state-hover");
		},
		function(){
			$(this).removeClass("ui-state-hover");
		}
	)
	.mousedown(function(){
			$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
			if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
			else { $(this).addClass("ui-state-active"); }
	})
	.mouseup(function(){
		if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
			$(this).removeClass("ui-state-active");
		}
	});
}

function removeMessage() {
    if(dashMessageElement = document.getElementById('dashMessage')) {
        dashMessageElement.style.display = "none";
    }
}

function pngFix() {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (version < 7) && (document.body.filters))  {
        var el = getElementsByClass('png');
        for(e=0; e<el.length; e++) {
            var realSrc = el[e].src;
            var realWidth = el[e].width;
            var realHeight = el[e].height;
            el[e].src = '/global/images/blank.gif';
            el[e].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + realSrc + "',sizingMethod='scale')";
            el[e].width = realWidth;
            el[e].height = realHeight;
            el[e].style.visibility = "visible";
        }
    }
}

function vcInteractive() {
    if(typeof vcInteractiveTimer == "number") {
      window.clearTimeout(vcInteractiveTimer);
      delete vcInteractiveTimer;
    }
    vcInteractiveTimer = window.setTimeout('vcInteractiveTimeout()', 20000);
}

function vcInteractiveTimeout() {
    var windowLocation = window.location.toString();
    if(windowLocation.substr(windowLocation.length-4, windowLocation.length) != "/dash/") {
        window.location = "/dash/";
    }
}

function vcRefresh() {
    if(typeof vcRefreshTimer == "number") {
      window.clearTimeout(vcRefreshTimer);
      delete vcRefreshTimer;
    }
    vcRefreshTimer = window.setTimeout('vcRefreshTimeout()', 60000 * 10);
}

function vcRefreshTimeout() {
    window.location = "/dash/";
}


function windowResized() {
    if(document.getElementById('dashboard')) {
        var dashColumns = getElementsByClass('dashColumn');
        var dash = document.getElementById('dashboard');
        var dashWidth = dash.clientWidth || dashboard.clientWidth;

        var dashWidth = (window.innerWidth || document.body.offsetWidth) - 180;

        if(dashColumns.length > 1 && dashWidth / 390 >= 2) {
            var colWidth = dashWidth / Math.floor(dashWidth / 390);
            for(i = 0; i < dashColumns.length; i ++) {
                dashColumns[i].style.cssFloat = "left";
                dashColumns[i].style.styleFloat = "left";
                dashColumns[i].style.width = (colWidth - 20)+'px';
            }
        }
        else {
            for(i = 0; i < dashColumns.length; i ++) {
                dashColumns[i].style.cssFloat = "left";
                dashColumns[i].style.styleFloat = "left";
                dashColumns[i].style.width = (dashWidth - 30)+'px';
                //dashColumns[i].style.width = 'auto';
            }
        }
    }
}



function dashColumnOut(el) {
     dashColumnOver(el, true);
}


function dashColumnOver(el, out) {
    // if(out == true) {
    //     el.style.backgroundColor = "#F9FCFF";
    // }
    // else {
    //     el.style.backgroundColor = "#F4FAFF";
    // }

    /*
    var small = getElementsByClass('small', el);

    for(j = 0; j < small.length; j++) {
        if(out == true) {
            small[j].style.visibility = "hidden";
        }
        else {
            small[j].style.visibility = "visible";
        }
    }
    */

}

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    if(classElements.length > 0) return classElements;
    else return false;
}


function statResolution() {
    var screen_w = screen.availWidth || screen.width;
    var screen_h = screen.availHeight || screen.height;
    if(screen_w > 0 && screen_h > 0) {
        imag = new Image();
        imag.src = '/image.php?w='+screen_w+'&h='+screen_h;
    }
}

function validateFormError(field) {
    if(document.getElementById(field)) {
        document.getElementById(field).style.border = '1px solid red';
    }
    if(document.getElementById('formError_'+field)) {
        document.getElementById('formError_'+field).style.display = 'block';
        return true;
    }
    else {
        return false;
    }
}

function validateFormErrorReset(field) {
    if(document.getElementById(field)) {
        document.getElementById(field).style.border = '1px solid green';
    }
    if(document.getElementById('formError_'+field)) {
        document.getElementById('formError_'+field).style.display = 'none';
    }
    return true;
}

function validateForm(form) {
    var msg = "";
    var required;
    var valid = true;

    if(form == null) {
        form = document.forms[0];
    }

    for(i = 0; i < form.elements.length; i++) {
        if(form.elements[i].name == '_required') {
            required = form.elements[i].value.split(",");
        }
    }

    if(document.getElementById(form.name+'_formError')) {
        document.getElementById(form.name+'_formError').style.display = 'none';
    }

    if(required.length > 0) {
        for(i = 0; i < required.length; i ++) {
            if(required[i].length > 0) {
                validateFormErrorReset(form.name+'_'+required[i]);

                for(x = 0; x < form.elements.length; x++) {
                    var checked = false;
                    if(form.elements[x].name == required[i]
                        || form.elements[x].name == required[i]+'[]'
                        || form.elements[x].name.substr(0,required[i].length + 1)  == required[i]+'['
                       ) {
                        if(form.elements[x].type == "checkbox" || form.elements[x].type == "radio") {
                            if(form.elements[x].checked == true) checked = true;
                        }
                        else {
                            if(form.elements[x].value != "") checked = true;
                        }
                        if(checked == true) break;
                    }
                }
                if(checked == false) {
                    if(validateFormError(form.name+"_"+required[i])) {
                        valid = false;
                    }
                    else {
                        msg += "\n"+required[i].replace(/_/g, " ");
                        //alert('yep');
                    }
                }
            }

        }

        if(msg.length > 0 || valid == false) {
            if(msg.length > 0) {
                alert("Please fill in the following fields before submitting:\n"+msg);
            }
            if(document.getElementById(form.name+'_formError')) {
                document.getElementById(form.name+'_formError').style.display = 'block';
            }
            lu_FormFixup(form,1);
            lu_FormFixup(form);
            return false;
        }
        else {
            for(i = 0; i < form.elements.length; i++) {
                // fix spam field
                if(form.elements[i].name == '_spamFix') {
                    form.elements[i].value = 'yes';
                }
            }
            return true;
        }
    }
    return true;
}


function log(msg) {
    if (typeof(console) != 'undefined'){
        console.log(msg);
    }
}

function toggleCalendar(id) {

    if(document.getElementById(id).style.display == 'block') {
		$('.calContainer').parent().hide();
		$('.calendarImage').parent().css('margin-bottom', '0px');
    }
    else {
		$('.calContainer').parent().hide();
		$('.calendarImage').parent().css('margin-bottom', '0px');

        document.getElementById(id).parentNode.style.marginBottom = "105px";
        document.getElementById(id).style.display = 'block';

        if(document.getElementById(id.substr(0, id.length - 10))) {
            document.getElementById(id.substr(0, id.length - 10)).focus();
        }
    }
}

function lu_FormShowHelp2(e) {
    if(document.getElementById(this.id+"_Item")) {
        document.getElementById(this.id+"_Item").style.borderColor = "#3161A3";
        if(document.getElementById(this.id+"_Help")) {
            document.getElementById(this.id+"_Help").style.display = "block";
            var thisID = this.id;
        }
    }
    else {
        // try one more time with a shorter 'ID'
        var new_id = this.id.substr(0, this.id.length - (this.id.split("_")[this.id.split("_").length - 1].length + 1));
        if(document.getElementById(new_id+"_Item")) {
            document.getElementById(new_id+"_Item").style.borderColor = "#3161A3";
            if(document.getElementById(new_id+"_Help")) {
                document.getElementById(new_id+"_Help").style.display = "block";
                var thisID = new_id;
            }
        }
    }
}

var originalBorder;
function lu_FormShowHelp(e) {

    if(document.getElementById(this.id+"_Item")) {
        originalBorder = document.getElementById(this.id+"_Item").style.borderColor;
        document.getElementById(this.id+"_Item").style.borderColor = "#3161A3";
        if(document.getElementById(this.id+"_Help")) {
            document.getElementById(this.id+"_Help").style.display = "block";
            var thisID = this.id;
        }
    }
    else {
        // try one more time with a shorter 'ID'
        var new_id = this.id.substr(0, this.id.length - (this.id.split("_")[this.id.split("_").length - 1].length + 1));
        if(document.getElementById(new_id+"_Item")) {
	        originalBorder = document.getElementById(new_id+"_Item").style.borderColor;
            document.getElementById(new_id+"_Item").style.borderColor = "#3161A3";
            if(document.getElementById(new_id+"_Help")) {
                document.getElementById(new_id+"_Help").style.display = "block";
                var thisID = new_id;
            }
        }
    }

    if(document.getElementById(thisID+"_Help")) {
        if(window.innerWidth > 860 || document.body.offsetWidth > 860) {
            if(browser == "ie7") var marginWidth = "270px";
            else var marginWidth = "470px";
            document.getElementById(thisID+"_Help").style.marginLeft = marginWidth;
            document.getElementById(thisID+"_Help").style.marginTop = "0px";
        }
        else {
            if(browser == "ie7") var marginWidth = "-200px";
            else var marginWidth = "0px";
            document.getElementById(thisID+"_Help").style.marginLeft = marginWidth;
            document.getElementById(thisID+"_Help").style.marginTop = "20px";
        }
    }
}

function lu_FormHideHelp(e) {

    if(document.getElementById(this.id+"_Item")) {
        document.getElementById(this.id+"_Item").style.borderColor = originalBorder;
        if(document.getElementById(this.id+"_Help")) {
            document.getElementById(this.id+"_Help").style.display = "none";
        }
    }
    else {
        // try one more time with a shorter 'ID'
        var new_id = this.id.substr(0, this.id.length - (this.id.split("_")[this.id.split("_").length - 1].length + 1));
        if(document.getElementById(new_id+"_Item")) {
            document.getElementById(new_id+"_Item").style.borderColor = originalBorder;
            if(document.getElementById(new_id+"_Help")) {
                document.getElementById(new_id+"_Help").style.display = "none";
            }
        }
    }
}

function lu_FormMoveSide(form) {
    var formSide = document.getElementById(form.name+'_formSide');

    var formItems = getElementsByClass('formSide', form);
    for(var i = 0; i < formItems.length; i ++) {
        var moveField = formItems[i].parentNode.removeChild(formItems[i]);
        formSide.appendChild(moveField);

        formSide.style.display = "block";
        formSide.style.zIndex = 1;
    }

    var formItemHelp = getElementsByClass('formItemHelp', formSide);
    for(var i = 0; i < formItemHelp.length; i ++) {
        var removeField = formItemHelp[i].parentNode.removeChild(formItemHelp[i]);
    }

    lu_FormFixup(form);
}

function lu_FormFixup(form, num) {
    // fix up label height issues
    var formItems = getElementsByClass('formItem', form);
    var formItemNames = getElementsByClass('formItemName', form);
    var formItemInputs = getElementsByClass('formItemInput', form);

    for(var i = 0; i < formItems.length; i ++) {
        if(formItems[i].className.indexOf("formSide") > -1) {
            var itemHeight = formItemNames[i].offsetHeight + formItemInputs[i].offsetHeight;
        }
        else {
            var itemHeight = Math.max(formItemNames[i].offsetHeight, formItemInputs[i].offsetHeight);
        }

        if(num) {
            itemHeight += num;
        }
        //formItemNames[i].parentNode.parentNode.style.height = itemHeight+'px';
    }
}

/* tooltips */

Array.prototype.inArray = function (value) {
    var i;
    for (i=0; i < this.length; i++) {
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

function addEvent( obj, type, fn ) {
    if (obj.addEventListener) {
        obj.addEventListener( type, fn, false );
        EventCache.add(obj, type, fn);
    }
    else if (obj.attachEvent) {
        obj["e"+type+fn] = fn;
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
        obj.attachEvent( "on"+type, obj[type+fn] );
        EventCache.add(obj, type, fn);
    }
    else {
        obj["on"+type] = obj["e"+type+fn];
    }
}

var tableFilterTimeout;
var tableFilterValue;
function tableFilter(value) {
	if(typeof(tableFilterTimeout) != "undefined") {
		clearTimeout(tableFilterTimeout);
	}
	tableFilterValue = value;
	tableFilterTimeout = setTimeout("tableFilterDelay(tableFilterValue)", 1000);
}

function tableFilterDelay(value) {
	var pattern = value.toLowerCase();
	$('#tableFilterRows').find('.filterRow').each(function(index) {
		if (pattern == "" || $(this).text().toLowerCase().indexOf(pattern) > -1) {
			$(this).css('display', '');
		}
		else {
			$(this).css('display', 'none');
		}
	});
}

function clearTableFilter() {
    document.getElementById('tableFilterBox').value = "";
    tableFilter("");
}

var EventCache = function(){
    var listEvents = [];
    return {
        listEvents : listEvents,
        add : function(node, sEventName, fHandler){
            listEvents.push(arguments);
        },
        flush : function(){
            var i, item;
            for(i = listEvents.length - 1; i >= 0; i = i - 1){
                item = listEvents[i];
                if(item[0].removeEventListener){
                    item[0].removeEventListener(item[1], item[2], item[3]);
                };
                if(item[1].substring(0, 2) != "on"){
                    item[1] = "on" + item[1];
                };
                if(item[0].detachEvent){
                    item[0].detachEvent(item[1], item[2]);
                };
                item[0][item[1]] = null;
            };
        }
    };
}();
addEvent(window,'unload',EventCache.flush);

/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
*/
var sweetTitles = {
    xCord : 0,								// @Number: x pixel value of current cursor position
    yCord : 0,								// @Number: y pixel value of current cursor position
    tipElements : ['a','abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
    obj : Object,							// @Element: That of which you're hovering over
    tip : Object,							// @Element: The actual toolTip itself
    active : 0,								// @Number: 0: Not Active || 1: Active
    init : function() {
        if ( !document.getElementById ||
            !document.createElement ||
            !document.getElementsByTagName ) {
            return;
        }
        var i,j;
        this.tip = document.createElement('div');
        this.tip.id = 'toolTip';
        document.getElementsByTagName('body')[0].appendChild(this.tip);
        this.tip.style.top = '0';
        this.tip.style.visibility = 'hidden';
        var tipLen = this.tipElements.length;
        for ( i=0; i<tipLen; i++ ) {
            var current = document.getElementsByTagName(this.tipElements[i]);
            var curLen = current.length;
            for ( j=0; j<curLen; j++ ) {
                if(current[j].title.length > 0) {
                    addEvent(current[j],'mouseover',this.tipOver);
                    addEvent(current[j],'mouseout',this.tipOut);
                    current[j].setAttribute('tip',current[j].title);
                    current[j].removeAttribute('title');
                }
            }
        }
    },
    updateXY : function(e) {
        if ( document.captureEvents ) {
            sweetTitles.xCord = e.pageX;
            sweetTitles.yCord = e.pageY;
        } else if ( window.event.clientX ) {
            sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
            sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
        }
    },
    tipOut: function() {
        if ( window.tID ) {
            clearTimeout(tID);
        }
        if ( window.opacityID ) {
            clearTimeout(opacityID);
        }
        sweetTitles.tip.style.visibility = 'hidden';
    },
    checkNode : function() {
        var trueObj = this.obj;
        if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
            return trueObj;
        } else {
            return trueObj.parentNode;
        }
    },
    tipOver : function(e) {
        sweetTitles.obj = this;
        tID = window.setTimeout("sweetTitles.tipShow()",50);
        sweetTitles.updateXY(e);
    },
    tipShow : function() {
        var scrX = Number(this.xCord);
        var scrY = Number(this.yCord);
        var tp = parseInt(scrY+15);
        var lt = parseInt(scrX+10)+70;
        var anch = this.checkNode();
        var addy = '';
        var access = '';

		this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
		if($(this.tip).width() > 300) {
			$(this.tip).width(300);
		}
		this.tip.style.display = 'none';
		this.tip.style.visibility = 'visible';
		
		if(($(this.tip).height() + tp) - $(window).scrollTop() > $(window).height()) {
			this.tip.style.top = (($(window).scrollTop() + $(window).height()) - ($(this.tip).height() + 40))+'px';
			this.tip.style.left = (lt - this.tip.offsetWidth) + 'px';
		}
		else {
			this.tip.style.top = tp+'px';
			this.tip.style.left = (lt - this.tip.offsetWidth/2) + 'px';
		}

		if(($(this.tip).width() + lt) - $(window).scrollLeft() > $(window).width()) {
			this.tip.style.left = (lt - (this.tip.offsetWidth + $(this.tip).width() + 40)) + 'px';
		}
		
		$(this.tip).bgiframe();
		$(this.tip).fadeIn('fast');
    }
};


var filterlistTimeout;
var filterlistValue;
function lu_FilterList(e, array) {
	if(typeof(filterlistTimeout) != "undefined") {
		clearTimeout(filterlistTimeout);
		log('filterlist: cleartimeout: '+document.getElementById(array[1]).value);
	}

	filterlistValue = array;
	filterlistTimeout = setTimeout("filterListDelay(filterlistValue)", 500);
	log('filterlist: timeout: '+document.getElementById(array[1]).value);
}

function filterListDelay(array) {
    el = document.getElementById(array[0]);
    filter = document.getElementById(array[1]).value;
	log('filterlist: delay: '+filter);
    array[0].set(filter);
}

function filterlist(selectobj) {

	this.selectobj = selectobj;

	this.init = function() {
		log('filterlist: init');

		if (!this.selectobj) return false;
		if (!this.selectobj.options) return false;

		this.optionscopy = new Array();
		if (this.selectobj && this.selectobj.options) {
			for (var i=0; i < this.selectobj.options.length; i++) {

				this.optionscopy[i] = new Option();
				this.optionscopy[i].text = selectobj.options[i].text;

				if (selectobj.options[i].value) {
					this.optionscopy[i].value = selectobj.options[i].value;
				} else {
					this.optionscopy[i].value = selectobj.options[i].text;
				}
			}
		}
	}

	this.reset = function() {
		log('filterlist: reset');
		this.set('');
	}

	this.set = function(pattern) {
		log('filterlist: set: '+pattern);

		var selectParentNode = this.selectobj.parentNode;
		var newSelectObj = this.selectobj.cloneNode(false); // Make a shallow copy
		selectParentNode.replaceChild(newSelectObj, this.selectobj);
		this.selectobj = newSelectObj;

		var loop=0, index=0, e;

		if (!this.selectobj) return false;
		if (!this.selectobj.options) return false;

		if(pattern == "") {
			log('filterlist: clear');
			for (loop=0; loop < this.optionscopy.length; loop++) {
				var option = this.optionscopy[loop];
				this.selectobj.options[index++] = new Option(option.text, option.value, false);
			}
		}
		else {
			pattern = pattern.toLowerCase();
			for (loop=0; loop < this.optionscopy.length; loop++) {
				var option = this.optionscopy[loop];
				if (option.text.toLowerCase().indexOf(pattern) == 0) {
					log('found: '+option.text.toLowerCase());
					this.selectobj.options[index++] = new Option(option.text, option.value, false);
				}
			}
			for (loop=0; loop < this.optionscopy.length; loop++) {
				var option = this.optionscopy[loop];
				if (option.text.toLowerCase().indexOf(pattern) > 0) {
					this.selectobj.options[index++] = new Option(option.text, option.value, false);
				}
			}
		}
	}
	this.init();
}


function printReport(id) {
	if(id) {
		$('.reportReport').addClass('noprint');
		$('#reportReport_'+id).removeClass('noprint');
	}
	else {
		$('.reportReport').removeClass('noprint');
	}

	print();
}



AttachEvent(window, "load", LoadEvents);


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/*
 * jQuery Caret Range plugin
 * Copyright (c) 2009 Matt Zabriskie
 * Released under the MIT and GPL licenses.
 */
(function($) {
	$.extend($.fn, {
		caret: function (start, end) {
			var elem = this[0];

			if (elem) {
				// get caret range
				if (typeof start == "undefined") {
					if (elem.selectionStart) {
						start = elem.selectionStart;
						end = elem.selectionEnd;
					}
					else if (document.selection) {
						var val = this.val();
						var range = document.selection.createRange().duplicate();
						range.moveEnd("character", val.length)
						start = (range.text == "" ? val.length : val.lastIndexOf(range.text));

						range = document.selection.createRange().duplicate();
						range.moveStart("character", -val.length);
						end = range.text.length;
					}
				}
				// set caret range
				else {
					var val = this.val();

					if (typeof start != "number") start = -1;
					if (typeof end != "number") end = -1;
					if (start < 0) start = 0;
					if (end > val.length) end = val.length;
					if (end < start) end = start;
					if (start > end) start = end;

					elem.focus();

					if (elem.selectionStart) {
						elem.selectionStart = start;
						elem.selectionEnd = end;
					}
					else if (document.selection) {
						var range = elem.createTextRange();
						range.collapse(true);
						range.moveStart("character", start);
						range.moveEnd("character", end - start);
						range.select();
					}
				}

				return {start:start, end:end};
			}
		}
	});
})(jQuery);
