function autoTab(input, len) {
	if (input.value.length >= len) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input) 
			index = i;
		else 
			i++;
		return index;
	}
	
	return true;
}

function toggleMessage(onOrOff) {
	if (document.getElementById) {
		var part = document.getElementById('elipsis');
		var full = document.getElementById('extended');
		if (part && full) {
			  if (part.style) {
					part.style.display = (onOrOff ? 'none' : 'inline');
					full.style.display = (onOrOff ? 'inline' : 'none');
				}
		}
	}
}

$(document).ready(function() {
  toggleMessage(false);
});

function toggleMessagenewuser(onOrOff) {
	if (document.getElementById) {
		var part = document.getElementById('elipsisnewuser');
		var full = document.getElementById('extendednewuser');
		if (part && full) {
			  if (part.style) {
					part.style.display = (onOrOff ? 'none' : 'inline');
					full.style.display = (onOrOff ? 'inline' : 'none');
				}
		}
	}
}
function textCounter(field, countfield, maxlimit) {
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb. of characters.
*/
	if (field.value.length > maxlimit) // if the current length is more than allowed
		field.value =field.value.substring(0, maxlimit); // don't allow further input
	else
		countfield.value = maxlimit - field.value.length; // set the display field to remaining number
} 


function copyToList(from,to)
{
	fromList = eval('document.forms[0].' + from);
	toList = eval('document.forms[0].' + to);
	if (toList.options.length > 0 && toList.options[0].value == 'temp')
	{
		toList.options.length = 0;
	}
	var sel = false;
	for (i=0;i<fromList.options.length;i++)
	{
		var current = fromList.options[i];
		if (current.selected)
		{
			sel = true;
			if (current.value == 'temp')
			{
				alert ('You cannot move this text!');
				return;
			}
			txt = current.text;
			val = current.value;
			toList.options[toList.length] = new Option(txt,val);
			fromList.options[i] = null;
			i--;
		}
	}
	if (!sel) alert ('You haven\'t selected any options!');
}

function allSelect()
{
	List = document.forms[0].chosen;
	if (List.length && List.options[0].value == 'temp') return;
	for (i=0;i<List.length;i++)
	{
		List.options[i].selected = true;
	}
}

// JavaScript Document
var ajax_content = function(containerId, url, minutes) {
	// save element references
	var container = document.getElementById(containerId);
	if (!container) { return; }
	
	var timer;

	this.refresh = function() {
		// start the ajax request
		$.ajax({
			url: url,
			cache: false,
			context: container,
			success: function(data) {
				if (data.indexOf('Problem Encountered') == -1) {
					$(this).html(data);
				} else if (console && console.log) {
					var d = new Date();
					var curr_hour = d.getHours();
					var curr_min = d.getMinutes();
					console.log(curr_hour+':'+curr_min+' - '+containerId+' Refresh Problem Encountered');
				}
			},
			error: function(jqXHR, textStatus, errorThrown) {
				if (console && console.log) {
					var d = new Date();
					var curr_hour = d.getHours();
					var curr_min = d.getMinutes();
					console.log(curr_hour+':'+curr_min+' - '+textStatus+' Refresh Problem Encountered');
				}
			}
		});
	};

	this.repeat = function( minutes ) {
		// start repeating timer
		timer = setInterval( refresh, minutes * 60 * 1000 );
	};
	
	// if minutes specified, start repeat
	if (minutes && (minutes > 0)) { repeat( minutes ); }
};

function correct_host(in_url) {
	out_url = in_url.split('.');
	prefix = location.href.split('.', 1);
	out_url[0] = prefix[0];
	out_url = out_url.join('.');
	return out_url;
}

