$(document).ready(function(){GetTemplate();colorPalette();apply_onkeypress_event();var form=document.getElementById('postform');if(form)
$(form).submit(PreSend);if(ie8)check_posting_area();});$(window).bind('load resize',function()
{if(ie8)check_posting_area();});function check_posting_area(){var box=$('#message-box');if(!box.length)return false;var textarea=$('textarea#message');if(!textarea.length)return false;textarea.css('width','auto');var diff=20,width=box.width(),cols=textarea.attr('cols');if((textarea.width()+diff)>=width)
{var min=200;var count=0;while(textarea.width()>(width-diff))
{count++;if(count>20)
{return false;}
cols-=((textarea.width()-width)>100)?10:(((textarea.width()-width)>30)?2:1);if(cols<10||textarea.width()<min)return;textarea.attr('cols',cols);}
return true;}
var count=0;while(textarea.width()<(width-diff))
{count++;if(count>20)
{return false;}
cols+=((width-textarea.width())>100)?10:(((width-textarea.width())>30)?2:1);textarea.attr('cols',cols);}
return true;}
function PreSend()
{var subject=document.getElementById('subject');sOld=subject.value;sNew=sOld.replace(/[\[\(](avi|dd|divx|dual|xvid|mp4|vcd|(h|x)\.?264|completa)[\]\)]/gi,'');sNew=sNew.replace(/\.*mp4/gi,'');sNew=sNew.replace(/\d+mb/gi,'');sNew=sNew.replace(/\(*completa\)*/gi,'');sNew=sNew.replace(/\[\|*\]/g,'');sNew=sNew.replace(/\(\|*\)/g,'');sNew=sNew.replace(/\s+/g,' ');if(sOld!=sNew)
subject.value=sNew;d=document.getElementById('message');sOld=d.value;sNew=sOld.replace(/http:\/\/animehd\./g, 'http://www.animehd.').replace(/\[\/image\]\[\/url\][\r\n|\n]+\[url=/g,'[/image][/url] [url=').replace(/\[\/img\][\r\n|\n]+\[img\]/gi,'[/img] [img]').replace(/www\.animehd\.org\/capturas/g, 'img.animehd.org\/full').replace(/www\.animehd\.org\/4images/g, 'img.animehd.org');if(sOld!=sNew)
d.value=sNew;return true;}
function ShowTemplate()
{d=document.getElementById('uploadtemplate');$(d).slideToggle("slow");}
function InsertTemplate()
{u=document.getElementById('uploadtemplate');e=u.getElementsByTagName('input');t=document.getElementsByName('uTitulo')[0].value;x=document.getElementsByName('uTipo');if(x)
c=x[0].value;else
{f=getUrlVars()['f'];if((f==84)||(f==75))c='documental';else if((f==33)||(f==86))c='manga';else if((f==72)||(f==73))c='ost';}
if(!t)
{alert('Tienes que especificar un titulo');return;}
s='[upload='+t+'|'+c.toLowerCase()+']';$.each(e,function(index,element){t=element.title;v=element.value;if(t&&v)
s+='[b]'+t+':[/b] '+v+'\n';});Capturas=document.getElementsByName('uCapturas')[0].value;if(Capturas)
s+='\n[spoiler=Capturas]'+Capturas.replace('\n',' ')+'[/spoiler]\n';Sinopsis=document.getElementsByName('uSinopsis')[0].value;if(Sinopsis)
s+=Sinopsis+'\n';Enlaces=document.getElementsByName('uEnlaces')[0].value;if(Enlaces)
{ if (Enlaces.split('[url=').length < 10)	s+='\n[b]Descarga Directa:[/b]\n'+Enlaces;else s+='\n[spoiler=Descarga Directa]'+Enlaces+'[/spoiler]';} s+='[/upload]';insert_text(s.replace('  ',' '));ShowTemplate();}
function getUrlVars(){var map={};var parts=window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m,key,value){map[key]=value;});return map;}
function GetTemplate()
{u=document.getElementById('uploadtemplate');f=getUrlVars()['f'];anime=((f==6)||(f==54)||(f==43));cine=((f==45)||(f==46)||(f==8)||(f==18));otros=((f==84)||(f==75)||(f==33)||(f==86)||(f==72)||(f==73));
if(!anime&&!cine&&!otros)return;
document.getElementById('addTemplate').style.visibility='visible';
animehd=((f==6)||(f==54)||(f==43)||(f==45)||(f==46)||(f==84));
s='<table><tr><td style="width:104px">Titulo:</td><td><input type="text" name="uTitulo" /></td>';
if(anime){s+='<td style="width:104px">Tipo:</td><td><select name="uTipo"><option>Serie</option><option>OVA</option><option>Pelicula</option></select></td></tr><tr><td>Titulo Alternativo:</td><td><input type="text" title="Titulo Alternativo" /></td><td>Kanji / Kana:</td><td><input type="text" title="Kanji / Kana" /></td></tr><tr><td>Género:</td><td><input type="text" title="Género" /></td><td>Estudio:</td><td><input type="text" title="Estudio" /></td></tr><tr><td>Episodios:</td><td><input type="text" title="Episodios" /></td><td>Duración:</td><td><input type="text" title="Duracion" /></td></tr><tr><td>Año:</td><td><input type="text" title="Año" /></td><td></td><td></td></tr>';if(animehd)
s+='<tr><td>Video:</td><td><input type="text" title="Video" value="DVD-Rip, H.264, 640x480" /></td><td>Audio:</td><td><input type="text" title="Audio" value="Castellano, AAC" /></td></tr><tr><td>Contenedor:</td><td><input type="text" title="Contenedor" value="MP4" /></td><td>Compresión:</td><td><input type="text" title="Compresión" value="[url=http://www.animehd.org]AnimeHD[/url]" disabled /></td></tr><tr><td>Calidad:</td><td><input type="text" title="Calidad" value="Excelente" /></td><td></td><td></td></tr>';else
s+='<tr><td>Video:</td><td><input type="text" title="Video" /></td><td>Audio:</td><td><input type="text" title="Audio" /></td></tr><tr><td>Subtítulos:</td><td><input type="text" title="Subtitulos" /></td><td>Contenedor:</td><td><input type="text" title="Contenedor" /></td></tr><tr><td>Fansub (sub):</td><td><input type="text" title="Fansub" /></td><td>Compresión (dub):</td><td><input type="text" title="Compresión" /></td></tr><tr><td>Calidad:</td><td><input type="text" title="Calidad" /></td><td></td><td></td></tr>';}
else if(cine)
{s+='<td style="width:104px">Tipo:</td><td><select name="uTipo"><option>Serie</option><option>Pelicula</option></select></td></tr><tr><td>Titulo Original:</td><td><input type="text" title="Titulo Original" /></td><td>Nacionalidad:</td><td><input type="text" title="Nacionalidad" /></td><tr><td>Género:</td><td><input type="text" title="Genero" /></td><td></td><td></td></tr><tr><td>Episodios:</td><td><input type="text" title="Episodios" /></td><td>Duración:</td><td><input type="text" title="Duracion" /></td></tr><tr><td>Año:</td><td><input type="text" title="Año" /></td><td></td><td></td></tr><tr><td>Video:</td><td>';
if (animehd) s+='<input type="text" title="Video" value="DVD-Rip, H.264, 640x480" /></td><td>Audio:</td><td><input type="text" title="Audio" value="Castellano, AAC" /></td></tr><tr><td>Contenedor:</td><td><input type="text" title="Contenedor" value="MP4" /></td><td></td><td></td></tr><tr><td>Compresión:</td><td><input type="text" title="Compresión" value="[url=http://www.animehd.org]AnimeHD[/url]" disabled /></td><td>Calidad:</td><td><input type="text" title="Calidad" value="Excelente" /></td></tr>';
else s+='<input type="text" title="Video" /></td><td>Audio:</td><td><input type="text" title="Audio" /></td></tr><tr><td>Contenedor:</td><td><input type="text" title="Contenedor" /></td><td></td><td></td></tr><tr><td>Compresión:</td><td><input type="text" title="Compresion" /></td><td>Calidad:</td><td><input type="text" title="Calidad" /></td></tr>';
}else if((f==84)||(f==75))
{s+='<td style="width:104px">Titulo Original:</td><td><input type="text" title="Titulo Original" /></td><tr><td>Nacionalidad:</td><td><input type="text" title="Nacionalidad" /></td><td>Género:</td><td><input type="text" title="Genero" /></td></tr><tr><td>Episodios:</td><td><input type="text" title="Episodios" /></td><td>Duración:</td><td><input type="text" title="Duracion" /></td></tr><tr><td>Año:</td><td><input type="text" title="Año" /></td><td></td><td></td></tr><tr><td>Video:</td><td>';
if (animehd) s+='<input type="text" title="Video" value="DVD-Rip, H.264, 640x480" /></td><td>Audio:</td><td><input type="text" title="Audio" value="Castellano, AAC" /></td></tr><tr><td>Contenedor:</td><td><input type="text" title="Contenedor" value="MP4" /></td><td></td><td></td></tr><tr><td>Compresión:</td><td><input type="text" title="Compresión" value="[url=http://www.animehd.org]AnimeHD[/url]" disabled /></td><td>Calidad:</td><td><input type="text" title="Calidad" /></td></tr>';
else s+='<input type="text" title="Video" /></td><td>Audio:</td><td><input type="text" title="Audio" /></td></tr><tr><td>Contenedor:</td><td><input type="text" title="Contenedor" /></td><td></td><td></td></tr><tr><td>Compresión:</td><td><input type="text" title="Compresion" /></td><td>Calidad:</td><td><input type="text" title="Calidad" value="Excelente" /></td></tr>';} else {s+='<td style="width:104px">Kanji / Kana:</td><td><input type="text" title="Kanji / Kana" /></td></tr><tr><td>Género:</td><td><input type="text" title="Genero" /></td><td>Capitulos:</td><td><input type="text" title="Capitulos" /></tr><tr><td>Año:</td><td><input type="text" title="Año" /></td><td>Fansub:</td><td><input type="text" title="Fansub" /></td></tr>';} s+='<tr><td>Capturas:</td><td colspan="3"><textarea style="width:95%;" rows="4" cols="80" name="uCapturas"></textarea></td></tr><tr><td>Sinopsis:</td><td colspan="3"><textarea style="width:95%;" rows="4" cols="80" name="uSinopsis"></textarea></td></tr><tr><td>Enlaces:</td><td colspan="3"><textarea style="width:95%;" rows="10" cols="80" name="uEnlaces"></textarea></td></tr><tr><td colspan="4" style="text-align:center;"><input type="button" value="Insertar Plantilla" onclick="InsertTemplate()" /></td></tr></table>';u.innerHTML=s;}
var imageTag=false;var theSelection=false;var bbcodeEnabled=true;var clientPC=navigator.userAgent.toLowerCase();var clientVer=parseInt(navigator.appVersion);var is_ie=((clientPC.indexOf('msie')!=-1)&&(clientPC.indexOf('opera')==-1));var is_win=((clientPC.indexOf('win')!=-1)||(clientPC.indexOf('16bit')!=-1));var baseHeight;function initInsertions()
{var doc=document.forms[form_name]?doc=document:opener.document;var textarea=doc.forms[form_name].elements[text_name];if(is_ie&&typeof(baseHeight)!='number')
{textarea.focus();baseHeight=doc.selection.createRange().duplicate().boundingHeight;if(!document.forms[form_name])
document.body.focus();}}
function bbstyle(bbnumber)
{if(bbnumber!=-1)
bbfontstyle(bbtags[bbnumber],bbtags[bbnumber+1]);else
{insert_text('[*]');document.forms[form_name].elements[text_name].focus();}}
function bbfontstyle(bbopen,bbclose)
{theSelection=false;var textarea=document.forms[form_name].elements[text_name];textarea.focus();if((clientVer>=4)&&is_ie&&is_win)
{theSelection=document.selection.createRange().text;if(theSelection)
{document.selection.createRange().text=bbopen+theSelection+bbclose;document.forms[form_name].elements[text_name].focus();theSelection='';return;}}
else if(document.forms[form_name].elements[text_name].selectionEnd&&(document.forms[form_name].elements[text_name].selectionEnd-document.forms[form_name].elements[text_name].selectionStart>0))
{mozWrap(document.forms[form_name].elements[text_name],bbopen,bbclose);document.forms[form_name].elements[text_name].focus();theSelection='';return;}
var caret_pos=getCaretPosition(textarea).start;var new_pos=caret_pos+bbopen.length;insert_text(bbopen+bbclose);if(!isNaN(textarea.selectionStart))
{textarea.selectionStart=new_pos;textarea.selectionEnd=new_pos;}
else if(document.selection)
{var range=textarea.createTextRange();range.move("character",new_pos);range.select();storeCaret(textarea);}
textarea.focus();return;}
function insert_text(text,spaces,popup)
{var textarea=!popup?document.forms[form_name].elements[text_name]:opener.document.forms[form_name].elements[text_name];if(spaces)
text=' '+text+' ';if(!isNaN(textarea.selectionStart))
{var sel_start=textarea.selectionStart;var sel_end=textarea.selectionEnd;mozWrap(textarea,text,'')
textarea.selectionStart=sel_start+text.length;textarea.selectionEnd=sel_end+text.length;}
else if(textarea.createTextRange&&textarea.caretPos)
{if(baseHeight!=textarea.caretPos.boundingHeight)
{textarea.focus();storeCaret(textarea);}
var caret_pos=textarea.caretPos;caret_pos.text=caret_pos.text.charAt(caret_pos.text.length-1)==' '?caret_pos.text+text+' ':caret_pos.text+text;}
else
textarea.value=textarea.value+text;if(!popup)
textarea.focus();}
function attach_inline(index,filename)
{insert_text('[attachment='+index+']'+filename+'[/attachment]');document.forms[form_name].elements[text_name].focus();}
function addquote(post_id,username)
{var message_name='message_'+post_id;var divarea=document.all?document.all[message_name]:document.getElementById(message_name);var theSelection=window.getSelection?window.getSelection().toString():document.getSelection?document.getSelection():document.selection?document.selection.createRange().text:'';if(theSelection==''||typeof theSelection=='undefined'||theSelection==null)
{if(divarea.innerHTML)
{theSelection=divarea.innerHTML.replace(/<br>/ig,'\n');theSelection=theSelection.replace(/<br\/>/ig,'\n');theSelection=theSelection.replace(/&lt\;/ig,'<');theSelection=theSelection.replace(/&gt\;/ig,'>');theSelection=theSelection.replace(/&amp\;/ig,'&');theSelection=theSelection.replace(/&nbsp\;/ig,' ');}
else if(document.all)
theSelection=divarea.innerText;else if(divarea.textContent)
theSelection=divarea.textContent;else if(divarea.firstChild.nodeValue)
theSelection=divarea.firstChild.nodeValue;}
if(theSelection)
{if(bbcodeEnabled)
insert_text('[quote="'+username+'"]'+theSelection+'[/quote]');else
{var lines=split_lines(theSelection);for(i=0;i<lines.length;i++)
insert_text('> '+lines[i]+'\n')}}
return;}
function split_lines(text)
{var lines=text.split('\n');var splitLines=new Array();var j=0;for(i=0;i<lines.length;i++)
{if(lines[i].length<=80)
{splitLines[j]=lines[i];j++;}
else
{var line=lines[i];do
{var splitAt=line.indexOf(' ',80);if(splitAt==-1)
{splitLines[j]=line;j++}
else
{splitLines[j]=line.substring(0,splitAt);line=line.substring(splitAt);j++;}}
while(splitAt!=-1)}}
return splitLines;}
function mozWrap(txtarea,open,close)
{var selLength=(typeof(txtarea.textLength)=='undefined')?txtarea.value.length:txtarea.textLength;var selStart=txtarea.selectionStart;var selEnd=txtarea.selectionEnd;var scrollTop=txtarea.scrollTop;if(selEnd==1||selEnd==2)
selEnd=selLength;var s1=(txtarea.value).substring(0,selStart);var s2=(txtarea.value).substring(selStart,selEnd)
var s3=(txtarea.value).substring(selEnd,selLength);txtarea.value=s1+open+s2+close+s3;txtarea.selectionStart=selEnd+open.length+close.length;txtarea.selectionEnd=txtarea.selectionStart;txtarea.focus();txtarea.scrollTop=scrollTop;return;}
function storeCaret(textEl)
{if(textEl.createTextRange)
textEl.caretPos=document.selection.createRange().duplicate();}
function colorPalette()
{var r=0,g=0,b=0;var numberList=new Array(6);var color='';numberList[0]='00';numberList[1]='40';numberList[2]='80';numberList[3]='BF';numberList[4]='FF';var s='';for(r=0;r<5;r++)
{for(g=0;g<5;g++)
{for(b=0;b<5;b++)
{color=String(numberList[r])+String(numberList[g])+String(numberList[b]);s+='<a title="#'+color+'" style="background-color:#'+color+'" href="#" onclick="bbfontstyle(\'[color=#'+color+']\', \'[/color]\'); return false;"></a>';}}}
document.getElementById('colorselector').innerHTML=s;}
function change_palette()
{$('#colour_palette').slideToggle('slow');}
function caretPosition()
{var start=null;var end=null;}
function getCaretPosition(txtarea)
{var caretPos=new caretPosition();if(txtarea.selectionStart||txtarea.selectionStart==0)
{caretPos.start=txtarea.selectionStart;caretPos.end=txtarea.selectionEnd;}
else if(document.selection)
{var range=document.selection.createRange();var range_all=document.body.createTextRange();range_all.moveToElementText(txtarea);var sel_start;for(sel_start=0;range_all.compareEndPoints('StartToStart',range)<0;sel_start++)
range_all.moveStart('character',1);txtarea.sel_start=sel_start;caretPos.start=txtarea.sel_start;caretPos.end=txtarea.sel_start;}
return caretPos;}
