	var frosty_containerOffsetTop;
	var frosty_previousSize = [0,0];
	var frosty_scrollOffset = jQuery.browser.mozilla ? 25 : 28;
	var frosty_isOldBrowser = jQuery.browser.msie && jQuery.browser.version < 7 ? true : false;
	var frosty_isFirstLoad = true;

	//
	// JQUERY METHOD
	//
	// Takes a jQuery object array and options object and passes them
	// to createTable.
	//
	jQuery.fn.frostyGrid = function(options) {
		options = jQuery.extend({
			freezeColumns : 2,
			sizeToViewport : false,
			paddingBottom : 0,
			height : 300,
			width : 500
		}, options);	
		return this.each(function(){
			init(this, options);
		});
	};

	//
	// CREATE TABLE
	//
	// Takes a standard table and creats a frosty grid.
	//
    function init(table, options) {
        var state = jQuery.extend({
            containerTop : null, 
            cellWidths : new Array(), 
            cellHeights : new Array()
        }, options);	

        var $sourceTable = jQuery(table);

        // Index Column Widths and Row Heights
        getWidths($sourceTable, state);
        getHeights($sourceTable, state);

        // Create table elements
        $container = createTable($sourceTable, state);

        // Insert Assembled table into the DOM before source table
        table.parentNode.insertBefore($container[0],table);

        setCommonStyles($container, $sourceTable);

        // Hook Up Events
        $container.find(".bottomRightDiv").scroll(syncScroll);

        if (options.sizeToViewport) {
            resize($container, state);
            jQuery(window).bind('resize', state, sizeToWindow);
            $container.addClass('_resizable');
        }
        else {
          setFixedSize($container, state);
        }
	}
  
    function createTable($sourceTable, state) {
        var $container = jQuery(createElement('div', 'scrollContainer'));
        var $structureTable = jQuery(createElement('table', 'structureTable'));

        var topLeftTable = createTopLeftTable($sourceTable, state);
        var topRightTable = createTopRightTable($sourceTable, state);
        var bottomLeftTable = createBottomLeftTable($sourceTable, state);
        var bottomRightTable = createBottomRightTable($sourceTable, state);

        var structureTHead = document.createElement('thead');
        var structureTBody = document.createElement('tbody');
        var structureRow1 = document.createElement('tr');
        var structureRow2 = document.createElement('tr');
        var $topLeftCell = jQuery(createElement('td', 'topLeftCell'));
        var $topRightCell = jQuery(createElement('td','topRightCell'));
        var $bottomLeftCell = jQuery(createElement('td','bottomLeftCell'));
        var $bottomRightCell = jQuery(createElement('td','bottomRightCell'));
        var $topRightDiv = jQuery(createElement('div','topRightDiv'));
        var $bottomRightDiv = jQuery(createElement('div','bottomRightDiv'));
        var $bottomLeftDiv = jQuery(createElement('div','bottomLeftDiv'));
        var $topLeftDiv = jQuery(createElement('div','topLeftDiv'));

        // Assemble final table(S)
        $topLeftDiv[0].appendChild(topLeftTable);
        $topRightDiv[0].appendChild(topRightTable);
        $bottomLeftDiv[0].appendChild(bottomLeftTable);
        $bottomRightDiv[0].appendChild(bottomRightTable);

        $topLeftCell[0].appendChild($topLeftDiv[0]);
        $bottomLeftCell[0].appendChild($bottomLeftDiv[0]);
        $topRightCell[0].appendChild($topRightDiv[0]);
        $bottomRightCell[0].appendChild($bottomRightDiv[0]);

        structureRow1.appendChild($topLeftCell[0]);
        structureRow1.appendChild($topRightCell[0]);
        structureRow2.appendChild($bottomLeftCell[0]);
        structureRow2.appendChild($bottomRightCell[0]);

        structureTHead.appendChild(structureRow1);
        structureTBody.appendChild(structureRow2);
        $structureTable[0].appendChild(structureTHead);
        $structureTable[0].appendChild(structureTBody);

        $container[0].appendChild($structureTable[0]);

        return $container;
    }

    //
    // RESIZE
    //
    // Resize branch for most browser. Liquid mode only.
    //
    function resize($container, state) {
		
		if (frosty_isOldBrowser) {
			resizeIE6($container, state);
			return;
		}

		var $t = $container.find('table.structureTable');
		
		if ($t.length == 0 || $container.length == 0) return;

		var $body = jQuery('body');
		var $leftDiv = $t.find('.bottomLeftDiv');
		var $headDiv = $t.find('.topRightDiv');
		var $bodyDiv = $t.find('.bottomRightDiv');
		var bodyWidth = $body.innerWidth();
		var bodyHeight = $body.innerHeight();
	
		if (!frosty_containerOffsetTop) {
			frosty_containerOffsetTop = $container.offset().top;
		}
		else {
			// This is for IE7 which calculates offset incorrectly after a resize
			// (though it calculates findPos wrong before a resize, go figure)
			frosty_containerOffsetTop = findPos($container[0])[1] ;
		}

		// if there's a footer (named footer), calculate it
		var $footer = $body.find('.footer');   
		if ($footer.length > 0) {
			frosty_containerOffsetTop += $footer.height();
		}
		
		if (state.paddingBottom) {
			frosty_containerOffsetTop =  frosty_containerOffsetTop + state.paddingBottom;
		}

		if (bodyHeight > frosty_containerOffsetTop) {
			$container.height(bodyHeight-frosty_containerOffsetTop);
		}

		var width = $container.innerWidth();
		var height = $container.innerHeight();
		var leftWidth = $leftDiv.innerWidth();
   		
		if (width > leftWidth) {
			$headDiv.width(width-leftWidth-18);
			$bodyDiv.width(width-leftWidth);

			if (height >= frosty_scrollOffset) {
			    $bodyDiv.height(height - frosty_scrollOffset - ($bodyDiv.find('tr').length == 0 ? 4 : 2));
			}
			if (height >= 42) {
			  $leftDiv.height(height-42);
			}
		}
	}
		
	//
	// RESIZE IE6
	//
	// Resize branch specifically for IE6.
	// Known bug: does not work when making the window 
	// smaller (because IE6 sucks).
	//
	function resizeIE6($container, state)  {
		
		var isWidthSmaller = false;
		var isHeightSmaller = false;
		var lastSize = frosty_previousSize;
		var currentSize = getViewportSize();
		
		// This check is neccessary to stop IE6 from resizing itself infinitely
		if (currentSize[0] != frosty_previousSize[0] || currentSize[1] != frosty_previousSize[1]) {
				isWidthSmaller = (currentSize[0] < frosty_previousSize[0]);
				isHeightSmaller = (currentSize[1] < frosty_previousSize[1]);
		  frosty_previousSize = currentSize;
		}
		else return;

		var $t = $container.find('table.structureTable');

		if ($t.length == 0 || $container.length == 0) return;

		var $body = jQuery('body');
		var $leftDiv = $t.find('.bottomLeftDiv');
		var $headDiv = $t.find('.topRightDiv');
		var $bodyDiv = $t.find('.bottomRightDiv');

		//var bodyWidth = $body.innerWidth();
		//var bodyHeight = $body.innerHeight();
	
		if (!frosty_containerOffsetTop) {
			frosty_containerOffsetTop = $container.offset().top;
		}
		else {
			// This is for IE7 which calculates offset incorrectly after a resize
			// (though it calculates findPos wrong before a resize, go figure)
			frosty_containerOffsetTop = findPos($container[0])[1] ;
		}

		// if there's a footer (named footer), calculate it
		var $footer = $body.find('.footer');   
		if ($footer.length > 0) {
			frosty_containerOffsetTop += $footer.height();
		}
		
		if (state.paddingBottom) {
			frosty_containerOffsetTop =  frosty_containerOffsetTop + state.paddingBottom;
		}

		var width = currentSize[0]-23;
		var height = currentSize[1]-frosty_containerOffsetTop;
		var leftWidth = $leftDiv.innerWidth();

		$container.width(currentSize[0]-23);
		$container.height(currentSize[1]-frosty_containerOffsetTop);
   		
		if (width > leftWidth) {
			$headDiv.width(width-leftWidth-18);
			$bodyDiv.width(width-leftWidth);

			if (height >= frosty_scrollOffset)  {
			  $bodyDiv.height(height-frosty_scrollOffset);
			}
			if (height >= 42) {
			  $leftDiv.height(height-42);
			}
		}
	
		// Needed for IE to prevent resizing itself
		frosty_isFirstLoad = false;
	}
		
	//
	// SET COMMON STYLES
	//
	// Sets the bare minimum styles needed to make the 
	// grid work for both fixed and liquid grids.
	//
	function setCommonStyles($container, $sourceTable) {
		// Set Default Styles
		$sourceTable.css('display','none');
        
		$container.find(".structureTable")
			.css('border-collapse','collapse')
			.css('padding','0')
			.css('margin','0');
		
		$container.find(".topLeftCell")
			.css('padding','0')
			.css('margin','0');
		$container.find(".topRightCell")
			.css('padding','0')
			.css('margin','0');
		$container.find(".bottomLeftCell")
			.css('padding','0')
			.css('margin','0')
			.css('vertical-align','top');
		$container.find(".bottomRightCell")
			.css('padding','0')
			.css('margin','0');
		
		$container.find(".bottomLeftDiv").css('overflow','hidden');
		$container.find(".topRightDiv").css('overflow','hidden');
		$container.find(".bottomRightDiv").css('overflow','scroll');
	}
	
	//
	// SET FIXED SIZE
	//
	function setFixedSize($container, state) {
		var $topRightDiv = $container.find(".topRightDiv");
		var $bottomLeftDiv = $container.find(".bottomLeftDiv");
		
		var headerHeight = $topRightDiv.height();
		var frozenWidth = $bottomLeftDiv.width();
		
		$container
			.css('width', state.width)
			.css('height', state.height);
		
		$topRightDiv.css('width',state.width-frozenWidth);
		$bottomLeftDiv.css('height',state.height-headerHeight);
		$container.find(".bottomRightDiv")
		    .css('height',state.height-headerHeight)
		    .css('width',state.width-frozenWidth);
	}
	
	//
	// FIND POSITION
	//
	// Calculates an accurate position for an object by 
	// traversing the DOM via parent nodes.
	//
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}

	//
	// GET VIEWPORT SIZE
	//
	// Get the overall viewport size. This method is more
	// accurate than the equivalent jQuery (+dimensions) method.
	//
	function getViewportSize() {
    var size = [0, 0];
    // Firefox/Safari
    if (typeof window.innerWidth != 'undefined') {
     size = [window.innerWidth, window.innerHeight];
    }
    // IE 6/7 Standards Mode
    else if (typeof document.documentElement != 'undefined' &&
			 typeof document.documentElement.clientWidth != 'undefined' &&
			 document.documentElement.clientWidth != 0) {
     size = [document.documentElement.clientWidth, 
			document.documentElement.clientHeight];
    }
    // IE 6/7 Quirks Mode
    else {
     size = [document.getElementsByTagName('body')[0].clientWidth,
			document.getElementsByTagName('body')[0].clientHeight];
    }
    return size;
  }

	//
	// CREATE ELEMENT
	//
	//	Shortcut method to create the element and set it's className
	//	at the same time to save some typing.
	//
	function createElement(elementName, elementId) {
		var e = document.createElement(elementName);
		if (elementId) {
			e.className = elementId;
		}
		return e;
	}
 
	//
	// CREATE TOP LEFT TABLE
	//
	// Creates the upper left table which 
	// contains the frozen header cells.
	//
  function createTopLeftTable($sourceTable, state) {
    var $topLeftTable = jQuery($sourceTable[0].cloneNode(true));
    var $thead = $topLeftTable.find("thead");
    $thead.find("th:gt(" + (state.freezeColumns-1) + ")").each(function(){this.parentNode.removeChild(this);});
    $topLeftTable.find("tbody").each(function(){this.parentNode.removeChild(this);});
    addSpacers($sourceTable[0], $thead[0], 0, 0, state);
    $topLeftTable.addClass('topLeftTable');
    return $topLeftTable[0];
  }

  //
  // CREATE TOP RIGHT TABLE
  //
  // Creates the upper right table which 
  // contains the unfrozen header cells.
  //
  function createTopRightTable($sourceTable, state){
    var $topRightTable = jQuery($sourceTable[0].cloneNode(true));
    var $thead = $topRightTable.find("thead");
    $thead.find("th:lt(" + state.freezeColumns + ")").each(function(){this.parentNode.removeChild(this);});
    $topRightTable.find("tbody").each(function(){this.parentNode.removeChild(this);});
    addSpacers($sourceTable[0], $thead[0], state.freezeColumns, 0, state);
    $topRightTable.addClass('topRightTable');
    return $topRightTable[0];
  }

  //
  // CREATE BOTTOM LEFT TABLE
  //
  // Creates the bottom left table which 
  // contains the frozen body cells.
  //
  function createBottomLeftTable($sourceTable, state) {
	  var $bottomLeftTable = jQuery($sourceTable[0].cloneNode(true));
	  var $tbody = $bottomLeftTable.find("tbody");
	  $tbody.find("tr").each(function(){
        jQuery(this).find("td:gt(" + (state.freezeColumns-1) + ")").each(function(){this.parentNode.removeChild(this);});
	  });
	  $bottomLeftTable.find("thead").each(function(){this.parentNode.removeChild(this);});
      addSpacers($sourceTable[0], $tbody[0], 0, 0, state);
	  $bottomLeftTable.addClass('bottomLeftTable');
    return $bottomLeftTable[0];
  }

  //
  // CREATE BOTTOM RIGHT TABLE
  //
  // Creates the bottom right table which 
  // contains the unfrozen body cells.
  //
  function createBottomRightTable($sourceTable, state) {
	  var $bottomRightTable = jQuery($sourceTable[0].cloneNode(true));
	  var $tbody = $bottomRightTable.find("tbody");
	  $tbody.find("tr").each(function(){
        jQuery(this).find("td:lt(" + state.freezeColumns + ")").each(function(){this.parentNode.removeChild(this);});
	  });
	  $bottomRightTable.find("thead").each(function(){this.parentNode.removeChild(this);});
	  addSpacers($sourceTable[0], $tbody[0], state.freezeColumns, 0, state);   
	  $bottomRightTable.addClass('bottomRightTable');
      return $bottomRightTable[0];
	}
	
	//
	// GET WIDTHS
	//
	// Gets all of the column widths in the 
	// source table and caches them in the state 
	// object.
	//
	function getWidths($table, state) {
		var $thead = $table.find('thead');
		var $cells = $thead.find('tr:first th');
		$cells.each(function(index) {
			var width = 0;
 			if (this.offsetWidth > width) width = this.offsetWidth;
			state.cellWidths[index] = width;
		});
	}
	
	//
	// GET HEIGHTS
	//
	// Gets all of the row heights in the 
	// source table and caches them in the state 
	// object.
	//
	function getHeights($table, state) {
		$table.find('TR').each(function(rowIndex){
			var height = this.offsetHeight;
			// Safari 1/2, check each cell in the row to get the maximum height
			if (height == 0) {
				jQuery(this).find('TH,TD').each(function(cellIndex){
					if (this.offsetHeight > height) {
						height = this.offsetHeight;
					}
				});
			}
			state.cellHeights[rowIndex] = height;
		});
	}

	//
	// ADD SPACERS
	//
	// Adds the spacer cells and rows that enforce the column/row
	// sizes between the separate component tables.
	// 
	//
	function addSpacers(table, container, columnStartIndex, rowStartIndex, state) {
		// right hand spacers
		var tagName = container.tagName == 'THEAD' ? 'TH' : 'TD';
		var rows = container.getElementsByTagName('TR');

		if (rows.length == 0) return;
		
		for (i = rowStartIndex; i < rows.length; i++) {
			var tr = rows[i];
			if (container.tagName == 'THEAD')  {
				tr.appendChild(createSpacerCell(state.cellHeights[i], 1, tagName));
			}
			else if (container.tagName == 'TBODY') {
				tr.appendChild(createSpacerCell(state.cellHeights[i+1], 1, tagName));
			}
		}

		// Spacer row
		var cells;
		if (container.tagName == 'THEAD')  {
			cells = rows[0].getElementsByTagName('TH');
		}
		else if (container.tagName == 'TBODY'){
			cells = rows[0].getElementsByTagName('TD');
		}
		var spacerRow = document.createElement('TR');
		spacerRow.style.height = '1px';

		for (i = columnStartIndex; i < (cells.length + columnStartIndex -1); i++)  {
			var width = state.cellWidths[i];
			if (width == 0) width = 1; 
			var cell = createSpacerCell(1,width, tagName);
			spacerRow.appendChild(cell);
		}
		var cell = createSpacerCell(1,1, tagName);
		spacerRow.appendChild(cell);
		
		container.appendChild(spacerRow);
	}

	//
	// CREATE SPACER CELL
	//
	// Creates the cell and image for a spacer to save 
	// typing.	
	//
	function createSpacerCell(height, width, tagName) {
		if (!height) height = 0;
		if (!width) width = 0;
		var scell = document.createElement(tagName);
		var simg = document.createElement('img');
		scell.style.border = '0px';
		scell.style.padding = '0px';
		scell.style.margin = '0px';
		scell.style.lineHeight = '0px';
		scell.style.background = '';
		scell.style.height = height + 'px';
		scell.style.width = width + 'px';
		simg.src='Styles/images/spacer.gif';
		simg.style.height = height + 'px';
		simg.style.display = 'block';
		simg.style.width = width + "px";
		scell.appendChild(simg);
		return scell;
	}

	//
	// SIZE TO WINDOW (EVENT)
	//
	// The event called when a browser is resized.
	//
	function sizeToWindow(e) {
		resize(jQuery('div._resizable'), e.data);
	}

	//
	// SIZE IE6 (EVENT)
	//
	// The event called at the end of a browser resize during the mouseup event.
	// (may not be perfect)
	//
	function sizeIE6() {
		resize(jQuery('div._resizable'), e.data);
	}
	
	
	//
	// SYNC SCROLL (EVENT)
	//
	// The event called when the body (lower right) div
	// is scrolled.
	//
	function syncScroll(e) {
		// 'Pure DOM' method, more code than jQuery, but speedier scrolling in IE
		var sender = e.target;
		var parent = sender.parentNode;
		while (parent.className != 'structureTable') {
			parent = parent.parentNode;
		}
		var bottomRight, topRight, bottomLeft;
		var divs = parent.getElementsByTagName('DIV');
		for (var i = 0; i < divs.length; i++) {
			var div = divs[i];
			if (div.className == 'bottomRightDiv') bottomRight = div;
			else if (div.className == 'topRightDiv') topRight = div;
			else if (div.className == 'bottomLeftDiv') bottomLeft = div;
		}
		if (!bottomRight || !topRight || !bottomLeft) return;
		
		topRight.scrollLeft = bottomRight.scrollLeft;
		bottomLeft.scrollTop = bottomRight.scrollTop;
	}
function IsDate(DateToCheck){
  if (DateToCheck==""){return true;}
  var date_array = DateToCheck.split('/');
  var month = date_array[0] - 1;
  var day = date_array[1];
  var year = date_array[2];
  source_date = new Date(year, month, day);
  if (year != source_date.getFullYear()) {
      return false;
  }
  if (month != source_date.getMonth()) {
      return false;
  }
  if (day != source_date.getDate()) {
      return false;
  }
  return true;
}

// From Apriori Library
function IsNumeric(VALUE){
	for(var ivA = 0; ivA < VALUE.length;ivA ++){
		if(VALUE.charCodeAt(ivA) < 48 || VALUE.charCodeAt(ivA) > 57){
			if(VALUE.charCodeAt(ivA) != 46 && VALUE.charCodeAt(ivA) != 32 && VALUE.charAt(ivA) != ","){
			return false;
			}
		}																					
	}
	return true;
}

function IsNumeric(VALUE){
	for(var ivA = 0; ivA < VALUE.length;ivA ++){
		if(VALUE.charCodeAt(ivA) < 48 || VALUE.charCodeAt(ivA) > 57){
			if(VALUE.charCodeAt(ivA) != 46 && VALUE.charCodeAt(ivA) != 32 && VALUE.charAt(ivA) != ","){
			return false;
			}
		}																					
	}
	return true;
}

function getSrcElement(e) {
	if ( typeof( window.event ) != "undefined" ) {
		return window.event.srcElement;
	}
	if ( e != null && typeof( e.target ) != "undefined" ) {
		return e.target;
	}
	if (e != null && e != undefined) {
		return e;
	}
	return null;
}

function countLeft(e) {
	var sender = getSrcElement(e);
	if (!sender) return;
	var parent = sender.parentNode;
	if (!parent) return;
	var counter;
	var inputs = parent.getElementsByTagName('INPUT');

	// Find the counter input
	for (i = 0; i < inputs.length; i++) {
		var element = inputs[i];
		if (element.className == 'counter') {
			counter = element;
		}
	}

	var max = maxLens[sender.id];
	//field, count, max

	if (sender.value.length > max)
		sender.value = sender.value.substring(0, max);
	else {
		counter.value = max - sender.value.length;
	}
}

function initCounters() {
	maxLens = {};
	var controls = document.getElementsByTagName('TEXTAREA');
	var additionalControls = document.getElementsByTagName('INPUT');

	for (i = 0; i < additionalControls.length; i++) {
		controls[controls.length] = additionalControls[i];
	}
	
	var x = 0;
	for (i = 0; i < controls.length; i++) {
		var control = controls[i];
		if (control.className.indexOf('counter_enabled') > -1) {
			var parent = control.parentNode;
			var spans = parent.getElementsByTagName('SPAN');
			// Find the counter total span
			for (x = 0; x < spans.length; x++) {
				var element = spans[x];
				if (element.className == 'counter_total') {
					total = Number(element.innerHTML);
					break;
				}
			}

			control.onkeydown = countLeft;
			control.onkeyup = countLeft;
			maxLens[control.id] = total;
			countLeft(control);
		}
	}
}
			
function confirmDelete() {
	return confirm( "Are you sure you want to delete this item?" );
}

//
// Alert user on unsaved changes
//
function setConfirmUnload(on) {
     window.onbeforeunload = (on) ? unloadMessage : null;
}

function unloadMessage() {
     return 'You have entered new data on this page.  If you navigate away from this page without first saving your data, the changes will be lost.';
}

function lookForChanges() {
	$(':input').bind("change", function(){ 
		setConfirmUnload(true);
	});
	$('form').bind('submit', function() {
		setConfirmUnload(false);
	});
}﻿$(document).ready(function() {
    $("fieldset .ctrl_group:nth-child(odd)").addClass("odd");
    $('fieldset label, fieldset input, fieldset textarea, fieldset select').focus(function() {
        $(this).parents('.ctrl_group').addClass("over");
    }).blur(function() {
        $(this).parents('.ctrl_group').removeClass("over");
    });

    $('.ctrl_group').each(function() {
        var $this = $(this);
        $this.append('<div class="clear"></div>');
        var height = $this.height();
        var diff = (height % 34);
        if (diff > 0) $this.height(height + (34 - diff));
    });
});