
function $E(id)
{
  return document.getElementById(id);
}


function $S(id)
{
  var obj=document.getElementById(id);
  return obj.item(obj.selectedIndex).value;
}


$P = function(parameter, url)
{
	url = isUndef(url) ? location.href : url;
	var result = url.match(new RegExp("[\#|\?]([^#]*)[\#|\?]?"));
	url = "&" + (isNull(result) ? "" : result[1]);	
	result = url.match(new RegExp("&"+parameter+"=", "i"));
	return isNull(result) ? undefined : url.substr(result.index+1).split("&")[0].split("=")[1];
};

isUndef  = function(a){ return typeof a == "undefined";};
isNull 	 = function(a){ return typeof a == "object" && !a; };

String.prototype.trim = function()
{
	return this.replace(new RegExp("(^[\\s]*)|([\\s]*$)", "g"), "");	
}


function IsNum(obj)
{
    if (!(/^\d+$/.test(obj.value)))
    {
        alert("请输入正确的商品数量！");
        obj.focus();
    }
}


function ConvertUrlToString(str)
{
    return str.replace("/","%");
}


function focus_input(input)
{
	if(!input || input.disabled) return true;
	else {
		input.select();
		return false;
	}
}



function HTMLEncode(text)
{
    if (text==null)
    {
        return "";
    }
    text = text.replace(/&/g, "&amp;") ;
    text = text.replace(/"/g, "&quot;") ;
    text = text.replace(/</g, "&lt;") ;
    text = text.replace(/>/g, "&gt;") ;
    text = text.replace(/\ /g,"&nbsp;");
    text = text.replace(/\n/g,"<br>");
    text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
    return text;
}


function getObject(elementId)
{
    if (document.getElementById)
    {
        return document.getElementById(elementId);
    }
    else if (document.all)
    {
        return document.all[elementId];
    }
    else if (document.layers)
    {
        return document.layers[elementId];
    }
}


function getObjectsByTagAndClass(tag,cls)
{
    var array = document.getElementsByTagName(tag);
    var output = new Array();
    var matches = 0;
    for(var i=0;i<array.length;i++)
    {
        var parts = array[i].className.split(' ');
        for(var j=0;j<parts.length;j++)
        {
            if(parts[j]==cls)
            {
                output[matches++]=array[i];
            }
        }
    }
    return output;
}


function getObjectsOfElementByTagAndClass(object,tag,cls,id)
{
    var output = new Array();
    if(object)
    {
        var array = object.getElementsByTagName(tag);
        var matches = 0;
        if (array != undefined && array != null)
        {
            for(var i=0;i<array.length;i++)
            {
                var parts = array[i].className.split(' ');
                for(var j=0;j<parts.length;j++)
                {
                    if(parts[j]==cls)
                    {
                        if(id)
                        {
                            if (array[i].id.indexOf(id) == 0)
                            {
                                output[matches++]=array[i];
                            }
                        }
                        else
                        {
                            output[matches++]=array[i];
                        }
                    }
                }
            }
        }
    }
    return output;
}


function getBrowserWidth()
{
    if(window.innerWidth)
	{
		return window.innerWidth;
	}
    else if(document.body.clientWidth)
	{
		return document.body.clientWidth;
	}
    else
	{
		return -1;
	}
}


function getBrowserHeight()
{
	return (window.innerHeight?window.innerHeight:document.documentElement.clientHeight);
}


function getBodyHeight()
{
	if(document.body.clientHeight)
	{
		return document.body.clientHeight;
	}
	else
	{
		return -1;
	}
}


function get_event_obj()
{
	var evt = window.event;
	var obj=evt.srcElement;
	return obj;
}








