// Cure of Souls check forms

function checkEbook(ebook)
{
	if(!ebook.yourName.value || !ebook.yourEmail.value)
	{	
		alert('You must enter your name and e-mail address');
		return false;
	}
	
	var x = ebook.yourEmail.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (!filter.test(x)) 
	{ 
		alert('Please enter a valid e-mail address, e.g. user@domain.com.'); return false; 
	}
}


function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = (screen.width - w) / 2; 
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+','
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function checkForm(mform)
{
	if(!mform.fullname.value)
	{	alert('You must enter your name.');	return false;	}
	
	if(!mform.address1.value)
	{	alert('You must enter your address.');	return false;	}
	
	if(!mform.city.value)
	{	alert('You must enter your city.');	return false;	}
	
	if(!mform.state.value)
	{	alert('You must enter your state.');	return false;	}
	
	if(!mform.zip.value)
	{	alert('You must enter your zip code.');	return false;	}
	
	if(!mform.email.value)
	{	alert('You must enter your e-mail address.');	return false;	}
	
	
	
	var x = mform.email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (!filter.test(x)) 
	{ 
		alert('Please enter a valid e-mail address, e.g. user@domain.com.'); return false; 
	}
	
	var strGroupName="membership[]";
 	var checkedCount=0;
 	for (var i=0; i<document.mform[strGroupName].length; i++)
 	{
		var curBox=document.mform[strGroupName][i];
		checkedCount += (curBox.checked)?1:0;
 	}
 	if (checkedCount == 0) 
	{ 
		alert("You must select a membership category."); return false; 
	}
	
	if(!mform.schoolname1.value)
	{	alert('You must enter your the name of your school.');	return false;	}
	
	if(!mform.schooladdress1.value)
	{	alert('You must enter your the address of your school.');	return false;	}
	
	if(!mform.datesattended1.value)
	{	alert('You must enter the dates attended for your school.');	return false;	}
	
	if(!mform.credits1.value)
	{	alert('You must enter your credits or degree earned from your school.');	return false;	}
	
	if(!mform.major1.value)
	{	alert('You must enter your major subject from your school.');	return false;	}
	
	if(!mform.CC_Type.value || !mform.CC_Number.value || !mform.exp_mo.value || !mform.exp_yr.value)
	{	alert('You must fill in all credit card information.');	return false;	}
	
	var y = mform.CC_Number.value;
	
	if (isNaN(y)) 
	{ 
		alert("Credit card number must contain only numbers."); return false; 
	}

	var dateToday = new Date( );
	var dateYear = dateToday.getFullYear( );
	var dateMonth = dateToday.getMonth( ) + 1;
	
	if (mform.exp_mo.value < (dateMonth) && mform.exp_yr.value <= (dateYear))
	{ 
		alert("Invalid Expiration Date."); return false; 
	}
	
	else 
	{
		return checkCC(mform.CC_Number.value,mform.CC_Type.value); 
	}
}

function checkCC(n,o) 
{
	var num = n;
	var type = "";
	var realType = o;
	var z = o;

	if(num.substring(0,1) == "3") { type="American Express"; }
	if(num.substring(0,1) == "4") {	type="Visa"; }
	if(num.substring(0,1) == "5") { type="MasterCard"; }

	if (num.length == 15 && type == z && type == "American Express") { return true; }
	else if (num.length == 16 && type == z && type == "Visa") { return true;  }
	else if (num.length == 16 && type == z && type == "MasterCard") { return true;  }
	else { alert("Invalid credit card information.  Please try again."); return false; }
}

