
var rastromigasGoog,  vDesa_Prod_Goog, vInter_Intra_Goog, vDescAplicGoog, blnExistevAplicGoog, arrPagsGoog, intUltItemGoog, vItemArrURLGoog, vRegistrarNoIdentifGoog, vRegistrarGoog, vCuentaGoog;
var cCuentaGoogInter = "UA-6474630-1";
var cCuentaGoogIntra = "UA-11223949-1";
var cCuentaGoogDesa  = "UA-11097605-1";

	vDesa_Prod_Goog = "Desarrollo";
	//vDesa_Prod_Goog = "Produccion";
		
	vInter_Intra_Goog = "Internet";
	//vInter_Intra_Goog = "Intranet";
	
	if (vDesa_Prod_Goog == "Desarrollo"){
		vCuentaGoog = cCuentaGoogDesa;
		}
	else{
		if(vInter_Intra_Goog == "Intranet"){
			vCuentaGoog = cCuentaGoogIntra;
		}
		else{
			vCuentaGoog = cCuentaGoogInter;
		}
	}

	vDescAplicGoog = "";			// Identificador de la aplicación			
	vItemArrURLGoog = 1;			// Tomar el último elemento del path (1), el precedente (2), etc.
	vRegistrarNoIdentifGoog = true;	// Registrar o no los accesos a páginas que no están en la relación dentro del js específico

	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

	blnExistevAplicGoog = false;
	try {									//Puede que vAplicGoogle no exista
		if(vAplicGoogle.length > 3) {		// Si desde la pág llamante se indica que existe un fich. con un array de págs clasificadas...
			blnExistevAplicGoog = true;	//blnExistevAplicGoog se usa después. Se trae un fich. específico de cada aplic. Ej.  /inc/estadisticas/SGPS.js
			document.write(unescape("%3Cscript src='/inc/estadisticas/" + vAplicGoogle + ".js' type='text/javascript'%3E%3C/script%3E"));
			switch(vAplicGoogle) {
				case "IFWB":
					vRegistrarNoIdentifGoog = false;	//Se descartan muchas páginas que darían resultados aumentados erróneamente
					break;
				case "SCPF":
					vItemArrURLGoog = 2;
					break;
			}
		}
	} catch(err) {}
	

function fClasificPagina(vPagina){	//Buscar la pag recibida en el array específico de esa aplicación y ver a qué parte corresponde
	var intI, strPaginaUC, strReturn = "";

	fCrearArrayGoogle();	//Esta función está en cada fich. con array de cada aplic. Ej.  /inc/estadisticas/SGPS.js
	strPaginaUC = vPagina.toUpperCase();
	for (intI=0; intI <= intUltItemGoog; intI++) {
		if (arrPagsGoog[intI][0] == strPaginaUC) {
			strReturn = arrPagsGoog[intI][1];
			intI = intUltItemGoog + 1;
		} 
	} 
	return strReturn;
}

function fpageTracker(vAplicacion, vInterIntra, vIdioma, vPagina){
/* Puede recibir 1 solo parametro con todo (en vAplicacion) o 4 parámetros.  vAplicacion y vInterIntra en general se pasan vacíos y se usan los de este script y del fichero
 aplic.js específico, vPagina se busca en el array de cada aplic y si no se encuentra, se usa el parámetro recibido*/

	var intI, vDescAplicTracker, vInter_Intra_Tracker, vIdiomTracker, vTexto_A_Buscar, vPagTracker;

	vRegistrarGoog = true;			// En esta llamada se va a registrar algo
		
	/* Si se recibe 1 solo parámetro con todo */
	if (arguments.length < 2) {
		rastromigasGoog = vAplicacion;	
	}
	
	/* Si se reciben 4 parámetros     INI */
	if (arguments.length > 3) {

		/* aplicación */
		vDescAplicTracker = vAplicacion;
		if (vAplicacion.length < 1 && vDescAplicGoog.length > 1){
			vDescAplicTracker = vDescAplicGoog;
		}
		
	/* Internet-intranet */
		vInter_Intra_Tracker = vInterIntra;
		if (vInterIntra.length < 1){
			vInter_Intra_Tracker = vInter_Intra_Goog;
		}
	
	/* Idioma */
		switch(vIdioma.toLowerCase()) {
			case "eus":
			case "eu":
				vIdiomTracker = "eu_EU";
				break;
			case "ing":
			case "in":
			case "en":
				vIdiomTracker = "en_EN";
				break;
			case "fr":
				vIdiomTracker = "fr_FR";
				break;
			case "eu_es":
				vIdiomTracker = "eu_ES";
				break;
			default:
				vIdiomTracker = "es_ES";
		}

	/* Parte de la aplicación o página */		
		var arrPartesUrl = vPagina.split("/");	//Se puede recibir o nombre pag o ServerVariables("URL"), en cuyo caso se trocea por /
		vPagTracker = "";
		vTexto_A_Buscar = "";
		for(intI = 0; intI < vItemArrURLGoog; intI++){ 				// Se "retrocede" en el array tanto como se solicita (vItemArrURLGoog) y se va probando si existe item hacia el final
			if (arrPartesUrl.length - vItemArrURLGoog + intI >= 0){ 
				vTexto_A_Buscar = arrPartesUrl[arrPartesUrl.length - vItemArrURLGoog + intI];
				intI = vItemArrURLGoog + 1;
			}
		}
				
		if(blnExistevAplicGoog) { // Si nos indican que busquemos la asociación página-parte de la aplic en el array de la aplic
			vPagTracker = fClasificPagina(vTexto_A_Buscar);
		}
		
		if(vPagTracker.length < 1){				// Si no se ha podido clasificar
			if (vRegistrarNoIdentifGoog){
				vPagTracker = vTexto_A_Buscar;	// Se registra con el texto a buscar (lo recibido como parámetro)
			}
			else {
				vRegistrarGoog = false;			// No se registra			
			}
		}
		
		/* Se monta todo */	
		rastromigasGoog = "/" + vDescAplicTracker + "/" + vInter_Intra_Tracker + "/" + vIdiomTracker + "/" + vPagTracker;
	}
	/* Si se reciben 4 parámetros     FIN */

	
	/*   BORRAR ******************************************************  */
	//if (vAplicGoogle == "SCPF"){
	//	vRegistrarGoog = false;
	//}
	/*   BORRAR ******************************************************  */
	
		
	var blnRegistrarEnDesarrollo;
	blnRegistrarEnDesarrollo = true;
	
	/* Registrar acceso */	
	if(vRegistrarGoog){
		if (vDesa_Prod_Goog == "Desarrollo" && !blnRegistrarEnDesarrollo){
			alert(rastromigasGoog);
		}
		else{
			try {
				var pageTracker = _gat._getTracker(vCuentaGoog);
				pageTracker._trackPageview(rastromigasGoog);
			} catch(err) {}
		}
	}
	
	/* Fin */	
}
