// ========== Global JS file for Woman's ==============

// Pop Up Window ==============
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}



//This is to Validate an email address 
function checkEmail(email) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
return (true)
}
//alert("Invalid E-mail Address! Please re-enter.")
return (false)
}
//  End -->

//This is to validate the Creation of a new MyWomans account
function validate_register() {
    my_form = document.getElementById('register');
    my_error = false;
    my_alert="";
    my_email = checkEmail(my_form.email.value);
     if (!my_email) {
      	  my_error = true;
      	  my_alert = 'Your email address is not valid please agiain. \n\r';
      }
 	
     if (my_form.email.value !=  my_form.email2.value) {
     	 my_error = true;
      	 my_alert += 'Your email addresss do not match please agiain. \n\r';
     } 
   
     
     if(my_form.pword.value.length < 5) {
     	 my_error = true;
      	 my_alert += 'Password is to short please try again. \n\r';
     }
     
     
     if(my_form.pword2.value != my_form.pword.value) {
     	 my_error = true;
      	 my_alert += 'Your passwords do not match please agiain. \n\r';
     }
      
      
   if(my_error) {
   		alert(my_alert);
   		return false;
   }   
	else {
		my_form.submit();
	}
}


<!-- Begin
function popUppass(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300');");
}
// End -->


//This is the function to validate story
function validate_story() {
	my_form = document.getElementById('story');
    my_alert = "";
	my_error = false;
	  
	  if(my_form.name.value.length < 3) {
	     my_error = true;
	     my_alert = "Your name must be > 3 characters \n";
	  } 
	  
	    if(my_form.age.value.length < 1) {
	     my_error = true;
	     my_alert += "Your age must be at least 1 characters \n";
	  } 
	  
	    if(my_form.city.value.length < 3) {
	     my_error = true;
	     my_alert += "Your city must be > 2 character \n";
	  } 
	  
	    if(my_form.state.value.length != 2) {
	     my_error = true;
	     my_alert += "Your state must be 2 characters \n";
	  } 
	  
	  if(my_form.my_story.value.length < 3) {
	     my_error = true;
	     my_alert += "Your story must be > 3 characters \n";
	  } 

     
	 if(my_error) {
	 	alert(my_alert);
	 }
      else {
	    document.forms.story.submit();
	  }
}




//This is the function to validate story
function validate_testimony() {
	my_form = document.getElementById('testimony');
    my_alert = "";
	my_error = false;
	  
	  if(my_form.name.value.length < 3) {
	     my_error = true;
	     my_alert = "Your name must be > 3 characters \n";
	  } 
	  
		  
	  if(my_form.city.value.length < 3) {
	     my_error = true;
	     my_alert += "Your city must be > 2 character \n";
	  } 
	  
	    if(my_form.state.value.length != 2) {
	     my_error = true;
	     my_alert += "Your state must be 2 characters \n";
	  } 
	  
	  if(my_form.my_story.value.length < 3) {
	     my_error = true;
	     my_alert += "Your story must be > 3 characters \n";
	  } 

     
	 if(my_error) {
	 	alert(my_alert);
	 }
      else {
	    document.forms.testimony.submit();
	  }
}




function validateDate(form_name) {
    var my_form = document.getElementById(form_name);
    var fld = my_form.due_date;
	var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var errorMessage = 'Please enter valid date as month, day, and four digit year.\nFormat mm-dd-yyyy.';
    if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
        my_form.submit();
    	//alert('Date is OK'); 
    } else {
        alert(errorMessage);
        return false;
        //fld.focus();
    } 
}


function Show_Class_Subs() {
   my_form = document.getElementById('classes');	
   my_layer =  document.getElementById('SubType');
   my_show = false;
    for(i=0; i<my_form.CL_SER_ID.length; i++) {
    	if (my_form.CL_SER_ID.options[i].value==395 && my_form.CL_SER_ID.options[i].selected == true) {
    	    my_show = true;
      	}	
    }

if(my_show) {
  my_layer.style.display = 'block';
 
}  
else {
  	my_layer.style.display = 'none';
     
}
}


function account_merge (form_name) {
  
  var my_alert = '';
  var my_error = false;
  var my_form = document.getElementById(form_name); 		
  var form_name2;   
  
    if(form_name == "REG_ID") form_name2 = "wm_user";
      else 	form_name2 = "REG_ID";
  var my_form2 = document.getElementById(form_name2);
  
  //This is to check if no data set is selected
  if(!my_form.set.checked && !my_form2.set.checked) {
  	  my_error = true;
  	  my_alert += "You must select at least one Data set \n"; 	
  }
  
    //This is to check if both data set is selected
  if(my_form.set.checked && my_form2.set.checked) {
  	  my_error = true;
  	  my_alert += "You may only select one Data set \n"; 	
  }
  
  
  
  //This is to display the alert if errir
  if(my_error) {
  	alert(my_alert);
  }
    else my_form.submit();

}

