function SetHeaderImage() {
	var n = Math.floor(Math.random() * 6) + 1;
	document.getElementById("headerImage").src = "assets/images/home_header_" + n + ".jpg";
}

function writeFooter(topOffset) {
	document.writeln('<div class="contentContainer grayContent footerContainer"' + (topOffset == 0 ? '' : 'style="position:relative; top: ' + topOffset + 'px;"') + '>');
	document.writeln('<div class="content grayContent" style="font-size:80%;">');
	document.writeln('<table cellpadding="0" cellspacing="0">');
	document.writeln('<tr>');
	document.writeln('<td valign="top" style="width:628px; padding-left:10px;">');
	document.writeln('<a href="index.htm" class="footerLink">Home</a>');
	document.writeln('| <a href="next_event.php" class="footerLink">Events</a>');
	document.writeln('| <a href="membership_application.php" class="footerLink">Membership</a>');
	document.writeln('| <a href="speakers.php" class="footerLink">Guest Speakers</a>');
	document.writeln('| <a href="student_awards.php" class="footerLink">Student Awards and Grants</a>');
	document.writeln('| <a href="officers.php" class="footerLink">Officers and Governors</a>');
	document.writeln('<br />');
	document.writeln('<br />');
	document.writeln('&copy; 2011 Money Marketeers of New York University, Inc.');
	document.writeln('</td>');
	document.writeln('<td valign="top" style="width:310px; text-align:right">');
	document.writeln('60 Constant Avenue<br />');
	document.writeln('Staten Island, NY 10314<br />');
	document.writeln('718-981-1746<br />');
	document.writeln('nyumm@hotmail.com');
	document.writeln('</td>');
	document.writeln('</div>');
	document.writeln('</div>');
}

function writeHeader(whichPage) {
	document.writeln('<div class="contentContainer purpleContent">');
	document.writeln('<div class="content purpleContent"' + (whichPage == 'home' ? '' : ' style="height:202px;"') + '>');
	document.writeln('<img src="assets/images/logo.gif" alt="Money Marketeers logo">');
	document.writeln('<a href="about_money_marketeers.htm"><img src="assets/images/topnav_1_' + (whichPage == 'about' ? 'hi' : 'lo') + '.gif" class="topnav" style="left:620px;" alt="About Money Marketeers"' + (whichPage == "about" ? '' : 'onmouseover="src=\'assets/images/topnav_1_hi.gif\';" onmouseout="src=\'assets/images/topnav_1_lo.gif\';"') + '></a>');
	document.writeln('<a href="http://www.stern.nyu.edu/" target="_blank"><img src="assets/images/topnav_2_lo.gif" class="topnav" style="left:790px;" alt="NYU Stern" onmouseover="src=\'assets/images/topnav_2_hi.gif\';" onmouseout="src=\'assets/images/topnav_2_lo.gif\';"></a>');
	document.writeln('<a href="contact.php"><img src="assets/images/topnav_3_' + (whichPage == 'contact' ? 'hi' : 'lo') + '.gif" class="topnav" style="left:876px;" alt="Contact Us"' + (whichPage == "contact" ? '' : 'onmouseover="src=\'assets/images/topnav_3_hi.gif\';" onmouseout="src=\'assets/images/topnav_3_lo.gif\';"') + '></a>');
	document.writeln('<a href="index.htm"><img src="assets/images/nav_1_' + (whichPage == 'home' ? 'hi' : 'lo') + '.gif" class="nav" style="left:0px;" alt="Home"' + (whichPage == "home" ? '' : 'onmouseover="src=\'assets/images/nav_1_hi.gif\';" onmouseout="src=\'assets/images/nav_1_lo.gif\';"') + '></a>');
	document.writeln('<a href="next_event.php"><img src="assets/images/nav_2_' + (whichPage == 'events' ? 'hi' : 'lo') + '.gif" class="nav" style="left:110px;" alt="Events"' + (whichPage == "events" ? '' : 'onmouseover="src=\'assets/images/nav_2_hi.gif\';" onmouseout="src=\'assets/images/nav_2_lo.gif\';"') + '></a>');
	document.writeln('<a href="membership_application.php"><img src="assets/images/nav_3_' + (whichPage == 'membership' ? 'hi' : 'lo') + '.gif" class="nav" style="left:224px;" alt="Membership"' + (whichPage == "membership" ? '' : 'onmouseover="src=\'assets/images/nav_3_hi.gif\';" onmouseout="src=\'assets/images/nav_3_lo.gif\';"') + '></a>');
	document.writeln('<a href="speakers.php"><img src="assets/images/nav_4_' + (whichPage == 'speakers' ? 'hi' : 'lo') + '.gif" class="nav" style="left:370px;" alt="Guest speakers"' + (whichPage == "speakers" ? '' : 'onmouseover="src=\'assets/images/nav_4_hi.gif\';" onmouseout="src=\'assets/images/nav_4_lo.gif\';"') + '></a>');
	document.writeln('<a href="student_awards.php"><img src="assets/images/nav_5_' + (whichPage == 'awards' ? 'hi' : 'lo') + '.gif" class="nav" style="left:531px;" alt="Student awards and grants"' + (whichPage == "awards" ? '' : 'onmouseover="src=\'assets/images/nav_5_hi.gif\';" onmouseout="src=\'assets/images/nav_5_lo.gif\';"') + '></a>');
	document.writeln('<a href="officers.php"><img src="assets/images/nav_6_' + (whichPage == 'officers' || whichPage == 'governors' || whichPage == 'past_presidents' ? 'hi' : 'lo') + '.gif" class="nav" style="left:729px;" alt="Officers and governors"' + (whichPage == "officers" || whichPage == "governors" ? '' : 'onmouseover="src=\'assets/images/nav_6_hi.gif\';" onmouseout="src=\'assets/images/nav_6_lo.gif\';"') + '></a>');
	if (whichPage == 'home')
		document.write('<img id="headerImage" src="assets/images/home_header_1.jpg" alt="Header image">');
	document.write('</div>');
	document.write('</div>');
}

function writeHomeLink(admin) {
	var str = '<br><div class="centeredText">[ <a href="menu.php">ADMIN HOME</a> ]</div>';
	document.write (str);
}

function writeSubheader(whichPage) {
	var n = Math.floor(Math.random() * 5) + 1;
	document.write('<div class="gradient" style="width:100%; height:115px; background-color:#acacac;">\n');
	document.write('<div style="position:relative; top:-52px; margin-left:auto; margin-right:auto; width:960px;">\n');
	document.write('<img src="assets/images/content_subheader_' + n + '.jpg" alt=""/>\n');
	document.write('</div>\n');
	document.write('<div style="position:relative; top:-45px;">\n');
	document.write('<div style="width:960px; margin-left:auto; margin-right:auto;">\n');
	writeSubheaderTabs(whichPage);
	document.write('</div>\n');
	document.write('</div>\n');
	document.write('</div>\n');
}

function writeSubheaderTabs(whichPage) {
		if (whichPage == "about_money_marketeers") {
			document.write('<div class="contentSubheader">ABOUT M.M.</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="about_marcus_nadler.htm" class="contentSubheaderLink">ABOUT M. NADLER</a></div>\n');
		}
		if (whichPage == "about_marcus_nadler") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc;"><a href="about_money_marketeers.htm" class="contentSubheaderLink">ABOUT M.M.</a></div>\n');
			document.write('<div class="contentSubheader" style="left:150px; position:relative; top:-30px;">ABOUT M. NADLER</div>\n');
		}
		if (whichPage == "officers") {
			document.write('<div class="contentSubheader">OFFICERS</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="governors.php" class="contentSubheaderLink">GOVERNORS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:300px; position:relative; top:-60px;"><a href="past_presidents.php" class="contentSubheaderLink">PAST PRESIDENTS</a></div>\n');
		}
		if (whichPage == "governors") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc; position:relative;"><a href="officers.php" class="contentSubheaderLink">OFFICERS</a></div>\n');
			document.write('<div class="contentSubheader" style="left:150px; position:relative; top:-30px;">GOVERNORS</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:300px; position:relative; top:-60px;"><a href="past_presidents.php" class="contentSubheaderLink">PAST PRESIDENTS</a></div>\n');
		}
		if (whichPage == "past_presidents") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc; position:relative;"><a href="officers.php" class="contentSubheaderLink">OFFICERS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="governors.php" class="contentSubheaderLink">GOVERNORS</a></div>\n');
			document.write('<div class="contentSubheader" style="left:300px; position:relative; top:-60px;">PAST PRESIDENTS</div>\n');
		}
		if (whichPage == "student_awards") {
			document.write('<div class="contentSubheader">STUDENT AWARDS</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="achievement_awards.php" class="contentSubheaderLink">ACHIEVEMENT AWARDS</a></div>\n');
		}
		if (whichPage == "achievement_awards") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc;"><a href="student_awards.php" class="contentSubheaderLink">STUDENT AWARDS</a></div>\n');
			document.write('<div class="contentSubheader" style="left:150px; position:relative; top:-30px;">ACHIEVEMENT AWARDS</div>\n');
		}
		if (whichPage == "membership_application") {
			document.write('<div class="contentSubheader">APPLY</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="dues_payment.php" class="contentSubheaderLink">DUES PAYMENT</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:300px; position:relative; top:-60px;"><a href="other_payments.php" class="contentSubheaderLink">OTHER PAYMENTS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:450px; position:relative; top:-90px;"><a href="honorary_members.php" class="contentSubheaderLink">HONORARY MEMBERS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:600px; position:relative; top:-120px;"><a href="fellows.php" class="contentSubheaderLink">FELLOWS</a></div>\n');
		}
		if (whichPage == "dues_payment") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc; position:relative;"><a href="membership_application.php" class="contentSubheaderLink">APPLY</a></div>\n');
			document.write('<div class="contentSubheader" style="left:150px; position:relative; top:-30px;">DUES PAYMENT</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:300px; position:relative; top:-60px;"><a href="other_payments.php" class="contentSubheaderLink">OTHER PAYMENTS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:450px; position:relative; top:-90px;"><a href="honorary_members.php" class="contentSubheaderLink">HONORARY MEMBERS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:600px; position:relative; top:-120px;"><a href="fellows.php" class="contentSubheaderLink">FELLOWS</a></div>\n');
		}
		if (whichPage == "other_payments") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc; position:relative;"><a href="membership_application.php" class="contentSubheaderLink">APPLY</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="dues_payment.php" class="contentSubheaderLink">DUES PAYMENT</a></div>\n');
			document.write('<div class="contentSubheader" style="left:300px; position:relative; top:-60px;">OTHER PAYMENTS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:450px; position:relative; top:-90px;"><a href="honorary_members.php" class="contentSubheaderLink">HONORARY MEMBERS</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:600px; position:relative; top:-120px;"><a href="fellows.php" class="contentSubheaderLink">FELLOWS</a></div>\n');
		}
		if (whichPage == "honorary_members") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc;"><a href="membership_application.php" class="contentSubheaderLink">APPLY</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="dues_payment.php" class="contentSubheaderLink">DUES PAYMENT</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:300px; position:relative; top:-60px;"><a href="other_payments.php" class="contentSubheaderLink">OTHER PAYMENTS</a></div>\n');
			document.write('<div class="contentSubheader" style="left:450px; position:relative; top:-90px;">HONORARY MEMBERS</div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:600px; position:relative; top:-120px;"><a href="fellows.php" class="contentSubheaderLink">FELLOWS</a></div>\n');
		}
		if (whichPage == "fellows") {
			document.write('<div class="contentSubheader" style="background-color:#cccccc; position:relative;"><a href="membership_application.php" class="contentSubheaderLink">APPLY</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:150px; position:relative; top:-30px;"><a href="dues_payment.php" class="contentSubheaderLink">DUES PAYMENT</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:300px; position:relative; top:-60px;"><a href="other_payments.php" class="contentSubheaderLink">OTHER PAYMENTS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#cccccc; left:450px; position:relative; top:-90px;"><a href="honorary_members.php" class="contentSubheaderLink">HONORARY MEMBERS</a></div>\n');
			document.write('<div class="contentSubheader" style="background-color:#ccccccc; left:600px; position:relative; top:-120px;">FELLOWS</div>\n');
		}
}

function monthName (m) {
	var a = new Array ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	if (m >= 1 && m <= 12)
		return a[m];
	return "";
}

function monthLen (m) {
	var a = new Array (0,31,28,31,30,31,30,31,31,30,31,30,31);
	if (m >= 1 && m <= 12)
		return a[m];
	return 0;
}

function intVal (s) {
	if (s == "")
		return 0;
	if (s.substr(0,1) == "0") {
		if (s.length == 1)
			return 0;
		return parseInt (s.substr(1,1));
	}
	return parseInt (s);
}

function writeMonthSelector (selectedMonth) {
	selectedMonth = intVal (selectedMonth);
	for (var i = 1; i <= 12; i++)
		document.write ('<option value="' + i + '"' + (i == selectedMonth ? ' selected' : '') + '>' + monthName (i) + '</option>');
}

function writeDaySelector (selectedMonth, selectedDay, selectedYear) {
	selectedMonth = intVal (selectedMonth);
	selectedDay = intVal (selectedDay);
	selectedYear = intVal (selectedYear);
	var monthLength = (selectedMonth == 2 && selectedYear % 4 == 0) ? 29 : monthLen (selectedMonth);
	for (var i = 1; i <= monthLength; i++)
		document.write ('<option value="' + i + '"' + (i == selectedDay ? ' selected' : '') + '>' + (i < 10 ? '0' : '') + i + '</option>');
}

function updateDaySelector (m, d, y) {
	var monthLengthArray = new Array (0,31,28,31,30,31,30,31,31,30,31,30,31);
	var month = document.getElementById (m).options[document.getElementById (m).selectedIndex].value;
	var year = document.getElementById (y).options[document.getElementById (y).selectedIndex].value;
	var d2 = document.getElementById (d);
	var index = d2.selectedIndex;
	for (var i = d2.options.length - 1; i >= 28; i--)
		d2.removeChild (d2.options[i]);
	var monthLength = (month == 2 && year % 4 == 0) ? 29 : monthLen (month);
	for (var i = 28; i < monthLength; i++)
		d2.options[i] = new Option (i + 1, i + 1);
	if (index >= 0 && index < d2.options.length)
		d2.selectedIndex = index;
}

function writeYearSelector (selectedYear) {
	selectedYear = intVal (selectedYear);
	for (var i = 1960; i <= 2030; i++)
		document.write ('<option value="' + i + '"' + (i == selectedYear ? ' selected' : '') + '>' + i + '</option>');
}

function writeHourSelector (selectedHour) {
	selectedHour = intVal (selectedHour);
	for (var i = 1; i <= 12; i++)
		document.write ('<option value="' + i + '"' + (i == selectedHour ? ' selected' : '') + '>' + (i < 10 ? "0" : "") + i + '</option>');
}

function writeMinuteSelector (selectedMinute) {
	selectedMinute = intVal (selectedMinute);
	for (var i = 0; i < 60; i+= 15)
		document.write ('<option value="' + i + '"' + (i == selectedMinute ? ' selected' : '') + '>' + (i < 10 ? "0" : "") + i + '</option>');
}

function formatDate (monthDropdownName, dayDropdownName, yearDropdownName) {
	var m = document.getElementById(monthDropdownName);
	var month = m.options[m.selectedIndex].value;
	month = (month < 10 ? "0" : "") + month;
	var d = document.getElementById(dayDropdownName);
	var day = d.options[d.selectedIndex].value;
	day = (day < 10 ? "0" : "") + day;
	var y = document.getElementById(yearDropdownName);
	var year = y.options[y.selectedIndex].value;
	return month + "/" + day + "/" + year;
}

function formatTime (hourDropdownName, minuteDropdownName) {
	var h = document.getElementById(hourDropdownName);
	var hour = h.options[h.selectedIndex].value;
	hour = (hour < 10 ? "0" : "") + hour;
	var m = document.getElementById(minuteDropdownName);
	var minute = m.options[m.selectedIndex].value;
	minute = (minute < 10 ? "0" : "") + minute;
	return hour + ":" + minute;
}

function trim (s) {
	return s.replace (/^\s+|\s+$/g, "");
}

function isBlank (v) {
	return (trim (v) == "");
}

function isNumeric (v) {
	var v2 = trim (v);
	if (isBlank (v2))
		return false;
	for (var i = 0; i < v2.length; i++) {
		if (v2.charAt (i) < "0" || v2.charAt (i) > "9")
			return false;
	}
	return true;
}

function isNumericOrBlank (v) {
	return (isBlank (v) || isNumeric (v));
}

function isDollarAmount (v) {
	var v2 = trim (v);
	if (isBlank (v2))
		return false;
	var pos = v2.indexOf(".");
	if (pos != -1 && pos != v2.length - 3)
		return false;
	if (v2.lastIndexOf(".") != v2.indexOf("."))
		return false;
	for (var i = 0; i < v2.length; i++){
		if ((v2.charAt (i) < "0" || v2.charAt (i) > "9") && v2.charAt (i) != ".")
			return false;
	}
	return true;
}

function isEmail (s) {
	if (s.indexOf ("@") < 1)
		return false;
	if (s.indexOf (".") < 1)
		return false;
	if (s.indexOf ("@") > s.lastIndexOf ("."))
		return false;
	return true;
}

function isPhone (areaCode, exchange, number, extension) {
	areaCode = trim (areaCode);
	exchange = trim (exchange);
	number = trim (number);
	extension = trim (extension);
	if (isBlank (areaCode) && isBlank (exchange) && isBlank (number) && isBlank (extension))
		return true;
	if (isBlank (areaCode) || isBlank (exchange) || isBlank (number))
		return false;
	if (!isNumericOrBlank (areaCode) || !isNumericOrBlank (exchange) || !isNumericOrBlank (number) || !isNumericOrBlank (extension))
		return false;
	if (areaCode.length != 3 || exchange.length != 3 || number.length != 4)
		return false;
	return true;
}

function isYear (s) {
	if (isBlank (s))
		return false;
	if (!isNumericOrBlank (s))
		return false;
	if (s < 1 || s > 9999)
		return false;
	return true;
}

function isYear2 (s) {
	if (!isYear (s))
		return false;
	if (s > 99)
		return false;
	return true;
}

