Need help redirecting visitors

I’ve got the following script and it works like a charm

<script type="text/javascript">
	var currentUrl = window.location.href;
	function goToPath() {
		
		var theUrlToGoTo = "http://someRandomSite";
		var aPosition = currentUrl.indexOf("Name_");
		aPosition=currentUrl.indexOf("/", (aPosition))+1;
		var secondPos = currentUrl.indexOf("/", aPosition);
		
                return theUrlToGoTo.concat("/").concat(currentUrl.substring(aPosition, secondPos)).concat("/summary.shtml");
			
	}	
		
<!--
window.location=goToPath();

//-->
</script>

Now to my problem

Sometimes there are two similar addresses, so for example
if there are two links that are similar that i can click on, for example

<html>

<td><a href="href="http://someOtherRandomSite/Name_/index.html"">RandomName</a>

<td><a href="href="http://someOtherRandomSite/Name_hi2/index.html"">Name1</a>

 <td><a href="href="http://someOtherRandomSite/Name_hi1/index.html"">Name2</a>



In the above example there are two similar links “Hi1, Hi2”. In these cases I want it to generate a new webpage with the name of this two and links to them.

example

 
<html>
<body>

<td><a href="href="http://someRandomSite/Name_hi1/Summary.shtml"">Name1</a>

 <td><a href="href="http://someRandomSite/Name_hi2/Summary.shtml"">Name2</a>
</body>
</html>

Can this be done by javascript,

first check when you click on a random adress if there are two(ore more) similar adresses and then generate and direct to a new webpage with those similar addresses with links to them?

(Dont mind if the script is incorrect, it works as is should)

Since there are no answers perhaps i have expressed myself in a bad way. So lets break it down.

I have the following psuedo code


<html>
<head>
<script type="text/javascript">
function redirect(){
var theUrlToGoTo = "www.hello.com";
var myArray = [];
int size=0;
for (i=0; i<document.length; i++) {
if(i == '\\\\b'+theUrlToGoTo+'\\\\b')
size++;
myArray[i]=allPageTags[i];
}
window.onload=redirect();
</script>
</head>
<body>
<table>
<tr>
<td><a href="www.hello1.com">www.hello1.com</a></td>
</tr>
<tr>
<td><a href="www.hello2.com">www.hello2.com</a></td>
</tr>

</table>

</body>
</html>





In other words i want the variable myArray to include the following data

myArray[‘www.hello1.com’,‘www.hello2.com’] when i am done.

How is this done, how do i search a html document with javascript after a certain predefined line?

Perpahs some soul can edit the above psuedo code so that it actually works?

Thanks