﻿
/*****************************************/
/*  Capa */
/*****************************************/

function posaDiv(pag)
{
    if (!document.getElementById("tapador"))
    {
        var ndiv = document.createElement('div');
        ndiv.id = 'tapador';
        ndiv.style.height = '100%';
        ndiv.style.width = '100%';
                
        ndiv.style.position = 'absolute';
        ndiv.style.top = '0';
        ndiv.style.left = '0';
        ndiv.style.backgroundColor = '#161B1D';
            
            ndiv.style.opacity = '0.7';
            ndiv.style.MozOpacity = '0.7';
            ndiv.style.filter = "alpha(opacity = 70";
        document.body.appendChild(ndiv);   
    }
   
    if (!document.getElementById("contenidor_missatge"))
    {
        var pdiv = document.createElement('div');
        pdiv.id = 'contenidor_missatge';
        pdiv.style.height = '100%';
        pdiv.style.width = '100%';
        pdiv.style.top = '0';
        pdiv.style.left = '0';
        pdiv.style.position = 'absolute';
        document.body.appendChild(pdiv);
    } 
        
        cridaiposa('/' + pag,'contenidor_missatge');
    
    
}

function posaDivAdvertencia()
{
    if (!document.getElementById("tapador"))
    {
        var ndiv = document.createElement('div');
        ndiv.id = 'tapador';
        ndiv.style.height = '100%';
        ndiv.style.width = '100%';
        ndiv.style.position = 'absolute';
        ndiv.style.top = '0';
        ndiv.style.left = '0';
        ndiv.style.backgroundColor = '#ec6e00';
        
            ndiv.style.opacity = '0.6';
            ndiv.style.MozOpacity = '0.6';
            ndiv.style.filter = "alpha(opacity = 60";
        document.body.appendChild(ndiv);   
    }
   
    if (!document.getElementById("contenidor_missatge"))
    {
        var pdiv = document.createElement('div');
        pdiv.id = 'contenidor_missatge';
        pdiv.style.height = '100%';
        pdiv.style.width = '100%';
        pdiv.style.top = '0';
        pdiv.style.left = '0';
        pdiv.style.position = 'absolute';
        document.body.appendChild(pdiv);
    } 
        
        cridaiposa('../contactar.htm','contenidor_missatge');
    
    
}


function tancaDiv()
{
    var obj = document.getElementById('contenidor_missatge');
    document.body.removeChild(obj);
    var obj = document.getElementById('tapador');
    document.body.removeChild(obj);
}



/*************************************************

		AJAX


***************************************************/
		    //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';	
                    //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)
		    {
		        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('POST',pagina,true);
                    repReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    //alert(qstring);
		            repReq.send(qstring);
                }
		    }



