function Is() {
	var agent = navigator.userAgent.toLowerCase();
	
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	
	this.ns = ((agent.indexOf('mozilla') != -1) && (agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1) && (agent.indexOf('opera') == -1) && (agent.indexOf('webtv') == -1));
	this.ns2 = (this.ns && (this.major == 2));
	this.ns3 = (this.ns && (this.major == 3));
	this.ns4 = (this.ns && (this.major == 4));
	this.ns6 = (this.ns && (this.major >= 5));
	
	this.opera = (agent.indexOf("opera") != -1);
	this.opera5 = (this.opera && (agent.indexOf("msie 6") != -1));
	
	this.ie = (agent.indexOf("msie") != -1) && ! this.opera;
	this.ie3 = (this.ie && (this.major < 4));
	this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5") == -1 && agent.indexOf("msie 6") == -1));
	this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5") != -1));
	this.ie6 = (this.ie && (this.major == 4) && (agent.indexOf("msie 6") != -1));
	this.ie7 = (this.ie && (this.major == 4) && (agent.indexOf("msie 7") != -1));
	this.ieX = (this.ie && !this.ie3 && !this.ie4);
	
	this.win = (agent.indexOf("win")!= -1);
	this.mac = (agent.indexOf("mac")!= -1);
	this.unix = (agent.indexOf("x11")!= -1);
}

function fnResize_iFrames() {
	var is = new Is(); // Create a browser detection object
	
	obj_body = document.body;
	
	if (is.ie7)  {
		height_ventana = document.documentElement.offsetHeight - 12;
	}else if (document.all) {
		height_ventana = obj_body.offsetHeight;
	} else if (document.getElementById) {
		height_ventana = window.innerHeight;
	} else return;
	
	// Altura mínima del Contenido
	height_minimal = 335;
	
	// Altura del contenido
	height_contenido = obj_body.scrollHeight
	
	// Altura donde empieza el pie
	obj_ImagenPos = new ImgObj("posframesRLGV");
	top_piepagina = obj_ImagenPos.y;
	
	height_piepagina = (height_contenido - top_piepagina);
	
	// Índices???
	obj_indice = new DivObj("indextree");
	if (obj_indice.obj) {
		top_objeto = obj_indice.y;
		height_objeto = (height_ventana - (height_piepagina + top_objeto));
		
		if (height_objeto < height_minimal) height_objeto = height_minimal;
		
		if (document.all) {
			document.all("indextree").style.height = (height_objeto - 18) + "px";
			//document.all("indextree").style.overflow = 'auto';
		} else if (document.getElementById) {
			document.getElementById("indextree").style.height = '280px';
			document.getElementById("indextree").style.height = (height_objeto - 21) + 'px';
			//document.getElementById("indextree").style.overflow = 'auto';
		}
		
		height_contenido = obj_body.scrollHeight;
	}
	// Índice Busqueda???
	obj_indice = new DivObj("indextreeSearch");
	if (obj_indice.obj) {
		top_objeto = obj_indice.y;
		height_objeto = (height_ventana - (height_piepagina + top_objeto));
		
		if (height_objeto < height_minimal) height_objeto = height_minimal;
		
		if (document.all) {
			document.all("indextreeSearch").style.height = (height_objeto - 18) + "px";
			//document.all("indextree").style.overflow = 'auto';
		} else if (document.getElementById) {
			document.getElementById("indextreeSearch").style.height = '280px';
			document.getElementById("indextreeSearch").style.height = (height_objeto - 21) + 'px';
			//document.getElementById("indextree").style.overflow = 'auto';
		}
		
		height_contenido = obj_body.scrollHeight;
	}

	obj_desarrollo = new DivObj("desarrollo");
	if (obj_desarrollo.obj) {
		top_objeto = obj_desarrollo.y;
		height_objeto = (height_ventana - (height_piepagina + top_objeto));
		
		if (height_objeto < height_minimal) height_objeto = height_minimal;
		
		if (document.all) {
			document.all("desarrollo").style.height = (height_objeto - 18) + "px";
			//document.all("desarrollo").style.overflow = 'auto';
		} else if (document.getElementById) {
			document.getElementById("desarrollo").style.height = '280px';
			document.getElementById("desarrollo").style.height = (height_objeto - 20) + 'px';
			// document.getElementById("desarrollo").style.overflow = 'auto';
		}
		
		height_contenido = obj_body.scrollHeight;
	}
	
	obj_normal = new DivObj("layerToResize");
	if (obj_normal.obj) {
		top_objeto = obj_normal.y;
		height_objeto = (height_ventana - (height_piepagina + top_objeto));
		
		if (height_objeto < height_minimal) height_objeto = height_minimal;
		
		if (document.all) {
			document.all("layerToResize").style.height = (height_objeto - 12) + "px";
			//document.all("layerToResize").style.overflow = 'auto';
		}else if (document.getElementById) {
			document.getElementById("layerToResize").style.height = '280px';
			document.getElementById("layerToResize").style.height = (height_objeto - 20) + 'px';
			//document.getElementById("layerToResize").style.overflow = 'auto';
		}
		
		height_contenido = obj_body.scrollHeight;
		//window.status = top_objeto + ":" + top_piepagina + "---" + height_contenido + "-" + (top_objeto+obj_normal.h+height_piepagina+3);
	}
}

function fnResize_PopUp() {
	fnCenterWindow();
	
	obj_body = document.body;
	
	if (document.all) height_ventana = obj_body.offsetHeight;
	else if (document.getElementById) height_ventana = window.innerHeight;
	else return;
	
	obj_ventananueva = new DivObj("ventananueva");
	if (obj_ventananueva.obj) {
		top_objeto = obj_ventananueva.y;
		height_objeto = height_ventana - top_objeto - 13;
		
		if (document.all) document.all("ventananueva").style.height = (height_objeto) + "px";
		else if (document.getElementById) document.getElementById("ventananueva").style.height = (height_objeto) + "px";
	}
}

function fnCenterWindow() {
	var browseWidth, browseHeight;
	
	if (document.layers){
		browseWidth=window.outerWidth;
		browseHeight=window.outerHeight;
	}else if (document.all){
		browseWidth=document.body.clientWidth;
		browseHeight=document.body.clientHeight;
		
		scrWidth = window.screen.availWidth;
		scrHeight = window.screen.availHeight;
		
		newPosX = parseInt((scrWidth - browseWidth) / 2);
		newPosY = parseInt((scrHeight - browseHeight) / 2);
		
		window.moveTo(newPosX, newPosY);
		
	}else if (document.getElementById) {
		browseWidth=window.outerWidth;
		browseHeight=window.outerHeight;
	}else{
		return false;
	}
}

/******************************************
* Find In Page Script -- Submitted/revised by Alan Koontz (alankoontz@REMOVETHISyahoo.com)
* Visit Dynamic Drive (http://www.dynamicdrive.com/) for full source code
* This notice must stay intact for use
******************************************/

// revised by Alan Koontz -- May 2003

var TRange = null;
var dupeRange = null;
var TestRange = null;
var win = null;

// SELECTED BROWSER SNIFFER COMPONENTS DOCUMENTED AT
// http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html

var nom = navigator.appName.toLowerCase();
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie = (agt.indexOf("msie") != -1);
var is_ie4up = (is_ie && (is_major >= 4));
var is_not_moz = (agt.indexOf('netscape')!=-1);
var is_nav = (nom.indexOf('netscape')!=-1);
var is_nav4 = (is_nav && (is_major == 4));
var is_mac = (agt.indexOf("mac")!=-1);
var is_gecko = (agt.indexOf('gecko') != -1);
var is_opera = (agt.indexOf("opera") != -1);

// GECKO REVISION
var is_rev=0;
if (is_gecko) {
	temp = agt.split("rv:");
	is_rev = parseFloat(temp[1]);
}

function fnUserRLGVDisposition_Search(whichform, whichframe, language) {
	// TEST FOR IE5 FOR MAC (NO DOCUMENTATION)
	if (is_ie4up && is_mac) return;
	
	// TEST FOR NAV 6 (NO DOCUMENTATION)
	if (is_gecko && (is_rev <1)) return;
	
	// TEST FOR Opera (NO DOCUMENTATION)
	if (is_opera) return;
	
	// INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES
	if (whichform.findthis.value != null && whichform.findthis.value != '') {
		str = whichform.findthis.value;
		win = whichframe;
		var frameval=false;
		if(win!=self) {
			frameval=true; // this will enable Nav7 to search child frame
			win = parent.frames[whichframe];
		}
	}else return; // i.e., no search string was entered
	
	var strFound;
	
	// NAVIGATOR 4 SPECIFIC CODE
	if(is_nav4 && (is_minor < 5)) {
		strFound=win.find(str); // case insensitive, forward search by default
		// There are 3 arguments available:
		// searchString: type string and it's the item to be searched
		// caseSensitive: boolean -- is search case sensitive?
		// backwards: boolean --should we also search backwards?
		// strFound=win.find(str, false, false) is the explicit
		// version of the above
		// The Mac version of Nav4 has wrapAround, but
		// cannot be specified in JS
	}
	
	// NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)
	if (is_gecko && (is_rev >= 1)) {
		if(frameval!=false) win.focus(); // force search in specified child frame
		strFound=win.find(str, false, false, true, false, frameval, false);
		
		// The following statement enables reversion of focus 
		// back to the search box after each search event 
		// allowing the user to press the ENTER key instead
		// of clicking the search button to continue search.
		// Note: tends to be buggy in Mozilla as of 1.3.1
		// (see www.mozilla.org) so is excluded from users 
		// of that browser.
		
		if (is_not_moz) whichform.findthis.focus();
		
		// There are 7 arguments available:
		// searchString: type string and it's the item to be searched
		// caseSensitive: boolean -- is search case sensitive?
		// backwards: boolean --should we also search backwards?
		// wrapAround: boolean -- should we wrap the search?
		// wholeWord: boolean: should we search only for whole words
		// searchInFrames: boolean -- should we search in frames?
		// showDialog: boolean -- should we show the Find Dialog?
	}
	
	if (is_ie4up) {
		// EXPLORER-SPECIFIC CODE revised 5/21/03
		if (TRange!=null) {
			TestRange=win.document.body.createTextRange();
			if (dupeRange.inRange(TestRange)) {
				TRange.collapse(false);
				strFound=TRange.findText(str);
				if (strFound) {
					//the following line added by Mike and Susan Keenan, 7 June 2003
					if (TRange.offsetTop > 0) {
						win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
						TRange.select();
					}else{
						fnUserRLGVDisposition_Search(whichform, whichframe, language);
					}
				}
			}else {
				TRange=win.document.body.createTextRange();
				TRange.collapse(false);
				strFound=TRange.findText(str);
				if (strFound) {
					//the following line added by Mike and Susan Keenan, 7 June 2003
					if (TRange.offsetTop > 0) {
						win.document.body.scrollTop = TRange.offsetTop;
						TRange.select();
					}else{
						fnUserRLGVDisposition_Search(whichform, whichframe, language);
					}
				}
			}
		}
		
		if (TRange==null || strFound==0) {
			TRange=win.document.body.createTextRange();
			dupeRange = TRange.duplicate();
			strFound = TRange.findText(str);
			if (strFound) {
				//the following line added by Mike and Susan Keenan, 7 June 2003
				win.document.body.scrollTop = TRange.offsetTop;
				if (TRange.offsetTop > 0) {
					TRange.select();
				}
			}
		}
	}
	
	if (!strFound) {
		switch(language) {
			case 0:
			case "0":
				alert ("Cadena '"+str+"' no encontrada!") // string not found
				break;
			case 1:
			case "1":
				alert ("Cadena '"+str+"' no trobada!") // string not found
				break;
		}
	}	
}

function fnUserRLGV_IndexSearch(whichform, whichlayer, language) {
	// TEST FOR IE5 FOR MAC (NO DOCUMENTATION)
	if (is_ie4up && is_mac) return;
	
	// TEST FOR NAV 6 (NO DOCUMENTATION)
	if (is_gecko && (is_rev <1)) return;
	
	// TEST FOR Opera (NO DOCUMENTATION)
	if (is_opera) return;
	
	// INITIALIZATIONS FOR FIND-IN-PAGE SEARCHES
	if (whichform.findthis.value != null && whichform.findthis.value != '') {
		str = whichform.findthis.value;
		win = whichlayer;
		var frameval=false;
		if(win != self) {
			frameval = true; // this will enable Nav7 to search child frame
			win = document.all(whichlayer); //parent.frames[whichframe];
		}
	}else return; // i.e., no search string was entered
	
	var strFound;
	
	// NAVIGATOR 4 SPECIFIC CODE
	if(is_nav4 && (is_minor < 5)) {
		strFound=win.find(str); // case insensitive, forward search by default
		// There are 3 arguments available:
		// searchString: type string and it's the item to be searched
		// caseSensitive: boolean -- is search case sensitive?
		// backwards: boolean --should we also search backwards?
		// strFound=win.find(str, false, false) is the explicit
		// version of the above
		// The Mac version of Nav4 has wrapAround, but
		// cannot be specified in JS
	}
	
	// NAVIGATOR 7 and Mozilla rev 1+ SPECIFIC CODE (WILL NOT WORK WITH NAVIGATOR 6)
	if (is_gecko && (is_rev >= 1)) {
		if(frameval!=false) win.focus(); // force search in specified child frame
		strFound=win.find(str, false, false, true, false, frameval, false);
		
		// The following statement enables reversion of focus 
		// back to the search box after each search event 
		// allowing the user to press the ENTER key instead
		// of clicking the search button to continue search.
		// Note: tends to be buggy in Mozilla as of 1.3.1
		// (see www.mozilla.org) so is excluded from users 
		// of that browser.
		
		if (is_not_moz) whichform.findthis.focus();
		
		// There are 7 arguments available:
		// searchString: type string and it's the item to be searched
		// caseSensitive: boolean -- is search case sensitive?
		// backwards: boolean --should we also search backwards?
		// wrapAround: boolean -- should we wrap the search?
		// wholeWord: boolean: should we search only for whole words
		// searchInFrames: boolean -- should we search in frames?
		// showDialog: boolean -- should we show the Find Dialog?
	}
	
	if (is_ie4up) {
		// EXPLORER-SPECIFIC CODE revised 5/21/03
		if (TRange!=null) {
			TestRange=win.document.body.createTextRange();
			if (dupeRange.inRange(TestRange)) {
				TRange.collapse(false);
				strFound=TRange.findText(str);
				if (strFound) {
					//the following line added by Mike and Susan Keenan, 7 June 2003
					win.document.body.scrollTop = win.document.body.scrollTop + TRange.offsetTop;
					TRange.select();
				}
			}else {
				TRange=win.document.body.createTextRange();
				TRange.collapse(false);
				strFound=TRange.findText(str);
				if (strFound) {
					//the following line added by Mike and Susan Keenan, 7 June 2003
					win.document.body.scrollTop = TRange.offsetTop;
					TRange.select();
				}
			}
		}
		
		if (TRange==null || strFound==0) {
			TRange=win.document.body.createTextRange();
			dupeRange = TRange.duplicate();
			strFound=TRange.findText(str);
			if (strFound) {
				//the following line added by Mike and Susan Keenan, 7 June 2003
				win.document.body.scrollTop = TRange.offsetTop;
				TRange.select();
			}
		}
	}
	
	if (!strFound) {
		switch(language) {
			case 0:
			case "0":
				alert ("Cadena '"+str+"' no encontrada!") // string not found
				break;
			case 1:
			case "1":
				alert ("Cadena '"+str+"' no trobada!") // string not found
				break;
		}
	}
}

// -->

function fnUserRLGVSearch_Equalizer(objSelect, destinationName) {
	objForm = objSelect.form;
	
	if (objForm) {
		objForm_field = false;
		for (i=0; i < objForm.elements.length; i++) {
			if (objForm.elements[i].name == destinationName) {
				objForm_field = objForm.elements[i];
			}
		}
		
		if (objForm_field) {
			for(i=0; i<objForm_field.options.length; i++) {
				if (objForm_field.options[i].value == objSelect.options[objSelect.selectedIndex].value) {
					objForm_field.options[i].selected = true;
				}
			}
		}
	}
}

var intLineAssistant_Number = 0;
var objDivAssistant = false;

function fnUserRLGVSearch_assistant(objLink, intLineNumber) {
	objForm = document.forms["frm-user-rlgv-pi-search"];
	if (objForm) {
		objForm_field = '';
		objForm_value = '';
		for (i=0; i < objForm.elements.length; i++) {
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineNumber+'][field]') {
				objForm_field = objForm.elements[i];
			}
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineNumber+'][value]') {
				objForm_value = objForm.elements[i];
			}
		}
		
		// Posicionamos la capa
		xPosition = 0;
		yPosition = 0;
		addToTop = 0;
		
		objLayerToResize = new DivObj("layerToResize");
		if (objLayerToResize) {
			if (document.getElementById) {
				xPosition = objLayerToResize.x;
				yPosition = objLayerToResize.y;
			}else if (document.all){
				xPosition = objLayerToResize.obj.scrollLeft;
				yPosition = objLayerToResize.obj.scrollBottom;
			}
		
			objIcon = new AnyObj(objLink);
			xPosition = (objIcon.x + 20);
			yPosition = (objIcon.y - yPosition);
			
			xPosition += 'px';
			yPosition += 'px';
		}
		
		// Si algo esta abierto, lo cerramos
		if (objDivAssistant) {
			objDivAssistant.SetVisibility('off');
			objDivAssistant = false;
		}
		
		// Abrimos en funcion de los seleccionado
		if (objForm_field && objForm_value) {
			switch(objForm_field.value) {
				case "number":
					/*
					objDivAssistant = new DivObj("user_rlgv_pi_search_DivInterval");
					objIcon = new ImgObj("asistente"+intLineNumber);
					objDivAssistant.SetVisibility('on');
					objDivAssistant.SetPosition(objIcon.x + initX, objIcon.y + initY);
					intLineAssistant_Number = intLineNumber;
					*/
					break;
				case "date":
				case "publicationdate":
					objDivAssistant = new DivObj("user_rlgv_pi_search_DivCalendar");
					objDivAssistant.SetVisibility('on');
					objDivAssistant.SetPosition(xPosition, yPosition);
					intLineAssistant_Number = intLineNumber;
					break;
				case "desctematicos":
				case "descpropios":
				case "desctoponimicos":
					
					// Oculto, si existen, los selectores de descriptores
					objDivAssistantTesauro = new DivObj("desctematicosAssistant");
					if (objDivAssistantTesauro) objDivAssistantTesauro.css.display = 'none';
					objDivAssistantTesauro = new DivObj("descpropiosAssistant");
					if (objDivAssistantTesauro) objDivAssistantTesauro.css.display = 'none';
					objDivAssistantTesauro = new DivObj("desctoponimicosAssistant");
					if (objDivAssistantTesauro) objDivAssistantTesauro.css.display = 'none';
								
					// Hago visible el tesauro seleccionado
					objDivAssistantTesauro = new DivObj(objForm_field.value + "Assistant");
					if (objDivAssistantTesauro) objDivAssistantTesauro.css.display = 'block';
					
					objDivAssistant = new DivObj("user_rlgv_pi_search_DivTesauros");
					objDivAssistant.SetVisibility('on');
					objDivAssistant.SetPosition(xPosition, yPosition);
					intLineAssistant_Number = intLineNumber;
					
					
					frmAssistant = document.forms['frmUserRLGVSearch_Tesauros'];
					if (frmAssistant) {
						for (i=0; i < frmAssistant.elements.length; i++) {
							if (frmAssistant.elements[i].id == 'frmUserRLGVSearch_Tesauros_' + objForm_field.value) {
								frmAssistant.elements[i].style.background = "#FFFFFF";
								frmAssistant.elements[i].disabled = false;
							}else{
								frmAssistant.elements[i].style.background = "#DEDEDE";
								frmAssistant.elements[i].disabled = true;
							}
							for (line=0; line < frmAssistant.elements[i].options.length; line++) {
								frmAssistant.elements[i].options[line].selected = false;
							}
						}
					}
					
					break;
				default:
					break;
			}
		}
	}
}

function fnUserRLGVSearch_info(objLink, intLineNumber) {
	objForm = document.forms["frm-user-rlgv-pi-search"];
	
	if (objForm) {
		objForm_field = '';
		objForm_value = '';
		for (i=0; i < objForm.elements.length; i++) {
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineNumber+'][field]') {
				objForm_field = objForm.elements[i];
			}
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineNumber+'][value]') {
				objForm_value = objForm.elements[i];
			}
		}
		
		if (objForm_field) {
			objForm = document.forms["frmUserRLGVSearch_info"];
			if (objForm && objForm_field.value != '') {
				objForm.elements["user_rlgv_pi_notesviewer[infoType]"].value = objForm_field.value;
				infoWin = window.open('about:blank', 'infoWin', 'width=500,height=400,status=0,menubar=0,scrollbars=1,resizable=0');
				objForm.submit();
				infoWin.focus();
				
			}
			
		}
	}
}

function fnUserRLGVSearch_ExitDiv(divName) {
	objDivAssistant = new DivObj(divName);
	objDivAssistant.SetVisibility('off');
}

function fnUserRLGVSearch_changeAssitantIcon(objSelect, intLineNumber, intStyle, strAltText) {
	
	icosPath = 'typo3conf/ext/user_rlgv/pi_search/res/';
	
	selectType = objSelect.options[objSelect.selectedIndex].value;
	
	objImgAssistant = new ImgObj("asistente"+intLineNumber);
	
	if (objImgAssistant) {
		switch(selectType) {
			case "date":
			case "publicationdate":
				objImgAssistant.SetSrc(icosPath + 'ico_asistfecha_'+intStyle+'.gif');
				objImgAssistant.obj.title = strAltText;
				break;
			/*case "number":
				objImgAssistant.SetSrc(icosPath + 'ico_asistintervalo_'+intStyle+'.gif');
				break;*/
			/*case "type":
			case "origin":
				alert("Ieee una lista");
				break;*/
			case "desctematicos":
			case "descpropios":
			case "desctoponimicos":
				objImgAssistant.SetSrc(icosPath + 'ico_asistintervalo_'+intStyle+'.gif');
				objImgAssistant.obj.title = strAltText;
				break;
			default:
				objImgAssistant.SetSrc(icosPath + 'ico_noasistente.gif');
				objImgAssistant.obj.title = '';
		}
	}else{
		alert("error");
	}
}

var fnUserRLGVSearch_DateArray = new Array;
fnUserRLGVSearch_DateArray[0] = new Array;
fnUserRLGVSearch_DateArray[1] = new Array;
// Castellano
fnUserRLGVSearch_DateArray[0][0]=new Option("Enero",31);
fnUserRLGVSearch_DateArray[0][1]=new Option("Febrero",28);
fnUserRLGVSearch_DateArray[0][2]=new Option("Marzo",31);
fnUserRLGVSearch_DateArray[0][3]=new Option("Abril",30);
fnUserRLGVSearch_DateArray[0][4]=new Option("Mayo",31);
fnUserRLGVSearch_DateArray[0][5]=new Option("Junio",30);
fnUserRLGVSearch_DateArray[0][6]=new Option("Julio",31);
fnUserRLGVSearch_DateArray[0][7]=new Option("Agosto",31);
fnUserRLGVSearch_DateArray[0][8]=new Option("Septiembre",30);
fnUserRLGVSearch_DateArray[0][9]=new Option("Octubre",31);
fnUserRLGVSearch_DateArray[0][10]=new Option("Noviembre",30);
fnUserRLGVSearch_DateArray[0][11]=new Option("Diciembre",31);
// Valenciano
fnUserRLGVSearch_DateArray[1][0]=new Option("Gener",31);
fnUserRLGVSearch_DateArray[1][1]=new Option("Febrer",28);
fnUserRLGVSearch_DateArray[1][2]=new Option("Març",31);
fnUserRLGVSearch_DateArray[1][3]=new Option("Abril",30);
fnUserRLGVSearch_DateArray[1][4]=new Option("Maig",31);
fnUserRLGVSearch_DateArray[1][5]=new Option("Juny",30);
fnUserRLGVSearch_DateArray[1][6]=new Option("Juliol",31);
fnUserRLGVSearch_DateArray[1][7]=new Option("Agost",31);
fnUserRLGVSearch_DateArray[1][8]=new Option("Setembre",30);
fnUserRLGVSearch_DateArray[1][9]=new Option("Octubre",31);
fnUserRLGVSearch_DateArray[1][10]=new Option("Novembre",30);
fnUserRLGVSearch_DateArray[1][11]=new Option("Decembre",31);

var fnUserRLGVSearch_DaysArray = new Array;

function fnUserRLGVSearchCalendar(frmName, uniquename, disabled, language) {
	objForm = document.forms[frmName];
	
	if(language == '') language = 0;
	
	statusDisabled = '';
	if (disabled) {
		statusDisabled = 'disabled';
	}
	
	document.writeln('<table cellpadding="0" cellspacing="1" border="0">');
		document.writeln('<tr>');
			document.writeln("<td><SELECT " + statusDisabled + " name=\"days"+uniquename+"\"></SELECT></td>");
			document.writeln("<td>");
				document.writeln("<SELECT " + statusDisabled + " name=\"months"+uniquename+"\" onchange=\"fnUserRLGVSearchCalendar_UpdateDays(this.form, '"+uniquename+"', "+language+")\">");
					for(x=0;x<12;x++) {
						document.writeln("<OPTION value=\""+x+"\">"+fnUserRLGVSearch_DateArray[language][x].text);
					}
				document.writeln("</SELECT>");
			document.writeln("</td>");
			
			document.writeln("<td>");
				document.writeln("<SELECT " + statusDisabled + " name=\"years"+uniquename+"\" onchange=\"fnUserRLGVSearchCalendar_UpdateDays(this.form, '"+uniquename+"', "+language+")\">")
					for(x=1982;x<2101;x++) {
						document.writeln("<OPTION value=\""+x+"\">"+x);
					}
				document.writeln("</SELECT>");
			document.writeln("</td>");
		document.writeln('</tr>');
	document.writeln('</table>');
	
	fnUserRLGVSearchCalendar_UpdateDays(objForm, uniquename, language);
}

function fnUserRLGVSearchCalendar_SelectType(objSelect, uniquename_init, uniquename_end) {
	objForm = objSelect.form;
	
	objForm_days_init = false;
	objForm_months_init = false;
	objForm_years_init = false;
	objForm_days_end = false;
	objForm_months_end = false;
	objForm_years_end = false;
	for (i=0; i < objForm.elements.length; i++) {
		if (objForm.elements[i].name == 'days'+uniquename_init) {
			objForm_days_init = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'months'+uniquename_init) {
			objForm_months_init = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'years'+uniquename_init) {
			objForm_years_init = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'days'+uniquename_end) {
			objForm_days_end = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'months'+uniquename_end) {
			objForm_months_end = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'years'+uniquename_end) {
			objForm_years_end = objForm.elements[i];
		}
	}
	
	switch(objSelect.value) {
		case "en":
		case "hasta":
		case "desde":
			objForm_days_init.disabled = false;
			objForm_months_init.disabled = false;
			objForm_years_init.disabled = false;
			objForm_days_end.disabled = true;
			objForm_months_end.disabled = true;
			objForm_years_end.disabled = true;
			break;
		case "entre":
			objForm_days_init.disabled = false;
			objForm_months_init.disabled = false;
			objForm_years_init.disabled = false;
			objForm_days_end.disabled = false;
			objForm_months_end.disabled = false;
			objForm_years_end.disabled = false;
			break;
	}
}

function fnUserRLGVSearchCalendar_UpdateDays(objForm, uniquename, language) {
	if(language == '') language = 0;
	
	objForm_days = false;
	objForm_months = false;
	objForm_years = false;
	for (i=0; i < objForm.elements.length; i++) {
		if (objForm.elements[i].name == 'days'+uniquename) {
			objForm_days = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'months'+uniquename) {
			objForm_months = objForm.elements[i];
		}
		if (objForm.elements[i].name == 'years'+uniquename) {
			objForm_years = objForm.elements[i];
		}
	}
	
	temp = objForm_days.selectedIndex;
	for(x=fnUserRLGVSearch_DaysArray.length; x>0; x--) {
		fnUserRLGVSearch_DaysArray[x]=null;
		objForm_days.options[x]=null;
	}
	
	
	
	
	selection = parseInt(objForm_months[objForm_months.selectedIndex].value);
	selection = parseInt(fnUserRLGVSearch_DateArray[language][selection].value);
	
	ret_val = 0;
	if(selection == 28) {
		year=parseInt(objForm_years.options[objForm_years.selectedIndex].value);
		if (year % 4 != 0 || year % 100 == 0 ) {
			ret_val=0;
		} else {
			if (year % 400 == 0) ret_val=1;
			else ret_val=1;
		}
	}
	
	selection = selection + ret_val;
	
	for(x=1;x < selection+1;x++) {
		fnUserRLGVSearch_DaysArray[x-1]=new Option(x, x);
		objForm_days.options[x-1]=fnUserRLGVSearch_DaysArray[x-1];
	} 
	
	if (temp == -1) objForm_days.options[0].selected=true;
	else objForm_days.options[temp].selected=true;
}

function fnUserRLGVSearchCalendar_SubmitForm(frmName, uniquename_init, uniquename_end, divName) {
	objForm = document.forms[frmName];
	
	objForm_daysInit = '';
	objForm_monthsInit = '';
	objForm_yearsInit = '';
	objForm_daysEnd = '';
	objForm_monthsEnd = '';
	objForm_yearsEnd = '';
	objForm_type = '';
	for (i=0; i < objForm.elements.length; i++) {
		if (objForm.elements[i].name == 'days'+uniquename_init) {
			objForm_daysInit = objForm.elements[i].value;
		}
		if (objForm.elements[i].name == 'months'+uniquename_init) {
			objForm_monthsInit = parseInt(objForm.elements[i].value) + 1;
		}
		if (objForm.elements[i].name == 'years'+uniquename_init) {
			objForm_yearsInit = objForm.elements[i].value;
		}
		if (objForm.elements[i].name == 'days'+uniquename_end) {
			objForm_daysEnd = objForm.elements[i].value;
		}
		if (objForm.elements[i].name == 'months'+uniquename_end) {
			objForm_monthsEnd = parseInt(objForm.elements[i].value) + 1;
		}
		if (objForm.elements[i].name == 'years'+uniquename_end) {
			objForm_yearsEnd = objForm.elements[i].value;
		}
		if (objForm.elements[i].name == 'type') {
			objForm_type = objForm.elements[i].value;
		}
	}
	
	switch(objForm_type) {
		case "en":
			cadenaBusqueda = "En " + objForm_daysInit + "." + objForm_monthsInit + "." + objForm_yearsInit;
			break;
		case "desde":
			cadenaBusqueda = "Desde " + objForm_daysInit + "." + objForm_monthsInit + "." + objForm_yearsInit;
			break;
		case "hasta":
			cadenaBusqueda = "Hasta " + objForm_daysInit + "." + objForm_monthsInit + "." + objForm_yearsInit;
			break;
		case "entre":
			cadenaBusqueda = "Entre " + objForm_daysInit + "." + objForm_monthsInit + "." + objForm_yearsInit + " y " + objForm_daysEnd + "." + objForm_monthsEnd + "." + objForm_yearsEnd;
			break;
	}
	
	objForm = document.forms["frm-user-rlgv-pi-search"];
	
	if (objForm) {
		objForm_value = '';
		for (i=0; i < objForm.elements.length; i++) {
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineAssistant_Number+'][value]') {
				objForm_value = objForm.elements[i];
			}
		}
		
		if (objForm_value && cadenaBusqueda != '') {
			objForm_value.value = cadenaBusqueda;
		}
	}
	
	fnUserRLGVSearch_ExitDiv(divName);
}

function fnUserRLGVSearchInterval_SubmitForm(frmName, divName) {
	objForm = document.forms[frmName];
	cadenaBusqueda = '';
	
	objForm_type = '';
	objForm_desde = '';
	objForm_hasta = '';
	for (i=0; i < objForm.elements.length; i++) {
		if (objForm.elements[i].name == 'type') {
			objForm_type = objForm.elements[i].value;
		}
		if (objForm.elements[i].name == 'desde') {
			objForm_desde = objForm.elements[i].value;
		}
		if (objForm.elements[i].name == 'hasta') {
			objForm_hasta = objForm.elements[i].value;
		}
	}
	alert(objForm_type + ":" + objForm_desde + ":" + objForm_hasta);
	switch(objForm_type) {
		case "en":
			cadenaBusqueda = "En " + objForm_desde;
			break;
		case "desde":
			cadenaBusqueda = "Desde " + objForm_desde;
			break;
		case "hasta":
			cadenaBusqueda = "Hasta " + objForm_desde;
			break;
		case "entre":
			cadenaBusqueda = "Entre " + objForm_desde + " y " + objForm_hasta;
			break;
	}
	
	objForm = document.forms["frm-user-rlgv-pi-search"];
	
	if (objForm) {
		objForm_value = '';
		for (i=0; i < objForm.elements.length; i++) {
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineAssistant_Number+'][value]') {
				objForm_value = objForm.elements[i];
			}
		}
		
		if (objForm_value && cadenaBusqueda != '') {
			objForm_value.value = cadenaBusqueda;
		}
	}
	
	fnUserRLGVSearch_ExitDiv(divName);
}

function fnUserRLGVSearchTesauros_SubmitForm(frmName, divName) {
	objForm = document.forms[frmName];
	cadenaBusqueda = '';
	
	for (i=0; i < objForm.elements.length; i++) {
		if ( !objForm.elements[i].disabled ) {
			for (line=0; line < objForm.elements[i].options.length; line++) {
				if ( objForm.elements[i].options[line].selected ) {
					if (line != 0) cadenaBusqueda += ' ';
					cadenaBusqueda += objForm.elements[i].options[line].value;
				}
			}
		}
	}
	
	objForm = document.forms["frm-user-rlgv-pi-search"];
	
	if (objForm) {
		objForm_value = '';
		for (i=0; i < objForm.elements.length; i++) {
			if (objForm.elements[i].name == 'user_rlgv_pi_search['+intLineAssistant_Number+'][value]') {
				objForm_value = objForm.elements[i];
			}
		}
		
		if (objForm_value && cadenaBusqueda != '') {
			objForm_value.value = cleanPreposiciones(cadenaBusqueda);
		}
	}
	
	fnUserRLGVSearch_ExitDiv(divName);
}


function fnPrintDisposition(objFrame) {
	objFrame.focus();
	objFrame.print();
}

// Esquema de una disposición

function fnResize_DispositionTree() {
	desplegaDivObj = new DivObj('desplegaDiv');
	desplegaSobreDivObj = new DivObj('desplegaSobreDiv');
	desplegaDivTreePosImgObj = new ImgObj('desplegaDivTreePosImg');
	
	if (desplegaDivObj.obj && desplegaSobreDivObj.obj && desplegaDivTreePosImgObj.obj) {
		if (document.all) {
			x = (parseInt(desplegaDivTreePosImgObj.obj.offsetLeft) - 9) + "px";
			y = (desplegaDivTreePosImgObj.obj.offsetTop) + "px";
			h = "19px"; //(desplegaDivTreePosImgObj.h - 1) + "px";
			w = (desplegaDivTreePosImgObj.w - 1) + "px";
		}else{
			x = (desplegaDivTreePosImgObj.obj.x) + "px";
			y = (desplegaDivTreePosImgObj.obj.y) + "px";
			h = "20px"; //(desplegaDivTreePosImgObj.h - 3) + "px";
			w = (desplegaDivTreePosImgObj.w - 2) + "px";
		}
		
		desplegaDivObj.SetSize(w, h);
		desplegaDivObj.SetPosition(x, y);
		desplegaDivObj.SetVisibility("on");
		desplegaSobreDivObj.SetSize(w, h);
		desplegaSobreDivObj.SetPosition(x, y);
		desplegaSobreDivObj.SetVisibility("on");
	}
}

var posGlobal_DispositionTree = 0;
var parteDivGlobal_DispositionTree = null;

function fnOpenSelector_DispositionTree(posParam) {
	if (document.all) {
		objDiv = document.all['desplegaDiv'];
		objDivSobre = document.all['desplegaSobreDiv'];
	}else if (document.getElementById) {
		objDiv = document.getElementById('desplegaDiv');
		objDivSobre = document.getElementById('desplegaSobreDiv');
	}
	
	if (objDiv) {
		overflowStatus = objDiv.style.overflow;
		switch(overflowStatus) {
			case 'auto':
				objDiv.style.zIndex = 1;
				objDivSobre.style.zIndex = 2;
				
				objDivSobre.onmouseover = function (){}
				
				objDiv.style.overflow = "hidden";
				objDiv.style.height = "20px";
				objDiv.style.width = (parseInt(objDiv.style.width) - 30) + "px";
				objDiv.scrollTop = 0;
				
				objDivSobre.style.height = objDiv.style.height;
				objDivSobre.style.width = objDiv.style.width;
				objDivSobre.style.top = objDiv.style.top;
				objDivSobre.style.left = objDiv.style.left;
				break;
			default:
				objDiv.style.zIndex = 2;
				objDivSobre.style.zIndex = 1;
				
				objDivSobre.onmouseover = function () {fnOpenSelector_DispositionTree(posGlobal_DispositionTree);}
				
				objDiv.style.overflow = "auto";
				objDiv.style.height = "360px";
				objDiv.style.width = (parseInt(objDiv.style.width) + 30) + "px";
				
				intOversize = 60;
				
				objDivSobre.style.height = (parseInt(objDiv.style.height) + 20) + "px";
				objDivSobre.style.width = (parseInt(objDiv.style.width) + 20) + "px";
				objDivSobre.style.top = (parseInt(objDiv.style.top) - 10) + "px";
				objDivSobre.style.left =  (parseInt(objDiv.style.left) - 10) + "px";
				break;
		}
	}
	
	if (posParam == undefined || !posParam) {
		posParam = posGlobal_DispositionTree;
	}
	
	if (posParam > 0) {
		posGlobal_DispositionTree = posParam;
		topTmp = 0;
		lineHeightTmp = 17;
    if (document.getElementById && !document.all) {
      lineHeightTmp = 19;
    }
		
		objDiv.scrollTop = topTmp + (( parseInt(posParam) - 1) * lineHeightTmp);
	}
}

function fnSelectPart_DispositionTree(posParam, anchorParam, dispositionTarget) {
	if (anchorParam != '') {
		dispositionTarget.document.location.hash = anchorParam;
		document.location.hash = "toppage";
		
		
		if (document.all) {
			parteDiv = dispositionTarget.document.all[anchorParam+'Div'];
		}else if (document.getElementById) {
			parteDiv = dispositionTarget.document.getElementById(anchorParam+'Div');
		}
		
		if (parteDivGlobal_DispositionTree) {
			parteDivGlobal_DispositionTree.style.backgroundColor = "";
		}
		if (parteDiv) {
			parteDivGlobal_DispositionTree = parteDiv;
			parteDiv.style.backgroundColor = "#F0F0F0";
		}
	}
	
	fnOpenSelector_DispositionTree(posParam);
}



function fns_SingleDispView() {
	fnResize_DispositionTree();
	fnResize_SingleDispView();
}


function fnResize_SingleDispView() {
	obj_body = document.body;
	obj_body.style.overflow = 'hidden';
	
	if (document.all) {
		height_ventana = obj_body.offsetHeight;
	} else if (document.getElementById) {
		height_ventana = window.innerHeight;
	} else return;
	
	height_minimal = 330;
	
	obj_normal = new DivObj("layerToResize");
	if (obj_normal.obj) {
		// Altura del contenido
		height_objeto = height_ventana - obj_normal.y;
		
		if (height_objeto < height_minimal) height_objeto = height_minimal;
		if (document.all) {
			document.all("layerToResize").style.height = (height_objeto - 12) + "px";
			document.all("layerToResize").style.overflow = 'auto';
		} else if (document.getElementById) {
			document.getElementById("layerToResize").style.height = '280px';
			document.getElementById("layerToResize").style.height = (height_objeto - 20) + 'px';
			document.getElementById("layerToResize").style.overflow = 'auto';
		}
	}
}


function cleanPreposiciones(texto) {
	preposiciones = new Array("a","ante","bajo","con","de","desde","durante","en","entre","excepto","hacia","hasta","mediante","para","por","salvo","según","sin","sobre","tras","davant de","davall","amb","de","des de","durant","en","entre","excepte","cap a","fins a","per mitjà de","per a","per","excepte","segons","sense","sobre","la","el","lo","del");
	
	for(preCounter=0; preCounter < preposiciones.length; preCounter++) {
		texto = texto.replace( eval("/ " + preposiciones[preCounter] + " /gi"), " ");
	}
	
	return texto;
}