/*var contextPath = "file:///C:/Documents%20and%20Settings/Javi/Mis%20documentos/Proyectos/javimarin.com/";*/
/*var contextPath = "file:///H:/Mis%20proyectos/Personal/javimarin.com/";*/
var contextPath = "http://www.javimarin.com/";
var oldReportClass = "";
var oldReport = "";
//capture mouse position for quick help functionality
var xpos, ypos;
if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=getMouseCoordinates;

function getMouseCoordinates(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {xpos = e.pageX;ypos = e.pageY;}
	else if (e.clientX || e.clientY){xpos = e.clientX + document.body.scrollLeft;ypos = e.clientY + document.body.scrollTop;}
}

/**
 * Crea l'objecte ajax
 */
function creaAjax() {
     var objetoAjax=false;
     try {
	      /*Para navegadores distintos a internet explorer*/
	      objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
	      try {
	               /*Para explorer*/
	               objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
	               }
	               catch (E) {
	               objetoAjax = false;
	      }
     }

     if (!objetoAjax && typeof XMLHttpRequest!='undefined') {
      objetoAjax = new XMLHttpRequest();
     }
     
     return objetoAjax;
}

/**
 * Crida la url especificada i omple la capa amb el resultat obtingut
 * @param url Url a cridar
 * @param capa Capa on posar el resultat
 */
function read(url,capa) {
	url = contextPath + url;
	var ajax=creaAjax();
	var capaContenedora = document.getElementById(capa);
	ajax.open ('GET', url, true);
	ajax.onreadystatechange = function() {
	  if (ajax.readyState==1) {
		capaContenedora.innerHTML="<img src='../img/wait.gif' border='0'/>";
	  } else if (ajax.readyState==4){
		if(ajax.status==200 || ajax.status == 0) {
		  document.getElementById(capa).innerHTML = ajax.responseText;
		} else if(ajax.status==404) {
			capaContenedora.innerHTML = "La direccion no existe";
		} else {
			capaContenedora.innerHTML = "Error: "+ajax.status;
		}
	  }
	}
    ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(null);
    return;
}

function resize(img, anchura, altura){
	img.height = altura;
	img.width = anchura; 
}

function selectReport(idObject){
	var report = document.getElementById(idObject);
	var oldClass = report.className;
	
	// Restaurem l'stil a l'opció deseleccionada
	if (oldReport != "") {
		document.getElementById(oldReport).className = oldReportClass;
		document.getElementById(oldReport).style.fontWeight="normal";
	}
	// Remarquem l'opció com seleccionada i guardem la nova referčncia
	report.style.fontWeight="bold";
	oldReport = idObject;
	oldReportClass = oldClass;
	
	/*if (document.getElementById("a"+idObject)) {
		document.getElementById("a"+idObject).className="selected";
		document.getElementById("a"+oldReport).className="";
	}*/	
}

// Mostrar ayuda
function showHelp(id){
	var obj = getObject(id); var left; var top;
	if((xpos+4+125)>windowSize("w")) {left = xpos-100-15;} else {left = xpos+4;}
	top=ypos+12;
	if (obj) {obj.style.left=left+'px';obj.style.top=top+'px';if (obj.style.display!='block'){obj.style.display='block';}}
}
function hideHelp(id) {
	getObject(id).style.display="none";
}
function getObject(id) {
	if (document.all){return(document.all(id))}
	if (document.getElementById){return(document.getElementById(id))}
}
function windowSize(type) {
	var wWidth, wHeight;
	if( typeof( window.innerWidth ) == 'number' ) {wWidth = window.innerWidth;wHeight = window.innerHeight;}//Non-IE
  	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {wWidth = document.documentElement.clientWidth;wHeight = document.documentElement.clientHeight;}//IE 6+ in 'standards compliant mode'
  	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {wWidth = document.body.clientWidth;wHeight = document.body.clientHeight;}//IE 4 compatible
	if(type=="w"){return(wWidth);}else{return(wHeight);}
}
