﻿//取得字符串的字节长度
function strlen(str)
{
    var i;
    var len;
    len = 0;
    for (i=0;i<str.length;i++){if(str.charCodeAt(i)>255){len+=2;}else{len++;}}
    return len;
}

// 用正则表达式将前后空格  
// 用空字符串替代。  
function LikeTrim(str){return str.replace(/(^\s*)|(\s*$)/g, "");}

function SetTimeToURL(NewUrl,TimeSec){setTimeout('location = "'+ NewUrl +'"',TimeSec);}

function MakeWindowLocation(Key,Value)
{
    var url = window.location.toString();
    var Index = url.indexOf('?');
    if(Index>-1)
    {
        var temp = url.substring(Index+1,url.length);
        var tempArray = temp.split('&');
        if(temp.indexOf(Key)>-1)
        {
            var url_temp = url.substring(0,Index);
            for(var i=0;i<tempArray.length;i++)
            {
                url_temp+=i==0?"?":"&";
                if(tempArray[i].indexOf(Key)>-1){url_temp+=Key+"="+Value;}
                else{url_temp+=tempArray[i];}
            }
            window.location=url_temp;
        }
        else{window.location=url+"&"+Key+"="+Value;return;}
    }
    else{window.location=url+"?"+Key+"="+Value;}
}