<!--

// declare variables
var ourpoor;
var ourrich;
var strInput;
var strPlace2;

// Detect browser
ns4 = (document.layers)? true:false
ns6 = (document.getElementById)? true:false
ie4 = (document.all)? true:false

// the os
var agt = navigator.userAgent.toLowerCase();
var iswin = (agt.indexOf("win")!=-1);

//alert(Math.round(Math.random() * 3));

arrDidYouKnow = new Array();
arrDidYouKnow[0] = "The world's 225 richest people now have a combined wealth of $1 trillion. That's equal to the combined annual income of the world's 2.5 billionpoorests people";
arrDidYouKnow[1] = "Three billion people live on less than $2 per day while 1.3 billion get by on less than $1 per day. Seventy percent of those living on less than $1 per day are women.";
arrDidYouKnow[2] = "Three decades ago, the people in well-to-do countries were 30 times better off than those in countries where the poorest 20 percent of the world's people live. By 1998, this gap had widened to 82 times.";
arrDidYouKnow[3] = "Microsoft CEO Bill Gates has more wealth than the bottom 45 percent of American households combined.";


// open popup window
function open_window(qs) {

	// the width and height
	width = 400;
	height = 300;
	
	//get the top left corner for the popup
	sx = screen.width/2 - width/2;
	sy = screen.height/2 - height/2;
	
	// open the popup window
	window.open('download.html?'+escape(qs),'','width='+width+',height='+height+',resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,screenX='+sx+',screenY='+sy+',top='+sy+',left='+sx);
}


// if submitted
function fnSubmit() {
	
	// hide the news
	fnIncludeHide();

	// error check
	if ((document.priceForm.strIn.value == "") && (document.priceForm.strInP.value == "")) {
		alert("Please type in your income in either US Dollars or UK Pounds");
		return false;
	}
	
	// error check
	if ((document.priceForm.strIn.value != "") && (document.priceForm.strInP.value != "")) {
		alert("Please type in your income in either US Dollars or UK Pounds");
		return false;
	}
	
	ourpoor = false;
	ourrich = false;
	
	// array
	arrPlace = new Array();
	strPlace2 = "";
	
	arrPlaceRicher = new Array();
	strPlaceRicher2 = "";
	
	// the input
	strInput = document.priceForm.strIn.value;
	
	// convert to pounds
	if (!strInput) {
		strInput = document.priceForm.strInP.value;
		
		strHourly=(Math.floor((strInput / 1440)* 100)/ 100);
		
		strInput = strInput * 1.6;
		strCurrency = "£";
	} else {
		strCurrency = "$";
		
		strHourly=(Math.floor((strInput / 1440)* 100)/ 100);
	}
	
	// validate input
	if (isNaN(strInput)) {
		
		// not valid			
		alert("Please type in a number.");
		
	} else {
		
		// calculate place and percent
		if (strInput <=90) {
			// no output if less than 90 dollars / day
			ourpoor = true;
			strPercentagePoorer = 1;
		} else if (strInput >90 && strInput <=500) {
			// calculate
			strPlace = ((strInput*1)/0.000415) * 1000;
		} else if (strInput >500 && strInput <=850) {
			// calculate
			strPlace = (((strInput*1) - 253.95)/0.0002) * 1000;
		} else if (strInput >850 && strInput <=1486) {
			// calculate
			strPlace = (((strInput*1) + 334.64)/0.000401) * 1000;
		} else if (strInput >1486 && strInput <=2182) {
			// calculate
			strPlace = (((strInput*1) + 3520.5)/0.0011) * 1000;
		} else if (strInput >2182 && strInput <=25400) {
			// calculate
			strPlace = (((strInput*1)+195416)/0.0389) * 1000;
		} else if (strInput >25400 && strInput <=33700) {
			// calculate
			strPlace = (((strInput*1)+178696)/0.0359) * 1000; //179696 //182456
		} else if (strInput >33700 && strInput <=200000) {
			// calculate
			strPlace = 59809265 - ((strInput - 33700) * 359)
			strPlace = Math.round(strPlace);

			// calculate percentage
			strPercentagePoorer = (strPlace / 6000000000) * 100;
			strPercentagePoorer = Math.floor(strPercentagePoorer * 1000) / 1000;

			// people richer
			strPlaceRicher = strPlace;//.substring(0,10);
				
			// people poorer
			strPlace = 6000000000 - strPlace;
			
		} else if (strInput >200000 ) {
			// no output if more than 200 000 dollars / day
			ourrich = true;
			strPercentagePoorer = 99;
		}
		
		// calculate if in accepteble range
		if (ourpoor == false && ourrich == false) {
		
			// convert to string
			strPlace = strPlace.toString();
	
			// get the right digits
			strPlace = strPlace.substring(0,10);
			
			// make number again
			strPlace = (strPlace * 1);
			
			// make world number
			if (strInput <=33700) {
				strPlace_1 = strPlace;
				strPlace = 6000000000 - strPlace;
			
				// calculate percentage	
				strPercentagePoorer = (strPlace / 6000000000) * 100;
				strPercentagePoorer = Math.floor(strPercentagePoorer * 100) / 100;
				
				// people richer
				strPlaceRicher = strPlace;
				
				// people poorer
				strPlace = strPlace_1;
				
			}
			
			// convert to string again
			strPlace = strPlace.toString();
			strPlaceRicher = strPlaceRicher.toString();
			
			// for the popupwindow
			tempPlace = strPlaceRicher;
			
			// reverse it
			strPlace = reverse(strPlace);
			strPlaceRicher = reverse(strPlaceRicher);
			
			// make array
			for (i=0; i<strPlace.length; i++) {
				arrPlace[i] = strPlace.charAt(i);
		    }
			
			// make array richer
			for (i=0; i<strPlaceRicher.length; i++) {
				arrPlaceRicher[i] = strPlaceRicher.charAt(i);
		    }
			
			// add spaces
			for (i=0; i<strPlace.length; i++) {
				
				if ((i == 2) || (i == 5 && (strPlace.length != 6)) || (i == 8 && (strPlace.length != 9))) {
					
					strPlace2 = strPlace2 + arrPlace[i] + ","
				} else {
					strPlace2 = strPlace2 + arrPlace[i];
				}
			}
	
			// add spaces richer
			for (i=0; i<strPlaceRicher.length; i++) {
				
				if ((i == 2) || (i == 5 && (strPlaceRicher.length != 6)) ||(i == 8 && (strPlaceRicher.length != 9))) {
					
					strPlaceRicher2 = strPlaceRicher2 + arrPlaceRicher[i] + ","
				} else {
					strPlaceRicher2 = strPlaceRicher2 + arrPlaceRicher[i];
				}
			}
			
			// reverse it back
			strPlace2 = reverse(strPlace2);
			strPlaceRicher2 = reverse(strPlaceRicher2);
		}
		
		if (ourpoor == true ) {
			
			// if you are poor
			text = "<TABLE WIDTH=599 BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD width='599' background='http://www.goodfoundation.com/_images/dot.gif'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD></TR><TD><TABLE WIDTH=597 BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD width='75'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='15' border='0'><br></TD><TD align='left'><font class=blackheader><br>YOUR GLOBAL RICH LIST POSITION</font><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='110' border='0'><br>";
			text += "<br><table border=0 CELLSPACING=8 width=400><tr><td class='body' align=left>Sorry, if you earn less than $90 a year we are unable to calculate your position on the richlist.<br><br>If this is the case you would be one of the billions of people who earn less than $2 a day. Typically you would also not have access to a computer or an Internet connection.<br><br>If you are earning less than $90 a year itıd be unfair to ask you to donate money to Care International, if however, you actually earn more than this it may be worth re-calculating your position<br><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='6' border='0'><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='1' height='1' border='0'><br></td></tr></table><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='430' border='0'><br>";	
			text += "</TD></TR></TABLE></TD></TABLE>";
		
			strPlaceRicher2 = "5,780,722,892"; 
	
			tempPlace = "5780722892";
			strPlace2 = "5,780,722,892";
			currpos = 5;
			
		} else if (ourrich == true ) {
		
			// if you are rich
			text = "<TABLE WIDTH=599 BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD width='599' background='http://www.goodfoundation.com/_images/dot.gif'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD></TR><TD><TABLE WIDTH=597 BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD width='75'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='15' border='0'><br></TD><TD align='left'><font class=blackheader><br>YOUR GLOBAL RICH LIST POSITION</font><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='110' border='0'><br>";
			text += "<br><table border=0 CELLSPACING=8 width=400><tr><td class='body' align=left>You are in the top <font class='blackmedium'>0,001% </font>richest people in the world.</td></tr><tr><td class='body' align=left>You donıt need to know any more than that (and besides our calculator can't do sums that big).</td></tr><tr><td align=left colspan=3 class='body'>Please consider donating just a small amount of your enormous wealth to help some of the poorest people in the world. Many of their lives could be improved dramatically or even saved if you donate just one hour's salary (approx <font class='blackmedium'>" + strCurrency + strHourly + "</font>)<br><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='2' border='0'><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='1' height='9' border='0'><a href='http://www.justgiving.com/globalrichlist' target='_blank' onFocus='blur();'><img src='http://www.goodfoundation.com/_images/care.gif' width='239' height='150' border='0'></a><br></td></tr></table><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='450' border='0'><br>";
			text += "</TD></TR></TABLE></TD></TABLE>";
			
			strPlaceRicher2 = "107,565"; 
			
			tempPlace = "107565";
			strPlace2 = "107,565";
			currpos = 349;
			
		} else if (ourpoor == false && ourrich == false) {
			
			// if you are within the acceptable range
			text = "<TABLE WIDTH=599 BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD width='599' background='http://www.goodfoundation.com/_images/dot.gif'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD></TR><TD><TABLE WIDTH=597 BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD width='75'><img src='http://www.goodfoundation.com/_images/blank.gif' width='75' height='15' border='0'><br></TD><TD align='left' colspan='4'><font class=blackheader><br>YOUR GLOBAL RICH LIST POSITION</font><br></td></tr><tr><td>&nbsp;</td><td><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='130' border='0'><br>";
			text += "<table border=0 CELLSPACING=8><tr><td class='body' align=left>You are in the top <font class='blackmedium'>" + strPercentagePoorer + "% </font>richest people in the world.</td></tr><tr><td class='body' align=left>There are <font class='blackmedium'>" + strPlace2 + " </font>people poorer than you.</td></tr><tr><td align=left colspan=3 class='body'>How do you feel about that? A bit richer we hope. Please consider donating just a small amount to help some of the poorest people in the world. Many of their lives could be improved dramatically or even saved if you donate just one hour's salary (approx <font class='blackmedium'>" + strCurrency + strHourly + "</font>)<br><br>Oh, and in case youre interested you are the <font class='blackmedium'>" + strPlaceRicher2 + " </font></b> richest person in the world.</td></tr></table><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='350' border='0'>";
			text += "</TD><TD width='10'><img src='http://www.goodfoundation.com/_images/blank.gif' width='10' height='15' border='0'><br></TD><TD width='220' valign='top'><img src='http://www.goodfoundation.com/_images/blank.gif' width='100' height='120' border='0'><br><font class=blackheader><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='33' height='5' border='0'>DONATE SECURELY <br><img src='http://www.goodfoundation.com/_images/blank.gif' width='33' height='5' border='0'>IN 2 MIN</font><br><a href='http://www.justgiving.com/globalrichlist' target='_blank' onFocus='blur();'><img src='http://www.goodfoundation.com/_images/care.gif' width='239' height='150' border='0'></a><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='36' height='31' border='0' align='left'><font class=blacksmall></font></TD><TD width='10'><img src='http://www.goodfoundation.com/_images/blank.gif' width='10' height='15' border='0'><br></TD></TR></TABLE></TD></TABLE>";
			
			// calculate pos on line
			currpos = Math.round(((100 - strPercentagePoorer) * 0.01) * 350);
		}
		
		html = "<TABLE WIDTH=599 BORDER=0 CELLPADDING=1 CELLSPACING=0>";
		html += "<TR>";
		html += "<TD colspan='8' background='http://www.goodfoundation.com/_images/dot.gif'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD>";
		html += "</TR><TR>";
		
		html += "<TD valign='top' width='50'><img src='http://www.goodfoundation.com/_images/blank.gif' width='50' height='1' border='0'><br></TD>";
		
		html += "<TD valign='top' width='30'><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='5' border='0'><br><img src='http://www.goodfoundation.com/_images/q_mark.gif' width='30' height='25' border='0'><br></TD>";
		
		html += "<TD valign='top' width='200'><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='11' border='0'><br><font class=blackheader>DID YOU <br>KNOW...?<br></font><img src='http://www.goodfoundation.com/_images/blank.gif' width='1' height='5' border='0'><br>";
		html += "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>";
		html += "<TR>";
		html += "<TD><font class=blacksmall>";
		html += arrDidYouKnow[Math.round(Math.random() * 3)] + "<br></font>";
		html += "</TD>";
		html += "</TR>";
		html += "</TABLE>";
		html += "</TD>";
		
		html += "<TD valign='top' width='15'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD>";

		html += "<TD valign='top' width='3' background='http://www.goodfoundation.com/_images/dot.gif'><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='1' border='0'><br></TD>";
		
		html += "<TD valign='top' width='15'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD>";

		html += "<TD valign='top' width='300'><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='11' border='0'><br><font class=blackheader>ABOUT CARE INTERNATIONAL<br></font><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='3' border='0'><br><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><font class=blacksmall>Global Rich List supports <a href='http://www.careinternational.org.uk/' target='_blank'>CARE International.</a><br><br>CARE International works in some of the poorest countries of the world where it acts for the poor and vulnerable - during crises and over the long term. Operating on a global scale, CARE counters hunger and fights poverty and inequality. Last year alone its projects touched the lives of nearly 25 million people across the globe. Payments managed by JustGiving.com. </font><br><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='11' border='0'><br></TD></TR></TABLE></TD>";
		
		html += "<TD valign='top' width='15'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD>";

		html += "</TR><TR>";
		html += "<TD colspan='8' background='http://www.goodfoundation.com/_images/dot.gif'><img src='http://www.goodfoundation.com/_images/blank.gif' width='15' height='1' border='0'><br></TD>";
		html += "</TR>";
		html += "</TABLE>";
		
		html += "<TABLE WIDTH=599 BORDER=0 CELLPADDING=1 CELLSPACING=0>";
		html += "<TR>";
		html += "<TD valign='top' width='75'><img src='http://www.goodfoundation.com/_images/blank.gif' width='85' height='49' border='0'><br></TD>";
		html += "<TD valign='top' width='230'><img src='http://www.goodfoundation.com/_images/blank.gif' width='3' height='11' border='0'><br><font class=blackheader>HELP US SPREAD <br>THE WORD!<br></font><img src='http://www.goodfoundation.com/_images/blank.gif' width='1' height='5' border='0'><br>";
		
		html += "<TABLE WIDTH=200 BORDER=0 CELLPADDING=0 CELLSPACING=0>";
		html += "<TR>";
		html += "<TD><font class=blacksmall>";
		html += "Add the box to the right to your own website.<br><br>";
		html += "<a href='download.html?"+tempPlace+"' onFocus='blur();'>Click here</a> to download the code you'll need.<br></font>";
		html += "</TD>";
		html += "</TR>";
		html += "</TABLE>";
		
		html += "</TD>";
		html += "<TD valign='top' width='49'><img src='http://www.goodfoundation.com/_images/blank.gif' width='52' height='19' border='0'><br></TD>";
		html += "<TD valign='top' width='*'><br><TABLE BORDER=0 CELLPADDING=8 CELLSPACING=1 style='border: 1px solid #000000; width:190px;' bgcolor='#ffffff'><TR><TD align=left style='font-size=12px; font-family:arial; color:#ffffff; background-color:#FF9900; line-height: 120%;'><font style='font-size=12px; font-family:arial; color:#000000;'><strong>I'm</strong> the <font style='font-size=12px; font-family:arial; color:#ffffff;'>" + strPlaceRicher2 + "</font> richest person on earth!</font><br><br><a href='http://www.globalrichlist.com' onFocus='blur();' style='text-decoration: none; font-weight: bold; color: #ffffff;'><img src='http://www.goodfoundation.com/_images/logo.gif' width=102 height=10 border=0><br><font style='font-size=10px;'>Discover how rich you are!</font> &rsaquo;&rsaquo;</a></TD></TR></TABLE><br></TD>";
		html += "</TR>";
		html += "</TABLE>";
		
		// print to page
		layerWrite(1,'answer1',null,text);
		layerWrite(2,'answer2',null,html);

		// move to right place on line
		fn_move_pos(currpos);
		
		
		if (ourpoor == false && ourrich == false) {
			fnInclude();
		}
		
	}
}



// reverses a string of text
function reverse(value) {

   for (var text = '',i=value.length-1;i>-1;i=i-1)
       text += value.charAt(i);
 
   return text;
}


// display answer
function layerWrite(i,id,nestref,text) {
	
	if (ns4) {
		var lyr = (nestref)?
		eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
		lyr.open()
		lyr.write(text)
		lyr.close()
	}
	
	if (ie4) {
		document.all[id].innerHTML = text;
	}
	
	// NS 6
	if (ns6) {
		document.getElementById('answer' + i).innerHTML = text;
	}
}

// includes the news
function fnInclude() {
	
	if (ie4) {
		document.all.news.style.visibility = 'visible';
		if (iswin) {
		document.all.news.style.posTop = 780;
		} else {
		document.all.news.style.posTop = 760;
		}
     } else if (ns4) {
		document.news.visibility = 'show';
		document.news.top = 780;
    } else if (ns6) {
		document.getElementById('news').style.visibility = 'visible';
		document.getElementById('news').style.posTop = 780;
	}
}

// hides the news
function fnIncludeHide() {
	
	if (ie4) {
		document.all.news.style.visibility = 'hidden';
		if (iswin) {
		document.all.news.style.posTop = 780;
		} else {
		document.all.news.style.posTop = 760;
		}
     } else if (ns4) {
		document.news.visibility = 'hide';
		document.news.top = 780;
    } else if (ns6) {
		document.getElementById('news').style.visibility = 'hidden';
		document.getElementById('news').style.posTop = 780;
	}
}

// moves the position graphic
function fn_move_pos(currpos) {
	
	if (ie4) {
	 	document.all.arr.style.posLeft = 135 + currpos;
		document.all.arr.style.posTop = 505;
		document.all.answer2.style.posTop = 860;
		document.all.arr.style.visibility = 'visible';
		document.all.line.style.visibility = 'visible';
     } else if (ns4) {
        document.arr.left = 135 + currpos;
		document.arr.top = 505;
		document.arr.visibility = 'show';
		document.line.visibility = 'show';
		document.answer2.top = 860;
    } else if (ns6) {
		document.getElementById('arr').style.posLeft = 135 + currpos;
		document.getElementById('arr').style.posTop = 505;
		document.getElementById('arr').style.visibility = 'visible';
		document.getElementById('line').style.visibility = 'visible';
		document.getElementById('answer2').style.posTop = 860;
	}
}

function hide_pos() {

	if (ie4) {
		document.all.arr.style.visibility = 'hidden';
		document.all.line.style.visibility = 'hidden';
	} else if (ns4) {
		document.arr.visibility = 'hide';
		document.line.visibility = 'hide';
    } else if (ns6) {
		document.getElementById('arr').style.visibility = 'hidden';
		document.getElementById('line').style.visibility = 'hidden';
	}
}

function whatkey() {
	if (ie4 || ns6) {
		thekey = window.event.keyCode;
				
		if (thekey == 13 && iswin) {
		//confirm("press");
			fnSubmit();
			//return false;
		}
	}
}

//-->
