function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function vpreregistro(){
	if(trim(document.pre_reg.razonsocial.value) == ""){
		alert("La razon social es obligatoria");
		return false;
	}
	if(document.pre_reg.slc_ministry.value == "0"){
		alert("El ministerio es obligatorio");
		return false;
	}
	if(trim(document.pre_reg.cedula.value) == ""){
		alert("El numero de cedula es obligatorio");
		return false;
	}
	if(trim(document.pre_reg.apaterno.value) == ""){
		alert("El apellido paterno es obligatorio");
		return false;
	}
	if(trim(document.pre_reg.pnombre.value) == ""){
		alert("El primer nombre es obligatorio");
		return false;
	}	
	if(trim(document.pre_reg.mail.value) == ""){
		alert("El mail es obligatorio");
		return false;
	}
	if(trim(document.pre_reg.telefono.value) == ""){
		alert("El telefono es obligatorio");
		return false;
	}	
	if(trim(document.pre_reg.login.value) == ""){
		alert("El nombre de usuario es obligatorio");
		return false;
	}
	if(trim(document.pre_reg.password.value) == ""){
		alert("El password es obligatorio");
		return false;
	}
	if(trim(document.pre_reg.password.value) != ""){
		if(trim(document.pre_reg.password.value) != trim(document.pre_reg.cpassword.value))
		{
			alert("Repita el password");
			document.pre_reg.password.value = "";
			document.pre_reg.cpassword.value = "";
			return false;
		}
	}	
	return true;
}

function ControlSelection(form, idsel)
	{
		var limit = 1;
		var counter = 0;
		for(i = 0; i < form.elements.length; i++)
		{
			if(form.elements[i].type == 'checkbox')
			{
				if(form.elements[i].id == idsel)
				{
					if(form.elements[i].checked == true)
					{
						counter++;
					}
				}
			}
		}
		
		if(counter > limit)
		{
			counter = counter - 1;
			return false;
			
		}
		return true;
	}

function transfer_submit()
{
	if(document.edit.potencialMId.value!='')
	{ 
		if(trim(document.edit.motivo.value) != '')
		{ 
			if(trim(document.edit.fechaCambio.value) != '')
			{
				var indice = document.edit.potencialMId.selectedIndex; 
				if(confirm('Est\u00E1 seguro de Traspasar la OSC al ' + document.edit.potencialMId.options[indice].text +' ?'))
				{ 
					document.edit.editar.value=1; 
					document.edit.submit(); 
				}
			}
			else
			{
				alert('El campo Fecha en que se definio el Traspaso es obligatorio');
			} 
		} 
		else
		{ 
			alert('El campo motivo es obligatorio'); 
		} 
	} 
	else
	{ 
		alert('Seleccione un Ministerio para hacer el traspaso'); 
	}
}

function transferdesrec_submit()
{
	if(trim(document.edit.motivo.value) != '')
	{ 
		if(trim(document.edit.fechaCambio.value) != '')
		{
			if(confirm('Est\u00E1 seguro de Rechazar el Traspaso de la OSC al ' + document.edit.potencialMId.value +'?'))
			{ 
				document.edit.editar.value=1; 
				document.edit.submit(); 
			}
		}
		else
		{
			alert('El campo Fecha en que se definio el Rechazo de Traspaso es obligatorio');
		}
	} 
	else
	{ 
		alert('El campo motivo es obligatorio'); 
	} 
}

function transferdesace_submit()
{
	if(trim(document.edit.motivo.value) != '')
	{ 
		if(trim(document.edit.fechaCambio.value) != '')
		{
			if(confirm('Est\u00E1 seguro de Aceptar el Traspaso de la OSC al ' + document.edit.potencialMId.value +'?'))
			{ 
				document.edit.editar.value=2;				 
				document.edit.submit(); 
			}
		}
		else
		{
			alert('El campo Fecha en que se definio la Aceptaci\u00F3n de Traspaso es obligatorio');
		}
	} 
	else
	{ 
		alert('El campo motivo es obligatorio'); 
	} 
}

function ControlSelectionUnit(obj, idsel)
{
	if (!obj.checked) return
    	elem=document.getElementsByName(idsel);
    for(i=0;i<elem.length;i++) 
        elem[i].checked=false;
    obj.checked=true;
}