
document.write('<script type="text/javascript" src="/js/cdlogic.js"></scr'+'ipt>');

debug = 0;			// Debug
var visible = false;
var flashResetter;
var first_start;
var runPos = 0;
var logged_in = 0;
var myRequest;
var colOrig = '';

var amoF = '2,.A&nbsp;&euro;';
var aCol = "#03ae23";
var cCol = "#0958f8";


lABidNum = 0;
lABidAmo = 0;
lMBidNum = 0;
lMBidAmo = 0;
myDailyBids = 0;


// 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);
	}
	

	if ("undefined" != typeof cAL && cAL.length > 0) {
		for (i = 0; i < cAL.length; i++) {
			aid = cAId[i];
			tL[aid] = 0;
		}
		cdTimesThread = setInterval("setCdTimes()", 500);
		cdLoaderThread = setInterval("cdLoader()", 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") {
		setCreditAmount(content);
	}
	if(command=="creditbids") {
		setCreditBids(content);
	}
	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") {
		setAmountField(aid, content, 'standard');
	}

	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>Connection interrupted</font>";
			}
		started = 0;
	}

	if (command == "slogan") {
		slogan = content;
		sloganS = 4;
	}
	
	
	if (command == "started") {
		started = content;
	}

	
	
	if (command == "history") {
		setHistory(aid);
	}
	

	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") {
		setUsername(aid, content);
    	}

  }
  
/*  
  function aF(a) {			// Cast amount Format
alert(amo);
  	decimals = amo.substring(0, 1);
  	dec_point = amo.substring(1, 1);
  	thousands_sep = amo.substring(2, 1);
  	amo = amo.substring(3);
  	amo = amo.replace("A", a);
  	return amo;
  }
*/

  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++) {
		r = rL[i];
		if (document.getElementById('a' + r['id'])) {
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
				document.getElementById('a' + r['id']).style.backgroundColor = '#FFF';
			else 
				document.getElementById('a' + r['id']).style.backgroundColor = null;

			document.getElementById('a' + r['id']).style.color = r['col'];
		}
	}
	if(document.getElementById('sloganfield')) {
		if (sloganS > 0) sloganS--;
		else slogan = '';
		document.getElementById('sloganfield').innerHTML = slogan;
	}
	if(started == 0) {
		initLoader();
	}
	rL = new Array();


  }
  
  
  function setAmountField(aid, content, type) {
	lAmount = content;
	aEl = document.getElementById('a' + aid);
	amoN = strAmount(content);
	amoN = amoN.substr(0, amoN.indexOf(",") + 3);
	amoO = aEl.innerHTML;
	amoO = amoO.substr(0, amoO.indexOf(",") + 3);
//alert(amoO);
	if (aEl && amoN != amoO) {
		aEl.innerHTML = strAmount(content);
		aEl.style.backgroundColor = '#FF0000';
		colOrig = aEl.style.color;
		aEl.style.color = '#FFFFFF';
		r = new Object();
		r['id'] = aid;
		r['col'] = type == 'countdown' ? cCol : aCol;
		rL[rL.length] = r;
	}
  }
  
  
  function setCalculation() {
  	if (document.getElementById('off_p')) {
		document.getElementById('sale_p').innerHTML = strAmount(lAmount);
		a = market_price - lAmount - lABidAmo;
		if (lMBidAmo) a -= lMBidAmo;
		if (a < 0) a = 0;
		document.getElementById('off_p').innerHTML = strAmount(a);
		if (document.getElementById('abids_p')) {
			document.getElementById('abids_p').innerHTML = strAmount(lABidAmo);
			document.getElementById('mybids').innerHTML = lABidNum;
			if (document.getElementById('mbids_p')) document.getElementById('mbids_p').innerHTML = strAmount(lMBidAmo);
			document.getElementById('mobids').innerHTML = lMBidNum;
		}
	}
	if (document.getElementById('dailybids'))
		document.getElementById('dailybids').innerHTML = myDailyBids;
  }
  
  
  function setCreditAmount(content) {
	document.getElementById('creditamount').innerHTML = strAmount(content);
  }


  function setCreditBids(content) {
	content = content * 1;
	document.getElementById('creditbids').innerHTML = content.toString();
  }


  function setFinalAmountField(aid, content) {
	amo = strAmount(content);
	aEl = document.getElementById('fa' + aid);
	if (aEl && amo != aEl.innerHTML) {
		aEl.innerHTML = amo;
//		aEl.style.backgroundColor = '#FF0000';
//		colOrig = aEl.style.color;
//		aEl.style.color = '#FFFFFF';
//		rL[rL.length] = aid;
	}
  }
  
  
  function setHistory(aid) {
	if ("undefined" != typeof detailId && aid == detailId && lAmount > 0 && lUser != '') {
		// Filter gegen Doppeleinträge
		var oldAmo = document.getElementById('bid0').innerHTML;
		var newAmo = strAmount(lAmount);
		var del = newAmo.indexOf(",") > 0 ? "," : ".";
		if (oldAmo.substr(0, oldAmo.indexOf(del) + 3) == newAmo.substr(0, newAmo.indexOf(del) + 3)) 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') ? 'BidAgent' : 'Web-Gebot';
		document.getElementById('bicon0').innerHTML = '<img src="/img/en/placement1.gif" border=0 />';
		document.getElementById('bid0').innerHTML = newAmo;
		document.getElementById('bidder0').innerHTML = lUser;
		document.getElementById('btype0').innerHTML = btype;
		p = 1;
		usrs = lUser;
		if (detailId != cAId[0]) {			// placements for standard only
			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/en/placement' + (p+1) + '.gif" border=0>';
					usrs += un;
					p++;
				} else {
					document.getElementById('bicon' + i).innerHTML = '';
				}
			}
		}
		setCalculation();
	}
  }
  
  
  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 setUsername(aid, content) {
	if(document.getElementById('u' + aid)) {
		document.getElementById('u' + aid).innerHTML = content;
		lUser = content;
	}
  }
  

  function strAmount(amo) {
  	dec_point = amoF.substr(1, 1);
  	thou_sep = amoF.substr(2, 1);
	amount = amo / 100;
	amo = amount.toString();
	amo = amo.replace(".", dec_point);
	if (amo.indexOf(dec_point) < 0) amo += dec_point + "00";
	if (amo.indexOf(dec_point) == amo.length - 2) amo += "0";
	if (amo.indexOf(dec_point) > 3) amo = amo.substr(0, amo.indexOf(dec_point) - 3) + thou_sep + amo.substr(amo.indexOf(dec_point) - 3);
	amount = amoF.substr(3);
	Ax = amount.indexOf("A");
	amo = amount.substr(0, Ax) + amo + amount.substr(Ax + 1);
	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!");

