debug = 0;			// Debug
var visible = false;
var flashResetter;
var first_start;
var runPos = 0;
var logged_in = 0;
var myRequest;

// On LOAD

// multibox
var box = {};
window.addEvent('domready', function(){
	flashResetter = window.setInterval("resetFlash()", 1000);

	box = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: true});

/**/
	if (first_start == 1) {
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
			var ieversion=new Number(RegExp.$1);
			if (ieversion <= 6) {
				openBox('/browser.html',600,150);
			}
		}
		
	}
/**/

	if (aL.length > 0) {
		for (i = 0; i < aL.length; i++) {
			aid = aId[i];
			tL[aid] = 0;
		}
		timesThread = setInterval("setTimes()", 1000);
	}


});


function openBox(html, width, height) {
	document.getElementById("mb8").href=html;
	document.getElementById("mb8").rel='width:' + width + ',height:' + height;
	box.open(document.getElementById('mb8'));
	document.getElementById("mb8").href="login.html";
	document.getElementById("mb8").rel='width:350,height:450';
}


// End LOAD



// category

function hidden_category()
{
        if (visible)
        {
                document.getElementById('category').style.display = 'none';
                visible = false;
        }
        else
        {
                document.getElementById('category').style.display = 'block';
                visible = true;
        }
}





// swf

var rL = new Array(); // List of reset amount flash


/*
<!--
*/
  if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
          navigator.userAgent.indexOf("Windows") != -1 &&
          navigator.userAgent.indexOf("Windows 3.1") == -1) {
     document.write('<script type="text/vbscript"> \n');
     document.write('on error resume next \n');
     document.write('Sub moLoader_FSCommand(ByVal command, ByVal content)\n');
     document.write('  call moLoader_DoFSCommand(command, content)\n');
     document.write('end sub\n');
     document.write('</script\> \n');
  }
//-->


  aid = "";


  aId = new Array();
  aL = new Object();
  aL.length = 0;
  aD = new Object();
  tL = new Object();
  tL.length = 0;

  
  slogan = "";
  sloganS = 0;
  
  lTime = "";
  lAmount = "";
  lUser = "";
  
  
  started = 0;
  
  lastTime = 0;
  currentTime = 0;


  function premiumbutton_DoFSCommand(command, content) {
	if(command == "bid"){
		sendBid(content);
	}
  }


  function moLoader_DoFSCommand(command, content) {

	if(command=="id") {
		aD = aL[content];
		aid = content;
	}
	if(command=="creditamount") {
		document.getElementById('creditamount').innerHTML = strAmount(content);
	}
	if(command=="creditbids") {
		content = content * 1;
		document.getElementById('creditbids').innerHTML = content.toString();
	}
	if(command=="done") {
		aid = "";
	}
	if(command=="time") {
		dl = content.indexOf(";");
		aid = content.substr(0, dl);
		ti = content.substr(dl + 1, content.length);
		if (ti == "F") {
			tL[aid] = lTime = 0;
		} else {
			t = new Date();
			ti -= Math.ceil(t.getTime() / 1000);
			lTime = ti;
			if (aId['0'] == aid) currentTime = ti;
			tL[aid] = ti;
		}
		setTimeField(aid, ti);
	}
	if(command=="timeHtml") {
		document.getElementById('t' + aid).innerHTML = content;
	}
	if(command == "alert"){
		content += "\n" + 't' + aid;
		alert(content);
	}
	if (command == "amount") {
		lAmount = content;
		amo = strAmount(content) + ' &euro;';
		aEl = document.getElementById('a' + aid);
		if (amo != aEl.innerHTML) {
			aEl.innerHTML = amo;
			aEl.style.backgroundColor = '#FF0000';
			aEl.style.color = '#FFFFFF';
			rL[rL.length] = aid;
		}
	}

	if(command == "bid"){
		sendBid(content);
	}

	if (command == "clock") {
		serverTS = parseInt(content);
	}
	
	
	if (command == "debug" && document.getElementById("debug1") && document.getElementById("debug2")) {
		d1 =  document.getElementById("debug1");
		d2 =  document.getElementById("debug2");
		d1.innerHTML = d2.innerHTML;
		d2.innerHTML = content;
	}
	
	
	if (command == "nodebit") {
		top.location.href = 'http://www.maxodo.de/mein-maxodo/konto_aufladen.html';
	}
	
	
	if(command=="notconnected") {
		for (i = 0; i < aL.length; i++) 
			if (document.getElementById('t' + aId[i])) {
				txt = document.getElementById('t' + aId[i]).innerHTML;
				if (txt.indexOf("Beendet") < 0)
					document.getElementById('t' + aId[i]).innerHTML = "<font size=-2>Verbindung unterbrochen</font>";
			}
		started = 0;
	}

	if (command == "slogan") {
		slogan = content;
		sloganS = 4;
	}
	
	
	if (command == "started") {
		started = content;
	}

	
	
	if (command == "history") {
		if (aid == detailId && lAmount > 0) {
			// Filter gegen Doppeleinträge
			var oldAmo = document.getElementById('bid0').innerHTML;
			var newAmo = strAmount(lAmount);
			if (oldAmo == newAmo) return;
			for(i = 9; i > 0; i--) {
				j = i - 1;
				document.getElementById('bicon' + i).innerHTML = '';
				document.getElementById('bid' + i).innerHTML = document.getElementById('bid' + j).innerHTML;
				document.getElementById('bidder' + i).innerHTML = document.getElementById('bidder' + j).innerHTML;
				document.getElementById('btype' + i).innerHTML = document.getElementById('btype' + j).innerHTML;
			}
			btype = (content == 'B') ? 'BietAgent' : 'Web-Gebot';
			document.getElementById('bicon0').innerHTML = '<img src="img/1.gif" border=0 />';
			document.getElementById('bid0').innerHTML = newAmo;
			document.getElementById('bidder0').innerHTML = lUser;
			document.getElementById('btype0').innerHTML = btype;
			p = 1;
			usrs = lUser;
			for (i = 1; i < 9 && p < 3; i++) {
				un = document.getElementById('bidder' + i).innerHTML;
				if (usrs.indexOf(un) < 0) {
					document.getElementById('bicon' + i).innerHTML = '<img src="img/' + (p+1) + '.gif" border=0>';
					usrs += un;
					p++;
				} else {
					document.getElementById('bicon' + i).innerHTML = '';
				}
			}
			setCalculation();
		}
	}
	

	if (command == "getAuctions") {
		initLoader();
	}
	if (command == "nextbidprice") {
		if (document.getElementById('cbidprice'))
			document.getElementById('cbidprice').innerHTML = content;
	}
	if (command == "reload") {
		// website reload
		top.location.reload();
	}
	if (command == "sumamount") {
		// set users amount sum & calculate
		amo = parseInt(content * 1);
		lABidAmo = amo;
		setCalculation();
	}
	if (command == "sumamountbids") {
		num = lABidNum;
		lABidNum = parseInt(content * 1);
		if (num < lABidNum)
			myDailyBids++;
		setCalculation();
	}	
	if (command == "sumbids") {
		num = lMBidNum;
		// set users bids sum & calculate
		lMBidNum = parseInt(content * 1);
		lMBidAmo = lMBidNum * 50;
		if (num < lMBidNum)
			myDailyBids++;
		setCalculation();
	}

	if (command == "time_color") {
		document.getElementById('t' + aid).style.color = content;
	}
    	if (command == "user" && document.getElementById('u' + aid)) {
		document.getElementById('u' + aid).innerHTML = content;
		lUser = content;
    	}

  }


  function resetFlash() {

  	runPos++;
  	if (runPos >= 300) {
 		runPos = 0;
  		if (logged_in == 1) {
			sendRequest('http://www.maxodo.de/', handleResp, 'ch=ping');

		}
 	}


/*
	if (lastTime == currentTime) {
if (debug==2 && !confirm("RESTART: " + lastTime + " / " + currentTime)) debug = 0;
		mo = null;
		if(window.moLoader) mo = window.document["moLoader"];
		if(document.moLoader) mo = document.moLoader;
		if(mo != null) {
			mo.Rewind();
			mo.Play();
			started = 0;
		}
	}
	lastTime = currentTime;
*/

	for (i = 0; i < rL.length; i++) {
		if (document.getElementById('a' + rL[i])) {
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
				document.getElementById('a' + rL[i]).style.backgroundColor = '#FFF';
			else 
				document.getElementById('a' + rL[i]).style.backgroundColor = null;

			document.getElementById('a' + rL[i]).style.color = '#339933';
		}
	}
	if(document.getElementById('sloganfield')) {
		if (sloganS > 0) sloganS--;
		else slogan = '';
		document.getElementById('sloganfield').innerHTML = slogan;
	}
	if(started == 0) {
		initLoader();
	}
	rL = new Array();


  }
  
  
  function setCalculation() {
  	if (document.getElementById('off_p')) {
		document.getElementById('sale_p').innerHTML = strAmount(lAmount) + '&nbsp;&euro;';
		a = market_price - lAmount - lABidAmo - lMBidAmo;
		document.getElementById('off_p').innerHTML = strAmount(a) + '&nbsp;&euro;';
		if (document.getElementById('abids_p')) {
			document.getElementById('abids_p').innerHTML = strAmount(lABidAmo);
			document.getElementById('mybids').innerHTML = lABidNum;
			document.getElementById('mbids_p').innerHTML = strAmount(lMBidAmo);
			document.getElementById('mobids').innerHTML = lMBidNum;
		}
	}
	if (document.getElementById('dailybids'))
		document.getElementById('dailybids').innerHTML = myDailyBids;
  }
  
  
  function setTimes() {
  	for (i = 0; i < aL.length; i++) {
  		aid = aId[i];
  		tL[aid]--;
  		ti = tL[aid];
		if (ti >= 1) 
			setTimeField(aid, ti);
	}
  }
  
  
  function setTimeField(aid, ti) {
  	if (ti == "F") {
		txt = "Beendet";
		col = '#777777';
	} else {
		t = new Date();
		t.setTime(ti * 1000);
		iDay = t.getDate() - 1;
		iHours = t.getHours() - 1;
		day = iDay > 0 ? iDay.toString() + "T" : "";
		col = ti > 10 ? '#000000' : '#FF0000';
		txt = day + strFormat(iHours) + ":" + strFormat(t.getMinutes()) + ":" + strFormat(t.getSeconds());
	}
	tF = document.getElementById('t' + aid);
	if (tF) {
		tF.innerHTML = txt;
		tF.style.color = col;
	}
  }
  

  function strAmount(amo) {
	amount = amo / 100;
	amo = amount.toString();
	amo = amo.replace(".", ",");
	if (amo.indexOf(",") < 0) amo += ",00";
	if (amo.indexOf(",") == amo.length - 2) amo += "0";
	if (amo.indexOf(",") > 3) amo = amo.substr(0, amo.indexOf(",") - 3) + "." + amo.substr(amo.indexOf(",") - 3);
	return amo;
  }
  
  
  function strFormat(i) {
	return i < 10 ? '0' + i.toString() : i.toString();
  }


  function contactL(msg) {
	if(window.moLoader) window.document["moLoader"].SetVariable("outx", msg);
	if(document.moLoader) document.moLoader.SetVariable("outx", msg);
  }
  
  
  function initLoader() {
	msg = 'alist';
	for (i = 0; i < aL.length; i++) {
		msg += aId[i];
	}
	if (debug==1 && !confirm(msg)) debug = 0;
	contactL(msg);
  }
  




function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}


function handleResp(req) {
/*
	var writeroot = [some element];
	writeroot.innerHTML = req.responseText;
*/
}




if (debug==1) alert("JS Load Test Ok!");
