// in_array function for javascript
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

//need to fix IE error
if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
}


function makeUrl(currentUrl,partUrl,sharpPart,base){
	loc = currentUrl;
	pid = sharpPart
		if(loc.split('#')[1]){//sharp detected
			sSharp = loc.split('#')[1];
			sharp = sSharp.split('|');
			//alert(sharp[0] + "|" + sharp[1])
			if(sharp[1]){ //more then 1 things detected
				if(sharp.in_array(pid)){//value exist remove from array
					//alert("in array");
					indexValue = sharp.indexOf(pid);
					sharp.splice(indexValue,1);
					return base + partUrl + sharp.join("|");
				}else{//value does not exist, add to sharp
					return loc + "|" + pid;
				}
			}else{
				if(pid == sSharp){ //value exist - close detected
					return base + partUrl
				}else{ //value does not exist add new value
					return loc + "|" + pid;
				}
			}
		}else{//no sharp. open first and add sharp
			return base + partUrl + pid;
		}
}
