/**
 * @author thomsonk
 */
//
// this routine will queue initialisation routines
// and should be used instead of <body onload=...
//
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function addUnloadEvent(func) {
	var oldonunload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			if (oldonunload) {
				oldonunload();
			}
			func();
		}
	}
}

function altTextAsTitles() {
// assigns value of image alt text as title text for Firefox
	if(document.images) {
		var images = document.getElementsByTagName('img');
		for(var i = 0; i < images.length; i++) {
			if(images[i].alt) {
				images[i].title = images[i].alt;
			}
		}
	}
}

function tabNavInit() {
//    var tabs = document.getElementById('tabNavInner');
//    var listElements = tabs.getElementsByTagName('li');
//    if(listElements) {
//        for (var i = 0; i < listElements.length; i++) {
//            if(listElements[i].id.indexOf('select') == -1) {
//                // this is not a selected element, so
//                // assign mouseover / mouseout functions
//                listElements[i].onmouseover = tabOver;
//                listElements[i].onmouseout = tabOut;
//            }
//        }
//    }
}

function tabOut() {
    var thisAnchor = this.getElementsByTagName('a');
    this.style.backgroundImage = 'url(/images/tabRight.gif)';
    thisAnchor[0].style.color = '#333367';
    thisAnchor[0].style.backgroundImage = 'url(/images/tabLeft.gif)';
    //this.className = '';
}
function tabOver() {
    var thisAnchor = this.getElementsByTagName('a');
    this.style.backgroundImage = 'url(/images/tabSelectedRight.gif)';
    thisAnchor[0].style.color = '#ffffff';
    thisAnchor[0].style.backgroundImage = 'url(/images/tabSelectedLeft.gif)';
    //this.className = 'over';
}

/* This function is used as a work-around to
   the Internet Explorer 6+ on Windows XP SP2 and higher
   which requires a user to click the ActiveX control to activate it
*/
function documentWrite(htmlText)
{
    document.write(htmlText);
}
// function needed for WP836(Remove countdown applet)
// start time need to be declared into invoking context
function countdown(auctionClosingTimeInSec, elementName){
	// time is already past
	element = document.getElementById(elementName);
	remainingTimeInSecs = auctionClosingTimeInSec - (new Date().getTime() - startTime) / 1000
	if (remainingTimeInSecs <= 0){
		//make font color black
		element.style.color = "#000000";
		element.innerHTML="auction closed";
	} else {// date is still good	
		//check if remaning time is less thant hour, and if is, change color to red
		if (remainingTimeInSecs <= 3600) {
			element.style.color = "#FF0000";
		}
		hours=0;mins=0;secs=0;out="Time left: ";

		hours = Math.floor(remainingTimeInSecs / 3600);//hours
		remainingTimeInSecs = remainingTimeInSecs % 3600;
		
		mins = Math.floor(remainingTimeInSecs / 60);//minutes
		remainingTimeInSecs = remainingTimeInSecs % 60;
		
		secs = Math.floor(remainingTimeInSecs);//seconds
		
		if(hours != 0){out += (hours < 10 ? "0" + hours : hours) +"h ";}
		if(hours != 0 || mins != 0){out += (mins < 10 ? "0" + mins : mins) +"m ";}
		out += (secs < 10 ? "0" + secs : secs) +"s";
		element.innerHTML=out;
	}
}