//Variables que se utilizan durante la ejecución
var mouseX=0;
var mouseY=0;
var x1=0;
var y1=0;
var x2=0;
var y2=0;
var zleft=0;
var zright=0;
var ztop=0;
var zbottom=0;
var hspc = 0;
var vspc = 0;

//Grosor de línea en la caja de Zoom
var ovBoxSize = 1;

//Color de línea en la caja de Zoom
var zoomBoxColor = '#CE6384';

var zooming=false;
var panning=false;
var measuring=false;

//Coordenadas de las esquinas de la caja de Zoom
var bx1;
var by1;
var bx2;
var by2;

//Herramienta activa (1 Zoom In, 2 Zoom Out, 3 Pan, 4 Identify)
var toolMode;


// setup test for Nav 4.0
var isIE = false;
var isNav = (navigator.appName.indexOf("Netscape")>=0);
var isNav4 = false;
var isIE4 = false;
var is5up = false;

if (isNav) {
	if (parseFloat(navigator.appVersion)<5) {
		isNav4=true;
	} else {
		is5up = true;
	}
} else {
	isIE4=true;
	isIE=true;
	if (navigator.appVersion.indexOf("MSIE 5")>0) {
		isIE4 = false;
		is5up = true;
	}
}	

// Botones del ratón
var leftButton =1;
var rightButton = 2;
if (isNav) {
	leftButton = 1;
	rightButton = 3;
}

//Variables utilizadas para la medida de distancias
var clickCount = 0;
var clickMapX = new Array();
var clickMapY = new Array();
var clickMouseX = new Array();
var clickMouseY = new Array();
var medidasColor = '#9C3152';   // Color de la linea de medida
var numPuntosLinea = 100 	//Numero de Puntos de la linea


// Obtiene las coordenadas de la posición del ratón
function getMouse(e) {
	window.status="";
	getImageXY(e);

	//alert(document.Coordenadas.Coordenadas.value);
	if ((mouseX>numMapImageWidth) || (mouseY>numMapImageHeight) || (mouseX<=0) ||(mouseY<=0)){
		chkMouseUp(e);
		return true;
	}
	else {

		//Pasa las coordenadas a unidades de mapa y las muestra
		var CoordenadaX = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + (parseFloat(mouseX/numMapImageWidth)*document.form1.ancho.value)
		var CoordenadaY = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - (parseFloat(mouseY/numMapImageHeight)*document.form1.alto.value)

		//Me quedo con dos decimales
                CoordenadaX = parseInt(CoordenadaX * 100 + 0.5) / 100
                CoordenadaY = parseInt(CoordenadaY * 100 + 0.5) / 100

		//Muestra las coordenadas
		document.coordenadas.coordenadas.value = '  X: ' + CoordenadaX + '  ;  ' + 'Y: ' + CoordenadaY;
//		document.coordenadas.coordenadas.value = '  X: ' + mouseX + '  ;  ' + 'Y: ' + mouseY;

		x2=mouseX;
		y2=mouseY;
		
		if (zooming){			
			setClip();
			return false;
		}
		if (panning){
			panMouse()
			return false;
		}
		if (measuring) {			

			//Paso las coordenadas a unidades de mapa
			Mapx2 = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((x2/numMapImageWidth)*document.form1.ancho.value)
			Mapy2 = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((y2/numMapImageHeight)*document.form1.alto.value)
			distancia_Mostrar(Mapx2,Mapy2,x2,y2,20)
		}
		return true;		  
	}
}

// Obtiene las coordenadas xy del ratón sobre la imagen
function getImageXY(e) {
	if (isNav) {
		mouseX=e.pageX;
		mouseY=e.pageY;
	} 
	else {
		mouseX=event.clientX + document.body.scrollLeft;
		mouseY=event.clientY + document.body.scrollTop;
	}
	mouseX = mouseX-hspc;
	mouseY = mouseY-vspc;
}	

function getOVMapImageXY(e) {
	if (isNav) {
		mouseX=e.pageX;
		mouseY=e.pageY;
	} 
	else {
		mouseX=event.clientX + document.body.scrollLeft;
		mouseY=event.clientY + document.body.scrollTop;
	}
	mouseX = mouseX-OVhspc;
	mouseY = mouseY-OVvspc;
}	

// Inicia la visualización de la caja de de zoom
function startZoomBox(e) {
	//moveLayer("theMap",hspc,vspc);
	getImageXY(e);	

	// keep it within the MapImage
	if ((mouseX<numMapImageWidth) && (mouseY<numMapImageHeight)) {
		if (zooming) {
			stopZoomBox(e);
		} 
		else {
			x1=mouseX;
			y1=mouseY;
			x2=x1+1;
			y2=y1+1;
			zleft=x1;
			ztop=y1;
			zbottom=y1;
			zright=x1

			boxIt(x1,y1,x2,y2);

			zooming=true;

			showLayer("zoomBoxTop");
			showLayer("zoomBoxLeft");
			showLayer("zoomBoxRight");
			showLayer("zoomBoxBottom");		
		}
	}
	return false;
}


// Finaliza la visualización de la caja de zoom
function stopZoomBox(e) {
	zooming=false;

	hideLayer("zoomBoxTop");
	hideLayer("zoomBoxLeft");
	hideLayer("zoomBoxRight");
	hideLayer("zoomBoxBottom");

	if ((zright <zleft+2) && (zbottom < ztop+2)) {
		zoomin(e);
	} 
	else {
		getImageXY(e);
		bx2 = mouseX;
		by2 = mouseY;

		hideLayer("zoomBoxTop");
		hideLayer("zoomBoxLeft");
		hideLayer("zoomBoxRight");
		hideLayer("zoomBoxBottom");

		//Pasa las coordenadas de los puntos que definen la caja en la imagen a coordenadas de mapa
		bx1 = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((bx1/numMapImageWidth)*document.form1.ancho.value)
		by1 = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((by1/numMapImageHeight)*document.form1.alto.value)
		bx2 = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((bx2/numMapImageWidth)*document.form1.ancho.value)
		by2 = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((by2/numMapImageHeight)*document.form1.alto.value)

		Map_Extension(Math.min(bx1,bx2),Math.min(by1,by2),Math.max(bx1,bx2),Math.max(by1,by2))
		//Obtiene el minimo nivel que contiene la nueva extensión
		//numNivel = Map_GetNivel(Math.abs(bx2-bx1),Math.abs(by2-by1))

		//Realiza la petición de mapa
		//Map_XY(((bx1+bx2)/2),((by1+by2)/2),numNivel)

		}

	return true;
}

// Operaciones por punto
function zoomin(e) {
	getImageXY(e);

	mouseX = mouseX - 1.5
	mouseY = mouseY - 1.2

	//Pasa las coordenadas de la imagen a coordenadas de mapa
	X = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((mouseX/numMapImageWidth)*document.form1.ancho.value)
	Y = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((mouseY/numMapImageHeight)*document.form1.alto.value)

	//Zoom in por punto
	if(toolMode == '1') {
		numNivel = Number(document.form1.nivel.value) - 1
		Map_XY(X,Y,numNivel)
	}
	//Zoom out por punto
	else if(toolMode == '2') {
		numNivel = Number(document.form1.nivel.value) + 1
		Map_XY(X,Y,numNivel)
	}
	//Desplazamiento
	else if(toolMode == '3') {
		Map_XY(X,Y,document.form1.nivel.value)
	}
	//Datos de elementos
	else if(toolMode == '4') {
		Cmd_Id(X,Y,document.form1.nivel.value)
	}
	//Hiperenlace
	else if(toolMode == '6') {
		Cmd_Hyp(X,Y,document.form1.nivel.value)
	}
}

// clip zoom box layer to mouse coords
function setClip() {	
	var tempX=x1;
	var tempY=y1;
	if (x1>x2) {
		zright=x1;
		zleft=x2;
	} else {
		zleft=x1;
		zright=x2;
	}
	if (y1>y2) {
		zbottom=y1;
		ztop=y2;
	} else {
		ztop=y1;
		zbottom=y2;
	}

	if ((x1 != x2) && (y1 != y2)) {
		boxIt(zleft,ztop,zright,zbottom);
	}
}



//Se ejecuta cuando se suelta el botón del ratón (evento Mouse up)
//Controla el final del Zoom In por caja y del Pan
function chkMouseUp(e) { 
		
	if ((toolMode == 1) && (zooming)) {
		stopZoomBox(e);			
	}		
	if ((toolMode == 3) && (panning)) {
		stopPan(e);			
	}		
	return false;
}


//Se ejecuta cuando se pulsa con el ratón sobre el mapa (evento Mouse Down)
function mapTool (e) {
	var theButton= 0;
	// Obtiene el botón pulsado. Si es el derecho permitimos al browser hacer el popup
	if (isNav) {
		theButton = e.which;
	} else {
		theButton =window.event.button;
	}	
	if (theButton==leftButton) {
		getImageXY(e);
		bx1 = mouseX;
		by1 = mouseY;
		if ((mouseX>=0) && (mouseX<numMapImageWidth) && (mouseY>=0) && (mouseY<numMapImageHeight)) {
			switch(toolMode) {

				case 1:
					startZoomBox(e);
					return false;
					break
				case 2:
					zoomin(e);
					return false;
					break
				case 3:
					startPan(e);
					return false;
					break
				//Identificación
				case 4:
					identificacion_dibujarPunto(mouseX,mouseY) 
					zoomin(e);
					return false;
					break
				//Medida de distancias
				case 5:
					clickAddPoint();
					break
				//Hiperenlace
				case 6:
					zoomin(e);
					return false;
					break
				default:
					zoomin(e);
					return false;
			}
		}
		else {
			getOVMapImageXY(e)
			if ((mouseX>=0) && (mouseX<numOVMapImageWidth) && (mouseY>=0) && (mouseY<numOVMapImageHeight)) {
				MapReferencia_XY(mouseX,mouseY)
				return false;
			}	
		}
	}
}

//Mide distancias
function clickAddPoint() {

	//Se inicializa la medida de distancias
	if (clickCount>1) {
		distancia_Inicializar()
	}

	//Obtiene las coordenadas del ratón
	var CoordenadaX = mouseX;
	var CoordenadaY = mouseY;

	//Incluyo las coordenadas en el Array de Coordenadas de la Imagen
	clickMouseX[clickCount]=CoordenadaX;
	clickMouseY[clickCount]=CoordenadaY;

	//Paso las coordenadas a unidades de mapa
	CoordenadaX = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((CoordenadaX/numMapImageWidth)*document.form1.ancho.value)
	CoordenadaY = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((CoordenadaY/numMapImageHeight)*document.form1.alto.value)

	//Incluyo las coordenadas en el Array de Coordenadas de Mapa
	clickMapX[clickCount]=CoordenadaX;
	clickMapY[clickCount]=CoordenadaY;
	
	//Dibujo el punto sobre la imagen
	distancia_dibujarPunto(clickCount)

	//Comienza la medida
	if (clickCount==0){
		measuring=true;
	}

	//Obtengo la longitud del último segmento
	if (clickCount>0) {
		measuring=false;
		distancia_Mostrar(clickMapX[1],clickMapY[1],clickMouseX[1],clickMouseY[1],4)
	}
	clickCount += 1;
}

function distancia_Mostrar(MapX2,MapY2,MouseX2,MouseY2,numFactor){
	distancia_OcultarLayersLinea();
	var distancia = Math.sqrt(Math.pow(MapX2-clickMapX[0],2)+Math.pow(MapY2-clickMapY[0],2))
	distancia = parseInt((distancia/1000) * 100 + 0.5) / 100
	document.distancia.distancia.value = 'Distancia ' + distancia + ' km.'
	distancia_dibujarLinea(clickMouseX[0],clickMouseY[0],MouseX2,MouseY2,numFactor)
}

function distancia_Inicializar(){
	document.distancia.distancia.value = '';
	clickCount = 0;
	distancia_OcultarLayersPuntos();
	distancia_OcultarLayersLinea();
}

//Hace invisibles el punto inicial y final
function distancia_OcultarLayersPuntos() {
	hideLayer("Punto0");  		
	hideLayer("Punto1");  		
}

//Hace invisibles los layers con los puntos de la línea
function distancia_OcultarLayersLinea() {
	for (i=0; i<numPuntosLinea ;i++) {
		nomLayer = "Linea" + i ;
		hideLayer(nomLayer);
	}
}

//Dibuja el Punto inicial o final de la línea de distancia
function distancia_dibujarPunto(numPunto) {
	var nomLayer = "Punto" + numPunto ;   
	hideLayer(nomLayer);    
	moveLayer(nomLayer, hspc + clickMouseX[numPunto] - 11, vspc + clickMouseY[numPunto] - 11);
	showLayer(nomLayer);
}

//Dibuja la Lína de medida de distancias
function distancia_dibujarLinea(x1,y1,x2,y2,numFactor) {
	d = Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2))	
	numPuntos = d/numFactor
	if (numPuntos>numPuntosLinea){
		numPuntos = numPuntosLinea
	}
	for (i=1; i<numPuntos ;i++) {		
		dp = i*(d/numPuntos)
		alfa = Math.atan((x2-x1)/(y2-y1))
		if (y2<y1){	
			alfa = alfa + Math.PI
		}
		y = y1 + dp*Math.cos(alfa)
		x = x1 + dp*Math.sin(alfa)
		nomLayer = "Linea" + i;   
		moveLayer(nomLayer, hspc + x-2, vspc + y -2);
		showLayer(nomLayer);	
	}
}

//Muestra una imagen que indica el lugar donde se realizó la identificacion
function identificacion_dibujarPunto(X,Y) {
	var nomLayer = "Identificacion";   
	hideLayer(nomLayer );    
	moveLayer(nomLayer, hspc + X - 11, vspc + Y - 11);
	showLayer(nomLayer );
}


// Inicia el desplazamiento (Pan)
function startPan(e) {
//	document.form1.mapa.src="/internet/ServiciosMapas/SiasEspana/img/pixel.gif"
	showLayer("theMap");
	moveLayer("theMap",hspc,vspc);
	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<numMapImageWidth) && (mouseY<numMapImageHeight)) {
		if (panning) {
			stopPan(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}
	return false;
}

// Finaliza el desplazamiento (Pan)
function stopPan(e) {
	panning=false;

	bx2 = mouseX;
	by2 = mouseY;

	//Pasa las coordenadas de los puntos que definen el desplazamiento a coordenadas de mapa
	bx1 = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((bx1/numMapImageWidth)*document.form1.ancho.value)
	by1 = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((by1/numMapImageHeight)*document.form1.alto.value)
	bx2 = parseFloat(document.form1.centrox.value) - document.form1.ancho.value/2 + ((bx2/numMapImageWidth)*document.form1.ancho.value)
	by2 = parseFloat(document.form1.centroy.value) + document.form1.alto.value/2 - ((by2/numMapImageHeight)*document.form1.alto.value)

	//Obtiene el nuevo centro del mapa
	centroX = parseFloat(document.form1.centrox.value) - bx2 + bx1
	centroY = parseFloat(document.form1.centroy.value) - by2 + by1

	//Hace la petición de mapa
	Map_XY(centroX,centroY,document.form1.nivel.value)

	//hideLayer("theMap");

	return true;
}



// move map image with mouse
function panMouse() {
	var xMove = x2-x1;
	var yMove = y2-y1;
	var cLeft = -xMove;
	var cTop = -yMove;
	var cRight = numMapImageWidth;
	var cBottom = numMapImageHeight;
	if (xMove>0) {
		cLeft = 0;
		cRight = numMapImageWidth - xMove;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = numMapImageHeight - yMove;
	}
	document.form1.mapa.src="/internet/ServiciosMapas/SiasEspana/img/pixel.gif"
	clipLayer2("theMap",cLeft,cTop,cRight,cBottom);
	moveLayer("theMap",xMove+hspc,yMove+vspc);
	//return false;
}

// Abre en una ventana una página y pone el foco en dicha ventana
function createWindow(cUrl,cName,cFeatures) {
	var xWin = window.open(cUrl,cName,cFeatures);
	xWin.focus();
}

//-----------------------------------------------
//Funciones llamadas desde la plantilla mapa.xsl
//-----------------------------------------------
function Map(numNivel,numPanV,numPanH) {

	centroX = parseFloat(document.form1.centrox.value) + (numPanH * (document.form1.ancho.value/2))
	centroY = parseFloat(document.form1.centroy.value) + (numPanV * (document.form1.alto.value/2))
	
	Map_XY(centroX,centroY,numNivel)
}

function Map_XY(numX,numY,numNivel) {

	strHREF  = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=map"
	strHREF += "&too=" + toolMode
	strHREF += "&cox=" + numX
        strHREF += "&coy=" + numY
	strHREF += "&niv=" + numNivel 
	strHREF += "&scw=" + screen.width
        strHREF += "&sch=" + screen.height

	//Temas visibles
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].name == "tem") {
			if (document.form1.elements[i].type == "checkbox") {
				if (document.form1.elements[i].checked) {
					
					if (document.form1.elements[i].value == "punacu") {
						strHREF += "&tem=" + document.form1.elements[i].value
						strHREF += "&tem=" + "punacu2"
					} else {
						strHREF += "&tem=" + document.form1.elements[i].value
					}
					if (document.form1.elements[i].value == "punacu2") {
						strHREF += "&tem=" + document.form1.elements[i].value
						strHREF += "&tem=" + "punacu"
					} 
				} 
			}
			else {
				if (document.form1.elements[i].value != "punacu") {
					strHREF += "&tem=" + document.form1.elements[i].value
				}
			}
		}
	}

	//Mascara
	if (document.form1.TemaMascara != null) {
	        strHREF += "&mst=" + document.form1.TemaMascara.value
	        strHREF += "&msc=" + document.form1.ConsultaMascara.value
	}

	window.location.href = strHREF
}

function Map_Extension(XMin,YMin,XMax,YMax){

	//Obtiene el minimo nivel que contiene la nueva extensión
	numNivel = Map_GetNivel(Math.abs(XMax-XMin),Math.abs(YMax-YMin))

	//alert (XMin + "-" + YMin + "-" + XMax + "-" + YMax)

	//Realiza la petición de mapa
	Map_XY(((XMin+XMax)/2),((YMin+YMax)/2),numNivel)

}

function MapReferencia_XY(numX,numY) {

	//Paso las coordenadas a unidades de mapa
	centroX = parseFloat(document.form1.OVcentrox.value) - document.form1.OVancho.value/2 + ((numX/numOVMapImageWidth)*document.form1.OVancho.value)
	centroY = parseFloat(document.form1.OVcentroy.value) + document.form1.OValto.value/2 - ((numY/numOVMapImageHeight)*document.form1.OValto.value)
	
	Map_XY(centroX,centroY,document.form1.nivel.value)
}

function Cmd_Id(numX,numY,numNivel) {

	strHREF  = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=idf"
	strHREF += "&cox=" + numX
        strHREF += "&coy=" + numY
	strHREF += "&niv=" + numNivel 

	//Temas visibles
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].name == "tem") {
			if (document.form1.elements[i].type == "checkbox") {
				if (document.form1.elements[i].checked) {
					strHREF += "&tem=" + document.form1.elements[i].value
				} 
			}
			else {
				strHREF += "&tem=" + document.form1.elements[i].value
			}
		}
	}  
	createWindow(strHREF,'identificacion','scrollbars=yes,resizable=yes,width=600,height=300')
}

function Cmd_Hyp(numX,numY,numNivel) {

	strHREF  = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=hyp"
	strHREF += "&cox=" + numX
        strHREF += "&coy=" + numY
	strHREF += "&niv=" + numNivel 
	strHREF += "&scw=" + screen.width
        strHREF += "&sch=" + screen.height

	//Temas visibles
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].name == "tem") {
			if (document.form1.elements[i].type == "checkbox") {
				if (document.form1.elements[i].checked) {
					strHREF += "&tem=" + document.form1.elements[i].value
				} 
			}
			else {
				strHREF += "&tem=" + document.form1.elements[i].value
			}
		}
	}  
	createWindow(strHREF,'hiperenlace','scrollbars=yes,resizable=yes,width=600,height=300')
}

// Identifica un elemento a partir de su código de elemento y municipio
function IdentificarElemento(strElemento,strMunicipio) {
	strHREF = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=id"
	strHREF += "&id=" + strElemento
	strHREF += "&mun=" + strMunicipio

	window.location.href = strHREF
}

// Identifica un elemento a partir de sus coordenadas X e Y
//function IdentificarXY(CoordenadaX,CoordenadaY) {
//	strHREF = document.form1.action + "?"
//	strHREF += "name=" + document.form1.name.value 
//	strHREF += "&cmd=idc"
//	strHREF += "&cox=" + CoordenadaX
//	strHREF += "&coy=" + CoordenadaY
//	strHREF += "&niv=" + document.form1.nivel.value
//	window.location.href = strHREF
//}


// Obtiene el mínimo nivel que contiene un rectángulo
function Map_GetNivel(numAncho,numAlto) {
	for (i=0; i<g_arrEscalas.length; i++){
	        numAnchoNivel = g_arrEscalas[i] * (document.form1.ancho.value/g_arrEscalas[Number(document.form1.nivel.value)-1]) 
	        numAltoNivel = g_arrEscalas[i] * (document.form1.alto.value/g_arrEscalas[Number(document.form1.nivel.value)-1]) 
		
	        if ((numAncho <= numAnchoNivel) && (numAlto <= numAltoNivel)){
			return i+1;
		}
	}	
}


//Muestra el formulario de selección
function Cmd_SeF() {
	strHREF = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=sef"
	strHREF += "&clv=" + document.form1.clave.value
	strHREF += "&gra=" + document.form1.grafico.value
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].type == "select-one") {
			strHREF += "&" + document.form1.elements[i].name + "=" + document.form1.elements[i].value;
		} 
	}
	window.location.href = strHREF
}

//Realiza la seleccion desde el formulario
function Cmd_Sel() {
	strHREF = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=sel"
	strHREF += "&clv=" + document.form1.clave.value
	strHREF += "&gra=" + document.form1.grafico.value
	strHREF += "&identi=" + document.form1.reg.value
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].type == "select-one") {
			strHREF += "&" + document.form1.elements[i].name + "=" + document.form1.elements[i].value;
		} 
	}

	//Temas visibles
//	if (window.opener.document.form1 != null) {
//		for (var i=0; i <= window.opener.document.form1.elements.length-1 ;i++) {
//			if (window.opener.document.form1.elements[i].name == "tem") {
//				if (window.opener.document.form1.elements[i].type == "checkbox") {
//					if (window.opener.document.form1.elements[i].checked) {
//						strHREF += "&tem=" + window.opener.document.form1.elements[i].value
//					} 
//				}
//				else {
//					strHREF += "&tem=" + window.opener.document.form1.elements[i].value
//				}
//			}
//		}  
//	}
//	else {
//		strHREF += "&tem=ini"
//	}
//
//	//Añade el tema por el que se hace la búsqueda
//	strHREF += "&tem=" + strTema

	//Resolución de pantalla del cliente
	strHREF += "&scw=" + screen.width
        strHREF += "&sch=" + screen.height
	window.location.href = strHREF
}

function Cmd_inf(Valor) {	
	strHREF  = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=inf"
	strHREF += "&tem=" + document.form1.tema.value
	strHREF += "&fld=" + document.form1.campo.value
        strHREF += "&val=" + Valor
	createWindow(strHREF,'informacion','menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,width=600,height=350')
}

//Muestra el formulario de selección
function Cmd_SeP() {
	strHREF = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=sep"
	strHREF += "&clv=" + document.form1.clave.value
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].type == "select-one") {
			strHREF += "&" + document.form1.elements[i].name + "=" + document.form1.elements[i].value;
		} 
	}
	window.location.href = strHREF
}

//Realiza la seleccion desde el formulario
function Cmd_SeG() {
	strHREF = document.form1.action + "?"
	strHREF += "name=" + document.form1.name.value 
	strHREF += "&cmd=seg"
	strHREF += "&clv=" + document.form1.clave.value
	strHREF += "&identi=" + document.form1.reg.value
	for (var i=0; i <= document.form1.elements.length-1 ;i++) {
		if (document.form1.elements[i].type == "select-one") {
			strHREF += "&" + document.form1.elements[i].name + "=" + document.form1.elements[i].value;
		} 
	}
	
	//Resolución de pantalla del cliente
	strHREF += "&scw=" + screen.width
        strHREF += "&sch=" + screen.height
	window.location.href = strHREF
}
