﻿//--------  Recuperar Datos de la Cookie --------//    
//------------ Gratuito
    var arrTmp = Array();
    arrTmp = getCookie("timer").split("&");
    var indice = 0;
    var intervalo = getIntervalo(arrTmp[1]);
    var cantidadBanners = getCantidad(arrTmp[0]);        
    
//------------ Pago    
    
    var arrTmpPago = Array();
    arrTmpPago = getCookie("timerPago").split("&");
    var indicePago = 0;
    var intervaloPago = getIntervalo(arrTmpPago[1]);
    var cantidadBannersPago = getCantidad(arrTmpPago[0]);

////////////////////////////////////////////////////////////////////////
function getProvincias(_id){
    ajaxUPTA.main.getProvincias(_id.value  , getProvincias_cb);
}

function getProvincias_cb(res){
     document.getElementById("divProvincia").innerHTML=res.value;
}

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];    
}
///////////////// Banner Gratuito ///////////////////////////////////////////////////////
function getIntervalo(arrTmp) {
 var r;
 r = arrTmp.split("=");
 return r[1];
}
function getCantidad(arrTmp) {
 var r;
 r = arrTmp.split("=");
 return r[1];
}
function getBanner() {   
// katy:poner for
	setTimeout("getBanner()", intervalo);      
    ajaxUPTA.main.getBannerHTML(indice,getBanner_cb);
    indice = (indice % cantidadBanners) + 1 //El efecto RANDOM - parte2
}
function getBanner_cb(res) {
    // katy:ocultar for
    document.getElementById("ctl00_publicidad").innerHTML=res.value;
}
///////////////// Banner Pago ///////////////////////////////////////////////////////
function getBannerPago() {   
// katy:poner for
	setTimeout("getBannerPago()", intervaloPago);      
    ajaxUPTA.main.getBannerPrivadoHTML(indicePago,getBanner_cbx);
    indicePago = (indicePago % cantidadBannersPago) + 1
}
function getBanner_cbx(res) {
   document.getElementById("ctl00_banner_publicidad_pagado").innerHTML=res.value;
   var el = document.getElementById('ctl00_banner_header');
   var elx = document.getElementById('ctl00_banner_publicidad_pagado');
   if (res.value == '')
   {
       if(el!=null)
            el.style.display = (el.style.display == 'block') ? 'none' : 'none';
       if(elx!=null)
            elx.style.display = (el.style.display == 'block') ? 'none' : 'none';
   }
   else
   {
       if(elx!=null)
            elx.style.display = (el.style.display == 'none') ? 'block' : 'block';
   }     
}
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;
}
