function validateForm(form) {
	
	// Login Information
	if (form.affusername.value == '') {
		alert("Username is required field.");
		form.affusername.focus();
		return false;
	}
	if (form.affpassword.value == '') {
		alert("Password is required field.");
		form.affpassword.focus();
		return false;
	}
	if (form.affpassword1.value == '') {
		alert("Please re-enter a password.");
		form.affpassword1.focus();
		return false;
	}
	if (form.affpassword.value != form.affpassword1.value) {
		alert("The password and its confirmation don't match. Please re-enter.");
		form.affpassword.select();
		form.affpassword.focus();
		return false;
	}
	
	// Website Information
	if (form.affcomname.value == '') {
		alert("Website name is required field.");
		form.affcomname.focus();
		return false;
	}
	if (form.affurl.value == '') {
		alert("Website URL is required field.");
		form.affurl.focus();
		return false;
	}
	
	// Contact Information
	if (form.affemail.value == '') {
		alert("Email address is required field.");
		form.affemail.focus();
		return false;
	} else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.affemail.value)) {
		} else {
			alert("Invalid e-mail address! Please re-enter.")
			form.affemail.focus();
			return false;
		}
	}
	if (form.affpersonname.value == '') {
		alert("Contact name is required field.");
		form.affpersonname.focus();
		return false;
	}
	if (form.affpayable.value == '') {
		alert("Checks Payable To is required field.");
		form.affpayable.focus();
		return false;
	}
	if (form.affadd1.value == '') {
		alert("Address is required field.");
		form.affadd1.focus();
		return false;
	}
	if (form.affcity.value == '') {
		alert("City is required field.");
		form.affcity.focus();
		return false;
	}
	if (form.affstate.value == '') {
		alert("State / Province is required field.");
		form.affstate.focus();
		return false;
	}
	if (form.affzip.value == '') {
		alert("Zip Code is required field.");
		form.affzip.focus();
		return false;
	}
	
	// Funds Distribution
	var affdist_WT_ind = 0;
	var affdist_EP_ind = 0;
	for (var i=0; i<form.affdist.length; i++) {
		if (form.affdist[i].checked && form.affdist[i].value == 'WT') {
			affdist_WT_ind = 1;
			break;
		} else if (form.affdist[i].checked && form.affdist[i].value == 'EP') {
			affdist_EP_ind = 1;
			break;
		}
	}
	if (affdist_EP_ind == 1) { // if Epassporte selected
		if (form.EPASSPORTE_ID.value == '') {
			alert("Please enter your Epassporte ID.");
			form.EPASSPORTE_ID.focus();
			return false;
		}
	}
	if (affdist_WT_ind == 1) { // if Wire Transfer selected
		if (form.affbank_name.value == '') {
			alert("Bank Name is a required field with Distribution choice of Wire Transfer.");
			form.affbank_name.focus();
			return false;
		}
		if (form.affbank_branch.value == '') {
			alert("Bank Branch is a required field with Distribution choice of Wire Transfer.");
			form.affbank_branch.focus();
			return false;
		}
		if (form.affbank_addr.value == '') {
			alert("Bank Address is a required field with Distribution choice of Wire Transfer.");
			form.affbank_addr.focus();
			return false;
		}
		if (form.affbank_tele.value == '') {
			alert("Bank Telephone is a required field with Distribution choice of Wire Transfer.");
			form.affbank_tele.focus();
			return false;
		}
		/*
		if (form.affbank_ABA.value == '') {
			alert("Bank Routing is a required field with Distribution choice of Wire Transfer.");
			form.affbank_ABA.focus();
			return false;
		}
		*/
		if (form.affbank_swift.value == '') {
			alert("Bank ABA/Swift is a required field with Distribution choice of Wire Transfer.");
			form.affbank_swift.focus();
			return false;
		}
		if (form.affbank_acct.value == '') {
			alert("Bank Acct. Number is a required field with Distribution choice of Wire Transfer.");
			form.affbank_acct.focus();
			return false;
		}
		if (form.affben_name.value == '') {
			alert("Beneficiary Name is a required field with Distribution choice of Wire Transfer.");
			form.affben_name.focus();
			return false;
		}
		if (form.affben_addr.value == '') {
			alert("Beneficiary Address is a required field with Distribution choice of Wire Transfer.");
			form.affben_addr.focus();
			return false;
		}
		if (form.affben_tele.value == '') {
			alert("Beneficiary Telephone is a required field with Distribution choice of Wire Transfer.");
			form.affben_tele.focus();
			return false;
		}
	}
	
	// Legal Information
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
	var dob_date = form.affdobmonth.value + "/" + form.affdobday.value + "/" + form.affdobyear.value ;
	
	if (isValidDate(dob_date)) { // Validates DOB date 
		date1temp = new Date(dob_date);
		date1.setTime(date1temp.getTime());
	}
	else return false; // otherwise exits
	
	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();
	
	years = Math.floor(timediff / (1000 * 60 * 60 * 24 * 365));
	if (years < 18) {
		alert("You must be 18 or older to open an account with us.\nPlease come back when you are.");
		form.affdobmonth.focus();
		return false;
	}
	
	// Publisher Service Agreement
	if (form.agreement.checked == false) {
		alert("You have to agree with the terms and conditions.");
		return false;
	}
	if (form.affsig.value == '') {
		alert("Your digital signature is a required field.");
		form.affsig.focus();
		return false;
	}
	
}

function isNumeric(obj) {
	// NaN is Not A Number
	if ( isNaN(obj.value) ) {
		alert (obj.value + " " + "must be numeric.");
		obj.focus();
		obj.select();
		return false;
	} else if (obj.value < 0) {
		alert (obj.value + " " + "must be greater than zero.");
		obj.focus();
		obj.select();
		return false;
	}
}

function validateEmail (form, obj) {
	if (obj.value != '') {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value)) {
		} else {
			alert("Invalid e-mail address! Please re-enter.")
			obj.focus();
			return false;
		}
	}
}

function isValidDate(dateStr) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert(dateStr + " Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
	   }
	}
	return true;
}

function open_window(url) {
   	sealWin = window.open(url,"GOW");
}

function updateMinAmt(form) {
	for (var i=0; i<form.affdist.length; i++) {
		if (form.affdist[i].checked && form.affdist[i].value == 'WT') {
			if (form.affminamt.value < 300) {
				form.affminamt.value = 300;
			}
			break;
		}
	}
}

function updateFundType (form) {
	var affdist_WT_ind = 0;
	var affdist_EP_ind = 0;
	for (var i=0; i<form.affdist.length; i++) {
		if (form.affdist[i].checked && form.affdist[i].value == 'WT') {
			affdist_WT_ind = 1;
			if (form.affminamt.value < 300) {
				form.affminamt.value = 300;
			}
			break;
		} else if (form.affdist[i].checked && form.affdist[i].value == 'EP') {
			affdist_EP_ind = 1;
			break;
		}
	}
	if (affdist_WT_ind == 1) { // if Wire Transfer selected
		form.EPASSPORTE_ID.disabled = true;
		form.affbank_name.disabled = false;
		form.affbank_branch.disabled = false;
		form.affbank_addr.disabled = false;
		form.affbank_ABA.disabled = false;
		form.affbank_acct.disabled = false;
		form.affben_name.disabled = false;
		form.affben_addr.disabled = false;
		form.affbank_swift.disabled = false;
		form.affben_tele.disabled = false;
		form.affbank_tele.disabled = false;
		
		form.EPASSPORTE_ID.style.backgroundColor = "ddd";
		form.affbank_name.style.backgroundColor = "fff";
		form.affbank_branch.style.backgroundColor = "fff";
		form.affbank_addr.style.backgroundColor = "fff";
		form.affbank_ABA.style.backgroundColor = "fff";
		form.affbank_acct.style.backgroundColor = "fff";
		form.affben_name.style.backgroundColor = "fff";
		form.affben_addr.style.backgroundColor = "fff";
		form.affbank_swift.style.backgroundColor = "fff";
		form.affben_tele.style.backgroundColor = "fff";
		form.affbank_tele.style.backgroundColor = "fff";
	} else if (affdist_EP_ind == 1) { // if Epassporte selected
		form.EPASSPORTE_ID.disabled = false;
		form.affbank_name.disabled = true;
		form.affbank_branch.disabled = true;
		form.affbank_addr.disabled = true;
		form.affbank_ABA.disabled = true;
		form.affbank_acct.disabled = true;
		form.affben_name.disabled = true;
		form.affben_addr.disabled = true;
		form.affbank_swift.disabled = true;
		form.affben_tele.disabled = true;
		form.affbank_tele.disabled = true;
		
		form.EPASSPORTE_ID.style.backgroundColor = "fff";
		form.affbank_name.style.backgroundColor = "ddd";
		form.affbank_branch.style.backgroundColor = "ddd";
		form.affbank_addr.style.backgroundColor = "ddd";
		form.affbank_ABA.style.backgroundColor = "ddd";
		form.affbank_acct.style.backgroundColor = "ddd";
		form.affben_name.style.backgroundColor = "ddd";
		form.affben_addr.style.backgroundColor = "ddd";
		form.affbank_swift.style.backgroundColor = "ddd";
		form.affben_tele.style.backgroundColor = "ddd";
		form.affbank_tele.style.backgroundColor = "ddd";
	} else {
		form.EPASSPORTE_ID.disabled = true;
		form.affbank_name.disabled = true;
		form.affbank_branch.disabled = true;
		form.affbank_addr.disabled = true;
		form.affbank_ABA.disabled = true;
		form.affbank_acct.disabled = true;
		form.affben_name.disabled = true;
		form.affben_addr.disabled = true;
		form.affbank_swift.disabled = true;
		form.affben_tele.disabled = true;
		form.affbank_tele.disabled = true;
		
		form.EPASSPORTE_ID.style.backgroundColor = "ddd";
		form.affbank_name.style.backgroundColor = "ddd";
		form.affbank_branch.style.backgroundColor = "ddd";
		form.affbank_addr.style.backgroundColor = "ddd";
		form.affbank_ABA.style.backgroundColor = "ddd";
		form.affbank_acct.style.backgroundColor = "ddd";
		form.affben_name.style.backgroundColor = "ddd";
		form.affben_addr.style.backgroundColor = "ddd";
		form.affbank_swift.style.backgroundColor = "ddd";
		form.affben_tele.style.backgroundColor = "ddd";
		form.affbank_tele.style.backgroundColor = "ddd";
	}
}

function WTon() {
  
}