var IDENTITY_COOKIENAME = "mypersonaldatacookie";
var ATTRIBUTE_DELIMITER = "~~";
var EXPIRES = 10;  // cookie expiration parameter (in days)


String.prototype.isEmpty = function(){
	return (this.length==0);
}


function MyIdentity(zip){
	this._cookieName = IDENTITY_COOKIENAME;
	this.zip = zip;
	return "MyIdentity";
}

MyIdentity.prototype.toString = function(){
	return this.zip;
}

MyIdentity.prototype.toObject = function(){
	var value = readCookie(this._cookieName);
	var result = null;
	if(!value.isEmpty())
	{
		var attrList = value.split(ATTRIBUTE_DELIMITER);			
		if(attrList.length>0 && !attrList[0].isEmpty())
		{	
			var zip = attrList[0];
			result = new MyIdentity(zip);
		}
	}
	return result;
}


MyIdentity.prototype.flush = function (){
	try{
	eraseCookie(this._cookieName);
	}
	catch(ex)
	{}
}

MyIdentity.prototype.save = function (){
		this.flush();
		createCookie(this._cookieName,this.toString(),EXPIRES);		
}


function saveIdentity(zip)
{	
	try{
		var myData = new MyIdentity(zip);
		myData.save();
		return true
	}catch(ex)
	{
		return  false
	}
}

function getIdentity()
{
	try{
	var myData = new MyIdentity(null);
	return myData.toObject();
	}catch(ex)
	{
		return null;
	}
}



