var ELEMENT_NODE = 1;
var ATTRIBUTE_NODE = 2;
var TEXT_NODE = 3;
var CDATA_SECTION_NODE = 4;
var ENTITY_REFERENCE_NODE = 5;
var ENTITY_NODE = 6;
var PROCESSING_INSTRUCTION_NODE = 7;
var COMMENT_NODE = 8;
var DOCUMENT_NODE = 9;
var DOCUMENT_TYPE_NODE = 10;
var DOCUMENT_FRAGMENT_NODE = 11;
var NOTATION_NODE = 12;

var filterContent = null;
var cFilterContent = null;
var _winTabs = new Array();
	
var SUPER = window;
var SUPERi = 0;
var MYPLIST = null;
var ACTUALBLOG = false;

if(window.location.host.indexOf('loaded.') != -1)	var BLOGDIR = 'blogs.loaded.vg';
else																								var BLOGDIR = 'loaded.blogs.int';

var FOROSDIR = "site/foros";

var LASTSECTION = 0;

var prefix="site/web/";
while(SUPER.ME_WIN_ID != "MAIN" & SUPERi<5){
	SUPER = SUPER.parent;
	SUPERi++;
}
		/*p = window.location.pathname.split("/")[1] ? "" : "/";
		if(window.location.pathname.indexOf(p + "site/web/") == -1)				var prefix = p + "site/web/";
		else if(window.location.pathname.indexOf(p) == -1)	var prefix = "site/web/";
		else if(window.location.pathname.indexOf("site/web/") == -1)	var prefix = p;
		else																											var prefix = "";
		*/
		//if(window.location.host != "pansensual" && window.location.host != "router") prefix = "/site/teb/";

var SUPERDIRECT = (SUPER.location.href.indexOf("?to=") != -1) ? true : false;


if((SUPER.location.href.indexOf(BLOGDIR) != -1 || SUPER.location.href.indexOf(FOROSDIR) != -1)){
	try{
		if(_toLoad)		var ok = true;
	}catch(e){
		_toLoad = new Array();
	}

	_toLoad[_toLoad.length] = function(){
		ACTUALBLOG = (SUPER.location.href.indexOf(BLOGDIR) != -1);
		BlogON();
	}
}

	function initListado(section){
		if(!section)
			section = SECTION;

		section = section.toUpperCase();

		if(section == 'BUSQUEDA' || section == 'JUEGOS' || section == 'VIDEOS' || section == 'DOWNLOADS' || section == 'ESPECIALES')
			MYPLIST = new Listado(section, "../xml/get_avanzado.php", "Listado", "Destacado", SUPER.filterContent.getFilters(), SEARCH);
		else if(section == 'TRUCOS')
			MYPLIST = new Listado(section, "../xml/trucos.php", "Listado", "Destacado", SUPER.filterContent.getFilters(), SEARCH);
		else
			MYPLIST = new Listado(section, "../xml/get_listado.php", "Listado", "Destacado", SUPER.filterContent.getFilters(), SEARCH);
	}
	
	function sAvanzado(Objs, Filters, mSearch, dates){
		if(!Filters)
			Filters = SUPER.filterContent.getFilters();

		MYPLIST = new ListadoAVZ(Objs, "../xml/avanzado.php", "Listado", "KindDemo", Filters, mSearch, null,dates);
	}

	function initListadoHome(){
		//myplistN = new Listado("Noticias", "../xml/listado.php", "N_Listado", "N_Destacado", SUPER.filterContent.getFilters());
		myplistN = new Listado("Noticias", "../xml/get_listado.php", "N_Listado", "N_Destacado", SUPER.filterContent.getFilters());
		//myplistP = new Listado("Previews", "../xml/listado.php", "P_Listado", "P_Destacado", SUPER.filterContent.getFilters());
		myplistP = new Listado("Previews", "../xml/get_listado.php", "P_Listado", "P_Destacado", SUPER.filterContent.getFilters());
		//myplistR = new Listado("Reviews", "../xml/listado.php", "R_Listado", "R_Destacado", SUPER.filterContent.getFilters());
		myplistR = new Listado("Reviews", "../xml/get_listado.php", "R_Listado", "R_Destacado", SUPER.filterContent.getFilters());
		
		//myplistV = new Listado("Videos", "../xml/avanzado.php", "V_Listado", false, SUPER.filterContent.getFilters(), null, "VideoDemo");
		myplistV = new Listado("Videos", "../xml/get_avanzado.php", "V_Listado", false, SUPER.filterContent.getFilters(), null, "VideoDemo");
		myplistV.setPageLength(3);
	}
	
	//function SearchAv(OBJ,DATES,SEARCH,FILTER){
	function SearchAv(param){
		if(ACTUALBLOG)
			BlogOFF();

		var str = "";
		var splitParams = param.split('|') ;	  
	  var ops = new Array("all","juegos","previews","reviews","noticias","videos","downloads","guias","trucos");

	  // Parseo el parametro grande ,en sub-parametros.
		var OBJnum = splitParams[0];
		var DATES = splitParams[1];
		var SEARCH = splitParams[2];
		var FILTER = null;
		var FECHA = false;
		var error = "";

		// Juego un poco con las fechas
		var aDATES = DATES.split(',');

		if ( aDATES.length == 0 || DATES == ",")
			DATES = null;
		else{
			if ( ( aDATES[0] == '' ) && ( aDATES[1] != '' ) )					error += (error == "" ? "" : "\n") + "Debe especificar ambas fechas";
			else if ( ( aDATES[1] == '' ) && ( aDATES[0] != '' ) )		error += (error == "" ? "" : "\n") + "Debe especificar ambas fechas";
			else																												DATES = aDATES[0] + ',' + aDATES[1];
			var error1 = (error == "") ? true : false;

			if(aDATES[0].length < 8)																		error += (error == "" ? "" : "\n") + "La fecha DESDE, esta mal formateada, debe estar asi DD/MM/YYYY ejemplo, 01/01/2007";
			if(aDATES[1].length < 8)																		error += (error == "" ? "" : "\n") + "La fecha HASTA, esta mal formateada, debe estar asi DD/MM/YYYY ejemplo, 01/01/2007";
			
			var error2 = (error != "") ? true : false;
			
			if(!SAV_ValidateDate(aDATES[0]) && !error2)								error += (error == "" ? "" : "\n") + "La fecha DESDE es invalida";
			if(!SAV_ValidateDate(aDATES[1]) && !error2)								error += (error == "" ? "" : "\n") + "La fecha HASTA es invalida";
			
			var error3 = (error != "") ? true : false;
			
			if((aDATES[1]*1)<(aDATES[0]*1) && !error2 && !error3)		error += (error == "" ? "" : "\n") + "La fecha HASTA, debe ser mayor a la fecha DESDE";
			FECHA = true;
		}

		if(!error || error == ""){
			// Transformo los OBJ en  numero a los OBJ en palabras
			var OBJopciones = OBJnum.split(',');
			var OBJ = new Array(OBJopciones.length);
	
			for( var index = 0 ; index < OBJopciones.length ; index++ )
			{
				OBJ[index] = ops[ OBJopciones[index] ] ;
			}
	
			if(!OBJ)	str += "OBJ=ALL";
			else			str += "OBJ=" + OBJ;
			
			if(!FILTER)		str += "&FILTER=" + SUPER.filterContent.getFilters();
			else					str += "&FILTER=null"; //+ FILTER;
			
			if(DATES)			str += "&DATES=" + DATES;
			if(FECHA)			str += "&FECHA=1";
			
			if(SEARCH)		str += "&SEARCH=" + SEARCH;
		
			$('ContentFrame').src = prefix+'contents/resultados_av.php?' + str;
		}else{
			alert(error);
		}
	}
	
	function loaded(){
		for(var i=0;i<_toLoad.length;i++){
			try{
				_toLoad[i]();
			}
			catch(e){}
		}
		
		reScaleColumns();
		
		if(ME_WIN_ID && ME_WIN_ID != "MAIN")
			iframeGetSize();
	}
	
	function setTitle(t){
		document.title = t;
		SUPER.document.body.scrollTop=0;
	}
	
	function reScaleColumns(offset){
		var colI = $('ColumnaIzquierda');
		var colD = $('ColumnaDerecha');


		if(colI || colD){
			colI.style.height = "auto";
			if(firstElementChild(colI).className == "ContentSumario")
				firstElementChild(colI).style.height = "auto";
	
			if(!offset) offset = 0;
			else{
				//colI.style.height = colI.offsetHeight+offset+"px";
				//firstElementChild(colI).style.height = colI.offsetHeight+offset+"px";
			}
			
			if(colD){
				if((colI.offsetHeight+offset) < colD.offsetHeight){
					colI.style.height = colD.offsetHeight+"px";
					if(firstElementChild(colI).className == "ContentSumario")
						firstElementChild(colI).style.height = colD.offsetHeight+"px";
				}
			}
		}
	}
	
	function firstElementChild(pa){
		var c = pa.childNodes;
		for(var i=0;i<c.length;i++){
			if(c[i].nodeType == ELEMENT_NODE){
				return c[i];
				break;
			}				
		}
		return null;
	}
	
	function iframeResize(id, height){
		try{
			$(id).style.height = height+"px";
		}catch(e){}
	}
	
	function byPass(){
		return document.getElementsByTagName('*');
	}
	
	function changeSection(id){
		if((id != 9 && id != 8)){
			BlogOFF();
		}
	
	
		if(id != null){
			switch(id){
				case 0:
					$('ContentFrame').src = prefix+'contents/index.php';
				break;
				case 1:
					$('ContentFrame').src = prefix+'contents/noticias.php';
					break;
				case 2:
					$('ContentFrame').src = prefix+'contents/previews.php';
					break;
				case 3:
					$('ContentFrame').src = prefix+'contents/reviews.php';
					break;
				case 4:
					$('ContentFrame').src = prefix+'contents/trucos.php';
					break;
				case 5:
					$('ContentFrame').src = prefix+'contents/downloads.php';
					break;
				case 6:
					$('ContentFrame').src = prefix+'contents/videos.php';
					break;
				case 7:
					$('ContentFrame').src = prefix+'contents/especiales.php';
					break;
				case 8:
					document.title = "LOADED | Foros";
					BlogON();
					$('ContentFrame').src = 'site/foros';
					break;
				case 9:
					document.title = "LOADED | Blogs";
					ACTUALBLOG = true;
					BlogON();
					
					var _loginuser = LOGINUSER != "" ? LOGINUSER : "NOLOGIN";
					
					$('ContentFrame').src = 'http://' + BLOGDIR + '/?login=' + _loginuser + '&loginkey=' + LOGINKEY;
					break;
				case 100:
					$('ContentFrame').src = prefix+'contents/registracion.php';
					break;
				case 101:
					$('ContentFrame').src = prefix+'contents/perfil.php';
					break;
				case 155:
					$('ContentFrame').src = prefix+'contents/resultados_av.php';
					break;
			}
			
			LASTSECTION = id;
		}
	}
	
	function contentLoad(){
		/*debug('LOAD');
		var cD = $('ContentFrame').contentDocument ? $('ContentFrame').contentDocument : document.frames['ContentFrame'].document;
		if(!filterContent)		filterContent = new cFilterContent(cD);
		else									filterContent.setActionArea(cD);*/
	}
	
	function frameReSize(y){
		$('ContentFrame').style.height = y+"px";
	}
	
	function array_merge() {
		one = arguments[0];
		for(var i=1;i<arguments.length;i++){
			one.push(arguments[i]);
			one.flatten();
		}
		return one;
	}

var debugLine = 0;

	function debug(s){
		/*var _str = $('DEBUG').value;
		$('DEBUG').value = (++debugLine) + ':>>> '+ s +'\n' + _str;*/
	}
	
	function PrincipalAction(o){
		var lnk = o.getElementsByTagName("a")[0];
		
		if(lnk.getAttribute("target") == null || lnk.getAttribute("target") == ME_WIN_ID)
			window.location.href = lnk.href;
		else
			window.parent.location.href = lnk.href;
	}
	
	
function resetForms(a,v,p){
	try{
		$('iAction').value = a;
		$('iValue').value = v;
		$('iPagina').value = p;
	
		//$('sAction').value = a;
		//$('sValue').value = v;
		$('sPagina').value = p;
		$('sFilter').value = $('iFilter').value;
	}catch(e){}
}

	function busqueda(search){
		$('ContentFrame').src = prefix+'contents/resultados.php?search='+search;
	}
	
function initResize(){
	iframeGetSize();
	var timer = setInterval("iframeGetSize()", 1000);
}

function uc_first(msg){
	
	var fl = msg.substring(0,1).toUpperCase();
	var msg = fl + msg.substring(1);
	
	return msg;
}

function legales(){
	if(window.location.pathname.indexOf("451") != -1)		var p = "/451";
	else																									var p = "";
	
	var legal = window.open(p+"/site/web/contents/legales.php", "Legales", "width=500,height=400,menubar=0,resizable=0,status=0,toolbar=0,scrollbars=1");
}

function login(){
	if(LOGINUSER == "" || LOGINUSER == null)
		STEP = 2;
	GetLoginData(1);
}

function logout(){
	GetLoginData(0);
}

function cerrarSesion()
{
	//changeSection(LASTSECTION);
	$('ContentFrame').src = prefix+'contents/index.php';
}

function HaveLogin(){
	var MAIN = $("Menu");
	
	while(MAIN.hasChildNodes())
		MAIN.removeChild(MAIN.firstChild);
	
	var d = document.createElement("div");
	d.id = "FLP";
	
	MAIN.appendChild(d);
	
	var botonera = new FlashObject(prefix + "media/loaded_botonera.swf", "botonera", "778", "130", "8", "");
		botonera.addParam("allowScriptAccess", "sameDomain");
		botonera.addParam("movie", prefix + "media/loaded_botonera.swf");
		botonera.addParam("quality", "high");
		botonera.addParam("scale", "noscale");
		botonera.addParam("wmode", "transparent");
		botonera.addVariable("urlLogin", prefix + "contents/login.php");
	botonera.write("FLP");	
}

function imagenPopUp( id ){

	var path = window.location.pathname;
	path = path.substring(0, path.lastIndexOf("/")+1);

	if (pinicio==true)
	{
		ini=1;
	} else {
		ini=0;
	}
	
	if(id)
		window.open(path + "popup.php?id="+id+"&ini="+ini, "popup", "width=1000,height=700,scrollbars=0,resizable=1");
}

function BlogONR(){
	var pp = document.body.clientHeight;
	
	var offset = $('PieC').offsetHeight + 40;
	
	$('PieC').className = $('PieC').className + " Hidden";
	
	pp = pp - ($('Menu').offsetHeight);
	$('ContentFrame').style.height = pp + "px";
}

function BlogON(){
	BlogONR();
	
	if(document.all){
		var s = $('ContentFrame').cloneNode();
		s.setAttribute("scrolling", "auto");
		$('ContentFrame').parentNode.replaceChild(s, $('ContentFrame'))
	}else{
		$('ContentFrame').scrolling = "auto"
	}
	
	window.onresize = function(){
		BlogONR();
	}
}

function BlogOFF(){
	$('ContentFrame').style.height = "400px";	

	if(document.all){
		var s = $('ContentFrame').cloneNode();
		s.setAttribute("scrolling", "no");
		$('ContentFrame').parentNode.replaceChild(s, $('ContentFrame'))
	}else{
		$('ContentFrame').scrolling = "no"
	}

	ACTUALBLOG = false;
	$('Pie').className = $('Pie').className.replaceAll("Hidden", "");
	
	window.onresize = function(){return null;}
}

function SAV_ValidateDate(k){
	var vDay = (k.substring(6,8))*1;
	var vMonth = ((k.substring(4,6))*1)-1;
	var vYear = (k.substring(0,4))*1;

	var oDate = new Date();
	oDate.setFullYear(vYear, vMonth, vDay);
	
	if(document.all)	var GYEAR = oDate.getYear();
	else							var GYEAR = 1900 + oDate.getYear();
	
	if((GYEAR != vYear) || (oDate.getMonth() != (vMonth)) || (oDate.getDate() != vDay)){
		return false;
	}else
		return true;
}