var TIMEOUT_ALERT_STR = "您已经超时, 请立即保存信息";
var allminutes = 20;
setTimeout("Time()", 60000);

function Time() {
	allminutes--;

	if (document.layers)
	{
		document.layers.minpt.document.write(allminutes.toString());
		document.layers.minpt.document.close();
	}
	else if (document.all)
		minpt.innerHTML = allminutes.toString();


	if (allminutes > 0)
		setTimeout("Time()", 60000);
	else
		alert(TIMEOUT_ALERT_STR);
}


function selectAdd(mode) {
	var remote = null;

	if (mode == "To")
	{
		remote = window.open("selectadd.asp?mode=To&GRSN=4200403", "", "top=80; left=150; height=345,width=496,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no");

		if (remote)
			remote.opener = this.f1.EasyMail_To;
	}
	else if (mode == "Cc")
	{
		remote = window.open("selectadd.asp?mode=Cc&GRSN=3371807", "", "top=80; left=150; height=345,width=496,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no");

		if (remote)
			remote.opener = this.f1.EasyMail_Cc;
	}
	else if (mode == "Bcc")
	{
		remote = window.open("selectadd.asp?mode=Bcc&GRSN=1169179", "", "top=80; left=150; height=345,width=496,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no");

		if (remote)
			remote.opener = this.f1.EasyMail_Bcc;
	}
}


function showSave() {
	f1.SendMode.value = "save";

	sub(0);
}

function showSending() {
	sub(1);
}

function timerSending() {
	if (checkTime() == true)
	{
		f1.SendMode.value = "timersend";
		sub(0);
	}
}

function cutz(inval)
{
	var rval = "";

	for (var i = 0; i < inval.length; i++)
	{
		if (inval.charAt(i) != '0')
			break;
	}

	rval = inval.substring(i);

	return rval;
}

function checkTime()
{
	var err = "日期错误";
	var nowdate = new Date(2007,3,2,12,35);
	var mydate = new Date(f1.t_year.value, f1.t_month.value, f1.t_day.value, f1.t_hour.value, 1);

	var nmonth = f1.t_month.value;
	var nday = f1.t_day.value;
	var nhour = f1.t_hour.value;

	if (f1.t_year.value == "" || f1.t_year.value > 9999 || f1.t_year.value < 2007)
	{
		alert(err);
		f1.t_year.focus();
		return false;
	}

	if (nmonth == "" || nmonth > 12 || nmonth < 1)
	{
		alert(err);
		f1.t_month.focus();
		return false;
	}

	if (nday == "" || nday > 31 || nday < 1)
	{
		alert(err);
		f1.t_day.focus();
		return false;
	}

	if (nhour == "" || nhour > 23 || nhour < 0)
	{
		alert(err);
		f1.t_hour.focus();
		return false;
	}


	if (mydate > nowdate)
	{
		if (f1.t_month.value < 10)
			nmonth = "0" + cutz(f1.t_month.value);

		if (f1.t_day.value < 10)
			nday = "0" + cutz(f1.t_day.value);

		if (f1.t_hour.value < 10)
			nhour = "0" + cutz(f1.t_hour.value);

		if (nhour == "0")
			nhour = "00"

		f1.EasyMail_TimerSend.value = f1.t_year.value + nmonth + nday + nhour;
	}
	else
	{
		f1.t_hour.focus();
		alert("定时发送的日期应该比现在迟.");
		return false;
	}

	return true;
}

function sub(smode){
	if (allminutes < 1)
	{
		alert(TIMEOUT_ALERT_STR);
		return ;
	}

	if (check_sendto_number() == false)
	{
		f1.EasyMail_To.focus();
		alert("邮件接收地址过多.");
		return ;
	}

	if (f1.needCheckCertPassword.value == "1")
	{
		if (f1.EasyMail_CertPW.value.length < 8)
		{
			alert("密码输入错误!");
			f1.EasyMail_CertPW.focus();
			return ;
		}
	}

	if (f1.EasyMail_To.value != "")
	{

	f1.RichEdit_Text.value = richedit.getText();
	f1.RichEdit_Html.value = richedit.getHTML();

	dec_RichEdit_Text();
	dec_RichEdit_Html();


f1.AddFromAttFileString.value = "";

var i = 0;
for (i; i < f1.NetAtts.length; i++)
{
	f1.AddFromAttFileString.value = f1.AddFromAttFileString.value + f1.NetAtts[i].value + "\t";
}

		f1.submit();
	}
	else
	{
		alert("请输入收件人地址");
		f1.EasyMail_To.focus();
	}
}

function window_onload() {

	f1.EasyMail_To.value = parent.parent.f1.to.value;
	f1.EasyMail_Cc.value = parent.parent.f1.cc.value;
	f1.EasyMail_Bcc.value = parent.parent.f1.bcc.value;

	parent.parent.f1.to.value = "";
	parent.parent.f1.cc.value = "";
	parent.parent.f1.bcc.value = "";

}

var qF = "EasyMail_To";

function addit(qaEmail){
	if (f1.elements[qF].value.length == 0 || f1.elements[qF].value.indexOf(qaEmail) == -1) 
	{
		if (f1.elements[qF].value.length != 0 && f1.elements[qF].value.charAt(f1.elements[qF].value.length - 1) != ",")
		f1.elements[qF].value += ",";
		f1.elements[qF].value += qaEmail;
	}
}

function setIt(H){qF=H;}

function EditSpeedAff(){
	window.open("editspeedadd.asp?GRSN=5121272", "", "top=80; left=150; height=345,width=496,scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no");
}

function delNetAtt(){
	if (f1.NetAtts.selectedIndex != -1)
	{
		f1.NetAtts.remove(f1.NetAtts.selectedIndex);
		f1.NetAtts.selectedIndex = 0;
	}
}

function addNetAtt(){
	if (f1.NetSaveAtts.selectedIndex != -1)
	{
		var oOption = document.createElement("OPTION");
		oOption.text = f1.NetSaveAtts[f1.NetSaveAtts.selectedIndex].text;
		oOption.value = f1.NetSaveAtts[f1.NetSaveAtts.selectedIndex].value;
		f1.NetAtts.add(oOption);

		f1.NetAtts.selectedIndex = f1.NetAtts.length - 1;
	}
}

function dec_EasyMail_Text()
{
	var count = 0;
	var theObj;
	var FormLimit = 50000;

	var TempVar = new String;
	TempVar = document.f1.EasyMail_Text.value;

	if (TempVar.length > FormLimit)
	{
		while (TempVar.length > 0 && count < 10)
		{
			theObj = eval("document.all(\"add" + count + "\")");
			theObj.innerHTML = "<Textarea rows=1 cols=1 name='Mdec_EasyMail_Text" + count + "'></Textarea>";

			theObj = eval("f1.Mdec_EasyMail_Text" + count);
			theObj.value = TempVar.substr(0, FormLimit);

			TempVar = TempVar.substr(FormLimit);

			count++;
		}
	}
	else
	{
		theObj = eval("document.all(\"add1\")");
		theObj.innerHTML = "<Textarea rows=1 cols=1 name='Mdec_EasyMail_Text1'></Textarea>";

		theObj = eval("f1.Mdec_EasyMail_Text1");
		theObj.value = TempVar;
	}
}

function dec_RichEdit_Text()
{
	var count = 10;
	var theObj;
	var FormLimit = 50000;

	var TempVar = new String;
	TempVar = document.f1.RichEdit_Text.value;

	if (TempVar.length > FormLimit)
	{
		while (TempVar.length > 0 && count < 20)
		{
			theObj = eval("document.all(\"add" + count + "\")");
			theObj.innerHTML = "<Textarea rows=1 cols=1 name='Mdec_RichEdit_Text" + count + "'></Textarea>";

			theObj = eval("f1.Mdec_RichEdit_Text" + count);
			theObj.value = TempVar.substr(0, FormLimit);

			TempVar = TempVar.substr(FormLimit);

			count++;
		}
	}
	else
	{
		theObj = eval("document.all(\"add10\")");
		theObj.innerHTML = "<Textarea rows=1 cols=1 name='Mdec_RichEdit_Text10'></Textarea>";

		theObj = eval("f1.Mdec_RichEdit_Text10");
		theObj.value = TempVar;
	}
}

function dec_RichEdit_Html()
{
	var count = 20;
	var theObj;
	var FormLimit = 50000;

	var TempVar = new String;
	TempVar = document.f1.RichEdit_Html.value;

	if (TempVar.length > FormLimit)
	{
		while (TempVar.length > 0 && count < 30)
		{
			theObj = eval("document.all(\"add" + count + "\")");
			theObj.innerHTML = "<Textarea rows=1 cols=1 name='Mdec_RichEdit_Html" + count + "'></Textarea>";

			theObj = eval("f1.Mdec_RichEdit_Html" + count);
			theObj.value = TempVar.substr(0, FormLimit);

			TempVar = TempVar.substr(FormLimit);

			count++;
		}
	}
	else
	{
		theObj = eval("document.all(\"add20\")");
		theObj.innerHTML = "<Textarea rows=1 cols=1 name='Mdec_RichEdit_Html20'></Textarea>";

		theObj = eval("f1.Mdec_RichEdit_Html20");
		theObj.value = TempVar;
	}
}

function sec_onchange(){

	theObj = eval("document.all(\"cert_check\")");

	if (f1.EasyMail_CertServer.value == 0)
	{
		theObj.innerHTML = "";
		f1.needCheckCertPassword.value = "0";
	}
	else if (f1.EasyMail_CertServer.value == 1)
		theObj.innerHTML = "&nbsp;<a href='javascript:checkcanenc()'>验证是否可以向接收者发送加密邮件</a>";
	else if (f1.EasyMail_CertServer.value == 2)
		theObj.innerHTML = "";
}

function checkcanenc(){
	if (f1.EasyMail_To.value != "" || f1.EasyMail_Cc.value != "" || f1.EasyMail_Bcc.value != "")
	{
		f1.action = "checkcanenc.asp";
		f1.target = "_block";
		f1.submit();

		f1.action = "sendmail.asp";
		f1.target = "_parent";
	}
}


function check_sendto_number() {
	var all_sendto_num = 0;

	if (f1.EasyMail_To.value != "")
		all_sendto_num = all_sendto_num + get_char_number(f1.EasyMail_To.value, ",") + 1;

	if (f1.EasyMail_Cc.value != "")
		all_sendto_num = all_sendto_num + get_char_number(f1.EasyMail_Cc.value, ",") + 1;

	if (f1.EasyMail_Bcc.value != "")
		all_sendto_num = all_sendto_num + get_char_number(f1.EasyMail_Bcc.value, ",") + 1;

	if (50 < all_sendto_num)
		return false;

	return true;
}

function get_char_number(showstr, schar) {
	var sindex = 0;
	var retval = 0;

	while(1)
	{
		sindex = showstr.indexOf(schar, sindex);

		if (sindex == -1)
			break;

		retval++;
		sindex++;
	}

	return retval;
}