function showElm(id) {
	var elm = document.getElementById(id);
	if(elm) {
		elm.style.display = 'block';
	}
}

function hideElm(id) {
	var elm = document.getElementById(id);
	if(elm) {
		elm.style.display = 'none';
	}
}

function changeSubscriptionType(type) {
	var oform = document.getElementById('PromotionForm');
	if(oform) {
		changeFieldAttr('subscription_type', 'value', type);
		
		if(type == 'signin') {
			changeFieldAttr('registration_phone_number', 'checkallownull', 'true');
			changeFieldAttr('registration_phone_number', 'checktype', '');
			changeFieldAttr('registration_first_name', 'checkallownull', 'true');
			changeFieldAttr('registration_password', 'checkallownull', 'true');
			changeFieldAttr('registration_zip', 'checkallownull', 'true');
			changeFieldAttr('registration_email', 'checkallownull', 'true');
			changeFieldAttr('registration_email', 'checktype', '');
			changeFieldAttr('registration_last_name', 'checkallownull', 'true');
			changeFieldAttr('registration_terms_agreement', 'checkallownull', 'true');
			changeFieldAttr('registration_note', 'checkallownull', 'true');
			
			changeFieldAttr('signin_phone_number', 'checkallownull', 'false');
			changeFieldAttr('signin_email', 'checkallownull', 'false');
			changeFieldAttr('signin_email', 'checktype', 'email');
			changeFieldAttr('signin_password', 'checkallownull', 'false');
			changeFieldAttr('signin_note', 'checkallownull', 'false');
		}
		else {
			changeFieldAttr('registration_phone_number', 'checkallownull', 'false');
			changeFieldAttr('registration_phone_number', 'checktype', 'phone');
			changeFieldAttr('registration_first_name', 'checkallownull', 'false');
			changeFieldAttr('registration_password', 'checkallownull', 'false');
			changeFieldAttr('registration_zip', 'checkallownull', 'false');
			changeFieldAttr('registration_email', 'checkallownull', 'false');
			changeFieldAttr('registration_email', 'checktype', 'email');
			changeFieldAttr('registration_last_name', 'checkallownull', 'false');
			changeFieldAttr('registration_terms_agreement', 'checkallownull', 'false');
			changeFieldAttr('registration_note', 'checkallownull', 'false');
			
			changeFieldAttr('signin_phone_number', 'checkallownull', 'true');
			changeFieldAttr('signin_email', 'checkallownull', 'true');
			changeFieldAttr('signin_email', 'checktype', '');
			changeFieldAttr('signin_password', 'checkallownull', 'true');
			changeFieldAttr('signin_note', 'checkallownull', 'true');
		}
	}
}

function changeFieldAttr(id, name, value) {
	if(document.getElementById(id)) {
		document.getElementById(id).setAttribute(name, value);
	}
}

function checkdob(cform) {
	var PromotionDobValidationYear = document.getElementById("UserDobValidationYear");
	var PromotionDobValidationMonth = document.getElementById("UserDobValidationMonth");
	var PromotionDobValidationDay = document.getElementById("UserDobValidationDay");
	
	var dob_year = PromotionDobValidationYear.options[PromotionDobValidationYear.selectedIndex].value;
	var dob_month = PromotionDobValidationMonth.options[PromotionDobValidationMonth.selectedIndex].value;
	var dob_day = PromotionDobValidationDay.options[PromotionDobValidationDay.selectedIndex].value;
	var dob_time = dob_year + "" + dob_month + "" + dob_day;
	
	var today = new Date();
	var today_month = today.getMonth() + 1;
	today_month = today_month.toString().length > 1 ? today_month : "0" + today_month;
	var today_day = today.getDate() + 1;
	today_day = today_day.toString().length > 1 ? today_day : "0" + today_day;
	var today_time = today.getFullYear() + "" + today_month + "" + today_day;

	var dif = parseInt(today_time - dob_time);
	if(dif >= 210000) {
		var PromotionRegistrationDobYear, PromotionRegistrationDobMonth, PromotionRegistrationDobDay;
		
		var selects = document.getElementsByTagName("select");
		for(var i = 0; i < selects.length; ++i) {
			if(selects[i].name == "data[User][registration_data][dob][year]") {
				PromotionRegistrationDobYear = selects[i];
			}
			else if(selects[i].name == "data[User][registration_data][dob][month]") {
				PromotionRegistrationDobMonth = selects[i];
			}
			else if(selects[i].name == "data[User][registration_data][dob][day]") {
				PromotionRegistrationDobDay = selects[i];
			}
		}
		
		if(PromotionRegistrationDobYear) {
			for(var i = 0; i < PromotionRegistrationDobYear.options.length; ++i) {
				if(PromotionDobValidationYear.options[i].value == dob_year) {
					PromotionRegistrationDobYear.selectedIndex = i;
				}
			}
		}
		if(PromotionRegistrationDobMonth) {
			for(var i = 0; i < PromotionRegistrationDobMonth.options.length; ++i) {
				if(PromotionRegistrationDobMonth.options[i].value == dob_month) {
					PromotionRegistrationDobMonth.selectedIndex = i;
				}
			}
		}
		if(PromotionRegistrationDobDay) {
			for(var i = 0; i < PromotionRegistrationDobDay.options.length; ++i) {
				if(PromotionRegistrationDobDay.options[i].value == dob_day) {
					PromotionRegistrationDobDay.selectedIndex = i;
				}
			}
		}
		
		showElm('subscribe-registration');
		hideElm('subscribe-signin');
		changeSubscriptionType('registration');
	}
	else {
		alert("You must be at least 21");
	}
	
	return false;
}

