function doVoid(){
}

function doisnull(xVal)
{
	if ($.trim(xVal)==null || $.trim(xVal)=="")
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isValidEmail(xVal)
{
	var cEmail = $.trim(xVal)
	var atpos=cEmail.indexOf("@");
	var dotpos=cEmail.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=cEmail.length)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function isAlpha(str){
	var re = /[^a-zA-Z]/g
	if (re.test(str)) return false;
	return true;
}
function isNumeric(str){
	var re = /[\D]/g
	if (re.test(str)) return false;
	return true;
}
function isZipCode(strZip){
	var reZip = /^\d{5}(-\d{4})?$/g
	if (reZip.test(strZip)) return true;
	return false;
}
function isAlphaNumeric(strAlpha){
	var re = /[^a-zA-Z0-9]/g
	if (re.test(strAlpha)) return false;
	return true;
}
function isLengthBetween(str, min, max){
  return (str.length >= min)&&(str.length <= max);
}

$(document).ready(function(){

	if ($('#heightAdjuster').length != 0)
	{
		var footerheight = $('#designBase').height()
		var p = $('#heightAdjuster').offset();
		$('#heightAdjuster').css("height",$(window).height()-p.top-$('#footer').outerHeight(false));
	}
})

function handleCheckBox(strPre, strActual){
	$('#' + strPre).click(function(){
		if($('#' + strPre).is(':checked')){
			$('#' + strActual).val("1");
		}else{
			$('#' + strActual).val("0");
		}
	});
}

function showInfoBar(strtype,caption){
	if ($('#infoBar').length == 0){
	 $(document.body).append("<div id='infoBarPlaceHolder'></div><div style='overflow: hidden'><div class='infoBar' id='infoBar'><table border='0' width='100%'><tr nowrap><td><table border='0'><tr nowrap><td width='40'>&nbsp;</td><td><img src='/images/paperlink2.gif' border='0'></td><td align=left id='infoBarContent' class='infoBarContent'><div id='infoCenterText'></div></td></tr></table></td><td width=60 align=left><div id='infoClose'>[close]</div></td></tr></table></div></div>");
	}
	$("#infoCenterText").html('RTSynergy Info Center: ' + caption + '');
	$("#infoClose").click(function(){
		$("#infoBar").stop(); // MUST DO THIS TO STOP CURRENT 10 SECOND ANIMATION TO CLOSE
		$('#infoBar').animate({ marginTop: '-' + $('#infoBar').height() + 'px' }, function () {
			$('#infoBar').hide();
			});

		//$("#infoBar").slideUp(400);
		});
	$("#infoClose").css("cursor","pointer");
	$("#infoBar").css("marginTop","-" + $('#infoBar').height() + 'px')
	$("#infoBar").hide();
	//$("#infoBar").css("position","absolute");

	$(window).resize(info_position);
	info_position();


	//$('#infoBar').show();
	//$('#infoBar').animate({ marginTop: '0px' });

	//$("#infoBar").show( "drop", "down" );
	//$("#infoBar").slideDown(400).delay(10000).slideUp(400);

	$('#infoBar').show();
	$('#infoBar').animate({ marginTop: '0px' }).delay(10000);
	$('#infoBar').animate({ marginTop: '-' + $('#infoBar').height() + 'px' }, function () {
		$('#infoBar').hide();
		});

}



function encodeUrl(url)
{
 	if (url.indexOf("?")>0)
 	{
		encodedParams = "?";
 		parts = url.split("?");
 		params = parts[1].split("&");
 		for(i = 0; i < params.length; i++)
 		{
			if (i > 0)
	 		{
				encodedParams += "&";
			}
			if (params[i].indexOf("=")>0) //Avoid null values
			{
				p = params[i].split("=");
				encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
			}
			else
			{
				encodedParams += params[i];
			}
		}
		url = parts[0] + encodedParams;
	}
	return url;
}

function left(str,n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


 // AUTOGROW by Chrys Bader (www.chrysbader.com)

(function(jQuery) {

	var self = null;

	jQuery.fn.autoGrow = function(o)
	{
		return this.each(function() {
			new jQuery.autoGrow(this, o);
		});
	};


    /**
     * The autogrow object.
     *
     * @constructor
     * @name jQuery.autogrow
     * @param Object e The textarea to create the autogrow for.
     * @param Hash o A set of key/value pairs to set as configuration properties.
     * @cat Plugins/autogrow
     */

	jQuery.autoGrow = function (e, o)
	{
		this.options		  	= o || {};
		this.dummy			  	= null;
		this.interval	 	  	= null;
		this.line_height	  	= this.options.lineHeight || parseInt(jQuery(e).css('line-height'));
		this.min_height		  	= this.options.minHeight || parseInt(jQuery(e).css('min-height'));
		this.max_height		  	= this.options.maxHeight || parseInt(jQuery(e).css('max-height'));;
		this.textarea		  	= jQuery(e);
		this.expand_tolerance	= (!isNaN(this.options.expandTolerance) && this.options.expandTolerance > 0) ? this.options.expandTolerance : 1;

		if(isNaN(this.line_height))
		  this.line_height = 20; // YOU NEED A DEFAULT FOR SAFARI

		// Only one textarea activated at a time, the one being used
		this.init();
	};

	jQuery.autoGrow.fn = jQuery.autoGrow.prototype = {
    	autoGrow: '1.2.3'
  	};

 	jQuery.autoGrow.fn.extend = jQuery.autoGrow.extend = jQuery.extend;

	jQuery.autoGrow.fn.extend({
		init: function() {
			var self = this;
			this.textarea.css({overflow: 'hidden', display: 'block'});
			this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand() });
			this.checkExpand();
		},

		startExpand: function() {
		  var self = this;
			this.interval = window.setInterval(function() {self.checkExpand()}, 400);
		},

		stopExpand: function() {
			clearInterval(this.interval);
		},

		checkExpand: function() {
			if (this.dummy == null) {
				this.dummy = jQuery('<div></div>');
				this.dummy.css({
					'font-size'  : this.textarea.css('font-size'),
					'font-family': this.textarea.css('font-family'),
					'width'      : this.textarea.css('width'),
					'padding'    : this.textarea.css('padding'),
					'line-height': this.line_height + 'px',
					'overflow-x' : 'hidden',
					'position'   : 'absolute',
					'top'        : 0,
					'left'		 : -9999
					}).appendTo('body');
			} else {
				// If the dummy was already created, show it as it is hidden after expansion
				this.dummy.show();
			}

			// Strip HTML tags
			var html = this.textarea.val().replace(/(<|>)/g, '');

			// IE is different, as per usual
			if (jQuery.browser.msie) {
				html = html.replace(/\n/g, '<BR/>new');
			}
			else {
				html = html.replace(/\n/g, '<br/>new');
			}

			if (this.dummy.html() != html) {
				this.dummy.html(html);
				if (this.max_height > 0 && (this.dummy.height() + (this.expand_tolerance*this.line_height) > this.max_height)) {
					this.textarea.css('overflow-y', 'auto');
					if (this.textarea.height() < this.max_height) {
						this.textarea.animate({height: (this.max_height + (this.expand_tolerance*this.line_height)) + 'px'}, 100);
					}
				}
				else {
					this.textarea.css('overflow-y', 'hidden');
					if (this.textarea.height() < this.dummy.height() + (this.expand_tolerance*this.line_height) || (this.dummy.height() < this.textarea.height())) {
						if (this.dummy.height() < this.min_height) {
							this.textarea.animate({height: (this.min_height + (this.expand_tolerance*this.line_height)) + 'px'}, 100);
						} else {
							this.textarea.animate({height: (this.dummy.height() + (this.expand_tolerance*this.line_height)) + 'px'}, 100);
						}
					}
				}
			}

			// Hide the dummy, as otherwise it overflows the body when the content is long
			this.dummy.hide();
		}

	 });
})(jQuery);

// SORTING DIV TAGS
// MGATES 4-11-2011
// YOU MUST SPECIFY PREFIXES FOR THE DIV CONTAINERS
// MAIN DIV CONTAINER THAT HOLDS DIV IS sortDivContainer
// DIVS TO BE SORT MUST START WITH M_[ID] WHERE ID IS THE CUSTOM ID
// THE DOWN DIV MUST BE D_[ID]
// THE UP DIV MUST BE U_[ID]
// THE VALUE DUE IS V_[ID], BUT IS NOT CURRENTLY USED
// YOU CAN ONLY HAVE ONE CONTAINER DIV PER PAGE CURRENTLY

function initSortDivs(){

	$('[id*="U_"]').each(function(){
			$(this).click(function(){
				moveDiv('up','M_' + $(this).attr('id').substring(2));
			})
	})
	$('[id*="D_"]').each(function(){
			$(this).click(function(){
				moveDiv('down','M_' + $(this).attr('id').substring(2));
			})
	})

}

function moveDiv(strDirection, strDivToMove, strWhereClause){

	var curPos = 0;
	var curDiv = strDivToMove;
	var divString = '';
	var divHTML = '';

	curArray = $('#sortDivs').val().split(',');
	for (x=0;x<curArray.length;x++){
		if(curArray[x]!=''&&curArray[x]!=null&&curArray[x]!=undefined){
			if(curDiv=='M_' + curArray[x]){
				curPos = x;
			}
		}
	}

	var sortVal = 0;
	if(strDirection=='up')
	{
		sortVal = -1;
		sortVal2 = +1
	}
	else
	{
		sortVal = +1;
		sortVal2 = -1
	}

	if((curPos>0&&strDirection=='up')||(curPos<(curArray.length-2)&&strDirection=='down')){
		for (x=0;x<curArray.length;x++){
			if(curArray[x]!=''&&curArray[x]!=null&&curArray[x]!=undefined){
				if((curPos+sortVal)==x&&strDirection=='up'){
					divString = divString + curArray[x+sortVal2] + ',';
					divHTML = divHTML + '<div id="M_' + curArray[x+sortVal2] + '">' + $('#M_' + curArray[x+sortVal2]).html() + '</div>';
				}
				if((curPos)!=x)
				{
					divString = divString + curArray[x] + ',';
					divHTML = divHTML + '<div id="M_' + curArray[x] + '">' + $('#M_' + curArray[x]).html() + '</div>';
				}
				if((curPos+sortVal)==x&&strDirection=='down'){
					divString = divString + curArray[x+sortVal2] + ',';
					divHTML = divHTML + '<div id="M_' + curArray[x+sortVal2] + '">' + $('#M_' + curArray[x+sortVal2]).html() + '</div>';
				}
			}
		}
		$('#sortDivs').val(divString);
		$('#sortDivContainer').html(divHTML);
		initSortDivs();

		// DO THE AJAX UPDATE IF EXISTS

		if($('#sortCode').val()!='')
		{
	        $.ajax({ url: "/etools/savedata.asp?values=" + encodeURI($('#sortDivs').val()) + "&code=" + $('#sortCode').val()})
	            .success(function(msg)
	            {

	            })
	            .error(function(msg)
	            {
	                alert("ERROR SORTING QUESTIONS");
	            })
		}
	}
}

function loadDynamicContent(dynamicPage)
{

	if ($('#dynamicContent').length == 0){
		$(document.body).append("<div id='dynamicContent' class='dynamicContent'><div class='inlineDiv'>AAWP : More Information</div><div class='inlineDivRight' id='dynamicContentClose' style='text-align:right;cursor:pointer;padding-bottom:6px;'>Close This Dialog</div><div class='clear'></div><div id='dynamicContentHTML' style='height: 690px;overflow:auto;background-image:url(/images/contentbg.gif);padding:6px;'></div></div>");
		$('#dynamicContentClose').click(function(){
			$('#dynamicContent').fadeOut();
		})
	}

	$.ajax({url: dynamicPage})
		.success(function(msg){
			$('#dynamicContentHTML').html(msg);
			positionDynamicContent();
			document.getElementById('dynamicContentHTML').scrollTop = 0;
			$('#dynamicContent').fadeIn();
		})
		.error(function(msg){
			alert(msg);
		})

}

function positionDynamicContent()
{

	var p = $('#cornerPosition').offset();
	$('#dynamicContent').css('left',p.left+210)
	$('#dynamicContentClose').css('left',p.left+914)

}
