var all="all";

/**
* 获得对象所在的表单对象
*/
function getForm(formName){
  if(formName==null){
    var objEvent = window.event.srcElement;
    var objParent = objEvent.parentElement;
    while (objParent!=null){
      if(objParent.tagName=="FORM"){
        break;
      }
      objParent=objParent.parentElement;
    }
    if(objParent!=null&&objParent.tagName=="FORM"){
      return objParent;
    }
    else{
      var e = new Error("没有找到表单对象");
      throw e;
    }
  }
  else{
    var objForm= document.forms[formName];
    if(objForm!=null){
      return objForm;
    }
    else{
      var e = new Error("没有找到表单对象");
      throw e;
    }
  }
}

/**
* 获得表单中的对象
* 调用getForm()
*/  
function getFormElement(name){
  var oForm=getForm();
  return oForm.elements(name);
}

/**
 * 获得单元格对象
 * oRows行对象
 * id单元格的id名字
 * 姜敏
 */
function getCell(oRows, id){
   var oCells=oRows.cells;
   var oCell=null;
   for(var i=0;i<oCells.length;i++){
     oCell = oCells[i];
     if(oCell.id==id){
       break;
     }
   }
   return oCell;
}

/**
 * 获得对象数组
 * name:对象数组的名字
 * oWindow:window对象
 * Banglu
 */
function getObjects(name, oWindow){
  var objs
  if(oWindow==null){
    objs = window.document.getElementsByName(name);
  }
  else{
    objs = oWindow.document.getElementsByName(name);
  }
  return objs;
}

/**
* 获得对象
* id:对象的id
* oWindow:window对象
* Banglu
*/
function getObject(id, oWindow){
  var obj;
  if(oWindow==null){
    obj = window.document.getElementById(id);
  }
  else{
    obj = oWindow.document.getElementById(id);
  }
  return obj;
}

/**
 * 触发动作的对象必须是inupt,button等
 * 提交按钮所在的表单
 * url:表单要提交的动作(可选)
 * Banglu
 */
function postForm(formName, url){
  var oForm = getForm(formName);
    oForm.target ='_self';
  if(url!=null){
    oForm.action = url;
  }
  oForm.submit();
}

/**
 * 触发动作的对象必须是inupt,button等
 * 提交按钮所在的表单到空白窗口
 * url:表单要提交的动作(可选)
 * Banglu
 */
function postFormBlank(url){
  var obj = window.event.srcElement;
  var oForm = obj.form;
  oForm.target ='_blank';
  if(url!=null){
    oForm.action = url;
  }
  oForm.submit();
}

/**
 * 触发动作的对象必须是inupt,button等
 * 提交按钮所在的表单到新开无工具栏窗口,用于打印窗口
 * formName:要提交的表单名(可选)
 * Banglu
 */
function postFormPrint(formName, url){
  var oForm = getForm(formName);
  var sFeatures = "toolbar=no, menubar=no, scrollbars=no,resizable=yes, "
                + "location=no, status=no,titlebar=no";
  var name='notoolbar'+randomNum();
  window.open('about:blank',name,sFeatures);
  oForm.target = name;
  if(url!=null) {
    oForm.action = url;
  }
  oForm.submit();
}


function postFormBlank(formName, url){
  var oForm = getForm(formName);
  var sFeatures = "toolbar=no, menubar=no, scrollbars=no,resizable=yes, "
                + "location=no, status=no,titlebar=no,width=560, height=350,top=200,left=250";
  var name='notoolbar'+randomNum();
  window.open('about:blank',name,sFeatures);
  oForm.target = name;
  if(url!=null) {
    oForm.action = url;
  }
  oForm.submit();
}
/**
 * 触发动作的对象必须是inupt,button等
 * 按回车提交表单
 * formName:要提交的表单名称(可选)
 * Banglu
 */
function enterPostForm(url){
  var ieKey = window.event.keyCode;
  var obj = window.event.srcElement;
  var oForm = obj.form;
  if(ieKey==13) {
    oForm.target ='_self';
    if(url!=null){
      oForm.action = url;
    }
    oForm.submit();
  }
}


/**
* 触发动作的对象必须是inupt,button等
* 清除表单上的非隐藏域输入框的值
* Banglu
*/
function clearForm(thisForm,param){
    var obj = document.all(thisForm);
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "text" || obj[i].type == "password" || obj[i].type == "textarea") {
			obj[i].value="";
		} 
		if( obj[i].type == "hidden"){
          if(param=='all'){
           obj[i].value="";
          }
        }
		if (obj[i].type == "select-one") {
				obj[i].options[0].selected=true;
			}
	    if (obj[i].type == "radio"||obj[i].type == "checkbox") {
				obj[i].checked=false;
			}
		}
	}


/**
* 显示和隐藏对象
* IDName:对象ID
* status:根据状态来显示和隐藏(可选)
* 姜敏
*/
function openOrCloseID(IDName, status){
  try{
   var obj=getObject(IDName);
   if(status!=null){
     obj.style.display=(status==true)?"block":"none";
   }
   else{
     obj.style.display=(obj.style.display == "none")?"block": "none";
   }
  }
  catch(e){
  }
}

/**
* 复选框的状态选择(全/不选,)
*/
function selectAll(thisObj, checkboxname) {
	var obj = getObjects(checkboxname);
	var n = obj.length;
	if (thisObj==null || thisObj.checked == true) {
		for (var i = 0; i < n; i++) {
			obj[i].checked = true;
		}
	} else {
		for (var i = 0; i < n; i++) {
			obj[i].checked = false;
		}
	}
}

/**
* 使按钮变成不可编辑状态  
* btns:按钮ID数组
*/
 function lockButton(btns){
   if(btns==null)return;
   
  for(var i=0;i<btns.length;i++){
  var btn=getObject(btns[i]);
  btn.style.disabled="disabled";
  }
 }

/**
* 使页面上所有控件变成不可编辑状态
* Banglu
*/
 function lockAll() {
	var obj=document.all;
	  var len=obj.length;
	 for(var i=0;i<len;i++){
	  obj[i].disabled="disabled";
	  }
}
/**
* 使页面上所有控件变成可编辑状态
* Banglu
*/
 function unLockAll() {
	var obj=document.all;
	  var len=obj.length;
	 for(var i=0;i<len;i++){
	  obj[i].disabled="";
	  }
}
/**
* 通过控件ID使变成不可编辑状态
* Banglu
*/
function setDisable(id){

 var obj=getObject(id);
 if(obj.disabled=true){
 	 obj.disabled=false;
	 }else{
	 	 obj.disabled=true;
	 }
}


/**
 * 通过表单名字获得要提交的数据
 * @param {Object} thisForm
 */
function getParameter(thisForm) {
	var obj = document.all(thisForm);
	var action = document.getElementById(thisForm).action;
	var url = action + "?";
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].type == "text" 
		        || obj[i].type == "password" 
		        || obj[i].type == "textarea" 
		        || obj[i].type == "hidden" 
		        || obj[i].type == "select-one") {
			url += obj[i].name + "=" + obj[i].value + "&";
		} else {
			if ((obj[i].type == "radio" || obj[i].type == "checkbox") 
			                            && obj[i].checked == true) {
				url += obj[i].name + "=" + obj[i].value + "&";
			}
		}
	}
	return url;
}
