/*
 * para navegar las alertas
 */
var _resultado_ajax_js_ = true;
NavegarAlertas = function(idNorma, fechaVigencia, idParte, tipoAlerta) {

	if(tipoAlerta=="TEXTO_ACTUALIZADO"){
		NavegarNorma(idNorma,idParte,'','');
		return;
	}
	
	
	this.success = function(req){
		var JSON = req.responseText;
		var res = eval('('+JSON+')');
		if (!res.idNorma && tipoAlerta == 'FECHA DEROGACION') {
			alert("Norma derogada por fecha");
		}
		else {
			var fecha = res.fechaVigencia;
			if(tipoAlerta == 'REFUNDIDO_POR'){
				fecha = '';
			}
			NavegarNorma(res.idNorma, res.idParte, fecha);
		}
	};
	
	this.failure = function(responseText, responseXML ){ 
		alert(responseText.responseText);
	};
	
	var params = {
		method:'get',
		onSuccess: this.success,
		onFailure: this.failure,
		parameters: {idNorma: idNorma, fechaVigencia: fechaVigencia, idParte:idParte, tipoAlerta:tipoAlerta}
	};
	this.request = new Ajax.Request(parent.urlServidor + '/../Navegar/scripts/getInfoAlerta', params);
};

descargarNormaListadoRefundido =  function(idNorma, idVersion, idParte, idVersionParte, formato, nombreArchivo, tipoAlerta,nombreRefundida) {
	this.success = function(req){
		var JSON = req.responseText;
		var res = eval('('+JSON+')');
		if (res.idNorma) {
			alert("Descargando la norma "+nombreArchivo+" que refunde a "+nombreRefundida);
			var d = document;
			var radioExportar = d.createElement("input");
			var exportar_formato = d.createElement("input");
			var nombrearchivo = d.createElement("input");
			var exportar_con_notas_bcn = d.createElement("input");
			var exportar_con_notas_originales = d.createElement("input");
			var exportar_con_notas_al_pie = d.createElement("input");
			var hddResultadoExportar = d.createElement("input");
			var f = d.createElement("form");
			
			radioExportar.setAttribute("name", "radioExportar");
			exportar_formato.setAttribute("name", "exportar_formato");
			nombrearchivo.setAttribute("name", "nombrearchivo");
			exportar_con_notas_bcn.setAttribute("name", "exportar_con_notas_bcn");
			exportar_con_notas_originales.setAttribute("name", "exportar_con_notas_originales");
			exportar_con_notas_al_pie.setAttribute("name", "exportar_con_notas_al_pie");
			hddResultadoExportar.setAttribute("name", "hddResultadoExportar");
			
			radioExportar.value = "Normas";
			exportar_formato.value = formato;
			
			nombrearchivo.value = nombreArchivo;
			
			exportar_con_notas_bcn.value = "True";
			exportar_con_notas_originales.value = "True";
			exportar_con_notas_al_pie.value = "True";
			
			hddResultadoExportar.value = res.idNorma + "." +  res.fechaVigencia + ".0.0#";
			if (typeof(urlServidor) == 'undefined') {
				urlServidor = parent.urlServidor;
			}
			f.setAttribute("action", urlServidor + "/../Consulta/Exportar")
			f.setAttribute("method", "get");
			f.style.display = "none";
			d.body.appendChild(f);
			
			f.appendChild(radioExportar);
			f.appendChild(exportar_formato);
			f.appendChild(nombrearchivo);
			f.appendChild(exportar_con_notas_bcn);
			f.appendChild(exportar_con_notas_originales);
			f.appendChild(exportar_con_notas_al_pie);
			f.appendChild(hddResultadoExportar);
			
			/* Se utiliza esta funcion para registrar la traza porque ocupa los mismos parametros*/
			RegistrarNevegarNorma(58,idNorma,idVersion,getCodigoModulo(),0,0,'');
			f.submit();

		}else{
			alert("No se ha encontrado la información de la norma "+nombreArchivo);
		}
	};
	
	this.failure = function(responseText, responseXML ){ 
		alert(responseText.responseText);
	};
	
	var params = {
		method:'get',
		onSuccess: this.success,
		onFailure: this.failure,
		parameters: {idNorma: idNorma, fechaVigencia: idVersion, idParte:idParte, tipoAlerta:tipoAlerta}
	};
	this.request = new Ajax.Request(parent.urlServidor + '/../Navegar/scripts/getInfoAlerta', params);
};

function cargaUrlIn(url,destino, onEnd){
	if (typeof(onEnd) == 'undefined' || !onEnd){
		onEnd = 'void(0);';
	}
	this.success = function(req){
		$(destino).style.display = "";
		$(destino).innerHTML = req.responseText;
		eval(onEnd);
	};
	this.failure = function(responseText, responseXML ){ 
		$(destino).style.display = "none";
	};
	var params = {
		method:'get',
		onSuccess: this.success,
		onFailure: this.failure,
		parameters: {}
	};
	this.request = new Ajax.Request(url, params);
};

function seleccionaBrowserCache(){
	var ids = {
		"ie": "MSIE",
		"ff": "Firefox",
		"ch": "Chrome",
		"sf": "Safari",
		"op": "Opera"
	};
	var nameN = navigator.userAgent;
	for(var key in ids){
		if (nameN.indexOf(ids[key]) > -1) {
			$(key).style.border="1px dotted";
			break;
		}
	}
}
