// JavaScript Document
/*
Arxiu *.js
Aqui hi ha ses funcions que s'hauran d'emprar
*/

/* variable est�tica que guarda ses peticions i ses respostes */
var xmlHttp;			

// PETICIO
function posar_foto(nom,id) { 
/* declaracio de s�objecte */
xmlHttp=GetXmlHttpObject()

if (xmlHttp==null) {
 alert ("Aquest navegador no suporta Ajax");
 return;
 }
/*
//Altura de pantalla (necesaria para el parametro MOZILLA)
var alturaPantalla=document.all?document.body.offsetHeight:window.innerHeight;
var anchoPantalla=document.all?document.body.offsetWidth:window.innerWidth;
var navegador = window.navigator.appName;

//Altura de pantalla (EXPLORER)
if(navegador=="Microsoft Internet Explorer"){
	alturaPantalla=screen.availHeight;
	anchoPantalla=screen.availWidth;
}
*/
    var widthViewport,heightViewport;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth-17;
        heightViewport= window.innerHeight-17;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }

var url="consultes/abrir_foto_mini_galeria.php";
url=url+"?id="+id+"&nom="+nom+"&alturaPantalla="+heightViewport+"&anchoPantalla="+widthViewport;

xmlHttp.onreadystatechange=resposta_foto;
	
/* aqui enviam sa petici�, en aquest cas li deim que es parametre li arribar� per m�tode GET (tot i que podria haver-se fet per post, i li passam tamb� s�url de s�arxiu PHP que far� sa petici� */
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



// RESPOSTA
function resposta_foto() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 
		document.getElementById("shadow").innerHTML= xmlHttp.responseText; 
		
		//Parche para ie 6
		var navegador = window.navigator.appName;
		var version = window.navigator.appVersion;
		
		var es_ie6 = navegador.match("Microsoft Internet Explorer") != null && version.match("MSIE 6.0") != null;
		if(es_ie6){
			document.getElementById("general").style.display = 'none';
		}
		
		//Ajustamos foto
		var alturaPantalla=document.all?document.body.offsetHeight:window.innerHeight; 
		var alturaFoto = document.getElementById("shadow_foto").offsetHeight;
		document.getElementById("shadow_foto").style.marginTop = -(alturaFoto / 2) + 'px';
	} 
}


// GETXMLHTTPOBJECT
function GetXmlHttpObject() {
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

