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.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(E){var C,D=$("check"+E);if(A=="+"){C=!D.checked}else{if(A&messagelist[E]){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(H){var B=H.element();var I=H.keyCode;var E,C;if(H.altKey||H.ctrlKey){var D,F;switch(I){case Event.KEY_UP:D=-1;F=-1;break;case Event.KEY_DOWN:D=1;F=1;break;default:return}if(!messagelist){return}if(B.id.indexOf("check")==0&&B.tagName=="INPUT"){C=B.id.substring(5);keyId=getMessage(C,D);E=$("subject"+keyId)}else{if(B.id.indexOf("subject")==0&&B.tagName=="A"){C=B.id.substring(7);keyId=getMessage(C,F);E=$("subject"+keyId)}else{keyId=((D+F)>0)?$H(messagelist).keys().first():$H(messagelist).keys().last();if(Event.KEY_UP||Event.KEY_DOWN){E=$("subject"+keyId)}}}}else{if(I==32&&B.id.indexOf("subject")==0&&B.tagName=="A"){startrange="check"+keyId;selectRow(startrange,!$(startrange).checked)}else{if(!H.shiftKey){var G;if(I==Event.KEY_LEFT&&$("prev")){G=$("prev").href}else{if(I==Event.KEY_RIGHT&&$("next")){G=$("next").href}}if(G){document.location.href=G}return}else{return}}}if(E){E.focus();var J=$("row"+keyId);if(H.altKey){var A=E.id.replace(/subject/,"check");selectRow(A,!$(A).checked)}else{if(C!=E.id&&J.className.indexOf("-over")==-1){J.className+="-over"}}if(C){J=$("row"+C);if(C!=E.id){J.className=J.className.replace(/-over/,"")}}}H.stop()}if(IMP.conf.hasDOM){document.observe("dom:loaded",function(){document.observe("keydown",onKeyDownHandler)})};