﻿// JavaScript 文件

/************ ExpandFunction 扩展方法 对JavaScript方法的扩展 **************/

/***************************************************************************

名称：trim()
作者：wdfch
时间：2010-05-14 10:05
描述：删除字符串前后的空格

***************************************************************************/
String.prototype.trim = function()
{
    var reExtraSpace = /^\s*(.*?)\s+$/;
    return this.replace(reExtraSpace,"$1");
}

/***************************************************************************

名称：UrlEncode()
作者：wdfch
时间：2010-10-18 15:00
描述：URL编码

***************************************************************************/
String.prototype.UrlEncode = function(){ 
var zipstr=""; 
var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
var tt= ""; 
for(var i=0;i<this.length;i++){ 
var chr = this.charAt(i); 
var c=chr.StringToAscii(); 
tt += chr+":"+c+"n"; 
if(parseInt("0x"+c) > 0x7f){ 
zipstr+=encodeURI(this.substr(i,1)); 
}else{ 
if(chr==" ") 
zipstr+="+"; 
else if(strSpecial.indexOf(chr)!=-1) 
zipstr+="%"+c.toString(16); 
else 
zipstr+=chr; 
} 
} 
return zipstr; 
}

/***************************************************************************

名称：UrlDecode()
作者：wdfch
时间：2010-10-18 15:00
描述：URL解码

***************************************************************************/
String.prototype.UrlDecode=function(){ 
var uzipStr=""; 
for(var i=0;i<this.length;i++){ 
var chr = this.charAt(i); 
if(chr == "+"){ 
uzipStr+=" "; 
}else if(chr=="%"){ 
var asc = this.substring(i+1,i+3); 
if(parseInt("0x"+asc)>0x7f){ 
uzipStr+=decodeURI("%"+asc.toString()+this.substring(i+3,i+9).toString()); ; 
i+=8; 
}else{ 
uzipStr+=String.fromCharCode(parseInt("0x"+asc)); 
i+=2; 
} 
}else{ 
uzipStr+= chr; 
} 
} 
return uzipStr; 
}
/***************************************************************************

名称：StringToAscii()
作者：wdfch
时间：2010-10-18 15:00
描述：String To Ascii

***************************************************************************/
String.prototype.StringToAscii=function(){ 
return this.charCodeAt(0).toString(16); 
}
/***************************************************************************

名称：AsciiToString()
作者：wdfch
时间：2010-10-18 15:00
描述：Ascii To String

***************************************************************************/
String.prototype.AsciiToString = function(){ 
return String.fromCharCode(this); 
}
/***************************************************************************

名称：DrawImage()
作者：wdfch
时间：2010-10-18 15:00
描述：图片大小调整

***************************************************************************/
function DrawImage(ImgD,FitWidth,FitHeight)
{ 
    var image=new Image(); 
    //FitWidth      图片要显示的宽 
    //FitHeight     图片要显示的高 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0)
    { 
        if(image.width/image.height>= FitWidth/FitHeight)
        { 
            if(image.width>FitWidth)
            { 
                ImgD.width=FitWidth; 
                ImgD.height=(image.height*FitWidth)/image.width; 
            } 
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
            //ImgD.alt="原图片大小("+image.width+"×"+image.height+")"; 
        } 
        else
        { 
            if(image.height>FitHeight)
            { 
                ImgD.height=FitHeight; 
                ImgD.width=(image.width*FitHeight)/image.height; 
            } 
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
            //ImgD.alt="原图片大小("+image.width+"×"+image.height+")"; 
        } 
    } 
    
    //var h_2=(FitHeight-ImgD.height)/2;
    //ImgD.style.marginTop=h_2+"px";
}
