var request;
var dest;
if(undefined==window.php_path){
	var php_path = '/reloj2.php';
}


function processStateChange(){
	if (request.readyState == 4){
		horaDiv = document.getElementById("hora");
		fechaDiv = document.getElementById("fecha");
		if (request.status == 200){
			response = request.responseText;
			response_Arr = response.split('|');
			fechaDiv.innerHTML = response_Arr[0];
				horaDiv.innerHTML = response_Arr[1].substring(0,5);
				initClock();
		} else {
			fechaDiv.innerHTML = "Error: Status "+request.status;
		}
	}
}

function loadHTML(URL, destination){
	dest = destination;
	if (window.XMLHttpRequest){
		request = new XMLHttpRequest();
		request.onreadystatechange = processStateChange;
		request.open("GET", URL, true);
		request.send(null);
	} else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if (request) {
			request.onreadystatechange = processStateChange;
			request.open("GET", URL, true);
			request.send();
		}
	}
}
ruido = Math.floor(Math.random()*9999+1);
loadHTML(php_path+'?r='+ruido,'hora');
function initClock(){
	if (document.all) var horarg = hora.innerHTML
	else if (document.getElementById) var horarg=document.getElementById("hora").innerHTML
	hrstmp = parseFloat(horarg.substring(0,2));
	mintmp = parseFloat(horarg.substring(3,5));
//	sectmp = parseFloat(horarg.substring(6,8));
	setInterval("upClock()",60000);
}
function upClock(){
	var col = ":";
	if (!document.layers&&!document.all&&!document.getElementById) return
	if (document.all) var horarg = hora.innerHTML
	else if (document.getElementById) var horarg=document.getElementById("hora").innerHTML
	hrstmp = parseFloat(hrstmp);
	mintmp = parseFloat(mintmp);
	mintmp = mintmp+1;
//	sectmp = parseFloat(sectmp);
//	sectmp = sectmp+1;
//	if (sectmp == 60) {
//		sectmp=0;
//		mintmp= mintmp+1;
//	}
	if (mintmp == 60) {
		mintmp=0;hrstmp= hrstmp+1;
	}
	if (hrstmp == 24) hrstmp=00;
//	hrstmp = '' + hrstmp;mintmp = '' + mintmp;sectmp = '' + sectmp;
	hrstmp = '' + hrstmp;
	mintmp = '' + mintmp;
	if (hrstmp.length == 1) {
		hrs = '0' + hrstmp;
	}
	else {
		hrs = hrstmp;
	}
	if (mintmp.length == 1) {
		min = '0' + mintmp;
	}
	else {
		min = mintmp;
	}
//	if (sectmp.length == 1) {
//		sec = '0' + sectmp;
//	}
//	else {
//		sec = sectmp;
//	}
//	hora_str = hrs+col+min+col+sec;
	hora_str = hrs+col+min;

	if (document.layers){
		document.layers.hora.document.write(hora_str);
		document.layers.hora.document.close();
	}
	else if (document.all) hora.innerHTML=hora_str
	else if (document.getElementById) document.getElementById("hora").innerHTML=hora_str
}
