<!--

function getSource(oSrc)
{
	if(typeof oSrc=='string') return document.getElementById(oSrc);
	else return oSrc;
}

/*************************************************************************/

Array.prototype.unique =
  function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j])
          j = ++i;
      }
      a.push(this[i]);
    }
    return a;
  };

/*************************************************************************/

String.prototype.begins=function(sub_str)
{
	return this.indexOf(sub_str)==0;
}

String.prototype.endWith=function(sub_str)
{
	var pos=this.indexOf(sub_str);
	if(pos+sub_str.length==this.length) return true;
	else return false;
}

String.prototype.left=function(sub_str)
{
	var pos;
	if((pos=this.indexOf(sub_str))>-1)
		return this.substring(0,pos);
	else return "";
}

String.prototype.right=function(sub_str)
{
	var pos;
	if((pos=this.indexOf(sub_str))>-1)
		return this.substring((pos+sub_str.length),this.length);
	else return "";
}

String.prototype.leftBack=function(sub_str)
{
	var pos;
	if((pos=this.lastIndexOf(sub_str))>-1)
		return this.substring(0,pos);
	else return "";
}

String.prototype.rightBack=function(sub_str)
{
	var pos;
	if((pos=this.lastIndexOf(sub_str))>-1)
		return this.substring((pos+sub_str.length),this.length);
	else return "";
}

String.prototype.middle=function(str1,str2)
{
	var pos1,pos2;
	if((pos1=this.indexOf(str1))==-1 || (pos2=this.lastIndexOf(str2))==-1)
		return "";
	if(pos1==pos2) return "";
	return this.substring((pos1+str1.length),pos2);
}

String.prototype.contains=function(sub_str)
{
	if(this.indexOf(sub_str)>-1) return true;
	else return false;
}

String.prototype.trim=function()
{
  var s = this.replace(/^(\s)*/, '');
  s = s.replace(/(\s)*$/, '');
  return s;
}

/****************************************************************/

function XUrl(xurl)
{	
	if(xurl==undefined)
		this.xurl=location.href;
	else this.xurl=xurl;
	this.parse();
}

XUrl.prototype.parse=function()
{
	this.anchor='';
	this.parameters=new Array();
	if(typeof this.xurl!="string") {alert("error XUrl: xurl must be a string, "+typeof this.xurl+" given");return;}
	var uri=this.xurl.right("?");
	if(uri=="") return;
	
	var i;
	var pieces=uri.split("&");
	for(i=0;i<pieces.length;i++)
	{
		var subPieces=pieces[i].split("=");
		subPieces[1]=unescape(subPieces[1]);
		if(subPieces[1].contains('#')) 
		{
			this.anchor=subPieces[1].right('#');
			subPieces[1]=subPieces[1].left('#');
		}
		this.parameters.push(subPieces);
	}
}

XUrl.prototype.setParameter=function(param,value)
{
	var p=this._getParameter(param);
	if(p!=undefined)
	{
		this.parameters[p[0]]=new Array(param,value);
	}
	else
	{
		this.parameters.push(new Array(param,value));
	}
}

XUrl.prototype.getAnchor=function(value)
{
	return this.anchor;
}

XUrl.prototype.setAnchor=function(value)
{
	this.anchor=value;
}

XUrl.prototype._getParameter=function(param)
{
	var i;
	for(i=0;i<this.parameters.length;i++)
	{
		if(this.parameters[i][0]==param)
			return new Array(i,this.parameters[i][1]);
	}
	
	return undefined;
}

XUrl.prototype.getParameter=function(param)
{
	var val=this._getParameter(param);
	if(val!=undefined)
		return val[1];
	else return "";
}

XUrl.prototype.resetParameters=function()
{
	this.parameters=new Array();
}

XUrl.prototype.getUrl=function()
{
	var urlStr = this.xurl.left("?");
	if(urlStr=="") urlStr=this.xurl;
	
	var uri=new Array();
	
	var i,actionStr;
	for(i=0;i<this.parameters.length;i++)
	{
		if(this.parameters[i][1]=='undefined')
			uri.push(this.parameters[i][0]);
		else uri.push(this.parameters[i][0]+"="+escape(this.parameters[i][1]));
	}
	
	urlStr+="?"+uri.join("&");
	if(this.anchor!='') urlStr+="#"+escape(this.anchor); 
	return urlStr;
}


//-->
