var band=0;
function cargar_toolTip(){
    ref=document.getElementById("but_box");
    var toolTip=document.createElement('div');
    toolTip.id='tool_tip';
    ref.appendChild(toolTip);
    toolTip.innerHTML="<p>&iquest;A que a ti tambi&eacute;n te gustar&iacute;a recibir abrazos? Intercambia abrazos con tus amigos de <a href='http://apps.facebook.com/abraza-tu-meriva/' target='_blank' >Facebook</a> y g&aacute;nate un fin de semana conduciendo el Nuevo Opel Meriva. &iexcl;Participa!</p>";
    var btn_close = document.createElement('a');
   	btn_close.id='close_tool_tip';
    btn_close.innerHTML = '<span>Close window</span>';
    btn_close.href = 'javascript:void(0)';
    btn_close.onclick = function() 
    {
      tool_t=document.getElementById('tool_tip');
      tool_t.style.display='none';
    };
    toolTip.appendChild(btn_close);
}
function mostrar_info(){
    if(band==0) {cargar_toolTip(); band=1;}
    tool_t=document.getElementById('tool_tip');
    tool_t.style.display='block';
}


function mostrar_envio(id_blogger){
        aux=document.getElementById("hidden_val");
        texto=aux.value;
        var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
    
        var layer = document.createElement('div');
        layer.style.zIndex = 2;
        layer.id = 'layer';
        layer.style.position = 'fixed';
        layer.style.top = '0px';
        layer.style.left = '0px';
        //layer.style.height = document.documentElement.scrollHeight + 'px';
        layer.style.height = '100%';
        layer.style.width = '100%';
        layer.style.width = width + 'px';
        layer.style.backgroundColor = 'black';
        layer.style.opacity = '.6';
        layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
        document.body.appendChild(layer);  
        
        var div = document.createElement('div');
        div.style.zIndex = 6;
        div.id = 'lbox';
        div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'absolute';
        div.style.top = '55px';
        div.style.left = (width / 2) - (357) + 'px';	
        div.style.width = '714px';
    	
        document.body.appendChild(div);  
    	
    	div.innerHTML = 
        "<div id='modal'>"+
            "<h3>1. &iquest;Qui&eacute;n eres?</h3>"+
            "<input id='nombre_send' name='nombre_send' type='text' />"+
            "<h3>2. Elige el abrazo que quieres enviar</h3>"+
            "<ul class='tipo'>"+
                "<li><label for='abrazo0'><img src='http://abrazatumeriva.es/widget/www/system/resources/img/tipo_abrazo_0.jpg' alt='' /></label><input id='abrazo0' class='radio' type='radio' value='0' name='tipo' checked='' /><label style='font-size: 12px; font-family: arial; font-weight: bold; color: #535353;'>Abracito</label></li>"+
                "<li><label for='abrazo1'><img src='http://abrazatumeriva.es/widget/www/system/resources/img/tipo_abrazo_1.jpg' alt='' /></label><input id='abrazo1' class='radio' type='radio' value='1' name='tipo' /><label style='font-size: 12px; font-family: arial; font-weight: bold; color: #535353;'>Abrazote</label></li>"+
                "<li><label for='abrazo2'><img src='http://abrazatumeriva.es/widget/www/system/resources/img/tipo_abrazo_2.jpg' alt='' /></label><input id='abrazo2' class='radio' type='radio' value='2' name='tipo' /><label style='font-size: 12px; font-family: arial; font-weight: bold; color: #535353;'>Abrazo de Oso</label></li>"+
                "<li><label for='abrazo3'><img src='http://abrazatumeriva.es/widget/www/system/resources/img/tipo_abrazo_3.jpg' alt='' /></label><input id='abrazo3' class='radio' type='radio' value='3' name='tipo' /><label style='font-size: 12px; font-family: arial; font-weight: bold; color: #535353;'>Abrazo con palmas</label></li>"+
            "</ul>"+
            "<h3>3. &iquest;Vas a enviar un abrazo y no decirle por qu&eacute;? Vamos, escr&iacute;belo:</h3>"+
            "<textarea id='mensaje' onKeyUp='return maximaLongitud(this,150)' name='mensaje'></textarea>"+
            "<button id='btn_send' class='btn_enviar' onclick='enviar("+id_blogger+")' href='#'>"+
                    "<span>"+
                        "Env&iacute;a tu abrazo"+
                    "</span>"+
            "</button>"+
        "</div>";
        
        var a = document.createElement('a');
    	a.id='close_box';
        a.innerHTML = '<span>Close window</span>';
        a.href = 'javascript:void(0)';
        a.onclick = function() 
        {
          document.body.removeChild(document.getElementById('layer'));
          document.body.removeChild(document.getElementById('lbox'));
        };
        div.appendChild(a);
}


function NuevoAjax(){
    var xmlhttp=false;
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }

    if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function enviar(id_blogger){
    
    var tipo;
    n_send=document.getElementById("nombre_send");
    msg=document.getElementById("mensaje");
    if(n_send.value!='' && msg.value!=''){
        
        ajax=NuevoAjax();
    auxx1=document.getElementById("nombre_send");
    var nombre_send = auxx1.value;
    auxx2=document.getElementById("mensaje");
    var mensaje=auxx2.value;
    for(i=0; i<4; i++){
        radio=document.getElementById("abrazo"+i);
        if(radio.checked) {
            tipo=radio.value;
        }
    }
    ajax.open("GET", "http://abrazatumeriva.es/widget/www/index.php/widget/send/"+tipo+"/"+mensaje+"/"+nombre_send+"/"+id_blogger,true); 
    ajax.onreadystatechange=function(){
    }
    ajax.send(null);
    //alert("Su abrazo fué enviado satisfacoriamente.");
    //window.location.reload();
    document.body.removeChild(document.getElementById('layer'));
    document.body.removeChild(document.getElementById('lbox'));
    mostrarMsgEnviado();    
    }else alert("Introduzca su nombre y mensaje.");
    
}

function mostrarMsgEnviado(){
        msgEnviado="Tu mensaje fue enviado satisfactoriamente";
        var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
        var layer2 = document.createElement('div');
        layer2.style.zIndex = 4;
        layer2.id = 'layer2';
        layer2.style.position = 'fixed';
        layer2.style.top = '0px';
        layer2.style.left = '0px';
        //layer2.style.height = document.documentElement.scrollHeight + 'px';
        layer2.style.height = '100%';
        //layer2.style.width = width + 'px';
        layer2.style.width = '100%';
        layer2.style.backgroundColor = 'black';
        layer2.style.opacity = '.6';
        layer2.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
        document.body.appendChild(layer2);  
        
        var divmsg = document.createElement('div');
        divmsg.style.zIndex = 5;
        divmsg.id = 'lbox2';
        divmsg.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
        divmsg.style.top = '55px';
        divmsg.style.left = (width / 2) - (125) + 'px';	
        divmsg.style.width = '250px';
    	
        document.body.appendChild(divmsg);  
    	
    	divmsg.innerHTML = 
        "<div id='modalmsg'>"+
            "<p style='font-size:12px; text-align:center; font-family:arial;'>"+msgEnviado+"</p>"+
        "</div>";
        
        var close_msg = document.createElement('a');
    	close_msg.id='close_box';
        close_msg.innerHTML = '<span>Close window</span>';
        close_msg.href = 'javascript:void(0)';
        close_msg.onclick = function() 
        {
          document.body.removeChild(document.getElementById('layer2'));
          document.body.removeChild(document.getElementById('lbox2'));
          window.location.reload();
        };
        divmsg.appendChild(close_msg);
    
}

function maximaLongitud(texto,maxlong) { 
  var tecla, in_value, out_value; 
 
  if (texto.value.length > maxlong) { 
    in_value = texto.value; 
    out_value = in_value.substring(0,maxlong); 
    texto.value = out_value; 
    return false; 
  } 
  return true; 
}

/*function cambiarTilde(){
    elem=document.getElementById("tilde");
    elem.innerHTML="Env&iacute;a";
}*/
