<!--

var waitTimeout = 1000;  //This is how long to wait (in milliseconds) before allowing people to reclick buttons that wait

function logout(){
	if((fld_trash ? fld_trash : 0) > 1048576)
	{
		if(confirm("Your trash is larger than 1Mb\nWould you like to empty your trash now?"))
		{
			window.parent.location = action + "?cmd=empty&process=logout&utoken=" + utoken + ((logout_url=="")?"":"&process=url&url=" + logout_url);
			return;
		}
	}
	window.parent.location = action + "?cmd=logout_go&utoken=" + utoken + ((logout_url=="")?"":"&url=" + logout_url);
}


// The below code is used if you want the popup to also use the pulldown menu.
function popup_box()
{
	link = action + '?cmd=list&page=stubf.tpl&utoken=' + putoken + '&pophost=';

	for (i=0;i< document.yList.host_cur.options.length;i++) {
		if (document.yList.host_cur.options[i].selected == true)
			link = link + document.yList.host_cur.options[i].value + '&&';
	}

	open(link,
		'CHECKMAIL',
		'width=470,height=150,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes',
		'POPUP');
}

function mylistsubmit(cmd){
	if(_nopreview){
		if(window.parent.frames[2].document.List){
			document.menu.folder.value = window.parent.frames[2].document.List.folder.value;
		}
		else{
			document.menu.folder.value = window.parent.frames[1].document.form1.current.value;
		}
	}
	else{
		if(window.parent.frames[2].frames[0].document.List){
			document.menu.folder.value = window.parent.frames[2].frames[0].document.List.folder.value;
		}
		else{
			document.menu.folder.value = window.parent.frames[1].document.form1.current.value;
		}
	}

	document.menu.listcmd.value = cmd;
	document.menu.cmd.value = "show";
	document.menu.page.value = "framenew";
	document.menu.submit();
}

function next(){
	if(window.parent.frames[2].frameliston == true){
		if(window.parent.frames[2].frames[1].document.email != null && window.parent.frames[2].frames[1].document.email.mynext != null){
			if(window.parent.frames[2].frames[1].document.email.mynext.value == ""){
				alert("You are already viewing the last message in this folder");
				return;
			}
			var next = action + "?cmd=item-"
					 + window.parent.frames[2].frames[1].document.email.mynext.value
					 + "&utoken=" + utoken + "&folder="
					 + window.parent.frames[2].frames[1].document.email.folder.value;
			window.parent.frames[2].frames[1].document.location.replace(next);
		}
		else{
			window.parent.frames[2].frames[0].document.location.replace(action + "?cmd=list&utoken=" + utoken + "&folder=" + window.parent.frames[1].document.form1.current.value);
		}
	}
	else{
		window.parent.frames[2].location.replace(action + "?cmd=" + (_nopreview ? "list" : "show") + "&page=framelist&listcmd=list&folder=" + window.parent.frames[1].document.form1.current.value + "&utoken=" + utoken);
	}
}

function prev(){
	if(window.parent.frames[2].frameliston == true){
		if(window.parent.frames[2].frames[1].document.email != null && window.parent.frames[2].frames[1].document.email.myprev != null){
			if(window.parent.frames[2].frames[1].document.email.myprev.value == ""){
				alert("You are already viewing the first message in this folder");
				return;
			}
			var prev = action + "?cmd=item-"
					 + window.parent.frames[2].frames[1].document.email.myprev.value
					 + "&utoken=" + utoken + "&folder="
					 + window.parent.frames[2].frames[1].document.email.folder.value;

			window.parent.frames[2].frames[1].document.location.replace(prev);
		}
		else{
			window.parent.frames[2].frames[0].document.location.replace(action + "?cmd=list&utoken=" + utoken + "&folder=" + window.parent.frames[1].document.form1.current.value);
		}
	}
	else{
		window.parent.frames[2].location.replace(action + "?cmd=" + (_nopreview ? "list" : "show") + "&page=framelist&listcmd=list&folder=" + window.parent.frames[1].document.form1.current.value + "&utoken=" + utoken);
	}
}

function getUID(){
	var now = new Date();
	var rnd = Math.random() + "";
	rnd = rnd.substring(0, rnd.indexOf('.')) + rnd.substring(rnd.indexOf('.')+1,rnd.length);
	return now.getMilliseconds() + "_" + rnd;
}

function NewMsgWindow(){
	var UID = getUID();
	window.open(action + "?cmd=show&page=framenew&listcmd=msg_new&utoken=" + utoken ,UID,'left=20,top=20,width=750,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
}

function openWindow(){
	var UID = getUID();
	window.open(nwimg + "/blank.htm",UID,'left=20,top=20,width=750,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
	return UID;
}

function redirectf(){
	if(window.parent.frames[2].frameliston == true && window.parent.frames[2].frames[1].document.email != null && window.parent.frames[2].frames[1].document.email.myuidl != null){
		if(window.parent.frames[2].frames[0].document.List != null){
			var form = window.parent.frames[2].frames[0].document.List;
			var selected = null;

			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){

							form.cmd.value = "forwardsel";
							form.target = openWindow();
							form.redirect.value = "true";
							form.submit();
							return;
						}
					}
				}
			}

			form.cmd.value = "forward-" + window.parent.frames[2].frames[1].document.email.myuidl.value;
			form.target = openWindow();
			form.redirect.value = "true";
			form.submit();

			if(netscape_version.indexOf("4.") >= 0 || ie_version.indexOf("5.") >= 0){
				setTimeout('document.menu.not_new.value = ""', 1000);
				setTimeout('document.menu.redirect.value = ""', 1000);
			}else{
				document.menu.not_new.value = "";
				document.menu.redirect.value = "";
			}

			return;
		}
	}

	var form = null;
	if(window.parent.frames[2]){
		if(window.parent.frames[2].frames[0]){
			if(window.parent.frames[2].frames[0].name){
				if(window.parent.frames[2].frames[0].listf)
					form = window.parent.frames[2].frames[0].document.List;
			}
		}
	}
	if(window.parent.frames[2].listf2)
		form = window.parent.frames[2].document.List;
	if(form){
			var selected = null;

			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){

							form.cmd.value = "forwardsel";
							form.target = openWindow();
							form.redirect.value = "true";
							form.submit();
							return;
						}
					}
				}
			}
	}
	alert("Please select a message before trying to redirect it");
	return;
}

function fwd_reply(cmd){
	if(window.parent.frames[2].frameliston == true && window.parent.frames[2].frames[1].document.email != null && window.parent.frames[2].frames[1].document.email.myuidl != null){
		if(window.parent.frames[2].frames[0].document.List != null){
			var form = window.parent.frames[2].frames[0].document.List;
			var selected = null;

			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							selected = form.elements[i].name.substring(4,form.elements[i].name.length);
							break;
						}
					}
				}
			}
		}
		if(selected){
			document.menu.myuidl.value = selected;
		}
		else{
			document.menu.myuidl.value = window.parent.frames[2].frames[1].document.email.myuidl.value;
		}
		document.menu.not_new.value = "true";
		document.menu.target = openWindow();
		mylistsubmit(cmd + document.menu.myuidl.value);
		//document.menu.not_new.value = "";
		document.menu.myuidl.value = "";
		return;
	}
	else{
		var form = null;
		if(window.parent.frames[2]){
			if(window.parent.frames[2].frames[0]){
				if(window.parent.frames[2].frames[0].name){
					if(window.parent.frames[2].frames[0].listf){
						form = window.parent.frames[2].frames[0].document.List;
					}
				}
			}
		}
		if(window.parent.frames[2].listf2){
			form = window.parent.frames[2].document.List;
		}
		if(form){
			var selected = null;

			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							if(selected != null){
								if (cmd == "forward_edit-"){
									form.cmd.value = "forwardsel";
									form.target = openWindow();
									form.submit();
									return;
								}
								else{
									alert("You can only reply to one message at a time");
									return;
								}
							}
							selected = form.elements[i].name.substring(4,form.elements[i].name.length);
						}
					}
				}
			}
			if(selected){
				window.open(action + "?cmd=show&page=framenew&listcmd=" + cmd + selected + "&utoken=" + utoken + "&folder=" + form.folder.value + ampersand + "not_new=true&&",'POPUP','width=750,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
				return;
			}
		}
	}
	if(cmd == "forward_edit-")
		alert("Please select a message before trying to forward it");
	else
		alert("Please select a message before trying to reply to it");
	return;
}


function forward(){
	if(window.parent.frames[2].frameliston == true && window.parent.frames[2].frames[1].document.email != null && window.parent.frames[2].frames[1].document.email.myuidl != null){
		if(window.parent.frames[2].frames[0].document.List != null){
			var form = window.parent.frames[2].frames[0].document.List;
			var selected = null;

			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							if(selected != null){
								form.cmd.value = "forwardsel";
								form.target = openWindow();
								form.redirect.value = "";
								form.submit();
								return;
							}
							selected = form.elements[i].name.substring(4,form.elements[i].name.length);
						}
					}
				}
			}
			if(selected){
				window.parent.frames[2].frames[1].document.email.myuidl.value = selected;
			}
			if (one_fwd == 'checked') {
				form.cmd.value = "forwardsel";
				form.target = openWindow();
				form.redirect.value = "";
				form.submit();
				return;
			}
			else
				fwd_reply("forward_edit-");
			return;
		}
	}

	if(window.parent.frames[2].listf2){
		if (one_fwd == 'checked') {
			form = window.parent.frames[2].document.List

			form.cmd.value = "forwardsel";
			form.target = openWindow();
			form.redirect.value = "";
			form.submit();
			return;
		}
		else
			fwd_reply("forward_edit-");
		return;
	}
	alert("Please select a message before trying to forward it");
	return;
}

function openFolder(folder){
	window.parent.frames[1].document.form1.current.value = folder;
	window.parent.frames[2].location.replace(action + "?cmd=" + (_nopreview ? "list" : "show") + "&page=framelist&listcmd=list&folder=" + folder + "&utoken=" + utoken);
}

function attach(){
	if(window.parent.frames[2].frameliston == true && window.parent.frames[2].frames[0].document.sendform != null){
		window.parent.frames[2].frames[0].document.sendform.cmd.value = "add_attach";
		window.parent.frames[2].frames[0].document.sendform.submit();
	}
	else{
		alert("You must compose a message to attach a file");
	}
}

function spell_check(){
	if(window.parent.frames[2].frameliston == true){
		if(window.parent.frames[2].frames[0].document.sendform != null){
			window.parent.frames[2].frames[0].document.sendform.message.value = window.parent.frames[2].frames[1].document.bodyform.message.value;
			window.parent.frames[2].frames[0].document.sendform.cmd.value = "spell_check";
			window.parent.frames[2].frames[0].document.sendform.submit();
		}
		else if(window.parent.frames[2].frames[0].frames[1].document.sendform != null){
			window.parent.frames[2].frames[0].frames[1].document.sendform.message.value = window.parent.frames[2].frames[1].document.bodyform.message.value;
			window.parent.frames[2].frames[0].frames[1].document.sendform.cmd.value = "spell_check";
			window.parent.frames[2].frames[0].frames[1].document.sendform.submit();
		}
	}
	else{
		alert("You must compose a message to perform a spellcheck");
	}
}

function print(){
	if(window.parent.frames[2].frameliston == true && window.parent.frames[2].frames[1].document.email != null && window.parent.frames[2].frames[1].document.email.myuidl != null){
		window.open(action + '?cmd=item-' + window.parent.frames[2].frames[1].document.email.myuidl.value + '&page=print&folder=' + window.parent.frames[2].frames[1].document.email.folder.value + '&utoken=' + utoken + '&&','print','width=470,height=400,toolbar=no,location=no,directories=no,status=no,menubar=yes,resizable=yes,scrollbars=yes');
		return;
	}
	if(window.parent.frames[2].listf2){
		var form = window.parent.frames[2].document.List;
		for(var i=0; i<form.elements.length; i++){
			if(form.elements[i].type == "checkbox"){
				if(form.elements[i].name.substr(0,4) == "sel_"){
					if(form.elements[i].checked){
						window.open(action + '?cmd=item-' + form.elements[i].name.substr(4,form.elements[i].name.length) + '&page=print&folder=' + form.fld.value + '&utoken=' + utoken + '&&','print','width=470,height=400,toolbar=no,location=no,directories=no,status=no,menubar=yes,resizable=yes,scrollbars=yes');
						return;
					}
				}
			}
		}
	}

	alert("Please select a message to print");
}

var waitDelsel = false;
function delsel(){
	if(!waitDelsel){
		waitDelsel = true;
		setTimeout("waitDelsel = false;", waitTimeout);
		if(window.parent.frames[2].frameliston == true){
			if(window.parent.frames[2].frames[0].document.List != null){
				var form = window.parent.frames[2].frames[0].document.List;
				for(var i=0; i<form.elements.length; i++){
					if(form.elements[i].type == "checkbox"){
						if(form.elements[i].name.substr(0,4) == "sel_"){
							if(form.elements[i].checked){
								form.cmd.value = "delsel";
								form.target = "_self";
								if(form.folder.value == waste_name){
									form.ignore_trash.value = "true";
									form.force_empty.value = "true";
								}
								form.submit();
								return;
							}
						}
					}
				}
			}

			if(window.parent.frames[2].frames[1].document.email != null){
				if(confirm("Are you sure you want to delete the message you are viewing?")){
					window.parent.frames[2].location.replace(window.parent.frames[2].frames[1].document.email.delquery.value);
				}
				return;
			}
		}

		if(window.parent.frames[2].listf2){
			var form = window.parent.frames[2].document.List;
			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							form.cmd.value = "delsel";
							//form.page.value = "listf2";
							if(form.folder.value == waste_name){
								form.ignore_trash.value = "true";
								form.force_empty.value = "true";
							}
							form.target = "_self";
							form.submit();
							return;
						}
					}
				}
			}
		}

		alert("You must select which messages you wish to delete before clicking delete");
	}
	return;
}

var waitspam_removesel = false;
function spam_removesel(){
	if(!waitspam_removesel){
		if(!confirm("Are you sure that you want to delete the selected emails and submit them to our SPAM Database?"))
			return;
		waitspam_removesel = true;
		setTimeout("waitspam_removesel = false;", waitTimeout);
		if(window.parent.frames[2].frameliston == true){
			if(window.parent.frames[2].frames[0].document.List != null){
				var form = window.parent.frames[2].frames[0].document.List;
				for(var i=0; i<form.elements.length; i++){
					if(form.elements[i].type == "checkbox"){
						if(form.elements[i].name.substr(0,4) == "sel_"){
							if(form.elements[i].checked){
								form.cmd.value = "spam_removesel";
								form.target = "_self";
								form.submit();
								return;
							}
						}
					}
				}
			}

			if(window.parent.frames[2].frames[1].document.email != null){
				if(confirm("Are you sure you want to delete the message you are viewing?")){
					window.parent.frames[2].location.replace(window.parent.frames[2].frames[1].document.email.delquery.value);
				}
				return;
			}
		}

		if(window.parent.frames[2].listf2){
			var form = window.parent.frames[2].document.List;
			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							form.cmd.value = "spam_removesel";
							//form.page.value = "listf2";
							form.target = "_self";
							form.submit();
							return;
						}
					}
				}
			}
		}

		alert("You must select which messages you wish to delete before clicking delete");
	}
	return;
}

function forcedelsel(){
	if(!waitDelsel){
		waitDelsel = true;
		setTimeout("waitDelsel = false;", waitTimeout);
		if(window.parent.frames[2].frameliston == true){
			if(window.parent.frames[2].frames[0].document.List != null){
				var form = window.parent.frames[2].frames[0].document.List;
				for(var i=0; i<form.elements.length; i++){
					if(form.elements[i].type == "checkbox"){
						if(form.elements[i].name.substr(0,4) == "sel_"){
							if(form.elements[i].checked){
								form.cmd.value = "delsel";
								form.ignore_trash.value = "true";
								form.force_empty.value = "true";
								form.target = "_self";
								form.submit();
								return;
							}
						}
					}
				}
			}

			if(window.parent.frames[2].frames[1].document.email != null){
				if(confirm("Are you sure you want to delete the message you are viewing?")){
					window.parent.frames[2].location.replace(window.parent.frames[2].frames[1].document.email.delquery.value);
				}
				return;
			}
		}

		if(window.parent.frames[2].listf2){
			var form = window.parent.frames[2].document.List;
			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							form.cmd.value = "delsel";
							//form.page.value = "listf2";
							form.target = "_self";
							form.submit();
							return;
						}
					}
				}
			}
		}

		alert("You must select which messages you wish to delete before clicking delete");
	}
	return;
}

function getSelFld(){
	for(var i=0; i<document.menu.dstfld.options.length; i++){
		if(document.menu.dstfld.options[i].selected == true){
			return (document.menu.dstfld.options[i].value).replace("&", "%26");
		}
	}
	return document.menu.dstfld.options[0].value;
}

var waitCopy = false;
function copysel(){
	if(!waitCopy){
		waitCopy = true;
		setTimeout("waitCopy = false;", waitTimeout);
		if(window.parent.frames[2].frameliston == true){
			if(window.parent.frames[2].frames[0].document.List != null){
				var form = window.parent.frames[2].frames[0].document.List;
				for(var i=0; i<form.elements.length; i++){
					if(form.elements[i].type == "checkbox"){
						if(form.elements[i].name.substr(0,4) == "sel_"){
							if(form.elements[i].checked){
								form.dstfld.value = getSelFld();
								form.cmd.value = "copysel";
								form.target = "_self";
								form.submit();
								return;
							}
						}
					}
				}
			}

			if(window.parent.frames[2].frames[1].document.email != null){
				window.parent.frames[2].location.replace(window.parent.frames[2].frames[1].document.email.copyquery.value + "&dstfld=" + getSelFld());
				return;
			}
		}
		if(window.parent.frames[2].listf2){
			var form = window.parent.frames[2].document.List;
			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							form.dstfld.value = getSelFld();
							form.cmd.value = "copysel";
							form.page.value = "listf2";
							form.target = "_self";
							form.submit();
							return;
						}
					}
				}
			}
		}

		alert("You must select which messages you wish to copy before clicking copy");
	}
	return;
}

var waitMove = false;
function movesel(){
	if(!waitMove){
		waitMove = true;
		setTimeout("waitMove = false;", waitTimeout);
		if(window.parent.frames[2].frameliston == true){
			if(window.parent.frames[2].frames[0].document.List != null){
				var form = window.parent.frames[2].frames[0].document.List;
				for(var i=0; i<form.elements.length; i++){
					if(form.elements[i].type == "checkbox"){
						if(form.elements[i].name.substr(0,4) == "sel_"){
							if(form.elements[i].checked){
								form.dstfld.value = getSelFld();
								form.cmd.value = "movesel";
								form.target = "_self";
								form.submit();
								return;
							}
						}
					}
				}
			}

			if(window.parent.frames[2].frames[1].document.email != null){
				window.parent.frames[2].location.replace(window.parent.frames[2].frames[1].document.email.movequery.value + "&dstfld=" + getSelFld());
				return;
			}
		}
		if(window.parent.frames[2].listf2){
			var form = window.parent.frames[2].document.List;
			for(var i=0; i<form.elements.length; i++){
				if(form.elements[i].type == "checkbox"){
					if(form.elements[i].name.substr(0,4) == "sel_"){
						if(form.elements[i].checked){
							form.dstfld.value = getSelFld();
							form.cmd.value = "movesel";
							form.page.value = "listf2";
							form.target = "_self";
							form.submit();
							return;
						}
					}
				}
			}
		}

		alert("You must select which messages you wish to move before clicking move");
	}
	return;
}

function newMsgTo(address){
	address = address.substring((address.indexOf(':')+1), address.length);
	var UID = getUID();
	window.open(action + "?cmd=show&page=framenew&listcmd=msg_new&utoken=" + utoken + "&get_attach_id=true" + ampersand + "not_new=false&h_from=" + address,UID,'left=20,top=20,width=750,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no');
}

var waitTrash = false;
function emptyTrash(){
	if(confirm("Are you sure you want to delete all the messages in your " + waste_name + " folder?")){
		if(!waitTrash){
			waitTrash = true;
			setTimeout("waitTrash = false;", waitTimeout);
			window.parent.frames[2].location = action + "?cmd=" + (_nopreview ? "empty&page=listf2" : "show&page=framelist&listcmd=empty") + "&utoken=" + utoken;
		}
	}
}

var waitSpam = false;
function emptySpam(){
	if(confirm("Are you sure you want to delete all the messages in your " + spam_name + " folder?")){
		if(!waitSpam){
			waitSpam = true;
			setTimeout("waitSpam = false;", waitTimeout);
			window.parent.frames[2].location = action + "?cmd=" + (_nopreview ? "empty_spam&page=listf2" : "show&page=framelist&listcmd=empty_spam") + "&utoken=" + utoken;
		}
	}
}

var waitCheck = false;
function checkMail(){
	if(!waitCheck){
		waitCheck = true;
		setTimeout("waitCheck = false;", waitTimeout);
		window.parent.frames[2].location = action + "?cmd=" + (_nopreview ? "reload_mail" : "show&listcmd=reload_mail") + "&force_imap_read_reload=true&page=framelist&utoken=" + utoken;
		window.parent.frames[1].document.form1.current.value = new_mail_name;
	}
}
//-->