﻿function getViewportHeight() 
{
	if (window.innerHeight != window.undefined) return window.innerHeight;
	if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}

function getViewportWidth() 
{
	if (window.innerWidth != window.undefined) return window.innerWidth; 
	if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}



function DrawImage(ImgD, iwidth, iheight)
{ 
     var image = new Image();
     image.src = ImgD.src;
     var w = image.width;
     var h = image.height;

     if(image.width > 0 && image.height > 0)
     { 
         if(image.width/image.height >= iwidth/iheight)
         { 
              if(image.width > iwidth)
              {  
                 ImgD.height = (image.height*iwidth)/image.width; 
                 ImgD.width  = iwidth;  
              }
         } 
         else
         { 
             if(image.height > iheight)
             {   
                ImgD.width  = (image.width*iheight)/image.height;   
                ImgD.height = iheight;  
             } 
          }
          ImgD.style.display = "";
          var loading = ImgD.parentNode.firstChild;
          if(loading && loading.id == "loading")
             loading.style.display = "none";
          //ImgD.alt=ImgD.width+"×"+ImgD.height + " AND " + w+"×"+h;
     }
} 

function $(id)
{
   if( !id )
   {
       throw new Error("$(String id)缺少有效参数")
   }   
   if(document.getElementById)
   {
       return eval('document.getElementById("'+id+'")')
   }
   else if(document.layers)
   {
       return eval("document.layers['"+id+"']")
   }
   else
   {
       return eval('document.all.'+id)
   }
}

String.prototype.getQuery = function(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = this.substr(this.indexOf("\?")+1).match(reg);
	if(r!=null)
	{
		return unescape(r[2]);
	}
	return null;
}
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g,"");
}
String.prototype.Tlength = function()
{
	var arr=this.match(/[^\x00-\xff]/ig);
	return this.length + (arr == null ? 0 : arr.length );
}

function isNull(sVal)
{
	return (sVal == "" || sVal == null || typeof sVal == "undefined");
}

function  queryString() 
{
    var  name,value,i; 
    var  str=location.href;
    var  num=str.indexOf("?") 
    str=str.substr(num+1);
    var  arrtmp=str.split("&"); 
    for(i=0;i  <  arrtmp.length;i++)
    { 
        num=arrtmp[i].indexOf("="); 
        if(num>0)
        { 
            name=arrtmp[i].substring(0,num); 
            value=arrtmp[i].substr(num+1); 
            this[name]=value; 
        } 
    } 
}


function centerPopWin(win, width, height) 
{ 
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
		
		var theBody = document.body;
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		win.MoveTo((scLeft + ((fullWidth - width) / 2)),(scTop + ((fullHeight - height)  / 2)) );
}

function ShowWindow(url, width, height)
{				
	var oWnd = window.radopen(null, "RadWindow");
	oWnd.SetSize(width,height);
	centerPopWin(oWnd, width, height); 
	
	oWnd.SetUrl(url);
	
}


function GetRadWindow()
{
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
		
    return oWindow;
}

function CloseAndRebind()
{
    GetRadWindow().Argument = "Rebind";
    GetRadWindow().Close();
}

function CloseWindow(args)
{
    GetRadWindow().Argument = args;
    GetRadWindow().Close();
}







