<!--

/*

FILE:		home.js

AUTHOR:		Alex Jonas

LAST UPDATED:	2/2/2006

DESCRIPTION:	JavaScript functions used in support of the ICONS Project homepage and public Web site at http://www.icons.umd.edu/.

*/

function popWin(pageTitle, bodyText, titleSlug) {

	var html = '<html>\n';
	html += '<head>\n'; 
	html += '<title>' + titleSlug + pageTitle + '</title>\n';
	html += '<link rel="stylesheet" type="text/css" href="http://www.icons.umd.edu/public.css">\n';
	html += '</head>\n';
	html += '<body bgcolor="#FFFFCC" text="#000000" link="#0000FF" alink="#CC0033" vlink="#CC0033" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">\n';
	html += '<!--  BEGIN TOP BANNER WITH PAGE TITLE.  -->\n';
	html += '<table width="100%" cellspacing="0" cellpadding="3" border="0">\n';
	html += '  <tr valign="top" bgcolor="#666666">\n';
	html += '    <td width="1"><img src="http://www.icons.umd.edu/images/pix10.gif" alt="spacer image" width="15" height="10" vspace="0" hspace="0" border="0" /></td>\n';
	html += '    <td width="100%" style="color: #E7E6E0;"><big><b>' + pageTitle + '</b></big></td>\n';
	html += '  </tr>\n';
	html += '</table>\n';
	html += '<!--  BEGIN RULE TABLE.  -->\n';
	html += '<table width="100%" cellspacing="0" cellpadding="0" border="0">\n';
	html += '  <tr valign="top">\n';
	html += '    <td class="banner" bgcolor="#E7E6E0"><img src="http://www.icons.umd.edu/images/pix10.gif" alt="spacer image" width="100%" height="3" vspace="0" hspace="0" border="0" /></td>\n';
	html += '  </tr>\n';
	html += '</table>\n';
	html += '<!--  BEGIN PAGE TEXT TABLE.  -->\n';
	html += '<br />\n';
	html += '<div style="margin-right: 5%">\n';
	html += '<table width="100%" cellspacing="0" cellpadding="3" border="0">\n';
	html += '  <tr valign="top" bgcolor="#FFFFCC">\n';
	html += '    <td width="1"><img src="http://www.icons.umd.edu/images/pix10.gif" alt="spacer image" width="15" height="10" vspace="0" hspace="0" border="0" /></td>\n';
	html += '    <td width="100%" style="color: #000066;"><small><b>' + bodyText + '</b></small></td>\n';
	html += '  </tr>\n';
	html += '</table>\n';
	html += '</div>\n';
	html += '</body>\n';
	html += '</html>';

	var win = window.open('','','width=375,height=375,resizable,scrollbars,screenX=50,screenY=50,left=50,top=50');
	win.document.open();
	win.document.write(html);
	win.document.close();

}

function simDetailsWindow(num) {

	var details = document.open('http://www.icons.umd.edu/staff/register.sim_details?v_sim_type_id=' + num,
'map','width=475,height=325,toolbar,scrollbars,screenX=25,screenY=25,left=25,top=25');

}

function showSimnums() {

	var simNums = document.open('http://www.icons.umd.edu/staff/website.show_simnums','simnums','width=475,height=325,scrollbars,status,screenX=25,screenY=25,left=25,top=25');
	document.login_form.name.focus();
	simNums.focus();

}
	
function writeDate() {

	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
	var today = new Date();
	var date = today.getDate();
	var month = today.getMonth();
	var year = today.getYear();
	if (year < 2000) {
		year = year + 1900;
	}
	dateString = months[month] + '&nbsp;' + date + ',&nbsp;' + year;
	document.write(dateString);

}

function validate() {

	var err_msg = '';
	var num_errs = 0;
	var cursor_position = 0;

	var sim_num = document.login_form.simnum.value;
	var user_name = document.login_form.name.value;
	var pass_word = document.login_form.pwd.value;

	if (sim_num.length == 0 || sim_num == ""|| sim_num == "null" || sim_num == null || stringOnlySpaces(sim_num, 1) == true) {

		num_errs++;
		err_msg += '\n' + num_errs + '. Missing simulation number.  Please enter the number for your simulation.\n';

		if (cursor_position == 0) {

			cursor_position += 1;

		}

	}

	if (stringNotNumber(sim_num)) {

		num_errs++;
		err_msg += '\n' + num_errs + '.  Simulation number must contain ONLY digits (i.e., 0 - 9).  Please enter the number for your simulation.\n';


		if (cursor_position == 0) {

			cursor_position += 1;

		}

	}

	if (user_name.length == 0 || user_name == ""|| user_name == "null" || user_name == null || stringOnlySpaces(user_name, 2) == true) {

		num_errs++;
		err_msg += '\n' + num_errs + '. Missing username.  Please enter your individual or team username.\n';

		if (cursor_position == 0) {

			cursor_position += 2;

		}

	}

	if (pass_word.length == 0 || pass_word == ""|| pass_word == "null" || pass_word == null || stringOnlySpaces(pass_word, 3) == true) {

		num_errs++;
		err_msg += '\n' + num_errs + '. Missing password.  Please enter your individual or team password, as appropriate.\n';

		if (cursor_position == 0) {

			cursor_position += 3;

		}

	}

	if (num_errs > 0) {

		if (num_errs > 1) {

			err_msg = 'The following errors were found:\n' + err_msg;

		} else {

			err_msg = 'The following error was found:\n' + err_msg;

		}

		alert(err_msg);

		if (cursor_position > 0) {

			position_cursor(cursor_position);

		}

		return false;

	}

	return true;

}

function position_cursor(num) {

		if (num == 1) {

			document.login_form.simnum.focus();

		} else if (num == 2) {

			document.login_form.name.focus();

		} else if (num == 3) {

			document.login_form.pwd.focus();

		}

}


function writeRandom() {

	var statements = new Array();

	//statements[0] = 'The ICONS Project has won numerous awards for its innovative use of technology in support of education.<br /><br /><img src="/images/pclogo.gif" alt="ICONS Project logo!" width="55" height="25" border="0">';
	statements[0] = 'The ICONS Project was recently recongnized by the American Council on Education and the AT&T Foundation for the innovative use of technology to enhance undergraduate international learning. [<a style="color: orange;" href="http://www.acenet.edu/programs/international/att/">Details...</a>]<br /><br /><a href="http://www.acenet.edu/programs/international/att/"><img src="http://www.icons.umd.edu/images/ace_award.jpg" alt="ACE/ATT award plaque" width="75" height="107" border="0"></a>';
	statements[1] = 'The ICONS Project was one of the earliest programs to make use of distributed computer networks as a forum for simulation.<br /><br /><img src="/images/pclogo.gif" alt="ICONS Project logo!" width="55" height="25" border="0">';
	statements[2] = '<a style="color: orange;" href="http://www.icons.umd.edu/negotiating/index.html"><i>Negotiating a Complex World</i></a><br />is an introductory text on international negotiations that can be used in conjunction with participation in an ICONS simulation.<br /><br /><a href="http://www.icons.umd.edu/negotiating/index.html"><img src="http://www.icons.umd.edu/images/complex_world_small.jpg" alt="Negotiating a Complex World" width="75" height="117" border="0"></a>';
	statements[3] = 'ICONS simulations can be designed to involve students from one class, one school, or from schools around the world.<br /><br /><img src="/images/pclogo.gif" alt="ICONS Project logo!" width="55" height="25" border="0">';
	statements[4] = 'ICONS can work with instructors and practitioners to develop simulations customized to address their particular educational and training needs.<br /><br /><img src="/images/pclogo.gif" alt="ICONS Project logo!" width="55" height="25" border="0">';
	//statements[5] = 'High school students can enroll in a college-level International Relations course at the University of Maryland in Summer 2003. The course uses ICONS simulations to demonstrate the core elements of international relations theories. [<a style="color: orange;" href="http://www.summer.umd.edu/youngscholars/">Details...</a>]<br /><br /><a href="http://www.summer.umd.edu/youngscholars/"><img src="http://www.icons.umd.edu/images/webglobesm.gif" alt="Details" width="61" height="61" border="0">';
	statements[5] = 'Develop your own simulations with the ICONS Project\'s Simulation Builder!<br /><br />The Simulation Builder is an organizational tool that helps you design and successfully run online or face-to-face simulations.  Its step-by-step approach will guide you through the process of simulation development. [<a style="color: orange;" href="/simbuilder/">Details...</a>]<br /><br /><a href="/simbuilder/"><img src="/images/pclogo.gif" alt="ICONS Project logo!" width="55" height="25" border="0"></a>';
	var i = parseInt((Math.random() * 6));
	document.write(statements[i]);

}

function stringOnlySpaces(theString, pos) {

        var nonSpaceCharCounter = 0;

        for (var j = 0; j < theString.length; j++) {

                if (theString.charAt(j) != ' ') {

                        nonSpaceCharCounter++;
                        break;
                }

        }

        if (nonSpaceCharCounter < 1) {

		if (pos == 1) {

			document.login_form.simnum.value = ""

		} else if (pos == 2) {

			document.login_form.name.value = ""

		} else if (pos == 3) {

			document.login_form.pwd.value = ""

		}

                return true;

        }

        return false;

}


function stringNotNumber(theString) {

        var nonNumberCounter = 0;

	for (var k = 0; k < theString.length; k++) {

                if (isNaN(parseInt(theString.charAt(k)))) {

                        nonNumberCounter++;
                        break;
                }

	}

	if (nonNumberCounter > 0) {

		document.login_form.simnum.value = ""
		return true;

	}

	return false;

}

// -->
