// 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, "");
}

//client set cookies
//time set
//# var rightNow = new Date();  
//# var expdate = new Date();  
//# expdate.setTime (expdate.getTime() + 1 * (24 * 60 * 60 * 1000));
function setCookie(name, value)  
{  
	var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) +  
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +  
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +  
		((secure == true) ? "; secure" : "");  
}

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;
}
//a1@a
function isRightEmailAddress(email){
    //var reg=/^@([\w-]+\.)+[\w-]{2,4}$$$/;
    var reg = /^@([\w-]+)/;
    return (email.match(reg) != null) ? true : false;
}
//a1@a.com
function matchAtAddress(email){
	var reg=/^@([\w-]+\.)+[\w-]{2,4}$$$/;	
	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,"&apos;");
    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++) {
    	 var mailItem = document.frm1.msgid[i];
    	 mailItem.checked = document.frm1.cb1[n].checked;
    	 $(mailItem.parentNode.parentNode).css('background-color',document.frm1.cb1[n].checked?'#FFFFCC':'');
    }
    document.frm1.msgid.checked = document.frm1.cb1[n].checked;
    $("input[name='cb1']").attr("checked", document.frm1.cb1[n].checked);
}

function chooseall_id(n){

    if (document.frm1.id == null) 
        return;
    for (i = 0; i < document.frm1.id.length; i++) {
        //if(frm1.cb1[0].checked == true)
        document.frm1.id[i].checked = document.frm1.cb1[n].checked;
    }
    document.frm1.id.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();
	
	if(document.frm1.mbtype && parent){
		parent.refreshNewMsgs(document.frm1.mbtype.value);
		parent.refreshNewMsgs(document.frm1.move.value);
	}
}

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();
	
	if(document.frm1.mbtype && parent){
		parent.refreshNewMsgs(document.frm1.mbtype.value);
	}	
}

function getmaillist(name, mbid){
    document.frm.action = version + "?type=getmail&mbtype=i" + name + "&mbid=" + mbid;
    document.frm.submit();
    
}

function viewmsg(n, showtype, subject){
    document.frm.msgid.value = n;
    var mbid = document.frm.mbid.value;
    var mbtype = document.frm.mbtype.value;
    var page = document.frm.page.value;
    var currenthref=document.getElementById(n);
    if(currenthref){
    	var p = currenthref.parentNode.parentNode;
    	var tds = p.getElementsByTagName("td");
    	for(var i = 0; i < tds.length; i++){
    		if(tds[i].className.indexOf("BlackBold") !=-1){
    	    	tds[i].className=tds[i].className.replace("BlackBold",""); 	    	
    		}
    	}
    }
    
    if (showtype == "1") { //inline show
        if (parent.viewmsg) {
            parent.viewmsg(subject, mbid, mbtype, n);
        }
        else {
            parent.main.location = version + "?type=showmsg&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        }
        ///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=800,height=580,top=" + (screen.availHeight - 585) / 2 + ",left=" + (screen.availWidth - 710) / 2);
    }
	
	//更改已读图片
    var imgid = n.replace(/\./g,'_');
	$("#read_img_" + imgid).attr({ src: "../../Images/icon_read.gif",height:"12",width:"14"});
	
	if(parent && parent.showProgressBar)
		parent.showProgressBar();
}

function viewmsgabstract(n, showtype, useraccount){
	var url = version + "?type=showmsg_abstract&mbid=0&msgid=" + n;
    window.open(url , 
    			"showmsg", "resizable,width=800,height=580,top=" + (screen.availHeight - 585) / 2 + ",left=" + (screen.availWidth - 710) / 2);
}

function videomail(){
    window.open("videomail/videomail.jsp", "videomail", "resizable,width=420,height=380,top=" + (screen.availHeight - 585) / 2 + ",left=" + (screen.availWidth - 710) / 2);
}

function audiomail(){
    window.open("audiomail/audiomail.jsp", "audiomail", "resizable,width=420,height=140,top=" + (screen.availHeight - 585) / 2 + ",left=" + (screen.availWidth - 710) / 2);
}

function searchusermailviewmsg(uid, domain, mbid, mbtype, msgid, showtype){

    if (showtype == "1") { //inline show
        parent.main.location = "mailmain?type=searchusermailshowmsg&uid=" + uid +
        "&domain=" +
        domain +
        "&mbid=" +
        mbid +
        "&msgid=" +
        msgid +
        "&mbtype=" +
        mbtype;
    }
    else { //pop show by default
        window.open("mailmain?type=searchusermailshowmsg&uid=" + uid +
        "&domain=" +
        domain +
        "&mbid=" +
        mbid +
        "&msgid=" +
        msgid +
        "&mbtype=" +
        mbtype, "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(subtype){

    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(subtype){
    	window.open(version + "?type=vieworg&subtype=" + subtype + "&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page, "showorg", "scrollbars,resizable,width=600,height=450");
    }else{
    	window.open(version + "?type=vieworg&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page, "showorg", "scrollbars,resizable,width=600,height=450");    	
    }
}

function printview(subtype){
    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(subtype){
    	window.open(version + "?type=printview&subtype=" + subtype + "&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page, "printpreview", "scrollbars,resizable");
    }else{
    	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
        if (typeof(parent.parent.main) == "undefined") {
            parent.location = "composerindex.jsp?subtype=reply&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        }
        else {
            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
        if (typeof(parent.parent.main) == "undefined") {
            parent.location = "composerindex.jsp?subtype=reply&replytype=all&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        }
        else {
            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,tabName){
    var mbid = document.frm1.mbid.value;
    var mbtype = document.frm1.mbtype.value;
    var page = document.frm1.page.value;
    var n = msgid;
    var url = "";
    var currenthref=document.getElementById(msgid);
    if(currenthref){
    	var p = currenthref.parentNode.parentNode;
    	var tds = p.getElementsByTagName("td");
    	for(var i = 0; i < tds.length; i++){
    		if(tds[i].className.indexOf("BlackBold") !=-1){
    	    	tds[i].className=tds[i].className.replace("BlackBold",""); 	    	
    		}
    	}
    	$("#read_img_" + n).attr({ src: "../../Images/icon_read.gif"});
    }
    if (showtype == "1") { //inline show
        //parent.main.location = "composerindex.jsp?subtype=reply&kind=1&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        url = "composerindex.jsp?subtype=reply&kind=1&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        
        if((parent.turbomail || turbomail).i_WM_MAINPAGE_STYLE == 0){
        	parent.createNewDiv("Re:" + tabName, url);
        //right_mailline maillisttitle
        }else{
        	(parent.mainFrame || mainFrame).location = url;
        }
    }
    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, subject){
    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
        if (parent.composedraft) {
            parent.composedraft(subject, mbid, mbtype, n);
        }
        else {
            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=700,height=650,top=" + (screen.availHeight - 585) / 2 + ",left=" + (screen.availWidth - 710) / 2);
    }
	
	$("#read_img_" + n).attr({ src: "../../Images/icon_read.gif"});
}

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
        if (typeof(parent.parent.main) == "undefined") {
            parent.location = "composerindex.jsp?subtype=forward&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        }
        else {
            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
        if (typeof(parent.parent.main) == "undefined") {
            parent.location = "composerindex.jsp?subtype=forwardattach&mbid=" + mbid + "&msgid=" + n + "&mbtype=" + mbtype + "&page=" + page;
        }
        else {
            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&subtype=refresh&mbtype=new&mbid=" + mid;
    document.submitfrm.submit();
}

function return2org(u){
    parent.main.location = u;
}

function getmailfolder(mid, mbtype, mbname){
    if (parent.maillist_open) {
        parent.maillist_open(mbtype, mbname);
    }
    else {
        document.submitfrm.action = mainpage + "?type=getmail&mbtype=" + mbtype + "&mbid=" + mid;
        document.submitfrm.submit();
    }
}


function getnewmail(){
    if (parent && parent.main) {    
        if (typeof(parent.main.document.forms[0]) != "undefined" &&
        typeof(parent.main.document.forms[0].msglist) != "undefined" &&
        parent.main.document.forms[0].mbtype.value == 'new') {
            document.submitfrm.action = mainpage + "?type=getmail&mbtype=new&mbid=0";
            document.submitfrm.submit();
        }
    }
	
	refreshNewMsgs("new");
}

function mustgetnewmail(){
    document.submitfrm.action = mainpage + "?type=getmail&mbtype=new&mbid=0";
    document.submitfrm.submit();
}

function returnmaillist_compose(mbtype, t){

    var Content = FCKeditorAPI.GetInstance("htmlbody").GetXHTML();
    if (Content == null || Content == "") {
    }
    else {
        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 returnmaillist_page(mbtype, page){
    if (mbtype == "sometime") {
        parent.location = "sometimemsglist.jsp?type=getmail&mbtype=" + mbtype + "&page=" + page + "&mbid=0";
    }
    else 
        if (mbtype == "") {
            parent.location = mainpage + "?type=getmail&mbtype=new&mbid=0" + "&page=" + page;
        }
        else {
            parent.location = mainpage + "?type=getmail&mbtype=" + mbtype + "&page=" + page + "&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 archivemaillistgopage(t, iup){
   	var sQuery = document.frm1.query.value;
    sQuery = sQuery.trim();
	
	var sRealfrom = document.frm1.realfrom.value;
	sRealfrom = sRealfrom.trim();
	
	var sRealto = document.frm1.realto.value;
	sRealto = sRealto.trim();
	
	var sStarttime = document.frm1.starttime.value;
	sStarttime = sStarttime.trim();
	
	var sEndtime = document.frm1.endtime.value;
	sEndtime = sEndtime.trim();
   
    if (sQuery != "" || sRealfrom != "" || sRealto != "" || sStarttime != "" || sEndtime != "") {  
        document.frm1.query.value = sQuery;
        document.frm1.action = "archivemaillist.jsp?type=getmail&search=true&sorttype=" + t + "&up=" + iup;
    }
    else {		
        document.frm1.action = "archivemaillist.jsp?type=getmail&search=true&sorttype=" + t + "&up=" + iup;
    }
    
    document.frm1.page.value = document.frm1.page.value;
    document.frm1.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&setpage=1";
    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();
	
	if(document.frm1.mbtype && parent){
		parent.refreshNewMsgs(document.frm1.mbtype.value);		
	}
}

function reportspam(){
    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_reportspam_1);
        return;
    }
    
    if (confirm(list_reportspam) == false) {
        return;
    }
    
    document.frm1.action = mainpage + "?type=getmail&subtype=reportspam";
    document.frm1.submit();
	
	if(document.frm1.mbtype && parent){
		parent.refreshNewMsgs(document.frm1.mbtype.value);		
	}
}

function msgdelall(){
    if (confirm(list_msgdel) == false) {
        return;
    }
    
    document.frm1.action = mainpage + "?type=getmail&subtype=delall";
    document.frm1.submit();
	
	if(document.frm1.mbtype && parent){
		parent.refreshNewMsgs(document.frm1.mbtype.value);		
	}
}

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();
        return;
    }
    
    if (showtype == "100") {
        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 = "mailmain?type=searchdelmsg";
        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 viewreportspam(showtype){
    if (confirm(list_viewreportspam) == false) {
        return;
    }
    if (showtype == "1") {
        document.frmreportspam.mbid.value = document.frm.mbid.value;
        document.frmreportspam.mbtype.value = document.frm.mbtype.value;
        document.frmreportspam.msgid.value = document.frm.msgid.value;
        document.frmreportspam.action = mainpage + "?type=getmail&subtype=reportspam";
        document.frmreportspam.submit();
        return;
    }
    
    if (showtype == "100") {
        document.frmreportspam.mbid.value = document.frm.mbid.value;
        document.frmreportspam.mbtype.value = document.frm.mbtype.value;
        document.frmreportspam.msgid.value = document.frm.msgid.value;
        document.frmreportspam.action = "mailmain?type=searchreportspam";
        document.frmreportspam.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.msgid.value = document.frm.msgid.value;
        window.parent.opener.document.frm1.action = mainpage + "?type=getmail&subtype=reportspam";
        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&subtype=refresh";
    document.frm1.submit();
    mailwait();
	
	if (parent) {
		parent.refreshNewMsgs(document.frm1.mbtype.value);
	}
}

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.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;
     }
     }
     */
    FCKeditorAPI.GetInstance('htmlbody').UpdateLinkedField();
    
    if (document.composeform.subject.value.trim().length == 0) {
        alert(list_sendnow_2);
        return;
    }
    
    
    document.composeform.action = version + "?type=sendmail";
    document.composeform.submit();
	if(parent && parent.partent && parent.parent.showProgressBar)
    	parent.parent.showProgressBar();
    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();
    
    document.composeform.action = version + "?type=savedraft";
    document.composeform.submit();
	if(parent && parent.partent && parent.parent.showProgressBar)
    	parent.parent.showProgressBar();
    sendmailwait();
}

function preview(t){
    if (t == 1) 
        getattachments_1();
    else 
        getattachments_0();
    
    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.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 cleanfolder(){
    if (confirm(list_cleanfolder) == false) {
        return;
    }
    
    document.frm.action = "mailmain?type=cleanfolder";
    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 spamabstractfresh(){
    document.frm1.action = "filteremailabstractlist.jsp";
    document.frm1.submit();
} 

function archivemaillistrefresh(){
    document.frm1.action = "archivemaillist.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 abstractdel(msgid){
    if (confirm(list_samsgdel) == false) {
        return;
    }
    document.frm1.action = "filteremailabstractlist.jsp?type=getmail&subtype=del&msgid=" + msgid;
    document.frm1.submit();
}

function searchusermailrefresh(){
    document.frm1.action = "mailmain?type=searchusermail&subtype=refresh";
    document.frm1.submit();
    mailwait();
}

function searchusermaildel(){
    if (confirm(list_msgdel) == false) {
        return;
    }
    document.frm1.action = "mailmain?type=searchusermail&subtype=delete";
    document.frm1.submit();
    mailwait();
}

function searchusermaildelall(){
    if (confirm(list_msgdel) == false) {
        return;
    }
    document.getElementById("cb1").click();
    document.frm1.action = "mailmain?type=searchusermail&subtype=delete&deltype=all";
    document.frm1.submit();
    mailwait();
}

function samsgdelall(){
    if (confirm(list_samsgdel) == false) {
        return;
    }
    
    document.frm1.action = "spamboxlist.jsp?type=getmail&subtype=delall";
    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 avmsgdelall(){
    if (confirm(list_avmsgdel) == false) {
        return;
    }
    
    document.frm1.action = "virusboxlist.jsp?type=getmail&subtype=delall";
    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 domainwhitelistdel(){
    if (confirm(list_userwhitelistdel) == false) {
        return;
    }
    document.frm.action = "domainwhitelist.jsp?subtype=del";
    document.frm.submit();
}


function domainblacklistdel(){
    if (confirm(list_userblacklistdel) == false) {
        return;
    }
    document.frm.action = "domainblacklist.jsp?subtype=del";
    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;
    }
    
    if (document.loginfrm.logincheckcode.value.trim() == "true") {
    	if (document.loginfrm.randomnumber.value.trim().length == 0) {
	        alert(common_enter_code);
	        document.loginfrm.randomnumber.focus();
	        return false;
    	}
    }
    
	if(document.loginfrm.rememberuid && document.loginfrm.rememberuid.checked){
		var rightNow = new Date();  
	    var expdate = new Date();  
		expdate.setTime (expdate.getTime() + 7 * (24 * 60 * 60 * 1000));
		setCookie('uid', document.loginfrm.uid.value,expdate);		
	}else{
		setCookie('uid');
	}
	//set client 
    //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 checkuserexist_reguser(){
    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_reguser(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();
}

function selfdelete(id){

    if (confirm(list_selfdelete) == false) {
        return;
    }
    
    document.frm.submit();
}

function getattachments_bulletin(){
    var e1 = "";
    var e2 = "";
    var filecount = 0;
    var v = parent.bulletinatt.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.bulletinatt.document.listform["filealias" + i].value;
        if (e1 != "") {
            e1 += ",";
            e1 += e;
        }
        else 
            e1 = e;
        e = parent.bulletinatt.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 sendbulletin(){
    if (document.composeform.subject.value.trim().length == 0) {
        alert(list_sendnow_1);
        return;
    }
    getattachments_bulletin();
    document.composeform.submit();
}

function addbulletin(){
    document.frm1.action = "bulletinindex.jsp";
    document.frm1.submit();
}

function refreshbulletin(){
    document.frm1.action = "bulletinlist.jsp";
    document.frm1.submit();
}

function viewbulletin(id, page, subject){
    if (parent.viewbulletin) {
        parent.viewbulletin(subject, id, page);
    }
    else {
        parent.main.location = version + "?type=showbulletin&id=" + id + "&page=" + page;
    }
}

function delbulletin(){
    if (confirm(list_delbulletin) == false) {
        return;
    }
    
    document.frm1.action = version + "?type=deletebulletin";
    document.frm1.submit();
}

function bulletingopage(t, iup){
    document.frm2.action = "bulletinlist.jsp?sorttype=" + t + "&up=" + iup;
    
    document.frm2.page.value = document.frm1.page.value;
    document.frm2.submit();
    mailwait();
}


//////ajax refresh new msg
function refreshSpanNewMsgs(newmsgs,mbtype){		
		$("#newmsgs" + mbtype).empty();
		if(newmsgs > 0)
			$("#newmsgs" + mbtype).append("(" + newmsgs + ")");
}
	
 function errorFunc(){
}

function successGetNewMsgsFunc(ret){

    if (ret == null) {
        return;
    }
    
    if (ret.ret_code != 0) {
        return;
    }	
    refreshSpanNewMsgs(ret.newmsgs,ret.mbtype);	
	//var eNew = $('#if_8,#fnew_new').text();
    if((parent.turbomail || turbomail).i_WM_MAINPAGE_STYLE == 0){
    	welcome.setMsgs(ret);
    }
}

function refreshNewMsgs(mbtype){    
    var url = 'mailmain?intertype=ajax&type=getnewmsgs&mbtype=' + mbtype;
    $.ajax({
            'url': url,
            'type': 'post',
            'dataType': 'json',
            'timeout': 20000,
            'error': errorFunc,
            'success': successGetNewMsgsFunc
        }); 
}

function selfdelete(){
	if (confirm(list_selfdelete) == false) {
        return;
    }
	
	document.frmselfdelete.submit();
}
