/**************************************************************************************************/
/***
/***	TERNSTYLE (TM) NEWSLETTER JAVASCRIPT DOCUMENT (ternNews tm v1.0)
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2008 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*-----------------------
	ternNews (tm) v1.0
-----------------------*/
ternNews = {
	init :
	function (i) {
		var th = this;
		ternEvents.addEvent(i,function () { th.show(); },'click',false);
		if(!th.l) {
			ternForm('ternNews_fm').init({
				css : 'req',
				func : function (f) {
					var a = f.elements,p='';
					for(var i=0;i<a.length;i++) {
						p += '&'+a[i].name+'='+_ternform.inputValue(a[i]);	
					}
					ternAjax('ternNews').ajax({
						type : 'post',
						func : function (r) {
							ternStyle('ternNews').setStyle({visibility : 'hidden'});
							alerts();
						},
						pass : true,
						node : document.body,
						empty : false,
						url : '/ternstyle/plugins/ternNews/',
						post : 'a=signup'+p
					});
				},
				submit : false
			});
			th.l = true;
		}
	},
	show :
	function () {
		this.center();
		ternStyle(document.body).elapsor({
			color : '#000',
			opacity : 85,
			func : function () {
				ternStyle('ternNews').setStyle({visibility : 'visible'});
			}
		});
	},
	close :
	function () {
		ternForm('ternNews_fm').resetErrorDiv();
		ternStyle('ternNews').setStyle({visibility : 'hidden'});
		ternStyle(document.body).hideElapsor();
	},
	center :
	function () {
		var w = ternStyle().getWindowSize(),d = ternStyle('ternNews').getDimensions(),t = parseInt((w[1]-d[1])/2) >= 30 ? parseInt((w[1]-d[1])/2) : 30;
		ternStyle('ternNews').setStyle({ top : t, left : (w[0]-d[0])/2 });
	}
}
/*-----------------------
	Miscellaneous
-----------------------*/
function alerts() {
	if(document.getElementById('alerts_cn')) {
		ternStyle(document.body).elapsor({
			image : '',
			color : '#000',
			opacity : 65,
			func : function () {
				ternEvents.addEvent('alerts_cl',hideAlerts,'click',false);
				var d = ternStyle('alerts_cn').getDimensions();
				var w = ternStyle().getWindowSize();
				ternStyle('alerts_cn').setStyle({
					top : (w[1]-d[1])/2,
					left : (w[0]-d[0])/2,
					visibility : 'visible'
				});
			}
		});
	}
}
function hideAlerts() {
	var i = document.getElementById('alerts_cn');
	i.parentNode.removeChild(i);
	ternStyle(document.body).hideElapsor();
}