//Author 王文涛
//Createdate 05-12-22
//Updatedate 07-4-11

//图片缩放
function DrawImage(ImgD,w,h){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= w/h){
if(image.width>w){
ImgD.width=w;
ImgD.height=(image.height*w)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>h){
ImgD.height=h;
ImgD.width=(image.width*h)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
//ImgD.alt=image.width+"×"+image.height;
}
}
}


//异步数据处理
//url 地址 eid 页面元素ID obj 参数
function GetAsynData(url,obj,eid) {
    if (obj == null) obj = '';
    var Bao = createXMLHttpRequest();
    Bao.onreadystatechange = function(){getready(eid,Bao)};
    Bao.open("POST",url,true);
    Bao.send(obj);
}


//同步从远程URL中读出所需数据
function GetAjaxData(url,obj) {
    if (obj == null) obj = '';
    var Bao = createXMLHttpRequest();
    Bao.open("POST",url,false);
    Bao.send(obj);
    return Bao.responseText;
}

//返回XMLHttp对像
function createXMLHttpRequest()
{
   var xmlHttpRequest=null;
   if(window.ActiveXObject)
   {
    try {
              xmlHttpRequest = new ActiveXObject("Msxml3.XMLHTTP");
        }catch (e) {
    try {
                 xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
   try {
                xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (e) {}}}
  }
  else if(window.XMLHttpRequest)
  {
          xmlHttpRequest=new XMLHttpRequest();
          if (xmlHttpRequest.overrideMimeType)
                  xmlHttpRequest.overrideMimeType('text/xml');
  }
  return xmlHttpRequest
}

//数据状态显示
function getready(AjaxElementID,obj)
{
        if(obj.readystate<4)
        {
            document.getElementById(AjaxElementID).innerHTML="数据传送中...";
        }
     else if(obj.readystate==4)
     {
          if(obj.status==200)
          {
             document.getElementById(AjaxElementID).innerHTML=obj.responseText;
          }
          else
          {
            document.getElementById(AjaxElementID).innerHTML="抱歉，数据处理失败。";
          }
     }
    
}


//其它通用方法

//请求url参数
function Request(sArgName) 
{ 
    var sHref=window.location.href;
    var args = sHref.split("?"); 
    var retval = ""; 

    if(args[0] == sHref) /*参数为空*/ 
    { 
        return retval; /*无需做任何处理*/ 
    } 
    var str = args[1]; 
    args = str.split("&"); 
    for(var i = 0; i < args.length; i ++) 
    { 
        str = args[i]; 
        var arg = str.split("="); 
        if(arg.length <= 1) continue; 
        if(arg[0] == sArgName) retval = arg[1]; 
    } 
    return retval; 
}

//显示对话框
function ShowDialog(url,width,height)
{
    window.showModalDialog(url,'','dialogWidth='+width+'px;dialogHeight='+height+'px;help=no;resizable=yes;status=no;scroll=yes;');
}