// JavaScript Document
function clearTxt(x){
	
	var t = document.getElementById(x);
	if (t.value == t.defaultValue) t.value = "";
}

function cMenu(){
	var m = document.getElementById('cMenu');
	m.style.display = m.style.display == 'block' ? 'none' : 'block';
//	m.style.display = "block";
	var swfs = new Array('timeline', 'bubblePanel', 'mdgMap');
	
	if (document.getElementById(swfs[0])) {
		for (i=0; i<swfs.length; i++) {
			document.getElementById(swfs[i]).style.display = 'none';
		}
		document.getElementById('timeline').style.display = 'block';
	}
}

var current="Today is Christmas. Merry Christmas!";
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function countdown(yr,m,d){
	theyear=yr;
	themonth=m;
	theday=d;
	
	var today=new Date()
	var todayy=today.getYear()
	if (todayy < 1000)
	todayy+=1900
	var todaym=today.getMonth()
	var todayd=today.getDate()
	var todayh=today.getHours()
	var todaymin=today.getMinutes()
	var todaysec=today.getSeconds()
	var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
	var msec = (today.getMilliseconds())+1;
	
	
	futurestring=montharray[m-1]+" "+d+", "+yr;
	
	dd=Date.parse(futurestring)-Date.parse(todaystring)
	dday=Math.floor(dd/(60*60*1000*24)*1)
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
	
	d = document.getElementById("dateCounter");

	if (dday==0&&dhour==0&&dmin==0&&dsec==1){
		d.nodeValue=current;
		return;
	}
	else
		dday = dday<10 ? '0'+dday : dday;
		dhour = dhour<10 ? '0'+dhour : dhour;	
		dmin = dmin<10 ? '0'+dmin : dmin;
		dsec = dsec<10 ? '0'+dsec : dsec;
		d.childNodes[1].firstChild.nodeValue = dday;
		d.childNodes[3].firstChild.nodeValue = dhour;
		d.childNodes[5].firstChild.nodeValue = dmin;
		d.childNodes[7].firstChild.nodeValue = dsec;
		if (d.childNodes[9]) d.childNodes[9].firstChild.nodeValue = msec;

		setTimeout("countdown(theyear,themonth,theday)", 100)
}


var cur, prev = "";
var curX = "";


function getMDG(){
	var q = window.location.href.split('&');
	if (typeof(q[1]) != 'undefined') {
		x = q[1].indexOf('mdgs');
		if (x>=0) m = q[1].substr(x+5);
	}
	else m = 1;
	MDG('MDG'+m);
	return(m);
}

function getCur(){
	var x = '?p=takeaction&mdgs=' + curX.substring(curX.length-1);
	return x;	
}


var PPID = new Array(8399468, 8399974, 8400013, 8400025, 8400055, 8400073, 8400140, 8400150);

function MDG(x){
	
	curX = x;
	if (prev == "") cur = document.getElementById('MDG1').firstChild;
	var path = "img/MDG/";
	var d = document.getElementById(x);
	prev = cur;
	cur = d.firstChild;
	if (prev) prev.setAttribute(document.all ? 'className' : 'class', "off"); // IE DOM fix. IE does not recognize 'class'... must be 'className'
	cur.setAttribute(document.all ? 'className' : 'class', "on");
	x = x.substring(x.length-1);
	var txt = " ";
	document.getElementById('MDGnum').lastChild.nodeValue = x;
	var divs = d.getElementsByTagName("em");
	
	for (i=0; i<divs[0].childNodes.length; i++) {
	if (divs[0].childNodes[i].nodeValue != null)  txt = txt + divs[0].childNodes[i].nodeValue;
	}
	newTxt = document.getElementById("MDGtxt");
	
	newTxt.lastChild.lastChild.nodeValue = txt.toUpperCase();
//	document.getElementById('mdgPic').setAttribute('src', path+'goal'+x+'_takeaction_picture.jpg');
	
	var tableData = new Array('org', 'partnerorg', 'location', 'budget', 'timeline', 'results', 'desc');
	for (i=0; i<tableData.length; i++) {
		if (tableData[i] == 'org') {
			document.getElementById(tableData[i]).firstChild.nodeValue = MDGtxt[x][i];
			var l = document.getElementById('orgLogo');
			for (j=0; j<=l.childNodes.length; j++) {
				l.removeChild(l.firstChild);
			}
			
			var orgURL = document.createElement('a');
			l.appendChild(orgURL);
			if (MDGtxt[x][2]!='') {
				orgURL.setAttribute("href", MDGtxt[x][2]);
				orgURL.setAttribute("target", "_blank");
			}
			else orgURL.removeAttribute("href");
			var PDF = '#';
			var k = document.getElementById('PDFlink');
			if (MDGtxt[x][1]!='') {
			var logo = document.createElement('img');
			logo.setAttribute('src', path+"lgo_"+MDGtxt[x][1]);
			logo.setAttribute('alt', MDGtxt[x][0]);
			orgURL.appendChild(logo);
			var docs = new Array('WCI_goal1', 'LilMDGs_ConceptPaper_BG_India', 'goal3_WCI', 'saveTheChildren', '#', 'FXB-Village_concept_paper', 'goal7-Live&Learn', 'GOAL8_grameenFoundation');
			k.setAttribute('href', path+'PDF/'+docs[x-1]+'.pdf');
			k.parentNode.style.display = "block";
			document.getElementById('MDGFactSheet').setAttribute('href', PDF);
			PDF = path+'PDF/factsheet_goal'+(x)+'.pdf';
			}
			
			else k.parentNode.style.display = "none";

			
			
			
						
		}
		
		else {
			tableData[i] == 'results' ? document.getElementById(tableData[i]).innerHTML = MDGtxt[x][i+2] : document.getElementById(tableData[i]).firstChild.nodeValue = MDGtxt[x][i+2];
		}
		
		if (x!=2) {
			table = document.getElementById('takeActionTable2');
			table.style.display = "none";
			
		}
		else table.style.display = "block";
		
	}

	document.getElementById('partnerorg').parentNode.style.display = "none"; // removing partner organization

	if (document.getElementById('flashBox')) {
		so = new SWFObject('img/goal'+x+'msg.swf','flashQuote','','','9');
		so.write('flashBox');

		var m = document.getElementById('targetsList');
		while (m.hasChildNodes()) {
			m.removeChild(m.firstChild);
		}
	
		
		for (i=0; i<goalsTxt[x].length; i++){
			listItem = document.createElement("li");
			txtNode = document.createTextNode(goalsTxt[x][i]);
			listItem.appendChild(txtNode);
			m.appendChild(listItem);
		}
	}
	
	if (document.getElementById('PayPalBNID')) {
//	document.getElementById('PayPalBNID').setAttribute('value', PPID[x-1]);
	}
	if (document.getElementById('MDGgraph')) document.getElementById('MDGgraph').setAttribute('src', 'img/graph/graph'+x+'.png');
}
