﻿// JScript 文件
Request = {
    QueryString : function(item){
    var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
    return svalue ? svalue[1] : svalue;
    }
}
//Request.QueryString("y1")

String.prototype.replaceQueryString = function (queryStringName, newValue)
{
	var regx = new RegExp("(\\&|\\?)" + queryStringName + "=([^\\&]+)","ig");
    regx.exec(this);

	if(regx.lastIndex > 0)
	{
	    return this.replace(regx, "$1" + queryStringName + "=" + newValue); 
	} 
	else
	{
	    return this + (this.indexOf("?") > -1 ? "&" : "?") + queryStringName + "=" + newValue;
	}
	return this + "&" + queryStringName + "=" + newValue;
}

String.prototype.trimQueryString = function (queryStringName)
{
	var regx1 = new RegExp("\\&" + queryStringName + "=([^\\&]+)","ig");
	var regx2 = new RegExp("\\?" + queryStringName + "=([^\\&]+)\\&","ig");
	var regx3 = new RegExp("\\?" + queryStringName + "=([^\\&]+)","ig");
	return this.replace(regx1, "").replace(regx2, "?").replace(regx3, "");
}
