function byId(id){
	return document.getElementById(id);
}
function testExplode(start, id){
	var div = byId(id);
	var cont = byId('cont');
	var outerWidth = 0;
	var posY = findPosY(start)-10;
	
	if(navigator.appName == "Microsoft Internet Explorer"){
		outerWidth = (document.body.clientWidth - 500) / 2;
	}
	else{
		outerWidth = (window.innerWidth - 500) / 2;
	}
	if(!div.style.left)
		div.style.left = outerWidth;
	if(!div.style.top)
		div.style.top = posY;
	
	var elements = document.documentElement.getElementsByTagName('select');
	for (var i=0; i<elements.length; i++) {
		elements[i].style.visibility = 'hidden';
	}
	new Element.setOpacity(cont, 0.4);
	new Effect.Appear(div);
}

function testImplode(start, id){
	var div = byId(id);
	var cont = byId('cont');
	
	var elements = document.documentElement.getElementsByTagName('select');
	for (var i=0; i<elements.length; i++) {
		elements[i].style.visibility = 'visible';
	}
	new Element.setOpacity(cont, 1);
	new Effect.Fade(div);
}

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent)
		while(1){
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1){
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}
function selectByVal(idSelect,val){
	sel=document.getElementById(idSelect);
	if(!sel){
		return false;
	}
	for(x=0;x<sel.length;x++){
		if(sel[x].value==val){
			sel[x].selected=true;
			return true;
		}
	}
}
/*****************************************************/
/*funciones javascript de los formularios:*/
function agregarFamiliares(){
	celdaFamiliares=document.getElementById("familiaresNuevos");
	/*cfsalina: primero borro todos los childs q se hayan creado antes*/
	while(celdaFamiliares.firstChild){
		celdaFamiliares.removeChild(celdaFamiliares.firstChild);
	}
	/*ahora agrego tantos childs como el valor actual de numHogar*/
	cant=document.getElementById("numHogar").value;
	contador=1;
	
	nuevoInput='INGRESE LOS DATOS DE LAS PERSONAS QUE COMPONEN SU HOGAR (SIN INCLUIRSE A USTED)';
	nuevoDiv = document.createElement("div");
	nuevoDiv.setAttribute("class", 'titleFam');
	nuevoDiv.innerHTML=nuevoInput;
	celdaFamiliares.appendChild(nuevoDiv);
	
	while(contador<=cant){
		nuevoInput='\n<div class="famLabelForm">'+contador+' NOMBRE COMPLETO: </div><input class="inputForm" type="text" size="30" name="nombreFam_'+contador+'" id="nombreFam_'+contador+'" value=""><div class="famLabelForm"> EDAD:</div> <input class="inputForm" type="text" size="2" name="edadFam_'+contador+'" id="edadFam_'+contador+'" value=""><div class="famLabelForm"> PARENTESCO: </div><select class="comboForm" name="parentFam_'+contador+'" id="parentFam_'+contador+'" >	<option value=""></option> <option value="conyuge">Cónyuge</option> <option value="hijo">Hijo(a)</option><option value="otro">Otro</option></select><br><div class="famLabelForm">&iquest;Trabaja? </div><input type="radio" name="trabaja_'+contador+'" value=1><div class="famLabelForm">SI</div> <input type="radio" name="trabaja_'+contador+'" value=0><div class="famLabelForm">NO</div><br><div class="famLabelForm"><div class="famLabelForm"> &iquest;Postula a beca de la fundación?</div> <input type="radio" name="postula_'+contador+'" value=1><div class="famLabelForm">SI</div><input type="radio" name="postula_'+contador+'" value=0><div class="famLabelForm">NO</div><br><br>\n';
		/* &iquest;Depende Económicamente?</div> <input type="radio" name="depende_'+contador+'" value=1><div class="famLabelForm">SI</div> <input type="radio" name="depende_'+contador+'" value=0><div class="famLabelForm">NO</div><br>*/
		nuevoDiv = document.createElement("div");
		nuevoDiv.setAttribute("id", 'familiarNuevo_'+contador);
		nuevoDiv.innerHTML=nuevoInput;
		celdaFamiliares.appendChild(nuevoDiv);
		contador++;
	}
}
function verJubilacion(){
	celdaJubilacion=document.getElementById("jubilacion");
	/*cfsalina: primero borro todos los childs q se hayan creado antes*/
	while(celdaJubilacion.firstChild){
		celdaJubilacion.removeChild(celdaJubilacion.firstChild);
	}
	nuevoInput='\n<div class="labelform">&iquest;CUANTO RECIBE MENSUALMENTE POR SU JUBILACIÓN?<\div><div class="labelform"><input class="inputForm2" type="text" size="10" name="montoJubilacion" id="montoJubilacion" value=""><\div>\n';
	celdaJubilacion.innerHTML=nuevoInput;
	/*celdaJubilacion.appendChild(nuevoDiv);*/
}
function borrarJubilacion(){
	celdaJubilacion=document.getElementById("jubilacion");
	/*cfsalina: borro todos los childs q se hayan creado antes*/
	while(celdaJubilacion.firstChild){
		celdaJubilacion.removeChild(celdaJubilacion.firstChild);
	}

}
function confirmarCambioEscolar(){
	var r= window.confirm('¿El alumno mantiene su colegio actual?. Si selecciona "Cancelar", se pedirán los datos del nuevo colegio');
	 if (r==true){
		document.getElementById("opcion").value="si";
	}
	else{
		document.getElementById("opcion").value="no";
	}
}
function get_firstchild(n)
  {
  var x=n.firstChild;
  while (x.nodeType!=1)
    {
    x=x.nextSibling;
    }
  return x;
 }
 function elegirJardines(){
	celdaColegios=document.getElementById("listJardines");
	idComuna=document.getElementById("comuna").value;
	var firstNode=get_firstchild(celdaColegios);
	for (var i=0;i<firstNode.childNodes.length;i++){ 
    	if (firstNode.childNodes[i].nodeType==1){
			if(firstNode.childNodes[i].value%100!=idComuna&&firstNode.childNodes[i].value!='jardin_NEW'&&firstNode.childNodes[i].value!=0)
				firstNode.childNodes[i].style.display="none";
			else
				firstNode.childNodes[i].style.display="block";
    	}
  	}
}
function elegirColegios(){
	celdaColegios=document.getElementById("listColegios");
	idComuna=document.getElementById("comuna").value;
	var firstNode=get_firstchild(celdaColegios);
	for (var i=0;i<firstNode.childNodes.length;i++){ 
    	if (firstNode.childNodes[i].nodeType==1){
			if(firstNode.childNodes[i].value%100!=idComuna&&firstNode.childNodes[i].value!='colegio_NEW'&&firstNode.childNodes[i].value!=0)
				firstNode.childNodes[i].style.display="none";
			else
				firstNode.childNodes[i].style.display="block";
    	}
  	}
}
function elegirMensajesIngSup(){
	opcion=document.getElementById("anoIngreso8").value;
	if(opcion==1){
		document.getElementById("primerAno").style.display="block";
		document.getElementById("otroAno").style.display="none";
	}
	else{
		document.getElementById("primerAno").style.display="none";
		document.getElementById("otroAno").style.display="block";
	}
	
}
function confirmarBorrarFormulario(){
	var r= window.confirm('Si modifica sus datos de trabajador, se borrará la información previamente ingresada de los familiares y postulaciones en curso . ¿Está seguro que desea modificar sus datos de trabajador?\n\nHaga click en "Aceptar" si desea editar sus datos.');
	return r; 
	
}
function seleccionarDocsPendientes(id){
	var tipoBeca=document.getElementById("tipoBeca_"+id).value;
	if(tipoBeca=="1")
		toggleDiv("docsPendientesPreescolar_"+id);
	if(tipoBeca=="2")
		toggleDiv("docsPendientesEscolar_"+id);
	if(tipoBeca=="3")
		toggleDiv("docsPendientesSuperior_"+id);
}
/* Sobreescribimos el evento OnKeyPress*/
/*Funcion que elimina el submit al hacer enter sobre un input text o un input radio*/
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && ( (node.type=="text") || (node.type=="radio"))) {return false;}
}

/*Para todos los documentos*/
document.onkeypress = stopRKey;
/******************************/

