/*
  Este es el Script para el reproductor Flash
*/


var flashvars = {
  'type': 'mp3',
  'file': encodeURIComponent('http://74.55.246.134:8000/;stream.nsv'),
  'autostart': 'true',
  'backcolor': '0xAE1414',
  'lightcolor': '0x141D2C',
  'frontcolor': '0x141D2C',
  'screencolor': '0xFB9B2B',
  'bufferlength': '1',
  'displayclick': 'play',
  'repeat': 'none',
  'id': 'flashplayer'
};

var params = {
  'allowfullscreen': 'true',
  'allowscriptaccess': 'always',
  'bgcolor': '#FFFFFF'
};

var attributes = {
  'id': 'flashplayer',
  'name': 'flashplayer'
};

/*
swfobject.embedSWF('flashplayer.swf', 'flashplayer', '250', '20', '8', false, flashvars, params, attributes);
*/


/*
  Este es el Script de FriendConnect
*/

function initAllData() {
  var req = opensocial.newDataRequest();
  req.add(req.newFetchPersonRequest("OWNER"), "owner_data");
  req.add(req.newFetchPersonRequest("VIEWER"), "viewer_data");
  var idspec = new opensocial.IdSpec({
    'userId' : 'OWNER',
    'groupId' : 'FRIENDS'
  });
  req.add(req.newFetchPeopleRequest(idspec), 'site_friends');
  req.send(onData);
};

function onData(data) {
  var tag_user = document.getElementById("tag_user");
  if (data.get("viewer_data").hadError()) {
    tag_user.innerHTML = "<input type='button' onclick='google.friendconnect.requestSignIn()' value='Participar'  id='tag_enviar' />Participa con tu cuenta de:<br /><div style='text-align: center; padding-top: 5px;'>" +
    "<img src='http://www.google.com/friendconnect/scs/images/id_logo_google.jpg' class='ico_openid' />" +
    "<img src='http://www.google.com/friendconnect/scs/images/id_logo_twitter.jpg' class='ico_openid' />" +
    "<img src='http://www.google.com/friendconnect/scs/images/id_logo_yahoo.jpg' class='ico_openid' />" +
    "<img src='http://www.google.com/friendconnect/scs/images/id_sm_logo_aim.png' class='ico_openid' />" +
    "<img src='http://www.google.com/friendconnect/scs/images/id_sm_logo_openid.png' class='ico_openid' />" +
    "<img src='http://netlog.com/favicon.ico' class='ico_openid' /></div>";
  } else {
    var viewer = data.get("viewer_data").getData();
    var d = new Date();
    var localTime = d.getTimezoneOffset();
    var localizacion;

    if (google.loader.ClientLocation) {
      localizacion =  "&latitud=" + google.loader.ClientLocation.latitude +
    "&longitud=" + google.loader.ClientLocation.longitude +
    "&pais_iso=" + google.loader.ClientLocation.address.country_code +
    "&ciudad=" + google.loader.ClientLocation.address.city +
    "&region=" + google.loader.ClientLocation.address.region +
    "&pais_nombre_en=" + google.loader.ClientLocation.address.country;
    }

    ajax3=nuevoAjax();
    ajax3.open('GET', 'entrar.php?openid=' + viewer.getId() + "&nombre=" + viewer.getDisplayName() + "&time_local=" + localTime + localizacion + "&thumb=" + viewer.getField(opensocial.Person.Field.THUMBNAIL_URL), true);
    ajax3.onreadystatechange=function() {
      if (ajax3.readyState==4) {
          escribe_perfil();
          contenido('tagboard');
      }
    }
    ajax3.send(null)
  }


  if (!data.get("site_friends").hadError()) {
    var site_friends = data.get("site_friends").getData();
    var list = document.getElementById("participantes");
    list.innerHTML = "";
    site_friends.each(function(friend) {
      list.innerHTML += "<img src=\"" + friend.getField(opensocial.Person.Field.THUMBNAIL_URL) + "\" alt=\"" + friend.getDisplayName() + "\" title=\"" + friend.getDisplayName() + "\" class=\"foto_participante\">\n";
    });
  }
};

google.friendconnect.container.initOpenSocialApi({
  site: '11038391571040325417',
  onload: function(securityToken) { initAllData(); }
});

/*
  Funcion AJAX Base
*/

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;
}

/*
  Funciones AJAX del Tagboard
*/

function agregar_mensaje(){
  var tag_display;
  tag_display = document.getElementById('tag_display');
  var mensaje = document.getElementById('tag_input').value;
  ajax2=nuevoAjax();
  ajax2.open('GET', 'display.php?mensaje=' + mensaje, true);
  ajax2.onreadystatechange=function() {
    if (ajax2.readyState==4) {
      tag_display.innerHTML = ajax2.responseText;
      document.getElementById('tag_input').value = '';
    }
  }
  ajax2.send(null)
}


function actualiza_display(){
  var tag_display;
  tag_display = document.getElementById('tag_display');
  ajax_display=nuevoAjax();
  ajax_display.open('GET', 'display.php', true);
  ajax_display.onreadystatechange=function() {
    if (ajax_display.readyState==4) {
      tag_display.innerHTML = ajax_display.responseText;
    }
  }
  ajax_display.send(null)
}

/*
  Funciones AJAX de Logueo
*/

function salir_radiointensa(){
    ajax4=nuevoAjax();
    ajax4.open('GET', 'salir.php', true);
    ajax4.onreadystatechange=function() {
      if (ajax4.readyState==4) {
        google.friendconnect.requestSignOut()
      }
    }
    var perfil;
    perfil = document.getElementById('perfil');
    perfil.innerHTML = "";
    actualiza_display();
    ajax4.send(null)
}

function inicia() {
	actualiza_display();
  actualiza_marquesina();
	window.setInterval('actualiza_display()', 10000);
	window.setInterval('actualiza_marquesina()', 4000);
}

/*
  Funciones AJAX de Marquesina
*/

function actualiza_marquesina(){
  var marquesina;
  marquesina = document.getElementById('marquesina');
  ajax5_marquesina=nuevoAjax();
  ajax5_marquesina.open('GET', 'marquesina.php', true);
  ajax5_marquesina.onreadystatechange=function() {
    if (ajax5_marquesina.readyState==4) {
      marquesina.innerHTML = ajax5_marquesina.responseText;
    }
  }
  ajax5_marquesina.send(null)
}

function agregar_sms(){
  var mensajito = document.getElementById('mensajito').value;
  ajax_sms=nuevoAjax();
  ajax_sms.open('GET', 'mensajito.php?mensajito=' + mensajito, true);
  ajax_sms.onreadystatechange=function() {
    if (ajax_sms.readyState==4) {
      contenido('tagboard');
    }
  }
  ajax_sms.send(null)
}




function contenido(pagina){
  var contenido;
  contenido = document.getElementById('contenido');
  ajax_contenido=nuevoAjax();
  ajax_contenido.open('GET', pagina + '.php', true);
  ajax_contenido.onreadystatechange=function() {
    if (ajax_contenido.readyState==4) {
      contenido.innerHTML = ajax_contenido.responseText;
    }
  }
  ajax_contenido.send(null)
}


function escribe_perfil(){
  var perfil;
  perfil = document.getElementById('perfil');
  ajax_perfil=nuevoAjax();
  ajax_perfil.open('GET', 'ver_perfil.php', true);
  ajax_perfil.onreadystatechange=function() {
    if (ajax_perfil.readyState==4) {
      perfil.innerHTML = ajax_perfil.responseText;
    }
  }
  ajax_perfil.send(null)
}


function patear(){
  contenido('patear');
  contenido('tagboard');
}




/*
  Funciones AJAX de Mensajitos
*/

function CountLeft(field, count, max) {
	if (field.value.length > max)
		field.value = field.value.substring(0, max);
	else
		count.value = max - field.value.length;
}
