/*	DECLARACIÓN DE VARIABLES GLOBALES	*/
var SumaRespuestas=0;	//Almacena los suma del valor de las respuestas.

/*	DECLARACIÓN DE FUNCIONES	*/
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 fnCenterContent(NombreCapa, Modificador){
	var PosX=0;
	
	if (document.documentElement.clientHeight){
		if (document.documentElement.clientWidth>parseInt(document.getElementById(NombreCapa).style.width)){
			PosX=(document.documentElement.clientWidth-parseInt(document.getElementById(NombreCapa).style.width)-Modificador)/2;
			document.getElementById(NombreCapa).style.left= PosX.toString()+'px';			}
	}
	else{
		if (document.body.clientWidth>parseInt(document.getElementById(NombreCapa).style.width)){
			document.getElementById(NombreCapa).style.left=(document.body.clientWidth-parseInt(document.getElementById(NombreCapa).style.width)-Modificador)/2;
		} 
	}
}

function fnColocaInfo(){
	var PosX=0;
	
	PosX = parseInt(document.getElementById('divContenido').style.left)+parseInt(document.getElementById('divContenido').style.width)-parseInt(document.getElementById('divAyuda').style.width)+15;
	document.getElementById('divAyuda').style.left = PosX.toString() + 'px';
}

function fnGetSearchValue(NombreElemento){
	var posNombre= -1;
	var posInicioV=-1;
	var posFinV= -1;
	var Valor= '';

	posNombre=location.search.indexOf(NombreElemento + '=',0);
	if(posNombre != -1){
		posInicioV=location.search.indexOf('=', posNombre)+1;
		posFinV=location.search.indexOf('&', posInicioV);

		if(posFinV !=-1){
			Valor=location.search.substring(posInicioV, posFinV);
		}
		else{
			Valor=location.search.substring(posInicioV);
		}
	}
	return unescape(Valor);
}

function fnMuestraRespuesta(){
	var Puntuacion=0;
	var Mensaje='';
	
	Puntuacion = fnGetSearchValue('valor');
	if (Puntuacion<1) Puntuacion=0;
	
	if (Puntuacion < 25) {
		Mensaje = '<span class="Exclama" >¡¡Vaya, vaya!!</span><br><br>Has obtenido <span class="Puntuacion" >' + Puntuacion.toString() + '</span> <strong>de 90</strong> puntos.<br><br>El medio ambiente no es una prioridad para vosotros. El desconocimiento o la despreocupación os llevan a derrochar agua, energía… y a contaminar en exceso. Por responsabilidad con el planeta y con los demás y por vuestro propio interés, debéis mejorar vuestra forma de consumir lo antes posible para reducir el impacto sobre el medio. <span class="Resalte">Sólo es cuestión de pensar y actuar, ¡no os quedéis atrás!</span>';
	}
	else{
		if (Puntuacion < 47){
			Mensaje = '<span class="Exclama" >¡Puedes hacerlo mejor!</span><br><br>Has obtenido <span class="Puntuacion" >' + Puntuacion.toString() + '</span> <strong>de 90</strong> puntos.<br><br>Algunas de vuestras costumbres son respetuosas con el medio ambiente, pero no ponéis en práctica hábitos importantes que ahorran agua, energía, papel… y además ayudan a reducir las facturas. Analizar las respuestas de forma crítica y comprometerse es el primer paso para iniciar el cambio:<span class="Resalte"> somos responsables de los impactos que produce nuestra forma de consumir.</span>';
		}
		else{
			if (Puntuacion < 71){
				Mensaje = '<span class="Exclama" >¡Ánimo, vais bien!</span><br>Has obtenido <span class="Puntuacion" >' + Puntuacion.toString() + '</span> <strong>de 90</strong> puntos.<br><br>Se nota que estáis preocupados por el medio ambiente, procurando no deteriorarlo. Repasad las respuestas, <span class="Resalte">mejorando algunos hábitos conseguiréis ser consumidores/as más responsables y ayudaréis a conservar el planeta.</span> Merece la pena el esfuerzo, estáis cerca de conseguirlo.';
			}
			else{
				Mensaje = '<span class="Exclama" >¡¡Enhorabuena!!</span><br><br>Has obtenido <span class="Puntuacion" >' + Puntuacion.toString() + '</span> <strong>de 90</strong> puntos.<br><br><span class="Resalte">Felicidades, vuestro comportamiento es responsable y solidario</span> y se traduce en un uso eficiente de los recursos y en menor contaminación. Seguid por este camino e intentad difundir estos buenos h&aacute;bitos entre los que os rodean.';
			}
		}
	}
	document.getElementById('pRespuesta').innerHTML = Mensaje;
}

function fnGetGrupo(Puntuacion){
	var Grupo=0;

	if (Puntuacion < 25) {
		Grupo=1;
	}
	else{
		if (Puntuacion < 47){
				Grupo=2;
		}
		else{
			if (Puntuacion < 71){
				Grupo=3;
			}
			else{
				Grupo=4;
			}
		}
	}
	return Grupo;
}

function fnMuestraResultado(){
	if (fnVerificaRespuestas()) {
		document.getElementById('ancBoton').href= "procesa.php?valor=" + SumaRespuestas.toString() + "&grupo=" + fnGetGrupo(SumaRespuestas).toString();//"procesa.asp?valor=" + SumaRespuestas.toString();//"resultado.htm?valor=" + SumaRespuestas.toString();
		//document.location.href= "resultado.htm?valor=" + SumaRespuestas.toString();
	}
}

function fnResalta(Resalta,Elemento){
	if (Resalta){
		Elemento.style.fontWeight='bold';
		Elemento.style.backgroundColor='#e7dbc5'; 
	}
	else{
		Elemento.style.fontWeight='100';
		Elemento.style.backgroundColor='';
	}
}

function fnVerificaRespuestas(){
	var Validacion=false;
	var Opciones;
	var Contador=1;
	
	SumaRespuestas=0;
	for(i=0; i<30; i++) {
		Validacion=false;
		Opciones = document.getElementsByName('T' + Contador);
		for (j=0; j<Opciones.length; j++){
			if(Opciones[j].checked) {
				Validacion=true;
				SumaRespuestas += parseInt(Opciones[j].value);
			}
		}
		if (Validacion==false) {
			document.getElementById('ancBoton').href='#T' + Contador;
			alert("Por favor, conteste todas las cuestiones.\nHa dejado sin contestar la pregunta: " + Contador);
			break;
		}
		Contador++;
	}
	if (Validacion) return true;
}












