﻿// JavaScript Document
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//#表单检查<input type="submit" onClick="MM_validateForm('News_Title','新闻标题','R');return document.MM_returnValue" value="添加">
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++元件name++++元件名称++类型+
//类型：R:不能为空;isEmail:电子邮件;RisNum:不能为空的数字;NisNum:可以为空的数字;RisUer不得少于4个字符
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments,issetfoc=-1;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm="["+args[i+1]+"]"; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)){ 
		errors+='  '+nm+' 必需是一个合法的电子邮件地址。\n';
		if (issetfoc==-1||issetfoc>i) issetfoc=i;
		}
      } else if (test=='RisNum') { num = parseFloat(val);
        if (isNaN(val)){ 
		errors+='  '+nm+' 必需是一个数字。\n';
		if (issetfoc==-1||issetfoc>i) issetfoc=i;
		}
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) {
			  errors+='  '+nm+' 必需是在 '+min+' 和 '+max+' 之间。\n';
			  if (issetfoc==-1||issetfoc>i) issetfoc=i;
			  }
    } }else if (test=='RisUer'&&val.length<4) {
		errors += '  '+nm+' 不得少于4个字符。\n';
		 if (issetfoc==-1||issetfoc>i) issetfoc=i;
		}
	} else if (test.charAt(0) == 'R') {
		errors += '  '+nm+' 不能为空。\n';
		if (issetfoc==-1||issetfoc>i) issetfoc=i;
		}
	}
  } 
  if (errors) {
	 if (issetfoc>-1) document.getElementById(args[issetfoc]).focus();
	  alert('注意:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}
