var pares=new Array();
var arrCursosEliminar = new Array(); // Cursos Quitados. Para eliminarlos del carrito.
var recargauno=1;
var validado=0;
function VerCurso(idorigen,idarea,idcursoa,urlpres){
	getListaCursosEliminar();
	document.getElementById('idorigen').value=idorigen;
	document.getElementById('idcursoa').value=idcursoa;
	document.getElementById('urlpres').value=urlpres;

	formPOST = document.getElementById('formularioPOST')
	formPOST.action="cursos2009curso.php";
	formPOST.submit();
}


function CambiarArea(idorigen,cmb){
	getListaCursosEliminar();

	document.getElementById('idorigen').value=idorigen;
	document.getElementById('idarea').value=cmb.options[cmb.selectedIndex].value;

	formPOST = document.getElementById('formularioPOST')
	formPOST.action="cursos2009cursosarea.php";
	formPOST.submit();
}


function IrArea(idorigen,idarea){
	document.getElementById('idorigen').value=idorigen;
	document.getElementById('idarea').value=idarea;

	formPOST = document.getElementById('formularioPOST')
	formPOST.action="cursos2009cursosarea.php";
	formPOST.submit();

}


function VerCursosSeleccionados(){
}

function Chk(ctl){
	cursoEliminar = "";
	if (ctl.checked){
		contCursos++;
		if (arrCursosEliminar[ctl.name]==1){
			arrCursosEliminar[ctl.name]=0;			
		}
		if (API_findObj(pares[ctl.name]) && API_findObj(pares[ctl.name]).checked){
			API_findObj(pares[ctl.name]).checked=!ctl.checked;
			contCursos--;
			cursoEliminar = pares[ctl.name];			
		}
	}else{
		contCursos--;
		cursoEliminar = ctl.name;
	}
	if (cursoEliminar!=""){
		arrCursosEliminar[cursoEliminar] = 1;
	}
	HabilitarInscripcion();
}

function HabilitarInscripcion(){
	if (contCursos>0){
		document.getElementById('iniciarinscripcion').className="submit2";
		document.getElementById('iniciarinscripcion').disabled = false;
		if (document.getElementById('vercursosseleccionados')){
			document.getElementById('vercursosseleccionados').style.display = "";
			document.getElementById('seleccionecurso').style.display = "none";
		}
	}else{
		document.getElementById('iniciarinscripcion').className="submit2disabled";
		document.getElementById('iniciarinscripcion').disabled = true;
		if (document.getElementById('vercursosseleccionados')){
			document.getElementById('vercursosseleccionados').style.display = "none";
			document.getElementById('seleccionecurso').style.display = "";
		}
	}
}


function getListaCursosEliminar(){
	listaCursosEliminar = "";
	for (chkcurso in arrCursosEliminar){
		if (arrCursosEliminar[chkcurso]==1){
			listaCursosEliminar += chkcurso + ",";
		}
	}
	document.getElementById('cursosEliminar').value=listaCursosEliminar;
}


function IniciarInscripcion(idorigen){
	getListaCursosEliminar();
	document.getElementById('idorigen').value=idorigen;
	

	formPOST = document.getElementById('formularioPOST')
	formPOST.action="cursos2009cursosseleccionados.php";
	formPOST.submit();
}


function EliminarCurso(idorigen,idcurso){
	if (idcurso==0){		
		msg_confirm = "¿Está seguro que desea eliminar todos los cursos?";
	}else{
		msg_confirm = "¿Está seguro que desea eliminar el curso seleccionado?";
	}
	if (confirm(msg_confirm)){
		document.getElementById('idorigen').value=idorigen;
		document.getElementById('idcursoeliminar').value=idcurso;
		formPOST = document.getElementById('formularioPOST')
		formPOST.action="cursos2009cursosseleccionados.php";
		formPOST.submit();

	}
}


function ConfirmarInscripcion(idorigen,demo){
	if (demo==1 && document.getElementById('numero_cursos').value>3){
		alert("Solo puede inscribirse en 3 cursos. Por favor elimine alguno de los cursos seleccionados");
	}else{
		document.getElementById('idorigen').value=idorigen;
		formPOST = document.getElementById('formularioPOST')
		formPOST.action="cursos2009cursosinscripcion.php";
		formPOST.submit();
	}
}



function Leer()	{
	var frm=API_findObj('formularioPOST');
	frm.chkaceptar.disabled=false;
	Popup('instrlegal.htm#condiciones');
}

function Popup(pag)	{
	window.open('../../../../cursos2009/'+pag, 'cmtpopup', 'top=20,left=3, width=500, height=500, scrollbars=yes, menubar=no, toolbar=no, resizable=yes');
}

function onPaisChg(cmb)	{
	var c=API_findObj('cbo18');
	if (cmb.selectedIndex==1) CargaProv();
	else	cmbRemoveTail(c,1)	
}


function CargaProv()	{
	var d=window.document;
	var c=API_findObj('cbo18');
	API2_AddOption(d,c,'A Coruña',241);
	API2_AddOption(d,c,'Álava',235);
	API2_AddOption(d,c,'Albacete',236);
	API2_AddOption(d,c,'Alicante',237);
	API2_AddOption(d,c,'Almería',238);
	API2_AddOption(d,c,'Asturias',239);
	API2_AddOption(d,c,'Ávila',240);
	API2_AddOption(d,c,'Badajoz',242);
	API2_AddOption(d,c,'Barcelona',243);
	API2_AddOption(d,c,'Burgos',244);
	API2_AddOption(d,c,'Cáceres',245);
	API2_AddOption(d,c,'Cádiz',246);
	API2_AddOption(d,c,'Cantabria',247);
	API2_AddOption(d,c,'Castellón',248);
	API2_AddOption(d,c,'Ceuta',249);
	API2_AddOption(d,c,'Ciudad Real',250);
	API2_AddOption(d,c,'Córdoba',251);
	API2_AddOption(d,c,'Cuenca',252);
	API2_AddOption(d,c,'Girona',253);
	API2_AddOption(d,c,'Granada',254);
	API2_AddOption(d,c,'Guadalajara',255);
	API2_AddOption(d,c,'Guipúzcoa',256);
	API2_AddOption(d,c,'Huelva',257);
	API2_AddOption(d,c,'Huesca',258);
	API2_AddOption(d,c,'Islas Baleares',259);
	API2_AddOption(d,c,'Jaén',260);
	API2_AddOption(d,c,'La Rioja',262);
	API2_AddOption(d,c,'Las Palmas',261);
	API2_AddOption(d,c,'León',263);
	API2_AddOption(d,c,'Lleida',264);
	API2_AddOption(d,c,'Lugo',265);
	API2_AddOption(d,c,'Madrid',266);
	API2_AddOption(d,c,'Málaga',267);
	API2_AddOption(d,c,'Melilla',268);
	API2_AddOption(d,c,'Murcia',269);
	API2_AddOption(d,c,'Navarra',270);
	API2_AddOption(d,c,'Ourense',271);
	API2_AddOption(d,c,'Palencia',272);
	API2_AddOption(d,c,'Pontevedra',273);
	API2_AddOption(d,c,'Salamanca',274);
	API2_AddOption(d,c,'Segovia',275);
	API2_AddOption(d,c,'Sevilla',276);
	API2_AddOption(d,c,'Soria',277);
	API2_AddOption(d,c,'Sta. Cruz de Tenerife',278);
	API2_AddOption(d,c,'Tarragona',279);
	API2_AddOption(d,c,'Teruel',280);
	API2_AddOption(d,c,'Toledo',281);
	API2_AddOption(d,c,'Valencia',282);
	API2_AddOption(d,c,'Valladolid',283);
	API2_AddOption(d,c,'Vigo',493);
	API2_AddOption(d,c,'Vizcaya',284);
	API2_AddOption(d,c,'Zamora',285);
	API2_AddOption(d,c,'Zaragoza',286);
	
}


function Inscribir(idorigen)	{
	var frm=API_findObj('formularioPOST');
	frm.modo.value=0;

	if (frm.txt2.value==''){	
		alert("Indique el nombre");				
		frm.txt2.focus(); return;
	}

	if (frm.txt13.value==''){
		alert("Indique el primer apellido");
		frm.txt13.focus(); return;
	}
	if (frm.txt21.value==''){
		alert("Indique la dirección de correo electrónico"); 
		frm.txt21.focus(); return;
	}
	if (frm.txt21.value.indexOf('@')==-1){
		alert("Indique una dirección válida de correo electrónico"); 
		frm.txt21.focus(); return;
	}
	if (frm.txt22.value==''){	
		alert("Indique el teléfono"); 
		frm.txt22.focus(); return;
	}
	if (frm.txt272.value==''){	
		alert("Indique el DNI"); 
		frm.txt272.focus(); return;
	}
	if (frm.txt323.value==''){	
		alert("Indique el Código Postal");
		frm.txt323.focus(); return;
	} // C.P
	if (frm.txt324.value==''){	
		alert("Indique la Dirección");
		frm.txt324.focus(); return;
	}
	if (frm.txt325.value==''){	
		alert("Indique la Población");
		frm.txt325.focus(); return;
	}
	if (frm.code.value==''){
		frm.code.focus(); 
		alert('Los caracteres que ha escrito no coinciden con la verificación de la palabra. Inténtelo de nuevo');
		document.getElementById('imagecapcha').src = '../securimage/securimage_show.php?sid=' + Math.random(); 
		return false;
	}

	if (frm.txt104.value!='' && (frm.txt272.value=='' || frm.txt331.value==''))	{
		alert('Si pertenece a una organización o empresa, ha de introducir el dato del CIF y el teléfono de la empresa.');
		return;
	}

	if (frm.chkaceptar.checked)	{	
	
		if(validado==0){
			var iframe=document.getElementById("miiframe");
			iframe.src="cursos2009graba.php?origen="+idorigen+"&code="+frm.code.value;
			return;
		}
	
		
		frm.action = "cursos2009graba.php?origen="+idorigen;
		validado=0;
		frm.submit();
		recargauno=false ;
	}
	else	{
		alert('Ha de leer y aceptar las Condiciones Generales para poder continuar');
	}
}




function InscribirDemo(idorigen)	{
	var frm=API_findObj('formularioPOST');
	frm.modo.value=0;

	if (frm.txt2.value==''){	
		alert("Indique el nombre");		
		frm.txt2.focus(); return;
	}				// Nombre
	if (frm.txt13.value==''){
		alert("Indique el primer apellido");
		frm.txt13.focus(); return;
	}				// Apellido1
	if (frm.txt22.value==''){
		alert("Indique el teléfono"); 
		frm.txt22.focus(); return;
	}	
	if (frm.txt21.value==''){
		alert("Indique la dirección de correo electrónico"); 
		frm.txt21.focus(); return;
	}				// E-mail
	if (frm.txt21.value.indexOf('@')==-1){
		alert("Indique una dirección válida de correo electrónico"); 
		frm.txt21.focus(); return;
	}	

	if (frm.radioperfil[0].checked==true && frm.txt104.value==''){
		alert("Debe indicar la empresa");
		frm.txt104.focus(); return;
	}
	if (frm.code.value=='')	{
		frm.code.focus(); 
		//alert();
		alert('Los caracteres que ha escrito no coinciden con la verificación de la palabra. Inténtelo de nuevo');
		document.getElementById('imagecapcha').src = '../securimage/securimage_show.php?sid=' + Math.random(); 
		return false;
	}	
	//recargauno=false ;

	if(validado==0){
		var iframe=document.getElementById("miiframe");
		iframe.src="cursos2009graba.php?origen="+idorigen+"&code="+frm.code.value+"&demo=1";
		return;
	}
		
	
	frm.action = "cursos2009graba.php?origen="+idorigen;
	validado=0;
	frm.submit();
	///alert("estoy aquí");
	///recargauno=false ;
	
}

function Enviarform(esvalido, idorigen){
	if(esvalido){
		validado=1;
		Inscribir(idorigen);
	} else {
		alert('Los caracteres que ha escrito no coinciden con la verificación de la palabra. Inténtelo de nuevo');
		recargacapcha();
	}
}

function Enviarformdemo(esvalido, idorigen){
	if(esvalido){
		validado=1;
		InscribirDemo(idorigen);
	} else {
		alert('Los caracteres que ha escrito no coinciden con la verificación de la palabra. Inténtelo de nuevo');
		recargacapcha();
	}
}

function recargacapcha(){
	//if(!recargauno && recargauno !=1){
		document.getElementById('imagecapcha').src = '../securimage/securimage_show.php?sid=' + Math.random(); 
		recargauno=true;
		return false;
	//}
}


h=screen.height;
w=screen.width;
xPos=(w-200)/2;
yPos=(h-100)/2;

function AccesoCampus(myform){
	window.document.formacceso.action = "http://netcampus.comunet.es/acceso_netcampus.php";
	if (! window.focus)return true;
	var d = new Date();
	windowname = d.getTime();
	opt='left='+xPos+',top='+yPos+',resizable=false,status=yes,width=300,height=100';
	window.openOriginal('', windowname, opt);
	myform.target=windowname;
	return true;
} 


function MostrarEmpresa(mostrar){
	if (mostrar==1){
		document.getElementById('trcampoempresademo').style.display="";
	}else{
		document.getElementById('txt104').value="";
		document.getElementById('trcampoempresademo').style.display="none";
	}
}