function isAURL(s) {
	var regexp = /^(?:http:\/\/)?(?:[\w-]+\.)+[a-z]{2,6}\/?/
	return regexp.test(s);
}

function autosuggest(target, controller, params, form)
{
	if (x > 0) showComponent(target, controller, params, form, 1);
}

function resetx()
{
	x++;	
}

function showComponent(resultsDiv, theSection, theParams, formDiv, hideResultsDiv)
{
	var params = parseParams(theParams);
	if(formDiv) params = getDivParams(formDiv,params);
	params['AJAX'] = 1;
	
	if(resultsDiv && hideResultsDiv) $(resultsDiv).update('Loading ...');
	
	var req = new Ajax.Request(theSection + '.php',
		{		
			method: 'POST', 
			parameters: params,
			onSuccess: function(transport, json)
			{
				if (json)
				{
					var data = eval(transport.responseText);
					if(data[0] == 'function') eval(data[1]+'(data)');
					else if(data[0] == 'show_component') showComponent(data[1],data[2],data[3]);
					else if(data[0] == 'AlertShowComponent'){
						alert(data[1]);
						showComponent(data[2],data[3],data[4]);
					}					
					else if(data[0] == 'alert_redirect'){
						alert(data[1]);
						window.location = data[2];
					}
					else if(data[0] == 'update_div') $(data[1]).update(data[2]);
					else if(data[0] == 'redirect') window.location = data[1];
					else if(data[0] == 'do_nothing') {}
					else if(data[0] == 'remove') $(data[1]).remove();
					else if(data[0] == 'lightbox')
					{
						if($(data[2])) $(data[2]).remove();
						Page.hideLightbox();
						Page.showLightbox(this, {'url':data[1]});
					}
					else alert(data);
				}
				else
				{
					if(params['insert']) $(resultsDiv).insert({before: transport.responseText});
					else if (resultsDiv && $(resultsDiv)) $(resultsDiv).update(transport.responseText);
					else if(resultsDiv && !$(resultsDiv)){}
					else alert(transport.responseText);
				}
			}				
		}
	);
	return false;
}

function parseParams(theParams)
{
	var params = {};
	var arr = theParams.split("||");
	for (var i =0; i < arr.length; i++)
	{
		var arr2 = arr[i].split("::");
		var key = arr2[0];
		var value = arr2[1];
		params[key] = value;
	}
	return params;
}

function showSelectDiv(e,div)
{
	var elem = $(div).childElements(); 
	for(var i=0; i < elem.length; i++)
	{
		if(elem[i].id == e)
		{
			elem[i].show(); 
			enableFields(elem[i].id,false); 
		}
		else{
			elem[i].hide();
			enableFields(elem[i].id,true); 
		}
	}	
}

function changeChallenge(e)
{
	if(e != 0) $('select_challenge').hide();
	else $('select_challenge').show();
	showSelectDiv(e,'challenges_div'); 	
}

function enableFields(theDiv,trueOrFalse)
{
	var form_types = new Array('input','select','textarea');
	for (var j =0; j < form_types.length; j++)
	{
		var i = 0;
		while($(theDiv).down(form_types[j],i))
		{
			ob = $(theDiv).down(form_types[j],i);
			ob.disabled = trueOrFalse;
			i++;		
		}
	}	
}

function getDivParams(theDiv,params)
{
	if(params == '') var params = {};		
	var form_types = new Array('input','select','textarea');
	for (var j =0; j < form_types.length; j++)
	{
		var i = 0;
		while($(theDiv).down(form_types[j],i))
		{
			ob = $(theDiv).down(form_types[j],i);
			
			if (!ob.disabled)
			{
				if (((form_types[j] == 'select' && ob.multiple == false) || 
				     ((ob.type == 'checkbox' && ob.name.indexOf("[]") == -1) || ob.type == 'radio') && ob.checked) || 
				     (ob.type == 'text' || ob.type == 'password' || ob.type == 'hidden') || 
				     form_types[j] == 'textarea')
				{
					var key = ob.name;
					var value = ob.value;
					params[key] = value;
					
					 // Added 5/27/09 by Eric D to account for values set by javascript
					if (ob.value.blank() && ob.id && $(ob.id)) params[key] = $(ob.id).value;
				}
				else if (ob.type == 'checkbox' && ob.name.indexOf("[]") != -1)
				{
					var key = ob.name;
					var ct = 0;
					$(theDiv).getElementsBySelector('[name="' + key + '"]').each(function(e)
					{
						if (e.checked)
						{
							key = key.replace('[]', '');
							params[key + '[' + ct + ']'] = e.value;
							ct++;
						}
					});
				}
				else if(form_types[j] == 'select' && ob.multiple == true)
				{
					var key = ob.name;
					for (var p = 0; p < ob.options.length; p++)
					{
					    if (ob.options[ p ].selected){
					    	var value = ob.options[ p ].value;
					    	key=key.split('[').join('');
					    	key=key.split(']').join('');			    	
					    	params[key+'['+p+']'] = value;
					    }
					}
				}
			}
			i++;
		}
	}
	return params;
}

function toggleComponent(theDiv,theSection,theParams)
{
	$(theDiv).toggle();
	if($(theDiv).innerHTML.blank()) showComponent(theDiv,theSection,theParams);
}

//CHANGE TABS
function switchTab(event)
{
    var obj = Event.element(event);

    $$('.tab3On').each(function(e)
    {
        e.className = "tab3";
        e.down("img").src = e.down("img").src.replace("arrow1on", "arrow1");
    });
    
    $$('.tab3OnRight').each(function(e)
    {
        e.className = "tab3Right";
        e.down("img").src = e.down("img").src.replace("tab3on_right", "tab3_right");
    });
    
    
    obj.down("img").src = obj.down("img").src.replace("arrow1", "arrow1on");
    var nextDiv = obj.next(".tab3Right");
    nextDiv.className = "tab3OnRight";
    nextDiv.down("img").src = nextDiv.down("img").src.replace("tab3_right", "tab3on_right");
    obj.className = "tab3On";
}

//SHOW HELP TEXT
function showHelp(e, id, target)
{
	if (!e || !$(id)) return;
	e.down('.help-icon').toggleClassName("help-icon-bg");
	if (target) e = target;
	
	if (!e.down('.help-body'))
	{
		var tpl = new Template($('help_template').innerHTML);
		e.insert(tpl.evaluate({content: $(id).innerHTML}));
	}
	
	e.down('.help-body').toggle();
}

//DISABLE SUBMIT BUTTON
var submitcount=0;
function disable_submit_button(button)
{
   if(submitcount == 0){
      submitcount++;
 	  document.getElementById(button).disabled=true;
 	  document.getElementById(button).value='Submitting Information, Please Wait...';
      return true;
   }
   else{
      alert("Your information is being saved, please be patient while it is processed.");
      return false;
   }
}

//POP-UP WINDOW
function NewWindow(url,width,height)
{
	window.open(url,'new_window','scrollbars=1,resizable,width='+width+',height='+height);
}

//GROW TEXT FIELD
function checkRows(textArea)
{
	if (navigator.appName.indexOf("Microsoft Internet Explorer") == 0)
	{
		textArea.style.overflow = 'visible';
		return;
	}
	while (textArea.scrollHeight > textArea.offsetHeight) textArea.rows++;
	return;
}

//CHECK OTHER
function checkOther(checkField)
{
	if($(checkField).value == 'Other') $(checkField+'_other_div').show();
	else $(checkField+'_other_div').hide();
}

var Component = 
{
	registerTabs: function()
	{
		if (this.down(".component-tabs"))
		{
			var arr = this.down(".component-tabs").down("tr").childElements();
		}
		else if (this.up(".component-container") && this.up(".component-container").down(".component-tabs"))
		{
			var arr = this.up(".component-container").down(".component-tabs").down("tr").childElements();
		}
		else return;
		
		var tabs = [];
		arr.each(function(e){ if (e.className.match('component-tab')) tabs.push(e) });
		
		tabs.each(function(e)
		{
			e.observe('click', function(event)
			{
				tabs.each(function(el)
				{
					el.removeClassName("tab-on");
					el.down(".tab-content").removeClassName("tab-content-on");
				});
				
				this.addClassName("tab-on");
				this.down(".tab-content").addClassName("tab-content-on");
				
 			});
		});
	},
	
	toggleTabIcon: function(className, id)
	{
		$$('.' + className).each(function(e) { if (e) e.src = e.src.replace('_on', '_off'); });
		
		if ($(id))
		{
			var e = $(id);
			if (e) e.src = e.src.replace('_off', '_on');
		}	
	}
};

var Page = 
{
	win: null,
	init: function(section)
	{
		$$(".component-tabbed").each(function(e)
		{
			Object.extend(e, Component);
			e.registerTabs();
		});
	},
	
	showLightbox: function(creator, obj)
	{
		if (!obj) obj = {};
		var xPos = 0; var yPos = 0;
		
		if (navigator.userAgent.toLowerCase().indexOf("msie") + 1 > 0)
		{
			if (self.pageYOffset) yPos = self.pageYOffset;
			else if (document.documentElement && document.documentElement.scrollTop) yPos = document.documentElement.scrollTop; 
			else if (document.body) yPos = document.body.scrollTop;
		}
		
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = '100%';
		bod.style.overflow = 'hidden';
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = '100%';
		htm.style.overflow = 'hidden';
		
		var selects = document.getElementsByTagName('select');
		for (i = 0; i < selects.length; i++) selects[i].style.visibility = 'hidden';
		window.scrollTo(0, 0); 
		
		$('lightbox-overlay').show();
		
		var lightbox = $('lightbox');
		Object.extend(lightbox, Object);
		lightbox.show();
		lightbox.creator = creator;
		
		if (obj.url)
		{
			if (!obj.params) obj.params = {};
			if (!obj.method) obj.method = 'GET';
			
			new Ajax.Updater({ success:$('lightbox-content')}, obj.url,
			{
				method:obj.method, evalScripts:true, parameters:obj.params
			});
		}
	},
	
	hideLightbox: function(url, params)
	{
		$('lightbox-content').update(" ");
		$('lightbox').hide();
		$('lightbox-overlay').hide();
		
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = 'auto';
		bod.style.overflow = 'auto';
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = 'auto';
		htm.style.overflow = 'auto';
		
		var selects = document.getElementsByTagName('select');
		for (i = 0; i < selects.length; i++) selects[i].style.visibility = '';
		window.scrollTo(0, 0); 		
	}
}

function submitCompData(event, className, override)
{
	var params = { 'action':'DataGoals', 'user_instance':$('user_instance').value, 'competition_id':$('competition_id').value, 
				   'submitted_by':$('submitted_by').value, 'submission_type':$('submission_type').value };
				   
	if (override) params.override = override;
	
	var valid = true;
	var validCt = 0;
	var isFocused = false;
	
	$$("." + className).each(function(e)
	{
		if (className.include('round_') && e.value.blank())
		{
			valid = false;
			e.focus();
			throw $break;
		}
		else if (className.include('day_') && e.value.blank())
		{
			if (!isFocused)
			{
				e.focus();
				isFocused = true;
			}
		}
		else
		{
			params[e.name] = e.value;
			validCt++;
		}
	});
	
	if (!valid)
	{
		alert("All fields are required.");
		return;
	}
	else if (validCt < 1)
	{
		alert("Please enter at least one value.");
		return;
	}
	
	var el = (event.target) ? event.target : Event.element(event);
	
	new Ajax.Request('/tt.php',
	{
		method: 'post',
		evalScripts: true,
  		parameters: params,
  		onSuccess: function (transport)
  		{
  			var result = (transport.responseText.isJSON()) ? transport.responseText.evalJSON(true) : {};
  						
  			if (result.success)
  			{
  				if (result.update_round && result.round_data && result.data_type)
  				{
  					for (var i in result.round_data)
  					{
  						var id = result.data_type + '[round][' + result.update_round + '][' + i + ']';
  						if ($(id)) $(id).value = result.round_data[i];
  						
  						var id = 'view_' + result.data_type + '[' + result.update_round + '][' + i + ']';
  						if ($(id)) $(id).update(result.round_data[i]);
  					}
  				}
  				
  				switch (result.report_type)
  				{
  					case 'comp_round':
  					
  						toggleRoundEditFields(event, result.data_type, result.update_round);
  						
  					break;
  					
  					case 'comp_day':
  					
  						for (var i in result.input_data)
  						{
  							var id = result.data_type + '[round][' + result.update_round + '][' + result.update_day + '][' + i + ']';
	  						if ($(id)) $(id).value = result.input_data[i];
	  						
	  						var id = 'view_' + result.data_type + '[' + result.update_round + '][' + result.update_day + '][' + i + ']';
	  						if ($(id)) $(id).update(result.input_data[i]);
  						}
  						
  						toggleRoundEditFields(event, result.data_type, result.update_round + "_" + result.update_day);
  						
  						$$(".edit_" + result.data_type + "_" + result.update_round).each(function(e)
  						{
  							if (e.visible()) toggleRoundEditFields(event, result.data_type, result.update_round);
  							throw $break;
  						});
 					
  					break;
  				}
  				
  				var class_name = "";
  				
  				if (result.data_type == "result" && result.report_type == "comp_round")
  				{
  					$$("." + "rnd" + (parseInt(result.update_round) + 1).toString()).each(function(e)
					{
						if (e) e.show();
					});
					
					$$("." + "rndtxt" + (parseInt(result.update_round) + 1).toString()).each(function(e)
					{
						if (e) e.update('');
					});
					
					$$("." + "rndbtn" + (parseInt(result.update_round) + 1).toString()).each(function(e)
					{
						if (e)
						{
							e.removeClassName('submit_grey');
							e.addClassName('submit_regular');
						}
					});
  				}
  				
  				if (result.response_type == "lightbox")
				{				
					result.url = "tt.php?page=data_goals_feedback&AJAX=1&comp_round="+parseInt(result.update_round).toString()+"&comp_day="+result.update_day;
					Page.showLightbox(this, result);
				}
				else alert($('msg_data_saved').innerHTML);
  			}
  			else if (result.error)
  			{
  				var id = ($(result.error)) ? result.error : 'default_error_msg';
  				alert($(id).innerHTML);
  			}
  			else if (result.notice)
  			{
  				var msgs = $('confirm_header').innerHTML;
  				
  				$A(result.notice).each(function(e)
  				{
  					msgs += $(e.notice).innerHTML + "\n";
  				});
  				
  				msgs += $('confirm_footer').innerHTML;
  				
				if (window.confirm(msgs))
				{
					submitCompData(event, result.interval + "_" + result.data_type + "_" + result.interval_val, 1);
				}
  			}
  		}
	});
}

function toggleRoundEditFields(event, type, round_num)
{
	var elmt = (event.target) ? event.target : Event.element(event);
	
	$$(".view_" + type + "_" + round_num).each(function(e)
	{
		e.toggle();
	});
	
	$$(".edit_" + type + "_" + round_num).each(function(e)
	{
		if (elmt.hasClassName("editbtn") && e.visible())
		{
			// do nothing
		}
		else e.toggle();
	});
}

var App = 
{
		postData: function(event)
	    {
	        var f = Event.element(event).up("form");
	        $(f.target).onload = showComponent('shipping_data','admin','page::shipping_data','drilldown');
	        f.submit();
	        //$(f.target).onload = $('shipping_data').update('');	        
	    }	
}

var ffocus = new Array(''); 
function clearOnFocus(field){
	var fieldname = $(field).name; 
	if(!ffocus[fieldname]){ 
		$(field).value = ''; 
		ffocus[fieldname] = 1;
	}
}

/**
* Returns the value of the selected radio button in the radio group, null if
* none are selected, and false if the button group doesn't exist
*
* @param {radio Object} or {radio id} el
* OR
* @param {form Object} or {form id} el
* @param {radio group name} radioGroup
*/ 
function $RF(el, radioGroup)
{ 
	alert(el);
    if($(el).type && $(el).type.toLowerCase() == 'radio') { 
        var radioGroup = $(el).name; 
        var el = $(el).form; 
    } else if ($(el).tagName.toLowerCase() != 'form') { 
        return false; 
    } 
 
    var checked = $(el).getInputs('radio', radioGroup).find( 
        function(re) {return re.checked;} 
    ); 
    return (checked) ? $F(checked) : null; 
}

function CheckGoalValue(formType)
{
	if (!$(formType+'_target_value')) return;
	
	if($(formType+'_target_value').value == 'most')
	{
		$(formType+'_target_freq').hide();
	}
	else
	{
		$(formType+'_target_freq').show();
	}	
}

function ChangeFormFields(formType)
{
	if($(formType+'_action')){
		var e = $(formType+'_action').value;
		$(formType+'_standings_unit').value = eval(formType+'_standings_unit[e]'); 
		$(formType+'_target_value').value = eval(formType+'_target_value[e]'); 
		CheckGoalValue(formType);
		$(formType+'_target_freq').value = eval(formType+'_target_freq[e]');
	}
}

DHTMLWin = 
{
	load: function(event, template, params, parent)
	{
		if ($('dhtml_win')) $('dhtml_win').remove();
		if (!params) params = {};
		if (!parent) parent = document.body;
	
		var e = Event.element(event);
		
		var tpl = new Template($(template).innerHTML);
		var div = new Element('div', { id:'dhtml_win' }).update(tpl.evaluate(params));
		div.style.display = 'none';
		parent.appendChild(div);
		
		if (Element.viewportOffset(e).top > div.getHeight()) var offset_top = 0 - div.getHeight();
		else if ((document.viewport.getHeight() - Element.viewportOffset(e).top)  > (div.getHeight() + e.getHeight())) var offset_top = e.getHeight();
		
		if ((document.viewport.getWidth() - Element.viewportOffset(e).left)  > div.getWidth()) var offset_left = 0;
		else var offset_left = 2 - (div.getWidth() - e.getWidth());
		
		offset_left += e.getWidth();
		
		Element.absolutize(div);
		Element.clonePosition(div, e, {offsetLeft:offset_left, offsetTop:offset_top});
		
		div.style.zIndex = 999;
		div.show();
		
		if (params.url)
		{
			if (!params.params) params.params = {};
			params.params.AJAX = '1';
			div.down('.dhtml_win_content').id = 'dhtml_win_content';
			
			var req = new Ajax.Request(params.url,
			{		
				method: 'POST', 
				parameters: params.params,
				onSuccess: function(transport, json)
				{
					$('dhtml_win_content').update(transport.responseText);
				}				
			});
		}
	}
}

var Standings = 
{
	user_id: null,
	user_instance: null,
	competition_id: null,
	team_id: null,
	standings_round: null,
	challenge_id: null,
	location_col: null,
	location_id: null,
	pe: null,
	
	init: function(params, tabs)
	{
		Object.keys(params).each(function(e) { Standings[e] = params[e]; });
		
		var a = [$('location_' + tabs[0]), $('challenge_' + tabs[1])];
		a.each(function(e) { if (e) e.src = e.src.replace('_off', '_on'); });
	},
	
	load: function(type, id, col)
	{
		switch (type)
		{
			case 'location':
				this.location_col = col;
				this.location_id = id;
			break;
			
			case 'challenge':
				this.challenge_id = id;
			break;
		}
		
		Component.toggleTabIcon('standings_' + type, type + '_' + id);
		
		var params = "page::standings_data||competition_id::" + this.competition_id + "||location_col::" + this.location_col + 
					 "||location_id::" + this.location_id + "||challenge_id::" + this.challenge_id;
		
		showComponent('standings', 'tt', params);
	},
	
	addRival: function(team_id, challenge_id)
	{
		var params = "action::AddRival||user_instance::" + this.user_instance + "||team_id::" + team_id + "||challenge_id::" + challenge_id;
		showComponent('', 'tt', params);
		if ($('tabrivals')) $('tabrivals').show();
	},
	
	delRival: function(team_id, challenge_id)
	{
		var params = "action::DeleteRival||user_instance::" + this.user_instance + "||team_id::" + team_id + "||challenge_id::" + challenge_id;
		showComponent('', 'tt', params);
		Standings.load("location", Standings.location_id, Standings.location_col);
	},
	
	updateScroll: function(event)
	{
		if (this.team_id == null) return;
		
		if (event)
		{
			event.cancelBubble = true;
			window.detachEvent("onload", Standings.updateScroll);
		}
		
		var s = $('standings_scroll');
		var e = $("team_" + this.team_id.toString());
		var r = $("rival_" + this.team_id.toString());
		
		if (r) r.update("&nbsp;");
		
		if (s && e)
		{
			s.scrollTop = e.offsetTop - (s.offsetHeight / 2) + e.offsetHeight;
			e.className = "standings_row_team";
		}
	}
};

function showUserPrice(type,product_group_id){
	var user_pay = $(type+'_total_price'+product_group_id).value - $(type+'_company_pay'+product_group_id).value;
	if(user_pay < 0) user_pay = 0;
	$(type+'_user_price'+product_group_id).update(user_pay);
}

function pulldown_pop(e,div,page,theParams){
	var arr = e.split("::");
	if(arr.length > 1){
		if(arr[0] == 'Action'){
			var action = arr[1];
			var url = '/admin.php?action='+action;
			var params = parseParams(theParams);
			for( var i in params){
				if(i != 'page') url += '&'+i+'='+params[i];
			}
			window.location = url;
		}
		else if(arr[0] == 'Popup'){
			var page = arr[1];
			var url = '/admin.php?template=blank&page='+page;
			var params = parseParams(theParams);
			for( var i in params){
				if(i != 'page') url += '&'+i+'='+params[i];
			}
			window.open(url,'new_window');			
		}
	}
	else if(e){showComponent(div,page,theParams);}
}

Calendar = 
{
	id: null,
	
	deletePlan: function(event, plan_id)
	{
		showComponent('calendar', 'tt', 'action::CalendarDeletePlan||plan_id::' + plan_id);
		this.load(event, 'month');
	},
	
	load: function(event, view, date_str)
	{
		clearTimeout(Calendar.id);
		if (!date_str && $('calendar_date')) var date_str = $('calendar_date').value;
		
		if($('filter').value != $('calendar_filter').value)
		{
		  if ($('calendar_filter').value == 'my') var view = 'month';
		  else var view = 'list';
		}
		else if (!view && $('calendar_view')) var view = $('calendar_view').value;

		
		var obj = Calendar.parseDate(date_str);
		var params = '||view::' + view + '||month::' + obj.month + '||year::' + obj.year;
		if ($('calendar_filter')) params += '||filter::' + $('calendar_filter').value;
		if ($('calendar_search')) params += '||search::' + $('calendar_search').value;
		
		$('calendar').update('Loading...');
		showComponent('calendar', 'tt', 'page::calendar' + params);
	},
	
	parseDate: function(d)
	{
		var obj = new Object();
		obj.month = d.substr(5, 2);
		obj.year = d.substr(0, 4);
		return obj;
	},
	
	showEvent: function(event, view, repeat)
	{
		if ($('event_win')) $('event_win').remove();
		
		var e = Event.element(event);
		var obj = e.down('.event_json').innerHTML.evalJSON();
		
		var tpl = new Template($('event_tpl').innerHTML);
		var div = new Element('div', { id:'event_win' }).update(tpl.evaluate(obj));
		div.style.display = 'none';
		$('calendar').appendChild(div);
		
		if (Element.viewportOffset(e).top > div.getHeight()) var offset_top = 0 - div.getHeight();
		else if ((document.viewport.getHeight() - Element.viewportOffset(e).top)  > (div.getHeight() + e.getHeight())) var offset_top = e.getHeight();
		
		if ((document.viewport.getWidth() - Element.viewportOffset(e).left)  > div.getWidth()) var offset_left = 0;
		else var offset_left = 2 - (div.getWidth() - e.getWidth());
		
		Element.absolutize(div);
		
		try {
			Element.clonePosition(div, e, {offsetLeft:offset_left, offsetTop:offset_top});
		}
		catch (e) {
			if (!repeat) Calendar.showEvent(event, null, true);
		}
		
		div.style.zIndex = 1000000;
		div.show();
	}
};

var Plan = 
{
	requestInvite: function(event, user_id)
	{
		
	},
	
	edit: function(event)
	{
		if ($('plan_desc_view')) $('plan_desc_view').toggle();
		if ($('plan_desc_edit')) $('plan_desc_edit').toggle();
		if ($('plan_access_edit')) $('plan_access_edit').toggle();
		if ($('upload_form')) $('upload_form').toggle();
		if ($('plan_photo')) $('plan_photo').toggle();
	},
	
	saveDesc: function(event)
	{
		$('plan_desc_view').update($('plan_desc').value);
		showComponent('', 'tt', 'action::SavePlan', 'plan_desc_edit');
		this.edit();
	},
	
	saveAccess: function(event)
	{
		showComponent('', 'tt', 'action::SavePlan', 'plan_access_edit');
		this.edit();
	},
	
	sendInvites: function(event)
	{
		showComponent('', 'tt', 'action::SendInvites', 'plan_invites');
	},
	
	deletePlan: function(plan_id,page)
	{
		showComponent('', 'tt', 'action::CalendarDeletePlan||plan_id::'+plan_id+'||page::'+page);
	},
	
	handleReminderClick: function(event, id)
	{
		var divs = ['email', 'sms', 'phone', '_email', '_sms', '_phone'];
		
		divs.each(function(e)
		{
			if ($(e)) $(e).hide();
			if ($('input_' + e)) $('input_' + e).disable();
		});
		
		if ($(id)) $(id).show();
		if ($('input_' + id)) $('input_' + id).enable();
		
		if ($('save_reminder')) $('save_reminder').show();
	},
	
	setTimezoneOffset: function()
	{
		if ($('plan_date'))
		{
			var a = $('plan_date').value.split("/");
			if(a[0][0] == 0) a[0] = a[0][1];
			
			var d = new Date();
			d.setFullYear(a[2]);
			d.setMonth(parseInt(a[0]));
			d.setDate(parseInt(a[1]));
			
			var offset = (d.getTimezoneOffset() / 60) * (-1);
			$('tz_offset').value = offset;
		}
	},
	
	saveReminder: function()
	{
		Plan.setTimezoneOffset();
		showComponent('plan_reminders', 'tt', 'action::SaveReminder', 'reminder_create');
	},
	
	deleteReminder: function (event, id)
	{
		if (confirm("Are you sure you want to delete this reminder?"))
		{
			showComponent('plan_reminders', 'tt', 'action::DeleteReminder||reminder_id::' + id, 'reminder_create');
		}
	}
};