﻿// JScript 文件

// auto resize for iframe
function dyniframesize(iframename)
{
  var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
//extra height in px to add to iframe in FireFox 1.0+ browsers
  var FFextraHeight=getFFVersion>=0.1? 16 : 0 
  var pTar = null;
  if (document.getElementById){
    pTar = document.getElementById(iframename);
  }
  else{
    eval('pTar = ' + iframename + ';');
  }
  if (pTar && !window.opera){
    //begin resizing iframe
    pTar.style.display="block"
    
    if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
      //ns6 syntax
      pTar.height = pTar.contentDocument.body.offsetHeight+FFextraHeight; 
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight){
      //ie5+ syntax
      pTar.height = pTar.Document.body.scrollHeight;
    }
  }
}


//判断是内容是否超长，txtContent：要判断的内容；permitLen：允许的最大长度
//超长返回true
function isBeyondLen(txtContent,permitLen)
{
    if(txtContent.length <= permitLen )
        return false;
    return true;
}


//限制用户输入最大长度，须指定控件的 Manlength 属性,使用时传入this
//功能:到达长度不可输入，截断超长粘贴
function ismaxlength(obj)
{
   var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")):"";
   if (obj.getAttribute && obj.value.length>mlength)
   {
       obj.value=obj.value.substring(0,mlength)
   }
}
///用于关闭本身窗口，且返回父窗为true
function CloseWindow()
{
    window.returnValue = true;
    top.close();
}
function Openersub(strUrl)
{
     var vTmd=Math.random();
     var vReturn=false;
     var strFeature = 'dialogWidth:750px;dialogHeight:600px;status:0;scroll:1:0;help:0;';
     if(strUrl.indexOf('?')>-1)
     {
//      vReturn=window.showModalDialog(strUrl+'&tmd='+vTmd,window,strFeature);
        vReturn=window.showModalDialog(strUrl,window,strFeature);
     }
     else
     {
//      vReturn=window.showModalDialog(strUrl+'?tmd='+vTmd,window,strFeature);
        vReturn=window.showModalDialog(strUrl,window,strFeature);
     }   
//       alert("vReturn=" + vReturn);
    return vReturn;
}

function OpenerSubFeature(strUrl,width,height)
{
     var vTmd=Math.random();
     var vReturn=false;
     var strFeature = 'dialogWidth:'+width + 'px;dialogHeight:'+height+'px;status:0;scroll:1:0;help:0;';
     if(strUrl.indexOf('?')>-1)
     {
         vReturn=window.showModalDialog(strUrl+'&tmd='+vTmd,window,strFeature);
     }
     else
     {
         vReturn=window.showModalDialog(strUrl+'?tmd='+vTmd,window,strFeature);
       
     }   
//       alert("vReturn=" + vReturn);
    return vReturn;
}

///新建成功后弹出提示框并作相应处理
function AddContinueConfirm(content)
{
        window.returnValue = true;
     if (! window.confirm(content + "新建成功,是否继续?"))      //不继续增加则刷新列表页及关闭本模式窗口
     {  
        if(typeof(dialogArguments) != "undefined")
        {
        }
        else
        {
            top.parent.location.reload();
        }        
        top.close();
     }
  
}
///新建成功后弹出提示框并作相应处理
///多语言版本

function AddContinueConfirm2(mult_lan_content)
{    
     window.returnValue = true;
     if (! window.confirm(mult_lan_content))      //不继续增加则刷新列表页及关闭本模式窗口
     {  
        if(typeof(dialogArguments) != "undefined")
        {
        }
        else
        {
            top.parent.location.reload();
        }        
        top.close();
     }
  
}

    //GridView 全选功能
    function CheckAll(gridviewID,oCheckbox)
    {
      var gvResult = document.getElementById(gridviewID);
       for(i = 1;i < gvResult.rows.length; i++)
       {
           var obj = gvResult.rows[i].cells[0].getElementsByTagName("INPUT")[0];
           if (obj != null)
           {
               if( !obj.disabled)
               {
                
                obj.checked = oCheckbox.checked;
               }
           }
       }
    }
    
    //清空页面输入的部分内容
    function ClearPart(containID)
    {
        var element = document.getElementById(containID).all;
        for(var i=0;i<element.length;i++)
        {
            if(element[i].type =="checkbox")
                element[i].checked = false;

            if(element[i].type =="text" || element[i].type =="textarea")
                element[i].value = "";
            
            if(element[i].type == "select-one" && element[i].length>0)
                element[i].options[0].selected = "selected";
        }
        event.returnValue=false;
        
    }
    
    //清空页面输入的全部内容
    function Clear()
    {
        var element = document.all;
        for(var i=0;i<element.length;i++)
        {
            if(element[i].type =="checkbox")
                element[i].checked = false;

            if(element[i].type =="text" || element[i].type =="textarea")
                element[i].value = "";
            
            if(element[i].type == "select-one" && element[i].length>0)
                element[i].options[0].selected = "selected";        
        }
       event.returnValue=false;
    }
    //在没有选中记录时,删除操作不可点击
    function ShowCheckConfirm(oCheckBox,gridviewID,deletebutnID,selectedRecordToOpration)
    {
       var gvResult = document.getElementById(gridviewID);
       var btnObj = document.getElementById(deletebutnID);
       if (gvResult == null||btnObj == null)
       {
            return false;
       }
       if(oCheckBox.checked)
       {
            btnObj.disabled = false;
       }
       var flag = false;
       for(i = 1;i < gvResult.rows.length; i++)
       {
            if (gvResult.rows[i].cells[0].getElementsByTagName("INPUT")[0] != null)
            {
                if (gvResult.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked)
                {
                    flag = true;
                    break;
                }
            }            
       }
       if (flag)
       {
            btnObj.disabled = false;
       }
       else
       {
            btnObj.disabled = true;
       }
    }
    //在没有选中记录时的删除操作
    function ShowConfirm(gridviewID,isDelSelectedRecord,selectedRecordToOpration)
    {
       var gvResult = document.getElementById(gridviewID);
       if (gvResult == null)
       {
            return false;
       }
           
       var flag = false;
       for(i = 1;i < gvResult.rows.length; i++)
       {
            if (gvResult.rows[i].cells[0].getElementsByTagName("INPUT")[0] != null)
            {
                if (gvResult.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked)
                {
                    flag = true;
                }
            }            
       }
       
       if (flag)
        {
            //是否删除所选记录?
            return window.confirm(isDelSelectedRecord);
        }
        else
        {
            //请选择至少一条要删除的记录进行操作!
            alert(selectedRecordToOpration);
            return false;
        }
    }
    
    function adv_format(value,num) //四舍五入,第一个参数是待格式化的数值，第二个是保留小数位数
    {
        var a_str = formatnumber(value,num);
        var a_int = parseFloat(a_str);
        if (value.toString().length>a_str.length)
        {
            var b_str = value.toString().substring(a_str.length,a_str.length+1)
            var b_int = parseFloat(b_str);
            if (b_int<5)
            {
             return a_str
            }
            else
            {
                var bonus_str,bonus_int;
            if (num==0)
            {
                bonus_int = 1;
            }
            else
            {
                bonus_str = "0."
                for (var i=1; i<num; i++)
                bonus_str+="0";
                bonus_str+="1";
                bonus_int = parseFloat(bonus_str);
            }
            a_str = formatnumber(a_int + bonus_int, num)
            }
        }
        return a_str
    }
    function formatnumber(value,num) //直接去尾
    {
        var a,b,c,i
        a = value.toString();
        b = a.indexOf('.');
        c = a.length;
        if (num==0)
        {
            if (b!=-1)
                 a = a.substring(0,b);
        }
        else
        {
            if (b==-1)
            {
                a = a + ".";
                for (i=1;i<=num;i++)
                a = a + "0";
            }
            else
            {
                a = a.substring(0,b+num+1);
                for (i=c;i<=b+num;i++)
                a = a + "0";
            }
        }
        return a
     }

    //检查Gridview是否有被选择项
    function CheckSelected(gvName,alertMsg)
    {
        var gv=document.getElementById(gvName);
        var isSelect=false;
        if(gv==null)
        {
            return false;
        }
        for (i=1;i<gv.rows.length;i++)
        {
            if (gv.rows[i].cells[0].getElementsByTagName("INPUT")[0] !=null)
            {
                if (gv.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked==true)
                {
                    isSelect=true;
                }
            }
         }
         
         if (isSelect)
            return true;
         else
         {
            if (alertMsg!="")
            {
                window.alert(alertMsg);
            }
            return false;
         }
    }
        
        
    function ValidateMustFill(objects,msgEnterContent,msgSelectCust)
    {
        //var str = "tt,hh,jj,";
        var objs = objects.split(",");
        
        for(var i=0;i<=objs.length -2;i++)
        {
            var obj = document.getElementsByName(objs[i]);
            var flag = false;
            
            if (obj.length >1)
            {                  
                for(var y=0;y<=obj.length-1;y++)
                {                       
                    if (obj[y].checked)
                    {
                        flag = true
                        break; 
                    }
                }
            }
            else
            {
                obj = document.getElementById(objs[i]);
                if (obj.value != "")
                {
                    flag = true;
                }
            }
            
            if (!flag)
            {
                alert(msgEnterContent);//"请填写必答内容!"
                break;
            }            
        }
        
        if (flag)
        {
            if (top.IFRAME1.reviewHead.window.document.getElementById("txtCustName").value == "")
            {
                alert(msgSelectCust);//"请选择调查客户!"
                top.IFRAME1.reviewHead.window.document.getElementById("ibtnSearch").focus();
                flag = false;
            }
        }
        
        if (flag)
        {
            document.forms[0].submit();
        }
    }
    
    //给多选框，单选框赋值
    function FillDataToItems(objName,objValue,objType)
    {
        try
        {
            if (objType != "Qtext")
            {           
                var obj = document.getElementsByName(objName);
                
                for(y=0;y<=obj.length-1;y++)
                {
                    if (obj[y].value == objValue)
                    {                        
                        obj[y].checked = true;
                    }
                    obj[y].disabled= true;
                }
                
               
            }
            else
            {
                var obj = document.getElementsByName(objName);            
                obj[0].value = objValue;
                obj[0].readOnly=true
            }
         }
         catch(ex)
         {
            
         }   
    }
    
 function textCounter(field,maxlimit)
  {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0,maxlimit);
  }
String.prototype.trim = function()
{
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}
//重新设置DIV对应的宽度和高度为当前ID的父容器的宽度和高度
function SetDivWidth()
{
//    var objID;
//    for(var i=0;i<arguments.length;i++)
//    {
//        objID = arguments[i];
//        if(document.all(objID)!=null&&document.all(objID).style.display!="none")
//        {
//            document.all(objID).style.width="100px";
//            document.all(objID).style.height="10px";
//            document.all(objID).style.width=document.all(objID).parentElement.offsetWidth-5;
//            document.all(objID).style.height=document.all(objID).parentElement.offsetHeight-2;
//        }
//    }
    var objID;
    for(var i=0;i<arguments.length;i++)
    {
        objID = arguments[i];
        var obj = document.all(objID);
        var height = 20;
        if(obj!=null&&obj.style.display!="none")
        {
            try
            {
                obj.style.width="100px";
                obj.style.height="20px";
                obj.style.width=obj.parentElement.offsetWidth-5;
                if(obj.parentElement.id=="result"||obj.parentElement.className=="result")
                {
                    height = document.body.offsetHeight -obj.parentElement.offsetTop-40;
                    if(height<20)
                    {
                        height = 20;
                    }
                 }
                 else
                 {
                    height = obj.parentElement.offsetHeight-2;
                 }
                obj.style.height=height-2;
                obj.parentElement.style.height = height;
                
                
            }
            catch(e)
            {
            }
        }
    }
	
}
//禁止回车提交表单
  function  ifenter()   
  {   
      if(event.keyCode==13)   
      if(event.srcElement.type=="submit")   
      document.forms[0].submit();   
      else   
      return  (event.srcElement.type=="textarea");   
  }
  
  function setEnter()
  {
      document.onkeydown=ifenter;  
  } 
  //多属性下拉框
  execscript=function(obj)
{
    function formatex(st)
    {
        eval(obj.msg);
        return eval(st);
    }
    function getvalue(code)
    {
        var values=formatex("o."+code+"_"+obj.selectedIndex);
        return (values=="undefined"||values==null)?"":values;
    }
    this.getvalue=getvalue
}    
//四舍五入,第一个参数是待格式化的文本框，第二个是保留小数位数
    function AutoFormatNumber(obj,How)
    {
        if(isNaN(obj.value)) return;
        obj.value=Math.round(obj.value*Math.pow(10,How))/Math.pow(10,How);
        if(obj.value.indexOf(".")!=-1)
        {
            var va=obj.value.split('.');
            if(va[1]!=undefined)
            {
                 if(va[1].length<How)
                 {
                    var cnt="";
                    for(var i=0;i<How-va[1].length;i++)
                    {
                        cnt+="0";
                    }
                    va[1]=va[1]+"."+cnt;
                    va[1]=va[1].replace(".","");
                    obj.value=va[0]+"."+va[1];
                 }
             }
         }
         else
         {
            var zero="";
            for(var i=0;i<How;i++)
            {
                zero+="0"
            }
            if(obj.value.replace(" ","")=="")
            {
                obj.value="0."+zero;
            }
            else
            {
                obj.value=obj.value+"."+zero;
             }   
         }
    } 




///////////// 
