var componentes_mejorados = true;

/*$.getJSON('http://www.telmex.cl/formularios/webservice/is_mobile', function(data){
    if(data.mobile == 'true'){
        componentes_mejorados = false;
    }
});*/

function contador(sector){
    m = Math.random();
    //new Ajax.Updater('nada', '/contadorSeccion.php?sector=' + sector + '&key=' + m , { method: 'get' });	
    $.get('/contadorSeccion.php', {
        sector: sector,
        key: m
    });
}

// REPRODUCCION DE VIDEO
function play(id, video, width, height){
    var s2 = new SWFObject("/Hogar/players/mediaplayer.swf", "playlist", width, height, "7");
    s2.addParam("allowfullscreen", "true");
    
    s2.addVariable("file", video);
    s2.addVariable("displayheight", height);
    s2.addVariable("backcolor", "0x000000");
    s2.addVariable("frontcolor", "0xCCCCCC");
    s2.addVariable("lightcolor", "0x666666");
    s2.addVariable("width", width);
    s2.addVariable("height", height);
    s2.addVariable("autostart", "true");
    s2.addVariable("quality", "true");
    s2.addVariable("repeat", "list");
    s2.write(id);
}

//SET COOKIE
function SetCookie(name, value){
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        "; path=" +
        getBaseDir +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}

//GET COOKIE
function GetCookie(name){
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) 
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) 
            break;
    }
    return null;
}

//GET COOKIE VALUE
function getCookieVal(offset){
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) 
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

//DELETE COOKIE
function DeleteCookie(name){
    var exp = new Date();
    exp.setTime(exp.getTime() - 1000000000); // This cookie is history (changed -1 to make it previous time)
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

// BUSQUEDA DE COMUNAS
function buscar_comunas(region, comuna, parent){
    if (region != undefined) {
        $.get(getBaseDir + "cargar_comunas/region/" + region, function(data){
            if(parent == ''){
                $("#comuna").html(data);
                if (comuna != undefined) {
                    $('#comuna').val(comuna);
                }
            }
            else if(parent == 'popin'){
                $("#div_selects #div_comuna").html('<select class="" style="width:190px;" id="comuna">'+data+'</select>');
                if (comuna != undefined) {
                    $('#comuna').val(comuna);
                }
            }
        });
    }
}

// FORMATO MONEDA
function formatCurrency(num){
    num = num.toString().replace(/\$|\,/g, '');
    
    if (isNaN(num)) 
        num = '0';
    
    var signo = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    centavos = num % 100;
    num = Math.floor(num / 100).toString();
    
    if (centavos < 10) 
        centavos = '0' + centavos;
    
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) 
        num = num.substring(0, num.length - (4 * i + 3)) + '.' + num.substring(num.length - (4 * i + 3));
    
    return (((signo) ? '' : '-') + '$ ' + num);
}

// COMPROBAR COBERTURA
function comprobar_cobertura(comuna, _fnCallback){
    retornar = false;
    if (comuna != '') {
        $.get(getBaseDir + "comprobar_cobertura/comuna/" + comuna, function(data){
            if (data == 'Telmex') {
                retornar = true;
                _fnCallback(retornar);
            }
            else{
                _fnCallback(retornar);
            }
        });
    }
}

/*date picker espa�ol*/
jQuery(function($){
    $.datepicker.regional['es'] = {
        closeText: 'Cerrar',
        prevText: '&#x3c;Ant',
        nextText: 'Sig&#x3e;',
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles', 'Jueves', 'Viernes', 'S&aacute;bado'],
        dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mi&eacute;', 'Juv', 'Vie', 'S&aacute;b'],
        dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'S&aacute;'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['es']);
});



/*$(document).ready(function() {
	if ($('.linkControlParental').length > 0) {
		$('.linkControlParental').prettyPhoto();
	}
});*/
$(document).ready(function(){
    $('.cobertura_popin').prettyPopin();
    $('.button').button();
});