﻿// JScript 文件
String.prototype.Trim = function() 
{ 
   return   this.replace(/^\s+|\s+$/g,"");
} 


 function ShowImg(src)
{
    alert(src);
    document.getElementById("imgDiv").innerHTML="图片预览：<br><img id='imgObj' onerror='javascript:GetError()' onload='javascript:GetSize()' src='" + src + "'>";
}
function GetSize()
{
    var width,height;
    var imgObj=document.getElementById("imgObj");
    width=imgObj.width;
    height=imgObj.height;
    document.getElementById("err_msg").innerHTML="图片大小(宽×高):<font color=red>" + width + "×" + height + "</font>";
    if(width>164)
    {
        imgObj.width=164;
        imgObj.height=imgObj.height/(imgObj.width/164);
    }
}
function GetError()
{
    document.getElementById("err_msg").innerHTML="图片大小(宽×高):<font color=red>NaN</font>"; 
    document.getElementById("imgDiv").innerHTML="";
    document.getElementById("err_msg").innerHTML="图片文件不存在或格式错误！"
} 

function ShowImage(path){
 //处理前是原图，先将其隐藏，
 document.all.divShow.style.visibility = "hidden";
document.all.divShow.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = path;
//过一小会获取div的宽高.
setTimeout("setImg(document.all.divShow)",100);
}
function setImg(o)
{
	var width_img;
	var height_img;

	o.style.visibility = "visible";
	width_img=o.offsetWidth;
	height_img=o.offsetHeight;

	var width=274;   //预定义宽
	var height=100;  //预定义高


	var ratW;        //宽的缩小比例
	var ratH;        //高的缩小比例
	var rat;         //实际使用的缩小比例
	if(width_img<width && height_img<height)
	{
	    //如果比预定义的宽高小，原图显示。
	    o.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";
	    return;

	    
	}else{
	    //如果大的化，要把 sizingMethod改成scale 如果属性是image,不管怎么改div的宽高，都不起作用
	    o.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale";

	}
	ratH=height/height_img;
	ratW=width/width_img;
	if(ratH<ratW)       //选择最小的作为实际的缩小比例
	    rat=ratH;
	else
	    rat=ratW;
	    
	width_img=width_img * rat;
	height_img=height_img * rat;
	o.style.width=width_img;
	o.style.height=height_img;
}
//用于检查输入框输入内容的长度，一个汉字作2位，其它作1位
function checkStrLength(filedValue,intMaxLength)
{ 
	var strValue = String(filedValue);
	var SingleByteMaxValue = 0x007F;
	var TempA=0;
	var TempB=0;
	
	for (var intNums = 0; intNums < strValue.length; intNums++) 
	{
		var strEach = strValue.charCodeAt(intNums);
			if (strEach > SingleByteMaxValue)
			{
				TempA++;
			}
			else
			{
				TempB++;
			}
	}  
	var StrLength=TempA*2+TempB;
	if (StrLength > intMaxLength) 
	{
		return false;    
	}
	else
	{ 
		return true;
	}
}


function CheckInput(obj)
{
    //检查问题描述是否为空
    if (obj.value.Trim()=="")
   {
    alert("请输入问题描述!");
    return false; 
   } 
   //检查问题描述的长度
    if (checkStrLength(obj.value.Trim(),1000)==false)
   {
        alert("问题描述不应超过1000个字符");
        obj.focus();
        return false;
   } 
}
   function CheckCondition(objName1,objName2,ReportTime,Keywords)
   {  
        var obj1 = document.getElementsByName(objName1)[0];
        var obj2 = document.getElementsByName(objName2)[0];
        
        var hidReportTime = document.getElementsByName(ReportTime)[0];
        var hidKeywords = document.getElementsByName(Keywords)[0];
        if (obj1.value.Trim()=="" && (obj2.value.Trim()=="关键字" || obj2.value.Trim()==""))
        {
             alert("请输入查询条件"); 
           if (obj1.value.Trim()=="") 
           {
             obj1.focus();            
           } 
           else if (obj2.value.Trim()=="关键字" || obj2.value.Trim()=="")
           {
                obj2.focus();
           }
                    
           return false;
           
        }
        else
        {
            hidReportTime.value = obj1.value;
            hidKeywords.value = obj2.value;
            return true;
        }
        
   }

 function CheckValidate_Search(objName)
{
    var txtKeywords = document.getElementsByName(objName)[0];
   
    if (txtKeywords.value.Trim()=="")
   {
        alert("请输入关键字");
        txtKeywords.focus();
       return false; 
   }  
}
function keyup(btnSearchName,txtKeyword)
{
    var btnSearchName = document.getElementsByName(btnSearchName)[0];
     var txtKeyword = document.getElementsByName(txtKeyword)[0];
    if (event.keyCode == 13)
    {
         if (txtKeyword.value.Trim()=="")
       {
            alert("请输入关键字");
            txtKeyword.focus();
           return false; 
       }
        btnSearchName.focus(); 
    }  
}
    function doZoom(size) 
    {
        document.getElementById('zoom').style.fontSize=size+'px';
    }
    function doPrint() 
    { 
      bdhtml=window.document.body.innerHTML; 
      sprnstr="<!--startprint-->"; 
      eprnstr="<!--endprint-->"; 
      prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
    //  window.open("_blank");
      prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
      window.document.body.innerHTML=prnhtml; 
      window.print(); 
      window.document.body.innerHTML = bdhtml;
    }  
        function GoTo(obj)
    {
        var value = obj.value;
        if (value!="")
       {
            window.open(value);
       } 
    }
  function addfavorite()
    {     
     var title=document.title
    var url=document.location.href
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if( window.opera && window.print ){
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();}
    else if( document.all ) window.external.AddFavorite( url, title);

      
    }