
window.onload = function() {
	eval(_bodyloadfunctions.join("\n"));
};

var _bodyloadfunctions = new Array();
function addbodyloadfunction(code)
{
	_bodyloadfunctions.push(code);
}

function getPageScroll()
{
	var scrOfX = 0, scrOfY = 0;
	if (typeof(window.pageYOffset) == 'number') {
	    //Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX, scrOfY];
}

function getPageSize()
{
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	return [pageWidth, pageHeight, windowWidth, windowHeight];
}

function findpos(obj)
{
	var pos = [0, 0, obj.offsetWidth, obj.offsetHeight];
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			pos[0] += obj.offsetLeft;
			pos[1] += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} // add offsets
	pos.push(pos[2] + pos[0]); // right edge
	pos.push(pos[3] + pos[1]);
	return pos; // = [left, top, width, height, right, bottom]
}									

function contains(container, containee)
{
	if (!container) {
		return false;
	}
	if (container.contains) {
		return container.contains(containee);
	} // contains method (msie)
	while (containee != container && containee != null) {
		containee = containee.parentNode;
	} // manual recurse through parents (DOM)
	return containee == container;
}

function setlinestatus(el)
{
	theid = el.name.split('_').pop();
	thestatus = el.value;
	var ajax = new Ajax('post', '/ajax/setlinestatus.php');
	ajax.add_value('id', theid);
	ajax.add_value('status', thestatus);
	ajax.execute();
	var p = el;
	while (p.tagName.toUpperCase() != 'TABLE') {
		p = p.parentNode;
	}
	var ips = p.getElementsByTagName('INPUT');
	var total = 0;
	for (var i = 0; i < ips.length; i++) {
		if (ips[i].type != 'hidden') {
			continue;
		}
		var myid = ips[i].name.split('_').pop();
		if (document.getElementById('ok_' + myid).checked) {
			total += parseFloat(ips[i].value);
		}
	}

	document.getElementById('totalprice').innerHTML = number_format(total, 2, ',', '.');
}

function number_format(price, decimals, dsep, tsep)
{
	price = price.toFixed(decimals);
	price = price.toString().replace('.', 'SEPARATOR').replace('SEPARATOR', dsep);
	var newprice = new String(dsep + price.substring(price.length - decimals, price.length));
	var flag = false;
	for (var i = price.length - decimals - (decimals ? 1 : 0); i >= 0; i -= 3) {
		if (!price.substring(i - 3, i).length) {
			continue;
		}
		newprice = price.substring(i - 3, i) + (flag ? tsep : '') + newprice;
		flag = true;
	}
	return newprice;
}

function update_orderlist(el, thestatus, thesite)
{
	var userid = el.value;
	var ajax = new Ajax('post', '/ajax/updateorderlist.php');
	ajax.add_value('userid', userid);
	ajax.add_value('status', thestatus);
	ajax.add_value('site', thesite);
	ajax.set_readystatehandler(function() {
		document.getElementById('orderlist').innerHTML = this.http.responseText;
	});
	ajax.execute();
}

function flash_run(id, width, height, url, params)
{
	document.write(
		'<object id="' + id + '" type="application/x-shockwave-flash" ' +
		'data="' + url + '" class="video" style="width: ' + width + 'px; height: ' + height + 'px">' +
		'<param name="movie" value="' + url + '">' +
		flash_build_params(params) +
		'</object>'
	);
}

function flash_build_params(params)
{
	var html = new Array();
	for (name in params) {
		html.push('<param name="' + name + '" value="' + params[name] + '">');
	}
	return html.join('');
}
