// global functions for use sitewide


// rollover images
function swapImage(id,im) {
	document.images[id].src=im;
}



function openWindow(URL, intWidth, intHeight) {
	newWindow = window.open(URL, "loading", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+intWidth+",height="+intHeight+",left=200,top=200")
	newWindow.focus();
}




// application forms - people must agree before submitting
function agreeToTerms() {
	if (document.employmentForm.agreeTerms.checked == false) {
		alert ('You must agree to terms before submission');
		document.employmentForm.agreeTerms.focus();
		return false;
	} else {
		return true;
	}
}


// Validation for  the membership application form
function checkMembershipForm() {
	
	/* Joint Owner fields, don't need to validate
	'JO_Relationship',
	'JO_FirstName',
	'JO_LastName',
	'JO_Address1',
	'JO_Address2',
	'JO_HomePh',
	'JO_WorkPh',
	'JO_SSN',
	'JO_License',
	'JO_LicenseIssue'*/

	var formError = false;
	var flag = 0;
	var formItems = Array( 'accountsShouldBe',
							'PA_FirstName',
							'PA_LastName',
							'PA_DOB',
							'txtApplicantAddress1',
							'txtApplicantAddress2',
							'txtApplicantHomeTel',
							'txtApplicantWorkTel',
							'txtApplicantSSN',
							'txtApplicantLic',
							'txtLicStateIssued',
							'PA_motherMaiden',
							'PA_employer');
														
							for (var i=0;i<formItems.length;i++) {
									currentTest = document.getElementById(formItems[i]);
									currentTest.style.backgroundColor = '#FFFFFF';
									if (!currentTest.value) {
										this.formError = true;
										break;
									} else {
										this.formError = false;
									}
									
								}

							
							if (this.formError) {
								currentTest.style.backgroundColor = '#FFFF66';
								alert('There are a few required fields that you have not filled in.\nPlease review before submitting.');
								currentTest.focus();
								return false;
							} 
							
							if (document.membershipForm.PA_Group.value=="") {
								alert('Please select your employee group');
								document.membershipForm.PA_Group.focus();
								return false;
							}
							
							
							
							
							

							// check if any accounts were selected
							var totalChecked = 0;
							for (var i=0;i<document.membershipForm.accountTypeReq.length;i++) {
								if (document.membershipForm.accountTypeReq[i].checked) {
									totalChecked += 1;
								} 
							}
							
							if (totalChecked < 1) {
								alert('Please choose at least one account type');
								return false;
							}
							
							
							
							/* // check if any cards were requested
							var totalChecked = 0;
							for (var i=0;i<document.membershipForm.cardsRequested.length;i++) {
								if (document.membershipForm.cardsRequested[i].checked) {
									totalChecked += 1;
								} 
							}
							
							if (totalChecked < 1) {
								alert('Please choose at least one card');
								return false;
							} */
							
							
							// designate accounts if 'other' is chosen
							if ((document.membershipForm.POD_bene.value == 'Designate Specific Account(s)') && (!document.membershipForm.txtPOD_Explain.value)) {
								alert('Please designate accounts');
								document.membershipForm.txtPOD_Explain.focus();
								document.membershipForm.txtPOD_Explain.style.backgroundColor='#FFFF66';
								return false;
							} else {
								document.membershipForm.txtPOD_Explain.style.backgroundColor='#FFFFFF';
							}
							
							
							if (!document.membershipForm.applicantAgreeTerms.checked) {
								alert ('Applicant must agree to terms');
								document.membershipForm.applicantAgreeTerms.focus();
								return false;
							}
							
							
							if (!document.membershipForm.coApplicantAgreeTerms.checked) {
								alert ('Co applicant must agree to terms');
								document.membershipForm.coApplicantAgreeTerms.focus();
								return false;
							}
							
							if (!document.membershipForm.formcode.value) {
								alert ('Please enter the security code in the image');
								document.membershipForm.formcode.focus();
								return false;
							}
							
							
							return true;
	
}






// Validation for the online banking signup form
function checkOnlineBankingForm() {

	var formError = false;
	var formItems = Array( 'txtFirstName',
							'txtLastName',
							'txtEmail',
							'txtMemberNumber',
							'txtAddress',
							'txtCityStZip',
							'txtSSN',
							'formcode');
														
							for (var i=0;i<formItems.length;i++) {
									currentTest = document.getElementById(formItems[i]);
									currentTest.style.backgroundColor = '#FFFFFF';
									if (!currentTest.value) {
										this.formError = true;
										break;
									} else {
										this.formError = false;
									}
									
								}

							
							if (this.formError) {
								currentTest.style.backgroundColor = '#FFFF66';
								alert('All fields are required.');
								currentTest.focus();
								return false;
							} 
							
							
							return true;
	
}




// Validation for the credit card transfer form
function checkCCTransferForm() {

	var formError = false;
	var formItems = Array( 'txtFirstName',
							'txtLastName',
							'txtEmail',
							'txtDaytimePhone',
							'txtDPSCUCCNum',
							'txtCCIssuer1',
							'txtCCNum1',
							'txtTransferAmount1');
														
							for (var i=0;i<formItems.length;i++) {
									currentTest = document.getElementById(formItems[i]);
									currentTest.style.backgroundColor = '#FFFFFF';
									if (!currentTest.value) {
										this.formError = true;
										break;
									} else {
										this.formError = false;
									}
									
								}

							
							if (this.formError) {
								currentTest.style.backgroundColor = '#FFFF66';
								alert('Please complete all required fields');
								currentTest.focus();
								return false;
							} 
							
							
							return true;
	
}



// Validation for the 'Celebrate the members' form
function checkCelebrateMembersForm() {

	var formError = false;
	var formItems = Array( 'txtFirstName',
							'txtLastName',
							'txtPassion',
							'txtStory',
							'txtProduct',
							'uploadFile',
							'txtAddress',
							'txtAddress2',
							'txtPhone',
							'txtEmail',
							'txtAccount');
														
							for (var i=0;i<formItems.length;i++) {
									currentTest = document.getElementById(formItems[i]);
									currentTest.style.backgroundColor = '#FFFFFF';
									if (!currentTest.value) {
										this.formError = true;
										break;
									} else {
										this.formError = false;
									}
									
								}

							
							if (this.formError) {
								currentTest.style.backgroundColor = '#FFFF66';
								alert('All fields on this form are required');
								currentTest.focus();
								return false;
							} 
							
							if (!document.form.agreeTerms.checked) {
								alert ('You must agree to terms to submit form');
								document.form.agreeTerms.focus();
								return false;
							}
							
							if (!document.form.formcode.value) {
								alert ('Please enter the security code in the image');
								document.form.formcode.focus();
								return false;
							}
							
							alert('Click OK to begin upload - this may take a few minutes.\nDo not close browser until upload is complete');
							return true;
	
}

// upload alert box for celebrate photo upload form

function uploadAlert() {
	alert('Click OK to begin upload - this may take a few minutes.\nDo not close browser until upload is complete');
							return true;
	
}





function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}



// confirm the deletion of something
function confirmDelete(user) {
		var agree=confirm("Confirmation 1 of 3\nAre you sure you want to delete " +user+ "?");
		if (agree) {
			var agreeAgain=confirm("Confirmation 2 of 3\nAre you TOTALLY sure you want to delete " +user+ "?");
			if (agreeAgain) {
				var agreeFinal=confirm("Confirmation 3 of 3\nAre you COMPLETELY sure you want to delete " +user+ "?");
				if (agreeFinal) {
					return true;
				} else {
					return false ;
				}
			} else {
				return false ;
			}
		} else {
			return false ;
		}
	}
