function checkLeadForm() {
	var returnval = true;
	var f = document.main;

	if (!f.firstname.value.length) {
		alert("Please enter leader's first name");
		f.firstname.focus();
		returnval = false;
	} else if (!f.lastname.value.length) {
		alert("Please enter leader's last name");
		f.lastname.focus();
		returnval = false;
	} else if (!f.company.value.length) {
		alert("Please enter leader's Non-Profit Organization/ Company name");
		f.company.focus();
		returnval = false;
	} else if (!f.position.value.length) {
		alert("Please enter leader's position/title");
		f.position.focus();
		returnval = false;
	} else if (!f.submitter.value.length) {
		alert("Please enter your full name");
		f.submitter.focus();
		returnval = false;
	} else if (!f.affiliation.value.length) {
		alert("Please state your affiliation to the nominee");
		f.affiliation.focus();
		returnval = false;
	} else if (!f.submitter_email.value.length) {
		alert("Please enter your e-mail address");
		f.submitter_email.focus();
		returnval = false;
	} else if (!f.submitter_phone.value.length) {
		alert("Please enter your phone number");
		f.submitter_phone.focus();
		returnval = false;
	} else if (!f.leadsphrase.value.length) {
		alert("Please enter the 'Leads...' phrase");
		f.leadsphrase.focus();
		returnval = false;
	} else if (!f.body.value.length) {
		alert("Please Describe the nominee's unique leadership style or contribution");
		f.body.focus();
		returnval = false;
	}

	return returnval;
}



var clicked = false;
var products = 0;
function buynow() {

	if (clicked == true) {
		alert("You can only click once!")
	} else {


		var returnval = true;
		var f = document.main;
		var d = new Date();
		var year = d.getFullYear()-2000;	// should be valid for another 100 years ;)
		var month = d.getMonth()+1;

		if (returnval == true) {
			if (f.firstname.value.length<2) {
				alert("Please enter your first name!");
				f.firstname.focus();
				returnval = false;
			} else if (f.lastname.value.length<2) {
				alert("Please enter your last name!");
				f.lastname.focus();
				returnval = false;
			} else if (f.email.value.indexOf('@') == -1) {
				alert("Please enter your e-mail address!");
				f.email.focus();
				returnval = false;
			} else if (f.email.value != f.email2.value) {
				alert("The e-mail addresses do not match!");
				f.email2.focus();
				returnval = false;
			} else if (f.phone.value.length<10) {
				alert("Please enter your telephone number, at least 10 digits!");
				f.phone.focus();
				returnval = false;
			} else if (f.billingaddress.value.length<2) {
				alert("Please enter your billing address!");
				f.billingaddress.focus();
				returnval = false;
			} else if (f.city.value.length<2) {
				alert("Please enter your city!");
				f.city.focus();
				returnval = false;
			} else if (f.state.selectedIndex==0) {
				alert("Please select your state!");
				f.state.focus();
				returnval = false;
			} else if (f.country.selectedIndex==0) {
				alert("Please select your country!");
				f.country.focus();
				returnval = false;
			} else if (f.zip.value.length<5) {
				alert("Please enter a zip code that is at least 5 digits");
				f.zip.focus();
				returnval = false;
			} else if (f.thecreditcardtype.selectedIndex == 0) {
				alert("Please select credit card type!");
				f.thecreditcardtype.focus();
				returnval = false;
				/*
			} else if (f.thecreditcardtype.selectedIndex==1 && f.creditcard.value.length!=15) {
				alert("Please enter your credit card number (15 digits without spaces)!");
				f.creditcard.focus();
				returnval = false;
			} else if (((f.thecreditcardtype.selectedIndex!=1) && (f.thecreditcardtype.selectedIndex != 0)) && f.creditcard.value.length!=16) {
				alert("Please enter your credit card number (16 digits without spaces)!");
				f.creditcard.focus();
				returnval = false;
				*/
			} else if (f.creditcard.value.length!=16) {
				alert("Please enter your credit card number (16 digits without spaces)!");
				f.creditcard.focus();
				returnval = false;
			} else if (f.cvv.value.length != 3) {
				alert("For your protection, the 3-digit CCV (Credit Card Verification) number on your credit card is required for processing.\nAll credit card cards now being released have a three digit Credit Card Verification number issued on them.\nThe 3-digit CCV is usually printed on the signature panel on the back of the card immediately after the card number or partial card number.\nFor simplicity, the CCV is always the last 3 digits shown on the signature panel.");
				f.cvv.focus();
				returnval = false;
			} else if (f.expirationmonth.selectedIndex==0) {
				alert("Please select a credit card expiration month!");
				f.expirationmonth.focus();
				returnval = false;
			} else if (f.expirationyear.selectedIndex==0) {
				alert("Please select a credit card expiration year!");
				f.expirationyear.focus();
				returnval = false;
			}
		}

		if (returnval) {
			// buy now!
			if (confirm("Your order will be processed at this time.")) {
				clicked = true;
				//alert("submitting!")
				f.submit();
			}
		}

	}
}








// universal form check function... to be written one day...
///////////////////////////////////////////////////////
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}



var iPath = "images/";
var iExt = "gif";
var suffix = new Array("s","u");

function preLoad()
{
 if(document.images)
 {
 var argLen = arguments.length;
 for(var i = 0; i < argLen; i++)
 {
 var arg = arguments[i];
 var sufLen = suffix.length;
	 for(j = 0; j > sufLen; j++)
 {
 var suf = suffix[j]
 self[arg + suf] = new Image();
 self[arg + suf].src = iPath + arg + suf + '.' + iExt;
 }
 }
 loaded = true;
 }
}

window.onLoad = preLoad("m1","m2","m3","m4","m5","m6","m7");

///////////////////////////////////////////////////////

function removepicture() {
	document.main.removepicture.value = 1;
	document.main.submit();
}

function printthisconsultant(id, idh, session) {
	openAWindow('index.php?l=42&id='+id+'&idh='+idh+'&'+session, 'printconsultant', 600, 600, 1);
}

var clicked = false;
var events = 0;
function register_for_event() {

	if (clicked == true) {
		alert("Your order is already being processed.")
	} else {

		var returnval = true;
		var f = document.main;
		var d = new Date();
		var year = d.getFullYear()-2000;	// should be valid for another 100 years ;)
		var month = d.getMonth()+1;

		// check if events are selected
		var f = document.main;
		for (var n=0; n<f.elements.length; n++) {
			var o = f.elements[n];
			if (o.name.indexOf('event_') > -1) {
				var id = parseInt(o.name.substring(6,1000),10);
				if (o.checked) {
					var amount = f['tickets_'+id].value;
					if (amount>0) {
						events = 1;
						break;
					}
				}
			}
		}

		events = 1;

		// some of the events must be checked
		if (!events) {
			alert("You have to select at least one ticket for one Event!");
			returnval = false;
		}
		if (returnval == true) {
			if (f.firstname.value.length<2) {
				alert("Please enter your first name!");
				f.firstname.focus();
				returnval = false;
			} else if (f.lastname.value.length<2) {
				alert("Please enter your last name!");
				f.lastname.focus();
				returnval = false;
			} else if (f.email.value.indexOf('@') == -1) {
				alert("Please enter your e-mail address!");
				f.email.focus();
				returnval = false;
			} else if (f.email.value != f.email2.value) {
				alert("The e-mail addresses do not match!");
				f.email2.focus();
				returnval = false;
			} else if (f.telephone.value.length<10) {
				alert("Please enter your telephone number, at least 10 digits!");
				f.telephone.focus();
				returnval = false;
			} else if (f.street.value.length<2) {
				alert("Please enter your street address!");
				f.street.focus();
				returnval = false;
			} else if (f.city.value.length<2) {
				alert("Please enter your city!");
				f.city.focus();
				returnval = false;
			} else if (f.state.selectedIndex==0) {
				alert("Please select your state!");
				f.state.focus();
				returnval = false;
			} else if (f.zip.value.length<5) {
				alert("Please enter a zip code that is at least 5 digits");
				f.zip.focus();
				returnval = false;
			} else if (f.requirecreditcard.value==1) {
				// only if have to pay for tickets...
	
				if (f.total.value<=0) {
					alert("Please select some tickets!");
					f.total.focus();
					returnval = false;
				} else if (f.cardtype.selectedIndex == 0) {
					alert("Please select credit card type!");
					f.cardtype.focus();
					returnval = false;
				} else if ((f.cardtype.selectedIndex != 0) && (f.cardnumber.value.length!=16)) {
					alert("Please enter your credit card number (16 digits without spaces)!");
					f.cardnumber.focus();
					returnval = false;
				} else if (f.expirationmonth.selectedIndex==0) {
					alert("Please select a credit card expiration month!");
					f.expirationmonth.focus();
					returnval = false;
				} else if (f.expirationyear.selectedIndex==0) {
					alert("Please select a credit card expiration year!");
					f.expirationyear.focus();
					returnval = false;
				} else if (f.cardccv.value.length != 3) {
					alert("For your protection, the 3-digit CCV (Credit Card Verification) number on your credit card is required for processing.\nAll credit card cards now being released have a three digit Credit Card Verification number issued on them.\nThe 3-digit CCV is usually printed on the signature panel on the back of the card immediately after the card number or partial card number.\nFor simplicity, the CCV is always the last 3 digits shown on the signature panel.");
					f.cardccv.focus();
					returnval = false;
				} else if (f.billingstreet.value.length<2) {
					alert("Please enter your billing address street registered for the credit card!");
					f.billingstreet.focus();
					returnval = false;
				} else if (f.billingcity.value.length<2) {
					alert("Please enter your billing address city registered for the credit card!");
					f.billingcity.focus();
					returnval = false;
				} else if (f.billingstate.selectedIndex==0) {
					alert("Please select your billing address state registered for the credit card!");
					f.billingstate.focus();
					returnval = false;
				} else if (f.billingzip.value.length<5) {
					alert("Please enter your billing address zip code that is at least 5 digits registered for the credit card");
					f.billingzip.focus();
					returnval = false;
				}

			}
		}

		if (returnval) {
			// buy now!
			if (confirm("Your request will be processed at this time.")) {
				clicked = true;
				f.submit();
			}
		}

	}
}

// calculate total
function ct(me) {
	if (ct != -1) {
		me.value = parseInt(me.value*1, 10);
	}
	document.main.total.value = '';
	var sum = 0;

	var f = document.main;
	for (var n=0; n<f.elements.length; n++) {
		var o = f.elements[n];
		if (o.name.indexOf('tickets_') > -1) {
			var id = parseInt(o.name.substring(8,1000),10);
			var amount = f['tickets_'+id].value;
			var price = prices[id];
			var sub = amount*price;
			f['sub_'+id].value = sub;
			sum += sub;
		}
	}

	var no = false;
	if (!sum) {
		sum = '';
		var no = true;
	}

	if (parseInt(sum,10) == sum) {
		sum = String(sum)+'.00';
	}

	if (!no) {
		document.main.total.value = "$"+addCommas(sum);
	} else {
		document.main.total.value = '';
	}
	
}

function addCommas( sValue ) {

	sValue = String(sValue);
	var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
	while(sRegExp.test(sValue)) { 
		sValue = String(sValue).replace(sRegExp, '$1|$2');
	}
	sValue = sValue.split('.');
	sValue = sValue.join('.');
	sValue = sValue.split('|');
	sValue = sValue.join(',');
	return sValue; 
}

function selProduct(me, obj, t) {
	if (me.checked) {
		if (obj.value.length==0) {
			if (t){
				obj.value=1;
			} else {
				obj.value=1;
			}
		}
		obj.focus();
		obj.select();
		ct(obj);
//		products++;
	} else {
		obj.value='';
		ct(-1);
//		products--;
	}
}



function calendar_checkout() {
	if (confirm("Now making the Event available for the public!")) {
		document.main.regactive.value = 1;
		document.main.submit();
	}
}

function ads_checkout() {
	var f = document.main;
	var adname = f.headline.value;
	if (confirm("Now publishing the AD \""+adname+"\"\nAfter publishing, the AD will be visible for everyone.")) {
		document.main.purchase.value = 1;
		document.main.submit();
	}
	/*
	var adname = f.headline.value;
	var adweeks = f.weeks.value*1;
	var plan = js_plans[f.plan.options[f.plan.selectedIndex].value];
	var adprice = adweeks * plan;
	if (adweeks>0) {
		if (plan) {
			if (confirm("Now purchasing the AD \""+adname+"\" for $"+adprice+"\nAfter purchasing, the AD cannot be edited any more.")) {
				document.main.purchase.value = 1;
				document.main.submit();
			}
		} else {
			alert("You have to select AD plan!");
			f.plan.focus();
		}
	} else {
		alert("You have to enter amount of weeks!");
		f.weeks.focus();
	}
	*/
}

function form_check() {
}

function deleteselectedads() {
	if (confirm("Delete all selected ads?")) {
		document.main.do_action.value = "delete";
		document.main.submit();
	} else {
		// do nothing
	}
}

function deleteselectedevents() {
	if (confirm("Delete all selected events?")) {
		document.main.do_action.value = "delete";
		document.main.submit();
	} else {
		// do nothing
	}
}

function deleteselectedfavorites() {
	if (confirm("Delete all selected Favorites?")) {
		document.main.do_action.value = "delete";
		document.main.submit();
	} else {
		// do nothing
	}
}

function checkMail() {
	var returnval = true;
	var f = document.main;

	if (!f.fromname.value.length) {
		alert("Please enter your name");
		f.fromname.focus();
		returnval = false;
	} else if (!f.frommail.value.length) {
		alert("Please enter your e-mail");
		f.frommail.focus();
		returnval = false;
	} else if (!f.subject.value.length) {
		alert("Please write a subject");
		f.subject.focus();
		returnval = false;
	} else if (!f.body.value.length) {
		alert("Please enter message");
		f.body.focus();
		returnval = false;
	}
	return returnval;
}

function checkResourseSubmit() {
	var returnval = true;
	var f = document.mainSubmit;

	if (!f.username.value.length) {
		alert("Please enter your username");
		f.username.focus();
		returnval = false;
	} else if (!f.password.value.length) {
		alert("Please enter your password");
		f.password.focus();
		returnval = false;
	} else if (!f.category.selectedIndex) {
		alert("Please select a category");
		f.category.focus();
		returnval = false;
	} else if (!f.headline.value.length) {
		alert("Please enter a headline");
		f.headline.focus();
		returnval = false;
	} else if (!f.body.value.length) {
		alert("Please describe your posting");
		f.body.focus();
		returnval = false;
	}
	return returnval;
}

function connected_check() {
	var returnval = true;
	var f = document.connectedmain;

	if (f.email.value.indexOf('@') == -1) {
		alert("Please enter your e-mail address.");
		f.email.value = '';
		f.email.focus();
		returnval = false;
	} else if (!f.newsbrief_con.checked) {
		// && !f.newsbrief_non.checked && !f.discussion_con.checked && !f.discussion_conandnon.checked
		alert("Please select at least one community.");
		f.newsbrief_con.focus();
		returnval = false;
	}

	return returnval;
}

function join_check_0() {
	var returnval = true;
	var f = document.main;

	if (!f.entrytype[0].checked && !f.entrytype[1].checked) {
		alert("Please select your profile type.");
		f.entrytype[0].focus();
		returnval = false;
	}

	return returnval;
}

function join_check_0a() {
	var returnval = false;
	var f = document.main;
	for (var t =0; t<f.level.length; t++) {
		if (f.level[t].checked == true) {
			returnval = true;
		}
	}
	if (!returnval) {
		alert("Please select your Membership Level.");
		f.level[0].focus();
	}
	return returnval;
}

function join_check_1() {
	var returnval = true;
	var f = document.main;

	if (f.username.value.length<6) {
		alert("Your username must be at least 6 characters long.");
		f.username.focus();
		returnval = false;
	} else if (f.password.value.length<6) {
		alert("Your password must be at least 6 characters long.");
		f.password.focus();
		returnval = false;
	} else if (f.password.value != f.password2.value) {
		alert("The passwords do not match.");
		f.password2.focus();
		returnval = false;
	} else if (f.email.value.indexOf('@') == -1) {
		alert("Please enter your e-mail address.");
		f.email.focus();
		returnval = false;
	} else if (f.email.value != f.email2.value) {
		alert("The e-mails do not match.");
		f.email2.focus();
		returnval = false;
/*
	} else if (f.firstname.value.length<2) {
		alert("Please enter your first name.");
		f.firstname.focus();
		returnval = false;
	} else if (f.lastname.value.length<2) {
		alert("Please enter your last name.");
		f.lastname.focus();
		returnval = false;
	} else if (f.businessname.value.length<2) {
		alert("Please enter your business name.");
		f.businessname.focus();
		returnval = false;
	} else if (f.street.value.length<2) {
		alert("Please enter your street address.");
		f.street.focus();
		returnval = false;
	} else if (f.city.value.length<2) {
		alert("Please enter your city.");
		f.city.focus();
		returnval = false;
	} else if (f.state.selectedIndex==0) {
		alert("Please select your state.");
		f.state.focus();
		returnval = false;
	} else if (f.zip.value.length<5) {
		alert("Please enter your zip code.");
		f.zip.focus();
		returnval = false;
	} else if (f.phone1.value.length+f.phone2.value.length <10) {
		alert("Please enter your phone number.");
		f.phone1.focus();
		returnval = false;
	} else if (f["services[]"].options.selectedIndex == -1) {
		alert("Please select your services. Use CTRL-Key to select multiple services.");
		f["services[]"].focus();
		returnval = false;
	} else if (f["expertise[]"].options.selectedIndex == -1) {
		alert("Please select your areas of expertise. Use CTRL-Key to select multiple services.");
		f["expertise[]"].focus();
		returnval = false;
	} else if (f["nonprofits[]"].options.selectedIndex == -1) {
		alert("Please select the Types of Non-Profits You Serve. Use CTRL-Key to select multiple services.");
		f["nonprofits[]"].focus();
		returnval = false;
		*/
	}
	return returnval;
}

function join_check_1_nonprofit() {
	var returnval = true;
	var f = document.main;

	if (f.username.value.length<6) {
		alert("Your username must be at least 6 characters long.");
		f.username.focus();
		returnval = false;
	} else if (f.password.value.length<6) {
		alert("Your password must be at least 6 characters long.");
		f.password.focus();
		returnval = false;
	} else if (f.password.value != f.password2.value) {
		alert("The passwords do not match.");
		f.password2.focus();
		returnval = false;
	} else if (f.email.value.indexOf('@') == -1) {
		alert("Please enter your e-mail address.");
		f.email.focus();
		returnval = false;
	} else if (f.email.value != f.email2.value) {
		alert("The e-mails do not match.");
		f.email2.focus();
		returnval = false;
	} else if (f.firstname.value.length<2) {
		alert("Please enter your first name.");
		f.firstname.focus();
		returnval = false;
	} else if (f.lastname.value.length<2) {
		alert("Please enter your last name.");
		f.lastname.focus();
		returnval = false;
	} else if (f.businessname.value.length<2) {
		alert("Please enter your business name.");
		f.businessname.focus();
		returnval = false;
	} else if (f.street.value.length<2) {
		alert("Please enter your street address.");
		f.street.focus();
		returnval = false;
	} else if (f.city.value.length<2) {
		alert("Please enter your city.");
		f.city.focus();
		returnval = false;
	} else if (f.state.selectedIndex==0) {
		alert("Please select your state.");
		f.state.focus();
		returnval = false;
	} else if (f.zip.value.length<5) {
		alert("Please enter your zip code.");
		f.zip.focus();
		returnval = false;
	} else if (f.phone1.value.length+f.phone2.value.length <10) {
		alert("Please enter your phone number.");
		f.phone1.focus();
		returnval = false;
	}
	return returnval;
}



function join_check_3() {
	var returnval = true;
	var f = document.main;

	/*
		} else if (f.email.value.length<3) {
			alert("Please enter client e-mail address");
			f.email.focus();
			returnval = false;
	*/

	if (f.savetype.value == 'upload') {
		if (f.fullname.value.length<2) {
			alert("Please enter client's full name");
			f.fullname.focus();
			returnval = false;
		} else if (f.company.value.length<2) {
			alert("Please enter company's name");
			f.company.focus();
			returnval = false;
		} else if (f.services.value.length<3) {
			alert("Please describe the services you provided for that client");
			f.services.focus();
			returnval = false;
		}
	} else if (f.savetype.value == 'save') {
		// CHECK IF 2 REFERENCES ADDED...

		/*
		if (added_ref >=2) {
			// just continue...
		} else {
			if (added_ref == 1) {
				if (confirm("You submitted only 1 reference. You must submit at least 2. If you click continue your first reference will be saved, but you will need to provide a second reference before you are approved for membership.")) {
				} else {
					returnval = false;
				}
			} else if (added_ref == 0) {
				if (confirm("You submitted no references. You must submit at least 2. If you click continue your application will be saved, but you will need to provide two references before you are approved for membership.")) {
				} else {
					returnval = false;
				}
			}
		}
		*/
		//alert(added_ref);
		

	}


	return returnval;
	//return false;
}


function join_check_2() {
	var returnval = true;
	var f = document.main;

	if (f.savetype.value == 'upload') {
		if (f.caption.value.length<3) {
			alert("Please enter file caption");
			f.caption.focus();
			returnval = false;
		} else if (f.description.value.length<3) {
			alert("Please enter file description");
			f.description.focus();
			returnval = false;
		}
	}
	return returnval;
}

function openAWindow( pageToLoad, winName, width, height, center){
	var xposition=0; var yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) &&(center)){
		xposition = (screen.width - width) / 8;
		yposition = (screen.height - height) / 3;
	}

	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=0,"
	+ "scrollbars=1,"
	+ "status=0,"
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + "," //NN Only
	+ "screeny=" + yposition + "," //NN Only
	+ "left=" + xposition + "," //IE Only
	+ "top=" + yposition; //IE Only

	window.open( pageToLoad, winName, args );
}

