xpwb0n=xppr('0_0.gif');
xpwb0o=xppr('0_1.gif');
xpwb0c=xppr('0_2.gif');

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Hide_Msg() {
	Message.innerHTML= "&nbsp;";
	clearTimeout(timerID);
}

function Send_Form() {
	Message.innerHTML= "<img src='./images/loading.gif' align='absmiddle'>&nbsp;&nbsp;&nbsp;<font class='Text'>Enviando datos...</font>";
	setTimeout("Submit()", 3000);	
}

function Submit() {
	document.Formulario.submit();
}

function resizeDiv(){
	document.getElementById("Seo").style.left=((document.body.clientWidth/2));
}

function xppr(im){
	var i=new Image();
	i.src='images/bt'+im;return i;
}
function xpe(id){
	x=id.substring(0,id.length-1);
	document['xpwb'+x].src=eval('xpwb'+id+'.src');
	if(id.indexOf('e')!=-1)document['xpwb'+x+'e'].src=eval('xpwb'+id+'e.src');
}

function Goto(opc) {
	//alert(opc);
	id = document.Formulario.codigoCOD.value;
	if (opc=="Alumnos")
	{asp = "cuestionario_alumnos.php?perfil=2&id="+id;}
	if (opc=="Familias")
	{asp = "cuestionario_familias.php?perfil=4&id="+id;}
	if (opc=="Personal")
	{asp = "cuestionario_personal.php?perfil=5&id="+id;}
	if (opc=="Primaria")
	{asp = "cuestionario_alumnosprimaria.php?perfil=6&id="+id;}
	window.open(asp,'Formulario','toolbar=no,location=no,directories=no,status=no,menubar=no,top=0,left=0, scrollbars=yes,resizable=no,copyhistory=no,width='+window.screen.width+',height='+window.screen.height)
}

///////////////////////////////// CUESTIONARIOS /////////////////////////////////

//cambia aquí la dirección
//var targetURL="alumnos.asp"
//cambia los segundos que quieres que dure la cuenta atrás
var currentsecond=30

function redireccionar(){
	if (currentsecond!=1){
		currentsecond-=1
		Cuenta.innerHTML = 'El Formulario se cerrará en '+currentsecond+' segundos';
	}
	else{
		//document.location.href=targetURL;
		window.close();
		return
	}
	setTimeout("redireccionar()",1000)
}

/*------------------------------------------------------------------------------
--	  	  CUANDO PULSA EL BOTON DE ENVIAR COMPROBAMOS TODOS LOS CAMPOS        --
------------------------------------------------------------------------------*/
function Check_qst_adicional() {
	if (document.form1.Preguntas_adicionales.value == "") {
		return true;
	}
	else {
		//var divId = "QST_Adicional";
		//var oDiv = document.getElementById(divId);
		//if (oDiv.style.visibility == 'visible') {
			preguntas = 0;			
			var desplegables = document.getElementsByTagName("select");
			for(i=0;i<desplegables.length;i++) {
				if (desplegables[i].value == "")
				{
					preguntas = preguntas + 1;
				}
			}
			if (preguntas == 0) { return true; }
			else if (preguntas == i) 
			{
				if (confirm("No ha contestado a ninguna de las preguntas formuladas. ¿Desea continuar?")) { return true; }
				else { return false; }
			}
			else
			{
				if (confirm("Ha dejado sin contestar alguna pregunta. ¿Desea continuar?")) { return true; }
				else { return false; }
			}
			return true;
		//}
		//else {
		//	showDiv(divId);
		//}
	}
}

function Change_btn(stage) {
	if (stage == "stg1") {
		Boton.innerHTML= "<img src='./images/loading.gif' align='absmiddle'>&nbsp;&nbsp;&nbsp;<font class='Text'>Enviando datos...</font>";
	}
	else {
		Boton2.innerHTML= "<img src='./images/loading.gif' align='absmiddle'>&nbsp;&nbsp;&nbsp;<font class='Text'>Enviando datos...</font>";
	}
}

function Check_Conditions(cuestionario) {
	// alumnos 		---> COMPRUEBA: CODCENTRO/AÑO/CODPADRAL/CURSO/CODETAPA/CODSEXO
	// alumnosprimaria	---> COMPRUEBA: CODCENTRO/AÑO/CODPADRAL/CURSO/CODSEXO
	// familias	        ---> COMPRUEBA: CODCENTRO/AÑO/CODPADRAL/CURSO/CODETAPA/CODSEXO/CODHIJOS
	// personal	        ---> COMPRUEBA: CODCENTRO/AÑO/CODPADRAL

	//----------------- CODCENTRO --------------------
	if (document.form1.CODCENTRO.value == "") {
		alert ("CODCENTRO en blanco");
		return false;
	}
	//----------------- AÑO --------------------
	if (document.form1.AÑO.value == "") {
		alert ("CODCENTRO en blanco");
		return false;
	}
	//----------------- CODPADRAL --------------------
	if (document.form1.CODPADRAL.value == "") {
		alert ("CODPADRAL en blanco");
		return false;
	}
	if (cuestionario == "alumnos" || cuestionario == "alumnosprimaria" || cuestionario == "familias") {
		//----------------- CURSO --------------------
		if (document.form1.CURSO.value == "") {
			alert ("CURSO en blanco");
			return false;
		}
	}
	//----------------- CODETAPA --------------------
	if (cuestionario == "alumnos" || cuestionario == "familias") {
		if (document.form1.CODETAPA.value == "") {
			alert ("ETAPA en blanco");
			return false;
		}
	}
	//----------------- CODSEXO --------------------
	if (cuestionario == "alumnos" || cuestionario == "alumnosprimaria" || cuestionario == "familias") {
		if (document.form1.CODSEXO.value == "") {
			alert ("SEXO en blanco");
			return false;
		}
	}
	//----------------- CODHIJOS --------------------
	if (cuestionario == "familias") {
		if (document.form1.CODHIJOS.value == "") {
			alert ("Hijos en blanco");
			return false;
		}
	}
	return true;
}

function Check_Qst_Import(cuestionario) {
	
	if ( (document.form1.IMP1.value != "") && (isNaN(parseFloat(document.form1.IMP1.value))) ) {
		alert ("En las preguntas que le han parecido importantes debe de escribir el número");
		document.form1.IMP1.focus();
		return false;
  	}
		
	if ( (document.form1.IMP2.value != "") && (isNaN(parseFloat(document.form1.IMP2.value))) ) {
		alert ("En las preguntas que le han parecido importantes debe de escribir el número");
		document.form1.IMP2.focus();
		return false;
  	}
		
	if ( (document.form1.IMP3.value != "") && (isNaN(parseFloat(document.form1.IMP3.value))) ) {
		alert ("En las preguntas que le han parecido importantes debe de escribir el número");
		document.form1.IMP3.focus();
		return false;
  	}

	if ( (document.form1.IMP4.value != "") && (isNaN(parseFloat(document.form1.IMP4.value))) ) {
		alert ("En las preguntas que le han parecido importantes debe escribir el número de la pregunta");
		document.form1.IMP4.focus();
		return false;
  	}

	if ( (document.form1.IMP5.value != "") && (isNaN(parseFloat(document.form1.IMP5.value))) ) {
		alert ("En las preguntas que le han parecido importantes debe escribir el número de la pregunta");
		document.form1.IMP5.focus();
		return false;
  	}
	return true
}

function Sending(cuestionario,stage) {
	var str_action;
	
	if (cuestionario == "alumnos") { str_action = "cuestionario_alumnos.php"; }
	if (cuestionario == "alumnosprimaria") { str_action = "cuestionario_alumnosprimaria.php"; }
	if (cuestionario == "familias") { str_action = "cuestionario_familias.php"; }
	if (cuestionario == "personal") { str_action = "cuestionario_personal.php"; }

	if (stage == "stg2") {
		if (Check_qst_adicional()) {
			document.form1.action = str_action + "?MM_insert=form2";
			Change_btn(stage);
			document.form1.submit();
		}
	}
	else {
		document.form1.action = str_action + "?MM_insert=form1";
		Change_btn(stage);
		document.form1.submit();
	}
}

function Send(cuestionario,stage)
{
	if (Check_Conditions(cuestionario) == false) { return; }

	if (cuestionario == "alumnos" || cuestionario == "familias") {
		if (Check_Qst_Import(cuestionario) == false) { return; }			
	}

	//////// FORMULARIO COMPLETO ////////
	if (stage == "stg1" && cuestionario != "personal") {
		if (cuestionario != "alumnosprimaria") {
			if (confirm("  COMPRUEBA SI TUS DATOS SON CORRECTOS \r\r Curso: "+document.form1.CURSO.options[document.form1.CURSO.value].text+"   Etapa: "+ document.form1.CODETAPA.options[document.form1.CODETAPA.value].text +"   Sexo: "+ document.form1.CODSEXO.options[document.form1.CODSEXO.value].text +""))
			{ Sending(cuestionario,stage); }
			else { return; }
		}
		else {
			if (confirm("  COMPRUEBA SI TUS DATOS SON CORRECTOS \r\r Curso: "+document.form1.CURSO.options[document.form1.CURSO.value].text+"   Etapa: "+ document.form1.STR_CODETAPA.value +"   Sexo: "+ document.form1.CODSEXO.options[document.form1.CODSEXO.value].text +""))
			{ Sending(cuestionario,stage); }
			else { return; }		
		}
	}
	//////// PREGUNTAS ADICIONALES ////////
	else { Sending(cuestionario,stage); }
}

var HELPER_IFRAME_ID = "IFrmHelper";
var topDivZIndex = 10000;
// Add dynamic div to the page
function _init(){
// Creating and adding dynamic iframe to the page source.
var oBody = document.getElementsByTagName("BODY").item(0);
var oHelperIframe = document.createElement("IFRAME");
oHelperIframe.setAttribute("id", HELPER_IFRAME_ID);
oHelperIframe.style.border = 0; 
oHelperIframe.width = 0; 
oHelperIframe.height = 0;
oHelperIframe.style.position = "absolute";
oBody.appendChild(oHelperIframe);
}

// Should return the div actual width.
//function getDivWidth(divId){...}

// Should return the div actual height.
//function getDivHeight(divId){...}

// Will show the div and the helper iframe.
function showDiv(divId){
	_init();
	var oBody = document.getElementsByTagName("BODY").item(0);
	var oHelperIframe = document.getElementById(HELPER_IFRAME_ID);
	var oDiv = document.getElementById(divId);
	oDiv.style.zIndex = topDivZIndex;
	oHelperIframe.style.zIndex = topDivZIndex - 1000;
	topDivZIndex += 1; 
	oHelperIframe.style.top = oDiv.style.top;
	oHelperIframe.style.left = oDiv.style.left;
	//oHelperIframe.width = getDivWidth(divId) - 1;
	//oHelperIframe.height = getDivHeight(divId) - 1;
	oHelperIframe.width = "60%";
	oHelperIframe.height = "60%";
	oHelperIframe.style.visibility = 'visible';
	oDiv.style.visibility = 'visible';
	window.scrollTo(0,0);
}

// Will hide the div and the helper iframe.
function hideDiv(divId){
var oHelperIframe = document.getElementById(HELPER_IFRAME_ID);
var oDiv = document.getElementById(divId);
oHelperIframe.style.visibility = 'hidden';
oDiv.style.visibility = 'hidden';
}

// Will move the div and the helper iframe to the given X and Y position
function moveDiv(divId, Xpos, Ypos){
var oHelperIframe = document.getElementById(HELPER_IFRAME_ID);
var oDiv = document.getElementById(divId);
oHelperIframe.style.top = Ypos + 1;
oHelperIframe.style.left = Xpos + 1;
oDiv.style.top = Ypos;
oDiv.style.left = Xpos;
}

// Attach to the onload event
if(typeof(window.addEventListener) != "undefined") {
window.addEventListener("load", _init, false);
} else {
window.attachEvent("onload", _init);
}

/*
<!-- Mas trucos y scripts en http://www.javascript.com.mx -->
function Activo() {
temp = 0; 
Cuenta_QST_Adicional.innerHTML = '';
Check_Mouse();
var currentsecond2=90
}
function Check_Mouse(){ 
	temp ++;  
	if(temp > 50){  
		Inactivo(); 
	}
	setTimeout("Check_Mouse()", 30); 
} 
var currentsecond2=90
function Inactivo(){
	if (currentsecond2!=1){
		currentsecond2-=1
		Cuenta_QST_Adicional.innerHTML = 'Debido al tiempo de inactividad. El Formulario se enviará en '+currentsecond2+' segundos';
	}
	else{
		//document.location.href=targetURL;
		document.form1.action = str_action + "?MM_insert=form2";
		Change_btn(stage);
		document.form1.submit();	
		return
	}
	setTimeout("Inactivo()",1000)
}
*/


