	/*
	* creates a Unique UUID
	*/
	function VDNA_getUUID()
	{
		var chars = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); 	
		var uuid = new Array();
		uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
		uuid[14] = '4';		
		for (var i = 0; i < 36; i++) 
		{
			if (!uuid[i]) 
			{
				var r = Math.floor(Math.random()*36);
				uuid[i] = chars[r];
			}
		}
		return uuid.join("");
	}

	/*
	* flash app is calling this method to test!
	*/
	function VDNA_statusCookie(functionName, params)
	{
		var infoStr = functionName + "---" + params;
		alert(infoStr);			
		return true;
	}

	/*
	* flash app is calling this method to determin the domain!
	*/
	function VDNA_getCookieDomain()
	{
		var thisDomain = document.domain;
		var domainArr = thisDomain.split(".");
		thisDomain = '.' + domainArr[domainArr.length-2] + "." + domainArr[domainArr.length-1];
		
		return thisDomain;
	}


	/*
	* internal, is creating the user cookie
	*/
	function VDNA_setUpCookie(infoStr)
	{
		//cookie val: "uuid:123-123-123-123|storeVDNA:true|privateComputer:true|modules:123-111111,456-222222,789-3333333";
		thisDomain = VDNA_getCookieDomain();

		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );	
		var expires_date = new Date( today.getTime() + (360 * 1000 * 60 * 60 * 24) ); // one year
		document.cookie = "vdnaModules=" +escape( infoStr ) +
						  ";expires=" + expires_date.toGMTString() +
						  ";path=/" +
						  ";domain=" + thisDomain;
	}	

	/*
	* internal, gets the user cookie information
	*/
	function VDNA_getCookie(c_name)
	{
		if (document.cookie.length>0)
		{
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{
				c_start=c_start + c_name.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;
	}
	/*
	* flash app is calling this method to create the user's cookie
	*/
	function VDNA_createCookie()
	{
		var uuid = VDNA_getUUID();	

		// create cookie the cookie with the default values
		cookieInfo = VDNA_getCookie('vdnaModules');	
		if (cookieInfo == null) 
		{
			var infoStr = "uuid:" + uuid + "|storeVDNA:true|privateComputer:true|modules:";
			VDNA_setUpCookie(infoStr);
			
			return uuid;
		}
		return false;
	}
	/*
	* flash app is calling this method to add user moduleId and responseId to user's cookie
	*/
	function VDNA_addModule(moduleId, responseId)
	{
		cookieInfo = VDNA_getCookie('vdnaModules');	
		if (cookieInfo == null) 
		{
			VDNA_createCookie();
			cookieInfo = VDNA_getCookie('vdnaModules');	
		}
		
	
		var cookieInfoArr = cookieInfo.split("|");

		// if store and private are not true no module writing allowed
		for (var i = 0; i < cookieInfoArr.length; i++) 
		{
			if (cookieInfoArr[i].indexOf("storeVDNA") > -1) 
			{
				storeArr = cookieInfoArr[i].split(":");
				$storeBool = storeArr[1];
			}
			if (cookieInfoArr[i].indexOf("privateComputer") > -1) 
			{
				privateArr = cookieInfoArr[i].split(":");
				$privateBool = privateArr[1];
			}
		}
		if ($storeBool != "true" || $privateBool != "true")
			return false;
			
		for (var i = 0; i < cookieInfoArr.length; i++ )
		{	
			
			if (cookieInfoArr[i].indexOf("modules") > -1)	
			{
				// getting the module IDS	
				modulesArr = cookieInfoArr[i].split(":");
				// if delete function was not used previous
				if (modulesArr[1] != "")
				{	
					modules = modulesArr[1].split(",");
	
					var found = 0;
					for (var j = 0; j < modules.length; j++) 
					{
						// splitting into moduleId and responseId
						moduleIds = modules[j].split("-");
						if (moduleIds[0] == moduleId) 
						{
							// if found, overwrite the response for this module
							found = 1;
							modules[j] = moduleIds[0] + "-" + responseId;
						}
					}
	
					if (found == 0) 
					{
						// if not found, add the module and its response
						modules[modules.length] = moduleId + "-" + responseId;
					}	
	
					cookieInfoArr[i] = "modules:" + modules.join(",");
				}
				else 	// if delete function was used or this is a fresh cookie modulesArr[1] == "" so we just add the modules
					cookieInfoArr[i] = "modules:" + moduleId + "-" + responseId;	
			}
		}
		// write to the cookie the new values
		cookieInfo = cookieInfoArr.join("|");
		VDNA_setUpCookie(cookieInfo);

		return true;
	}

	/*
	* flash app is calling this method to delete all moduleId and responseId from user's cookie
	*/
	function VDNA_deleteCookieData()
	{
		cookieInfo = VDNA_getCookie('vdnaModules');	
		if (cookieInfo != null) 
		{
			var cookieInfoArr = cookieInfo.split("|");
			for (var i = 0; i < cookieInfoArr.length; i++) 
			{
				if (cookieInfoArr[i].indexOf("modules") > -1) {
					cookieInfoArr[i] = "modules:";
				}
			}
			// write to the cookie the new values
			cookieInfo = cookieInfoArr.join("|");
			VDNA_setUpCookie(cookieInfo);

			return true;
		}
		return false;
	}

	/*
	* flash app is calling this method to update privateComputer value from user's cookie
	*/
	function VDNA_setPrivateComputer(bool)
	{
		cookieInfo = VDNA_getCookie('vdnaModules');	
		if (cookieInfo != null) 
		{
			var cookieInfoArr = cookieInfo.split("|");
			for (var i = 0; i < cookieInfoArr.length; i++) 
			{
				if (cookieInfoArr[i].indexOf("privateComputer") > -1) {
					cookieInfoArr[i] = "privateComputer:" + bool;
				}
			}
			// write to the cookie the new values
			cookieInfo = cookieInfoArr.join("|");
			VDNA_setUpCookie(cookieInfo);

			return true;
		}
		return false;
	}

	/*
	* flash app is calling this method to update storeVDNA value from user's cookie
	*/
	function VDNA_setStoreVDNA(bool)
	{
		if (bool == 'true')
			VDNA_setPrivateComputer("true");
		if (bool == 'false')
			VDNA_deleteCookieData();

		cookieInfo = VDNA_getCookie('vdnaModules');	
		if (cookieInfo != null) 
		{
			var cookieInfoArr = cookieInfo.split("|");
			for (var i = 0; i < cookieInfoArr.length; i++) 
			{
				if (cookieInfoArr[i].indexOf("storeVDNA") > -1) {
					cookieInfoArr[i] = "storeVDNA:" + bool;
				}
			}
			// write to the cookie the new values
			cookieInfo = cookieInfoArr.join("|");
			VDNA_setUpCookie(cookieInfo);

			return true;
		}
		return false;
	}
