/*
Aviso de licencia
-----------------
El c�digo fuente contenido en este fichero es propiedad
intelectual del Grupo de Sistemas de Informaci�n Avanzados
(IAAA), del Dpto. de Inform�tica e Ingenier�a de Sistemas
de la Universidad de Zaragoza (http://iaaa.cps.unizar.es)

Este c�digo fuente se proporciona �nicamente como
mecanismo para posibilitar la ejecuci�n de la aplicaci�n
que lo contiene, por razones t�cnicas, y se licencia
para ese uso exclusivamente. El hecho de estar leyendo
este aviso de licencia ya implica, por tanto, un acceso no
autorizado a este c�digo.

Los due�os de la propiedad intelectual de este c�digo
fuente prohiben expresamente cualquier uso del
mismo distinto al enunciado en el p�rrafo anterior,
incluyendo su lectura, an�lisis, copia a cualquier formato,
incluyendo papel, transmisi�n por cualquier medio, modificaci�n
y su utilizaci�n (tal cual o tras modificarlo) en aplicaciones
distintas a aquella para la que el c�digo ha sido licenciado.
*/

// Variables para mantener el estado de los valores
var validInputX = false;
var validInputY = false;
var validInputLatitudeDegree = false;
var validInputLatitudeMinutes = false;
var validInputLatitudeSeconds = false;
var validInputLongitudeDegree = false;
var validInputLongitudeMinutes = false;
var validInputLongitudeSeconds = false;
var validInputLatitude = false;
var validInputLongitude = false;
var validInputURL = false;
var validInputGML = false;
var validOutputURL = false;
var loadingOutputURL = false;

//-----------------------------------------------------------------------------
// Obtiene un parametro de una url
function getURLParameterValue( url, paramName )
{
	var index = url.indexOf("?");   
	var Params = url.substr(index + 1, url.length).split("&");
	for (var i =	0; i < Params.length; i++)
	{
		if ( Params[i].split("=")[0] == paramName )
		{
			if ( Params[i].split("=").length > 1 ) 
				return Params[i].split("=")[1];
			return "";
		}
	}
   return "";
}

//-------------------------------------------------------------------------------------------------------------------------------
// Redondea al numero de decimales pasado como parametro
function round( number, precision )
{	
	factor = Math.pow(10,precision);
	return Math.round(number*factor)/factor;
}

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es un float valido, false en caso contrario
function checkFloat( value )
{	

	// Sustituimos ',' por '.'
	var value2 = value.replace(/,/,".");
	// Quitamos .0 .00 .000
	value2 = value2.replace(/\.0+$/,"");
	var lvalue2 = value2.length;
	// Quitamos 0 a la izquierda
	value2 = value2.replace(/^0+/,"");
	if ((lvalue2 > 0) && ((value2.length == 0) || (value2.charAt(0) == '.')))
		// Era todo 0, ponemos uno
		value2 = "0" + value2;
	var realVal = parseFloat(value2);
	if ( isNaN(realVal) )
		return false;
	if ( value2.length != ('' + realVal).length )
		return false;
	return true;
}

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es un float positivo valido, false en caso contrario
function checkPositiveFloat( value )
{	
	if ( !checkFloat( value ) )
		return false;
	var realVal = parseFloat(value.replace(/,/,"."));	
	if ( realVal < 0.0 )
		return false;
	return true;	
}

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es un float sexagesimal positivo valido, false en caso contrario
function checkSexagesimalPositiveFloat( value )
{	
	if ( !checkPositiveFloat( value ) )
		return false;
	var realVal = parseFloat(value.replace(/,/,"."));	
	if ( realVal >= 60.0 )
		return false;
	return true;	
}

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es un entero positivo valido, false en caso contrario
function checkInteger( value )
{	
	var value2 = value;
	var lvalue2 = value2.length;
	// Quitamos 0 a la izquierda
	value2 = value2.replace(/^0+/,"");
	if ((lvalue2 > 0) && (value2.length == 0))
		// Era todo 0, ponemos uno
		value2 = "0";
	var integerVal = parseInt(value2);
	if ( isNaN(integerVal) )
		return false;
	if ( value2.length != ('' + integerVal).length )
		return false;
	return true;
}

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es un integer positivo valido, false en caso contrario
function checkPositiveInteger( value )
{	
	if ( !checkInteger( value ) )
		return false;
	var integerVal = parseInt(value);	
	if ( integerVal < 0 )
		return false;
	return true;	
}

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es un integer sexagesimal positivo valido, false en caso contrario
function checkSexagesimalPositiveInteger( value )
{	
	if ( !checkPositiveInteger( value ) )
		return false;
	var integerVal = parseInt(value);	
	if ( integerVal >= 60 )
		return false;
	return true;	
}

//-------------------------------------------------------------------------------------------------------------------------------
// Pausa la ejecucion
// @param millis: milisegundos que se desea parar
function pause(millis)
{
	var date = new Date();
	var curDate = null;

	do
	{ 
		curDate = new Date();
	}
	while(curDate-date < millis);
} 

//-------------------------------------------------------------------------------------------------------------------------------
// Devuelve true si es una URL valida, false en caso contrario
function validateURL(urlStr)
{
	// Espacios
	if (urlStr.indexOf(" ")!=-1)
	{
		//alert("Spaces are not allowed in a URL");
		return false;
	}	
		
	// Cadena vacia o nula	
	if (urlStr==""||urlStr==null)
		return false;
	
	// Expresion regular que chequea que la url este formada por:
	// Protocolo: "http://" o "https://" o "ftp://"
	// Usuario: user:password@ (Opcional)
	// Servidor: una o mas cadenas, formadas por uno o mas de los caracteres permitidos, seguidos de "."
	// Dominio: formado por entre 2 y 6 letras en el rango a-z
	// IP: puede ser IP en lugar de servidor.dominio
	// Puerto: uno o mas digitos y ":" (Opcional)
	// Por ultimo "/" seguido del path del fichero sin restricciones o final
	var urlPat=/^(?:(?:(?:ftp)|(?:http))|(?:https)):\/\/(?:[^\:]+\:[^\:]+@)?(?:(?:(?:(?:[a-zA-Z0-9:,;<>\"\[\]@\\\(\)_\-\+]+)\.)+[a-z]{2,6})|(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3}))(?:\:[0-9]+)?(?:\/|$)/;
	var matchArray=urlStr.match(urlPat);
	
	if (matchArray==null)
		return false;
	
	return true;
}

//-----------------------------------------------------------------------------
// Chequea si en la creacion de un xmlDocument en Mozilla ha habido error
function checkForMozillaXMLParseError (xmlDocument)
{
    var errorNamespace = 'http://www.mozilla.org/newlayout/xml/parsererror.xml';
    var documentElement = xmlDocument.documentElement;
    var parseError = { errorCode : 0 };
    if (documentElement.nodeName == 'parsererror' && documentElement.namespaceURI == errorNamespace)
    {
		parseError.errorCode = 1;
		var sourceText = documentElement.getElementsByTagNameNS(errorNamespace, 'sourcetext')[0];
		if (sourceText != null)
			parseError.srcText = sourceText.firstChild.data
		parseError.reason = documentElement.firstChild.data;	
	}
	return parseError;
}

//-----------------------------------------------------------------------------
// Crea un xmlDocument a partir de un string
// -1    Navegador no compatible
// null  No se ha podido crear el xmlDocument a partir del string
function loadXMLFromString ( xmlString )
{
	var xmlDocument = null;
	if(window.ActiveXObject)
	{
		//Explorer
		//xmlDocument = new ActiveXObject("Msxml2.DOMDocument.3.0");
		xmlDocument = new ActiveXObject("Microsoft.XMLDOM");		
		xmlDocument.async = false;	
		if ( xmlDocument.loadXML(xmlString) )
			return xmlDocument;
		else 
			return null;		
	}
	else if(typeof(XPCNativeWrapper) == "function")
	{
		//Mozilla, Netscape, Opera ...
		var domParser = new DOMParser();
		xmlDocument = domParser.parseFromString(xmlString,"text/xml");		
		parseError = checkForMozillaXMLParseError(xmlDocument);
		if (parseError.errorCode == 0)
			return xmlDocument;	
		else
			return null;	
	}
	else
		return -1;
}

//-----------------------------------------------------------------------------
// Crea un objeto para la peticion por AJAX
var http_request_array = new Array();

function createAJAX()
{
	var request = null;
	if (window.ActiveXObject)	
		request = new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		request = new XMLHttpRequest();
		
	return request;
}

//-----------------------------------------------------------------------------
// Envia una peticion asincrona por AJAX
// @param url:               url para la peticion
// @param method:            metodo HTTP para la peticion GET, POST ...
// @param handlerWhenLoaded: funcion a llamar cuando cambie el estado
// @param postParams:        cadena a pasar como parametro POST
// @param contentType:       cadena a poner como Content-Type
// @param cache:             true si la peticion puede ser cacheada, false en caso contrario
function sendAJAX(url,method,handlerWhenLoaded,postParams,contentType,cache)
{
	var act = new Date();
	http_request_array[act] = createAJAX();
	
	if (http_request_array[act])
	{
		http_request_array[act].onreadystatechange = function() {handlerWhenLoaded(http_request_array[act]);}
		http_request_array[act].open(method, url, true);
		if ( contentType != null )
			http_request_array[act].setRequestHeader('Content-Type', contentType);
		if ( ( cache != null ) && ( cache == false ) )	
			http_request_array[act].setRequestHeader('Cache-Control', 'no-cache');	
		http_request_array[act].send(postParams);
	}
	else
		return false;	

	return true;
	
}

//-----------------------------------------------------------------------------
// Devuelve el codigo html para una imagen png con transparencias
function pngTransparente(pathPngTrans, pathImgVacia, pngWidth, pngHeight)
{
	if (document.all)
		//Explorer
		return "<img src=\"" + pathImgVacia + "\" style=\"width:" + pngWidth + ";height:" + pngHeight + ";filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + pathPngTrans + "', sizingMethod='scale');\"></img>";
	else
		return "<img src='" + pathPngTrans + "'></img>";	
}

//-----------------------------------------------------------------------------
// Devuelve los grados correspondientes a la cadena decimal
function decimal2degree_degree(decimalStr)
{
	return Math.floor(Math.abs(parseFloat(decimalStr)));
}

//-----------------------------------------------------------------------------
// Devuelve los minutos correspondientes a la cadena decimal
function decimal2degree_minutes(decimalStr)
{
	var decimal = parseFloat(decimalStr);
	var decimalPart = Math.abs(decimal) - Math.floor(Math.abs(decimal));
	return Math.floor(decimalPart*60);
}

//-----------------------------------------------------------------------------
// Devuelve los segundos correspondientes a la cadena decimal
function decimal2degree_seconds(decimalStr)
{
	var decimal = parseFloat(decimalStr);
	var decimalPart = Math.abs(decimal) - Math.floor(Math.abs(decimal));
	var secondsDecimalPart = decimalPart*60 - Math.floor(decimalPart*60);
	return secondsDecimalPart*60;
}

//-----------------------------------------------------------------------------
// Devuelve N o S correspondientes a la cadena decimal
function decimal2degree_NS(decimalStr)
{
	var decimal = parseFloat(decimalStr);
	if ( decimal >= 0.0 )
		return "N";
	else
		return "S";	
}

//-----------------------------------------------------------------------------
// Transforma las coordenadas de grados a decimal
function degree2decimal(degreeStr, minutesStr, secondsStr, NSEO)
{
	var decimal = parseFloat(degreeStr) + (parseFloat(minutesStr)/60) + (parseFloat(secondsStr)/3600);
	if ( (NSEO == "S") || (NSEO == "O") )
		decimal -= 2*decimal;
	return decimal;	
}

//-----------------------------------------------------------------------------
// Devuelve E o O correspondientes a la cadena decimal
function decimal2degree_EO(decimalStr)
{
	var decimal = parseFloat(decimalStr);
	if ( decimal >= 0.0 )
		return "E";
	else
		return "O";	
}

//-----------------------------------------------------------------------------
// Clase numero sexagesimal
function degree(decimal, precision)
{
	var degs = 0;
	var mins = 0;
	var secs = round(decimal2degree_seconds(decimal),precision);
	if (secs == 60)
	{
		secs = 0;
		mins = 1;
	}
	mins += decimal2degree_minutes(decimal);
	if (mins == 60)
	{
		mins = 0;
		degs = 1;
	}
	degs += decimal2degree_degree(decimal);
	this.degrees = degs;
	this.minutes = mins;
	this.seconds = secs;
}

//-----------------------------------------------------------------------------
// Devuelve el huso correspondiente a la longitud entre 28 y 31 (Espa�a)
function calculateTimeZone(decimalValue)
{
	if ( (decimalValue >= 0.0) && (decimalValue < 6.0) )
		return "31";
	else if ( (decimalValue >= -6.0) && (decimalValue < 0.0) )
		return "30";
	else if ( (decimalValue >= -12.0) && (decimalValue < -6.0) )
		return "29";
	else if ( (decimalValue >= -18.0) && (decimalValue < -12.0) )	
		return "28";
	else
		return -1;			
}

//-----------------------------------------------------------------------------
// Establece el huso apropiado a la longitud introducida
function setTargetTimeZone()
{
	// Comprobamos si es un entero positivo valido
	var inputLongitudeDegree = document.getElementById("inputLongitudeDegree").value;
	var inputLongitudeMinutes = document.getElementById("inputLongitudeMinutes").value;
	var inputLongitudeSeconds = document.getElementById("inputLongitudeSeconds").value;
	var targetCRS = document.getElementById("targetCRSCombo");
	var outputHuso = document.getElementById("outputHuso");
		
	// Calculamos el huso y lo ponemos si destino es CRS UTM y la longitud introducida es v�lida
	if ( targetCRS.options[targetCRS.selectedIndex].value.indexOf("UTM") != -1 && validInputLongitude )
	{
		var inputLongitudeEO = document.getElementById("inputLongitudeEO");
		var inputLongitudeEOValue = inputLongitudeEO.options[inputLongitudeEO.selectedIndex].value;
		var huso = calculateTimeZone(degree2decimal(inputLongitudeDegree,inputLongitudeMinutes,inputLongitudeSeconds,inputLongitudeEOValue));
		
		/* UTM */
		// Marcamos el huso que corresponda
		for ( var a = 0; a < outputHuso.options.length; a++ )
		{
			if ( outputHuso.options[a].value == huso )
			{
				outputHuso.selectedIndex = a;
				break;
			}
		}	
		
	}

}

//-----------------------------------------------------------------------------
// Descarga el fichero de capabilities del Servidor
function getCapabilities( )
{

	var url = WCTS_URL + "?service=" + WCTS_SERVICE + "&version=" + WCTS_VERSION + "&request=GetCapabilities";

	// Pasamos por post la url al jsp que descarga el archivo y ponemos de target el iframe
	// para que no nos abra otra ventana o nos fastidie la que tenemos
	//document.getElementById('downloadLink').src = "downloadLink.jsp?url=" + url;
	document.getElementById('downloadLinkFormURL').value = url;
	document.getElementById('downloadLinkFormFileName').value = capabilitiesFileName;
	document.getElementById('downloadLinkForm').submit();
}

//-----------------------------------------------------------------------------
// Habilita o deshabilita un boton
function disenableButton( button, enable )
{
	if ( enable )
	{
		button.disabled = false;
		button.className = "buttonEnabled";
	}
	else
	{
		button.disabled = true;
		button.className = "buttonDisabled";
	}
}

//-----------------------------------------------------------------------------
// Limpiar todos los campos
function cleanFields()
{
	document.getElementById("inputLatitudeDegree").value = '';
	document.getElementById("inputLatitudeMinutes").value = '';
	document.getElementById("inputLatitudeSeconds").value = '';
	document.getElementById("inputLongitudeDegree").value = '';
	document.getElementById("inputLongitudeMinutes").value = '';
	document.getElementById("inputLongitudeSeconds").value = '';
	document.getElementById("inputX").value = '';
	document.getElementById("inputY").value = '';
	document.getElementById("inputURL").value = '';
	document.getElementById("inputGML").value = '';
	document.getElementById("outputLatitudeDegree").value = '';
	document.getElementById("outputLatitudeMinutes").value = '';
	document.getElementById("outputLatitudeSeconds").value = '';
	document.getElementById("outputLatitudeNS").value = '';
	document.getElementById("outputLongitudeDegree").value = '';
	document.getElementById("outputLongitudeMinutes").value = '';
	document.getElementById("outputLongitudeSeconds").value = '';
	document.getElementById("outputLongitudeEO").value = '';
	document.getElementById("outputX").value = '';
	document.getElementById("outputY").value = '';
	document.getElementById("outputURL").value = '';
	document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
	document.getElementById('errorInputURL').innerHTML = '&nbsp;';
	document.getElementById('errorInputGML').innerHTML = '&nbsp;';
	document.getElementById('errorOutputURL').innerHTML = '&nbsp;';
	document.getElementById('loadingPoint').style.visibility = "hidden";
	document.getElementById('loadingURL').style.visibility = "hidden";
	document.getElementById("sourceCRSCombo").selectedIndex = 0;
	document.getElementById("targetCRSCombo").selectedIndex = 0;
	validInputX = false;
	validInputY = false;
	validInputLatitudeDegree = false;
	validInputLatitudeMinutes = false;
	validInputLatitudeSeconds = false;
	validInputLongitudeDegree = false;
	validInputLongitudeMinutes = false;
	validInputLongitudeSeconds = false;
	validInputLatitude = false;
	validInputLongitude = false;
	validInputURL = false;
	validInputGML = false;
	validOutputURL = false;
	loadingOutputURL = false;	
	changeSourceCRS();
	changeTargetCRS();
}

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del combo source CRS
function changeSourceCRS()
{
	var sourceCRS = document.getElementById("sourceCRSCombo");
	var targetCRS = document.getElementById("targetCRSCombo");
	var inputPointGEO = document.getElementById("inputPointGEO");
	var inputPointUTM = document.getElementById("inputPointUTM");
	var inputCRSHuso = document.getElementById("inputCRSHuso");
	var inputHuso = document.getElementById("inputHuso");
	
	// Deshabilitamos boton de transformar
	disenableButton(document.getElementById('transformPoint'),false);		
	
	if ( sourceCRS.options[sourceCRS.selectedIndex].value.indexOf("UTM") == -1 )
	{
		/* Geodesicas */
		inputPointUTM.style.display = "none";
		inputCRSHuso.style.display = "none";
		if ( inputPointGEO.style.display == "none" )
		{
			document.getElementById("inputLatitudeDegree").value = '';
			document.getElementById("inputLatitudeMinutes").value = '';
			document.getElementById("inputLatitudeSeconds").value = '';
			document.getElementById("inputLongitudeDegree").value = '';
			document.getElementById("inputLongitudeMinutes").value = '';
			document.getElementById("inputLongitudeSeconds").value = '';
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';		
			inputPointGEO.style.display = "block";
		}	
		else
			changeInputLatitudeDegree();
	}
	else
	{
		/* UTM */
		inputPointGEO.style.display = "none";
		if ( inputPointUTM.style.display == "none" )
		{
			document.getElementById("inputX").value = '';
			document.getElementById("inputY").value = '';
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
			inputPointUTM.style.display = "block";	
			inputCRSHuso.style.display = "block";
		}	
		else
			changeInputX();
		// Marcamos por defecto el huso 30
		for ( var a = 0; a < inputHuso.options.length; a++ )
		{
			if ( inputHuso.options[a].value == "30" )
			{
				inputHuso.selectedIndex = a;
				break;
			}
		}		
	}
	
	// Ponemos de nuevo el combo porque IE no permite deshabilitar la opci�n an�loga del targetCRSCombo
	if ( targetCRS )
	{
		while ( targetCRS.options.length > 0 )
			targetCRS.remove(0);
			
		for ( var a = 0; a < targetCRSLabel.length; a++ )
		{
		
			if ( targetCRSValue[a] != sourceCRS.options[sourceCRS.selectedIndex].value )
			{
				var option = document.createElement('option');
	  			option.text = targetCRSLabel[a];
	  			option.value = targetCRSValue[a];
				try
				{
					targetCRS.add(option,null); // standards compliant
	    		}
				catch(ex)
				{
					targetCRS.add(option); // IE only
				}	
			}		
		}
		
		changeTargetCRS();
	}
	
}	

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del combo target CRS
function changeTargetCRS()
{
	var sourceCRS = document.getElementById("sourceCRSCombo");
	var targetCRS = document.getElementById("targetCRSCombo");
	var outputPointGEO = document.getElementById("outputPointGEO");
	var outputPointUTM = document.getElementById("outputPointUTM");
	var outputCRSHuso = document.getElementById("outputCRSHuso");
	var outputHuso = document.getElementById("outputHuso");	
	
	if ( targetCRS.options[targetCRS.selectedIndex].value.indexOf("UTM") == -1 )
	{
		/* Geodesicas */
		outputPointUTM.style.display = "none";
		outputCRSHuso.style.display = "none";
		if ( outputPointGEO.style.display == "none" )
		{
			document.getElementById("outputLatitudeDegree").value = '';
			document.getElementById("outputLatitudeMinutes").value = '';
			document.getElementById("outputLatitudeSeconds").value = '';
			document.getElementById("outputLatitudeNS").value = '';	
			document.getElementById("outputLongitudeDegree").value = '';
			document.getElementById("outputLongitudeMinutes").value = '';
			document.getElementById("outputLongitudeSeconds").value = '';
			document.getElementById("outputLongitudeEO").value = '';				
			outputPointGEO.style.display = "block";
		}	
	}
	else
	{
		/* UTM */
		outputPointGEO.style.display = "none";
		if ( outputPointUTM.style.display == "none" )
		{
			document.getElementById("outputX").value = '';
			document.getElementById("outputY").value = '';		
			outputPointUTM.style.display = "block";	
			outputCRSHuso.style.display = "block";
		}	
		
		if ( sourceCRS.options[sourceCRS.selectedIndex].value.indexOf("UTM") == -1 )
		{
			// Marcamos por defecto el huso 30 si el source es geodesicas
			for ( var a = 0; a < outputHuso.options.length; a++ )
			{
				if ( outputHuso.options[a].value == "30" )
				{
					outputHuso.selectedIndex = a;
					break;
				}
			}	
			// Intentamos poner otro si la longutid esta rellena
			setTargetTimeZone();
		}
		else
		{
			// Marcamos el mismo huso que el source
			changeSourceHuso()
		}			
	}
}

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del combo source Huso
function changeSourceHuso()
{
	var targetCRS = document.getElementById("targetCRSCombo");
	var outputHuso = document.getElementById("outputHuso");
	var inputHuso = document.getElementById("inputHuso");
	
	if ( targetCRS.options[targetCRS.selectedIndex].value.indexOf("UTM") != -1 )
	{
		/* UTM */
		// Marcamos el mismo huso que el fuente
		for ( var a = 0; a < outputHuso.options.length; a++ )
		{
			if ( outputHuso.options[a].value == inputHuso.options[inputHuso.selectedIndex].value )
			{
				outputHuso.selectedIndex = a;
				break;
			}
		}	
	}

}

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del combo target Huso
function changeTargetHuso()
{
	var sourceCRS = document.getElementById("sourceCRSCombo");
	var outputHuso = document.getElementById("outputHuso");
	var inputHuso = document.getElementById("inputHuso");
	
	if ( sourceCRS.options[sourceCRS.selectedIndex].value.indexOf("UTM") != -1 )
	{
		/* UTM */
		// Marcamos el mismo huso que el fuente
		for ( var a = 0; a < inputHuso.options.length; a++ )
		{
			if ( inputHuso.options[a].value == outputHuso.options[outputHuso.selectedIndex].value )
			{
				inputHuso.selectedIndex = a;
				break;
			}
		}	
	}

}
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo X de entrada
function changeInputX()
{
	// Comprobamos si es un real valido
	var inputX = document.getElementById("inputX").value;
	
	if (!checkFloat(inputX))
	{
		// No lo es
		validInputX = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o longitud es valido
		if ( document.getElementById('inputX').value.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectX"];
		else
		{
			if ( validInputY || (!validInputY && (document.getElementById('inputY').value.length == 0)) )
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
			else
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectY"];
		}		
	}	
	else
	{
		// Si lo es
		validInputX = true;
		if ( validInputY )
		{
			// Longitud tambien valida, habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Longitud no valida, deshabilitamos boton y ponemos error si longitud no vacia
			disenableButton(document.getElementById('transformPoint'),false);
			if ( document.getElementById('inputY').value.length > 0 )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectY"];
			else
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}	
	}

}
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Y de entrada
function changeInputY()
{
	// Comprobamos si es un real valido
	var inputY = document.getElementById("inputY").value;
	
	if (!checkFloat(inputY))
	{
		// No lo es
		validInputY = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o latitud es valido
		if ( document.getElementById('inputY').value.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectY"];
		else
		{
			if ( validInputX || (!validInputX && (document.getElementById('inputX').value.length == 0)) )
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
			else
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectX"];
		}	
	}	
	else
	{
		// Si lo es
		validInputY= true;
		if ( validInputX )
		{
			// Latitud tambien valida, habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Latitud no valida, deshabilitamos boton y ponemos error si latitud no vacia
			disenableButton(document.getElementById('transformPoint'),false);
			if ( document.getElementById('inputX').value.length > 0 )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectX"];
			else
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
	}

}	
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Grados de la latitud de entrada
function changeInputLatitudeDegree()
{
	// Comprobamos si es un entero positivo valido
	var inputLatitudeDegree = document.getElementById("inputLatitudeDegree").value;
	
	if (!checkPositiveInteger(inputLatitudeDegree))
	{
		// No lo es
		validInputLatitudeDegree = false;
		validInputLatitude = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o longitud es valido
		if ( inputLatitudeDegree.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];
		else
		{
			if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];
			else if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];	
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];		
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
				
		}		
	}	
	else
	{
		// Si lo es
		validInputLatitudeDegree = true;
		if ( validInputLatitudeMinutes && validInputLatitudeSeconds )
			validInputLatitude = true;
		if ( validInputLatitude && validInputLongitude )
		{
			// Habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Deshabilitamos boton y ponemos error si longitud no vacia
			disenableButton(document.getElementById('transformPoint'),false);
			if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];
			else if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];	
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];		
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
	}

}	

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Minutos de la latitud de entrada
function changeInputLatitudeMinutes()
{
	// Comprobamos si es un entero positivo valido
	var inputLatitudeMinutes = document.getElementById("inputLatitudeMinutes").value;
	
	if (!checkSexagesimalPositiveInteger(inputLatitudeMinutes))
	{
		// No lo es
		validInputLatitudeMinutes = false;
		validInputLatitude = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o longitud es valido
		if ( inputLatitudeMinutes.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];
		else
		{
			if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];
			else if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];	
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];		
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
				
		}		
	}	
	else
	{
		// Si lo es
		validInputLatitudeMinutes = true;
		if ( validInputLatitudeDegree && validInputLatitudeSeconds )
			validInputLatitude = true;
		if ( validInputLatitude && validInputLongitude )
		{
			// Habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Deshabilitamos boton y ponemos error si longitud no vacia
			disenableButton(document.getElementById('transformPoint'),false);
			if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];
			else if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];	
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];		
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
	}

}
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Segundos de la latitud de entrada
function changeInputLatitudeSeconds()
{
	// Comprobamos si es un real positivo valido
	var inputLatitudeSeconds = document.getElementById("inputLatitudeSeconds").value;
	
	if (!checkSexagesimalPositiveFloat(inputLatitudeSeconds))
	{
		// No lo es
		validInputLatitudeSeconds = false;
		validInputLatitude = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o los demas son valido
		if ( inputLatitudeSeconds.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];
		else
		{
			if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];
			else if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];	
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];		
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
				
		}		
	}	
	else
	{
		// Si lo es
		validInputLatitudeSeconds = true;
		if ( validInputLatitudeDegree && validInputLatitudeMinutes )
			validInputLatitude = true;
		if ( validInputLatitude && validInputLongitude )
		{
			// Habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Deshabilitamos boton y ponemos error
			disenableButton(document.getElementById('transformPoint'),false);
			if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];
			else if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];	
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];		
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
	}

}	
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Grados de la longitud de entrada
function changeInputLongitudeDegree()
{
	// Comprobamos si es un entero positivo valido
	var inputLongitudeDegree = document.getElementById("inputLongitudeDegree").value;
	var targetCRS = document.getElementById("targetCRSCombo");
	var outputHuso = document.getElementById("outputHuso");
	
	if (!checkPositiveInteger(inputLongitudeDegree))
	{
		// No lo es
		validInputLongitudeDegree = false;
		validInputLongitude = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o longitud es valido
		if ( inputLongitudeDegree.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];
		else
		{
			if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];
			else if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];	
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];		
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
				
		}		
	}	
	else
	{
		// Si lo es
		validInputLongitudeDegree = true;
		if ( validInputLongitudeMinutes && validInputLongitudeSeconds )
			validInputLongitude = true;
		if ( validInputLatitude && validInputLongitude )
		{
			// Habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Deshabilitamos boton y ponemos error si longitud no vacia
			disenableButton(document.getElementById('transformPoint'),false);
			if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];
			else if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];	
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];		
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
		
	}
	
	// Ponemos el huso destino si necesario
	setTargetTimeZone();

}	

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Minutos de la longitud de entrada
function changeInputLongitudeMinutes()
{
	// Comprobamos si es un entero positivo valido
	var inputLongitudeMinutes = document.getElementById("inputLongitudeMinutes").value;
	
	if (!checkSexagesimalPositiveInteger(inputLongitudeMinutes))
	{
		// No lo es
		validInputLongitudeMinutes = false;
		validInputLongitude = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o longitud es valido
		if ( inputLongitudeMinutes.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];
		else
		{
			if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];
			else if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];	
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];		
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
				
		}		
	}	
	else
	{
		// Si lo es
		validInputLongitudeMinutes = true;
		if ( validInputLongitudeDegree && validInputLongitudeSeconds )
			validInputLongitude = true;
		if ( validInputLatitude && validInputLongitude )
		{
			// Habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Deshabilitamos boton y ponemos error
			disenableButton(document.getElementById('transformPoint'),false);
			if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];
			else if ( !validInputLongitudeSeconds && ( document.getElementById('inputLongitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];
			else if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];	
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];		
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
	}

	// Ponemos el huso destino si necesario
	setTargetTimeZone();

}
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Segundos de la longitud de entrada
function changeInputLongitudeSeconds()
{
	// Comprobamos si es un entero positivo valido
	var inputLongitudeSeconds = document.getElementById("inputLongitudeSeconds").value;
	
	if (!checkSexagesimalPositiveFloat(inputLongitudeSeconds))
	{
		// No lo es
		validInputLongitudeSeconds = false;
		validInputLongitude = false;
		// Deshabilitamos boton de transformar
		disenableButton(document.getElementById('transformPoint'),false);
		// Ponemos el error correspondiente o vacio si los dos estan vacios o longitud es valido
		if ( inputLongitudeSeconds.length > 0 )
			document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeSeconds"];
		else
		{
			if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];
			else if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];	
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];		
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
				
		}		
	}	
	else
	{
		// Si lo es
		validInputLongitudeSeconds = true;
		if ( validInputLongitudeDegree && validInputLongitudeMinutes )
			validInputLongitude = true;
		if ( validInputLatitude && validInputLongitude )
		{
			// Habilitamos boton y quitamos error si hay
			disenableButton(document.getElementById('transformPoint'),true);
			document.getElementById('errorInputPoint').innerHTML = '&nbsp;';
		}
		else
		{
			// Deshabilitamos boton y ponemos error
			disenableButton(document.getElementById('transformPoint'),false);
			if ( !validInputLongitudeDegree && ( document.getElementById('inputLongitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeDegree"];
			else if ( !validInputLongitudeMinutes && ( document.getElementById('inputLongitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLongitudeMinutes"];
			else if ( !validInputLatitudeDegree && ( document.getElementById('inputLatitudeDegree').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeDegree"];	
			else if ( !validInputLatitudeMinutes && ( document.getElementById('inputLatitudeMinutes').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeMinutes"];		
			else if ( !validInputLatitudeSeconds && ( document.getElementById('inputLatitudeSeconds').value.length > 0 ) )
				document.getElementById('errorInputPoint').innerHTML = messages["incorrectLatitudeSeconds"];									
			else	
				document.getElementById('errorInputPoint').innerHTML = '&nbsp;';	
		}	
	}

	// Ponemos el huso destino si necesario
	setTargetTimeZone();

}

//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo Origen de la longitud de entrada
function changeInputLongitudeEO()
{
	setTargetTimeZone();
}
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo URL de entrada
function changeInputURL()
{
	
	// Comprobamos si sintacticamente es una URL
	if (!validateURL(document.getElementById("inputURL").value))
	{
		// No lo es
		validInputURL = false;
		disenableButton(document.getElementById('transformURL'),false);
		if (document.getElementById("inputURL").value.length > 0)
			document.getElementById('errorInputURL').innerHTML = messages["incorrectURL"];
		else
			document.getElementById('errorInputURL').innerHTML = '&nbsp;';	
	}	
	else
	{
		// Lo es
		validInputURL = true;
		if (!loadingOutputURL)
			disenableButton(document.getElementById('transformURL'),true);
		document.getElementById('errorInputURL').innerHTML = '&nbsp;';	
	}

}		
	
//-----------------------------------------------------------------------------
// Accion a realizar cuando cambia el valor del campo GML de entrada
function changeInputGML()
{
	
	//Validamos el gml
	var gml = document.getElementById("inputGML").value;

	if ( (gml==null) || (gml==""))
	{
		// Vacio
		validInputGML = false;
		document.getElementById('errorInputGML').innerHTML = '&nbsp;';
		disenableButton(document.getElementById('transformGML'),false);
		return false;
	}	

	// Intentamos crear un xmlDocument a partir de el texto introducido
	var xmlDocument = loadXMLFromString(gml);

	if ( xmlDocument == null )	
	{
		// No es codigo xml
		validInputGML = false;
		document.getElementById('errorInputGML').innerHTML = messages["noXML"];
		disenableButton(document.getElementById('transformGML'),false);
		return false;
	}	
	else if ( (typeof(xmlDocument) == "number") && xmlDocument == -1 )	
	{
		// No se puede crear el xmlDocument por incompatibilidad del navegador	
		validInputGML = false;
		document.getElementById('errorInputGML').innerHTML = messages["browserNotCompatible"];
		disenableButton(document.getElementById('transformGML'),false);		
		return false;
	}
	
	// Validado
	validInputGML = true;
	document.getElementById('errorInputGML').innerHTML = '&nbsp;';
	if (!loadingOutputURL)
		disenableButton(document.getElementById('transformGML'),true);	

}		

//-----------------------------------------------------------------------------
// Comprueba si en la respuesta el servidor comunica de un error y lo muestra
function checkServerError(xmlDocument)
{

	//Miramos si hay nodo ServiceException
	var serviceException = xmlDocument.getElementsByTagName('ServiceException');

	if (serviceException.length > 0)
	{

		//Obtenemos los atributos locator, code y el mensaje
		//Lo que no sea null se pone en el alert
	
		var locator = serviceException.item(0).attributes.getNamedItem('locator');
		var code = serviceException.item(0).attributes.getNamedItem('code');
		var text = serviceException.item(0).firstChild;
		
		var error = messages["transformationError"];
		
		if (locator)
			error += "\n" + messages["locator"] + ": " + locator.nodeValue;
		if (code)
			error += "\n" + messages["code"] + ": " + code.nodeValue;			
		if (text)
			error += "\n" + messages["message"] + ": " + text.nodeValue;		
		
		alert(error);
		
		return true;
	}	

	return false;
}

//-----------------------------------------------------------------------------
// Parsea la respuesta del servidor y pone las coordenadas del punto
function parsePoint(xmlDocument)
{

	//Comprobamos si hay errores
	if (checkServerError(xmlDocument))
		return false;

	//Extraemos las coordenadas
	var coordinates;
	if ( xmlDocument.getElementsByTagName('gml:coordinates').item(0) )
		coordinates = xmlDocument.getElementsByTagName('gml:coordinates').item(0).firstChild.nodeValue;
	else
		coordinates = xmlDocument.getElementsByTagName('coordinates').item(0).firstChild.nodeValue;
	
	var x = coordinates.substring(0,coordinates.indexOf(','));
	var y = coordinates.substring(coordinates.indexOf(',')+1);
	
	var targetCRSCombo = document.getElementById("targetCRSCombo");
	var targetCRSValue = targetCRSCombo.options[targetCRSCombo.selectedIndex].value;	

	if ( targetCRSValue.indexOf("UTM") == -1 )
	{	
		/* Geodesicas */
		//Las mostramos
		var latitude = new degree(y,GEO_DECIMALS);
		document.getElementById("outputLatitudeDegree").value = latitude.degrees;
		document.getElementById("outputLatitudeMinutes").value = latitude.minutes;	
		document.getElementById("outputLatitudeSeconds").value = ('' + latitude.seconds).replace(/\./,",");
		document.getElementById("outputLatitudeNS").value = decimal2degree_NS(y);
		var longitude = new degree(x,GEO_DECIMALS);
		document.getElementById("outputLongitudeDegree").value = longitude.degrees;
		document.getElementById("outputLongitudeMinutes").value = longitude.minutes;
		document.getElementById("outputLongitudeSeconds").value = ('' + longitude.seconds).replace(/\./,",");
		document.getElementById("outputLongitudeEO").value = decimal2degree_EO(x);				
	}
	else
	{
		/* UTM */
		//Las mostramos
		document.getElementById("outputX").value = ('' + round(parseFloat(x), UTM_DECIMALS)).replace(/\./,",");
		document.getElementById("outputY").value = ('' + round(parseFloat(y), UTM_DECIMALS)).replace(/\./,",");		
	}
	
}

//-----------------------------------------------------------------------------
// Accion a realizar tras la peticion de transformacion para punto
function handlerWhenLoadedPoint(http_request)
{	
	try
	{
		if ( http_request.readyState == 4 )
		{
			if ( http_request.status == 200 )
			{
				//alert(http_request.responseText);
				// Parseamos la respuesta y la mostramos
				parsePoint(http_request.responseXML);	
			}
			else
			{
				//alert("responseError1");
				alert(messages["responseError"]);
			}
			document.getElementById('loadingPoint').style.visibility = "hidden";
			disenableButton(document.getElementById('transformPoint'),true);
		}
	}
	catch(e)
	{
		//alert(e);
		//alert("responseError2");
		document.getElementById('loadingPoint').style.visibility = "hidden";
		disenableButton(document.getElementById('transformPoint'),true);
		alert(messages["responseError"]);
	}
}		

//-----------------------------------------------------------------------------
// Crea la petion para transformar las coordenadas de un punto
function createWCTSPointRequest(sourceCRS,targetCRS, srsName, x,y)
{

	// Creamos una feature collection con una feature ficticia con una propiedad de tipo punto
	pointRequest = "<?xml version=\"1.0\"?>" +
		"<Transform " +
			"xmlns=\"http://www.opengeospatial.net/wcts\" " + 
			"xmlns:gml=\"http://www.opengis.net/gml\" " + 
			"service=\"" + WCTS_SERVICE + "\" version=\"" + WCTS_VERSION + "\">" +
				"<SourceCRS>" + sourceCRS + "</SourceCRS>" +
				"<TargetCRS>" + targetCRS + "</TargetCRS>" +
				"<InputData>" +
					"<gml:FeatureCollection>" +
						"<gml:featureMember>" +
							"<Point>" +
								"<gml:pointProperty>" +
									"<gml:Point srsName=\"" + srsName + "\">" +
										"<gml:pos srsDimension=\"2\">"+ x + " " + y + "</gml:pos>" +
									"</gml:Point>" +
								"</gml:pointProperty>" +
							"</Point>" +
						"</gml:featureMember>" +
					"</gml:FeatureCollection>" +
				"</InputData>" +
				"<OutputFormat>" + WCTS_OUTPUT_FORMAT + "</OutputFormat>" +
		"</Transform>";

	return pointRequest;	
}

//-----------------------------------------------------------------------------
// Construye el CRS en formato WCTS
function constructCRS(prefix, CRSValue, huso)
{
	var CRSValue2 = prefix;
	if ( CRSValue.indexOf("UTM") == -1 )
	{
		/* Geodesicas */
		CRSValue2 += "42";
		if ( CRSValue.indexOf("ED50") != -1 ) 
			CRSValue2 += "30";
		else
			CRSValue2 += "58";	
	}
	else
	{
		/* UTM */
		if ( CRSValue.indexOf("ED50") != -1 ) 
			CRSValue2 += "230";
		else
			CRSValue2 += "258";	
		CRSValue2 += huso;		
	}
	return CRSValue2;	
}

//-----------------------------------------------------------------------------
// Transforma las coordenadas de un punto
function transformPoint()
{
/*
	//Validamos las coordenadas introducidas
	latitude = document.getElementById("inputLatitude").value;
	
	if (!checkFloat(latitude))
	{
		alert(messages["incorrectLatitude"]);
		return false;
	}	
	longitude = document.getElementById("inputLongitude").value;
	if (!checkFloat(longitude))
	{
		alert(messages["incorrectLongitude"]);
		return false;
	}	
*/
	
	var x;
	var y;
	var sourceCRS;
	var targetCRS;
	var srsName;
	
	var sourceCRSCombo = document.getElementById("sourceCRSCombo");
	var sourceCRSValue = sourceCRSCombo.options[sourceCRSCombo.selectedIndex].value;	
	var sourceHusoCombo = document.getElementById("inputHuso");
	var sourceHusoValue = sourceHusoCombo.options[sourceHusoCombo.selectedIndex].value;

	var targetCRSCombo = document.getElementById("targetCRSCombo");
	var targetCRSValue = targetCRSCombo.options[targetCRSCombo.selectedIndex].value;	
	var targetHusoCombo = document.getElementById("outputHuso");
	var targetHusoValue = targetHusoCombo.options[targetHusoCombo.selectedIndex].value;

	if ( sourceCRSCombo.options[sourceCRSCombo.selectedIndex].value.indexOf("UTM") == -1 )
	{
		/* Geodesicas */
		var inputLatitudeDegreeValue = document.getElementById("inputLatitudeDegree").value;
		var inputLatitudeMinutesValue = document.getElementById("inputLatitudeMinutes").value;
		var inputLatitudeSecondsValue = (document.getElementById("inputLatitudeSeconds").value).replace(/,/,".");
		var inputLatitudeNSCombo = document.getElementById("inputLatitudeNS");
		var inputLatitudeNSValue = inputLatitudeNSCombo.options[inputLatitudeNSCombo.selectedIndex].value;
		
		var inputLongitudeDegreeValue = document.getElementById("inputLongitudeDegree").value;
		var inputLongitudeMinutesValue = document.getElementById("inputLongitudeMinutes").value;
		var inputLongitudeSecondsValue = (document.getElementById("inputLongitudeSeconds").value).replace(/,/,".");
		var inputLongitudeEOCombo = document.getElementById("inputLongitudeEO");
		var inputLongitudeEOValue = inputLongitudeEOCombo.options[inputLongitudeEOCombo.selectedIndex].value;			
		
		y = degree2decimal(inputLatitudeDegreeValue, inputLatitudeMinutesValue, inputLatitudeSecondsValue, inputLatitudeNSValue);
		x = degree2decimal(inputLongitudeDegreeValue, inputLongitudeMinutesValue, inputLongitudeSecondsValue, inputLongitudeEOValue);
			
		sourceCRS = constructCRS(CRS_WCTS_PREFIX, sourceCRSValue);	
		srsName = constructCRS(CRS_GML_PREFIX, sourceCRSValue);
	}
	else
	{
		/* UTM */
		var inputX = document.getElementById("inputX").value;
		var inputY = document.getElementById("inputY").value;
		
		x = inputX.replace(/,/,".");
		y = inputY.replace(/,/,".");
		
		sourceCRS = constructCRS(CRS_WCTS_PREFIX, sourceCRSValue, sourceHusoValue);
		srsName = constructCRS(CRS_GML_PREFIX, sourceCRSValue, sourceHusoValue);		
	}	
			

	if ( targetCRSCombo.options[targetCRSCombo.selectedIndex].value.indexOf("UTM") == -1 )
	{
		/* Geodesicas */
		
		// Borramos la salida
		
		document.getElementById("outputLatitudeDegree").value = '';
		document.getElementById("outputLatitudeMinutes").value = '';
		document.getElementById("outputLatitudeSeconds").value = '';
		document.getElementById("outputLatitudeNS").value = '';
		
		document.getElementById("outputLongitudeDegree").value = '';
		document.getElementById("outputLongitudeMinutes").value = '';
		document.getElementById("outputLongitudeSeconds").value = '';
		document.getElementById("outputLongitudeEO").value = '';	
			
		targetCRS = constructCRS(CRS_WCTS_PREFIX, targetCRSValue);	
	}
	else
	{
		/* UTM */
		
		// Borramos la salida
		document.getElementById("outputX").value = '';
		document.getElementById("outputY").value = '';
		
		targetCRS = constructCRS(CRS_WCTS_PREFIX, targetCRSValue, targetHusoValue);		
	}	
	
	//Creamos la peticion
	pointRequest = createWCTSPointRequest(sourceCRS,targetCRS,srsName,x,y);
	
	//Realizamos la peticion
	if (!sendAJAX(WCTS_URL,"POST",handlerWhenLoadedPoint,pointRequest,'text/xml',false))
		alert(messages["requestError"]);	
	else
	{
		document.getElementById('loadingPoint').style.visibility = "visible";
		disenableButton(document.getElementById('transformPoint'),false);
	}	
}

//-----------------------------------------------------------------------------
// Deshabilitamos la posibilidad de transformacion cuyo resultado sea una URL
// por encontrarse otra en proceso
function disableOutputURLTransformation()
{
	loadingOutputURL = true;
	disenableButton(document.getElementById('transformURL'),false);
	disenableButton(document.getElementById('transformGML'),false);		
}

//-----------------------------------------------------------------------------
// Habilitamos la posibilidad de transformacion cuyo resultado sea una URL por
// haber terminado la anterior
function enableOutputURLTransformation()
{
	loadingOutputURL = false;
	if ( validInputURL )
		disenableButton(document.getElementById('transformURL'),true);
	if ( validInputGML )
		disenableButton(document.getElementById('transformGML'),true);		
}

//-----------------------------------------------------------------------------
// Accion a realizar tras la peticion de chequeo de URL
var existentURL = null;

function handlerWhenLoadedExistentInputURL(http_request)
{	
	try
	{
		if ( http_request.readyState == 4 )
		{
			document.getElementById('loadingURL').style.visibility = "hidden";			
			disenableButton(document.getElementById('transformURL'),true);				
			if ( http_request.status == 200 )
			{
				// Si en la respuesta esta la cadena 'true' existe
				existentURL = eval(http_request.responseText);	
				transformURL2();	
			}
			else
			{
				//alert("responseError1");
				enableOutputURLTransformation();
				alert(messages["responseError"]);
			}
		}
	}
	catch(e)
	{
		alert(messages["responseError"]);
		document.getElementById('loadingURL').style.visibility = "hidden";		
		disenableButton(document.getElementById('transformURL'),true);	
		enableOutputURLTransformation();
	}
}

function handlerWhenLoadedExistentOutputURL(http_request)
{	
	try
	{
		if ( http_request.readyState == 4 )
		{
			if ( http_request.status == 200 )
			{
				// Si en la respuesta esta la cadena 'true' existe
				existentURL = eval(http_request.responseText);	
				downloadURL2();
			}
			else
			{
				//alert("responseError1");
				enableOutputURLTransformation();
				alert(messages["responseError"]);
			}
			document.getElementById('loadingURL').style.visibility = "hidden";
		}
	}
	catch(e)
	{
		alert(messages["responseError"]);
		document.getElementById('loadingURL').style.visibility = "hidden";	
		disenableButton(document.getElementById('transformURL'),true);	
		enableOutputURLTransformation();
	}
}

//-------------------------------------------------------------------------------------------------------------------------------
// Realiza la peticion para ver si la URL de entrada existe
function checkInputURL( url )
{	

	existentURL = null;
	
	//Realizamos la peticion
	if (!sendAJAX("checkLink.jsp","POST",handlerWhenLoadedExistentInputURL,"url=" + url,"application/x-www-form-urlencoded",false))
	{
		alert(messages["requestError"]);		
		return false;
	}
	
	return true;
}

//-------------------------------------------------------------------------------------------------------------------------------
// Realiza la peticion para ver si la URL de salida existe
function checkOutputURL( url )
{	

	existentURL = null;
	
	//Realizamos la peticion
	if (!sendAJAX("checkLink.jsp","POST",handlerWhenLoadedExistentOutputURL,"url=" + url,"application/x-www-form-urlencoded",false))
	{
		alert(messages["requestError"]);		
		return false;
	}
	
	return true;
}

//-----------------------------------------------------------------------------
// Parsea la respuesta del servidor y pone la URL de respuesta
function parseURL(xmlDocument)
{

	//Comprobamos si hay errores
	if (checkServerError(xmlDocument))
		return false;

	//Extraemos las URL
	var url = xmlDocument.getElementsByTagName('Reference').item(0).attributes.getNamedItem('xlink:href').nodeValue;
	
	//La mostramos
	document.getElementById("outputURL").value = url;
	disenableButton(document.getElementById('downloadURL'),true);
	document.getElementById('errorOutputURL').innerHTML = '&nbsp';
}

//-----------------------------------------------------------------------------
// Accion a realizar tras la peticion de transformacion para URL
function handlerWhenLoadedURL(http_request)
{	
	try
	{
		if ( http_request.readyState == 4 )
		{
			if ( http_request.status == 200 )
			{
				var xmlDocument = http_request.responseXML;

				if ( (document.all) && (http_request.getResponseHeader('Content-Type')=="application/vnd.ogc.se_xml") )
				{
					//Explorer si el Content-Type no es text/xml no crea el xmlDocument
					xmlDocument = loadXMLFromString(http_request.responseText);
					if (xmlDocument == null)
					{
						alert(messages["responseError"]);
						return false;
					}						
				}

				// Parseamos la respuesta y ponemos la URL
				parseURL(xmlDocument);	
			}
			else
			{
				//alert("responseError1");
				alert(messages["responseError"]);
			}
			document.getElementById('loadingURL').style.visibility = "hidden";			
			enableOutputURLTransformation();		
			
		}
	}
	catch(e)
	{	
		document.getElementById('loadingURL').style.visibility = "hidden";		
		disenableButton(document.getElementById('transformURL'),true);	
		enableOutputURLTransformation();
		//alert(e);
		//alert("responseError2");
		alert(messages["responseError"]);
	}
}

//-----------------------------------------------------------------------------
// Crea la petion para transformar una url que contiene un GML
function createWCTSURLRequest(sourceCRS,targetCRS,url)
{
	
	var outputFormat = WCTS_OUTPUT_FORMAT + ((WCTS_RESPONSE_CHARSET!=null)?("; charset=" + WCTS_RESPONSE_CHARSET):"");
	
	// Creamos una peticion con una referencia con la url
	var urlRequest = "<?xml version=\"1.0\"?>" +
		"<Transform " +
			"xmlns=\"http://www.opengeospatial.net/wcts\" " + 
			"xmlns:gml=\"http://www.opengis.net/gml\" " + 
			"service=\"" + WCTS_SERVICE + "\" version=\"" + WCTS_VERSION + "\" store=\"true\" >" +
				"<SourceCRS>" + sourceCRS + "</SourceCRS>" +
				"<TargetCRS>" + targetCRS + "</TargetCRS>" +
				"<InputData>" +
					"<Reference xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"" + url + "\"/>" +
				"</InputData>" +
				"<OutputFormat>" + outputFormat  + "</OutputFormat>" +
		"</Transform>";

	return urlRequest;	
}

//-----------------------------------------------------------------------------
// Transforma las coordenadas de una URL
function transformURL()
{
/*
	//Validamos la url
	var url = document.getElementById("inputURL").value;
	if (!validateURL(url))
	{
		alert(messages["incorrectURL"]);
		return false;
	}	
	if (!checkURL(url))
	{
		alert(messages["nonexistentURL"]);
		return false;
	}
*/	


	// Borramos el campo URL de salida
	document.getElementById('outputURL').value = '';
	disenableButton(document.getElementById('downloadURL'),false);
	document.getElementById('errorOutputURL').innerHTML = '&nbsp';
	// Limpiamos el error
	document.getElementById('errorInputURL').innerHTML = '&nbsp;';

	// Deshabilitamos el boton
	disenableButton(document.getElementById('transformURL'),false);
	// Ponemos mensaje de cargando mientras chequea URL
	document.getElementById('loadingURL').style.visibility = "visible";
	disableOutputURLTransformation();
	
	// Chequeamos la URL
	var url = document.getElementById("inputURL").value;
	if (!checkInputURL(url))
	{
		// Escondemos mensaje de cargando
		document.getElementById('loadingURL').style.visibility = "hidden";
		enableOutputURLTransformation();	
		return false;
	}	

}

function transformURL2()
{

	var url = document.getElementById("inputURL").value;
	
	// Cambiamos & (si no compone una HTML entity) por &amp; 
	url = url.replace(/\x26(?![a-zA-Z]+;)/g,"&amp;");

	if ( existentURL == false )
	{
		// Escondemos mensaje de cargando
		document.getElementById('loadingURL').style.visibility = "hidden";	
		document.getElementById('errorInputURL').innerHTML = messages["nonexistentURL"];
		enableOutputURLTransformation();
		return false;	
	}

	// Escondemos mensaje de cargando
	document.getElementById('loadingURL').style.visibility = "hidden";

	// Extraemos las CRS fuente y destino
	
	var sourceCRS;
	var targetCRS;
	
	var sourceCRSCombo = document.getElementById("sourceCRSCombo");
	var sourceCRSValue = sourceCRSCombo.options[sourceCRSCombo.selectedIndex].value;	
	var sourceHusoCombo = document.getElementById("inputHuso");
	var sourceHusoValue = sourceHusoCombo.options[sourceHusoCombo.selectedIndex].value;

	var targetCRSCombo = document.getElementById("targetCRSCombo");
	var targetCRSValue = targetCRSCombo.options[targetCRSCombo.selectedIndex].value;	
	var targetHusoCombo = document.getElementById("outputHuso");
	var targetHusoValue = targetHusoCombo.options[targetHusoCombo.selectedIndex].value;

	if ( sourceCRSCombo.options[sourceCRSCombo.selectedIndex].value.indexOf("UTM") == -1 )
		sourceCRS = constructCRS(CRS_WCTS_PREFIX, sourceCRSValue);	
	else
		sourceCRS = constructCRS(CRS_WCTS_PREFIX, sourceCRSValue, sourceHusoValue);			
			
	if ( targetCRSCombo.options[targetCRSCombo.selectedIndex].value.indexOf("UTM") == -1 )
		targetCRS = constructCRS(CRS_WCTS_PREFIX, targetCRSValue);		
	else
		targetCRS = constructCRS(CRS_WCTS_PREFIX, targetCRSValue, targetHusoValue);		
	
	
	//Creamos la peticion
	urlRequest = createWCTSURLRequest(sourceCRS,targetCRS,url);

	//Realizamos la peticion
	if (!sendAJAX(WCTS_URL,"POST",handlerWhenLoadedURL,urlRequest,'text/xml',false))
	{
		enableOutputURLTransformation();
		alert(messages["requestError"]);
	}	
	else
	{
		document.getElementById('loadingURL').style.visibility = "visible";		
		disenableButton(document.getElementById('transformURL'),false);
	}		
	
	return true;
	
}

//-----------------------------------------------------------------------------
// Descarga el fichero XML representado por la URL
function downloadURL()
{
	var url = document.getElementById("outputURL").value;
	
	// Deshabilitamos boton y ponemos cargando
	disenableButton(document.getElementById('downloadURL'),false);
	document.getElementById('loadingURL').style.visibility = "visible";
	document.getElementById('errorOutputURL').innerHTML = '&nbsp';
	disableOutputURLTransformation();
	
	// Validamos y chequeamos la URL
	if (!validateURL(url))
	{
		document.getElementById('loadingURL').style.visibility = "hidden";	
		document.getElementById('errorOutputURL').innerHTML = messages["downloadIncorrectURL"];
		disenableButton(document.getElementById('downloadURL'),false);
		enableOutputURLTransformation();
		return false;
	}	
	if (!checkOutputURL(url))
	{
		document.getElementById('loadingURL').style.visibility = "hidden";	
		disenableButton(document.getElementById('downloadURL'),false);
		enableOutputURLTransformation();
		return false;	
	}	
}

function downloadURL2()
{
	var url = document.getElementById("outputURL").value;
	
	if ( existentURL == false )
	{
		// Escondemos mensaje de cargando
		document.getElementById('loadingURL').style.visibility = "hidden";	
		document.getElementById('errorOutputURL').innerHTML = messages["downloadNonexistentURL"];
		enableOutputURLTransformation();
		return false;	
	}	
	
	// Pasamos por post la url al jsp que descarga el archivo y ponemos de target el iframe
	// para que no nos abra otra ventana o nos fastidie la que tenemos
	//document.getElementById('downloadLink').src = "downloadLink.jsp?url=" + url;
	document.getElementById('downloadLinkFormURL').value = url;
	document.getElementById('downloadLinkFormFileName').value = '';
	document.getElementById('downloadLinkForm').submit();
	
	// Habilitamos y ponemos cargando
	document.getElementById('loadingURL').style.visibility = "hidden";
	disenableButton(document.getElementById('downloadURL'),true);
	enableOutputURLTransformation();
}

//-----------------------------------------------------------------------------
// Accion a realizar tras la peticion de transformacion para GML
function handlerWhenLoadedGML(http_request)
{	
	try
	{
		if ( http_request.readyState == 4 )
		{
			if ( http_request.status == 200 )
			{
				var xmlDocument = http_request.responseXML;

				if ( (document.all) && (http_request.getResponseHeader('Content-Type')=="application/vnd.ogc.se_xml") )
				{
					//Explorer si el Content-Type no es text/xml no crea el xmlDocument
					xmlDocument = loadXMLFromString(http_request.responseText);
					if (xmlDocument == null)
					{
						alert(messages["responseError"]);
						enableOutputURLTransformation();
						return false;
					}						
				}

				// Parseamos la respuesta y ponemos la URL
				parseURL(xmlDocument);	
			}
			else
			{
				//alert("responseError1");
				enableOutputURLTransformation();
				alert(messages["responseError"]);
			}			
			document.getElementById('loadingURL').style.visibility = "hidden";
			enableOutputURLTransformation();		
			
		}
	}
	catch(e)
	{
		document.getElementById('loadingURL').style.visibility = "hidden";
		disenableButton(document.getElementById('transformGML'),true);	
		enableOutputURLTransformation();		
		//alert(e);
		//alert("responseError2");
		alert(messages["responseError"]);
	}
}

//-----------------------------------------------------------------------------
// Crea la petion para transformar las coordenadas de un GML introducido directamente
function createWCTSGMLRequest(sourceCRS,targetCRS,featureCollection)
{

	var outputFormat = WCTS_OUTPUT_FORMAT + ((WCTS_RESPONSE_CHARSET!=null)?("; charset=" + WCTS_RESPONSE_CHARSET):"");

	var encoding = GML_REQUEST_CHARSET?"encoding=\"" + GML_REQUEST_CHARSET + "\"":"";

	// Creamos una peticion incluyendo el codigo html introducido por el usuario
	var gmlRequest = "<?xml version=\"1.0\" " + encoding + "?>" +
		"<Transform " +
			"xmlns=\"http://www.opengeospatial.net/wcts\" " + 
			"xmlns:gml=\"http://www.opengis.net/gml\" " + 
			"service=\"" + WCTS_SERVICE + "\" version=\"" + WCTS_VERSION + "\" store=\"true\">" +
				"<SourceCRS>" + sourceCRS + "</SourceCRS>" +
				"<TargetCRS>" + targetCRS + "</TargetCRS>" +
				"<InputData>" +
					featureCollection +
				"</InputData>" +
				"<OutputFormat>" + outputFormat + "</OutputFormat>" +
		"</Transform>";

	return gmlRequest;	
}

//-----------------------------------------------------------------------------
// Transforma las coordenadas de un GML introducido directamente
function transformGML()
{

/*
	//Validamos el gml
	var gml = document.getElementById("inputGML").value;

	if ( (gml==null) || (gml==""))
	{
		alert(messages["emptyGML"]);
		return false;
	}	

	// Intentamos crear un xmlDocument a partir de el texto introducido
	var xmlDocument = loadXMLFromString(gml);

	if ( xmlDocument == null )	
	{
		// No es codigo xml
		alert(messages["noXML"]);
		return false;
	}	
	else if ( (typeof(xmlDocument) == "number") && xmlDocument == -1 )	
	{
		// No se puede crear el xmlDocument por incompatibilidad del navegador	
		alert(messages["browserNotCompatible"]);
		return false;
	}	
*/
	
	//Borramos el campo URL de salida
	document.getElementById('outputURL').value = '';
	disenableButton(document.getElementById('downloadURL'),false);
	document.getElementById('errorOutputURL').innerHTML = '&nbsp';
	
	var gml = document.getElementById("inputGML").value;
	
	// Filtramos la cabecera xml
	gml = gml.replace(/<\?.*\?>\n*/,"");

	// Extraemos las CRS fuente y destino
	
	var sourceCRS;
	var targetCRS;
	
	var sourceCRSCombo = document.getElementById("sourceCRSCombo");
	var sourceCRSValue = sourceCRSCombo.options[sourceCRSCombo.selectedIndex].value;	
	var sourceHusoCombo = document.getElementById("inputHuso");
	var sourceHusoValue = sourceHusoCombo.options[sourceHusoCombo.selectedIndex].value;

	var targetCRSCombo = document.getElementById("targetCRSCombo");
	var targetCRSValue = targetCRSCombo.options[targetCRSCombo.selectedIndex].value;	
	var targetHusoCombo = document.getElementById("outputHuso");
	var targetHusoValue = targetHusoCombo.options[targetHusoCombo.selectedIndex].value;

	if ( sourceCRSCombo.options[sourceCRSCombo.selectedIndex].value.indexOf("UTM") == -1 )
		sourceCRS = constructCRS(CRS_WCTS_PREFIX, sourceCRSValue);
	else
		sourceCRS = constructCRS(CRS_WCTS_PREFIX, sourceCRSValue, sourceHusoValue);				
			
	if ( targetCRSCombo.options[targetCRSCombo.selectedIndex].value.indexOf("UTM") == -1 )
		targetCRS = constructCRS(CRS_WCTS_PREFIX, targetCRSValue);	
	else
		targetCRS = constructCRS(CRS_WCTS_PREFIX, targetCRSValue, targetHusoValue);
	
	//Creamos la peticion
	gmlRequest = createWCTSGMLRequest(sourceCRS,targetCRS,gml);

	//Realizamos la peticion
	if (!sendAJAX(WCTS_URL,"POST",handlerWhenLoadedGML,gmlRequest,'text/xml; charset=' + GML_REQUEST_CHARSET,false))
	{
		enableOutputURLTransformation();
		alert(messages["requestError"]);
	}	
	else
	{
		document.getElementById('loadingURL').style.visibility = "visible";		
		disenableButton(document.getElementById('transformGML'),false);
		disableOutputURLTransformation();
	}			

}
