function select_all() {
$.each($("#contacts_result").find('input'),function(a,ele){
  $(ele).attr("checked",true);
});

}
$(document).ready(function() {
 var espacio_izq = (document.body.clientWidth-$("#quick_menu").width())/2;
 $("#quick_menu").css("margin-left",espacio_izq);
 $(window).bind('resize', move_quickbar);
 $("twmensaje").wordWrap('on');
 // $(document).bind('scroll', move_quickbar);
  //move_quickbar();
  /*
  $(document).everyTime(15000, function(i) {
      twupdates();
    }, 99999);*/
});

function move_quickbar() {
  var espacio_izq = (document.body.clientWidth-$("#quick_menu").width())/2;
 $("#quick_menu").css("margin-left",espacio_izq);
 // var scroll = $(window).attr("scrollY");
 // $("#quick_menu").css("margin-top",scroll-20);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function send_tw() {
  var usuario = $("#twusuario").val();
  var password = $("#twpassword").val();
  var mensaje = $("#twmensaje").val();
 if (usuario == "" || password == "" || mensaje=="" || usuario == "Usuario" || password == "Password") {
   alert("Falta completar campos");
 } else {
     $.ajax({
  url: '/webservice/sendTW',
  data: ({user :usuario,
          pass: password,
          msg: mensaje
          }),
  type: "POST",
  dataType: 'json',
  success: function(data) {
    
    alert(data.msg);
    if (data.code== 200) {
      $("#twusuario").val("");
      $("#twpassword").val("");
      $("#twmensaje").val("");
    }
  }
});}
}

function labelUsuario() {
  if ($("#twusuario").val() == "Usuario") {
    $("#twusuario").val("");
  }
 
}

function labelPassword() {
  if ($("#twpassword").val() == "Password") {
    $("#twpassword").val("");
  }
}

function twresize() {
  var twmaxsize = 124;
  var twactualsize = $("#twmensaje").attr("value").length;
  if (twactualsize <= twmaxsize) {
    $("#twsize").attr("innerHTML",twmaxsize-twactualsize);
  } else {
    $("#twmensaje").attr("value",$("#twmensaje").attr("value").substr(0, 124));
  }
}

function twupdates() {
  $.ajax({
  url: '/webservice/twitterfeed',
  data: ({cant :1}),
  type: "POST",
  dataType: 'json',
  success: function(data) {
    var datatrim = $(data[0]).text().replace(" ", "");
    console.debug(datatrim);
    var fst = "<div>"+$($("#comentariosTwitter").children().get(0)).attr("innerHTML")+"</div>";
    fst = jQuery.trim(fst);
    console.debug(fst);
    if (fst != datatrim) {
    $.each(data, function(key, value) {
        $("#comentariosTwitter").append(value);
    });
    }
  }
});
}





/*
 * Change out the video that is playing
 */

// Update a particular HTML element with a new value
function updateHTML(elmId, value) {
  document.getElementById(elmId).innerHTML = value;
}

// Loads the selected video into the player.
function loadVideo1(idv) {
	//alert(idv)
  //var selectBox = document.getElementById("videoSelection");
  //var videoID = selectBox.options[selectBox.selectedIndex].value
  var videoID = idv;
  
  if(ytplayer) {
    ytplayer.loadVideoById(videoID);
  }
}

// This function is called when an error is thrown by the player
function onPlayerError(errorCode) {
  alert("An error occured of type:" + errorCode);
}

// This function is automatically called by the player once it loads
function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("ytPlayer1");
  ytplayer.addEventListener("onError", "onPlayerError");
}

// The "main method" of this sample. Called when someone clicks "Run".
function loadPlayer1() {
  // The video to load
  var videoID = "phpWEkpFwIo"
  // Lets Flash from another domain call JavaScript
  var params = { allowScriptAccess: "always" };
  // The element id of the Flash embed
  var atts = { id: "ytPlayer1" };
  // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
  swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "&enablejsapi=1&playerapiid=player1", "reproductorVideo", "480", "295", "8", null, null, params, atts);
}
