// JavaScript Document FUNCIONES
NS4 = document.layers;
IE 	= document.all;
intra = 5; intra2=5; intra1 = 5;
var objectpop=null; //Arrastrar capas. Capa mensaje + su capa de fondo. Siempre por parejas
var objectpopfondo=null; 
function IncioContador() { RightNow = new Date(); StartPoint = RightNow.getTime();}
function StartTheCount() { 
	var RightNow2 = new Date(); var CurrentTime = RightNow2.getTime();  var timeDifference = CurrentTime - StartPoint; 
    this.DifferenceInSeconds = timeDifference/1000; return(this.DifferenceInSeconds); 
} 
function TheSeconds() { 
    var SecCounts = StartTheCount(); var SecCounts1 = " "+SecCounts; 
    SecCounts1= SecCounts1.substring(0,SecCounts1.indexOf(".")) + " seconds"; 
	if (DifferenceInSeconds >= 4){
		for (i=1;i<=6;i=i+1){ 
			capa = "menu" + i;
			hideLayer (capa);
			RightNow = new Date();
			StartPoint = RightNow.getTime();
			DifferenceInSeconds= 0; }
		}
	else { window.setTimeout('TheSeconds()',1000);}
}
function writeLayer(capa, codigo) {
	  if (IE) document.all[capa].innerHTML = codigo;
	else if (NS4){
		document.layers[capa].document.open();
		document.layers[capa].document.write(codigo);
		document.layers[capa].document.close();
	  } else document.getElementById(capa).innerHTML = codigo;
}
function hideLayer(capa) { var objPopUp = document.getElementById(capa); objPopUp.style.visibility = 'hidden'; objPopUp = null; }
function showLayer(capa) { var objPopUp = document.getElementById(capa); objPopUp.style.visibility = 'visible';}
function menurevista (menu) { for (i=1;i<=6;i=i+1){ capa = "menu" + i; hideLayer (capa); } showLayer (menu); }
function barraestado(){	window.status="";}
function getxmlhttp (){
	var xmlhttp = false;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	} catch (E) {xmlhttp = false;}}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {	xmlhttp = new XMLHttpRequest();	}
	return xmlhttp;
}
function processajax (serverPage, objID, GetPostNull, str){
		xmlhttp = getxmlhttp ();
		switch (GetPostNull){
			case 'confirmar': 
				xmlhttp = getxmlhttp ();
				xmlhttp.open("POST", serverPage, true);
				xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
				xmlhttp.onreadystatechange = function() { 
					if (xmlhttp.readyState == 4 ) { 
						textsortida = xmlhttp.responseText;	opcio=textsortida.split("-*-"); //alert(textsortida);
						switch(opcio[0]){
							case "comentarisafegir": pagina='comentaris.php?id='+opcio[1]+'&idveure='+opcio[2]; processajax (pagina,opcio[2],'post','');  break;
						}
					}
				} 
			break;
			case 'post':
				var obj = document.getElementById(objID); obj.innerHTML='Un moment sius plau';
				xmlhttp = getxmlhttp ();
				xmlhttp.open("POST", serverPage, true);
				xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
				xmlhttp.onreadystatechange = function() {	if (xmlhttp.readyState == 4 ) {	obj.innerHTML = xmlhttp.responseText;}}
			break;
		}
		xmlhttp.send(str); intra=6;
	}
function getformvalues (theform, valfunc){
	var str = "";	aok = true;		var val;
		fobj = document.getElementById(theform);
		//Recorrer la lista de todos los objetos que contiene el formulario.
		for(var i = 0; i < fobj.elements.length; i++){
			if(valfunc) {
				if (aok == true){
					val = valfunc (fobj.elements[i].value,fobj.elements[i].name); 
					if (val == false){	aok = false;}
				}
			}
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
		}
		return str;
	}
	function trim(inputString) {
	   // Elimina los espacios iniciales y finales de la cadena que recibe. Tambi�n elimina
	   // espacios consecutivos y los sustituye por uno solo. Si se recibe algo que no sea una 
	   //cadena (null, objeto personalizado, ...), devuelve la entrada.
	   if (typeof inputString != "string") { return inputString; }
	   var retValue = inputString;
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") { // Busca espacios al principio de la cadena
	      retValue = retValue.substring(1, retValue.length);
	      ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Busca espacios al final de la cadena
	      retValue = retValue.substring(0, retValue.length-1);
	      ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   while (retValue.indexOf("  ") != -1) { // Comprueba si hay espacios consecutivos
	      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	   }
	   return retValue; // Devuelve la cadena sin espacios
	} // Final de la funci�n "trim"
function setStatus (theStatus, theObj){	obj = document.getElementById(theObj); if (obj){obj.innerHTML = theStatus;	}}
function recargar(){ location.reload();}


