/*Created By: Phillip Alnswick-Tobias for the Outreach
Division of the United Nations Department of Public
Information on 22 August 2008*/
/*===============================================
=		Random Peace Message Display		=
===============================================*/
//create an array of messages to be displayed
var msgs = new Array();
msgs[0] = "Vote for Peace&#33;";
msgs[1] = "Make love, not war&#33;&#33;&#33;";
msgs[2] = "Can't we all just get along&#63;";
msgs[3] = "Be the change you want to see in the world &mdash; Ghandi";
msgs[4] = "Don't have a cow man&#33;";
msgs[5] = "We want Peace on Earth&#33;";
msgs[6] = "No more war&#33;&#33;&#33;";
msgs[7] = "Salaam";
msgs[8] = "On 21 September, the International Day of Peace, I call on world leaders and peoples around the world to join forces against conflict, poverty and hunger, and for all human rights for all. &mdash; UN Secretary-General Ban Ki-moon";

var msgCountry = new Array(msgs.length);
msgCountry[0] = "Japan";
msgCountry[1] = "United Kingdom of Great Britain and Northern Ireland";
msgCountry[2] = "United States of America";
msgCountry[3] = "Trinidad and Tobago";
msgCountry[4] = "United States of America";
msgCountry[5] = "Monaco";
msgCountry[6] = "Iraq";
msgCountry[7] = "United States of America";

/*=====Random Number Generator Obtained from http://gwydir.demon.co.uk/jo/javascript/code.htm#random=====*/
/*Create psuedo random number generator based on the size of the array
Precondition: The container exists and contains at least one element to be displayed.
*/
function pRNG(arrSize)
{
var randNum = arrSize * Math.random();
randNum = Math.ceil(randNum);
return randNum;
}
/*Postcondition: "Random" number is generated based on the size of (number of elements in) the container*/

//generate and store a random number (subtract 1 to make sure element to be displayed in not out of index)
var storeRand = (pRNG(msgs.length) - 1);

/*display a "random" message
Precondition: Messages are stored within a container waiting to be displayed*/
function showMsg()
{
document.write(msgs[storeRand]);
}
/*Postcondition: Random number within the size limits of the container is generated and used to determine which element in the container of messages is displayed*/

/*display the number of messages in the array
Precondition: The container exists even if it has no messages*/
function msgCount()
{
document.write(msgs.length);
}
/*Postcondition: The size of the array is returned*/

function listMsgs()
{
document.write("<ol>");
for (var i=0; i < msgs.length; ++i)
	{
	document.write("<li><p class='msg'>" + msgs[i] + "</p><p class='country'>" + msgCountry[i] + "</li>");
	}
document.write("</ol>")
}

/*display pRNG value (for debugging)
Precondition: A "random" number is generated when pRNG is called with the size of the container as its parameter */
function showRandVal()
{
document.write(storeRand);
}
/*Postcondition: the value of pRNG is displayed*/

/*Added on 26 August 2008*/
/*===============================================
=			Get User IP Address			=
===============================================*/
//obtained from http://javascript.internet.com/user-details/ip-address.html
function getIP()
{
var ip = '<!--#echo var="REMOTE_ADDR"-->';
}

/*===============================================
=			Display User IP Address			=
===============================================*/
function showIP()
{
document.write("IP = " + ip);
}

/*===============================================
=		Get User Browser Information			=
===============================================*/
//obtained from http://www.w3schools.com
function browserInfo()
{
var x = navigator;
}

/*===============================================
=		Write User Information to a File		=
===============================================*/
function fileWrite()
{
browserInfo();
getIP();
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("/connectionLogs/" + ip + ".txt", true);
s.WriteLine("IP = " + ip);
s.WriteLine("CodeName = " + x.appCodeName);
s.WriteLine("MinorVersion = " + x.appMinorVersion);
s.WriteLine("Name = " + x.appName);
s.WriteLine("Version = " + x.appVersion);
s.WriteLine("CookieEnabled = " + x.cookieEnabled);
s.WriteLine("CPUClass = " + x.cpuClass);
s.WriteLine("OnLine = " + x.onLine);
s.WriteLine("Platform = " + x.platform);
s.WriteLine("UA = " + x.userAgent);
s.WriteLine("BrowserLanguage = " + x.browserLanguage);
s.WriteLine("SystemLanguage = " + x.systemLanguage);
s.WriteLine("UserLanguage = " + x.userLanguage);
s.Close();
}