// get rid of dashes, spaces, etc, from cc or bank numbers
/////////////////////////////////////////////////
function makeNum(what) {
	var digits = '';
	for (var i = 0; i < what.length; i++)	{
		if ((what.charAt(i) == '0') || (what.charAt(i) == '1') || 
			(what.charAt(i) == '2') || (what.charAt(i) == '3') || 
			(what.charAt(i) == '4') || (what.charAt(i) == '5') || 
			(what.charAt(i) == '6') || (what.charAt(i) == '7') || 
			(what.charAt(i) == '8') || (what.charAt(i) == '9'))	{
			digits = digits + what.charAt(i);
		}
	}
	return digits;
}

function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return false;
		}	
	} 

	// Newer browsers
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (re.test(e) || !re_two.test(e)) {
			return false;
		} 
	// Older Browsers
	} else {

		var myAtSymbolAt = e.indexOf('@');
		var myLastDotAt = e.lastIndexOf('.');
		var mySpaceAt = e.indexOf(' ');
		var myLength = e.length;

		// at least one @ must be present and not before position 2
		// @yellow.com : NOT valid
		// x@yellow.com : VALID

		if (myAtSymbolAt < 1 ) {
			return false;
		}

		// at least one . (dot) afer the @ is required
		// x@yellow : NOT valid
		// x.y@yellow : NOT valid
		// x@yellow.org : VALID

		if (myLastDotAt < myAtSymbolAt) {
			return false;
		}

		// at least two characters [com, uk, fr, ...] 
		//   must occur after the last . (dot), but not more than 4
		// x.y@yellow. : NOT valid
		// x.y@yellow.a : NOT valid
		// x.y@yellow.ca : VALID

		if (myLength - myLastDotAt <= 2 || myLength - myLastDotAt >= 4) {
			return false;
		}

		// no empty space " " is permitted (one may trim the email)
		// x.y@yell ow.com : NOT valid

		if (mySpaceAt != -1) {
			return false;
		}
	}
	return true;
}

function verifyFlash(flfname,fllname,flemail,flcemail,flevephone) {
	document.signupform.fname.value = flfname;
	document.signupform.lname.value = fllname;
	document.signupform.email.value = flemail;
	document.signupform.cemail.value = flcemail;
	document.signupform.evephone.value = flevephone;
	verify(document.signupform,'no');

}
function verify(frm,dofocus) {
	if (dofocus != 'no') {
		dofocus = 'yes';
	}
	if (frm.fname.value == '') {
		alert('You have not entered your first name.');
		if (dofocus == 'yes') {
			frm.fname.focus();
		}
		return false;
	}
	if (frm.fname.value.length > 50) {
		alert('We can only accept 50 characters for your first name.');
		if (dofocus == 'yes') {
			frm.fname.focus();
		}
		return false;
	}
	if (frm.lname.value == '') {
		alert('You have not entered your last name.');
		if (dofocus == 'yes') {
			frm.lname.focus();
		}
		return false;
	}
	if (frm.lname.value.length > 50) {
		alert('We can only accept 50 characters for your last name.');
		if (dofocus == 'yes') {
			frm.lname.focus();
		}
		return false;
	}
	if (frm.email.value == '') {
		alert("You have not entered your email address.");
		if (dofocus == 'yes') {
			frm.email.focus();
		}
		return false;
	}
	if (!check_email(frm.email.value)) {
		alert("You have not entered a valid email address.");
		if (dofocus == 'yes') {
			frm.email.focus();
		}
		return false;
	}	
	if (frm.cemail.value == '') {
		alert("You have not verified your email address.");
		if (dofocus == 'yes') {
			frm.cemail.focus();
		}
		return false;
	}
	if (frm.email.value != frm.cemail.value)	{
		alert('The email addresses do not match.');
		if (dofocus == 'yes') {
			frm.email.focus();
		}
		return false;
	}
	if (frm.evephone.value == '') {
		alert("You have not entered your phone number.");
		if (dofocus == 'yes') {
			frm.evephone.focus();
		}
		return false;
	}
	if (frm.evephone.value != '') {
		if (/[^\(\)\+\-0-9\s]/.test(frm.evephone.value)) {
			alert("Your phone number may contain only numbers + ( ) - and space.");
			if (dofocus == 'yes') {
				frm.evephone.focus();
			}
			return false;
		}
		var checkEvePhone = makeNum(frm.evephone.value);
		if (checkEvePhone.length < 10 && frm.evephone.value != '') {
			alert('You must enter at least 10 digits for your Evening Phone');
			if (dofocus == 'yes') {
				frm.evephone.focus();
			}
			return false;
		}
	}
	if (frm.submitted.value == 1) {
		validate = confirm('You have already clicked the "Submit" button.\n\n' + 
			'If you are retrying after an error, click "OK."\n\n' +
			'If you accidently double-clicked, click "Cancel."');
		if (validate == false) {
			return false;
		}
	} 
	frm.submitted.value = 1;
	frm.submit();

}

