/*************************************************

		AJAX

        Dani HeadMaster 2007 from empunyando.com

***************************************************/
		    //variable  clobal que conté l'objecte d'ajax
		    //var repReq = getAjaxObj();
            var repReq;
		    
		    //amb aixó montem la cadena de post amb el formulari
		    function getFormValues(fobj,valFunc)
		     {			
			var str = "";
			var valueArr = null;
			var val = "";
			var cmd = "";
			for(var i = 0;i < fobj.elements.length;i++)
			{
				switch(fobj.elements[i].type)
				{
				case "text":
					{
						//use single quotes for argument so that the value of			
						//fobj.elements[i].value is treated as a string not a literal			
						cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
						val = eval(cmd);
					}
			
					str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
					break;
			
				case "select-one":
					str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
					break;
				}
			}
			str = str.substr(0,(str.length - 1));
			return str;
			}	
		//capturar l'objecte
		
		//amb aixó escollim el component 
			function getObj()
			{
				var xh = null;
				try
				{
				//firefox, opera, KHTML
				xh =new XMLHttpRequest();	
				} catch(e)
					{
						//IE
						try
						{
						xh =new ActiveXObject("Msxml12.XMLHTTP");	
						}catch(e)
							{
								try{
									xh =new ActiveXObject("Microsoft.XMLHTTP")								
									}catch(e)
									{
										alert("El teu navegador no té suport per Ajax!");
										return false;	
									}
							}
					}
					
					return xh;		
					
			}
		
             function getAjaxObj()
             {
                if (window.XMLHttpRequest)
                {
                    return XMLHttpRequest; //NOT IE                    
                }else if (window.ActiveXObject)
                {
                    return new ActiveXObject("Microsoft.XMLHTTP");  //IE
                }else{
                    //navegadors que no suporten l'objecte
                    alert('El teu navegador no és compatible amb AJAX');
                    return false;
                }                
             }
             
             
      
/***********************************************************************************************/	
            var rDiv = '';

            //gestiona la resposta
             function handleReq()
             {
             	//alert('hem rebut');
                //comprobem que la connexió ha acabat
                if ( repReq.readyState == 4 )
                {
                    //posem el contingut a l'span
                    //alert(repReq.responseText);
                    document.getElementById(rDiv).innerHTML = repReq.responseText;
		            document.getElementById(rDiv).style.visibility = 'visible';	
		            NetejaLoading();
                    //document.meuform.resposta.value = repReq.responseText;
                }
             }
	
		    //amb aquesta crido un script asp i poso la resposta en una div 'situacio'
		    function cridaiposa(pagina,situacio)
		    {
		        
		        rDiv = situacio;
		        repReq = getObj();
             	//alert();
                if ( repReq.readyState == 4 || repReq.readyState == 0 )
                {
                	//configurem la funció que gestiona l'enllaç quan canvia
                    repReq.onreadystatechange = handleReq;                	
                    //configurem la connexió com un  GET
					//el "true" expecifica que es asíncrona ( opció per defecte)
                    repReq.open('GET',pagina,true);
		            //repReq.open('POST','temps.php',true);
                    //fem el request al servidor
                    repReq.send(null);
                }
		    }
		    
		    function cridaiposa_post(pagina,situacio,qstring)
		    {   
		        //alert('a');
		        //Loading("funcions/loading.asp",situacio,qstring);
		        //
		       rDiv = situacio;
		        repReq = getObj();
             	//alert(pagina);
                if ( repReq.readyState == 4 || repReq.readyState == 0 )
                {
                	//configurem la funció que gestiona l'enllaç quan canvia
                    repReq.onreadystatechange = handleReq;                	
                    //configurem la connexió com un  GET
					//el "true" expecifica que es asíncrona ( opció per defecte)
                    repReq.open('POST',pagina,true);
                    repReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    //carregant('Cargando...');
		            repReq.send(qstring);
                }
		    }

            function CanviCam(Num)
            {
               cridaiposa_post('curses.asp?Id='+Num,'div_fitxes','');
            }
            
            
            function Loading(pagina,situacio,qstring)
            {
		        rDiv = situacio;
		        repReq = getObj();
                if ( repReq.readyState == 4 || repReq.readyState == 0 )
                {
                    repReq.onreadystatechange = handleReq;                	
                    repReq.open('POST',pagina,true);
                    repReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		            repReq.send(qstring);
                }
                
            }
            function Neteja(Objecte)
            {
                Objecte.value="";
                            
            }
            function Cercador(Pagina,Valor,Zona)
            {
                
                cridaiposa_post(Pagina+Valor+"&Zona="+Zona,'div_fitxes','');
            }    

/*********************************************************************************************************/
/***************Posa la div amb el loading per "tapar" ***************************************************/

function carregant(missatge)
{
	//alert();

    var body_obj = document.body;

    var div1 = document.createElement('div');
	div1.style.height = '1000px';
	div1.style.width = '100%';
	div1.style.background = '#AAAAAA';
	div1.style.opacity = '0.8';
	div1.style.filter = 'alpha(opacity=80)';
	div1.style.visibility = 'hidden';
	div1.style.position = 'absolute';
	div1.style.top = '0';
	div1.style.left= '0';	
	div1.id="DIV1";
        
    var div2 = document.createElement('div');
    div2.style.visibility = 'hidden';
    div2.setAttribute('class','divmissatge');
    div2.setAttribute('align','center');
    div2.innerHTML = "<table class=\"tablemissatge\"><tr><td class=\"tdmissatge1\" align=\"center\" valign=\"middle\"></td><td class=\"tdmissatge\" align=\"center\" valign=\"middle\">" + missatge + "</td></tr></table>";
	div2.id="DIV2";
	
    
    body_obj.appendChild(div1);
    body_obj.appendChild(div2);

	div2.style.visibility = 'visible';
	div1.style.visibility = 'visible';
}
function NetejaLoading()
{
    var body_obj = document.body;
    if (document.getElementById("DIV1"))
    {
        body_obj.removeChild(document.getElementById("DIV1"));
    }
    if (document.getElementById("DIV2"))
    {
        body_obj.removeChild(document.getElementById("DIV2"));
    }
    
    
}
