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 GetCursorPosition(campo){
	var tb = document.getElementById(campo);
	var cursor = -1;

	if (document.selection && (document.selection != 'undefined')){
		var _range = document.selection.createRange();
		var contador = 0;
		while (_range.move('character', -1)){
			contador = contador + 1;
		}
		cursor = contador;
	}else if (tb.selectionStart >= 0){
		cursor = tb.selectionStart;
	}
	return cursor;
}

function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

	if (strEmail.search(validRegExp) == -1){
		alert('Direcci?n de mail no valida');
		return false;
	}
	return true;
}

function IsNumeric(strString){
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++){
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1){
         blnResult = false;
      }
   }
   return blnResult;
}

function enviarAmigo(id){
	window.open("/tv/enviar.php?vid_id=" + id, "popup_enviar", "width=570,height=300");
}

function comentar(id){
	window.open("/tv/comentar.php?vid_id=" + id, "popup_comentar", "width=570,height=300");
}

function incluir(id){
alert(id);
	window.open("{_PATH}/admin-citpax/copiar_url_fichero.php?fichero="+id,"popup_incluir", "width=565,height=250");
}

function descargar(id){
	window.open("/tv/descargar.php?vid_id=" + id, "popup_compartir", "width=565,height=150");
}

function cargarContenido(destino){
	var contenedor;
	var resaltado;
	contenedor = document.getElementById('canal');
	ajax=nuevoAjax();
	ajax.open("POST", "/tv/ajax/top_videos.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("destino="+destino);
	resaltado = document.getElementById(activoantes);
	resaltado.className="";
	resaltado = document.getElementById(destino);
	resaltado.className="seleccionado";
	activoantes=destino;
}

function cargaComentario(pag,cuantas){
	var pagina;
	var contenedor;
	var numeracion = document.getElementById('numeracion');
	numeracion.innerHTML = "P&aacute;gina "+pag+" de "+cuantas;
	for(i=1;i<=cuantas;i++){
		pagina = document.getElementById('pag_' + i);
		if(i==pag){
			pagina.className = "seleccionado";
		}else{
			pagina.className = "";
		}
	}

	contenedor = document.getElementById('zona_comentarios');
	contenedor.innerHTML = "";
	eval("var miArray = comentario_"+pag+";");
	for(i=0;i<miArray.length;i++){
		contenedor.innerHTML = contenedor.innerHTML + "" + miArray[i];
	}
}

function showPlaylist(){
	var zonaplaylist;
	zonaplaylist = document.getElementById('videoteca');
	if(show_playlist){
		show_playlist = false;
		zonaplaylist.innerHTML = "<h2><a href=\"javascript:showPlaylist()\">Mi Videoteca <img src=\"/tv/img/videotecanodesple.gif\" alt=\"\" /></a></h2>";
	}else{
		show_playlist = true;
		zonaplaylist.innerHTML = "Cargando datos ...";
		ajax=nuevoAjax();
		ajax.open("POST", "/tv/ajax/playlist_show.php",true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==4) {
				zonaplaylist.innerHTML = ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(null);
	}

}

function addPlaylist(video){
	ajax=nuevoAjax();
	ajax.open("POST", "/tv/ajax/playlist_add.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			dato_recibido = ajax.responseText;
			show_playlist = false;
			showPlaylist();
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("vid_id="+video);
}

function clearPlaylist(){
	ajax=nuevoAjax();
	ajax.open("POST", "/tv/ajax/playlist_clear.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			dato_recibido = ajax.responseText;
			show_playlist = true;
			showPlaylist();
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(null);
}

function dropFromPlaylist(video){
	ajax=nuevoAjax();
	ajax.open("POST", "/tv/ajax/playlist_drop.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			dato_recibido = ajax.responseText;
			show_playlist = false;
			showPlaylist();
		}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("vid_id="+video);
}

function getElementTop(Elem) {
	var elem = document.getElementById(Elem);
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
	var i=xUA.indexOf('opera');
	if(i!=-1){
		var v=parseInt(xUA.charAt(i+6));
		xOp7Up=v>=7;xOp6Dn=v<7;
	}
}else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){
	xIE4Up=parseFloat(navigator.appVersion)>=4;
	xIE4=xUA.indexOf('msie 4')!=-1;
	xIE5=xUA.indexOf('msie 5')!=-1;
}else if(document.layers){
	xNN4=true;
}
xMac=xUA.indexOf('mac')!=-1;

function xDef(){
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])=='undefined') return false;
	}return true;
}

function xGetElementById(e){
	if(typeof(e)=='string') {
		if(document.getElementById) e=document.getElementById(e);
		else if(document.all) e=document.all[e];
		else e=null;
	}
	return e;
}

function xLeft(e, iX){
	if(!(e=xGetElementById(e))) return 0;
	var css=xDef(e.style);
	if (css && xStr(e.style.left)) {
		if(xNum(iX)) e.style.left=iX+'px';
		else {
			iX=parseInt(e.style.left);
			if(isNaN(iX)) iX=0;
		}
	}else if(css && xDef(e.style.pixelLeft)) {
		if(xNum(iX)) e.style.pixelLeft=iX;
		else iX=e.style.pixelLeft;
	}
	return iX;
}

function xMoveTo(e,x,y){
	xLeft(e,x);xTop(e,y);
}

function xNum(){
	for(var i=0; i<arguments.length; ++i){
		if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;
	}
	return true;
}

function xScrollTop(e, bWin){
	var offset=0;
	if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
		var w = window;if (bWin && e) w = e;
		if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
		else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
	}else {
		e = xGetElementById(e);
		if (e && xNum(e.scrollTop)) offset = e.scrollTop;
	}
	return offset;
}

function xStr(s){
	for(var i=0; i<arguments.length; ++i){
		if(typeof(arguments[i])!='string') return false;
	}
	return true;
}

function xTop(e, iY){
	if(!(e=xGetElementById(e))) return 0;
	var css=xDef(e.style);
	if(css && xStr(e.style.top)) {
		if(xNum(iY)) e.style.top=iY+'px';
		else {
			iY=parseInt(e.style.top);
			if(isNaN(iY)) iY=0;
		}
	}else if(css && xDef(e.style.pixelTop)) {
		if(xNum(iY)) e.style.pixelTop=iY;
		else iY=e.style.pixelTop;
	}
	return iY;
}

  function popup(url){
    window.open(url, "popup", "width=560,height=700,scrollbars=yes,resizable=no");
  }