var output;
function showExactMoon(s,wpc,w){//w=1 for waxing, 2 for waning, wpc is pcent lit from left hand side(if w=0
	var size=s;
	var i,h,lasth,p;
	var wid;
	if(w==1){//waxing
		left="stdimages/singleblack.gif";
		right="stdimages/singlewhite.gif";
	}
	else{//waning
		left="stdimages/singlewhite.gif";
		right="stdimages/singleblack.gif";
	}
//	output='<div style="text-align: center;">';
	output="";
	p=Math.round(wpc);
	for(i=-(size-1);i<size;++i){
		var wid=2*parseFloat(Math.sqrt((size*size)-(i*i)));
		if(p!=0){//not new moon
			output+="<img src="+left+" height='1' width='"+(wid*(p/100))+"' />";
		}
		if(p!=100){//not full moon
			output+="<img src="+right+" height='1' width='"+(wid*((100-p)/100))+"' />";
		}
		output+="<br />\n";
	}
	return output;
}
function showMoon(s,wpc,w){
	if(w>0){
		output=showExactMoon(s,wpc,w);
		return output;
	}
	else{
		var currentDate=new Date();
		currentDate.setTime(currentDate.getTime()+(currentDate.getTimezoneOffset()*60000));
		var lunarPeriod=29.53058885*(24*3600*1000);//observed synodic month in millisecs 2000CE value of 29.53058885 days
		var fullMoonDate=new Date(Date.UTC(2004,11,26,14,5));//latest full moon - Day hour and month are 0 based
		var height=1;
		var size=s;
		var i;
		var moonPhaseTime=(currentDate.getTime()-fullMoonDate.getTime())%lunarPeriod;
		var percentRaw=(moonPhaseTime/lunarPeriod);
		var percent=Math.round(100*percentRaw)/100;
		var percentBy2=Math.round(200*percentRaw);
		var left=(percentRaw>=0.5)? "stdimages/singleblack.gif" : "stdimages/singlewhite.gif";
		var right=(percentRaw>=0.5)? "stdimages/singlewhite.gif" : "stdimages/singleblack.gif";
		output='<div style="text-align: center;">';
		if(percentBy2>100){
			percentBy2=percentBy2-100;
		}
		for(i=-(size-1);i<size;++i){
			var wid=2*parseFloat(Math.sqrt((size*size)-(i*i)));
			if(percentBy2!=100){
				output+="<img src="+left+" height='1' width='"+(wid*((100-percentBy2)/100))+"' />";
			}
			if(percentBy2!=0){
				output+="<img src="+right+" height='1' width='"+(wid*((percentBy2)/100))+"' />";
			}
			output+="<br />";
		}
		output+='</div>'
		return output;
	}
}
var nextnma,nextfqa,nextfma,nextlqa,lastnma,lastfqa,lastfma,lastlqa;
function updatepcent(nextnm,nextfq,nextfm,nextlq,lastnm,lastfq,lastfm,lastlq){
	var pcent,now,ang,wid,w;
	now=new Date();
	now.setTime(now.getTime()+(now.getTimezoneOffset()*60000)); 
	now/=1000;
	if(nextfm<nextnm){//waxing
		if(nextfq<nextfm){
			pcent=(now-lastnm)/(nextfq-lastnm);
			ang=pcent*90;
			ang=ang*((2*Math.PI)/360);//to radians
			wid=50*Math.cos(ang);
			wid+=50;//represents first(black) pixels width
		}
		else{
			pcent=(now-lastfq)/(nextfm-lastfq);
			ang=pcent*90;
			ang=ang*((2*Math.PI)/360);//to radians
			wid=50*Math.sin(ang);
			wid=(50-wid);//represents first(black) pixels width
		}
		w=1;
	}
	else{//waning
		if(nextlq<nextnm){
			pcent=(now-lastfm)/(nextlq-lastfm);
			ang=pcent*90;
			ang=ang*((2*Math.PI)/360);//to radians
			wid=50*Math.cos(ang);
			wid+=50;//represents first(white) pixels width
		}
		else{
			pcent=(now-lastlq)/(nextnm-lastlq);
			ang=pcent*90;
			ang=ang*((2*Math.PI)/360);//to radians
			wid=50*Math.sin(ang);
			wid=(50-wid);//represents first(white) pixels width
		}
		w=2;
	}
	if(w==1) wid=100-wid;
	wid*=1000;
	wid=Math.round(wid)/1000;
	document.all.pclit.innerHTML=wid;
	nextnma=nextnm;nextfqa=nextfq;nextfma=nextfm;nextlqa=nextlq;
	lastnma=lastnm;lastfqa=lastfq;lastfma=lastfm;lastlqa=lastlq;
	setTimeout("updatepcent(nextnma,nextfqa,nextfma,nextlqa,lastnma,lastfqa,lastfma,lastlqa)",5000);
}