// shared routines
var l2;

function redirect(type) {
   if (type==1) { // top redirect
      document.writeln("<p>Redirecting frame to <a target=\"_top\"");
      document.writeln(" href=\""+l2+"\">"+l2+"<\/a>");
      top.location=l2;
      // setTimeout("top.location=l2;",1000); // 1 secs
   } else {
      document.writeln("<p>Redirecting to <a target=\"_self\"");
      document.writeln(" href=\""+l2+"\">"+l2+"<\/a>");
      self.location=l2;
      // setTimeout("self.location=l2;",1000); // 1 secs
   }
}

function frame2(s1) {
   // for tenerife/gofio.html
   if (self==parent) {
      var l2=document.location.href;
      var i1=l2.lastIndexOf("/");
      l2=l2.substring(0,i1)+"/"+s1;
      // alert("Redirecting to "+l2);
      self.location=l2; // redirect self
   }
}

// For index
   var s1s=new Array;
   var l1s=new Array;
   var t1s=new Array;
   var ltop=0;

function lset3(s1,l1,t1) {
   s1s[ltop]="?"+s1;
   l1s[ltop]=l1;
   t1s[ltop]=t1;
   ltop++
}

function lset(s1,l1) {
   lset3(s1,l1,1);
}


function setup() {
   var fsnet;
   var freeola;
   var tiscali;
   var rya;
   if (document.location.hostname=="") {
      fsnet="file:///H:/webpages/";
      tiscali="file:///H:/tiscali/";
      rya="file:///H:/ryaonline/";
   } else {
      // fsnet="http://www.windsurfnow.fsnet.co.uk/";
      // tiscali="http://myweb.tiscali.co.uk/waveboy/";
      // rya="http://homepages.rya-online.net/waveboy/";
      // var talktalk="http://www.windsurfnow.talktalk.net/";
      var talktalk="http://www.windsurfnow.co.uk/";
      fsnet=talktalk;
      tiscali=talktalk;
      rya=talktalk;
   }
   // freeola="http://www.windsurfnow.ukfun.com/";
   // lset("home",fsnet+"index.html");
   // lset("",fsnet+"index.html");
   lset("tenerife",fsnet+"tenerife/index.html");
   lset("malta",fsnet+"web07/Malta.html");
   lset("naxos",fsnet+"web3/naxos.html");
   lset("capeverde",fsnet+"CapeVerde/index.html");
   lset("equipment",fsnet+"web07/wsequip.html");
   lset3("locations",fsnet+"web07/wslocs.html",2);
   lset("links",fsnet+"web07/links.html");
   lset("medical",fsnet+"web07/medical.html");
   lset("gofio",fsnet+"tenerife/gofio.html");
   lset("photos",fsnet+"photos/index.html");
   lset("contact",fsnet+"contact/index.html");
   lset("musicnotator",rya+"music/index.html");
   lset("javaupdate",rya+"music/JavaUpdate.html");
   lset("musicnotatorguide",rya+"music/MusicNotatorGuide.html");
   lset("midieditorguide",rya+"music/MidiEditorGuide.html");
   lset("imedit",rya+"photo/index.html");
   lset("ImageEditorGuide",rya+"photo/ImageEditorGuide.html");
   lset("ImagePrinterGuide",rya+"photo/ImagePrinterGuide.html");
   lset("ImageCatalogGuide",rya+"photo/ImageCatalogGuide.html");
}

function navigate() {
   var l3="";
   var i1=l1.indexOf("&");
   if (i1>=0) {
      l3=l1.substring(i1+1);
      l1=l1.substring(0,i1);
      // document.writeln("<p>l1:"+l1+" l3:"+l3);
   }
   l1=l1.toLowerCase();
   setup();
   var fnd=0;
   for (i1=0;i1<ltop;i1++) {
      if (l1==s1s[i1]) {
         fnd=1;
         break;
      // } else {
         // document.writeln("<p>l1:"+l1+" not "+s1s[i1]);
      }
   }
   if (fnd!=0) {
      l2=l1s[i1];
      if (l3!="")
         l2=l2+"?"+l3;
      // document.writeln("<p>Redirecting to <a target=\"_top\"");
      // document.writeln(" href=\""+l2+"\">"+l2+"<\/a>");
      // setTimeout("top.location=l2;",1000); // 1 secs
      redirect(t1s[i1]);
   } else {
      document.writeln("<p>Page requested not recognized");
   }
}

function sitemap() {
   document.writeln("<h2>Site Map<\/h2>");
   setup();
   document.writeln("<p><table><col width=\"180\"><tr><th>");
   document.writeln("KEY<\/th><th>LINK<\/th><\/tr><tr><td>");
   var i1;
   for (i1=0;;) {
      document.writeln(s1s[i1]+"<\/td><td><a target=\"_top\"");
      document.writeln(" href=\""+l1s[i1]+"\">"+l1s[i1]+"<\/a>");
      i1++;
      if (i1==ltop) break;
      document.writeln("<\/td><\/tr><tr><td>");
   }
   document.writeln("<\/td><\/tr><\/table>");
}

// For other files

function getsearch() {
   l2="";
   var i1=document.referrer.indexOf("?");
   if (i1>=0) {
      l2=document.referrer.substring(i1+1);
   }
   if ((l2=="") && (self.location.search!="")) {
      l2=self.location.search.substring(1);
   }
   l2=l2.toLowerCase();
}



function framecheck(rd1) {
   if ((document.location.hostname!="") && (self==parent)) {
      l2=location.hash;
      if (l2=="") l2=location.search;
      if (l2!="") l2=l2.substring(1); // remove '#'
      if (l2!="") {
         if (rd1.charAt(0)=="?")
            rd1=rd1+"&";
         else
            rd1=rd1+"?";
         rd1=rd1+l2;
      }
      l2="http://www.windsurfnow.co.uk/"+rd1;
      redirect(1);
      return;
   }
   l2="";
   if ((self!=parent) && (location.hash=="")) {
      var i1=document.referrer.indexOf("?");
      if (i1>=0) {
         l2=document.referrer.substring(i1+1);
         checkrefs();
      }
   }
}

function checkrefs() {
   if (l2=="") return;
   l2=l2.toLowerCase();
   var fnd=-1;
   for (i1=0;i1<refs.length;i1++) {
      if (refs[i1].indexOf(l2)==0) {
         fnd=i1;
         break;
      }
   }
   if (fnd>=0) {
      l2=location.href;
      i1=l2.indexOf("?");
      if (i1>=0) l2=l2.substring(0,i1);
      l2=l2+"#"+refs[fnd];
      redirect(2); // self redirect
   } else {
      document.writeln("Ref not found:"+l2);
   }
}

function dolink(href1,text) {
   var base1="http://www.windsurfnow.co.uk";
   var path1=location.pathname;
   var i3=path1.lastIndexOf("/");
   path1=path1.substring(0,i3+1);
   i3=href1.indexOf("#");
   var search="";
   if (i3>0) {
      search=href1.substring(i3+1);
      href1=href1.substring(0,i3);
   }
   if (location.host=="") {
      base1="file://";
      if (href1.charAt(href1.length-1)=="/")
         href1=href1+"index.html";
      if (search!="")
         href1=href1+"#";
   } else {
      if (search!="")
         href1=href1+"?";
   }
   document.writeln("<a href=\""+base1+path1+href1+search+
      "\" target=\"_top\">"+text+"</a>");
}

function tlink(href2,text) {
   var base3="../";
   if (location.host=="")
      base3="../../tiscali/";
   dolink(base3+href2,text);
}

function imglink(href2,src1,alt1,width1,height1) {
   var base1="http://www.windsurfnow.talktalk.net/";
   if (location.host=="") {
      base1="file://h:/tiscali/";
      if (href2.charAt(href2.length-1)=="/")
         href2=href2+"index.html";
   }
   document.writeln("<a href=\""+base1+href2+"\" target=\"_blank\">");
   document.writeln("<img class=\"floatrightnb\" alt=\""+alt1+"\"");
   document.writeln("src=\""+base1+src1+"\"");
   document.writeln(" width=\""+width1+"\" height=\""+height1+"\"");
   document.writeln("></a>");
}
