/**
 * @author esalguero
 */
function handlerAlert(){
    try {
    
        window.alert = window.jqalert
        
        
    } 
    catch (err) {
        window.alert('Your browser does not support overloading window.alert. ' + err);
    }
}

jQuery.fn.teLlamamos = function(opcions){
    var clase = opcions.clase
    var html = opcions.html
    
    this.fadeOut('2000', function(){
        $(this).empty().append(html).addClass(clase).fadeIn('2000')
    })
    $('#enviarCaptcha').teLlamamosLoad();
}

jQuery.fn.teLlamamosRestore = function(opcions){

    $('#teLlamamosDiv').empty().append($('#teLlamamosHide').html())
    
    
    $('#enviarCaptcha', '#teLlamamosDiv').teLlamamosLoad()
    $('#teLlamamosDiv').css('textAlign', '')
    
}

jQuery.fn.teLlamamosLoad = function(){


    var eu = this;
    
    eu.bind('click', function(event){
    
    
        var xjxquery = '<xjxquery><q>';
        $('#teLlamamosDiv form input').each(function(){
            if ($(this).hasClass('checkbox')) {
                if ($(this).attr('checked')) {
                    xjxquery += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
                }
            }
            else {
                xjxquery += $(this).attr('name') + '=' + encodeURIComponent($(this).val()) + '&';
            }
            
        })
        
        i = xjxquery.lastIndexOf('&')
        xjxquery = xjxquery.substr(0, i - 1)
        xjxquery += '</q></xjxquery>';
        showAjaxProgreso();
        xajax_teLlamamos(xjxquery);
        
    })
    var showAjaxProgreso = function(){
    
        var div = $('<div></div>').hide()
        div.attr('id', 'teLlamamosHide')
        
        
        div.append($('#teLlamamosDiv').html())
        $('body').prepend(div)
        
        var inf = $('#teLlamamosDiv')
        
        
        hInf = inf.height();
        if (hInf == 0) {
            hInf = $('#teLlamamosDiv').height()
        }
        
        
        inf.html('<img src="./imagenes/jquery_plugins/ajax-loader.gif" style="margin-top:' + ((hInf / 2) - 20) + 'px' + '"/>').css({
            textAlign: 'center'
        });
        
        
        
        
    }
}


$(document).ready(function(){

    
	
    $('#enviarCaptcha').teLlamamosLoad();
    if(!jQuery.browser.msie){
		 handlerAlert()
	}   
    
    
    if ($('#layerChIdioma').length) {
        $('#layerChIdioma').hide();
        $('#btChIdioma').bind('click', function(){
            $('#layerChIdioma').toggle();
        });
        
        
    }
    
    
    if ($('#ayuda_on_line').length) {
        $('#ayuda_on_line').bind('click', function(e){
			window.open('http://www.redcallao.com/phplive/request.php?l=redcallao&x=1&deptid=0&pagex='+escape(document.location),'chat9541384','width=475,height=400,resizable=yes');
        });
    }
    
    $.preloadImages("../../imagenes/estructura/btn_dominios_hover.gif", "../../imagenes/estructura/btn_hosting_hover.gif", "../../imagenes/estructura/btn_serv_ded_hover.gif", "../../imagenes/estructura/btn_juegos_hover.gif", "../../imagenes/estructura/btn_sms_hover.gif", "../../imagenes/estructura/btn_serv_jur_hover.gif", "../../imagenes/estructura/btn_resellers_hover.gif", "../../imagenes/estructura/btn_tienda_hover.gif");
    $.preloadImages("../../imagenes/imgGz/estructura/btn_dominios_hover.gif", "../../imagenes/imgGz/estructura/btn_hosting_hover.gif", "../../imagenes/imgGz/estructura/btn_serv_ded_hover.gif", "../../imagenes/imgGz/estructura/btn_juegos_hover.gif", "../../imagenes/imgGz/estructura/btn_sms_hover.gif", "../../imagenes/imgGz/estructura/btn_serv_jur_hover.gif", "../../imagenes/imgGz/estructura/btn_resellers_hover.gif", "../../imagenes/imgGz/estructura/btn_tienda_hover.gif");
    
})
