var IN_DEBUG_MODE = false;

var req_fifo = null;
var owol = window.onload;

window.onload = function () {
	if ('function' == typeof owol) {
		owol();
	}
	if (IN_DEBUG_MODE) {
		alert('refrescando promociones');
	}
	refreshPromotion();
}

function refreshPromotion() {
	var url = 'promociones.php';
	url += '?uKey=' + Math.ceil(Math.random()*1000000);
	
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req_fifo = new XMLHttpRequest();
		req_fifo.abort();
		req_fifo.onreadystatechange = GotAsyncData;
		req_fifo.open("GET", url, true);
		req_fifo.send(null);
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req_fifo = new ActiveXObject("Microsoft.XMLHTTP");
		if (req_fifo) {
			req_fifo.abort();
			req_fifo.onreadystatechange = GotAsyncData;
			req_fifo.open("GET", url, true);
			req_fifo.send();
		}
	}
}

// GotAsyncData is the read callback for the above XMLHttpRequest() call.
// This routine is not executed until data arrives from the request.
// We update the "fifo_data" area on the page when data does arrive.
function GotAsyncData() {
	// only if req_fifo shows "loaded"
	if (req_fifo.readyState != 4 || req_fifo.status != 200) {
		return;
	}
	document.getElementById("contenido").innerHTML = req_fifo.responseText;
	
	if (IN_DEBUG_MODE) {
		setTimeout('refreshPromotion()', 3000);
	} else {
		setTimeout('refreshPromotion()', 15000);
	}
	return;
}

