
 function nlBuild() {
	var nlCh = '';
	for (var z = 0; z < document.form_sign_up_addr.nlChoiceTmp.length; z++) {
		if (document.form_sign_up_addr.nlChoiceTmp[z].checked == true) {
			nlCh = nlCh + '&nlChoice=' + document.form_sign_up_addr.nlChoiceTmp[z].value;
		}
	}
	nlCh = nlCh.substring(1);
	document.form_sign_up_addr.nlChoice.value = nlCh;
 }
		
 function fillboxes() {
		for( x=0; x<document.form_sign_up_addr.nlChoiceTmp.length; x++) {
			eval("document.form_sign_up_addr.nlChoiceTmp[x].checked='true'")
		}
 }
 
 function lTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
			s = s.substring(j, i);
	}
	return s;
 }
 function rTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
			s = s.substring(0, i+1);
	}
	return s;
 }
 function trim(str) {
	return rTrim(lTrim(str));
 }

 function IsEmptyField(TextObj){
		//alert(TextObj);
		//alert(TextObj.value);
	return IsEmptyStr(TextObj.value)
}

function IsEmptyStr(Str){
	var retval = true;
	for (var i=0; i < Str.length; ++i){
		var c = Str.charAt(i);
		if (c != ' ' && c != '\t')
			retval = false;
	}
	return retval;
}

function checkform_sign_up_addr() {
	if (document.form_sign_up_addr.tos.checked != true) {
		alert('You must accept the Beliefnet Greetings Terms and Conditions.');
		return false;
	}
	nlBuild();
	/* if (IsEmptyField(document.form_sign_up_addr.user_name)){
		alert ("Please enter your first name.");
		return false;
	} */
	if (IsEmptyField(document.form_sign_up_addr.user_name)){
		alert ("Please enter your first name.");
		return false;
	}
	if (IsEmptyField(document.form_sign_up_addr.user_last_name)){
		alert ("Please enter your last name.");
		return false;
	}
	if (IsEmptyField(document.form_sign_up_addr.user_email)){
		alert ("Please Enter Your Email.");
		return false;
	}
	//if(document.form_sign_up_addr.user_email.value.indexOf("\@")==-1 || document.form_sign_up_addr.user_email.value.indexOf(".")==-1){
	//	alert ("Please enter correct your email address.")
	//	return false;
	//}
	var objRegExp = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if(!objRegExp.test(document.form_sign_up_addr.user_email.value)){
		alert("Please enter correct your email address.");
		document.form_sign_up_addr.user_email.focus();
		return;
	}
	if (IsEmptyField(document.form_sign_up_addr.user_name_id)){
		alert ("Please select a user ID.");
		document.form_sign_up_addr.user_name_id.focus();
		return false;
	}
	if (IsEmptyField(document.form_sign_up_addr.user_password) || IsEmptyField(document.form_sign_up_addr.password2)){
		alert ("Please enter your password.");
		return false;
	}
	if (document.form_sign_up_addr.user_password.value != document.form_sign_up_addr.password2.value){
		alert ("Please re-enter your password.");
		return false;
	}
	if (document.form_sign_up_addr.user_password.value.length < 6){
		alert ("Your password is too short. (minimum 6 characters).");
		return false;
	}
	if (document.form_sign_up_addr.user_gender.value == ''){
		alert ("Please enter your gender.");
		return false;
	}
	//if (IsEmptyField(document.form_sign_up_addr.us_zip)){
	if((IsEmptyField(document.form_sign_up_addr.user_zip)) || ((document.form_sign_up_addr.user_zip.value.length != 5) && (document.form_sign_up_addr.user_zip.value.length >7))){
		alert ("Please enter your zip code.");
		return false;
	}
	if (!verifyDate(document.form_sign_up_addr.user_birth_year.value, document.form_sign_up_addr.user_birth_mon.value, document.form_sign_up_addr.user_birth_mday.value)){
		alert ("Please enter your birthdate.");
		return false;
	}
	document.form_sign_up_addr.step.value='sign_up2';
	return true;
}

function addAddressVerifyDate (year1,month1,day1,year2,month2,day2,run) {
	/* in case they want the year blank but we still need to verfiy the month and day */
	if (year1 == '') { year1 = '1904'; }
	if (year2 == '') { year2 = '1904'; }
	
	badBDay = false; badSpecialDay = false; /* temp variable */
	
	if (month1 != '' || day1 != '') {
	/* if they entered something then test - if date is invalid then it is a badBDay */
		if (!verifyDate(year1,month1,day1)){ badBDay = true; }
	}
	if (month2 != '' || day2 != '') {
	/* if they entered something then test - if date is invalid then it is a badSpecialDay */
		if (!verifyDate(year2,month2,day2)){ badSpecialDay = true; }
	}
	
	if (badBDay || badSpecialDay) {
		alert ("Please enter a valid birthdate and/or special day.");
		return false;
	}
	if (run == '' || run == null) { return true; }
	else { eval(run); return true; }
}
function verifyDate (year,month,day) {
	/* if (month > 12) { return false; }
	if (day > 31) { return false; } */
	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
		if (day > 31) { return false; }
	}
	if (month == 4 || month == 6 || month == 9 || month == 11) {
		if (day > 30) { return false; }
	}
	if (month == 2 && ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
		if (day > 29) { return false; }
	} else if (month == 2) {
		if (day > 28) { return false; }
	}
 	if (!/^([0-9]{4})$/.test(year) || !/^([0-9]{1,2})$/.test(month) || !/^([0-9]{1,2})$/.test(day)) {
 		return false;
 	}
 	/* var ud = new Date();
 	var cd = new Date();
 	ud.setMonth(month-1);
 	ud.setDate(day);
 	var msg = '';
 	var diff = cd.getFullYear() - year;
 	
 	if (cd.getTime() < ud.getTime()) { diff -= 1; }
		
	if (diff < 18 || diff > 150) { return false; } */
	else { return true; }
}
function checkform_update_acct() {
	if (IsEmptyField(document.form1.user_name)){
		alert ("Please enter your first name.");
		return false;
	}
	if (IsEmptyField(document.form1.user_last_name)){
		alert ("Please enter your last name.");
		return false;
	}
	if (IsEmptyField(document.form1.user_email)){
		alert ("Please Enter Your Email.");
		return false;
	}
	//if(document.form1.user_email.value.indexOf("\@")==-1 || document.form1.user_email.value.indexOf(".")==-1){
	//	alert ("Please enter correct your email address.")
	//	return false;
	//}
	var objRegExp = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if(!objRegExp.test(document.form1.user_email.value)){
		alert("Please enter correct your email address.");
		document.form1.user_email.focus();
		return;
	}
	if (document.form1.user_gender.value == ''){
		alert ("Please enter your gender.");
		return false;
	}
	//if (IsEmptyField(document.form1.us_zip)){
	if((IsEmptyField(document.form1.user_zip)) || ((document.form1.user_zip.value.length != 5) && (document.form1.user_zip.value.length >7))){
		alert ("Please enter your zip code.");
		return false;
	}
	if (!verifyDate(document.form1.user_birth_year.value, document.form1.user_birth_mon.value, document.form1.user_birth_mday.value)){
		alert ("Please enter your birthdate.");
		return false;
	}
	document.form1.step.value='user_info2';
	return true;
}