
function PopUpTestString(pblnDebugging, pstrText){
// This function is used for debugging purposes. 
// It writes a test string to a popup window.
//
//	Company : Cadent.com
//	Author  : Chris Fusco
// 	Project : 
//
//	Parameters : 
//		pblnDebugging	- the form data
//		pstrText 		- comma separated list of required fields. (ie. ",Field1,Field2,Field3,")

	// If debugging is 'on'
	if (pblnDebugging){
		// popup the text
		alert(pstrText);
	}

}

function ValidateCertainFields(prqfdata, pstrReqFields){
// To implement, put the following in the <FORM> tag:
//
//      onSubmit="javascript:return ValidateCertainFields(this, strRequiredFields);"
//
// This function validates for a list of controls passed to it. 
// It returns true or false. If false, it pops up an alert box with 
// an error message.
//
//	Company : Cadent.com
//	Author  : Chris Fusco
// 	Project : 
//
//	Parameters : 
//		prqfdata		- the form data
//		pstrReqFields 	- comma separated list of required fields. (ie. ",Field1,Field2,Field3,")

	// Retrieve the list of required fields
	strReqFields	= pstrReqFields;

	// Error message displayed if form is invalid.
	strErrMsg		= "Please fill in all required fields.";

      // Assume success    
      blnValid    	= true;

      // for each control
	intNumControls	= prqfdata.elements.length;
      for (i = 0; i < intNumControls; i ++){

	    strControl	= prqfdata.elements[i].name;  
	    strControl 	= "," + strControl + ",";
	    intPos 		= strReqFields.indexOf(strControl);

	    // if this is NOT one of our Omitted Fields
	    if (intPos != -1){
	  	  // if this control has no data
        	  if (prqfdata.elements[i].value == ""){
        	      // note we have empty fields
        	      blnValid    = false;
        	  }    
	    }
      }

	// If the required fields are not filled in
	if (!blnValid) {
		// alert the user
		alert(strErrMsg);
	}
	return blnValid;
}
//	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function ValidateAllFields(prqfdata, pstrOmitFields){
// To implement, put the following in the <FORM> tag:
//
//      onSubmit="javascript:return ValidateAllFields(this);"
//
// This function validates for empty fields in a form; it bypasses any
// control names that are passed to it. It returns true or false. 
// If false, it pops up an alert box with an error message.
//
//	Company : Cadent.com
//	Author  : Chris Fusco
// 	Project : 
//
//	Parameters :
//		prqfdata			- the form data
//		pstrOmitFields 	- string of comma delimited controls
//					that we don't need to validate for. 
//					(ie. ",Control1,Control2,Control3,")

    //alert("Omit these fields = " +pstrOmitFields);
    strOmitFields = pstrOmitFields;
    // Error message displayed if form is invalid.
    strErrMsg	= "Please fill in all required fields.";

    // Assume success    
    blnValid    		= true;

    intNumControls	= prqfdata.elements.length; 
    // for each control
    for (i = 0; i < intNumControls; i ++){

	  strControl	= prqfdata.elements[i].name;  
	  strControl 	= "," + strControl + ",";
	  intPos 		= strOmitFields.indexOf(strControl);
	  blnNotOmitted	= (intPos == -1);

    	  //PopUpTestString(blnDebugging, "Testing for "+strControl);
	  //PopUpTestString(blnDebugging, "Field Not omitted = "+blnNotOmitted);

	  // if this is NOT one of our Omitted Fields
	  if (blnNotOmitted){
	  	// if this control has no data
        	if (prqfdata.elements[i].value == ""){
        	    // note failure
        	    blnValid    = false;
        	}    
	  }
    }
    
    // if we do not have a valid form
    if (!blnValid){
	  // alert the User
        alert(strErrMsg);        
    }

    // Return the result
    return blnValid;
}

//	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function ValidateEmailAddress(pstrEmailAdd){
// This function validates an email address (as best we can). 
// It searches for an '@' and a '.' after it. 
// It returns true or false based on the results 
//
//	Company : Cadent.com
//	Author  : Chris Fusco
// 	Project : 
//
//	Parameters : pstrEmailAdd - the form data

	strEmailAdd	= pstrEmailAdd;

	// Test for a '@' and a '.' after it.
	intAtSign	= strEmailAdd.indexOf("@");
	intPeriod	= strEmailAdd.indexOf(".", intAtSign);

	// Did we find both?
	blnValid	= ((intAtSign > -1) && (intPeriod > -1));

	// FOR DEBUGGING PURPOSES
	strMsg	= "@ = " + intAtSign + "\n";
	strMsg	= strMsg + ". = " + intPeriod + "\n";
	strMsg	= strMsg + "Validity = " + blnValid + "\n";
	//PopUpTestString(blnDebugging, strMsg);

	// Return the result
	return blnValid;

}

function ValidateEmail(form){
			// ValidateEmail checks the validity of the email address 
			// submitted for the Family Profile Alert
			
			strInvalidEmail	= "Please enter a valid email address.";
			blnValidEmail 	= ValidateEmailAddress(form.email.value);
			// if the e-mail address is not valid
			if (!blnValidEmail) {
				// prompt the user
				alert(strInvalidEmail);
			}
			return blnValidEmail;
		}
function ValidateAdditionalCard(pstrCardName, pstrCardNumber, pstrCardType, pstrExpMonth, pstrExpYear){
// This function checks to see if all of the credit card information 
// (all 5 required fields) are populated
// ValidateAdditionalCard returns a True or False value
// a false value is returned if the credit card data is only partial
// Company: Cadent.com
// Project: SPE
//
// Paramenters: 5 pieces of credit card data
	blnValid = true;
	
// set the error message
	strErrMsg = "Please complete all of the Backup Credit Card Information.";
	
	if ((pstrCardName != "") || (pstrCardNumber != "") || (pstrCardType != "") || (pstrExpMonth != "") || (pstrExpYear != "")){
		if (pstrCardName == ""){
			blnValid = false;
		}
		if (pstrCardNumber == ""){
			blnValid = false;
		}
		if (pstrCardType == ""){
			blnValid = false;
		}
		if (pstrExpMonth == ""){
			blnValid = false;
		}
		if (pstrExpYear == ""){
			blnValid = false;
		}
	}
	
	// if the required fields are not filled in
	if (!blnValid) {
		// alert the user
		alert(strErrMsg);
	}
	
	return blnValid;
}


