/* MediaPlus cmo34 Version cmo34B 03/31/07 12:24:12 delta js/registration.js
** Copyright 2001 Publishing Business Systems, Inc.
** All Rights Reserved Worldwide.
*/
/* #168449 07.03.16 todd	Merge CMO 3.3b WR#168448 up to 3.4.
** #168448 06.10.03 todd    Put accountNumber validation in validate.js function
** #168832 06.12.07 mickeyg Pass params to checkpwdlength; obsolete tab function
** #160027 06.10.02 mickeyg Check is house number field exists.
** #161592 06.09.21 mickeyg Updated phone references.
** #166066 06.03.25 todd	Identified as left behind
** #165666 06.03.08 robi	Merged 159865 up from 33.
** #159865 05.08.02 mickeyg	Addded RequireNumeric check.
** #161091 05.07.21 robi	Merged 161091 up from 33.
** #160965 05.03.29 mickeyg Added submitcount check; Validate account number
**              			and add myform var.
** #159742 05.01.04 mickeyg Created. 
** js/registration.js
** - validation routines used for Account Registration
** -------------------------------------------------------------------------- */

function init() {
	if (document.forms[0].accountnumber) {
		document.forms[0].accountnumber.focus();
	}
}

function valregistration(myform) {
	var submitcount = 0; 
	if (submitcount == 0) { 
    	// define and assign variables
		var myform = document.forms[0];
		var findcount = 0;
    	var alertMsg = "";
    	var housenumber = "";
    	accountnumber = trim(myform.accountnumber.value);
		phonenumber = trim(myform.phone.value);
    	if (myform.housenumber) {
			housenumber = trim(myform.housenumber.value);
		}
    	zipcode = trim(myform.zipcode.value);
    	lastname = trim(myform.lastname.value);
    	email = trim(myform.email.value);
    	newpwd = trim(myform.newpwd.value);
    	confirmpwd = trim(myform.confirmpwd.value);

		if (accountnumber != "") {
			findcount++;
		}
		if (phonenumber != "") {
			findcount++;
		}
		if (housenumber != "") {
			findcount++;
		}
		if (zipcode != "") {
			findcount++;
		}
		if (lastname != "") {
			findcount++;
		}

		if (findcount < 2 ) {
			alert('Please enter at least 2 pieces of account information.');
			myform.accountnumber.focus();
			return false;
		}

		// check required fields
    	if (email == "") {
    		alertMsg = (alertMsg + "Email Address \n");
 		}	
    	if (newpwd == "") {
    		alertMsg = (alertMsg + "Password \n");
 		}	
    	if (confirmpwd == "") {
    		alertMsg = (alertMsg + "Confirm Password \n");
    	}
    	if (alertMsg != "") {
    		alertMsg = ("Please fill in the following fields: \n" + alertMsg);
        	alert(alertMsg);
        	return false;
    	}

		// validate data format/type
		if (accountnumber != "") {
			if (myform.requirenumeric == undefined) {
                if (!validateAccountNumber(accountnumber)) {
                    return false;
                }
			}
		}

		if (phonenumber != "") {
			if(!checkPhoneNumber(myform.phone)){
    			return false;
			}
    	}
    	if(!validateEmail()) {
    		return false;
    	}
    	if (myform.newpwd) {
			if(!checkpwdlength(myform.newpwd, myform.pwdlength)) {
    			return false;
			}
		}
    	if (newpwd != confirmpwd) {
    		alert("Passwords do not match. Please enter again.");
	    	myform.newpwd.select();
        	return false;
    	}

		// increment counter to prevent multiple submissions
		submitcount++;
	}
	else {
		alert('Please wait.  We are searching our database for your records.');
	}

}	
