// JavaScript Document

function mycarousel_initCallback(carousel)
    {
            // Disable autoscrolling if the user clicks the prev or next button.
                                carousel.buttonNext.bind('click', function() {
                                carousel.startAuto(0);
             });
                            
                                carousel.buttonPrev.bind('click', function() {
                                carousel.startAuto(0);
             });
                            
                                // Pause autoscrolling if the user moves with the cursor over the clip.
                                carousel.clip.hover(function() {
                                    carousel.stopAuto();
             }, function() {
                                carousel.startAuto();
     });
 };
                            
//function mycarousel_initCallback2(carousel)
//{
//    // Disable autoscrolling if the user clicks the prev or next button.
//    carousel.buttonNext.bind('click', function() {
//        carousel.startAuto(0);
//    });
//
//    carousel.buttonPrev.bind('click', function() {
//        carousel.startAuto(0);
//    });
//
//    // Pause autoscrolling if the user moves with the cursor over the clip.
//    carousel.clip.hover(function() {
//        carousel.stopAuto();
//    }, function() {
//        carousel.startAuto();
//    });
//};
                            
jQuery(document).ready(function() {
                                jQuery('#mycarousel23').jcarousel({
                                    scroll: 1
                                });
});
                            
jQuery(document).ready(function() {
                                jQuery('#mycarousel1').jcarousel({
                                    auto: 2,
                                    wrap: 'last',
                                    initCallback: mycarousel_initCallback
});
                                
      //	jQuery('#mycarousel23').jcarousel({
      //        auto: 2,
      //        wrap: 'last',
      //        initCallback: mycarousel_initCallback2
      //    });
                            
});
                            
// validacion de select de canales
function valida_envia(){
    //valido el canales
    if (document.form2.canal2.selectedIndex==0){
       alert("Debe seleccionar un canal")
       document.form2.canal2.focus()
       return false;
    }
}
    
	
// funcion de datepicker
	
//	$(function() {
//		$("#datepicker").datepicker();
//	});
	
$(document).ready(function() {
									
		$("#datepicker_2ok").datepicker({
											showOn: 'button', 
											buttonImage: '/img/hogar3/btn_cal.jpg', 
											buttonImageOnly: true,
											dateFormat: 'yy-mm-dd', 
											monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'], 
											dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa']
		});
										
										
});
									
	
// funcion datepicker nr 2

						//	$(function() {
									//		$("#datepicker").datepicker();
									//	});
									
									$(document).ready(function() {
									
										$("#datepicker_2ok").datepicker({
											showOn: 'button', 
											buttonImage: '/img/hogar3/btn_cal.jpg', 
											buttonImageOnly: true,
											dateFormat: 'yy-mm-dd', 
											monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'], 
											dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa']
										});
										
										
									});
									
									
									
// fin func. datepicker caja nr 2
// ------------------------------

//Esta funcion escribe el flash con el VIDEO en autoplay, dentro del div identificado en ID
function play(id,video)
{
// 	var s2 = new SWFObject("players/mediaplayer.swf","playlist","180","135","7");
	var s2 = new SWFObject("players/mediaplayer.swf","playlist","276","185","7");
	s2.addParam("allowfullscreen","true");

//  *******************************************	
//  SE PRODUCE ERROR AL MOMENTO DE REALIZAR UNA PAUSA EN EL VIDEO	
//	s2.addParam("wmode", "transparent");
//  *******************************************
	
	s2.addVariable("file",video);
	s2.addVariable("displayheight","185");
	s2.addVariable("backcolor","0x000000");
	s2.addVariable("frontcolor","0xCCCCCC");
	s2.addVariable("lightcolor","0x666666");
	s2.addVariable("width","276");
	s2.addVariable("height","185");
	s2.addVariable("autostart","true");
	s2.addVariable("quality", "true");
	s2.addVariable("repeat", "list");
	s2.write(id);
}

//Esta otra funcion escribe en el div ID la imagen con el play, con alfa al 45%
function stop(id)
{
	document.getElementById(id).innerHTML = '<img style="filter:alpha(opacity=45);-moz-opacity:.45;opacity:.45;" src="players/arrow_180_135.gif">';
}


// funcion para validar rut

function verificarDV(rut, dv)
{
    var multiplicador = 9;
    var aux = rut;
    var suma = 0;
    while(aux > 0){
        var unidades = aux % 10 ;
        aux = (aux - unidades) / 10;
        suma += (multiplicador * unidades);
        multiplicador--;
        if (multiplicador < 4){
            multiplicador = 9;
        }
    }
    digito = suma % 11;
    if (digito == 10){
        digito = "k";
    }
    if (dv == digito){
        return true;
    }
    else {
        return false;
    }
} 

function validarRut()
{
    // Primer paso: Obtener el rut que ingreso el usuario
    var rutCompleto = document.form55.rut.value;
    // Eliminamos los caracteres raros, espacios, puntos, guiones.
    // Pasamos a minusculas, y separamos el rut y el digito verificador
    rutCompleto = rutCompleto.replace(/[ \.-]/g, "" );
    rutCompleto = rutCompleto.toLowerCase();
    var dv = rutCompleto.substring(rutCompleto.length - 1);
    var rut = rutCompleto.substring(0, rutCompleto.length - 1)

    var valido = true;
    // Primero comprobamos que el dv sea o un digito o una k
    valido = valido && dv.match(/^[\dk]$/);
    // luego vemos que el rut solo contenga digitos
    valido = valido && rut.match(/^\d+$/);
    // y por ultimo aplicamos la regla de calculo del DV
    valido = valido && verificarDV(rut, dv);

    if (valido){
        document.form55.rut.value = rut + "-" + dv;
        document.form55.rut_largo.value = rut + "-" + dv.toUpperCase();
        document.form55.rut_corto.value = rut;
		
		if(rut>50000000)
		{
			//alert("El RUT ingresado corresponde a una empresa.\nPor favor comuníquese al 800 000 171.");
			//return false;
            return true;
		}
		else
		{
			return true;
		}
    }
    else{
		alert('El RUT no es valido, verfiquelo y vuelva a intentarlo');
        document.form55.rut.focus();
        document.form55.rut.select();
		return false;
    }
}


// ------------------------ autocomplete 

function lookup(inputString) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("/Hogar/autocomplete/rpc.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
} // lookup
	
	function fill(thisValue) {
		$('#qs_programa_1').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
		
	}
	
// ------------------------	
