var wtd=0;
var maxworktd=0;
var idwtd=0;
var semuestrauh=0;
function checkEnd() {
	tmpa=0;	
	wtd--;	
	if (wtd==0) {
		$$('#tbody div.par').each(function(r) {	
			if (tmpa%2==0) { r.removeClassName('par').addClassName('impar'); }
			tmpa++;
			});
		
		url="end.php?";
		url=url+'q='+$('f').q.value;	
		url=url+'&n='+(($$('#tbody div.par')).length+($$('#tbody div.impar')).length);
		new Ajax.Request(url, {   
			method: 'get',			
			onSuccess: function(data) {  				
				writeBeforeAfter(data.responseText.evalJSON());
				end();
				},
			onFailure: function(data) {
				end();
				}
			});
		
		}
	}
function writeBeforeAfter(d) {	
	$('tinfoplus').update('');
	if (d.length>=2) {		
		//url1="/download/"+($('show').value.replaceAll(" ","-"))+'-'+d[0];
		//alert(url1);
		beforetxt="";
		if (d[0]!="") {
			url1="/download/"+$('show').value.toLowerCase()+"-"+d[0]+"/";
			url1=url1.replace(/ /g,"-");
			beforetxt=" <a href=\""+url1+"\" class=\"infopest\">&lt;&lt; "+$('show').value.capitalize()+" "+d[0]+"</a>";
			$('beforeShow').update(beforetxt);
		}
		urlshow="/download/"+$('show').value.toLowerCase()+"-"+d[0]+"/";
		if (d[1]!='') {
			url1="/download/"+$('show').value.toLowerCase()+"-"+d[1]+"/";
			url1=url1.replace(/ /g,"-");
			$('afterShow').update("<a href=\""+url1+"\" class=\"infopest\">"+$('show').value.capitalize()+' '+d[1]+" &gt;&gt;</a> ");
		}		
		
		if (d.length>2) {
			if (d[2]!='') {
				
			}
			if (d[3]!='') {
				//warn air date
				fila='<div class="savelater"><div><p><img src="/images/ayuda.png" height="16" width="16"/><a href="#" class="enlaceNovedad" onclick="saveForLater(); return false;"><b>'+msgWarningDateAired.replace("{fecha}",d[2])+'</a></b></p></div></div>';			
				$('tbody').insert( {top:fila});
			}
			if (d[4]!='') {
				//epi name
				dtxtair="";
				if (d[2]!="") {
					dtxtair=' - air date '+d[2];
				}					
				beforetxt='<a class="linkshow" title="more info'+dtxtair+'" href="/show/'+($('show').value.toLowerCase().replace(/ /g,"-"))+'" target="_blank"> '+getSE($('season').value,$('epi').value)+': '+d[4]+' </a>';
				$('tinfoplus').update(' - '+beforetxt);
			}
		}		
		
	}
}
function iralast() {
		$('boxLastShow').show();
		Effect.ScrollTo('boxLastShow');
		$('golast').click();
		}
function end() {
	Element.show($('go'));
	Element.hide($('ajxgo'));		
	Element.hide($('ajxgores'));
	wtd=0;
	paintWorkToDo();
	clearInterval(idwtd);
	if (itRU==0) {	
		if (($('f').quebusco[0].checked)&&($('season').value!='')&&($('epi').value!='')) {					
			Effect.Shake('parrafoAdvise',{duration:0.5,distance:20});
			}
		}
	//Usability
	if (($('epi').value=='')&&($('f').quebusco[0].checked)) {
		//SI Busco series, pero sin seleccionar EPI, 				
		fila='<div class="rowAdvise"><div><img src="/images/ayuda.png" height="16" width="16"/>'+msgNoSeasonEpi.replace("{q}",encodeURIComponent($('show').value))+'</div></div>';			
		$('tbody').down('div').insert( {before:fila});
		$('subdiv').innerHTML='<p>'+msgSubNoSeasonEpi+'</p>';
		} else if (($('epi').value!='')&&($('season').value!='')&&($('f').quebusco[0].checked)&&($('other').value!='')) {
		//SI Busco serie con Season y Epi, pero una palabra rara.
			if ($$('#tbody div').length==0) {
			fila='<div class="rowAdvise"><div><img src="/images/ayuda.png" height="16" width="16"/><a href="#" class="enlace" onclick="repeatNoOther(); return false;"><b>'+msgNoResultsWithOther+' '+$('other').value.toUpperCase()+'</a></b></div></div>';			
			$('tbody').insert( {top:fila});
			}
			
		} else if (($('epi').value!='')&&($('season').value!='')&&($('f').quebusco[0].checked)&&($('other').value=='')) {
		//SI Busco serie con Season y Epi, y sin palabra adicional y NO tengo resultados y NO estoy registrado... aconsejo guardar para la proxima vez
			if ($$('#tbody div').length==0) {
				if (itRU==0) {
					//Si no estoy registrado, lo muestro como el parrafoAdvise.
					fila='<div class="savelater"><div><p><img src="/images/ayuda.png" height="16" width="16"/><a href="#" class="enlaceNovedad" onclick="saveForLater(); return false;"><b>'+msgAdviseSaveLater+' '+$('other').value.toUpperCase()+'</a></b></p></div></div>';			
					$('tbody').insert( {top:fila});
				}
			}
			
		}
	}
function insertbf(row,data) {
	row.insert({before:getrow(data)});
	}

function getrow(dt) {
	dti=encodeURIComponent(dt.i);
	dtq=encodeURIComponent(dt.q);
	return '<div class="par"><div class="punt"><p class="pun"><strong>'+dt.s+'</strong></p><p>'+dt.lk+'/'+dt.sd+'/'+dt.lc+'</p></div><div class="res"><p class="torr"><a href="tor.php?i='+dti+'&q='+dtq+'" target="_blank" title="'+dt.t+'">'+dt.t+'</a></p><p class="url"><a href="tor.php?i='+dti+'&q='+dtq+'" target="_blank" title="'+dt.i+'">'+dt.i.replace(/\//g,'/ ')+'</a></p><p class="iconos"><a href="#" title="remote rss" onclick="addtorss(\''+dti+'\',\'T\'); return false;"><img class="icono" src="/img/rssadd.gif" width="12" height="12" id="img_'+dti+'"/></a> <a href="#" title="download with bitlet" onclick="sendbitlet(\''+dti+'\'); return false;"><img class="icono" src="/img/bitlet.png" width="12" height="12"/></a></p></div>';
	//return "<tr class=\"rowA\"><td><b>"+dt.s+"</b><br/>"+dt.lk+"/"+dt.sd+"/"+dt.lc+"</td><td><b><a href=\"tor.php?i="+dti+"&q="+dtq+"\" target=\"_blank\">"+dt.t+"</a></b> &nbsp;<a href=\"#\" title=\"remote rss\" onclick=\"addtorss('"+dti+"','T'); return false;\"><img class=\"icono\" src=\"/img/rssadd.gif\" width=\"16\" height=\"16\" id=\"img_"+dti+"\" /></a><br/><a href=\"tor.php?i="+dti+"&q="+dtq+"\" target=\"_blank\">"+dt.i.replace(/\//g,'/ ')+"</a></td></tr>";
	}
function insert(x) {			
	var dtx=x.evalJSON();		
	dtx.each(function(dt) {	
		var mv=dt.s;
		var insd=false;
		try {
		//$('tbody').select('div').each(function(r) {		
		$$('#tbody div.par').each(function(r) {	
			//alert('1'+r.innerHTML);
			vtmp=r.down('div').down('p');	
			//alert('2'+vtmp.innerHTML);
			if (vtmp.innerHTML.toLowerCase().indexOf("<strong")>=0) {					
				v=vtmp.down('strong').innerHTML;								
				if (!isNaN(v)) {					
					if (v<mv) {						
						insd=true;						
						insertbf(r,dt);
						throw $break;
						}
					}
				}
			});
			} catch (exc) { alert(exc); }		
		if (!insd) {			
			$('tbody').insert(getrow(dt));
			}		
		});
	}
var nsubrow=0;
function getsubrow(dt) {
	dturl=encodeURIComponent(dt.url);
	nsubrow++;
	return '<div class="impar"><div class="sb"><p><a href="/tor.php?i='+dturl+'" target="_blank">'+dt.name+'</a>&nbsp;<a href="#" title="remote rss" onclick="addtorss(\''+dturl+'\',\'S\',\''+nsubrow+'\'); return false;"><img src="/img/rssadd.gif" width="12" height="12" id="img_'+nsubrow+'_'+dturl+'"/></a></p></div></div>';
	}
function insertsubs(x) {		
	var dts=x.evalJSON();	
	if (dts.length>0) {
		//$('subdivwrap').show();
		}
	dts.each(function(dt) {				
		$('subdiv').insert({bottom:getsubrow(dt)});
		});
	}	
function errors(x) {
	
	}
function searchq(x,f) {
	var url = 'rss.php?t='+Math.random()+'&i='+x;
	if (f==1) { url=url+'&f='+f; }
	url=url+'&q='+$('f').q.value;	
	var pars={ "sh": $('show').value,
			"s":$('season').value,
			"e":$('epi').value,
			"o":$('other').value,
			"ex":$('exclude').value	};

	new Ajax.Request(url, {   
		method: 'post',
		parameters:pars,   
		onSuccess: function(data) {   	
			try {								
				insert(data.responseText);   
				} catch (excepcion) { 
				errors(data);
				}
			checkEnd();
			},
		onFailure: function(data) {
			errors(data);
			checkEnd();
			}
		});
	}
function searchsubs(f) {
	var url = 'sub.php?t='+Math.random()+'&ss='+$('ss').value;	
	url=url+'&q='+$('f').q.value;	
	new Ajax.Request(url, {   
		method: 'GET',		 
		onSuccess: function(data) {   	
			try {								
				insertsubs(data.responseText);   
				} catch (excepcion) { 
				errors(data);
				}
			checkEnd();
			},
		onFailure: function(data) {
			errors(data);
			checkEnd();
			}
		});
	}
function hasSeasonEpisode(v) {
	if (v.match(/ S..E../)) { return true; }
	return false;
	}
function updateShowInfo(q) {
	if (q!='') {				
		if (q.length>10) {
			q=q.substring(0,9)+"...";
			}
		$('showinfo').update(q);
		}
	}
function paintWorkToDo() {
	porcen=Math.ceil(((maxworktd-wtd)/maxworktd)*100);
	$('progress').update(porcen+"%");
	}
function searchenlaces() { $('allresults').style.visibility='visible'; verinfoshow();  }
function searchnews() {  $('allresults').style.visibility='visible'; vernewsshow();}
function search(f) {		
	if (searchprecon==2) { searchprecon=1; } else { searchprecon=0; }	
	if ($('f').q.value=='') { return; }	
	Effect.ScrollTo('logo');	
	$('beforeShow').update('');
	$('afterShow').update('');
	//if (itRU==0) { warnTxt('recuerda que si estuvieras registrado, podrias anotar series y ensenarsela a tus amigos con un perfil'); }	
	if ($('quebuscar').getValue()=='2') {
		//enlaces
		searchenlaces();
		return;
		}
	else if ($('quebuscar').getValue()=='3') {
		//noticias
		searchnews();
		return;
		}
	else {
		verresultados(); //pongo la pest de resultados activa
		}
	idwtd=setInterval("paintWorkToDo()", 500);   
	$('allresults').style.visibility='visible';	
	if (($('f').quebusco[0].checked)&&($('season').value!='')&&($('epi').value!='')) {					
			if ((itRU==0)||((searchprecon==0)&&(itRU==1))) {
				//si estoy registrado, solo lo pongo si searchprecon es cero
				$('advisetxt').update('<img src="/images/ayuda.png" width="16" height="16"/> '+msgFollowAdvise.replace("{SHOW}",$('f').q.value));						
				$('parrafoAdvise').show();			
				} 			
		} else {
			if (itRU==0) {
				$('advisetxt').update('<img src="/images/ayuda.png" width="16" height="16"/> '+msgRandAdvise);
				$('parrafoAdvise').show();
				} else {
				$('parrafoAdvise').hide();
				}
		}	
	searchprecon=0;	
	updateShowInfo($('show').value);
	//$('tbody').select('tr').each(function(r) { r.remove(); });
	$('tbody').update('');
	$('subdiv').update('');
	//$('subdivwrap').hide();
	//ocultado por jordim desocultar si da err hr=$('headertable');	
	//$('go').hide();
	//$('ajxgo').show();
	$('ajxgores').show();
	$('msglasttitle').hide();
	$('msglast').hide();
	$('rsslink').setAttribute("href","download/"+encodeURIComponent($('q').value)+"?mode=rss&subs=yes");
	$('rsslink').show();
	wtd=0;
	maxworktd=0;
	//subs?
	if ($('sc').checked) {		
		wtd++;
		if (wtd>maxworktd) { maxworktd=wtd; }
		searchsubs(f);
		}
	//count work to be done
	$('s').value.split(/(,)/).each(function(i) {
		//In FF split shows delimiter too; IE doesnt. 
		if (i!=',') {
			wtd++;
			if (wtd>maxworktd) { maxworktd=wtd; }
			}
		});
	//lets get started
	isf=1;
	$('s').value.split(/(,)/).each(function(i) {
		//In FF split shows delimiter too; IE doesnt. 
		if (i!=',') {
			searchq(i,isf);
			isf=0;
			}
		});
}
function presearch(t) {
	$('q').value=t;
	calc();
	search($('f'));
	}
function calclast(evt) {
if ($('ql').value!='') {
	$('show').value=$('ql').value;
	calc();
	}
}
function calc(evt) {
var q='';
if ($('show').value!='') {
	q=$('show').value;
	$('ql').value=$('show').value;
	updateShowInfo($('show').value);
	}
if ($('season').value!='') {
	if (q!='') { q=q+' '; }
	if ($('season').value.length==1) {
		q=q+"S0"+$('season').value;
		}
	else {
		q=q+"S"+$('season').value;
		}
	
	}
if ($('epi').value!='') {	
	if ((q!='')&&($('season').value=='')) { q=q+' '; }	
	if ($('epi').value.length==1) {
		q=q+"E0"+$('epi').value;
		} else {
		q=q+"E"+$('epi').value;
		}
	}
if ($('other').value!='') {
	if (q!='') { q=q+' '; }
	q=q+$('other').value;
	}
$('q').value=q;
$('exclude').value=''; //el exclude deja de ser valido
}
function qkeyup() {
	$('exclude').value=''; //el exclude deja de ser valido
	}
function clean() {
if ($('directexplain')!=undefined) {
	$('directexplain').hide();
	}
}

/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us> -- geekwisdom.com
License: MIT License (see below)
---------------------------------------------------------------
Copyright (c) 2006 Steve Moitozo <god at zilla dot us>
************************************************************ */
function testPassword(passwd)
{
		var intScore   = 0
		var strVerdict = "weak"
		var strLog     = ""
		
		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3)
			strLog   = strLog + "3 points for length (" + passwd.length + ")\n"
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6)
			strLog   = strLog + "6 points for length (" + passwd.length + ")\n"
		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12)
			strLog   = strLog + "12 points for length (" + passwd.length + ")\n"
		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18)
			strLog   = strLog + "18 point for length (" + passwd.length + ")\n"
		}
		
		
		// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1)
			strLog   = strLog + "1 point for at least one lower case char\n"
		}
		
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least one upper case char\n"
		}
		
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least one number\n"
		}
		
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least three numbers\n"
		}
		
		
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least one special char\n"
		}
		
									 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5)
			strLog   = strLog + "5 points for at least two special chars\n"
		}
	
		
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2)
			strLog   = strLog + "2 combo points for upper and lower letters\n"
		}

		if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		{
			intScore = (intScore+2)
			strLog   = strLog + "2 combo points for letters and numbers\n"
		}
 
									// [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2)
			strLog   = strLog + "2 combo points for letters, numbers and special chars\n"
		}
	
		if(passwd.length<6 ){	
			strVerdict = 0;
		}
		else if(intScore < 16)
		{
		   strVerdict = 1;
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = 1;
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = 2;
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = 2;
		}
		else
		{
		   strVerdict = 2;
		}
	
		return strVerdict;
	
}
function getSE(season,episode) {
getSEq='';
if (season<10) { getSEq='S0'+season; } else { getSEq='S'+season; }
getSEq=getSEq+'E';
if (episode<10) { getSEq=getSEq+'0'+episode; } else { getSEq=getSEq+episode; }
return getSEq;
}
function getlast() {
	$('ajxgolast').show();
	$('msglasttitle').hide();
	$('msglast').hide();
	new Ajax.Request('/last/for.php?q='+encodeURIComponent($('ql').value), {
		method:'get',
		onSuccess: function(data) {
			$('ajxgolast').hide();
			try {				
				dt=data.responseText.evalJSON();
				if (dt.ok=="1") {					
					$('msglast').hide();					
					$('season').value=dt.s;
					$('epi').value=dt.e;
					$('other').value='';
					$('season').addClassName('fondoverde');
					$('epi').addClassName('fondoverde');
					$('show').addClassName('fondoverde');
					$('msglasttitle').update("<a href='#' onclick=\"$('go').click(); return false;\">"+dt.show+" "+getSE(dt.s,dt.e)+" - "+dt.title+" ("+dt.lastemited+")</a> <a class='responseok' href='"+dt.url+"' target='_blank'>"+generalMore+"</a> ");
					$('msglasttitle').show();
					calclast();
					} else {
					
					lastNotFound();
					}
				} catch (e) { alert('lo sentimos, hubo un error encontrando el dato'); }
			},
		onFailure: function(data) {
			$('ajxgolast').hide();
			alert('lo sentimos, hubo un error encontrando el dato');
			}
		});
	}
function mostrar(donde,text) { $(donde).update(text); $(donde).show();}
function login() {
$('usererror').hide();
ajxLoading('sobre_login');
new Ajax.Request('login.php', {   
	method:'post',
	parameters: $('userform').serialize(true),
	onSuccess: function(data) {   
				try {
				datos=data.responseText.evalJSON();	
				ajxUnload('sobre_login');					
				if (datos.ok=='1') {				
					loginok(datos.alias);
					} else {				
					loginerror(datos.error);					
					}
				} catch (exc) {	
					ajxUnload('sobre_login');				
					loginerror(generalError);					
					}
				},
			onFailure: function(data) {
				ajxUnload('userbox');
				loginerror(generalError);				
				}
	}
	); 
return false;
}
function loginok(name) {
	//new Ajax.Updater("usercontent","userbox.php"); 
	//$('show').focus(); 
	window.location='/index.php';
	}
function loginerror(x) {		
	$('usererror').update(x);
	$('usererror').show();
	}
function pestanaVisible(cual) {
	pestanas=new Array('pestnews','pestshow','pestres','pestcom');
	suscapas=new Array('newsbox','showbox','resbox','combox');
	for (a=0;a<pestanas.length;a++) {
		if (pestanas[a]==cual) {
			$(pestanas[a]).removeClassName('pestanaoff');
			$(pestanas[a]).addClassName('pestanasel');
			$(suscapas[a]).show();
		} else {
			$(pestanas[a]).removeClassName('pestanasel');
			$(pestanas[a]).addClassName('pestanaoff');
			$(suscapas[a]).hide();
		}
	}
}
function verinfoshow(q) {
	if (q==undefined) { q=$('show').value; }
	pestanaVisible('pestshow');
	if (q=='') {	
		$('showbox').update(msgChooseShow+"<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>");
		return;
		}
	ajxLoading('showbox');
	new Ajax.Request('info.php?t='+Math.random()+'&q='+encodeURIComponent(q), {   
		method:'get',		
		onSuccess: function(data) {   
					try {
					$('showbox').update(data.responseText);
					ajxUnload('showbox');					
					} catch (exc) {	
						ajxUnload('showbox');				
						alert('no se pudo recuperar la informacion. intentelo mas tarde, por favor.');
						}
					},
				onFailure: function(data) {
					ajxUnload('showbox');
					alert('no se pudo recuperar la informacion. intentelo mas tarde.');
					}
			}
		); 
	}
function vernewsshow(q,cuantos) {
	if (q==undefined) { q=$('show').value; }	
	pestanaVisible('pestnews');	
	if (q=='') {	
		$('newsbox').update(msgChooseShow+"<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>");
		return;
		}
	ajxLoading('newsbox');
	new Ajax.Request('/news-service/index.php?t='+Math.random()+'&cuantos='+cuantos+'&q='+encodeURIComponent(q), {   
		method:'get',		
		onSuccess: function(data) {   
					try {
					$('newsbox').update(data.responseText);
					ajxUnload('newsbox');					
					} catch (exc) {	
						ajxUnload('newsbox');				
						alert('no se pudo recuperar la informacion. intentelo mas tarde, por favor.');
						}
					},
				onFailure: function(data) {
					ajxUnload('newsbox');
					alert('no se pudo recuperar la informacion. intentelo mas tarde.');
					}
			}
		); 
	}
function vercomshow(q,cuantos,dontsub) {
	pestanaVisible('pestcom');	
	Effect.ScrollTo('pestcom');
	vercomshowSS(q,cuantos,dontsub);	
}
function vercomshowSS(q,cuantos,dontsub) {
	if (q==undefined) { q=$('q').value; }
	if (cuantos==undefined) { cuantos=10; }
	if (q=='') {	
		$('combox').update(msgChooseShow+"<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>");
		return;
		}
	ajxLoading('combox');
	if (dontsub!=undefined) { dontsub=''; } else { dontsub='&sub=1'; }
	if ($('langfilter')!=undefined) { langfilter='&langfilter='+$('langfilter').value; } else { langfilter=''; }
	if ($('whatfilter')!=undefined) { whatfilter='&whatfilter='+$('whatfilter').value; } else { whatfilter=''; }
	new Ajax.Request('/comments/index.php?t='+Math.random()+'&cuantos='+cuantos+'&q='+encodeURIComponent(q)+dontsub+langfilter+whatfilter, {   
		method:'get',		
		onSuccess: function(data) {   
					try {
					$('combox').update(data.responseText);
					ajxUnload('combox');					
					} catch (exc) {	
						ajxUnload('combox');				
						alert('no se pudo recuperar la informacion. intentelo mas tarde, por favor.');
						}
					},
				onFailure: function(data) {
					ajxUnload('combox');
					alert('no se pudo recuperar la informacion. intentelo mas tarde.');
					}
			}
		); 
	}	
function verresultados() {
	pestanaVisible('pestres');
	}
function enviarcom(f) {
	ajxLoading('showbox');
	new Ajax.Request('/info.php', {   
		method:'post',
		parameters: $('cf').serialize(true),
		onSuccess: function(data) {   
					try {
					$('showbox').update(data.responseText);
					ajxUnload('showbox');									
					} catch (exc) {	
						ajxUnload('showbox');				
						alert('no se pudo enviar la informacion. intentalo mas tarde, por favor.');				
						}
					},
				onFailure: function(data) {
					ajxUnload('userbox');
					alert('no se pudo enviar la informacion. intentalo mas tarde!.');				
					}
			}
		); 
	}
function delcom(f) {	
	if (!confirm(msgConfirmCom)) { return; }
	ajxLoading('showbox');
	new Ajax.Request('/info.php?d='+f+'&q='+encodeURIComponent($('qcom').value), {   
		method:'get',		
		onSuccess: function(data) {   
					try {
					$('showbox').update(data.responseText);
					ajxUnload('showbox');									
					} catch (exc) {	
						ajxUnload('showbox');				
						alert('no se pudo enviar la informacion. intentalo mas tarde, por favor.');				
						}
					},
				onFailure: function(data) {
					ajxUnload('userbox');
					alert('no se pudo enviar la informacion. intentalo mas tarde!.');				
					}
			}
		); 
	}
function msdel(x) {
	if (!confirm(msgConfirmDel)) { return; }
	window.location='control.php?x='+Math.random()+'&d='+x;
	}
function wsstartmod(x,s,e) {
	$('wsse'+x).update("S<input type=\"text\" name=\"s"+x+"\" id=\"s"+x+"\"size=\"1\" maxlength=\"2\" value=\""+s+"\"/>-E<input type=\"text\" name=\"e"+x+"\" id=\"e"+x+"\" size=\"1\" maxlength=\"2\" value=\""+e+"\"/>");
	$('ok'+x).show();
	$('mod'+x).hide();
	}
function wsstartmodname(x,s,e,o) {
	$('wssename'+x).update("<input type=\"text\" name=\"show"+x+"\" id=\"show"+x+"\"size=\"33\" maxlength=\"255\" value=\""+s+"\"/><br/>&nbsp;&nbsp;+<input type=\"text\" class=\"cursiva\" name=\"other"+x+"\" id=\"other"+x+"\" size=\"30\" maxlength=\"255\" value=\""+e+"\"/><br/>&nbsp;&nbsp;- <input type=\"text\" class=\"cursivarojo\" name=\"exclude"+x+"\" id=\"exclude"+x+"\" size=\"30\" maxlength=\"255\" value=\""+o+"\"/>");
	$('okname'+x).show();
	$('modname'+x).hide();
	}
function wsendmodname(x,y) {
	var show=$('show'+x).value;
	if (show=='') { alert(msgFormValidation); return; }
	var other=$('other'+x).value;
	var exclude=$('exclude'+x).value;
	var f=$('formul');
	f.action='/control.php?action=modname';
	f.show.value=show;
	f.other.value=other;
	f.exclude.value=exclude;
	f.im.value=y;
	f.submit();
}	
function wsendmod(x,y) {
	wsgoto(y,$('s'+x).value,$('e'+x).value);	
}
function wsvalidar(f) {
	if ((f.show.value=='')||(f.s.value=='')||(f.e.value=='')) { alert(msgFormValidation); return false; }
	return true;		
}
function wsgoto(im,s,e) {
	window.location='control.php?action=mod&s='+s+'&e='+e+'&im='+im+'&x='+Math.floor(Math.random()*10000);
	}
var searchprecon=0;
function configuredmysearch(sh,s,e,o,ex) {
	//searchprecon permite marcar si voy a buscar de forma preconfigurada, para que no me salga la publi despues
	searchprecon=2;
	configuredsearch(sh,s,e,o,ex);
	}
function configuredsearch(sh,s,e,o,ex) {
	$('show').value=sh;
	$('season').value=s;
	$('epi').value=e;
	$('other').value=o;
	calc();
	$('exclude').value=ex;
	clean();
	search($('f'));
	}
function rememberpass() {
	if ($('email').value=='') {
		alert(msgRememberPass);
		} else {
		$('forgotLoading').show();					
		new Ajax.Request('/register/forgot.php', {
			method: 'post',
			parameters: $('userform').serialize(true),
			onSuccess: function(data) {   				
			$('forgotLoading').hide();
				datos=data.responseText.evalJSON();	
				alert(datos.msg);
				},
			onFailure: function(data) {
				$('forgotLoading').hide();
				loginerror(generalError);				
				}
			});
		}
	}
function checkforgotpass(x) {
	result=testPassword(x);	
	clase='responsenok';
	mensaje='';
	if (result==1) { clase='passweak'; }
	if (result==2) { 
		clase='responseok'; 
		mensaje='ok'; 
	} else {
		mensaje=msgNotSafe;
	}
	$('passresponse').update(mensaje);
	$('passresponse').show();
	$('passresponse').className=clase;	
}
function validatenewpass(f) {
	result=testPassword(f.newpass.value);
	if (result<1) {
		alert(msgConfirmNotSafe);
		return false;
		} else {
		return true;
		}
	}
function conectarfacebook() {
	window.location='/fblogin.php?'+Math.random();
	}
function wshide(q,x) {
	ajxLoading('showsbox');		
	valor=0;
	if (x.checked) { valor=1; }
		new Ajax.Request('/control.php?on='+valor+'&modhide='+q+'&t='+Math.random(), {
			method: 'get',			
			onSuccess: function(data) {   				
				ajxUnload('showsbox');				
				},
			onFailure: function(data) {
				ajxUnload('showsbox');
				x.checked=!x.checked;
				
				}
			});
	}
function wsset(x) {
	ajxLoading('settingsbox');		
	valor=0;
	if (x.checked) { valor=1; }
		new Ajax.Request('/control.php?on='+valor+'&mod'+x.name+'=1&t='+Math.random(), {
			method: 'get',			
			onSuccess: function(data) {   				
				ajxUnload('settingsbox');				
				},
			onFailure: function(data) {
				ajxUnload('settingsbox');
				x.checked=!x.checked;
				
				}
			});
	}	
var firstReset=1;
function resetshow(x) { 
	if (firstReset==1) {
		x.style.color='#777';
		$('season').style.color='#777';
		$('epi').style.color='#777';
		$('other').style.color='#777';
		if (x.value==msgShow) { x.value=''; firstReset=0; }
		if ($('season').value==msgSeason) { $('season').value=''; firstReset=0; }		
		if ($('epi').value==' '+msgEpi) { $('epi').value=''; firstReset=0; }
		if ($('other').value==msgOther) { $('other').value=''; firstReset=0; }
		}
	}
function showfield(x) {
	if (x.value==1) { 
		$('cajas').removeClassName("cajasother").addClassName("cajas");
		$('searchbyshow').show();
		$('searchbyother').hide();	
		$('quebuscar').disabled=false;
		calc();
	} else {
		$('q').value='';
		resetshow($('show'));
		$('cajas').removeClassName("cajas").addClassName("cajasother");		
		$('searchbyshow').hide();
		$('searchbyother').show();	
		$('quebuscar').selectedIndex=0;
		$('quebuscar').disabled=true;		
	}
}	
function addtorss(x,tipo,y) {
	if (itRU==0) {
		//alertar que solo para usuarios registrados!
		warnTxt(msgRemoteRss);
		} else {
		tagid='img_'+x;
		if (y!=undefined) {
			tagid='img_'+y+'_'+x;
			}
		$(tagid).src='/img/loadingb.gif';
		myurl='/feeds/add.php?i='+x+'&tipo='+tipo+'&t='+Math.random();
		if (($('f').quebusco[0].checked)) {
			myurl+='&q='+$('q').value;
		}
		new Ajax.Request(myurl, {
			method: 'get',			
			onSuccess: function(data) {   	
				if (data.responseText.substring(0,1)=='1') {
					$(tagid).src='/img/ok.gif';
					} else {
					$(tagid).src='/img/rss16.gif';
					warnTxt(generalError);
					}					
				},
			onFailure: function(data) {
				$(tagid).src='/img/rss16.gif';
				warnTxt(generalError);
				}
			});
		}
	}
function warnTxt(x) {	
	path_to_root_dir = "../";
	if ($('barra_arriba')!=undefined) {
		Effect.ScrollTo('barra_arriba');	
		}
	$('myWarningTxt').update(x);
	var myBox = new GlassBox();
	myBox.init( 'myWarning', '500px', '100px', 'hidden', '', true, true );
	//myBox.apos(400,300);
	myBox.lbo( false, 0.50 ); 
	myBox.appear(4000);
	}
function followshow() {
	if (itRU==0) {
		warnTxt(msgFollowRegister);
		} else {
		pars={ "submiter":1,"s":$('season').value,"e":$('epi').value,"show":$('show').value,"other":$('other').value };
		$('advisetxt').insert(" <img src='/img/loadingb.gif' width='16' height='16' id='addloadid'/>",{position:'bottom'});
		$('addloadid').show();
		new Ajax.Request('/control.php', {
			method: 'post',		
			parameters: pars,
			onSuccess: function(data) {   					
					$('addloadid').src='/img/ok.gif';
				},
			onFailure: function(data) {
				$('addloadid').hide();
				warnTxt(generalError);
				}
			});
		}
	}
function newrsswin(q) {
	if ($('barra_arriba')!=undefined) {
		Effect.ScrollTo('barra_arriba');	
		}	
	path_to_root_dir = "../";		
	var myBox2 = new GlassBox();
	myBox2.init( 'rssWin', '500px', '300px', 'hidden', '', true, true );
	myBox2.lbo( true, 0.50 ); 
	myBox2.appear();
	$('rssWinContent').src='/news-service/rss.php?t='+Math.random()+'&q='+encodeURIComponent(q);
	}
function init(){
		//$('fondo_buscador').setOpacity(0.3);
		//$('popup').setOpacity(0.7);		
		//$('logo').setOpacity(0.3);		
		//$('buscaen').setOpacity(0.4);
		//$('novedades').setOpacity(0.7);		
	}
	function showLogin(){
		document.body.style.overflow="hidden";
		var cubre = $("cubre");
		cubre.appear({duration:0.5, from:0.0, to: 0.2});
		cubre.setStyle( { position: 'absolute', top: 0 + 'px', left: 0 + 'px', width: '100%',height: '2000px' } );
		$('div_login').center();
		$('sobre_login').center();
		$('div_login').style.display="block";
		if ($('quebuscar')!=undefined) { $('quebuscar').hide(); }
		setTimeout(
			function(){
				Effect.Grow('sobre_login',{duration:0.6});
				setTimeout(function() { $('email').focus();
					},1000);				
			},
		300);
		Effect.Grow('bg_login',{duration:0.6});
		
		window.onresize = function(){
			$('div_login').center();
			$('sobre_login').center();
		}
		
	}
	function hideLogin(){
		var cubre = $("cubre");
		cubre.fade({duration:0.5});
		
		
		setTimeout(
		"Effect.Shrink('bg_login',{duration:0.6});",
		300);
		Effect.Shrink('sobre_login',{duration:0.6});
		
		window.onresize = null;
		document.body.style.overflow="auto";
		$("div_login").style.display="none";
		$('quebuscar').show();
	}
	var ElementExtensions= {
			center: function( element, limitX, limitY){
				element = $(element);

				var elementDims = element.getDimensions();
				var viewPort = document.viewport.getDimensions();
				var offsets = document.viewport.getScrollOffsets();
				var centerX = viewPort.width / 2 + offsets.left - elementDims.width / 2;
				var centerY = viewPort.height / 2 + offsets.top - elementDims.height / 2;
				if ( limitX && centerX < limitX )
				{
					centerX = parseInt(limitX);
				}
				if ( limitY && centerY < limitY )
				{
					centerY = parseInt(limitY);
				}

				element.setStyle( { position: 'absolute', top: Math.floor(centerY) + 'px', left: Math.floor(centerX) + 'px' } );

				return element;			
			}
		}
	Element.addMethods(ElementExtensions);	
function toggleuh() { 
	if (semuestrauh==0) {
		xpos=140;
		semuestrauh=1;
		} else {
		xpos=-140;
		semuestrauh=0;
		}	
	
	new Effect.Move($('pestana1'),{x:xpos,y:0,mode:'relative',duration:0.4});
	}
function showhelp() {
	Effect.toggle('popup', 'blind', { duration: 0.2 });
	}
function initplain(){		
		//$('logo').setOpacity(0.2);						
	}
function sendbitlet(i) {	
	window.open('/bitlet.php?torrent='+i);
	}
function repeatNoOther() {
	$('other').value='';
	calc();
	$('go').click()
}
function getHtmlData(tag,str) {
	iniTag="<!--"+tag+"-->";
	endTag="<!--/"+tag+"-->";	
	tm=str.substring(str.indexOf(iniTag)+iniTag.length,str.indexOf(endTag)); //str.indexOf(endTag)-str.indexOf(iniTag)+iniTag.length
	return tm;
}
function refreshShows() {
	$('idRefreshShows').hide();
	$('loadingRefreshShows').show();
	new Ajax.Request("/index.php?"+Math.random(), {   
		method: 'get',			
		onSuccess: function(data) {   	
			$('idYourShows').replace(getHtmlData('yourshow',data.responseText));
			},
		onFailure: function(data) {
			alert('server error');
			}
		});
}
function saveForLater() {
	window.location='/register.php?s4l='+encodeURIComponent($('show').value)+'&ss='+$('season').value+'&e='+$('epi').value+'&4.8.15.16.23.42!';
	}
function ajxForm(fname,loadiv) {
	var mif=document.getElementById(fname); 
	ajxLoading(loadiv);
	new Ajax.Request(mif.action, {   
		method:'post',
		parameters: Form.serialize(fname),
		onSuccess: function(data) {   
					try {
					$(loadiv).update(data.responseText);
					ajxUnload(loadiv);									
					} catch (exc) {	
						ajxUnload(loadiv);
						alert('no se pudo enviar la informacion. intentalo mas tarde, por favor.');				
						}
					},
				onFailure: function(data) {
					ajxUnload(loadiv);
					alert('no se pudo enviar la informacion. intentalo mas tarde!.');				
					}
			}
		); 
}
function validarCom(f) {	
	if (f.namecom.value=='') { alert(msgNameRequired); return false; }
	if (f.emailcom.value=='') { alert(msgEmailRequired); return false; }
	if (f.desccom.value=='') { alert(msgCommentRequired); return false; }
	return true;

}
function actualizarcom(x) {	
	if (x.value.length>200) { x.value=x.value.substring(0,200); }
	$('charsleft').update(200-x.value.length);
}
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);