﻿////////////////////////////////////////////////////////////////////////
function getProvincias(_id){
    ajaxUPTA.main.getProvincias(_id.value  , getProvincias_cb);
}

function getProvincias_cb(res){
     document.getElementById("divProvincia").innerHTML=res.value;
  //   document.getElementById("divLocalidad").innerHTML="<select id=\"Select2\"><option selected=\"selected\">-- Localidad --</option></select>";    
}

function getLocalidades(_id){
    ajaxUPTA.main.getLocalidades(_id.value  , getLocalidades_cb);
}

function getLocalidades_cb(res){
     document.getElementById("divLocalidad").innerHTML=res.value;    
}

////////////////////////////////////////////////////////////////////////
var indiceGaleria = 0;
var cantidadGaleria = 0;

function ocultarGaleria() {
   document.getElementById("divGaleria").style.display = "block";
   document.getElementById("ayn").style.display = "none";
   document.getElementById("tbl").style.display = "block";
   document.getElementById("tb2").style.display = "none";
}

function getNext(){ 
    ocultarGaleria();    
    galeria.ucGaleria.getNext(getNext_cb);
}

function getPrev(){  
    ocultarGaleria();    
    galeria.ucGaleria.getPrev(getNext_cb);
}

function getNext_cb(res){
     
     var arr = Array();
     arr = res.value.split("|"); 

     document.getElementById("divGaleria").innerHTML=arr[0];    
     document.getElementById("barNav").innerHTML=arr[1];    

}
////////////////////////////////////////////////////////////////////////

function getIntervalo(arrTmp) {
 var r;
 r = arrTmp.split("=");
 return r[1];
}
function getCantidad(arrTmp) {
 var r;
 r = arrTmp.split("=");
 return r[1];
}
var arrTmp = Array();
arrTmp = getCookie("timer").split("&");
var indice = 0;
var intervalo = getIntervalo(arrTmp[1]);
var cantidadBanners = getCantidad(arrTmp[0]);

function getBanner() {   
// katy:poner for
	setTimeout("getBanner()", intervalo);      
    ajaxUPTA.main.getBannerHTML(indice,getBanner_cb);
    indice = (indice % cantidadBanners) + 1
    //setTimeout("getBanner()", intervalo);      
}

function getBanner_cb(res) {
// katy:ocultar for
    document.getElementById("ctl00_publicidad").innerHTML=res.value;
}


function suscribir(){
    suscribiendo(true);
    var ddlComunidad=document.getElementById("ctl00_ddlComunidad").value;
    var ddlProvincia=document.getElementById("ddlProvincia").value;
    var txtEmail=document.getElementById("ctl00_TextBox1").value;
    var cbAcepto=document.getElementById("ctl00_CheckBox1").checked;
    var mensaje="";
    
    if ((ddlComunidad=="0") || (ddlComunidad==""))
    {
        mensaje +="- Seleccione una comunidad.\n"
    }
    else if ((ddlProvincia=="0") || (ddlProvincia==""))
    {
        mensaje +="- Seleccione una provincia.\n"
    } 
    
    if ((txtEmail=="0") || (txtEmail==""))
    {
        mensaje +="- Ingrese un E-Mail.\n"
    } 
    else if (!esEmail(txtEmail))
    {
        mensaje +="- Ingrese un E-Mail válido.\n"
    }
    
    if (!cbAcepto)
    {
        mensaje +="- Debe aceptar los términos y condiciones.\n"
    } 
    
    //Verificamos si hay error
    if (mensaje=="")
    {
        ajaxUPTA.main.suscribirvb(ddlProvincia,txtEmail,suscribir_cb);
    }
    else
    {
        alert("Error al suscribir por favor ingrese la siguiente información \n\n" + mensaje);
        suscribiendo(false);
    }
}

function suscribir_cb(res){
    alert(res.value);
    suscribiendo(false);
}


function esEmail(value){
    var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
    return (filter.test(value));
}

function suscribiendo(sw){
    var btn=document.getElementById("Button1");
    if (sw)
    {
        //deshabilitamos el boton
        btn.value = "Suscribiendo...";
    }
    else
    {
        //habilitamos el boton
        btn.value = "Suscribirme";
        document.getElementById("ctl00_ddlComunidad").value = "0";
        document.getElementById("ddlProvincia").value = "";
        document.getElementById("ctl00_TextBox1").value = "Email";
        document.getElementById("ctl00_CheckBox1").checked = false;
    }
    
    btn.disabled = sw;
}