/* ------------- unpersonalized horoscope selection -----------*/
function getHoroscope(sign) {
	document.horoscope_form.sign.value = sign;
	document.horoscope_form.submit();	
}

/*------------------ personalized form -------------------------*/
function showEmailArea(){
	var agt=navigator.userAgent.toLowerCase();
	if (document.getElementById('EmailOption')) {
		if (document.getElementById('EmailOption').checked) {
			document.getElementById('EmailArea').style.display = 'block';
		}
		else { 
			document.getElementById('EmailArea').style.display = 'none';
			document.horoscope_personalized.email.value = "";
		}	
	}
}

function isStringEmpty(StrInput) {
	var i, taille = StrInput.length;

	if (0 >= taille) return true;

	for (i = 0; i<taille; i++)
		if (' ' != StrInput.charAt(i)) return false;

	return true;
}

function SubmitValidation() {
	var aVariable, aConfirmationVariable, aBirthTimeUnkownFlag = false, aField;

	 // Use individual regular expressions to validate other parameters
		var aFormName = window.document.horoscope_personalized;
	
		if (aFormName.FirstName) {
			aVariable = aFormName.FirstName.value;
			if (isStringEmpty(aVariable)) {
				alert("Please enter your first name");
				return false;
			}
			var fieldRegExp = /^[a-z\.\_ \-\']{1,40}$/i;
			if(!(fieldRegExp.test(aVariable))){
				alert("Please enter your correct first name");
				return false;
			}
			
		}
	
		if (aFormName.MonthSelector) {
			aVariable = aFormName.MonthSelector[aFormName.MonthSelector.selectedIndex].value;
			if (isStringEmpty(aVariable)) {
				alert("Please select your birth month");
				return false;
			}
		}
		
		if (aFormName.DaySelector) {
			aVariable = aFormName.DaySelector[aFormName.DaySelector.selectedIndex].value;
			if (isStringEmpty(aVariable)) {
				alert("Please select your birth day");
				return false;
			}
		}
	
		if (aFormName.YearSelector) {
			aVariable = aFormName.YearSelector[aFormName.YearSelector.selectedIndex].value;
			if (isStringEmpty(aVariable)) {
				alert("Please select your birth year");
				return false;
			}
		}
	
		var emailCheckBox = aFormName.EmailOption;
		var emailField = aFormName.email;
		if(emailCheckBox){
			if (emailCheckBox.value != null && emailCheckBox.checked) {
				if (emailField.value != null && emailField.value == "") {
					alert("Please enter your email address to get your AstroProfile or uncheck the box if you don't want to receive it.")
					return false;
				}		
		
				var emailAdressRegExp = /^[a-z0-9_\.\-]+\@(?:[0-9a-z][a-z0-9\-]+\.)+[a-z]{2,4}$/i;
				if(!emailAdressRegExp.test(emailField.value)){
					alert("Please enter a valid email address");
					return false;
				}
			}
		}	
	
	return true;
}

/*------------------ subscriber info -------------------------*/
function show_the_overlay() {
	if( document.getElementById('horoscope_subsciber_info') ) {
		document.getElementById('horoscope_subsciber_info').innerHTML = getSubscriberContent();
		document.getElementById('horoscope_subsciber_info').style.display = 'block';
	}
	if( document.getElementById('GenderSelector') ) document.getElementById('GenderSelector').style.visibility="hidden";
	if( document.getElementById('MonthSelector') ) document.getElementById('MonthSelector').style.visibility="hidden";
	if( document.getElementById('DaySelector') ) document.getElementById('DaySelector').style.visibility="hidden";
	if( document.getElementById('YearSelector') ) document.getElementById('YearSelector').style.visibility="hidden";
	if( document.getElementById('advertisement') ) document.getElementById('advertisement').style.display = 'none';
}
function hide_the_overlay() {
	if( document.getElementById('horoscope_subsciber_info') ) {
		document.getElementById('horoscope_subsciber_info').style.display = 'none';
	}	
	if( document.getElementById('GenderSelector') ) document.getElementById('GenderSelector').style.visibility="visible";
	if( document.getElementById('MonthSelector') ) document.getElementById('MonthSelector').style.visibility="visible";
	if( document.getElementById('DaySelector') ) document.getElementById('DaySelector').style.visibility="visible";
	if( document.getElementById('YearSelector') ) document.getElementById('YearSelector').style.visibility="visible";
	if( document.getElementById('advertisement') ) document.getElementById('advertisement').style.display = 'block';
}
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ 
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/");
}
function deleteCookie(c_name) {
	document.cookie = c_name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;path=/';
}
function setFlag() {
	if (document.getElementById("personalizeNotice").checked == true) {
		setCookie('personalizeNotice','personalizeNotice',10000);
	} else {
		deleteCookie('personalizeNotice');
	}
}

function getSubscriberContent() {
	var returnValue;
	returnValue = '<div id="display_overlay_bg"></div>';
	returnValue = returnValue + '<div id="display_content">';
	returnValue = returnValue + '<b>Welcome! Thank you for being an active e-mail subscriber.</b><br><br>';

	returnValue = returnValue + 'This computer does not have your Sun Sign information because you haven\'t personalized yet.<br><br>';
	returnValue = returnValue + '<div style="height:5px"></div>';
	returnValue = returnValue + '<img src="http://www.astrocenter.com/us/images/PE.gif" align="center"><br><br>';
	returnValue = returnValue + '<a onclick="hide_the_overlay()" style="cursor:pointer"><font color="#0099CC">Click here</font></a> to enter your birth information and personalize!<br><br>';
	returnValue = returnValue + '<center>';
	returnValue = returnValue + '<input id="personalizeNotice" type="checkbox" onClick="setFlag()">Don\'t display this message anymore<br>';

	returnValue = returnValue + '<a onclick="hide_the_overlay()" style="cursor:pointer"><font color="#0099CC">close window <b>[x]</b></font></a>';
	returnValue = returnValue + '</center>';
	returnValue = returnValue + '</div>';
	
	return returnValue;
}

/*------------------ misc -------------------*/
function centeredPopup(page, popWidth, popHeight) {
	var options = 'toolbar=0,scrollbars=1,resize=1';
	window.open(page,"centerHoroscope","width="+popWidth+",height="+popHeight+","+options);
}

/*----------------- advertisement --------------------*/




