var formatos = new Array(
"top","<a href='@D@'   target='_top'>@W@ <img src='/on/images/icoLink.gif' alt='ampliar informacion'></a>",
"tienda2","<b><a href='http://www.telefonicaonline.com/on/es/servnav/on.html?servicio=redireccion&v_procede=qgo&v_producto=@D@'   target='_top'>@W@ <img src='/on/images/icoLink.gif' alt='info producto'></a></b>"
)

var npar=3;



function cargaurl(p1,p2,p3,p4,p5,p6){
var i,j,a,b,c,d,e;
var npar1=3;
var npar0=2;
b=rStr(p1,"%"," ");

for (i=0;i<urltot.length/npar1;i++){
a=(urltot[i*npar1]);
a=rStr(a," de "," ");
a=rStr(a," la "," ");
a=rStr(a," en "," ");
a=rStr(a,"  "," ");

if (a.indexOf(b)!=-1){
	
	for (j=0;j<urltot.length/npar1;j++){
	c=formatos[j*npar0];
	if (c==urltot[i*npar1+1]){
		d=formatos[j*npar0+1];
		e=urltot[i*npar1+2];
		d=rStr(d,"@D@",e)
		d=rStr(d,"@W@",p2)
		d=rStr(d,"@PA1@",p3)
		d=rStr(d,"@PA2@",p4)
		d=rStr(d,"@PA3@",p5)
		d=rStr(d,"@PA4@",p6)
		document.write(d);
	}
	}
}
}
}


function cargarelac(p1){
var i,j,a,b,c,d,e,x,y,k,a0;
var npar1=3;
var npar0=2;
d=p1;
b=rStr(d,"%"," ");
d=p1+"%";
c=d.split("%");
x=urltot.length/npar1;
y=formatos.length/npar0;
document.write("<br><br><br><br><b>Enlaces relacionados</b><ul>");
for (i=0;i<x;i++){
  a=urltot[i*npar1];
  d=urltot[i*npar1+1];
  a0=urltot[i*npar1+2];
  e=c.length;
  
  for (j=0;j<c.length;j++){

    if (a.indexOf(c[j])!=-1){
	e=e-1;
  
    }
  }
  if (e==0){
	document.write("<li>");

        for (j=0;j<y;j++){
	b=formatos[j*npar0];
	k=formatos[j*npar0+1];
        if (b==d){
		
		k=rStr(k,"@D@",a0)
		k=rStr(k,"@W@",a)
		document.write(k);
        }
   }
   }
}

document.write("</ul>");
}





function rStr(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function







