function CheckMail(d)
{
  if(d.Account.value=="" || d.Account.value.indexOf("@")==-1 || d.Account.value.indexOf(".")==-1)
   {
    alert("请输入正确的帐号，如user@domain.com");d.Account.focus();return false;
   }
   else if(d.Password.value=="")
   {
    alert("密码不能为空!");d.Password.focus();return false;
   }
   else
  {  
     var AccountArray=d.Account.value.split("@");
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="263")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.u263frm.usr.value=AccountArray[0];
		     document.u263frm.domain.value=AccountArray[1];
		     document.u263frm.pass.value=d.Password.value;
		     document.u263frm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
		     document.m263frm.user.value=d.Account.value;
		     document.m263frm.pswd.value=d.Password.value;
			 document.m263frm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="21cn")
	    {
		   if(d.UserType[0].checked==true)
		   {
		     document.u21cnfrm.UserName.value=d.Account.value;
		     document.u21cnfrm.passwd.value=d.Password.value;
			 document.u21cnfrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
		     document.u21cnfrm.UserName.value=d.Account.value;
		     document.u21cnfrm.passwd.value=d.Password.value;
			 document.u21cnfrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="corpease")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.ucorpeasefrm.user.value=AccountArray[0];
		     document.ucorpeasefrm.domain.value=AccountArray[1];
		     document.ucorpeasefrm.pass.value=d.Password.value;
		     document.ucorpeasefrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
	  	     document.mcorpeasefrm.uid.value=AccountArray[0];
		     document.mcorpeasefrm.domain.value=AccountArray[1];
		     document.mcorpeasefrm.passwd.value=d.Password.value;
			 document.mcorpeasefrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="china")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.uchinafrm.user.value=AccountArray[0];
		     document.uchinafrm.domain.value=AccountArray[1];
		     document.uchinafrm.pass.value=d.Password.value;
		     document.uchinafrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
	  	     document.mchinafrm.uid.value=AccountArray[0];
		     document.mchinafrm.domain.value=AccountArray[1];
		     document.mchinafrm.passwd.value=d.Password.value;
		     document.mchinafrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="tomdx")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.utomdxfrm.user.value=AccountArray[0];
		     document.utomdxfrm.domain.value=AccountArray[1];
		     document.utomdxfrm.pass.value=d.Password.value;
		     document.utomdxfrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
		     document.mtomdxfrm.uid.value=d.Account.value;
		     document.mtomdxfrm.passwd.value=d.Password.value;
			 document.mtomdxfrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="tomwt")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.utomwtfrm.user.value=AccountArray[0];
		     document.utomwtfrm.domain.value=AccountArray[1];
		     document.utomwtfrm.pass.value=d.Password.value;
		     document.utomwtfrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
		     document.mtomwtfrm.uid.value=d.Account.value;
		     document.mtomwtfrm.passwd.value=d.Password.value;
			 document.mtomwtfrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="tomhk")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.utomhkfrm.user.value=AccountArray[0];
		     //document.utomhkfrm.domain.value=AccountArray[1];
		     document.utomhkfrm.pass.value=d.Password.value;
		     document.utomhkfrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
	  	     document.utomhkfrm.user.value=AccountArray[0];
		    //document.utomhkfrm.domain.value=AccountArray[1];
		     document.utomhkfrm.pass.value=d.Password.value;
		     document.utomhkfrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="sina")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.usinafrm.user.value=d.Account.value;
			 usinalogin();
		     document.usinafrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
	  	     document.msinafrm.user.value=AccountArray[0];
		     document.msinafrm.domain.value=AccountArray[1];
		     document.msinafrm.psw.value=d.Password.value;
			 document.msinafrm.submit();
             ClearPass();
		   }
		}
//================
	 if(d.MailType.options[d.MailType.selectedIndex].value=="sohu")
	    {
		   if(d.UserType[0].checked==true)
		   {
	  	     document.usohufrm.id.value=AccountArray[0];
		     document.usohufrm.domain.value=AccountArray[1];
		     document.usohufrm.password.value=d.Password.value;
		     document.usohufrm.submit();
		     ClearPass();
		   }
		   else if(d.UserType[1].checked==true)
		   {
		     document.m263frm.admname.value=AccountArray[1];
		     document.m263frm.passwd.value=d.Password.value;
			 document.m263frm.submit();
             ClearPass();
		   }
		}
//================

  }
}


function ClearPass(){
document.maillogin.Account.value="";
document.maillogin.Password.value="";
}
//=========================
function trim(str)
{
 while(str.charAt(0)==" ") 
 {
  str=str.substr(1);
 }
 while(str.charAt(str.length-1)==" ") 
 {
  str=str.substring(0,str.length-1);
 }
 return str; 
 
}

function usinalogin()
{
	do_sha1();

	var acton_str = new String(document.usinafrm.action);

	var tmp_str1;
	var cur_action_domain;

	var re1 = /\/cgi-bin\/websso\/login.cgi/g;
	var re2 = /http:\/\//g;

	tmp_str1 = acton_str.replace(re1, "");
	cur_action_domain = tmp_str1.replace(re2, "");

	//alert(cur_web_domain);
	var is_sina_domain;
	var search_ptr = /\.sina\.net/i;
	var cur_location = new String(document.location);

	is_sina_domain = cur_location.search(search_ptr);

	if(is_sina_domain == -1)
	{
		//非从sina.net web登录用户
		//直接读取action url数据
		document.usinafrm.outurl.value = cur_location;//login out url
		document.usinafrm.curdomain.value = cur_action_domain;//mail serv
	}
	else
	{
		//从sina web服务器登录
		document.usinafrm.outurl.value = cur_location;
		document.usinafrm.curdomain.value = cur_location;
	}

	//alert(document.loginform.curdomain.value);
	//alert(document.loginform.outurl.value);
}

function wc(name,value){
        var e = new Date ();
        e.setTime (e.getTime() + (365*24*60*60*1000));
        e = e.toGMTString()
        document.cookie=name+"="+value+";path=/;expires="+e+";domain=mail.sina.net;"
        //alert(document.cookie);
}

// convert a 32-bit value to a 8-char hex string
function cvt_hex( val )
{
   var str="";
   var i;
   var v;

   for( i=7; i>=0; i-- )
   {
      v = (val>>>(i*4))&0x0f;
      str += v.toString(16);
   }
   return str;
}

// return a hex value LSB first
function lsb_hex( val )
{
   var str="";
   var i;
   var vh;
   var vl;

   for( i=0; i<=6; i+=2 )
   {
      vh = (val>>>(i*4+4))&0x0f;
      vl = (val>>>(i*4))&0x0f;
      str += vh.toString(16) + vl.toString(16);
   }
   return str;
}

// rotate left circular
function rotate_left( n, s )
{
   var t4 = ( n<<s ) | (n>>>(32-s));
   return t4;
}

// calculate the hash
function do_sha1()
{
   var blockstart;			// which block of words from the dataare we using now?
   var i, j;
   var W = new Array(80);
   // initial constants
   var H0 = 0x67452301;
   var H1 = 0xEFCDAB89;
   var H2 = 0x98BADCFE;
   var H3 = 0x10325476;
   var H4 = 0xC3D2E1F0;
   // working variables
   var A, B, C, D, E;
   var temp;

   // get message to hash
   var msg = document.maillogin.Password.value;

   // note current length
   var msg_len = msg.length;

   // convert to a 32-bit word array
   var word_array = new Array();
   for( i=0; i<msg_len-3; i+=4 )
   {
      // convert 4 bytes to a word
      j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
      word_array.push( j );
   }

   // handle final bits, add beginning of padding: 1 bit, then 0 bits
   switch( msg_len % 4 )
   {
      case 0:
         // text length was a multiple of 4 bytes, start padding
         i = 0x080000000;				// 4 bytes padding
         break;

      case 1:
         // one byte of text left
         i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;	// 3 bytes padding
         break;

      case 2:
         // two bytes of text left
         i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16
		| 0x08000;				// 2 bytes padding
         break;

      case 3:
         // three bytes of text left
         i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16
		| msg.charCodeAt(msg_len-1)<<8	| 0x80;	// 1 byte padding
         break;

      default:
         window.alert("Something went weird in the switch!")
         return;
   }

   // handle the end of the text and beginning of the padding
   word_array.push( i );

   // pad to 448 bits (mod 512 bits) = 14 words (mod 16 words)
   while( (word_array.length % 16) != 14 )
      word_array.push( 0 );

   // add 64-bit message length (in bits)
   word_array.push( msg_len>>>29 );
   word_array.push( (msg_len<<3)&0x0ffffffff );

   // Process each 16-word block.
   for ( blockstart=0; blockstart<word_array.length; blockstart+=16 )
   {
      // create entries in W array
      for( i=0; i<16; i++ )
         W[i] = word_array[blockstart+i];
      for( i=16; i<=79; i++ )
         W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);

      // copy state
      A = H0;
      B = H1;
      C = H2;
      D = H3;
      E = H4;

      // update state variables
      for( i= 0; i<=19; i++ )
      {
         temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;

         // update state
         E = D;
         D = C;
         C = rotate_left(B,30);
         B = A;
         A = temp;
      }

      for( i=20; i<=39; i++ )
      {
         temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;

         // update state
         E = D;
         D = C;
         C = rotate_left(B,30);
         B = A;
         A = temp;
      }

      for( i=40; i<=59; i++ )
      {
         temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;

         // update state
         E = D;
         D = C;
         C = rotate_left(B,30);
         B = A;
         A = temp;
      }

      for( i=60; i<=79; i++ )
      {
        temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6CA62C1D6) & 0x0ffffffff;

         // update state
         E = D;
         D = C;
         C = rotate_left(B,30);
         B = A;
         A = temp;
      }

      H0 = (H0 + A) & 0x0ffffffff;
      H1 = (H1 + B) & 0x0ffffffff;
      H2 = (H2 + C) & 0x0ffffffff;
      H3 = (H3 + D) & 0x0ffffffff;
      H4 = (H4 + E) & 0x0ffffffff;

   } // of loop on i

   // process output
   document.usinafrm.pass.value = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
}
//////////////////////////
function MailLogin(){
document.writeln("<table width=\"605\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"5D5D5D\">");
document.writeln("       <form name=\"maillogin\">");
document.writeln("	    <tr> ");
document.writeln("          <td width=\"10\" valign=\"top\"><img src=\"\/HtmlImages\/top_jiao.gif\" width=\"7\" height=\"7\"><\/td>");
document.writeln("          <td width=\"62\" height=\"25\" valign=\"middle\" class=\"12xpwhite\"> <div align=\"center\"><font color=\"FAFF5D\">企邮登录:<\/font><\/div><\/td>");
document.writeln("          <td width=\"35\" height=\"25\" valign=\"middle\" class=\"12xpwhite\"> <div align=\"center\">帐号<\/div><\/td>");
document.writeln("          <td width=\"64\" height=\"25\" valign=\"middle\"><input name=\"Account\" type=\"text\" class=\"form\" id=\"Account\" size=\"15\"><\/td>");
document.writeln("          <td width=\"29\" height=\"25\" valign=\"middle\" class=\"12xpwhite\"> <div align=\"center\">密码<\/div><\/td>");
document.writeln("          <td width=\"60\" height=\"25\" valign=\"middle\"><input name=\"Password\" type=\"password\" class=\"form\" id=\"Password\" size=\"15\"><\/td>");
document.writeln("          <td width=\"35\" height=\"25\" valign=\"middle\" class=\"12xpwhite\"> <div align=\"center\">品牌<\/div><\/td>");
document.writeln("          <td width=\"55\" height=\"25\" valign=\"middle\"><select name=\"MailType\" id=\"MailType\" style=\" width:65px\">");
document.writeln("            <option value=\"263\" selected>263<\/option>");
document.writeln("            <option value=\"21cn\">21CN<\/option>");
document.writeln("            <option value=\"corpease\">尚易<\/option>");
document.writeln("            <option value=\"china\">中华网<\/option>");
document.writeln("            <option value=\"tomdx\">TOM(电信)<\/option>");
document.writeln("            <option value=\"tomwt\">TOM(网通)<\/option>");
document.writeln("            <option value=\"tomhk\">TOM(香港)<\/option>");
document.writeln("            <option value=\"sina\">新浪<\/option>");
document.writeln("            <option value=\"sohu\">搜狐<\/option>");
document.writeln("          <\/select><\/td>");
document.writeln("          <td width=\"44\" height=\"25\" valign=\"middle\"> <input type=\"submit\" name=\"Submit\" value=\"登录\"  onClick=\"CheckMail(document.maillogin)\"> ");
document.writeln("          <\/td>");
document.writeln("          <td width=\"211\" height=\"25\" valign=\"middle\" class=\"12xpwhite\"> <input name=\"UserType\" type=\"radio\" value=\"User\" checked>");
document.writeln("            普通用户 ");
document.writeln("              <input type=\"radio\" name=\"UserType\" value=\"Admin\">");
document.writeln("            管理员&nbsp;<a href=\"http:\/\/price.globalmail.cn\" class=\"link1\" target=\"_blank\"><font color=\"#FFFF00\">企邮价格<\/font><\/a>          <\/td>");
document.writeln("        <\/tr>");
document.writeln("		<\/form>");
document.writeln("      <\/table>");
}
/////////////////////////////
document.writeln("<style type=\"text\/css\">");
document.writeln("a.KeyLink:link {");
document.writeln("    font-size:14px;");
document.writeln("	color: #000000;");
document.writeln("	text-decoration: none;");
document.writeln("}");
document.writeln("a.KeyLink:visited {");
document.writeln("    font-size:14px;");
document.writeln("	color: #000000;");
document.writeln("	text-decoration: none;");
document.writeln("}");
document.writeln("a.KeyLink:hover {");
document.writeln("    font-size:14px;");
document.writeln("	color: #000000;");
document.writeln("	text-decoration: none;");
document.writeln("}");
document.writeln("a.KeyLink:active {");
document.writeln("    font-size:14px;");
document.writeln("	color: #000000;");
document.writeln("	text-decoration: none;");
document.writeln("}");
document.writeln("<\/style>");
document.writeln("");



