window.g_Migrate = {
	_baseLocation: "/alpine.nsf",
	
	init: function() {
		if (document.location.href.toLowerCase().indexOf("http") != 0) {
			this._isLocal = true;
		}
	},
	
	_isLocal: false,
	
	getBaseLocation: function() {
		var ret = this._baseLocation;
		if (this._isLocal) {
			ret =  "http://www.alpinelakes.com" + ret;
		}
		return ret;
	},
	
	load: function(args) {
		if (typeof args == "undefined") args = {area: "", type: ""};
		if (typeof args.type == "undefined") args.type = "";
		if (typeof args.area == "undefined") args.area = "";
		
		var sUrl = "{0}/{1}?Open&Count=10000&RestrictToCategory={2}&windowTitle={3}";
		
		sUrl = sUrl.replace("{0}", this.getBaseLocation());

		
		if (args.area.length == 0 && args.type.length == 0) {
		
		} else if (args.area.length == 0) {
		
		} else {

			sUrl = sUrl.replace("{1}", "Viewer-ByAreaType");
			sUrl = sUrl.replace("{2}", args.area + "__" + args.type);
			
		}
		
		sUrl = sUrl.replace("{3}", escape(document.title));
		
		document.location.replace(sUrl);
	},
	
	
	cookie: {
		getCookie: function(name) {
			var cname = name + "=";               
			var dc = document.cookie;             
			if (dc.length > 0) {              
				begin = dc.indexOf(cname);       
				if (begin != -1) {           
					begin += cname.length;       
					end = dc.indexOf(";", begin);
					if (end == -1) end = dc.length;
					return unescape(dc.substring(begin, end));
				} 
			}
			return null;
		},

		// Use this function to save a cookie.
		setCookie: function(name, value, expires) {
			document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
		},

		// Use this function to delete a cookie.
		delCookie: function(name) {
			document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
		},

		getExpireDate: function(nodays) {
			var UTCstring;
			Today = new Date();
			nomilli=Date.parse(Today);
			Today.setTime(nomilli+nodays*24*60*60*1000);
			UTCstring = Today.toUTCString();
			return UTCstring;
		}	
	},
	
	isUserLoggedIn: function() {
		var namx = this.cookie.getCookie("DomAuthSessId");
		if (namx != null && namx != "") {
			return true;
		} else {
			return false;
		}
	},


	signout: function() {
		this.cookie.delCookie("DomAuthSessId");
	},
	
	writeIfLoggedIn: function(val, alt) {
		if (this.isUserLoggedIn()) {
			document.write(val);
		} else if (alt != null) {
			document.write(alt);
		}
	},
	
	writeAdminLinks: function(id) {
		var baseurl = this.getBaseLocation();
		

		var sLinks = 	"<br/><br/><span class=\"AdminLinks\">" +
							"<a style=\"color:red\" href=\"" + baseurl + "/0/" + id + "?EditDocument\">Edit Listing Info</a>" +
							"&nbsp;&nbsp;&nbsp;" +
							"<a style=\"color:red\" href=\"javascript: void window.g_Migrate.managePics('" + id + "');\">Edit Listing Pictures</a>" +
						"</span>";
							
		
		
		this.writeIfLoggedIn(sLinks);

	},
	
	writeControlPanelLink: function() {
		var baseurl = this.getBaseLocation();
		
		var sText = (this.isUserLoggedIn()) ? "Control Panel" : "&nbsp;|&nbsp;";
		
		var sLink = 	"<a style=\"text-decoration : none;\" href=\"" + baseurl + "/ControlPanel?ReadForm&Login\">" + sText + "</a>";							
		
		document.write(sLink);

	},
	
	writeCopyright: function() {
		var sTemp = "Copyright &copy; {0} - <strong>Alpine Lakes Real Estate</strong> - All rights reserved";
		
		document.write(sTemp.replace("{0}",new Date().getFullYear()));
	},
	
	managePics: function(id) {
		var baseurl = this.getBaseLocation();
		var picsWin = window.open(baseurl + "/ManagePics?OpenForm&parentUNID=" + id, "PicsWin", 'resizable,scrollbars=yes,width=600,height=600,left=75,top=100');
		picsWin.focus();
	}	
	
	
	


}

window.g_Migrate.init();


