// JavaScript Document
window.addEvent('domready', function() {
	if($('newsSignup')) {
		$('newsSignup').setStyle('display','block');
		if($('newsSignupForm')) {
			$('newsSignupForm').removeProperty('action');
			$('newsSignupForm').setProperty('action','/updates/newsSignup.php?js');
			var fnFade = new Fx.Style('log_res','background-color', {duration:3000,transition: Fx.Transitions.Quad.easeOut});
			$('newsSignupForm').addEvent('submit', function(e) {   
				new Event(e).stop();  
				$('log_res').style.display = 'block';
				var log = $('log_res').empty().addClass('ajax-loading');   
				this.send({   
					evalScripts:true,
					update: log,   
					onComplete: function() {   
						log.removeClass('ajax-loading'); 
						fnFade.start('#ffffff', '#ffff99'); 
					}   
				}); 
			});	
		}
	}
	if($('nsTabs')) {
		makeTabs();
		activeTab('nsSU');
	}
});

function makeTabs() {
	$$('#nsTabs a').each(function(el) {
		var tabid = el.getProperty('id');
		$(tabid).addEvent('click', function(e) {
			var ev = new Event(e).stop(); 
			activeTab(tabid);
		});
	});
}

function activeTab(tabid) {
	hideElements('nsTabs','a','acTab','inaTab');
	$(tabid).removeClass('inaTab');
	$(tabid).addClass('acTab');
	showContent(tabid+'_content');
}

function showContent(cid) {
	hideElements('nsTabsContent','div','acCon','inaCon');
	$(cid).removeClass('inaCon');
	$(cid).addClass('acCon');
	disableInputs();
	enableInputs();
}

function hideElements(container,element,aclass,iclass) {
	$$('#'+container+' '+element+'.'+aclass).each(function(el) {
		el.removeClass(aclass);
		el.addClass(iclass);
	});
}

function disableInputs() {
	$$('#nsTabsContent div.inaCon').each(function(el) {
		$$('#'+el.getProperty('id')+' input').each(function(input) {
			input.setProperty('disabled','disabled');
			//alert('active element '+input.getProperty('id'));
		});
	});
}

function enableInputs() {
	$$('#nsTabsContent div.acCon').each(function(el) {
		$$('#'+el.getProperty('id')+' input').each(function(input) {
			input.removeProperty('disabled');
			//alert('inactive '+input.getProperty('id'));
		});
	});
}
