var keyId,startrange=null;function anySelected(){return $H(messagelist).keys().detect(function(a){return $("check"+a).checked})}function selectRow(c,a){var b=$(c.replace(/check/,"row"));if(a){b.addClassName("selectedRow")}else{b.removeClassName("selectedRow");b.removeClassName("selectedRow-over")}$(c).checked=a}function imp_confirm(a,b){RedBox.overlay=true;RedBox.showHtml('<div id="RB_confirm"><p>'+b+'</p><input type="button" class="button" onclick="window.location=\''+a+'\';" value="'+IMP.text.yes+'" /><input type="button" class="button" onclick="RedBox.close();" value="'+IMP.text.no+'" /></div>')}function messages_submit(a){if(!anySelected()){alert(IMP.text.mailbox_submit);return}if(a=="delete_messages"){if(IMP.conf.pop3&&!confirm(IMP.text.mailbox_delete)){return}}else{if(a=="spam_report"){if(!confirm(IMP.text.spam_report)){return}}else{if(a=="notspam_report"){if(!confirm(IMP.text.notspam_report)){return}}}}$("actionID").setValue(a);$("messages").submit()}function makeSelection(b){var a="";switch(parseInt(b)){case-1:if($("checkAll").checked){a="!"}a+=IMP.conf.IMP_ALL;break;case 1:a=$F("filter1");break;default:a=$F("filter2")}if(a.empty()){return}else{if(a.startsWith("!")){selectFlagged(parseInt(a.substring(1)),false)}else{if(a.startsWith("+")){selectFlagged(a.substring(0,1),null)}else{selectFlagged(parseInt(a),true)}}}switch(parseInt(b)){case-1:break;case 1:$("select1").reset();break;default:$("select2").reset()}}function selectRange(c){Event.extend(c);var f=c.element().id,d=$(f);if(!d){return}var b=d.checked;if(startrange!==null&&c.shiftKey){var e=[$(startrange).id,d.id];var a=0;$H(messagelist).keys().detect(function(g){g="check"+g;if(e.indexOf(g)!=-1){++a}if(a){selectRow(g,b);if(a==2){return true}}})}else{selectRow(f,b)}startrange=f}function updateFolders(d){var a=$("targetMailbox2");if(a){var b=$("targetMailbox1");if((d==1&&$F(b)!="")||(d==2&&$F(a)!="")){var c=(d==1)?b.selectedIndex:a.selectedIndex;b.selectedIndex=a.selectedIndex=c}}}function transfer(d,b){if(anySelected()){var a=$("targetMbox");a.setValue((b==1)?$F("targetMailbox1"):$F("targetMailbox2"));if($F(a)=="*new*"){var c=prompt(IMP.text.newfolder,"");if(c!=null&&c!=""){$("newMbox").setValue(1);a.setValue(c);messages_submit(d)}}else{if($F(a)==""){alert(IMP.text.target_mbox)}else{messages_submit(d)}}}else{alert(IMP.text.mailbox_selectone)}}function selectFlagged(a,b){$H(messagelist).keys().each(function(f){var c,d=$("check"+f);if(a=="+"){c=!d.checked}else{if(a&messagelist[f]){c=b}else{c=!b}}selectRow(d.id,c)})}function flagMessages(b){var a=$("flag1"),c=$("flag2");if((b==1&&$F(a)!="")||(b==2&&$F(c)!="")){if(anySelected()){document.messages.flag.value=(b==1)?$F(a):$F(c);messages_submit("flag_messages")}else{if(b==1){a.selectedIndex=0}else{c.selectedIndex=0}alert(IMP.text.mailbox_selectone)}}}function getMessage(e,d){if(!d){return e}var a=$H(messagelist).keys();var c=a.indexOf(e);if(c!=-1){var b=c+d;if(b>=0&&b<a.length){return a[b]}}return""}function onKeyDownHandler(i){var b=i.element();var j=i.keyCode;var f,c;if(i.altKey||i.ctrlKey){var d,g;switch(j){case Event.KEY_UP:d=-1;g=-1;break;case Event.KEY_DOWN:d=1;g=1;break;default:return}if(typeof messagelist=="undefined"){return}if(b.id.indexOf("check")==0&&b.tagName=="INPUT"){c=b.id.substring(5);keyId=getMessage(c,d);f=$("subject"+keyId)}else{if(b.id.indexOf("subject")==0&&b.tagName=="A"){c=b.id.substring(7);keyId=getMessage(c,g);f=$("subject"+keyId)}else{keyId=((d+g)>0)?$H(messagelist).keys().first():$H(messagelist).keys().last();if(Event.KEY_UP||Event.KEY_DOWN){f=$("subject"+keyId)}}}}else{if(j==32&&b.id.indexOf("subject")==0&&b.tagName=="A"){startrange="check"+keyId;selectRow(startrange,!$(startrange).checked)}else{if(!i.shiftKey){var h;if(j==Event.KEY_LEFT&&$("prev")){h=$("prev").href}else{if(j==Event.KEY_RIGHT&&$("next")){h=$("next").href}}if(h){document.location.href=h}return}else{return}}}if(f){f.focus();var k=$("row"+keyId);if(i.altKey){var a=f.id.replace(/subject/,"check");selectRow(a,!$(a).checked)}else{if(c!=f.id&&k.className.indexOf("-over")==-1){k.className+="-over"}}if(c){k=$("row"+c);if(c!=f.id){k.className=k.className.replace(/-over/,"")}}}i.stop()}if(IMP.conf.hasDOM){document.observe("dom:loaded",function(){document.observe("keydown",onKeyDownHandler)})};