function GetOID() {
 // based on Bill Dortch's Public Domain Cookie Code
  function getCookieVal(offset) {
 	var endstr = document.cookie.indexOf(";", offset);
 	if (endstr == -1)	{
 		endstr = document.cookie.length;
 	}
 	return unescape(document.cookie.substring(offset, endstr));
  }

 	var arg = "oid=";
 	var alen = arg.length;
 	var clen = document.cookie.length;
 	var i = 0;
 	while (i < clen) {
 		var j = i + alen;
 		if (document.cookie.substring(i,j) == arg)	{
 			return getCookieVal(j);
 		}
 		i = document.cookie.indexOf(" ", i) + 1;
 		if (i == 0) break;
 	}
 	return null;
 }

  function SetOIDCookie(name,value) {
 	var argv = SetOIDCookie.arguments;
 	var argc = SetOIDCookie.arguments.length;
 	var expires = (argc > 2) ? argv[2] : null;
 	var path = (argc > 3) ? argv[3] : null;
 	var domain = (argc > 4) ? argv[4] : null;
 	var secure = (argc > 5) ? argv[5] : false;
 	document.cookie = name + "=" + escape(value) +
 	 			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
 	 			((path == null) ? "" : ("; path=" + path)) +
 	 			((domain == null) ? "" : ("; domain=" + domain)) +
 	 			((secure == true) ? "; secure" : "");
 }

 function SetGenericOID() {

  	var xDate = new Date();
 	if(GetOID() == null) {
 		xDate.setDate(xDate.getDate() + 1);
 		SetOIDCookie("oid", "generic", xDate, "/");
 	}


 }

function GetName(name) {
	function toUpper(nam) {
		var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters
		var a = nam.split(/\s+/g); // split the sentence into an array of words
		for (i = 0 ; i < a.length ; i ++ ) {
			var parts = a[i].match(pattern); // just a temp variable to store the fragments in.
			var firstLetter = parts[1].toUpperCase();
			var restOfWord = parts[2].toLowerCase();
			a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
		}
		return a.join(' '); // join it back together
	}

// this function KOs the numeric part, capitalises the first letter
// and suppresses the name if the length is < 2. If not it returns the name, else returns an empty string (not Null)
// if given null, it returns an empty string

if ((name=="")||(name==null)||(name=="generic"))
	{
	return "";
	}
else
	{
	name=name.replace(/[0-9]/,"");
	name=toUpper(name);
	return name;
	}
}



