///////////////////////////////////////////////////////////////////
// FunciяПНn para enviar la variable web "embebido" al player 
// para las estadisticas de Google                                                                                                     
///////////////////////////////////////////////////////////////////
function gaweb(){
  var webGA="embebido";
  return webGA;
}

///////////////////////////////////////////////////////////////////
// Keep Alive para subir video
///////////////////////////////////////////////////////////////////
function keepAlive() { 
	setInterval('ping()',1000*60*5);
}
function ping() {
	daleAjaxPOST(1,'/subir.php','ping=1','exitPing');
}
function exitPing() {
}

///////////////////////////////////////////////////////////////////
// SEM
///////////////////////////////////////////////////////////////////
function registrarEntrada() {
	var query_var = window.location.search;

	var rid = null;
	if (query_var.indexOf('?rid=') > -1) {
		( query_var.indexOf('&',query_var.indexOf('?rid=')) == -1) ? end_var = query_var.length :    end_var = query_var.indexOf('&',query_var.indexOf('?rid='));
		rid = query_var.substring(query_var.indexOf('?rid=')+5, end_var);
	} else if (query_var.indexOf('&rid=') > -1) {
		( query_var.indexOf('&',query_var.indexOf('&rid=')+5) == -1) ? end_var = query_var.length :    end_var = query_var.indexOf('&',query_var.indexOf('&rid=')+5);
		rid = query_var.substring(query_var.indexOf('&rid=')+5, end_var);
	}

	if(rid != null) {
		div_rid=document.getElementById("pixel");
		if (div_rid != null)
		{
			//contenido = "<img width=\"1\" height=\"1\" src=\"http://www.dalealplay.com/automaticos/pixel_register.php?rid="+rid+" />";
			//div_rid.innerHTML = contenido;
			div_rid.src = "http://www.dalealplay.com/automaticos/pixel_register.php?rid="+rid;
		}
	}
}

///////////////////////////////////////////////////////////////////
// Abrir paginas con AJAX
///////////////////////////////////////////////////////////////////
function crearObjeto()
{
	var ro;
	var browser = navigator.appName;
	if(browser == 'Microsoft Internet Explorer')
	{
		ro = new ActiveXObject('Microsoft.XMLHTTP');	
	}
	else
	{
		ro = new XMLHttpRequest();	
	}
	return ro;
}
var http1 = crearObjeto();
var http2 = crearObjeto();
function daleAjax(id,url,arg,func)
{
	eval("http"+id+".open('get','"+url+".php?"+arg+"',true);");
	eval("http"+id+".onreadystatechange = "+func+";");
	eval("try { http"+id+".send(null); } catch(e) { alert('Se ha producido un error. Por favor, actualiza la pяПНgina'); }");
}

function daleAjaxOriginal(id,url,arg,func)
{
	eval("http"+id+".open('get','"+url+"?"+arg+"',true);");
	eval("http"+id+".onreadystatechange = "+func+";");
	eval("http"+id+".setRequestHeader('content-type', 'text/html');");
	eval("try { http"+id+".send(null); } catch(e) { alert('Se ha producido un error. Por favor, actualiza la pяПНgina'); }");

//		req.setRequestHeader('content-type', 'text/xml');

}

function daleAjaxPOST(id,url,arg,func)
{
	/*http1.open('POST', url,true);
	http1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http1.setRequestHeader('Accept-Charset', 'UTF-8');
	http1.send(arg);
	eval("http"+id+".onreadystatechange = "+func+";");*/

	eval("http"+id+".open('POST','"+url+"',true);");
	eval("http"+id+".setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');");
	eval("http"+id+".setRequestHeader('Accept-Charset', 'UTF-8');");
	eval("http"+id+".send(arg);");
	eval("http"+id+".onreadystatechange = "+func+";");
	
}

/***********************************************
* Dynamic Ajax Content- яПН Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=0 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid){	
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false

	page_request.onreadystatechange=function(){
		loadpage(page_request, containerid)
	}

	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)

}

function loadpage(page_request, containerid){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
		document.getElementById(containerid).innerHTML=page_request.responseText
		if (document.getElementById(containerid).style.display == 'none')
			document.getElementById(containerid).style.display = '';
	}
}

function loadobjs() {
	if (!document.getElementById)
		return
	for (i=0; i<arguments.length; i++) {
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1) { //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1) { //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}
			else if (file.indexOf(".css")!=-1) { //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!="") {
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
}

function HideContent(d) {
	if(d.length < 1) { return; }
	objeto = document.getElementById(d);
	objeto.style.display = "none";
	objeto.innerHTML = "";
	hideCargando();
}
function ShowContent(d) {
	showCargando();
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
	else { document.getElementById(d).style.display = "none"; }
	}
function showCargando() {
	//cargando = document.getElementById('cargando');
	//cargando.style.display = "block";
	document.getElementById('cargando').style.display = "block";
}
function hideCargando() {
	//cargando = document.getElementById("cargando");
	//cargando.style.display = "none";
	document.getElementById('cargando').style.display = "none";
}

///////////////////////////////////////////////////////////////////
// COOKIES
///////////////////////////////////////////////////////////////////
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


///////////////////////////////////////////////////////////////////
// Mensajes en CAPA
///////////////////////////////////////////////////////////////////
function showSizedOverlay(width, height) {
	// Ocultar los objetos flash para que no se solapen.
	var objects = document.getElementsByTagName("video");
	for(var i = 0; i < objects.length; i++) {
		//objects[i].style.visibility = 'hidden';
		objects[i].style.display = 'none';
	}

	var objects = document.getElementsByTagName("object");
	for(var i = 0; i < objects.length; i++) {
		if (objects[i].id != "reproductor") {
			objects[i].style.visibility = 'hidden';
		}
	}
	if (document.getElementById('reproductorDiv') != null) {
		document.getElementById('reproductorDiv').style.visibility = 'hidden';
	}
	if (document.getElementById('videosDest') != null) {
		document.getElementById('videosDest').style.visibility = 'hidden';
	}
	if (document.getElementById('logo') != null) {
		document.getElementById('logo').style.visibility = 'hidden';
	}
	if (document.getElementById('banner_roba') != null) {
		document.getElementById('banner_roba').style.visibility = 'hidden';
	}
	if (document.getElementById('publi') != null) {
		document.getElementById('publi').style.visibility = 'hidden';
	}

	// Posicion basada en el scroll
	var yPos = (document.all)?document.documentElement.scrollTop:window.pageYOffset;
	setOverlaySize(width, height);
	document.getElementById("overlaySizer").style.marginTop = (yPos+50)+"px";
	document.getElementById("overlayLayer").style.visibility = "visible";
	setBackHeight();
	//setTimeout("setBackHeight()", 1000); // call again later... in case the page gets longer as a result of our display
}

function setOverlaySize(width, height) {
	document.getElementById("overlaySizer").style.width = width+"px";
	document.getElementById("overlaySizer").style.height = height+"px";
	// if the frame does not get its size set directly, IE does not size it right
	document.getElementById("overlayFrame").style.width = width+"px";
	document.getElementById("overlayFrame").style.height = height+"px";
}

function showOverlay() {
	showSizedOverlay(520, 350);
}

function hideOverlayNoContentChange() {
	document.getElementById("overlayBackground").style.height = "0px"; // resize this layer to nothing so it does not affect the scrollbar size
	// resize the overlay layer so it does not scroll invisibly (IE bug)
	setOverlaySize(0, 0);
	document.getElementById("overlayLayer").style.visibility = "hidden";

	var objects = document.getElementsByTagName("video");
	for(var i = 0; i < objects.length; i++) {
		objects[i].style.display = '';
	}

	var objects = document.getElementsByTagName("object");
	for(var i = 0; i < objects.length; i++) {
		objects[i].style.visibility = 'visible';
	}
	if (document.getElementById('reproductorDiv') != null) {
		document.getElementById('reproductorDiv').style.visibility = 'visible';
	}
	if (document.getElementById('videosDest') != null) {
		document.getElementById('videosDest').style.visibility = 'visible';
	}
	if (document.getElementById('logo') != null) {
		document.getElementById('logo').style.visibility = 'visible';
	}
	if (document.getElementById('banner_roba') != null) {
		document.getElementById('banner_roba').style.visibility = 'visible';
	}
	if (document.getElementById('publi') != null) {
		document.getElementById('publi').style.visibility = 'visible';
	}
	if (document.getElementById('capa_video_bri') != null) {
		document.getElementById('capa_video_bri').style.zIndex= '1';
	}
	if (document.getElementById('overlaySizer') != null) {
		document.getElementById('overlaySizer').style.display = 'block';
	}

	document.getElementById("overlayFrame").innerHTML = '<img src="/img/bigrotation2.gif" style="margin-top:100px;float:none" />';
}

function hideOverlay() {
	hideOverlayNoContentChange();
}

function setBackHeight() {
	var height = document.body.offsetHeight;
	document.getElementById("overlayBackground").style.height = height + "px";
}

function mostrarCortinillaOpoca(tpl) {
	div = 'overlayFrame';
	showOverlay();
	ajaxpage('/load.php?tpl=includes/'+tpl, 'overlayFrame');
	document.getElementById("overlayBackground").style.height = "10000px";
	document.getElementById("overlayBackground").style.opacity = '1';
	document.getElementById("overlayBackground").style.filter = 'alpha(opacity=1)';
}

///////////////////////////////////////////////////////////////////
// Carga el player con el nuevo sistema
///////////////////////////////////////////////////////////////////
function cargaPlayer(url_player, ancho, alto, colorfondo) {

	AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
		'width', ancho,
		'height', alto,
		'src', 'destacados',
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'transparent',
		'devicefont', 'false',
		'id', 'destacados',
		'bgcolor', colorfondo,
		'name', 'destacados',
		'menu', 'true',
		'allowFullScreen', 'true',
		'allowScriptAccess','sameDomain',
		'movie', url_player,
		'salign', ''
		); //end AC code

}

///////////////////////////////////////////////////////////////////
// Abrir una URL en ventana nueva.
///////////////////////////////////////////////////////////////////
function abrir_url(direccion, pantallacompleta, herramientas, direcciones, estado, barramenu, barrascroll, cambiatamano, ancho, alto, izquierda, arriba, sustituir) {
     var opciones = "fullscreen=" + pantallacompleta +
                 ",toolbar=" + herramientas +
                 ",location=" + direcciones +
                 ",status=" + estado +
                 ",menubar=" + barramenu +
                 ",scrollbars=" + barrascroll +
                 ",resizable=" + cambiatamano +
                 ",width=" + ancho +
                 ",height=" + alto +
                 ",left=" + izquierda +
                 ",top=" + arriba;
     var ventana = window.open(direccion,"venta",opciones,sustituir);
}
///////////////////////////////////////////////////////////////////
// SKIN de publicidad
///////////////////////////////////////////////////////////////////
	var contX;

	function body_click(ev) {
		var px, py, cadena, obj;

		if (!document.all) {
       event = ev;
       py = ev.pageY;
       px = ev.pageX;
		} else {
       py = event.clientY +document.body.scrollTop;
       px = event.clientX +document.body.scrollLeft;
		}

		if (contX > 0) {
			if ( (px < (contX)) && (px > (contX-155)) ) {
				click_publi();
			}
			if ( (px > (contX+960)) && (px < (contX+960+155)) ) {
				click_publi();
			}
		}

	}

	function mouse_move(ev) {
		var px, py, cadena, obj;

		if (!document.all) {
       event = ev;
       py = ev.pageY;
       px = ev.pageX;
		} else {
       py = event.clientY +document.body.scrollTop;
       px = event.clientX +document.body.scrollLeft;
		}

		if (contX > 0) {
			if ( (px < (contX)) && (px > (contX-155)) ) {
				cambiar_puntero("pointer");
			}
			else if ( (px > (contX+960)) && (px < (contX+960+155)) ) {
				cambiar_puntero("pointer");
			}
			else {
				cambiar_puntero("default");
			}
		}
	}

	function body_click_perfil(ev) {
		var px, py, cadena, obj;

		if (!document.all) {
       event = ev;
       py = ev.pageY;
       px = ev.pageX;
		} else {
       py = event.clientY +document.body.scrollTop;
       px = event.clientX +document.body.scrollLeft;
		}

		if (contX > 0) {
			if ( (px < (contX)) && (px > (contX-180)) ) {
				click_publi();
			}
			if ( (px > (contX+920)) && (px < (contX+920+180)) ) {
				click_publi();
			}
		}

	}

	function mouse_move_perfil(ev) {
		var px, py, cadena, obj;

		if (!document.all) {
       event = ev;
       py = ev.pageY;
       px = ev.pageX;
		} else {
       py = event.clientY +document.body.scrollTop;
       px = event.clientX +document.body.scrollLeft;
		}

		if (contX > 0) {
			//if ( (px < (contX)) && (px > (contX-155)) ) {
			if ( (px < (contX)) && (px > (contX-180)) ) {
				cambiar_puntero("pointer");
			}
			//else if ( (px > (contX+960)) && (px < (contX+960+155)) ) {
			else if ( (px > (contX+920)) && (px < (contX+920+180)) ) {
				cambiar_puntero("pointer");
			}
			else {
				cambiar_puntero("default");
			}
		}
	}

	function cambiar_puntero(puntero) {
		document.body.style.cursor = puntero;
	}

	function click_publi() {
			ran = Math.round(Math.random() * 100000000);
			url_publi = 'http://reachandrich.antevenio.com/call/cliccommand/3869888/'+ran+'?';
			abrir_url(url_publi, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1)
	}

	function body_resize() {
			contX = PositionOBJ.get(document.getElementById('container')).left;
	}


	var PositionOBJ = (function() {
	// Resolve a string identifier to an object
	// ========================================
	function resolveObject(s) {
		if (document.getElementById && document.getElementById(s)!=null) {
			return document.getElementById(s);
		}
		else if (document.all && document.all[s]!=null) {
			return document.all[s];
		}
		else if (document.anchors && document.anchors.length && document.anchors.length>0 && document.anchors[0].x) {
			for (var i=0; i<document.anchors.length; i++) {
				if (document.anchors[i].name==s) { 
					return document.anchors[i]
				}
			}
		}
	}
	
	var pos = {};
	pos.$VERSION = 1.0;
	
	// Set the position of an object
	// =============================
	pos.set = function(o,left,top) {
		if (typeof(o)=="string") {
			o = resolveObject(o);
		}
		if (o==null || !o.style) {
			return false;
		}
		
		// If the second parameter is an object, it is assumed to be the result of getPosition()
		if (typeof(left)=="object") {
			var pos = left;
			left = pos.left;
			top = pos.top;
		}
		
		o.style.left = left + "px";
		o.style.top = top + "px";
		return true;
	};
	
	// Retrieve the position and size of an object
	// ===========================================
	pos.get = function(o) {
		var fixBrowserQuirks = true;
			// If a string is passed in instead of an object ref, resolve it
		if (typeof(o)=="string") {
			o = resolveObject(o);
		}
		
		if (o==null) {
			return null;
		}
		
		var left = 0;
		var top = 0;
		var width = 0;
		var height = 0;
		var parentNode = null;
		var offsetParent = null;
	
		
		offsetParent = o.offsetParent;
		var originalObject = o;
		var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
		while (el.parentNode!=null) {
			el = el.parentNode;
			if (el.offsetParent==null) {
			}
			else {
				var considerScroll = true;
				/*
				In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
				take its scroll position into account. If elements further up the chain are scrollable, their 
				scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
				which must be ignored.
				*/
				if (fixBrowserQuirks && window.opera) {
					if (el==originalObject.parentNode || el.nodeName=="TR") {
						considerScroll = false;
					}
				}
				if (considerScroll) {
					if (el.scrollTop && el.scrollTop>0) {
						top -= el.scrollTop;
					}
					if (el.scrollLeft && el.scrollLeft>0) {
						left -= el.scrollLeft;
					}
				}
			}
			// If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
			if (el == offsetParent) {
				left += o.offsetLeft;
				if (el.clientLeft && el.nodeName!="TABLE") { 
					left += el.clientLeft;
				}
				top += o.offsetTop;
				if (el.clientTop && el.nodeName!="TABLE") {
					top += el.clientTop;
				}
				o = el;
				if (o.offsetParent==null) {
					if (o.offsetLeft) {
						left += o.offsetLeft;
					}
					if (o.offsetTop) {
						top += o.offsetTop;
					}
				}
				offsetParent = o.offsetParent;
			}
		}
		
	
		if (originalObject.offsetWidth) {
			width = originalObject.offsetWidth;
		}
		if (originalObject.offsetHeight) {
			height = originalObject.offsetHeight;
		}
		
		return {'left':left, 'top':top, 'width':width, 'height':height
				};
	};
	
	// Retrieve the position of an object's center point
	// =================================================
	pos.getCenter = function(o) {
		var c = this.get(o);
		if (c==null) { return null; }
		c.left = c.left + (c.width/2);
		c.top = c.top + (c.height/2);
		return c;
	};
	
	return pos;
})();

///////////////////////////////////////////////////////////////////
// LOGIN FORO
///////////////////////////////////////////////////////////////////

function LoginForo(id, aux_div) {
	div = aux_div;
	if (!puedoMostrarDIV(aux_div))
		return;

	showOverlay();

	if (logado) {
			//alert("hola");
		} else {
			login_retorno = 'reloadpage();';
		ajaxpage('/load.php?tpl=includes/login', aux_div);
		}

			
}
function reloadpage()
{
window.location.reload();
}
///////////////////////////////////////////////////////////////////
// Imagenes BC
///////////////////////////////////////////////////////////////////
	function getThumb() {
		return false;
		token = "swLkLblaefzpia4EkLVTNVzzayks6vm6jzbscIVEDnfytwKPHBT0UA..";
		arr_id = getElementById();
		if (arr_id.length > 0) {
			getBCVideos(arr_id, token);
		}
	}

	function getThumbQUE() {
		return false;
		token = "_i5RpV5gG4VXU9hVNCQ8eedcBheVNVINlar-9vvtZ1TxNtWm5kzCKQ..";
		arr_id = getElementById();
		if (arr_id.length > 0) {
			getBCVideos(arr_id, token);
		}
	}

	function getBCVideos(arr_id, token) {
		return false;
		kudos.token = token;
		kudos.cb = "response_getBCVideos";
		kudos.fields = "referenceId,thumbnailURL";

		reference_ids = arr_id.join(",");
		kudos.get("find_videos_by_reference_ids", reference_ids);
	}

	function response_getBCVideos(response) {
		for(var i = 0; i < objects.length; i++) {
			id_obj = objects[i].id.replace(bc_marca,bc_clon);
			if (id_obj != "") {
				for(var j = 0; j < response.items.length; j++) {
					if (response.items[j] != null) {
						if (id_obj == response.items[j].referenceId) {
							objects[i].src = response.items[j].thumbnailURL;
							j = 1000;
						}
					}
				}
			}
		}

		/*for(var i = 0; i < response.items.length; i++) {
			if (response.items[i] != null) {
				obj_img_id = response.items[i].referenceId.replace(bc_clon,bc_marca);
				if (document.getElementById(obj_img_id) != null) {
					document.getElementById(obj_img_id).src = response.items[i].thumbnailURL;
				}
			}
		}*/
	}

	function getElementById() {
		objects = document.getElementsByTagName("img");
		var tag = bc_marca;
		var arr_id = new Array();

		j = 0;
		for(var i = 0; i < objects.length; i++) {
			if(objects[i].id.indexOf(tag)!=-1) {
				arr_id[j] = objects[i].id.replace(bc_marca,bc_clon);
				j++;
			}
		}
		return arr_id;
	}



