var da,mo,yr,ho,mi,se;
var countdownwidth='140px';
var countdownheight='16px';
var dd;
var daystring, hourstring, minutestring, secondstring, endofauctionstring;
function CountDownClock(endtime, servtime, daystr, hourstr, minutestr, secondstr, endofauction)
{
	var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var dateq=endtime;
	var datetoday=servtime;

	if (dateq.charAt(2) != '/')
		dateq = "0" + dateq.substring(0,dateq.length);
	if (dateq.charAt(5) != '/')
		dateq = dateq.substring(0,3) + "0" + dateq.substring(3,dateq.length);
	if (dateq.charAt(13) != ':')
		dateq = dateq.substring(0,11) + "0" + dateq.substring(11,dateq.length);
	
	if (datetoday.charAt(2) != '/')
		datetoday = "0" + datetoday.substring(0,datetoday.length);
	if (datetoday.charAt(5) != '/')
		datetoday = datetoday.substring(0,3) + "0" + datetoday.substring(3,datetoday.length);

	if (datetoday.charAt(13) != ':')
		datetoday = datetoday.substring(0,11) + "0" + datetoday.substring(11,datetoday.length);

	daystring=daystr;
	hourstring=hourstr;
	minutestring=minutestr;
	secondstring=secondstr;
	endofauctionstring=endofauction;
	mo=dateq.substring(0,2);
	da=dateq.substring(3,5);
	yr=dateq.substring(6,10);
	ho=dateq.substring(11,13);
	mi=dateq.substring(14,16);
	se=dateq.substring(17,19);
	var ampm=dateq.substring(20,22);
	ampm=ampm.toUpperCase();

	if(ampm=="PM")
	{
		if(ho!=12)
		{
			ho=parseInt(ho,10);
			ho=ho+12;
		}
	}
	else
	{
		if(ampm=="AM")
		{
			if(ho==12)
			{ho=0;}
		}
	}
	
	var qdatestring=da+","+mo+","+yr+","+ho+","+mi+","+se;

	if(document.all)
	{
		document.write('<span id="countdownie" class=bgcol1></span>')
	}
	
	if(document.getElementById)
	{
		document.write('<div id="countdowndiv" class=bgcol1></div>')
	}
	
	futurestring=montharray[mo-1]+" "+da+" "+yr+" "+ho+":"+mi+":"+se;
	
	if(datetoday==0)
	{
		today=new Date();
		todayy=today.getYear();

		if(todayy<1000)
		{
			todayy+=1900;
		}
	
		todaym=today.getMonth();
		todayd=today.getDate();
		todayh=today.getHours();
		todaymin=today.getMinutes();
		todaysec=today.getSeconds();
		todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
	}
	else
	{
		todaym=datetoday.substring(0,2);
		todayd=datetoday.substring(3,5);
		todayy=datetoday.substring(6,10);
		todayh=datetoday.substring(11,13);
		todaymin=datetoday.substring(14,16);
		todaysec=datetoday.substring(17,19);
		var ampm2=datetoday.substring(20,22);
		ampm2=ampm2.toUpperCase();

		if(ampm2=="PM")
		{
			if(todayh!=12)
			{
				todayh=parseInt(todayh,10);
				todayh=todayh+12;
			}
		}
		else
		{
			if(ampm2=="AM")
			{
				if(todayh==12)
				{todayh=0;}
			}
		}
		
		todaystring=montharray[todaym-1]+" "+todayd+" "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
	}

	dd=Date.parse(futurestring)-Date.parse(todaystring);
	
	window.onload=start_countdown;
}

function start_countdown()
{
	function resized()
	{
		if(pageWidth!=innerWidth||pageHeight!=innerHeight)
		{
			location.reload();
		}
	}

	if(document.layers)
	{
		pageWidth=innerWidth;
		pageHeight=innerHeight;
		window.onresize=resized;
		document.countdownnsmain.visibility="show";
	}

	countdown();
}

function countdown()
{
	var occasion="Auction End!"
	var message_on_occasion="";
	var opentags='<CLASS=regemp>'
	var tabletags="<TABLE CLASS=bgcol1 Border=0>"
	
	if(dd>=1000)
	{
		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)

		if(dday<=0&&dhour<=0&&dmin<=0&&dsec<1)
		{}
		else 
		{
			if(document.layers)
			{
				document.countdownnsmain.document.countdownnssub.document.write(tabletags);
				document.countdownnsmain.document.countdownnssub.document.write("<tr CLASS=bgcol1><td align=left CLASS=regemp>");
				if (dday != 0)
					document.countdownnsmain.document.countdownnssub.document.write(dday+daystring)
				if (dhour != 0 || dmin != 0 || dsec != 0)
					document.countdownnsmain.document.countdownnssub.document.write(" "+dhour+hourstring)
				if (dmin != 0 || dsec != 0)
					document.countdownnsmain.document.countdownnssub.document.write(" "+dmin+minutestring)
				if (dsec != 0)
					document.countdownnsmain.document.countdownnssub.document.write(" "+dsec+secondstring)
				document.countdownnsmain.document.countdownnssub.document.write("</td></tr></table>")
				document.countdownnsmain.document.countdownnssub.document.close()
			}
			else if(document.all)
			{
				HTMLdisp=tabletags;
				HTMLdisp=HTMLdisp+"<tr CLASS=bgcol1><td align=left CLASS=regemp>";
				if (dday != 0)
					HTMLdisp=HTMLdisp+" "+dday+daystring
				if (dhour != 0)
					HTMLdisp=HTMLdisp+" "+dhour+hourstring
				if (dmin != 0)
					HTMLdisp=HTMLdisp+" "+dmin+minutestring
				if (dsec != 0)
					HTMLdisp=HTMLdisp+" "+dsec+secondstring
				HTMLdisp=HTMLdisp+"</td></tr></table>";
				countdownie.innerHTML=HTMLdisp
			}
			else if(document.getElementById)
			{
				content=tabletags;
				content+="<tr CLASS=bgcol1><td align=left CLASS=regemp>in";
				if (dday != 0)
					content+=" "+dday+daystring;
				if (dhour != 0 || dmin != 0 || dsec != 0)
					content+=" "+dhour+hourstring;
				if (dmin != 0 || dsec != 0)
					content+=" "+dmin+minutestring;
				if (dsec != 0)
					content+=" "+dsec+secondstring;
				content+="</td></tr></table>";
				rng=document.createRange();
				el=document.getElementById('countdowndiv');
				rng.setStartBefore(el);
				htmlFrag=rng.createContextualFragment(content)
		
				while(el.hasChildNodes())
					el.removeChild(el.lastChild);
			
				el.appendChild(htmlFrag);
			}
		}
		
		dd=dd-1000;
		setTimeout("countdown()",1000);
	}
	else
	{
		if(document.layers)
		{
			document.countdownnsmain.document.countdownnssub.document.write(tabletags)
			document.countdownnsmain.document.countdownnssub.document.write("<tr CLASS=bgcol1><td align=center CLASS=reg><b>"+endofauctionstring+"</b></td></tr></table>")
			document.countdownnsmain.document.countdownnssub.document.close()
		}
		else if(document.all)
		{
			HTMLdisp=tabletags;
			HTMLdisp=HTMLdisp+"<tr CLASS=bgcol1><td align=center CLASS=reg><b>"+endofauctionstring+"</b></td></tr></table>"
			countdownie.innerHTML=HTMLdisp
		}
		else if(document.getElementById)
		{
			content=tabletags;content=content+"<tr CLASS=bgcol1><td align=center CLASS=reg><b>"+endofauctionstring+"</b></td></tr></table>"
			
			rng=document.createRange();
			el=document.getElementById('countdowndiv');
			rng.setStartBefore(el);
			htmlFrag=rng.createContextualFragment(content)

			while(el.hasChildNodes())
				el.removeChild(el.lastChild);
			
			el.appendChild(htmlFrag);
		}
			
		return
	}
}