if(typeof HTMLElement!='undefined' && !HTMLElement.insertAdjacentElement)
{
     HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
     {
        switch (where)
        {
            case 'beforeBegin':
                this.parentNode.insertBefore(parsedNode,this)
                break;
            case 'afterBegin':
                this.insertBefore(parsedNode,this.firstChild);
                break;
            case 'beforeEnd':
                this.appendChild(parsedNode);
                break;
            case 'afterEnd':
                if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
                    else this.parentNode.appendChild(parsedNode);
                break;
         }
     }
}
if(typeof HTMLElement!='undefined' && !HTMLElement.insertAdjacentHTML)
{
     HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr)
     {
         var r = this.ownerDocument.createRange();
         r.setStartBefore(this);
         var parsedHTML = r.createContextualFragment(htmlStr);
         this.insertAdjacentElement(where,parsedHTML)
     }
}
if(typeof HTMLElement!='undefined' && !HTMLElement.insertAdjacentText)
{
     HTMLElement.prototype.insertAdjacentText = function (where,txtStr)
     {
         var parsedText = document.createTextNode(txtStr)
         this.insertAdjacentElement(where,parsedText)
     }
}
function  alertInfo(paramstr,info)
{
	var win=window, wins = new Array();
	wins[0]=window;
	while(win!=win.parent){win=win.parent; if(win.alertInfo)wins.push(win)}
	if(wins.length>1){return wins[wins.length-1].alertInfo(paramstr,info)}
	if(typeof info=="undefined")var info=paramstr;
    else if(paramstr!=null){
        paramstr.style.border= "1px solid red";
		if(typeof info=="string"){
			info = ({"content":info,"OK":(function(){try{paramstr.focus()}catch(e){}})});
		}
    }
    tipDialog.alert(info);
	return false;
}
function alertCode(codes)
{
	alertInfo(codes);
	return false;
}
function verifyempty(param,info)
{
    var paramstr=document.getElementById(param);
    if(paramstr.value=="")
    {
       alertInfo(paramstr,info);
	   return false;
    }
    return true;
}
function verifyLent(param,info)
{
    var paramstr=document.getElementById(param);
    if(paramstr.value.length>40)
    {
        alertInfo(paramstr,info);
        return false;
    }
    return true;
}
function verifymail(param,info)
{
    var paramstr=document.getElementById(param);
    if(!/\w+@\w+(\.\w+)+/ig.test(paramstr.value))
    {
        return alertInfo(paramstr,info);
    }
    return true;
}
function clearstyle(param)
{
    document.getElementById(param).style.border="1px solid #ccc";
}
String.prototype.trim=function()
{
    return this.replace(/^\s+|\s+$/g, '');
}
function validatemail(form_to,info)
{
	function trim(s){return s;}
	var txtstr=document.getElementById(form_to);
	var s0 = txtstr.value;
	if(s0.indexOf('；')>=0)s0 = txtstr.value = s0.replace(/；/g,';');
	var s = trim(s0);
	s = s.replace(/\"[^\"]*\"/g,'""');
	s = s.replace(/\s*([\'\"\,\;<>])\s*/g,'$1'); //清理引号两边、大小于号两边的空白
	var rgx = /^((?:\"\"|[^\"<>]*)?<([^<>]+)>|([^\,\;]+))(?:[\,\;]|$)/;   //一个段(被逗号分号分隔而成的段之一)
	var rgx_eml = /^\w[\w\-\.]*\@[\w\-\.]+$/; //纯粹的email
	var rgx_errdomain = /^[\-\.]|[\-\.]{2,}|[\-\.]$/; //无效的email后缀
	var tmp,tmp2,re=true;
	while(s){
		tmp = s.replace(rgx,"");
		if(tmp==s){ re=false; break;}
		else{
			s = tmp;
			tmp2=RegExp.$2+RegExp.$3;
			if(!rgx_eml.test(tmp2)){ re=false; break;}
			tmp2=tmp2.split("@")[1];
			if(rgx_errdomain.test(tmp2)){ re=false; break;}
		}
	}
	if(!re)alertInfo(txtstr,info);
	return re;
}
function verifycontain(param,info)
{
		var str=document.getElementById(param);
        var pattern=/^[\w\-]+(\.[\w\-]+)+$/;
		if(!pattern.test(str.value)){
			return alertInfo(str,info);
		}
		return true;
}
function checkfilter()
      {
          var $=function(id)
          {
               return document.getElementById(id);
          };
          var arr = ["send","receive","content","size","subject","mail"];
          for(var m in arr)
          {
              clearstyle("filter_"+arr[m]);
          }
          for(var s in arr)
          {
              if($(arr[s]).checked )
              {
                  if(!check("filter_"+arr[s]))
                      return false;
              }
          };
          function check(id)
          {
              if(id=="filter_mail")
                   if(!/\w+@\w+(\.\w+)+/ig.test($("filter_mail").value))
                       return alertInfo($(id),__("please input the mail for format",lang));
               if($(id).value=="")
                   return alertInfo($(id),__("The filter content can not be blank.",lang));
              if(id=="filter_size")
              {
                   if(isNaN($(id).value))
                      return  alertInfo($(id),__("Attachment size must be number.",lang));
                   if($(id).value<0)
                      return  alertInfo($(id),__("Please enter the correct value.",lang));
              }
                  return true;
          };
      }
function checkpwd()
{
          var $=function(id){return document.getElementById(id)};
          var arr = ["oldpassword","newpassword","confirmpassword"];
          clearpwd();
          for(var a in arr)
          {
              if($(arr[a]).value=="")
                  return alertInfo($(arr[a]),__("Password can not be empty.",lang));
          }
          if($("newpassword").value!=$("confirmpassword").value){
              return alertInfo($("confirmpassword"),__("Please make sure you put in the same password."));
          }
          return true;
}
function clearpwd()
{
    document.getElementById("oldpassword").style.border="";
    document.getElementById("newpassword").style.border="";
    document.getElementById("confirmpassword").style.border="";
}
