function updateCharCount( textField, displayArea, maxChars ){
	if ( textField.value.length > maxChars ){
		textField.value = textField.value.slice(0, maxChars);
	}
	displayArea.innerHTML = textField.value.length + " characters (maximum of "+maxChars+")";
}

function restrictTextLength( textField, displayArea, maxChars ){
	if ( textField.value.length > maxChars ){
		textField.value = textField.value.slice(0, maxChars);
	}
	displayArea.innerHTML = (maxChars - textField.value.length) + " characters left.";
}

// Open a new popup window with the specificed url content
// Disable all the controls, toolbar, etc. Good for help message
function PopUpHelpMessage(url, title, height, width)
{
	window.open(url, title, "scrollbars=yes,menubar=no,height=" + height + ",width=" + width + ",resizable=yes,toolbar=no,location=no,status=no");
}

// Open a new popup window with the specificed url content
// Good for invoice window
function PopUpInvoiceWindow(url, title, height, width)
{
	window.open(url, title, "scrollbars=yes,menubar=yes,height=" + height + ",width=" + width + ",resizable=yes,toolbar=no,location=no,status=no");
}

function confirmBeforeSubmit(question)
{
	if(confirm(question))
		return true;
	else
		return false; 
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}