function updateTextCounter(field, counterfield) 
{
	var limit = null;
	if(!field.maxLimit) return;

	limit = parseInt(field.maxLimit);
	if(isNaN(limit)) return;

	if (field.value.length > limit) {
		alert('You have reached the maximum ' + limit + ' characters limit for this field.');
		document.getElementById(counterfield).innerHTML = "<b>0</b>";
		field.value = field.value.substring(0,limit);
	} else {
		document.getElementById(counterfield).innerHTML = limit - field.value.length;
	}
}



function checkForEmpty() 
{
	for (var i = 0; i < document.forms[0].elements.length; i ++)
	{	var element = document.forms[0].elements[i];
		if(element.type != 'button' && element.type != 'submit' && element.type != 'hidden')
		{
			if (element.value.trim())
			{
				//There are values in the form 
				return;
			}
		}
	}
	alert("The form is empty. Please provide at least one value.");	
	return false;
}


String.prototype.trim = function() 
{
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};


function preloadImages()
{
	if (document.images)
	{
	  image= new Image(); 
	  image.src="./images/toss.gif"; 
	}
}

function addOnLoad(functionToAdd)
{
	var oldOnLoad = window.onload;
	if (typeof oldOnLoad != 'function')
	{
		window.onload = functionToAdd;
	}
	else
	{
		window.onload = function()
		{
			oldOnLoad();
			functionToAdd();
		}
	}
}
/*
function setCookie() 
{
    var the_name = prompt("What's your name?",""); 
    var the_date = new Date("December 21, 2012");
    var the_cookie = escape(the_name) + ";" ; 
    var the_cookie = the_cookie + "path=/;"; 
    var the_cookie = the_cookie + "domain=nostarch.com;"; 
    var the_cookie = the_cookie + "expires=" + the_date.toGMTString() + ";"; 
    document.cookie = "my_cookie=" + the_cookie; 
}*/
