function SetCookie(cookieName,cookieValue,nDays, Path)
{
   var today = new Date();
   var expire = new Date();
   if (nDays==null || nDays==0) nDays=1;
   expire.setTime(today.getTime() + 3600000*24*nDays);
	var dpath = (Path != null && Path != '') ? ';path='+Path  : '';
   document.cookie = cookieName + '=' + escape(cookieValue)
      + ";expires="+expire.toGMTString()+dpath;
}

function ReadCookie(cookieName)
{
   if ( ! (cookieName && typeof cookieName!='undefined') )
      return "";
   var theCookie=""+document.cookie;
   var ind=theCookie.indexOf(cookieName);
   if (ind==-1) ; 
   var ind1=theCookie.indexOf(';',ind);
   if (ind1==-1) ind1=theCookie.length; 
   return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


$(function() {
$('#wpcf7-f225-p100-o1 input,#wpcf7-f225-p100-o1 textarea').each(function() {
	$(this).focus(function() {
		if(this.value = 'Найти') {this.value = ''};
	});
});
});




$(function() {
	$('input#lozung').bind('blur', function() {
		var str = $(this).val();
		$('p.Value').html(str);
	});
	$('input#lozung').bind('keypress', function(e) {
		var str = $(this).val();
		$('p.Value').html(str+String.fromCharCode(e.charCode));
	});
});




$(window).ready(function(){
	

//Custom footer height	

//Front page
var frontFoot = $(".front-page").parent();

$(frontFoot).next().addClass('front-active-footer');


	$('#login-btn').bind("click", function(event){
		event.preventDefault();
		//var city_val = parseInt($('#user_city_select').attr('value'));
		var day_val = parseInt($('#user_day_select').attr('value'));
		var month_val = parseInt($('#user_month_select').attr('value'));
		var year_val = parseInt($('#user_year_select').attr('value'));
		if(day_val>0 && month_val>0 && year_val>0) {
			//var cookieValue = '{"userCity": "'+city_val+'","userDay": "'+day_val+'","userMonth": "'+month_val+'","userYear": "'+year_val+'","showLogin": "false"}';
			var cookieValueJson = {
					//userCity: city_val,
					userDay: day_val,
					userMonth: month_val,
					userYear: year_val,
					showLogin: false
			};
			var cookieValue = JSON.stringify(cookieValueJson);
			
			var now = new Date();
			var now_full_year = now.getFullYear();
			var now_month = now.getMonth();
			var now_day = now.getDate();
			
			var before18_full_year = now_full_year-18;
			var before18_month = now_month+1;
			var before18_day = now_day;
			
			if(year_val<before18_full_year || (year_val==before18_full_year && month_val<before18_month) || (year_val==before18_full_year && month_val==before18_month && day_val<=before18_day)) {
				SetCookie('loginPopup', cookieValue, 30, '/');
				$('#splash_bg').hide();
				$('#login_popup').hide();
			} else {
				location.href = 'http://www.centurycouncil.org/';
			};
		} else {
			alert('Заполните все поля!');
		};
	});


	var readedCook = ReadCookie('loginPopup');
	if(readedCook!=='') {
		
		var cook1 = JSON.parse(readedCook);
		
		if(cook1.showLogin) {
			$('#splash_bg').show();
			$('#login_popup').show();
				$("#user_city_select, #user_day_select, #user_month_select, #user_year_select").css("display","block").css("width","100px");
					params = {
					refreshEl: "#user_city_select, #user_day_select, #user_month_select, #user_year_select", /* перечисляем через запятую id селектов, которые нужно обновить */
					visRows: 2
					}
					cuSelRefresh(params);
			
		}
	} else {
		$('#splash_bg').show();
		$('#login_popup').show();
				$("#user_city_select, #user_day_select, #user_month_select, #user_year_select").css("display","block").css("width","100px");
					params = {
					refreshEl: "#user_city_select, #user_day_select, #user_month_select, #user_year_select", /* перечисляем через запятую id селектов, которые нужно обновить */
					visRows: 2
					}
					cuSelRefresh(params);		
	}
	
	

});

