function isEmail(text) {

	var textoStr = text.value.toString();

	var tiene = 0;
	var tieneP= 0;	
	valor = true;

	for(var i = 0;i < textoStr.length;i++)	{ 

		var oneChar = textoStr.charAt(i)
		if (oneChar == "@") { 
			tiene = 1
		}
		if ((oneChar == ".")&&(tiene==1)) { 
			tieneP = 1
		}
	}
	
	if ((tiene != 1)||(tieneP!=1)) { 
		valor=false;
	}	
	
	if (valor==false){
		alert("Please enter a valid email address");
		text.value="";
	}
}

function equal(text1, text2){
  	if(text1.value!=text2.value){
		alert("The passwords you entered do not match");  
		text1.value="";
		text2.value="";		 
	}		
}

function validator(){
	
	var fname=document.frm.firstname.value;
	var lname=document.frm.lastname.value;
	var email=document.frm.emailaddress.value;
	var pass=document.frm.pass.value;
	var repass=document.frm.repass.value;
	var address=document.frm.address.value;
	var city=document.frm.city.value;
	var state=document.frm.state.value;
	var zip=document.frm.zip.value;
	var val=true;

	if((fname=="")||(lname=="")||(email=="")||(pass=="")||(repass=="")||(address=="")||(city=="")||(state=="")||(zip=="")){
		document.bgColor="#ffffcc";
		alert("Please, complete all the information with *" );
		val=false;
	}
	
	return val;
}

function validator2(){
	
	var fname=document.frm.firstname.value;
	var lname=document.frm.lastname.value;
	var email=document.frm.emailaddress.value;
	var pass=document.frm.pass.value;
	var address=document.frm.address.value;
	var city=document.frm.city.value;
	var state=document.frm.state.value;
	var zip=document.frm.zip.value;
	var val=true;

	if((fname=="")||(lname=="")||(email=="")||(pass=="")||(address=="")||(city=="")||(state=="")||(zip=="")){
		document.bgColor="#ffffcc";
		alert("Please, complete all the information with *" );
		val=false;
	}
	
	return val;
}


function show_name(sname,val){
	if((val=="Friend")||(val=="Other")) {
		me.style.visibility="visible";
		if(val=="Friend"){
		    document.frm.namefo.value="Enter Name";
		}else{
			document.frm.namefo.value="Provide Source";
		}
			
	} else {
		me.style.visibility="hidden";
	}
}

function toggleVisibility(me) {
	if (me.style.visibility=="hidden") {
		me.style.visibility="visible";
	} else {
   	me.style.visibility="hidden";
	}
}

function addChild(){
	document.frm.child.value="add";
	var cant=document.frm.num.value;
	cant++;
	document.frm.num.value=cant;
	document.frm.submit();
}
  
function submitForm(){
	if(document.frm.child.value=="add"){
		document.frm.action="membership.php";
	} else {	
		if(validator()){	
			document.frm.action="membership_post.php";			
		}
	}
}
  
function due_date(val){	
	if(val=="N"){
		document.frm.monthdd.disabled=true;
		document.frm.daydd.disabled=true;
		document.frm.yeardd.disabled=true;	

		document.frm.dmonth_to.disabled=true;
		document.frm.dday_to.disabled=true;
		document.frm.dyear_to.disabled=true;	
	}else{
		document.frm.monthdd.disabled=false;
		document.frm.daydd.disabled=false;
		document.frm.yeardd.disabled=false;

		document.frm.dmonth_to.disabled=false;
		document.frm.dday_to.disabled=false;
		document.frm.dyear_to.disabled=false;	
	}
}
  
function submitFormAdmin(){
	if(document.frm.child.value=="add"){
		document.frm.action="addMembership.php";
	} else{	
		document.frm.num.value=0;	
		if(validator()){			
			document.frm.action="addMembership_post.php";			
		}
	}
}
	
function submitFormEdit(){
	if(document.frm.child.value=="add"){
		document.frm.action="editUser.php";
	} else {	
		document.frm.num.value=0;	
		document.frm.action="editUser_post.php";			
	}
}
	
function submitFormEditMem(){
	if(document.frm.child.value=="add"){
		document.frm.action="editMember.php";
	} else {
		document.frm.num.value=0;
		if(validator2()){
			document.frm.action="editMember_post.php";			
		}
	}
}
	
function isEmailAddress(email)
{
	var s = email.value.toString();
	var filter=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
		return true;
	else
		alert("wrong mail");
	return false;
}

function submitFormLogin(){ 
	if(document.frm.newpass.value=="new"){
		document.frm.action="newPass.php";
	} else {
		if(document.frm.emailaddress.value == "" || document.frm.pass.value == "" ) {
			alert("You must enter a valid email address and a valid password in order to login");
		} else {
			document.frm.action="login_post.php";			
		}
	}
}

function newPass(){
  	document.frm.newpass.value="new";
	document.frm.action="newPass.php";
	document.frm.submit();
  }

function uncheckall(status) {
	if(status) {
		document.frm.edu_seminar.checked = false;
		document.frm.expectant_events.checked = false;
		document.frm.holiday.checked = false;
		document.frm.new_mom_events.checked = false;
		document.frm.photo.checked = false;
		document.frm.shopping.checked = false;
		document.frm.family_events.checked = false;
		document.frm.other.checked = false;
	}
}

function uncheckallevents(status) {
	if(status) {
		document.frm.all_events.checked = false;
	}
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else
		cntfield.value = maxlimit - field.value.length;
}
