CAREConnectionsClass = Class.create();
CAREConnectionsClass.prototype = {

	Globals:function(){
		this.Conf = new Object();
		this.DevMode = false;
	},

	GetParam: function(variable){
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
	},

	readCookie: function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},

	initialize: function(conf){
		this.Globals.Conf = conf;
		this.Globals.Protocol = window.parent.document.location.protocol;
		this.Globals.Path = window.parent.document.location.pathname;
		this.Globals.Host = window.parent.document.location.hostname;
		this.Globals.Browser = navigator.appName;

		var devhost = new RegExp("^tsp.care.org", "ig");
		if(devhost.match(this.Globals.Host)){
			this.Globals.DevMode = true;
		}else{}


		if(!this.Globals.DevMode){
			var PowerUpExp = new RegExp("^/Groups/Power_Up(.*)", "ig");
			if(PowerUpExp.match(this.Globals.Path)){
				this.Modify("powerup");
			}
		}
	},

	Modify: function(flag){
		if(flag == "powerup"){
			var DIVs = $$("div.boldtxt16");
			var PUJoinTxt = new RegExp(".*You must be a Member of Power Up.*", "ig");
			for(var i = 0; i<DIVs.length;i++){
				if(PUJoinTxt.match(DIVs[i].innerHTML)){
					Element.insert(DIVs[i],{
						after:'<div id="powerUpStep1"><p>Step 1: <a href="javascript:tp_openActiveWin(\'/public/app/socialobjects/windows/join.aspx?g={F970499F-92CE-4962-B4AB-7F579D797799}\',450,300);">Click here to join the group</a></p></div>'
					});
					Element.insert($('powerUpStep1'),{
						bottom:'<p>Step 2: <a href="javascript:location.reload();">Once you\'ve joined, click here to proceed to the Power Up group!</a></p>'
					});

					DIVs[i].remove();

					$('powerUpStep1').setStyle({
						fontSize:"1.5em",
						fontWeight:"700",
						border:"1px #333 solid",
						padding:"2px",
						marginTop:"5px"
					});
				}
			}

			var As = $$("a");
			for(var i = 0; i<As.length;i++){
				if(As[i].href == "javascript:tp_openActiveWin('/public/app/socialobjects/windows/join.aspx?g={F970499F-92CE-4962-B4AB-7F579D797799}',450,300);"){
					Element.insert(As[i].up(),{bottom:"<br/><br/>"});
					Element.insert(As[i].up(),{bottom: As[i].previous(2)});
					As[i].setStyle({
						fontSize:"1.2em",
						fontWeight:"700"
					});
				}
			}
 		}


	}

};

var CAREMods = new Object();
document.observe("dom:loaded",function(){
	CAREMods = new CAREConnectionsClass({
		readCookie: "caresignupwidget"
	});
},false);

