var storage = new function () {
	var dataContainer = {};

	function linearize () {
		var string = "", name, value;
		for (name in dataContainer) {
			name = encodeURIComponent(name);
			value = encodeURIComponent(dataContainer[name]);
			string += name + "=" + value + "&";
		}
		if (string != "") {
			string = string.substring(0, string.length - 1);
		}
		return string;
	}

	function read () {
		if (window.name == '' || window.name.indexOf("=") == -1) {
			return;
		}
		var pairs = window.name.split("&");
		var pair, name, value;
		for (var i = 0; i < pairs.length; i++) {
			if (pairs[i] == "") {
				continue;
			}
			pair = pairs[i].split("=");
			name = decodeURIComponent(pair[0]);
			value = decodeURIComponent(pair[1]);
			dataContainer[name] = value;
		}
	}

	function write () {
		window.name = linearize();
	}

	/* --------- Public Methods --------- */

	this.set = function (name, value) {
		dataContainer[name] = value;
		write();
	};

	this.get = function (name) {
		var returnValue = dataContainer[name];
		if(typeof(returnValue) == undefined)
			return false;
		else return returnValue;
	};

	this.getAll = function () {
		return dataContainer;
	};

	this.remove = function (name) {
		if (typeof(dataContainer[name]) != undefined) {
			delete dataContainer[name];
		}
		write();
	};

	this.removeAll = function () {
		dataContainer = {};
		write();
	};

	read();
};


function mayGetHttpString(Param, Default , location){
    
    if(location =='parent'){
    	
    	try{
    		Url = parent.location.href;
    	} catch (e) { 		 
       		 return Default;
    	}
    	
    }else{
    	Url = window.location.href;
    }
    
	pos = Url.indexOf(Param+'=');
	if (pos == -1) return Default;
	pos+= Param.length+1;
	endpos = (Url.substr(pos)).indexOf('&')
	return (endpos>0) ? Url.substr(pos,endpos): Url.substr(pos);
}

function mayLoadLoginData(){
	var MAYTRAVELUID = mayGetHttpString("MAYTRAVEL-UID",0,"window");
	var MAYTRAVELKEY = mayGetHttpString("MAYTRAVEL-KEY",0,"window");
	var MAYTRAVELTKID = mayGetHttpString("MAYTRAVEL-TKID",0,"window");
	if(MAYTRAVELUID  != 0){
		storage.set("MAYTRAVEL-UID", MAYTRAVELUID );
		storage.set("MAYTRAVEL-KEY", MAYTRAVELKEY );
		storage.set("MAYTRAVEL-TKID", MAYTRAVELTKID );
	}else if(typeof parent != 'undefined'  ){
		var MAYTRAVELUID = mayGetHttpString("MAYTRAVEL-UID",0,"parent");
		var MAYTRAVELKEY = mayGetHttpString("MAYTRAVEL-KEY",0,"parent");
		var MAYTRAVELTKID = mayGetHttpString("MAYTRAVEL-TKID",0,"parent");
		if(MAYTRAVELUID  != 0){
			storage.set("MAYTRAVEL-UID", MAYTRAVELUID );
			storage.set("MAYTRAVEL-KEY", MAYTRAVELKEY );
			storage.set("MAYTRAVEL-TKID", MAYTRAVELTKID );
		}
	}else {
		storage.set("MAYTRAVEL-UID", 0 );
		storage.set("MAYTRAVEL-KEY", 0 );
		storage.set("MAYTRAVEL-TKID", 0 );
	}
}
