//alert('funciones.js');
var rutaNombreAplicacion=appContext;
function deshabilitarInstitucion(valor, forma, nombre1, nombre2, nombre3,
		nombre4) {
	if (document[forma].country.value == 'MEX') {
		if (valor == '03') {
			document[forma][nombre1].value = '0';
			document[forma][nombre1].disabled = true;
			document[forma][nombre2].value = '0';
			document[forma][nombre2].disabled = true;
			document[forma][nombre3].value = '0';
			document[forma][nombre3].disabled = true;
			document[forma][nombre4].value = '0';
			document[forma][nombre4].disabled = true;
		} else {
			document[forma][nombre1].disabled = false;
			document[forma][nombre2].disabled = false;
			document[forma][nombre3].disabled = false;
			document[forma][nombre4].disabled = false;
		}
	}

}
function addfav()
   {
   if (document.all)
      {
      window.external.AddFavorite
      ("http://www.siicyt.gob.mx/","SIICYT")
      }
   }
// UTILIZADA EN CVU Y VIECYT PM
function compararpassword(nomforma, elemento1, elemento2) {
	// alert("cont1="+document[nomforma].elements[1].value+"con2="+document[nomforma].elements[2].value);
	if (document[nomforma][elemento1].value == document[nomforma][elemento2].value)
		return true;
	return false;
}

function Redirect(direccion) {
	document.location = direccion;
}

//UTILIZADA EN BUZON DE NECESIDADES Y PROYECTOS
function validarClasificacion(nombreForma, nombreCampo, menje) {
	if (window.document[nombreForma][nombreCampo].value == 0) {
		return false;
	}
	return true;
}


//UTILIZADA EN EL JSP OLVIDO PASSWORD
function confirmaEnvioPassword(forma) {

	if (!validateUsuarioForm(forma))
		return false;

	if (confirm("¿Esta seguro de continuar?")) {
		return true;
	}
	return false;
}

function confirmaAccion(mensaje, nombreForma) {

	if (confirm(mensaje)) {
		return true;
		// window.document[nombreForma].submit();
	}

	return false;
}

//REPORTES CVU
function resetCuadrosLista(objeto) {
	objeto.selectedIndex = 0;
}



// ****BUSCADOR******************************/

function ConfirmarInformacion() {
	// alert(this.document.BusquedaForm.palabraClave.value);
	if (window.document.BusquedaForm.palabraClave.value == null
			|| window.document.BusquedaForm.palabraClave.value == "") {
		if (confirm("El despliegue de esta informacion puede tardar varios minutos le sugerimos la opción [Ir] del buscador para seleccionar criterios de busqueda.Desea continuar aun con la busqueda?")) {
			window.document.BusquedaForm.submit();
		}
	} else
		window.document.BusquedaForm.submit();
}

function validarAlgunDatoSeleccionado(form) {

	result = false;

	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type == 'checkbox'
				&& form.elements[i].checked == true)
			result = true;
	}

	if (!result)
		alert("No existen elementos seleccionados");

	return result;
}

function selecciona(form) {
	for (i = 1; i < form.elements.length; i++) {
		if (form.elements[i].type == 'checkbox') {
			if (form.elements[i].checked == true)
				form.elements[i].checked = false;
			else
				form.elements[i].checked = true;
		}
	}
}

var formRadiosSeleccion = function(){
	this.criterioDerecho=0;
	this.criterioIzquierdo=0;
	this.promocion=0;
	this.tipo=0;
	this.tipoPresentacion=0;
}

var seleccionRadios = new formRadiosSeleccion();

function cambiaTipoInvestigador(obj) {
	if (obj.value == 1) // //PARA SNI
	{
		document.getElementById('SNI').style.display = '';
		document.getElementById('BECAS').style.display = 'none';
		document.getElementById('BECAS2').style.display = 'none';
		document.ReportesSeleccionCVU.promocion.disabled = false;
		document.getElementById('tipo_presentacion').value=1;
		document.getElementById('tipo_presentacion').disabled=false;
		document.getElementById('nuevos_criterios').style.display = '';

		for (var counter = 0; counter < document.ReportesSeleccionCVU.tipo_reporte.length; counter++) {
			document.ReportesSeleccionCVU.tipo_reporte[counter].disabled = false;
		}
		// document.ReportesSeleccionCVU.mes.disabled = true;
		// document.ReportesSeleccionCVU.tipo_beca.disabled = true;
	}

	if (obj.value == 4) // /PARA BECAS
	{
		document.getElementById('BECAS').style.display = '';
		document.getElementById('BECAS2').style.display = '';
		document.getElementById('SNI').style.display = 'none';
		document.getElementById('tipo_presentacion').value=1;
		document.getElementById('tipo_presentacion').disabled=false;
		document.getElementById('nuevos_criterios').style.display = '';

		document.ReportesSeleccionCVU.promocion.disabled = false;

		for (var counter = 0; counter < document.ReportesSeleccionCVU.tipo_reporte.length; counter++) {
			document.ReportesSeleccionCVU.tipo_reporte[counter].disabled = false;
		}
		// document.ReportesSeleccionCVU.mes.disabled = false;
		// document.ReportesSeleccionCVU.tipo_beca.disabled = false;
		document.ReportesSeleccionCVU.promocion.options.collection = "promocionesB";

	}

	if (obj.value == 10)// /PARA INVESTIGADORES TOTALES
	{
		document.getElementById('BECAS').style.display = 'none';
		document.getElementById('BECAS2').style.display = 'none';
		document.getElementById('SNI').style.display = 'none';
		document.getElementById('nuevos_criterios').style.display = 'none';
		document.getElementById('tipo_presentacion').value=1;
		document.getElementById('tipo_presentacion').disabled=true;

		document.ReportesSeleccionCVU.promocion.disabled = true;

		//document.ReportesSeleccionCVU.tipo_reporte[0].checked = true;
		document.ReportesSeleccionCVU.tipo_reporte.checked = true;
		for (var counter = 0; counter < document.ReportesSeleccionCVU.tipo_reporte.length; counter++) {
			if (document.ReportesSeleccionCVU.tipo_reporte[counter].value != 1)
				document.ReportesSeleccionCVU.tipo_reporte[counter].disabled = true;
		}
		// document.ReportesSeleccionCVU.mes.disabled = true;
		// document.ReportesSeleccionCVU.tipo_beca.disabled = true;
	}
}

function checarReporte(valor) {
	if (valor == 1) {
		document.ReporteProyectosForm.formatoSalida[0].disabled = true;
		document.ReporteProyectosForm.formatoSalida[1].disabled = true;
		document.ReporteProyectosForm.formatoSalida[2].disabled = true;
	} else {
		document.ReporteProyectosForm.formatoSalida[0].disabled = false;
		document.ReporteProyectosForm.formatoSalida[1].disabled = false;
		document.ReporteProyectosForm.formatoSalida[2].disabled = false;
	}
}

var waitPage = function (action){
	var div = document.getElementById('waitImage');
	if (div){
		if (action=='show'){
			div.style.display='';
		}
		else
			div.style.display='none';
	}		
}


function displayButton(button){
	if (button.type && button.type=='checkbox'){
		pressButton(button, button.checked);
	} else
		if (!buttonsBuscador[button.id]){
			pressButton(button, true);
		}
		else {
			pressButton(button, false);
		}
}

function pressButton(button, press){
	buttonsBuscador[button.id]=press;
	if (button.type && button.type=='checkbox'){
		button.checked=press;
	} else
		if (press)
			button.className='buttonBusqueda buttonPressed';
		else
			button.className='buttonBusqueda buttonUnpressed';
} 


function loadScript(url, callback){
    var script = document.createElement("script")
    script.type = "text/javascript";

    if (script.readyState){  //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}

function loadCss(url, callback){
    var script = document.createElement("link")
    script.type = "text/css";
	script.rel = "stylesheet";

    if (script.readyState){  //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }

    script.href = url;
    document.getElementsByTagName("head")[0].appendChild(script);
}