/*=======================================================================================================
	Various Javascript functions:
	Copyright 2006 by: 	Tom Faulkner							http://www.bbsci.com
						BBS Consultants, Inc.
						3215 Guess Rd., #105
						Durham, North Carolina 27705
						US
			
	You are welcome to use these routines on any website you develop; however, they are not public domain
	and can not be used in other way without permission.
	======================================================================================================
*/

function isSessionCookieAllowed () {			
	//	Function to see if Session Cookies are Allowed
	document.cookie = "checkSessionAllowed=Yes";
	if (getSessionCookieValue ("checkSessionAllowed") == "Yes") {
		return true
		}
	else
		{
		return false;
		}
}

function isPersistentCookieAllowed () {			
	// Function to see if Persistent Cookies are Allowed
	setPersistentCookie ("checkPersistentAllowed=Yes", "Enabled", "minutes", 1);
	if (getCookieValue ("checkPersistentAllowe")=="Yes") {
		return true
		}
	else
		{
		return false;
		}
}

function getCookie(cookieName)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(cookieName + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + cookieName.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return null
}

function setSessionCookie (cookieName, cookieValue) {		
	// Function to set a Session Cookie
	if (isSessionCookieAllowed) {
		document.cookie = '"' + cookieName + '=' + cookieValue	
		return true;
		}
	else
		{
		alert("Please enable Session (temporary) cookies.");
		return false;
		}
}	

function setCookie(cookieName,cookieValue,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=cookieName+ "=" +escape(cookieValue)+((expiredays==null) ? "" : ";expires="+exdate)
}

function rightTrim(sString) {
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
}

//The allTrim() JavaScript function combines both leftTrim() and rightTrim() functions:

function trimAll(sString) {
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
		}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
		}
	return sString;
}
