//window.attachEvent('onload',initDefValue);

function tips(){
	alert("Please Login.");
	}
function initDefValue(){
      for(i=0;i<document.forms.length;i++){
      		resetFormElement(document.forms[i]);
            }
      }
function samePwd(p1,p2){
	if(p1.value!=p2.value){
		alert("Password Error");
		p2.focus();
		return false;
	}
		return true;
}

function onlyDigit()
{
  if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
         || (window.event.keyCode == 13) || (window.event.keyCode == 46)
         || (window.event.keyCode == 45)))
  {
    window.event.keyCode = 0 ;
  }
}



function trim(inputString) {
  var retValue = inputString;
  var ch = retValue.substring(0, 1);
  while (ch == " ") {
    retValue = retValue.substring(1, retValue.length);
    ch = retValue.substring(0, 1);
  }
  ch = retValue.substring(retValue.length-1, retValue.length);
  while (ch == " ") {
    retValue = retValue.substring(0, retValue.length-1);
    ch = retValue.substring(retValue.length-1, retValue.length);
  }
  while (retValue.indexOf("  ") != -1) {
    retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
  }
  return retValue;
}

function checkForm(check_form_etem)
  {
	  if(check_form_etem!=null&&check_form_etem.tagName=='FORM')
	  {
		 for(var i=0;i<check_form_etem.length;i++)
		  {
			  var temp_boolean=true;
			  var temp_comp=check_form_etem.elements[i];
			  var temp_type= temp_comp.type;
			  if(temp_comp!=null&&temp_comp.msg!=null)
			  {
                if(temp_type=='textarea'||temp_type=='text' || temp_type=='file'||temp_type=='password')
                 {
                   temp_boolean=temp_boolean && trim(temp_comp.value)!='';
                   //жǷisemail
                   if(temp_boolean && temp_comp.isemail!=null){
                     		temp_boolean = temp_boolean && ValidataEmail(temp_comp.value);
                   }
				   //жǷisdigit
                   if(temp_boolean && temp_comp.isdigit!=null){
							temp_boolean = temp_boolean && parseInt(temp_comp.value);
                   }
				   //жǷisfloat
                   if(temp_boolean && temp_comp.isfloat!=null){
							temp_boolean = temp_boolean && parseFloat(temp_comp.value);
                   }
				   
				   //如果有isDigit属性那么只能按数字按键
                	if(temp_comp.isdigit!= null)
					{
					temp_comp.onkeypress = function (e){
						onlyDigit();
                      };
					}
                    /*temp_comp.onchange = function (e){
                      if (!e) e = event;
                      var t = e.target ? e.target : e.srcElement;
                      t.value=formatNum(t.value,0);
                      };*/
				 }
				 if(temp_type=='select-one')
				 {
					temp_boolean=temp_boolean && temp_comp.value!='0' && temp_comp.value!='';
				 }
				 if(!temp_boolean)
				 {
					alert(temp_comp.msg);
					return false;
				 }
			  }
		  }

	  }
	  else
	  {
		alert('javaScript error!');
	  }
	  return true;
  }


function resetFormElement(check_form_etem)
{
   if(check_form_etem!=null&&check_form_etem.tagName=='FORM')
	  {
          var isRunFocus=false;
		  for(var i=0;i<check_form_etem.length;i++)
		  {
			  var temp_boolean=true;
			  var temp_comp=check_form_etem.elements[i];
			  var perElememt = check_form_etem.elements[i-1];
			  var temp_type= temp_comp.type;

			  if( temp_comp.defvalue!=null&&temp_comp.defvalue!=''&&temp_comp.defvalue!='null')
			  {
				 if(temp_type=='file' || temp_type=='hidden' || temp_type=='text' ||temp_type=='textarea'|| temp_type=='password')
				 {
					temp_comp.value = temp_comp.defvalue;
				 }

				 if(temp_type=='select-one')
				 {
                   for(var j=0;j<temp_comp.length;j++)
 				     {
   					     if(trim(temp_comp.options[j].value)==temp_comp.defvalue)
                        {
								temp_comp.selectedIndex=j;
                                //注意要先判断有否even
                                if(temp_comp.needchange!=null && temp_comp.onchange!=null){
									temp_comp.onchange();
                                }
								break;
   	 				    }
  				    }
				 }

				 if(temp_type=='checkbox')
				 {
                   	if(temp_comp.value == temp_comp.defvalue)
                 	{
                       temp_comp.checked=true;
                    }
				 }
                 //-----------
                 if(temp_type=='radio')
				 {
                 	if(temp_comp.value == temp_comp.defvalue)
                 	{
                       temp_comp.checked=true;
                    }
				 }
			  }

              //特别注意设置时间时候以小写的even
              if(temp_type=='file' || temp_type=='hidden' || temp_type=='text' ||temp_type=='textarea'|| temp_type=='password'){
			  	//如果有isDigit属性那么只能按数字按键
                if(temp_comp.isdigit!= null){
					temp_comp.onkeypress = function (e){
						onlyDigit();
                      };
                    /*temp_comp.onchange = function (e){
                      if (!e) e = event;
                      var t = e.target ? e.target : e.srcElement;
                      t.value=formatNum(t.value,0);
                      };*/
              	 }
                 //如果有isFloat属性那么只能按数字按键
				if(temp_comp.isfloat!= null||temp_comp.isFloat!= null){
					temp_comp.onkeypress = function (e){
						onlyDigit();
					};
					temp_comp.onchange = function (e){
						if (!e) e = event;
						var t = e.target ? e.target : e.srcElement;
						t.value=formatNum(t.value,1);
                      };
              	 }
              }

				
              if(temp_type=='checkbox'){
                //如果有select_all_index属性那么只将有全选的功能
                if(temp_comp.select_all_index!=null)
                {
                	temp_comp.onclick = function ()
                	{
                      checkallbox(this);
                      if(this.deletecheck!=null && checkActonFrame()){
                        	top.actionFrame.checkDelectElement();
                      }
	             	};
                }
                //如果有select_all_index属性能检测并设置全选按钮的状态
                if(temp_comp.select_index!=null)
                {
                	temp_comp.onclick = function ()
                	{
                      checkparentbox(this);
                      //添加对删除按钮的显示
                      if(this.deletecheck!=null && checkActonFrame()){
                        	top.actionFrame.checkDelectElement();
                      }
	             	};
                }
              }

	  }
	  }
}


function ValidataEmail(str)
{
	var ret = false;
	if (typeof(str) != "undefined")
	{
		if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(str)){
		ret = true;}
	}
	return ret;
}


function formatNum(expr,decplaces){
  var str = ""+Math.round((expr)*(Math.pow(10,decplaces)));
  if(trim(str).toUpperCase()=="NaN".toUpperCase()||str==null||trim(str)==""){
    return "";
  }else{
    while(str.length<=decplaces){
      str = "0"+str;
    }
    var decpoint = str.length - decplaces;
	if(decplaces==0)
	return str.substring(0,decpoint);
	else
    return str.substring(0,decpoint)+"."+str.substring(decpoint,str.length);
  }
}