var loadstatustext="<img src='iconos/loading.gif' /> Procesando ..."
var loadstatustext2="<img src='../iconos/loading.gif' /> Procesando ..."
var contenedor_anterior
var contenedor

//-----------------------------------------------------------------------------------------------------------
function objetoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
//-----------------------------------------------------------------------------------------------------------
function Votar(){
	GetContenedorAnterior();
	var contenedor
	var	id_pregunta
	var	id_opcion
	id_pregunta = document.getElementById('id_pregunta').value;
	id_opcion = document.getElementById('id_opcion').value;
	contenedor=document.getElementById("encuesta_resultados")
	contenedor.innerHTML=loadstatustext
	ajax=objetoAjax();
	ajax.open("POST", "encuesta.asp",true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	ajax.onreadystatechange=function() {if (ajax.readyState==4) {contenedor.innerHTML = ajax.responseText}}
	ajax.send("id_pregunta="+id_pregunta+"&id_opcion="+id_opcion)
}
//-----------------------------------------------------------------------------------------------------------
function Votar2(){
	GetContenedorAnterior();
	var contenedor
	var	id_pregunta
	var	id_opcion
	id_pregunta = document.getElementById('id_pregunta').value;
	id_opcion = document.getElementById('id_opcion').value;
	contenedor=document.getElementById("encuesta_resultados")
	contenedor.innerHTML=loadstatustext2
	ajax=objetoAjax();
	ajax.open("POST", "../encuesta.asp",true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	ajax.setRequestHeader("Pragma", "no-cache");
	ajax.onreadystatechange=function() {if (ajax.readyState==4) {contenedor.innerHTML = ajax.responseText}}
	ajax.send("id_pregunta="+id_pregunta+"&id_opcion="+id_opcion)
}
//-----------------------------------------------------------------------------------------------------------
function MarcarOpcion(id_opcion){
	document.getElementById('id_opcion').value=id_opcion;	
}
//-----------------------------------------------------------------------------------------------------------
function GetContenedorAnterior(){
	contenedor_anterior = document.getElementById("encuesta_resultados").innerHTML
}
//-----------------------------------------------------------------------------------------------------------
function Regresar(){
	contenedor=document.getElementById("encuesta_resultados")
	contenedor.innerHTML=contenedor_anterior	
}
//-----------------------------------------------------------------------------------------------------------
function trim(lstrcadena) 
{
  // quito primero los posibles caracteres vacíos al principio
  if (lstrcadena.length != 0)
  {		
    while (lstrcadena.charAt(0) == " ")
    {
      lstrcadena = lstrcadena.substr(1);		
    }
  }	
  // Ya ahora los últimos
  if (lstrcadena.length != 0)
  {		
    while (lstrcadena.charAt(lstrcadena.length-1) == " ")
    {
      lstrcadena = lstrcadena.substr(0,lstrcadena.length-1);		
    }
  }	

  return lstrcadena;  
}

function esNumerico(elinput)
{
  re=/^\d+$/;
  if(re.test(elinput.value))
  {
    return true;
  }
  else
  {
	  return false;
  }
}


function esAlfanumerico(elinput)
{
  re=/^\w+$/;
  if(re.test(elinput.value))
  {
    return true;
  }
  else
  {
	  return false;
  }
}

function esVacio(elinput)
{
	if(trim(elinput.value)=="")
	{
		return true;
	}
	else
	{
		return false;
	}
}

/**
* comprueba si una cadena tiene el formato de una dirección de email.
*/
	function esEmail( elinput )
	{
		var email = elinput.value;
		var exprEmail =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
		if (exprEmail.test(email))
		{
			return true;
		}
		else
		{
			return false;
		}
	}

/**
*Comprueba si una fecha esta en formato YYYY-MM-DD
*/

function esFecha2(input)
{
	re=/^\d\d\d\d-\d\d-\d\d$/;
	if(re.test(input.value))
	{
		return true;
	}
	else
	{
		return false;
	}
}

/**
*Comprueba si una fecha esta en formato DD-MM-YYYY ó DD/MM/YYYY
*/

/* Un anno es bisiesto si es divisible entre cuatro, excepto los divisibles entre cien, 
 * que no lo son de 400 */

function bisiesto( a )
{
    return  ( ( a % 400 == 0 ) || ( ( a % 4 == 0 ) && !( a % 100 == 0 )));
}

function esFecha(input)
{
	re=/^\d\d-\d\d-\d\d\d\d$/;
	re2=/^\d\d\/\d\d\/\d\d\d\d$/;
	if(!re.test(input.value) && !re2.test(input.value))
	{
		return false;
	}
        fecha = input.value;
        dia = fecha.substr( 0, 2 );
        mes = fecha.substr( 3, 2 );
        anno = fecha.substr( 6, 4 );      
        if ( mes < 1 || mes > 12 )
        {
            return false;
        }
        if ( dia < 1 )
        {
            return false;
        }
        if ( mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12 )
        {
            if ( dia > 31 )
            {
                return false;
            }
        }

        if ( mes == 4 || mes == 6 || mes == 9 || mes == 11 )
        {
            if ( dia > 30 )
            {
                return false;
            }
        }

        if ( mes == 2 )
        {
            if ( bisiesto( anno ) )
            {
                if ( dia > 29 )
                {
                    return false;
                }
            }
            else
            {
                if ( dia > 28 )
                {
                    return false;
                }
            }
        }
        return true;
}


function RellenarAnnosSelector(elselect)
{
	fecha=new Date;
 	year=fecha.getYear();
 	if (year<200)
	{
		year+=1900;
	}
  for (i=1998,contador=0;i<=(year+2);i++,contador++)
  {
	  opcion= new Option(i,i,false,false);
	  elselect.options[contador]=opcion;

  }
  return;
}