oSubscribe = {
	data : {},
	fieldCaptions: {
	"email" : "Электронная почта",
	"name" : "Имя",
	"birth_date" : "Время рождения",
	"everymonth" : "Получить ежемесячный гороскоп",
	"everyday" : "Получить ежедневный гороскоп",
	"sms" : "Получить информацию по СМС",
	"msisdn" : "Телефон" },
	
	getData: function(){
		var hData = {};
		$("#subscribe_form input").each(function(){
			hData[this.name] = (this.value != $(this).attr("default")) ? this.value : "";
		});
		if(hData.birth_date_day!="" && hData.birth_date_month!="" && hData.birth_date_year!="")
			hData.birth_date = hData.birth_date_year + "-" + hData.birth_date_month + "-" + hData.birth_date_day;
		return hData;
	},
	submit: function(page){
		var t = this;
		var hData = t.getData();
		var error="";
		var mes="";
		if(!hData.name){error=1; mes="Введите Ваше имя";} else {
			if(!hData.email){error=1; mes="Введите e-mail";} else {
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				if (reg.test(hData.email) == false){error=1; mes="Некорректный email";} else {
					if(!hData.birth_date) {error=1; mes="Введите дату рождения";} else {
						if(hData.sms==1){
							if(!hData.msisdn){error=1; mes="Введите номер телефона";} else {
								if(!/^\d/.test(hData.msisdn)){error=1; mes="Номер телефона должен состоять толлько из цифр";} else {
									if(hData.msisdn.length<8){error=1; mes="В Номере телефона должно быть не меньше 8 цифр";}
								}
							}
						}
					}
				}
			}
		}

		if(error==1){
			oPopup.alert("<div align='center' style='padding-bottom:10px'>" + mes + "</div>");
			$('#butt_send').show();  $('#ajax_send').hide();
			$("#subscribe_submit").show();$("#subscribe_ajax").hide();
		} else {
			if((page=='horoscope')||(page=='goroskop')||(page=='bitva')){
				page = '';
			} else {
				page = '/registration';
			}

			$.post(page+"/subscribe/", hData, function(data){
				//$('#butt_send').hide();  $('#ajax_send').show();
				if(data.success){
					_gaq.push(['_trackEvent', 'Banner', 'Success', 'subscribe']);
					yaCounter1478111.reachGoal('Subscribe_Success');
					_gaq.push(['_trackPageview', '/subscribe/success/']);
					// AdRiver code START. Type:audit Site: kolizeo SZ: subscription PZ: 0 BN: 0
					(function(s){
						var d = document, i = d.createElement('IMG'), b = d.body;
						s = s.replace(/!\[rnd\]/, Math.round(Math.random()*9999999)) + '&tail256=' + escape(d.referrer || 'unknown');
						i.style.position = 'absolute'; i.width=1; i.height=1;
						i.onload = i.onerror = function(){b.removeChild(i); i = b = null}
						i.src = s;
						b.insertBefore(i, b.firstChild);
					})('http://ad.adriver.ru/cgi-bin/rle.cgi?sid=157262&sz=subscription&bt=55&pz=0&rnd=![rnd]');
					oPopup.alert("Спасибо! Вы подписаны на рассылку гороскопов Колизео.");
					$("#subscribe_block").hide();
					spam_close();
					$(".blockOverlay").css('background','url("/images/pop/spam_bg_bg.png")','!important');
					$(".blockOverlay").css('z-index','5000');
				} else {
					oPopup.alert("<div align='center' style='padding-bottom:10px'>" + data.error + "</div>");
					$('#butt_send').show();  $('#ajax_send').hide();
					$("#subscribe_submit").show();$("#subscribe_ajax").hide();
				}
			}, "json");
			return false;
		}
	}
}
