var da,mo,yr,ho,mi,se;
var countdownwidth='130px';
var countdownheight='20px';
var StartMilsecleft=0;
var MilSecleftBeforeEnd = 0;
var daystring, hourstring, minutestring, secondstring, endofauctionstring, NextRefreshString, NextRefreshMinStr, NextRefreshSecStr;

function counter(timeLaps, daystr, hourstr, minutestr, secondstr, endofauction, nextrefreshstr, nextrefreshminstr, nextrefreshsecstr)
{
    var now = new Date();

		StartMilsecleft = timeLaps*1000;

        
	daystring = daystr;
	hourstring = hourstr;
	minutestring = minutestr;
	secondstring = secondstr;
	endofauctionstring = endofauction;

	NextRefreshString = nextrefreshstr;
	NextRefreshMinStr = nextrefreshminstr;
	NextRefreshSecStr = nextrefreshsecstr;
	
	if(document.all)
	{
		document.write('<span id="countdownie" class=bgcol1></span>')
	}
	
	if(document.getElementById)
	{
		document.write('<div id="countdowndiv" class=bgcol1></div>')
	}
	
	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";
		var id = "countdownnsmain";
		document.getElementById(id).style.display="block"
	}

	countdown(StartMilsecleft);	
	RefreshCountDownClock(StartMilsecleft);
}

function countdown(milsecleft)
{	

	if (isNaN(milsecleft))
	{

	}
	else if (milsecleft>=1000)
	{
		dday=Math.floor(milsecleft/(60*60*1000*24)*1)
		dhour=Math.floor((milsecleft%(60*60*1000*24))/(60*60*1000)*1)
		dmin=Math.floor(((milsecleft%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
		dsec=Math.floor((((milsecleft%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

		if(dday<=0&&dhour<=0&&dmin<=0&&dsec<1)
		{
		   
		}
		else 
		{
			if(document.layers)
			{
				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.close()
			}
			else if(document.all)
			{
				HTMLdisp="";
				if (dday != 0)
					HTMLdisp=HTMLdisp+" "+dday+daystring
				if (dhour != 0 || dmin != 0 || dsec != 0)
					HTMLdisp=HTMLdisp+" "+dhour+hourstring
				if (dmin != 0 || dsec != 0)
					HTMLdisp=HTMLdisp+" "+dmin+minutestring
				if (dsec != 0)
					HTMLdisp=HTMLdisp+" "+dsec+secondstring
				countdownie.innerHTML=HTMLdisp
			}
			else if(document.getElementById)
			{
				content="";
				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;
				rng=document.createRange();
				el=document.getElementById('countdowndiv');
				rng.setStartBefore(el);
				htmlFrag=rng.createContextualFragment(content)
		
				while(el.hasChildNodes())
					el.removeChild(el.lastChild);
			
				el.appendChild(htmlFrag);
			}
		}
		
		milsecleft=milsecleft-1000;
		setTimeout("countdown("+milsecleft+")",1000);
	}
	else if ( milsecleft < 1000 && milsecleft >= 0)
	{
	    milsecleft = 0;
	    window.location.reload();
	}
	
}


function RefreshCountDownClock(StartMilsecleft)
{	
	if (StartMilsecleft > 0)
	{
		MilSecleftBeforeEnd = StartMilsecleft;
			 
		milSecLeftBeforeRefresh = 600000;

		if (MilSecleftBeforeEnd < 30000) 
		{
			milSecLeftBeforeRefresh = 30000; 
		}
		else if (MilSecleftBeforeEnd < 600000 ) 
		{
			milSecLeftBeforeRefresh = 120000;
		}	
		RefreshCountDown(MilSecleftBeforeEnd,milSecLeftBeforeRefresh);
	}
}

function RefreshCountDown(MilSecLeftBeforeEnd, milSecLeftBeforeRefresh)
{
	if (isNaN(MilSecLeftBeforeEnd))
	{

	}
	else if(MilSecLeftBeforeEnd >= 1000) 
	{	
		if (MilSecLeftBeforeEnd < 3600000) 
		{
			dmin=Math.floor(((milSecLeftBeforeRefresh%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
			dsec=Math.floor((((milSecLeftBeforeRefresh%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

			if(dmin<=0&&dsec<1)
			{}
			else 
			{
				content = NextRefreshString;
				if (dmin != 0 || dsec != 0)
					content+=" "+dmin+NextRefreshMinStr;
				if (dsec != 0)
					content+=" "+dsec+NextRefreshSecStr;
				window.status = content			
			}
		
			if (milSecLeftBeforeRefresh <= 0)
				window.location.href = window.location.href + (window.location.href.indexOf('nocount=1') <= 0 ? '' : '');
			
			milSecLeftBeforeRefresh = milSecLeftBeforeRefresh - 1000;					
		}
		MilSecLeftBeforeEnd = MilSecLeftBeforeEnd-1000;
	
		if (MilSecLeftBeforeEnd >= 0)
		{
			setTimeout("RefreshCountDown("+MilSecLeftBeforeEnd+","+milSecLeftBeforeRefresh+")",1000);
		}
	}
	
}

