// JavaScript Document

//START :cookie ENCAPULATED OBJECT
function cookieMonster(){
	
//VARIABLES	
	var thisObject = this;
	var bSupported = false;
	var regAcceptableParam = /^[0-9a-z]{1,25}$/i;

//PROPERTIES / ACCESSIBLE METHODS
	thisObject.isSupported = isSupported;
	thisObject.setValue = setValue;
	thisObject.getValue = getValue;
//SETUP
	initialise();

////////////////////////////////////////////////
//PRIVATE FUNCTION:initialise
////////////////////////////////////////////////
	function initialise(){
		if(typeof(document.cookie)==='string'){
			try{
				document.cookie = "sessioncookie=true; path=/";
				if(document.cookie.indexOf('sessioncookie=')>-1){
					bSupported = true;	
				}
			}
			catch(err){
				bSupported = false;
			}
		}
	}

////////////////////////////////////////////////
//PRIVATE FUNCTION:setValue	
////////////////////////////////////////////////
	function setValue(name,value){
		var bReturn = false;
		if(bSupported){
			if(typeof(name)!=='undefined',typeof(value)!=='undefined'){
				name = name+'';
				value = value+'';
			  	if(name.search(regAcceptableParam)>-1&&value.search(regAcceptableParam)>-1){
					document.cookie = name.toLowerCase()+'='+value.toLowerCase()+'; path=/';
					bReturn = true;
				}
			}
		}
		return bReturn;
	}
	
////////////////////////////////////////////////	
//PRIVATE FUNCTION:getValue	
////////////////////////////////////////////////
	function getValue(name){
		var vReturn = '';
		if(bSupported){
			if(document.cookie.length>0){
			   var iSearch = document.cookie.indexOf(name+'='); 
			   if(iSearch>-1){
				  sValue = document.cookie.substring(iSearch+name.length+1);
				  iSearch = sValue.indexOf(';');
				  if(iSearch>-1){
					sValue = sValue.substring(0,iSearch);
				  }
				  vReturn = sValue; 
			   }
			}
		}
		return vReturn;
	}
	
////////////////////////////////////////////////
//PUBLIC METHOD:isSupported
////////////////////////////////////////////////
	function isSupported(){
		return bSupported;
	}

}
//END :cookie ENCAPULATED OBJECT