// var version = "minimain";
var version = "mailmain";
var mainpage = "msglist.jsp";

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
String.prototype.rtrim = function()
{
    return this.replace(/(\s*$)/g, "");
}

function  checkDateInput(obj)   
           {  
           if  (obj.value.length==0)  return  false;  
           var  objValue=obj.value.replace(/[-\.]/g,"/");  
             
           try  
                       {  
                       var  a=new  Date(objValue);  
                       if  (isNaN(a))  
                                   {  
                                   
                                   alert(list_checkDateInput_1);
                                   obj.select();    
                                   obj.focus();  
                                   return  false;  
                                   }  
                       var  b;  
                       if  (a.getFullYear()<1900  || a.getFullYear()>2200)  
                                   {var  Today=new  Date();  
                                   b=Today.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate();  
                                   }  
                       else  if  (a.getFullYear()<1930)  
                                   b=(a.getFullYear()+100)+"-"+(a.getMonth()+1)+"-"+a.getDate();  
                       else  b=a.getFullYear()+"-"+(a.getMonth()+1)+"-"+a.getDate();  
                       obj.value=obj.value.replace(/[-\.\/]0*/g,"-");  
                       if  (b!=obj.value)  
                                   {  
                                   obj.value=b;  
                                   alert(list_checkDateInput_2);  
                                   obj.select();  
                                   obj.focus();  
                                   return  false;  
                                   }  
                       }  
           catch(Exception)  
                       {  
                         
                       alert(list_checkDateInput_1); 
                       obj.select();  
                       obj.focus();  
                       return  false;  
                       }  
      return  true;  
 } 
 
function CheckTEL(TEL)
{
 var i,j,strTemp;
 strTemp="0123456789-()# ,;";
 for (i=0;i<TEL.length;i++)
 {
  j=strTemp.indexOf(TEL.charAt(i)); 
  if (j==-1)
  {  
  	alert(list_CheckTEL_1 + TEL);
   return false;
  }
 } 
 return true;
}

function checkfiltertime(t)
{
 var i,j,strTemp;
 strTemp="0123456789-:~,; ";
 for (i=0;i<t.length;i++)
 {
  j=strTemp.indexOf(t.charAt(i)); 
  if (j==-1)
  {  
  	alert(list_checkfiltertime_1 + t);
   return false;
  }
 } 
 return true;
}

//check time
function checkTimeNum(iNum,iType){
	if(iType == 0 && iNum < 1900 ){
		   alert(checkTimeNum_1);
		   return false;
	}
	if(iType == 1 && (iNum < 1 || iNum > 12) ){
		   alert(checkTimeNum_2);
		   return false;
	}
	if(iType == 2 && (iNum < 1 || iNum > 31) ){
		   alert(checkTimeNum_3);
		   return false;
	}
	
	if(iType == 3 && (iNum < 0 || iNum > 23) ){
		   alert(checkTimeNum_4);
		   return false;
	}
	
	
	if(iType == 4 && (iNum < 0 || iNum > 59) ){
		   alert(checkTimeNum_5);
		   return false;
	}
	
	if(iType == 5 && (iNum < 0 || iNum > 59) ){
		   alert(checkTimeNum_6);
		   return false;
	}
	
	return true;
}

function isRightEmailAddress( email )
{
	//var reg=/^@([\w-]+\.)+[\w-]{2,4}$$$/;
	var reg=/^@([\w-]+)/;
	return ( email.match( reg ) != null ) ? true:false;
}

 function checkmailaddr( mails )
{
	if( mails == "")
		return true;
	mails = mails.replace( /;/g, ",");
	var mailArray = mails.split( ",");
	var unregs = "";
	for( var i=0;i < mailArray.length; i++ )
	{
		if(mailArray[i].trim().length == 0)
		   continue;
		var pos = mailArray[i].lastIndexOf( "@");
		if( pos == -1)
		{	unregs = unregs + mailArray[i] + ",\n";
			continue;
		}
		if( mailArray[i].length == pos + 1)
		{	unregs = unregs + mailArray[i] + ",\n";
			continue;
		}
		if( mailArray[i].charAt( mailArray[i].length-1 ) == ">" ){
			fix = mailArray[i].substring( pos , mailArray[i].length-1 );
		}else{
			fix= mailArray[i].substr( pos );
		}
		if( !isRightEmailAddress(fix)){
			unregs = unregs + mailArray[i] + ",\n";
		}
	}
	if( unregs != "")
	{
		alert( list_checkmailaddr + unregs.substring( 0, unregs.length-2));		
		return false;
	}
	return true;
}

function txt2html(str)
{
   var html = str.replace( /&/g,"&amp;");
   html = html.replace( /"/g,"&quot;");
   html = html.replace( /</g,"&lt;");
   html = html.replace( />/g,"&gt;");
   html = html.replace( / /g,"&nbsp;");
   html = html.replace( /\n/g,"<br>");
   return html;
}

function html2txt(str)
{
    var tag="";
    var result="";
    var str2="";
    var l = "<";
    var r = ">";
    var offset1=-1;
    var offset2=-1;
    
    var temp="";
    
    str2 = str;
    
    do {
    offset1 = str2.indexOf(l);
    offset2 = str2.indexOf(r);
    
    if ( offset1 > 0 )
        { 
            temp = str2.substring(0,offset1);
			result += temp; 
			str2 = str2.substring(offset1,str2.length);
			continue;
		}
    if ( offset1 == -1 )
    {
        result +=   str2;
        break;
    }
    
    tag = str2.substring(offset1+1,offset2);
    str2 = str2.substring(offset2+1,str2.length);
    tag.toLowerCase();
    if ( tag == "br" || tag =="BR" )
        { result += "\r\n";  }
    else
        tag = "";
    }    
    while ( 1 );
    
    while ( result.indexOf("&nbsp;") != "-1" ) result = result.replace("&nbsp;"," ");
    return result;
}


 function sendmailwait(){           	
 }
 
 function mailwait(){                
 }
 
 function folderwait(){
               
 }
  
  
 function chooseall(n){
  
   if(document.frm1.msgid == null) return; 
   for(i=0; i < document.frm1.msgid.length;i++){
      //if(frm1.cb1[0].checked == true)
          document.frm1.msgid[i].checked = document.frm1.cb1[n].checked;
   }
   document.frm1.msgid.checked = document.frm1.cb1[n].checked;
   
 }
  
 function movemsg(){
 	  var e2 = "";
    for (var i=0;i<document.frm1.elements.length;i++) {
       var e = document.frm1.elements[i];
       if ((e.name == 'msgid') && e.checked) {
          e2 += ";" + e.value;          
       }
    }
    if(e2 == ""){
    	alert(list_movemsg);
       return;
    }
    document.frm1.action= mainpage + "?type=getmail&subtype=move";
    //document.frm1.action= version + "?type=getmail&subtype=move";
    document.frm1.submit();    
 }
 
 function movemsgdel(){
 	  var e2 = "";
    for (var i=0;i<document.frm1.elements.length;i++) {
       var e = document.frm1.elements[i];
       if ((e.name == 'msgid') && e.checked) {
          e2 += ";" + e.value;          
       }
    }
    if(e2 == ""){
    	alert(list_movemsgdel);
       return;
    }
    document.frm1.action= mainpage + "?type=getmail&subtype=movedel";   
    document.frm1.submit();    
 }
 
 function getmaillist(name,mbid){
    document.frm.action = version + "?type=getmail&mbtype=i" + name + "&mbid=" + mbid;
    document.frm.submit(); 
            
 }

 function viewmsg(n,showtype){
    document.frm.msgid.value=n;
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;    
  
    if(showtype=="1"){     //inline show
    	parent.main.location = version + "?type=showmsg&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;    	
    }else{    //pop show by default
    	window.open(version + "?type=showmsg&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"showmsg","resizable,width=660,height=580,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);   
    }
 }
 
 function nextmsg(o,n,inext){
    document.frm.msgid.value=n;
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value; 
    
    o.location = version + "?type=showmsg&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page + "&next=" + inext;    	   
 }
 
 function vieworg(){
     
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var n = document.frm.msgid.value;
    window.open(version + "?type=vieworg&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"showorg","scrollbars,resizable,width=600,height=450");
 }
 
 function printview(){
     
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var n = document.frm.msgid.value;
    window.open(version + "?type=printview&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"printpreview","scrollbars,resizable");
 }
 
 function addAccount(){
    window.open( version + "?type=account&subtype=add","account","scrollbars,resizable,width=600,height=460");
 }
 
 function viewAccount(mbid){
    window.open(version + "?type=account&subtype=mod&mbid=" + mbid,"account","scrollbars,resizable,width=600,height=460"); 	
 }
 
  
 function delAccount(){    
    document.frm.action=version + "?type=accountlist&subtype=del";
    document.frm.submit(); 
    
 }
 
 function saveAccount(){
  if(document.frm.name.value==""){
    alert(list_saveAccount_1);
    return ;
  }
  if(document.frm.sender.value==""){
    alert(list_saveAccount_2);
    return ;
  }  
  if(document.frm.address.value==""){
    alert(list_saveAccount_3);
    return ;
  }  
  if(document.frm.pop3.value==""){
    alert(list_saveAccount_4);
    return ;
  } 
  if(document.frm.smtp.value==""){
    alert(list_saveAccount_5);
    return ;
  } 
  if(document.frm.password.value!=document.frm.compassword.value){
    alert(list_saveAccount_6);
    document.frm.password.value="";
    document.frm.compassword.value="";
    return ;
  }  	
 	
    document.frm.submit();
 }
 
 function savepop3agent(){
  if(document.frm.server.value==""){
    alert(list_savepop3agent_1);
    return ;
  }
  if(document.frm.username.value==""){
    alert(list_savepop3agent_2);
    return ;
  }
 	
    document.frm.submit();
 }
 
 
 function replyi(showtype){     
   
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var n = document.frm.msgid.value;
    
    if(showtype=="1"){     //inline show
    	parent.parent.main.location = "composerindex.jsp?subtype=reply&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
    }else{
    	window.open("composerindex.jsp?subtype=reply&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"reply","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 
 function replyall(showtype){     
   
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var n = document.frm.msgid.value;
    
    if(showtype=="1"){     //inline show
    	parent.parent.main.location = "composerindex.jsp?subtype=reply&replytype=all&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
    }else{
    	window.open("composerindex.jsp?subtype=reply&replytype=all&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"reply","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 

 
 function reply(msgid,showtype){     
   
    var mbid = document.frm1.mbid.value;
    var mbtype = document.frm1.mbtype.value;
    var page = document.frm1.page.value;
    var n = msgid;
    
    if(showtype=="1"){     //inline show
        parent.main.location ="composerindex.jsp?subtype=reply&kind=1&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
    }else{
    	window.open("composerindex.jsp?subtype=reply&kind=1&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"reply","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 
 function composedraft(msgid,showtype){   
    var mbid = document.frm1.mbid.value;
    var mbtype = document.frm1.mbtype.value;
    var page = document.frm1.page.value;
    var n = msgid;
    if(showtype=="1"){     //inline show
    	parent.main.location ="composerindex.jsp?subtype=composedraft&kind=1&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
    }else{
    	window.open("composerindex.jsp?subtype=composedraft&kind=1&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"composedraft","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 
 function composeorg(msgid,showtype){       
    var n = msgid;
    if(showtype=="1"){     //inline show
        parent.main.location ="composerindex.jsp?subtype=composeorg&kind=1&mbid=0&msgid=" + n;
    }else{
    	window.open("composerindex.jsp?subtype=composeorg&kind=1&mbid=0&msgid=" + n ,"composeorg","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 
 function forward(showtype){
     
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var n = document.frm.msgid.value;
    
    if(showtype=="1"){     //inline show
        parent.parent.main.location ="composerindex.jsp?subtype=forward&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
    }else{
    	window.open("composerindex.jsp?subtype=forward&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"forward","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 
 function forwardattach(showtype){      
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var n = document.frm.msgid.value;
    
    if(showtype=="1"){     //inline show
        parent.parent.main.location ="composerindex.jsp?subtype=forwardattach&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
    }else{
    	window.open("composerindex.jsp?subtype=forwardattach&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page,"forwardattach","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }
 
 function composerindex(showtype){ 
    if(showtype=="1"){     //inline show
        parent.main.location = "composerindex.jsp?subtype=new";
    }else{
    	window.open("composerindex.jsp?subtype=new","composerindex","scrollbars,resizable,width=660,height=650,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);
    }
 }

 function getmaili(mid){    
 	   document.submitfrm.action =  mainpage + "?type=getmail&mbtype=new&mbid=" +mid;
 	   document.submitfrm.submit();
     
 }
 

 
  function return2org(u){
    alert("u:" + u);
     parent.main.location = u;
 }
 
 function getmailfolder(mid,mbtype){   
 	   document.submitfrm.action =  mainpage + "?type=getmail&mbtype=" + mbtype + "&mbid=" +mid;
 	   document.submitfrm.submit();    
 }
 
 function returnmaillist_compose(mbtype,t){  
  	if(document.composeform.cb1.checked){
   	  var htmlframe = window.frames["html"];
	    var fContent = htmlframe.frames["textArea"];
   	  var sContent = fContent.document.body.innerHTML; 
   	
   	  if (sContent.trim().length != 0) {  
      		if(confirm(list_returnmaillist_1)==true){
      			 savedraft(t);
      			 return;
      		}      		
   	  }	
   	  //sContent = sContent.replace(/\r|\n|\r\n/g, " ");   	
   	   document.composeform.htmlbody.value = sContent;      	
   }else{           
   	  if (document.composeform.body.value.trim().length != 0 ) {  
      		if(confirm(list_returnmaillist_1)==true){
      			 savedraft(t);
      			 return;
      		} 
   	  }
   }
   
  	if(mbtype == "sometime"){
  		  parent.location = "sometimemsglist.jsp?type=getmail&mbtype=" + mbtype + "&mbid=0";
  	}else if(mbtype == ""){
        parent.location = mainpage + "?type=getmail&mbtype=new&mbid=0";
    }else {
        parent.location = mainpage + "?type=getmail&mbtype=" + mbtype + "&mbid=0";
    }
 }
 
 function returnmaillist(mbtype){     
  	if(mbtype == "sometime"){
  		  parent.location = "sometimemsglist.jsp?type=getmail&mbtype=" + mbtype + "&mbid=0";
  	}else if(mbtype == ""){
        parent.location = mainpage + "?type=getmail&mbtype=new&mbid=0";
    }else {
        parent.location = mainpage + "?type=getmail&mbtype=" + mbtype + "&mbid=0";
    }
 }
 
 function returnspambox(mbtype){     
  	parent.location = "spamboxlist.jsp";  	
 }
 
 function returnvirusbox(mbtype){     
  	parent.location = "virusboxlist.jsp";  	
 }
 
 function returnsometime(mbtype){     
  	parent.location = "sometimemsglist.jsp";  	
 }
 
  function returnapprove(mbtype){     
  	parent.location = "approvemsglist.jsp";  	
 }
 
 function getfolderi(mid){
      
    parent.main.location = version + "?type=listfolder&mbid=" +mid;
 
 }
 
 function gopage(t,iup){
    var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;
    	document.frm2.action= mainpage + "?type=getmail&search=true&sorttype=" + t + "&up=" + iup;
    }else{
    	document.frm2.action= mainpage + "?type=getmail&sorttype=" + t + "&up=" + iup;
    }
    document.frm2.page.value=document.frm1.page.value;
    
    document.frm2.submit();
    mailwait();    
 }
 
 function sometimegopage(t,iup){ 
    var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;    	
    	document.frm2.action= "sometimemsglist.jsp?type=getmail&search=true&sorttype=" + t + "&up=" + iup;
    }else{
    	document.frm2.action= "sometimemsglist.jsp?type=getmail&sorttype=" + t + "&up=" + iup;
    }
    
    document.frm2.page.value=document.frm1.page.value;    
    document.frm2.submit();
    mailwait();    
 }
 
 function approvegopage(t,iup){
 	var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;   	
    	document.frm2.action= "approvemsglist.jsp?type=getmail&search=true&sorttype=" + t + "&up=" + iup;
    }else{
    	document.frm2.action= "approvemsglist.jsp?type=getmail&sorttype=" + t + "&up=" + iup;
    }
    
    document.frm2.page.value=document.frm1.page.value;    
    document.frm2.submit();
    mailwait();    
 }
 
  function gopage1(p){
    var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;    	
    	document.frm2.action= mainpage + "?type=getmail&search=true";
    }else{
    	document.frm2.action= mainpage + "?type=getmail";
    }
    
    document.frm2.page.value=p;
    
    document.frm2.submit(); 
    mailwait();	
 }
 
 function msgsearch(p){    
    document.frm1.action= p + "?type=getmail&search=true";
    document.frm1.submit(); 
    mailwait();	
 }
 
 function msgdel(){
 	  var e2 = "";
    for (var i=0;i<document.frm1.elements.length;i++) {
       var e = document.frm1.elements[i];
       if ((e.name == 'msgid') && e.checked) {
          e2 += ";" + e.value;          
       }
    }
    if(e2 == ""){
    	alert(list_msgdel_1);
       return;
    }
    
    if(confirm(list_msgdel)==false){
    	return;
    	}
   
    document.frm1.action= mainpage + "?type=getmail&subtype=del";
    document.frm1.submit(); 
    
 }
 
 function sometimemsgdel(){
    
    if(confirm(list_msgdel)==false){
    	return;
    	}
    
    document.frm1.action= "sometimemsglist.jsp?type=getmail&subtype=del";
    document.frm1.submit();     
 }
 
 function approvemsgdel(){
    
    if(confirm(list_msgdel)==false){
    	return;
    	}
    
    document.frm1.action= "approvemsglist.jsp?type=getmail&subtype=del";
    document.frm1.submit();     
 }
 
 
 function delpop3agent(id){
    
    if(confirm(list_delpop3agent)==false){
    	return;
    	}
    
    document.frm.action= "pop3agentlist.jsp?subtype=del&id=" + id;
    document.frm.submit(); 
    
 } 
 
 function approve(showtype){
    document.frmapprove.action=version + "?type=approve";
    document.frmapprove.submit();  	
 }
 
 function viewdel(showtype){
 	  if(confirm(list_viewdel)==false){
    	return;
    }
    if(showtype=="1"){
        document.frmdel.mbid.value = document.frm.mbid.value;
    	document.frmdel.mbtype.value = document.frm.mbtype.value;
    	document.frmdel.delid.value = document.frm.msgid.value;    
    	document.frmdel.action=mainpage + "?type=getmail&subtype=del";
    	document.frmdel.submit();    	
    }else{
    	window.parent.opener.document.frm1.mbid.value = document.frm.mbid.value;
    	window.parent.opener.document.frm1.mbtype.value = document.frm.mbtype.value;
    	window.parent.opener.document.frm1.delid.value = document.frm.msgid.value;
    	window.parent.opener.document.frm1.action=mainpage + "?type=getmail&subtype=del";
    	window.parent.opener.document.frm1.submit();
    	window.parent.close();
    }
 }
 
 function refreshOpener(showtype){
    if(showtype=="1"){
    }else{
    	window.parent.opener.document.frm1.action= mainpage + "?type=getmail";
    	window.parent.opener.document.frm1.submit();
    }    
 }
 
 function refresh(){    
    document.frm1.action= mainpage + "?type=getmail";
    document.frm1.submit(); 
    mailwait();    
 }
 
 function refreshsometime(){    
    document.frm1.action= "sometimemsglist.jsp?type=getmail";
    document.frm1.submit(); 
    mailwait();    
 }
 
  function refreshapprove(){    
    document.frm1.action= "approvemsglist.jsp?type=getmail";
    document.frm1.submit(); 
    mailwait();    
 }
 
  function refreshsort(t,iup){  
    document.frm1.action= mainpage + "?type=getmail&sorttype=" + t + "&up=" + iup;
    document.frm1.submit(); 
    mailwait();    
 }
 
 function writespace(){
    document.write("&nbsp;");
 }
 
 function writeand(){
    document.write("&");
 }
 

function getattachments_0(){
  var e1="";var e2="";
  var filecount=0;
  var v=parent.attachment.document.listform.filecount.value;
  if(v==parseInt(v)){
     filecount=parseInt(v);
  }else{
    filecount=0;
  }
  
  for(var i=1;i<filecount+1;i++){
    var e = parent.attachment.document.listform["filealias" + i].value;
    if (e1 != "") {e1 += ",";e1 += e;} else e1 = e;
    e = parent.attachment.document.listform["filename" + i].value;
    if (e2 != "") {
    	e2 += "\r\n";
    	e2 += e;
    } else e2 = e;  
  }
 
document.composeform.attachfilealias.value = e1;
document.composeform.attachfilename.value = e2;
}

function getattachments_1(){
  var c = document.getElementById("attachment");
  if(c == null)
     return;
     
  var e1="";var e2="";
  var filecount=0;
  var v= attachment.document.listform.filecount.value;
  if(v==parseInt(v)){
     filecount=parseInt(v);
  }else{
    filecount=0;
  }
  
  for(var i=1;i<filecount+1;i++){
    var e = attachment.document.listform["filealias" + i].value;
    if (e1 != "") {e1 += ",";e1 += e;} else e1 = e;
    e = attachment.document.listform["filename" + i].value;
    if (e2 != "") {
    	e2 += "\r\n";
    	e2 += e;
    } else e2 = e;  
  }
  
  document.composeform.attachfilealias.value = e1;
  document.composeform.attachfilename.value = e2;
}

function showaddress(){
var url = "addressurl";
var AWnd = window.open(url,"AddressWindow","width=600,height=350,resizable=yes,menubar=yes,scrollbars=yes");
if ((document.composeform.window != null) && (!AWnd.opener))
AWnd.opener = document.composeform.window;
AWnd.focus();
}

function sendnotification(i){
   document.composeform.action = version + "?type=notification";
   document.composeform.submit();
   sendmailwait();   
}

function notificationclose(mbid,mbtype,msgid){
	 if(confirm(list_notificationclose) == true){
	 	   setnotification(mbid,mbtype,msgid);
	 	   window.close();
	 }else{
	 	   window.close();
	 }
}

function sendsometime(t){
   if(t == 1)
   	getattachments_1();
   else
    getattachments_0();
    
   if (document.composeform.to.value == "") {  
      alert(list_sendnow_1);
      return;
   }
   
   if (document.composeform.year.value == "" ||
   document.composeform.month.value == "" ||
   document.composeform.datex.value == "" ||
   document.composeform.hour.value == "" ||
   document.composeform.minute.value == "") {  
      alert(list_sendsometime_1);
      return;
   }
   
   if(!checkTimeNum(document.composeform.year.value,0))
   		return;
   
   if(!checkTimeNum(document.composeform.month.value,1))
   		return;
   		
   if(!checkTimeNum(document.composeform.datex.value,2))
   		return;
   		
   if(!checkTimeNum(document.composeform.hour.value,3))
   		return;
   		
   if(!checkTimeNum(document.composeform.minute.value,4))
   		return;   		
   
   
  /* if(!checkmailaddr(document.composeform.to.value)){
       return;
   }
   
   if (document.composeform.cc.value != "") {  
      if(!checkmailaddr(document.composeform.cc.value)){
          return;
      }
   }
   if (document.composeform.bcc.value != "") {  
      if(!checkmailaddr(document.composeform.bcc.value)){
          return;
      }
   }
   */
   
   if(document.composeform.cb1.checked){
   	var htmlframe = window.frames["html"];
	var fContent = htmlframe.frames["textArea"];
   	var sContent = fContent.document.body.innerHTML; 
   	
   	if (sContent.trim().length == 0 && document.composeform.subject.value.trim().length == 0 ) {  
      		alert(list_sendnow_1);
      		return;
   	}	
   	//sContent = sContent.replace(/\r|\n|\r\n/g, " ");   	
   	document.composeform.htmlbody.value = sContent;      	
   }else{           
   	if (document.composeform.body.value.trim().length == 0 && document.composeform.subject.value.trim().length == 0 ) {  
      		alert(list_sendnow_1);
      		return;
   	}
   }
   
   document.composeform.action = version + "?type=sendsometime";
   document.composeform.submit();
   sendmailwait();   
}

function sendnow(t){
   if(t == 1)
   	getattachments_1();
   else
    getattachments_0();
   
   var sTo = document.composeform.to.value;
   sTo = sTo.trim();
   
   if (sTo == "") {  
      alert(list_sendnow_1);
      return;
   }
   
   /*if(!checkmailaddr(document.composeform.to.value)){
       return;
   }
   
   if (document.composeform.cc.value != "") {  
      if(!checkmailaddr(document.composeform.cc.value)){
          return;
      }
   }
   if (document.composeform.bcc.value != "") {  
      if(!checkmailaddr(document.composeform.bcc.value)){
          return;
      }
   }
   */
   
   if(document.composeform.cb1.checked){
   	  var htmlframe = window.frames["html"];
	    var fContent = htmlframe.frames["textArea"];
   	  var sContent = fContent.document.body.innerHTML; 
   	
   	  if (sContent.trim().length == 0 && document.composeform.subject.value.trim().length == 0 ) {  
      		alert(list_sendnow_2);
      		return;
   	  }	
   	  //sContent = sContent.replace(/\r|\n|\r\n/g, " ");   	
   	   document.composeform.htmlbody.value = sContent;      	
   }else{           
   	  if (document.composeform.body.value.trim().length == 0 && document.composeform.subject.value.trim().length == 0 ) {  
      		alert(list_sendnow_2);
      		return;
   	  }
   }
   
   document.composeform.action = version + "?type=sendmail";
   document.composeform.submit();
   sendmailwait();   
}

function resend(){
   document.frm.action = version + "?type=resend";
   document.frm.submit();
   sendmailwait();
}

// type 0 -- up,down frame mode
//      1 -- same frame mode
function savedraft(t){
   if(t == 1)
   	getattachments_1();
   else
    getattachments_0();
   
   if(document.composeform.cb1.checked){
   	var htmlframe = window.frames["html"];
	var fContent = htmlframe.frames["textArea"];
   	var sContent = fContent.document.body.innerHTML;   	   	
   	//sContent = sContent.replace(/\r|\n|\r\n/g, " ");   	
   	document.composeform.htmlbody.value = sContent;   	
   }
   
   document.composeform.action = version + "?type=savedraft";
   document.composeform.submit();
   
   sendmailwait();   
}

function preview(t){
   if(t == 1)
   	getattachments_1();
   else
    getattachments_0();   
   
   if(document.composeform.cb1.checked){
   	var htmlframe = window.frames["html"];
	  var fContent = htmlframe.frames["textArea"];
   	var sContent = fContent.document.body.innerHTML;   	   	
   	//sContent = sContent.replace(/\r|\n|\r\n/g, " ");   	
   	document.composeform.htmlbody.value = sContent;   	
   }
  
   document.composeform.target ="target";
   document.composeform.action = version + "?type=preview";
   document.composeform.submit();    
   document.composeform.target ="_parent";
}

function sendlater(t){
   if(t == 1)
   	getattachments_1();
   else
    getattachments_0();
    
   if (document.composeform.to.value == "") {  
      alert(list_sendlater_1);
      return;
   }
   
   if (document.composeform.body.value == " " && document.composeform.subject.value == "" ) {  
      alert(list_sendlater_2);
      return;
   }
 
   document.composeform.action = version + "?type=sendmail&subtype=later";
   document.composeform.submit(); 
   sendmailwait();
 
}

function Add(){
   if (document.listform.uploadfilename.value=="") {alert(list_Add);return;}
   document.listform.request.value="Add";
   document.listform.submit( );
   
}

function Addnetdisk(){
   if (document.listform.netdisk_name.value=="") {alert(list_Addnetdisk);return;}
   document.listform.request.value="Addnetdisk";
   //disabled the fileupload
   var fu = document.getElementById("uploadfilename");
   fu.setAttribute("disabled","true");
   document.listform.submit( );
   
}

function Delete(){
   document.listform.request.value="Delete";
   document.listform.submit();
   
}


function delfolder(mbid,msgnum){ 
	 if(msgnum > 0){
	 	  if(confirm(list_delfolder)==false){
    	      return;
    	}
	 }
   document.frm.action = "mailmain?type=delfolder&mbid=" + mbid;
   document.frm.submit();
   folderwait();
}

function addfolder(mbid){ 
	 var s = document.frm.newfolder.value;
	
	 if(s==""){
	 	   alert(list_addfolder);
	 	   return;
	 }
   document.frm.action = "mailmain?type=addfolder&mbid=" + mbid;
   document.frm.submit();
   folderwait();
}

function rename(mbid){ 
	 var s = document.frm.renamefolder.value;
	 
	 if(s==""){
	 	   alert(list_rename);
	 	   return;
	 }
   document.frm.action = "mailmain?type=renamefolder&mbid=" + mbid;
   document.frm.submit();
   folderwait();
}

 function showaddr(){     
    window.open("addressbook/addrmain.jsp?subtype=fill&curfoldertype=personal","addrfill","scrollbars,resizable,width=900,height=700");
 }
 
 
  function sarefresh(){     
    document.frm1.action= "spamboxlist.jsp?type=getmail";
    document.frm1.submit(); 
    mailwait();    
 }
 
  function samsgdel(){    
    if(confirm(list_samsgdel)==false){
    	return;
    	}
   
    document.frm1.action= "spamboxlist.jsp?type=getmail&subtype=del";
    document.frm1.submit();     
 }
 
   function sarefreshsort(t){  
    document.frm1.action= "spamboxlist.jsp?type=getmail&sorttype=" + t;
    document.frm1.submit(); 
    mailwait();    
 }
 
  function sagopage(){
    var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;    	
    	document.frm2.action= "spamboxlist.jsp?type=getmail&search=true";
    }else{
    	document.frm2.action= "spamboxlist.jsp?type=getmail";
    }
    
    document.frm2.page.value=document.frm1.page.value;    
    document.frm2.submit();
    mailwait();
    
 }
 
 function sagopage1(p){
    var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;    	
    	document.frm2.action= "spamboxlist.jsp?type=getmail&search=true";
    }else{
    	document.frm2.action= "spamboxlist.jsp?type=getmail";
    }
    
    document.frm2.page.value=p;    
    document.frm2.submit(); 
    mailwait();	
 }
 
 function saresend(){  
    document.frm1.action= "spamboxlist.jsp?type=getmail&subtype=resend";
    document.frm1.submit();     
 }
 
  function salearnspam(){  
    document.frm1.action= "spamboxlist.jsp?type=getmail&subtype=learnspam";
    document.frm1.submit();     
 }
 
   function salearnham(){  
    document.frm1.action= "spamboxlist.jsp?type=getmail&subtype=learnham";
    document.frm1.submit();     
 }
 
 //////////
  function avrefresh(){     
    document.frm1.action= "virusboxlist.jsp?type=getmail";
    document.frm1.submit(); 
    mailwait();    
 }
 
  function avmsgdel(){    
    if(confirm(list_avmsgdel)==false){
    	return;
    	}
   
    document.frm1.action= "virusboxlist.jsp?type=getmail&subtype=del";
    document.frm1.submit();     
 }
 
   function avrefreshsort(t){  
    document.frm1.action= "virusboxlist.jsp?type=getmail&sorttype=" + t;
    document.frm1.submit(); 
    mailwait();    
 }
 
function avgopage(){
   var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
   
    if (sQuery != "") {  
    	document.frm2.query.value = sQuery;   	
    	document.frm2.action= "virusboxlist.jsp?type=getmail&search=true";
    }else{
    	document.frm2.action= "virusboxlist.jsp?type=getmail";
    }
    
    document.frm2.page.value=document.frm1.page.value;   
    document.frm2.submit();
    mailwait();
    
 }
 
   function avgopage1(p){
    document.frm2.page.value=p;
    document.frm2.action= "virusboxlist.jsp?type=getmail";
    document.frm2.submit(); 
    mailwait();	
 }
 
 function avresend(){      
    document.frm1.action= "virusboxlist.jsp?type=getmail&subtype=resend";
    document.frm1.submit();     
 }
 
 function userblacklistdel(){  
    if(confirm(list_userblacklistdel)==false){
    	return;
    	}    	    
    document.frm.action= "userblacklist.jsp?subtype=del&usertype=personal";
    document.frm.submit();     
 }
 
 function userwhitelistdel(){  
    if(confirm(list_userwhitelistdel)==false){
    	return;
    	}    	    
    document.frm.action= "userwhitelist.jsp?subtype=del&usertype=personal";
    document.frm.submit();     
 }
 
 function savemessagephrase(){
  if(document.frm.topic.value==""){
    alert(list_savemessagephrase_1);
    return ;
  }
  if(document.frm.content.value==""){
    alert(list_savemessagephrase_2);
    return ;
  }
 	
    document.frm.submit();
 }
 
  function delmessagephrase(id){
    
    if(confirm(list_delmessagephrase)==false){
    	return;
    	}
    
    document.frm.action= "messagephraselist.jsp?subtype=del&id=" + id;
    document.frm.submit(); 
    
 }
 
  function ml_changemb(i){
     if(i == 0){
        document.frm1.move1.selectedIndex = document.frm1.move.selectedIndex;
     }else{
        document.frm1.move.selectedIndex = document.frm1.move1.selectedIndex;
     }
  }
  
 function shownetdisk(ctlindex){     
    window.open("fillnetdisk.jsp?seltype=file&ctlindex=" + ctlindex,"netdiskfill","scrollbars,resizable,width=680,height=500");
 }
 
 function shownetdisk_saveatt(){     
    var e2 = "";
    for (var i=0;i<document.frmheader.elements.length;i++) {
       var e = document.frmheader.elements[i];
       if ((e.name == 'selatt') && e.checked) {
          e2 += ";" + e.value;          
       }
    }
    if(e2 == ""){
    	alert(list_shownetdisk_saveatt);
       return;
    }
    window.open("fillnetdisk.jsp?seltype=path","netdiskfill_sa","scrollbars,resizable,width=680,height=500");
 }

 function showsaveaddr(email){     
    window.open("addressbook/saveaddr.jsp?curfoldertype=personal&email=" + email,"saveaddr","scrollbars,resizable,width=600,height=700");
 }
 
 function viewnotification(mbid,mbtype,msgid){
     window.open("notification.jsp?type=showmsg&mbid=" + mbid + "&msgid=" +msgid + "&mbtype=" + mbtype ,"notification","resizable,width=660,height=430,top="+(screen.availHeight-585)/2+",left="+(screen.availWidth-710)/2);      
 }
 
function profileclean(){
	document.frm.items.value = 50;
	document.frm.first_name.value = "";
	document.frm.telephone.value = "";
	document.frm.mobile.value = "";
	document.frm.postalcode.value = "";
	document.frm.country.value = "";
	document.frm.state_province.value = "";
	document.frm.city.value = "";
	document.frm.organization.value = "";
	document.frm.department.value = "";
	document.frm.address.value = "";
	document.frm.signtitle1.value = "";
	document.frm.sign1.value = "";
	document.frm.signtitle2.value = "";
	document.frm.sign2.value = "";
	document.frm.signtitle3.value = "";
	document.frm.sign3.value = "";	
}

function login(){
	if(document.loginfrm.uid.value.trim().length == 0){
		   alert(list_login_1);
       return false;
	}
	
	if(document.loginfrm.domain.value.trim().length == 0){
		   alert(list_login_2);
       return false;
	}
	
	//document.loginfrm.submit();
	return true;
}

function login_change_lang(){
	document.loginfrm.action = "login.jsp"	
	document.loginfrm.submit();
}

function maintlogin_change_lang(){
	document.loginfrm.action = "maintlogin.jsp"	
	document.loginfrm.submit();
}

function maintlogin(){
	if(document.loginfrm.uid.value.trim().length == 0){
		   alert(list_login_1);
       return false;
	}
		
	//document.loginfrm.submit();
	return true;
}

function checkuserexist(){
	var username = document.frm.username.value;
	var domain = document.frm.domain.value;
	
	if(domain.trim().length == 0 || username.trim().length==0){
		   alert(list_checkuserexist_1);
       return;
	}
	
	nq_checkusernameexist(username,domain);
}

function submitUrl(url){   
 	   document.submitfrm.action = url;
 	   document.submitfrm.submit();    
 }
 
 function sendsuggestion(){
 	if(document.frm.subject.value.trim().length == 0){
		   alert(list_sendsuggestion_1);
       return false;
	}
	
	if(document.frm.content.value.trim().length == 0){
		   alert(list_sendsuggestion_2);
       return false;
	}
	
	document.frm.submit();
 }