function obrir(x) {
	fin_nova = window
			.open(x, "fin_nova",
					"screenX=100,screenY=100,width=600,height=350,scrollbars=yes,toolbar=yes");
}

function guardar() {
	if (enviar_dades()) {
		max_camps = 130;
		c001 = document.frm["c001"].value;
		c002 = document.frm["c002"].value;
		c003 = document.frm["c003"].value;
		w = window.open("", "", "menubar=yes");
		w.document.writeln("<html><head><style>body { font-family:Arial; }\n");
		w.document.writeln("#t1 { font-size:16pt; font-weight:bold; }\n");
		w.document.writeln("</style><title>Guardar dades</title></head>");
		w.document.writeln("<body bgcolor=lightyellow>");
		w.document.writeln("<b>SOL·LICITUD D'ADMISSIÓ<br>");
		w.document.writeln(c001 + " " + c002 + " " + c003 + "</b><hr noshade>");
		w.document.writeln("Per a guardar les dades en disquet, cal:<br><br>");
		w.document.writeln("1- vagi al menú Arxiu/Archivo/File d'aquesta finestra<br>");
		w.document.writeln("2- seleccioni l'opció Guardar com.../Guardar como.../Save as...<br>");
		w.document.writeln("3- a la casella del nom de l'arxiu escrigui<br>");
		w.document.writeln("<center><span>A:uic");
		w.document.writeln("<form method=post>");
		for (i = 1; i <= max_camps; i++) {
			numx = 1000 + i;
			numx = '' + numx;
			numx = numx.substring(1, 4);
			camp = "c" + numx;
			valor = document.frm[camp].value;
			if (i == 4 || i == 7 || i == 8 || i == 9 || i == 10 || i == 16
					|| i == 25 || i == 58 || i == 59 || i == 60 || i == 61
					|| i == 62 || i == 63 || i == 64 || i == 65 || i == 66
					|| i == 120 || i == 122 || i == 124 || i == 125 || i == 127
					|| i == 128 || i == 129) {
				si = document.frm[camp].selectedIndex;
				valor = document.frm[camp].options[si].value;
			}

			if (i >= 67 && i <= 90) {
				si = document.frm[camp].selectedIndex;
				valor = document.frm[camp].options[si].value;
			}
			if (i == 27 || i == 28 || i == 29 || i == 30 || i == 32) {
				valor = "000";
				for (j = 0; j <= 3; j++) {
					if (document.frm[camp][j].checked) {
						valor = document.frm[camp][j].value;
					}
				}
			}
			if (i == 47 || i == 48 || i == 49 || i == 50 || i == 51) {
				for (j = 0; j <= 1; j++) {
					if (document.frm[camp][j].checked) {
						valor = document.frm[camp][j].value;
					}
				}
			}
			w.document.writeln("<input type=hidden name='" + camp
					+ "' value=\"" + valor + "\">");
		}
		w.document.writeln("</form>");
		w.document.close();
		w.focus();
	}
}

function promig() {
	cadena = "CÀLCUL PROMIG CURS\n\n";
	cadena += "Has de valorar cada assignatura d'acord amb la taula següent:\n\n";
	cadena += " 5.5 Suficient/Aprovat\n";
	cadena += " 6.5 Bé\n";
	cadena += " 7.5 Notable\n";
	cadena += " 9.0 Excel·lent\n";
	cadena += "10.0 Matrícula d'Honor\n";
	alert(cadena);
}

function veri1() {
	ch11 = document.frm.c048[0].checked;
	ch12 = document.frm.c048[1].checked;

	ch21 = document.frm.c050[0].checked;
	ch22 = document.frm.c050[1].checked;

	ch31 = document.frm.c051[0].checked;
	ch32 = document.frm.c051[1].checked;

	ch41 = document.frm.c049[0].checked;
	ch42 = document.frm.c049[1].checked;

	ch51 = document.frm.c047[0].checked;
	ch52 = document.frm.c047[1].checked;

	if (ch21 && !ch11) {
		alert('Si ja és diplomat o equivalent\nha de tenir estudis universitaris');
		document.frm.c048[0].checked = true;
		document.frm.c048[1].checked = false;
	}

	if (ch31 && !ch11) {

		alert('Si ja és llicenciat o equivalent\nha de tenir estudis universitaris');

		document.frm.c048[0].checked = true;

		document.frm.c048[1].checked = false;

	}

	if (ch41 && !ch11) {

		alert('Si sol·licita trasllat d\'expedient\nha de tenir estudis universitaris');

		document.frm.c048[0].checked = true;

		document.frm.c048[1].checked = false;

	}

	if (!ch11) {

		document.frm.c049[1].checked = true;

		document.frm.c050[1].checked = true;

		document.frm.c051[1].checked = true;

	}

	if (ch11 && ch51) {

		alert('Si té estudis universitaris cursats\nno pot fer les PAAU aquest any');

		document.frm.c047[0].checked = false;

		document.frm.c047[1].checked = true;

	}

	if (ch21 && ch51) {

		alert('Si ja és diplomat o equivalent\nno pot fer les PAAU aquest any');

		document.frm.c047[0].checked = false;

		document.frm.c047[1].checked = true;

	}

	if (ch31 && ch51) {

		alert('Si ja és llicenciat o equivalent\nno pot fer les PAAU aquest any');

		document.frm.c047[0].checked = false;

		document.frm.c047[1].checked = true;

	}

	if (ch41 && ch51) {

		alert('Si sol·licita trasllat d\'expedient\nno pot fer les PAAU aquest any');

		document.frm.c047[0].checked = false;

		document.frm.c047[1].checked = true;

	}

}

function enviar_dades() {

	val1 = document.frm.c001.value;

	val2 = document.frm.c002.value;

	val3 = document.frm.c006.value;

	val4 = document.frm.c014.value;

	val5 = document.frm.c011.value;

	val6 = document.frm.c012.value;

	val7 = document.frm.c013.value;

	val141 = document.frm.c141.value; // estudis pare
	
	val142 = document.frm.c142.value; // estudis mare

	val8 = document.frm.c033.value;

	val9 = document.frm.c036.value;

	val10 = document.frm.c039.value;

	val11 = document.frm.c042.value;

	val22 = document.frm.c121.value;

	valn1 = document.frm.n1.value;

	valn2 = document.frm.n2.value;

	valn3 = document.frm.n3.value;

	valn4 = document.frm.n4.value;
	
	val48 = document.frm.c048[0].checked;

	val50 = document.frm.c050[0].checked;

	val51 = document.frm.c051[0].checked;

	val52 = document.frm.c052.value;

	val55 = document.frm.c055.value;

	val58 = document.frm.c058.selectedIndex;

	val59 = document.frm.c059.selectedIndex;

	val60 = document.frm.c007.selectedIndex;

	val61 = document.frm.c008.selectedIndex;

	val62 = document.frm.c009.selectedIndex;
	
	val63 = "N";

	val126 = document.frm.c126.value; //Mobil 1 obligatori
	
	val130 = document.frm.c130.value;
	
	valCaptcha = document.frm.codi_seg_captcha.value;
	
	valEsportistaElit = document.frm.esportista_elit.value;

	for (i = 0; i <= 3; i++) {

		res = document.frm.c027[i].checked;

		if (res) {
			val63 = "S";
		}

	}

	ple47 = "N";

	for (i = 0; i < 2; i++) {

		res = document.frm.c047[i].checked;

		if (res) {
			ple47 = "S";
		}

	}

	ple48 = "N";

	for (i = 0; i < 2; i++) {

		res = document.frm.c048[i].checked;

		if (res) {
			ple48 = "S";
		}

	}

	ple49 = "N";

	for (i = 0; i < 2; i++) {

		res = document.frm.c049[i].checked;

		if (res) {
			ple49 = "S";
		}

	}

	ple50 = "N";

	for (i = 0; i < 2; i++) {

		res = document.frm.c050[i].checked;

		if (res) {
			ple50 = "S";
		}

	}

	ple51 = "N";

	for (i = 0; i < 2; i++) {

		res = document.frm.c051[i].checked;

		if (res) {
			ple51 = "S";
		}

	}

	txt1 = "";
	txt2 = "";
	txt3 = "";
	txt4 = "";
	txt126 = "";
	txt5 = "";
	txt6 = "";
	txt7 = "";
	txt141 = "";
	txt142 = "";
	txt8 = "";
	txt9 = "";
	txt10 = "";
	txt11 = "";
	txt12 = "";
	txt13 = "";
	txt14 = "";
	txt15 = "";
	txt16 = "";
	txt17 = "";
	txt18 = "";
	txt19 = "";
	txt20 = "";
	txt21 = "";
	txt22 = "";
	

	if (val1 == "") {
		txt1 = "nom\n";
	}
	if (val2 == "") {
		txt2 = "cognom 1\n";
	}
	if (val3 == "" && val130 == "") {
		txt3 = "dni o passaport\n";
	}
	if (val4 == "") {
		txt4 = "telèfon 1\n";
	}
	if (val126 == "") {
		txt126 = "mòbil 1\n";
	}
	if (val5 == "") {
		txt5 = "adreça\n";
	}
	if (val6 == "") {
		txt6 = "codi postal\n";
	}
	if (val7 == "") {
		txt7 = "població\n";
	}
	if (val141 == "") {
		txt141 = "estudis pare\n";
	}
	if (val142 == "") {
		txt142 = "estudis mare\n";
	}	
	
	if (val8 == "" && valn1 != '3 ESO' && valn1 != 'CFGS 1') {
		txt8 = "La nota " + valn1 + "\n";
	}
	if (val9 == "" && valn2 != 'CFGS 2') {
		txt9 = "La nota " + valn2 + "\n";
	}
	if (val10 == "" && valn1 != 'CFGS 1') {
		txt10 = "La nota " + valn3 + "\n";
	}
		
	if (valn4 != "" && val11 == "" && valn4 != "2 Batx") {	
		txt11 = "La nota " + valn4 + "\n";
	}
	if (val48) {
		txt8 = "";
		txt9 = "";
		txt10 = "";
		txt11 = "";
	}
	if (val48 && (val50 || val51) && val52 == "") {
		txt12 = "La nota del camp títol universitari";
	}
	if (val48 && !val50 && !val51 && val55 == "") {
		txt12 = "La nota del camp sense títol universitari\n";
	}
	if (val58 == 0) {
		txt13 = "titulació de primera preferència\n";
	}
	if (val59 == 0) {
		txt14 = "via d'accés de primera preferència\n";
	}
	if (val60 == 0 || val61 == 0 || val62 == 0) {
		txt15 = "la data de naixement no està completa\n";
	}
	if (val63 == "N") {
		txt16 = "nivell d'anglès\n";
	}
	if (ple48 == "N") {
		txt17 = "té estudis universitaris cursats?\n";
	}
	if (ple49 == "N") {
		txt18 = "sol·licita trasllat d'expedient?\n";
	}
	if (ple50 == "N") {
		txt19 = "ja és diplomat o equivalent?\n";
	}
	if (ple51 == "N") {
		txt20 = "ja és llicenciat o equivalent?\n";
	}
	if (ple47 == "N") {
		txt21 = "fa les PAAU aquest any?\n";
	}
	if (val22 == "") {
		txt22 = "e-mail\n";
	}

	txt = txt1 + txt2 + txt3 + txt4 + txt126 + txt5 + txt6 + txt7 + txt141 + txt142 + txt8 + txt9 + txt10
			+ txt11 + txt12 + txt13 + txt14 + txt15 + txt16 + txt17 + txt18
			+ txt19 + txt20 + txt21 + txt22 + txt126;

	if (valCaptcha=='') {
		txtCaptcha = "imatge de validació\n";
		txt += txtCaptcha;
	}


	if (txt != "") {
		alert("Hi ha camps obligatoris en blanc:\n\n" + txt);
		return false;
	}

	if (!document.getElementById("confirmaLlegidaOLPD").checked) {
		alert("Per poder continuar ha de llegir i acceptar les clàusules de Privacitat i Protecció de Dades.");
		return false;
	}

	alert("El formulari està complet.\nGràcies per omplir el formulari amb les dades necessàries\nPer donar continuïtat al seu procés d'admissió cal lliurar la documentació necessària.\n");

	return true;

}

function num(x) {
	nums = "0123456789.";
	cad = x.value;
	llarg = cad.length;
	correcte = "S";
	for (i = 0; i < llarg; i++) {
		ps = cad.substring(i, i + 1);
		if (nums.indexOf(ps) < 0) {
			correcte = "N";
		}
	}
	if (correcte == "N") {
		x.value = "";
		alert("Cal entrar un número amb punt decimal");
	}
}

function canvi(x) {
	if (x == 1) {
		document.frm.n1.value = "1 BUP";
		document.frm.n2.value = "2 BUP";
		document.frm.n3.value = "3 BUP";
		document.frm.n4.value = "COU";
	}
	if (x == 2) {
		document.frm.n1.value = "3 ESO";
		document.frm.n2.value = "4 ESO";
		document.frm.n3.value = "1 Batx";
		document.frm.n4.value = "2 Batx";
	}
	if (x == 3) {
		document.frm.n1.value = "3 FP";
		document.frm.n2.value = "4 FP";
		document.frm.n3.value = "5 FP";
		document.frm.n4.value = "";
	}
	if (x == 4) {
		document.frm.n1.value = "Nota 1";
		document.frm.n2.value = "Nota 2";
		document.frm.n3.value = "Nota 3";
		document.frm.n4.value = "Nota 4";
	}
	if (x == 5) {
		document.frm.n1.value = "CFGS 1";
		document.frm.n2.value = "CFGS 2";
		document.frm.n3.value = "";
		document.frm.n4.value = "";
	}
}

