var menuSelected="";
var menuShowFlag=true;
var ajaxTarget="";
var ajaxObj=null;
var ajaxLastAction="";
function disp_confirm(msg)
{
	var agree=confirm(msg);
	if (agree)	{		return true ;	}
	else		{		return false ;	}
}


function getHelp(Obj)
{
	alert(Obj);
}

function showhelp_byId(ObjId)
{
	var showText = document.getElementById(ObjId).innerHTML;
	var help_area = document.getElementById('help_area');
	help_area.innerHTML=showText;
	help_area.style.visibility='visible';
	moveLayer(help_area);
}

function showhelp(text)
{
	var help_area = document.getElementById('help_area');
	help_area.innerHTML=text;
	help_area.style.visibility='visible';
	moveLayer(help_area);
}

document.onmousemove=moveHelp;

function hidehelp()
{
	var help_area = document.getElementById('help_area');
	mousex=1;
	mousey=1;
	// if 0, apply rules for maximum content visibility, VI user
	if(help_area.style.zIndex==5){
	}
	else{
		help_area.style.visibility='hidden';
	}
	moveLayer(help_area);
}

function moveHelp()
{
	var help_area = document.getElementById('help_area');
	moveLayer(help_area);
}

function moveLayer(layer)
{
	mousex-=200;
	if(mousex>700){
		if(layer.style.width>0){
			mousex-=layer.style.width;
		}
		else{
		}
	}
	layer.style.left=mousex+3+'px';
	layer.style.top=mousey+3+'px';
//	alert(mousex+'|'+mousey);
	return true;
}

// ------------------------------------------------
// mouse position detection
//
// Detect if the browser is IE or not.
var IE = document.all?true:false					// If it is not IE, we assume that the browser is NS.
if (!IE) document.captureEvents(Event.MOUSEMOVE)	// If NS -- that is, !IE -- then set up for mouse capture
document.onmousemove = getMouseXY;					// Set-up to use getMouseXY function onMouseMove

// Temporary variables to hold mouse x-y pos.s
var mousex=0;
var mousey=0;
// These are for calendar
var tempX=0;
var tempY=0;
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e)
{
  if (IE)
  { // grab the x-y pos.s if browser is IE
  	if(document.body)
	{
    mousex = event.clientX + document.body.scrollLeft
    mousey = event.clientY + document.body.scrollTop
	}
  }
  else
  {  // grab the x-y pos.s if browser is NS
    mousex = e.pageX
    mousey = e.pageY
  }  
  // catch possible negative values in NS4
  if (mousex < 0){mousex = 0}
  if (mousey < 0){mousey = 0}
  tempX=mousex;
  tempY=mousey;
  return true
}

function showHide(layerId)
{
	DOM = (document.getElementById); // IE 5+ and NS 6+ 
	IE4 = (document.all); // IE 4 
	NS4 = (document.layers); // NS 4
	var state = ""; 

	if (DOM) { 
		state = document.getElementById(layerId).style.display;
		if(state == "none" && state != null) {
			document.getElementById(layerId).style.display = "";
		}
		else {
			document.getElementById(layerId).style.display = "none";
		}
	} 
	else if (IE4) { 
		state = document.all.layerId.style.display;
		if(state == "none" && state != null) {
			document.all.layerId.style.display = "";
		}
		else {
			document.all.layerId.style.display = "none";
		}
	} 
	else if (NS4) { 
		state = document.layers[layerId].style.display;
		if(state == "none" && state != null) {
			document.layers[layerId].style.display = "";
		}
		else {
			document.layers[layerId].style.display = "none";
		}
	} 	

}
function openPopUp(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function showMenu(layerId)
{
	menuSelected=layerId;
	menuShowFlag=true;
	layerId = "submenu_"+layerId;
	var submenu = document.getElementById(layerId);
//	submenuParent = submenu.offsetParent;
//	xx = findPosX(submenuParent);
//	yy = findPosY(submenuParent);
//	submenu.style.left = xx+"px";
//	submenu.style.top = yy+"px";
/*	var menu_area = document.getElementById(menuType);*/
	submenu.className="submenu_on";
//	submenu.style.display="block";
	
/*	menu_area.visibility='visible';*/
}

function hideMenu()
{
	if(menuSelected!="" && menuShowFlag==false)
	{
		layerId=menuSelected;
		layerId = "submenu_"+layerId;
		var submenu = document.getElementById(layerId);
		submenu.className="submenu_on";
	//	startMenuTimer();
		if(document.getElementById('submenu_office')){
			document.getElementById('submenu_office').className="submenu";
		}
		if(document.getElementById('submenu_factory')){
			document.getElementById('submenu_factory').className="submenu";
		}
		if(document.getElementById('submenu_raceweekend')){
			document.getElementById('submenu_raceweekend').className="submenu";
		}
		if(document.getElementById('submenu_community')){
			document.getElementById('submenu_community').className="submenu";
		}
		if(document.getElementById('submenu_admin')){
			document.getElementById('submenu_admin').className="submenu";
		}
		if(document.getElementById('submenu_all_offices')){
			document.getElementById('submenu_all_offices').className="submenu";
		}
	}
}

function hideMenuTimer(layerId)
{
	menuShowFlag=false;
//	menuId=layerId;
	var counter = setTimeout("hideMenu()", 1);
}

function select_menu_item(obj)
{
//	obj.style.border = '1px solid #0A246A';
//	obj.style.backgroundColor='#B6BDD2';
}

function unselect_menu_item(obj)
{
//	obj.style.border = '0px solid #FFFFFF';
//	obj.style.backgroundColor='';
}

function menu_position(layerId,obj)
{
	var menuElem = document.getElementById(layerId);
	xx = findPosX(obj)+0;
	menuElem.style.left = xx+'px';
//	alert(findPosX(obj)+30);
	yy = findPosY(obj)+10;
	menuElem.style.top = yy+'px';
//	alert(findPosY(obj)+13);
	//over.style.filter='alpha(opacity=85)';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
 
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function update_points_left()
{
	var points_left = document.getElementById("points_left");
	var points_used = 
		Number(document.getElementById("do1").value)+
		Number(document.getElementById("do2").value)+
		Number(document.getElementById("do3").value)+
		Number(document.getElementById("do4").value);
	if(document.getElementById("do5")!=null)
	{
		points_used+=Number(document.getElementById("do5").value);
	}
	points_left.innerHTML = driver_points-points_used;
	if(driver_points-points_used<0)
	{
		points_left.style.color =  '#990000';
		points_left.style.fontWeight = 'bold';
	}
	else{
		points_left.style.color =  '#000000';
		points_left.style.fontWeight = 'normal';
	}
	
}

function loadSetup($acceleration,$braking,$top_speed,$kerb_use,$racing_line,$front_wing,$rear_wing,$suspension,$gears,$revs_limiter,$tyres)
{
	document.getElementById('acceleration').value = $acceleration;
	document.getElementById('braking').value = $braking;
	document.getElementById('top_speed').value = $top_speed;
	document.getElementById('kerb_use').value = $kerb_use;
	document.getElementById('racing_line').value = $racing_line;
	document.getElementById('front_wing').value = $front_wing;
	document.getElementById('rear_wing').value = $rear_wing;
	document.getElementById('suspension').value = $suspension;
	document.getElementById('gears').value = $gears;
	document.getElementById('revs_limiter').value = $revs_limiter;
	document.getElementById('tyres').selectedIndex = $tyres-1;
	update_points_left();
}

function selectAll(formName)
{
	allElements = document.forms[formName].getElementsByTagName('input');
	for(var i=0;i<allElements.length;i++){
		if(allElements[i].type=="checkbox")
		{
			allElements[i].click();
		}
	}
}
function showTabElements()
{
	var args = showTabElements.arguments;
	for (var i=0;i<args.length;i++)
	{
		var obj = document.getElementById(args[i]);
		obj.style.display = "";
		var obj = document.getElementById("tab_"+args[i]);
		obj.className = "active";
	}
}
function hideTabElements()
{
	var args = hideTabElements.arguments;
	for (var i=0;i<args.length;i++)
	{
		var obj = document.getElementById(args[i]);
		obj.style.display = "none";
		var obj = document.getElementById("tab_"+args[i]);
		obj.className = "";
	}
}
function sortTable2(thObj)
{
	var tableObj = thObj.parentNode.parentNode.parentNode;
	var theadCells = tableObj.getElementsByTagName('th');
	var sortColumnNumber=0;
	for(var i=0; i<theadCells.length; i++)
	{
		if(theadCells[i]==thObj)
		{
			sortColumnNumber=i+1;
		}
	}

	var tbodyObj = tableObj.getElementsByTagName('tbody');
	var bodyRows = tableObj.getElementsByTagName('tr');
	var tdsSortColumnNumber = 0;
	
	indArray = new Array();
	for (var j=1; j<=bodyRows.length; j++){
		indArray[j]=parseInt(bodyRows[j].childNodes[sortColumnNumber].innerHTML);
	}
	newIndArray = quicksort(indArray, sortColumnNumber);
}

function quicksort(array)
{
	var list;
	var less = new Array();;
	var greater = new Array();;

	if (arraylength <= 1){
		return array;
	}
	//select and remove a pivot value $pivot from array
	var pivot = array[Math.round((array.length+1)/2)];
	for(var k=1; k<=array.length; k++)
	{
		if(array[k] == pivot){
			less[less.length]
			//append x to less
		}
		else{
			//append x to greater
		}
	}
	return concatenate(quicksort(less), pivot, quicksort(greater));
}

function quicksort1(array, left, right, sortColumnNumber)
{
	if(parseInt(array[right].childNodes[sortColumnNumber].innerHTML) > parseInt(array[left].childNodes[sortColumnNumber].innerHTML))
	{
		//select a pivot index (e.g. pivotIndex = left)
		pivotIndex = Math.round((right+left)/2);
		pivotNewIndex = 1;
		while(pivotNewIndex>0){
			pivotNewIndex = partition(array, left, right, pivotIndex, sortColumnNumber);
			quicksort(array, left, pivotNewIndex - 1, sortColumnNumber);
			quicksort(array, pivotNewIndex + 1, right, sortColumnNumber);
		}
	}
}

function partition(array, left, right, pivotIndex, sortColumnNumber)
{
	var counter = 0;
     pivotValue = parseInt(array[pivotIndex].childNodes[sortColumnNumber].innerHTML);
     // Move pivot to end
     swapRows(array,pivotIndex,right);
     storeIndex = left;
     for (i=left; i<right-1; i++)
     {
		if (parseInt(array[i].childNodes[sortColumnNumber].innerHTML) <= pivotValue)
		{
			swapRows(array, i, storeIndex);
			counter++;
			storeIndex = storeIndex+1;
		}
	}
	swapRows(array, storeIndex, right); // Move pivot to its final place
	if(counter==0){return 0;}
	return storeIndex;
}

function sortTable1(thObj)
{
	var tableObj = thObj.parentNode.parentNode.parentNode;
	var theadCells = tableObj.getElementsByTagName('th');
	var sortColumnNumber=0;
	for(var i=0; i<theadCells.length; i++)
	{
		if(theadCells[i]==thObj)
		{
			sortColumnNumber=i+1;
		}
	}

	var tbodyObj = tableObj.getElementsByTagName('tbody');
	var bodyRows = tableObj.getElementsByTagName('tr');
	var tdsSortColumnNumber = 0;
	
	for(var i=0; i<bodyRows.length-1; i++)
	{
		if(bodyRows[i].parentNode.tagName=='TBODY')
		{
			var highestRemainingRow=i;
			for(var j=i; j<bodyRows.length; j++)
			{
				if(tdsSortColumnNumber==0)
				{
					var countingTds = 0;
					for(var k=0; k<bodyRows[j].childNodes.length; k++)
					{
						if(bodyRows[j].childNodes[k].tagName=='TD')
						{
							countingTds=countingTds+1;
							if(countingTds==sortColumnNumber)
							{
								tdsSortColumnNumber = k;
							}
						}
					}
				}
//				alert('['+j+']'+bodyRows[j].childNodes[tdsSortColumnNumber].innerHTML+'?['+highestRemainingRow+']'+bodyRows[highestRemainingRow].childNodes[tdsSortColumnNumber].innerHTML);
				//numeric compare
				if(parseInt(bodyRows[j].childNodes[tdsSortColumnNumber].innerHTML)>0 && parseInt(bodyRows[highestRemainingRow].childNodes[tdsSortColumnNumber].innerHTML)>0)
				{
					if(parseInt(bodyRows[j].childNodes[tdsSortColumnNumber].innerHTML) > parseInt(bodyRows[highestRemainingRow].childNodes[tdsSortColumnNumber].innerHTML))
					{
						highestRemainingRow=j;
					}
				}
				else{
					if(bodyRows[j].childNodes[tdsSortColumnNumber].innerHTML > bodyRows[highestRemainingRow].childNodes[tdsSortColumnNumber].innerHTML)
					{
						highestRemainingRow=j;
					}
				}
			}
			//			alert('swap '+i+' - '+highestRemainingRow)
			//alert(parseInt(bodyRows[highestRemainingRow].childNodes[tdsSortColumnNumber].innerHTML));
			swapRows(bodyRows,i,highestRemainingRow);
		}
	}
}

var oldSortColumnNumber=0;
function sortTable(thObj){
	var tableObj = thObj.parentNode.parentNode.parentNode;
	var theadCells = tableObj.getElementsByTagName('th');
	var sortColumnNumber=0;
	//scan header cells
	for(var i=0; i<theadCells.length; i++)
	{
		if(theadCells[i]==thObj)
		{
			sortColumnNumber=i;
		}
	}

	var tbodyObj = tableObj.getElementsByTagName('tbody');
	tbodyObj[0].rows
	
	//scan all rows
	for(var i=0; i<tbodyObj[0].rows.length-1; i++)
	{
		tbodyObj[0].rows[i].cells[sortColumnNumber].className = addClass(tbodyObj[0].rows[i].cells[sortColumnNumber].className,'sort');
		tbodyObj[0].rows[i+1].cells[sortColumnNumber].className = addClass(tbodyObj[0].rows[i].cells[sortColumnNumber].className,'sort');
		tbodyObj[0].rows[i].cells[oldSortColumnNumber].className = removeClass(tbodyObj[0].rows[i].cells[oldSortColumnNumber].className,'sort');
		tbodyObj[0].rows[i+1].cells[oldSortColumnNumber].className = removeClass(tbodyObj[0].rows[i].cells[oldSortColumnNumber].className,'sort');
		var current = parseInt(tbodyObj[0].rows[i].cells[sortColumnNumber].innerHTML); 
		var next = parseInt(tbodyObj[0].rows[i+1].cells[sortColumnNumber].innerHTML);
		if( current < next )
		{
			// have to move
			beforeIndex = findFirstSmaller( tbodyObj[0].rows, next, sortColumnNumber );
			moveRowBefore(tbodyObj[0],i+1,beforeIndex)
		}
	}
	oldSortColumnNumber=sortColumnNumber;
}

function addClass(oldclass,newclass){
	if(typeof(oldclass)=="undefined"){oldclass='';}
	if(oldclass.indexOf(newclass)>-1){
		if(oldclass.length>0){
			oldclass = oldclass +" "+newclass; 
		}
		if(oldclass.length==0){
			oldclass = newclass; 
		}
	}
	return oldclass;
}
function removeClass(oldclass,newclass){
	if(typeof(oldclass)=="undefined"){oldclass='';}
	if(oldclass.indexOf(newclass)>-1){
		oldclass = oldclass.replace(newclass,''); 
	}
	return oldclass;
}

function findFirstSmaller(bodyRows, needle, sortColumnNumber)
{
	for(var i=0; i<bodyRows.length-1; i++)
	{
		compare = parseInt(bodyRows[i].cells[sortColumnNumber].innerHTML); 
		if( compare <= needle )
		{
			return i;
		}
	}
	return i;
}

function moveRowBefore(bodyRows,moveRowIndex,beforeIndex)
{
	var temp = bodyRows.rows[moveRowIndex];
	bodyRows.rows[moveRowIndex].parentNode.removeChild(bodyRows.rows[moveRowIndex]);
	bodyRows.insertBefore(temp,bodyRows.rows[beforeIndex]);
}

function swapRows(bodyRows,i,j)
{
	for (var k=0; k<bodyRows[i].childNodes.length; k++)
	{
		temp = bodyRows[i].childNodes[k].innerHTML;
		bodyRows[i].childNodes[k].innerHTML = bodyRows[j].childNodes[k].innerHTML;
		bodyRows[j].childNodes[k].innerHTML = temp;
	}
}


function countdown_clock(year, month, day, hour, minute, format)
{
	html_code = '<div id="countdown"></div>';
	document.write(html_code);
	countdown(year, month, day, hour, minute, format);                
}
         
/**
function countdown(year, month, day, hour, minute, format)
{
	Today = new Date();
	//alert(Today);
	Todays_Year = Today.getFullYear() - 2000;
	Todays_Month = Today.getMonth() + 1;                  
	
	//Convert both today's date and the target date into miliseconds.                           
	Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
						 Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
	Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
	
	//Find their difference, and convert that into seconds.                  
	Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
	
	if(Time_Left < 0)
	Time_Left = 0;
	
	switch(format)
	{
		case 0:
			//The simplest way to display the time left.
			document.all.countdown.innerHTML = Time_Left + ' seconds';
			break;
		case 1:
			//More datailed.
			days = Math.floor(Time_Left / (60 * 60 * 24));
			Time_Left %= (60 * 60 * 24);
			hours = Math.floor(Time_Left / (60 * 60));
			Time_Left %= (60 * 60);
			minutes = Math.floor(Time_Left / 60);
			Time_Left %= 60;
			seconds = Time_Left;
			
			dps = 's'; hps = 's'; mps = 's'; sps = 's';
			//ps is short for plural suffix.
			if(days == 1) dps ='';
			if(hours == 1) hps ='';
			if(minutes == 1) mps ='';
			if(seconds == 1) sps ='';
			
			document.all.countdown.innerHTML = days + ' day' + dps + ' ';
			document.all.countdown.innerHTML += hours + ' hour' + hps + ' ';
			document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and ';
			document.all.countdown.innerHTML += seconds + ' second' + sps;
			break;
		default: 
			document.all.countdown.innerHTML = Time_Left + ' seconds';
	}
	   
	//Recursive call, keeps the clock ticking.
	setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}
*/
function showhide_all_laps(laps)
{
	for(var i=1;i<=laps;i++)
	{
		lapObj = document.getElementById('lap_data'+i);
//		if(lapObj.style.display=='none')
//		{
			lapObj.style.display = '';
//		}
//		else{
//			lapObj.style.display = 'none';
//		}
	}
}

function select_row(obj)
{
	obj.className = 'selected';
}
function deselect_row(obj)
{
	obj.className = '';
}

var callbackFnName=null;
function ajaxCall(target, objId, callbackFn)
{
	callbackFnName = null;
	if(callbackFn){callbackFnName=callbackFn};
	ajaxTarget = target;
	if(objId){
		ajaxObj = document.getElementById(objId);
		ajaxObj.innerHTML='<img src="site/images/icons/autocomplete_spinner.gif" height="11" width="15">';
	}
	getData();
}

function getData()
{
	url = ajaxTarget;
    // branch for native XMLHttpRequest object
	// FF and Opera and others
    if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
	// IE
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange()
{
//	alert("process req change, \n ready state="+req.readyState+", status="+req.status);
	// only if req shows "completed"
	if (req.readyState == 4)
	{
		// only if "OK"
		if (req.status == 200)
		{
			//alert(req.getAllResponseHeaders());
			// process here
			ajaxReturn(req.responseText);
			return req.responseText;
		}
		else
		{
			if(ajaxObj!=null){
				ajaxObj.innerHTML = '<img src="site/images/icons/alert.gif" height="13" width="13">';
			}
			//alert("There was a problem retrieving data from the server:\n" + req.statusText);
			return false;
		}
	}
}

function ajaxReturn(text){
	if(ajaxObj!=null){
		ajaxObj.innerHTML = text;
		ajaxObj==null; 
	}
	if(callbackFnName){
		var callStr = callbackFnName+"('"+text+"');"; 
		eval(callStr);
	}
}

function showHideAll(layerId)
{
	var state = ""; 
	while(document.getElementById(layerId)){
		state = document.getElementById(layerId).style.display;
		if(state == "none" && state != null) {
			document.getElementById(layerId).style.display = "";
		}
		else {
			document.getElementById(layerId).style.display = "none";
		}
		document.getElementById(layerId).id='';
	}
}

/**
JS Function coundown, designed to take in a deadline date 
@params: int yr : deadline year
	 int mo : deadline month (1-12)
	 int da : deadline day (1-31)
	 int deadlineHr: deadline hour (24 hour clock)
	 boolean daylightSavings : set to true if currently in daylight savings(approx Mar-Nov), set to false if not
	 
@return : replaces the html between the following tags:
	  <span id="sec"> seconds remaining </span>
	  <span id="min"> minutes remaining </span>
	  <span id="hrs"> hours remaining </span>
	  <span id="dys"> days remaining </span>
	  
example html code: 

  	<span id="dys">00</span>:<span id="hrs">00</span>:<span id="min">00</span>:<span id="sec">00</span>
  	<!-- 
	<script type="text/javascript" src="http://assets.espn.go.com/js/countdownClock.js"></script>
	<script language="javascript">
	// yr, mo, day, hr (24 hr format)
	countdown(2008, 7, 21, 20, true)
	</script>
 	-->  
**/

/** 
* Calculates a time difference between client and server, to make js clock to run correctly
*/
var timeDifference = 0;
function timeDiff(Year, Month, Day, Hour, Minute, Second, dateFormat) {
    var serverClock = new Date(Year, Month - 1, Day, Hour, Minute, Second);

    var clientClock = new Date();
    var serverSeconds;
    var clientSeconds;
    timeDiff = clientClock.getTime() - serverClock.getTime() - 3000;
    timeDifference = timeDiff;
    runClock(timeDiff, dateFormat);
}

/*** Numbers < 10 should be presented with a zero in front*/
function fixNumber(number) {
    return (number < 10) ? '0' + number : number;
}

/*** Fixed look for month*/
function fixMonth(number) {
    number = number + 1;
    return (number < 10) ? '0' + number : number;
}

function getLocalDate(year, month, day, dateFormat) {
    if (dateFormat.length < 2) { // When not logged in there is no dateformat
        dateFormat = "yyyy-mm-dd";
    }
    dateFormat = dateFormat.replace("yyyy", year);
    dateFormat = dateFormat.replace("mm", month);
    dateFormat = dateFormat.replace("dd", day);
    dateFormat = dateFormat.replace("d", day);
    dateFormat = dateFormat.replace("m", month);

    return dateFormat;
}

/*** Show clock*/
function runClock(timeDiff, dateFormat) {
    var now = new Date();
    var newTime;
    newTime = now.getTime() - timeDiff;
    now.setTime(newTime);
    var localDate = getLocalDate(now.getFullYear(), fixMonth(now.getMonth()), fixNumber(now.getDate()), dateFormat);
    document.getElementById('time').innerHTML = localDate + ' ' + fixNumber(now.getHours()) + ':' + fixNumber(now.getMinutes()) + ':' + fixNumber(now.getSeconds());
    setTimeout('runClock(timeDiff,"' + dateFormat + '")', 1000);
}

/** update countdown to given date based on Server-client difference*/
function countdown(yr, mo, da, deadlineHr, deadlineMi, deadlineSe, noJsElemId, jsElemId){
	document.getElementById(noJsElemId).style.display="none";
	var countdownContainer = document.getElementById(jsElemId);
	countdownContainer.style.display="";
	var montharray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

	var now = new Date();
    var newTime;
    newTime = now.getTime() - timeDifference;
    now.setTime(newTime);

	var futureString = montharray[mo-1] + " " + da + ", " + yr + " " + deadlineHr + ":" + deadlineMi + ":" + deadlineSe;
	var dd = (Date.parse(futureString) - now)+500;
	dday=Math.floor(dd/(60*60*1000*24)*1);
	// TO SHOW DAYS
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
	// TO SHOW HOURS
	//dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1) + dday*24;
	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);
	    
	dday=Math.floor(dd/(60*60*1000*24)*1);
	// TO SHOW DAYS
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
	// TO SHOW HOURS
	//dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1) + dday*24;
	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);
	
	dday = (dday < 0) ? 0 : dday;
	dhour = (dhour < 0) ? 0 : dhour;
	dmin = (dmin < 0) ? 0 : dmin;
	dsec = (dsec < 0) ? 0 : dsec;

	// for multiple digits
	var hourPre = "";
	var minPre = "";
	var secPre = "";
	var dayPre = "";
	// for single digits
	if (dhour < 10) { hourPre = "0"; }
	if (dmin < 10) { minPre = "0"; }
	if (dsec < 10) { secPre = "0"; }
	if (dday < 10) { dayPre = "0"; }
	
	// update divs
	//countdownContainer.childNode.children[0]
	if(countdownContainer.childNodes.length > 0 &&  countdownContainer.childNodes[0].childNodes.length > 0){
		countdownContainer.childNodes[0].childNodes[6].innerHTML = secPre + dsec;
		countdownContainer.childNodes[0].childNodes[4].innerHTML = minPre + dmin;
		countdownContainer.childNodes[0].childNodes[2].innerHTML = hourPre + dhour;
		countdownContainer.childNodes[0].childNodes[0].innerHTML = dayPre + dday;
	}	
	
	funcStr = "countdown(" + yr + ',' + mo + ',' + da + ',' + deadlineHr + ',' + deadlineMi + ',' + deadlineSe + ', \'' + noJsElemId +'\', \'' + jsElemId +'\''+")";
	setTimeout(funcStr,1000);
}
function hideInformation(){
	var infoElem = document.getElementById('information');
	var infoWarn = document.getElementById('informationWarning');
	var oldText = infoElem.innerHTML;
	infoElem.innerHTML = infoWarn.innerHTML;
	infoWarn.innerHTML = oldText;
}
function showInformation(){
	var infoElem = document.getElementById('information');
	var infoWarn = document.getElementById('informationWarning');
	var oldText = infoElem.innerHTML;
	infoElem.innerHTML = infoWarn.innerHTML;
	infoWarn.innerHTML = oldText;
}
function hideHelpInfo(){
	showHide('help');
	ajaxCall('ajax.php?act=hideHelp',null,null);
	
}

function number_format(number, precision, decim, thous) {
	number = Math.round(number * Math.pow(10, precision)) / Math.pow(10, precision);
	e = number + '';
	f = e.split('.');
	if (!f[0]) {
		f[0] = '0';
	}
	if (!f[1]) {
		f[1] = '';
	}
	if (f[1].length < precision) {
		g = f[1];
		for (i=f[1].length + 1; i <= precision; i++) {
			g += '0';
		}
		f[1] = g;
	}
	if(thous != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j+=3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = thous + i + f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	decim = (precision <= 0) ? '' : decim;
	return f[0] + decim + f[1];
}
