<!--

//Copyright Mangolab 2002
//feel free to use this code in your own site but please
//give a link to www.mangolab.com as a credit
//script for main framed pages

var NS4 = (document.layers) ? true : false; 
var NS6 = ((document.getElementById) && (!document.all)) ? true : false;
var IndexPage = "index.htm";

//For footers that are themselves full pages (ie static pages, framsets), use:
//ie not for product list headers/footers or product pages

function LoadMain() {
//called by on load event of page
//check framing is correct
return LoadFullPageCheck();
}

function LoadFullPageCheck() {
//get name of page for web address
var thispage = self.location.pathname.substring((top.location.pathname.lastIndexOf("/"))+1);
return FrameSetCheck(thispage);
}

//For product pages only ( with a second parameter of quantity)
//called directly from body on load event
//Body On load event handler, to populate quantity
//with any quantity parameter passed to the page

function ProductPageLoad() {
if (LoadFullPageCheck()){
   return SetForQuantity();}
else {
   return false;
   }
}

function SetForQuantity() {
if (window.location.search!="") {
   var sstring = window.location.search;
   //find *final* ?
   var extractStr = sstring.substring(sstring.lastIndexOf("?") + 1, sstring.length);
   if (!isNaN(extractStr)){ 
      var the_form = window.document.forms[0];
      the_form.quantity.value=extractStr;
      UpdatePrice(0);
      }
   }
}

//For search pages only (with a second parameter of the keywords to search for)
//called directly from body on load event
//Body On load event handler, to populate quantity
//with any quantity parameter passed to the page
//dont have full page check as it just complicates matters
//& interferes with the form mail redirection!

function SearchPageLoad() {
//if (LoadFullPageCheck()){
return SetForKeywords();//}
//else {
//   return false;
//   }
}

function SetForKeywords() {
if (window.location.search!="") {
   var sstring = window.location.search;
   //find *final* ?
   var extractStr = sstring.substring(sstring.lastIndexOf("?") + 1, sstring.length);
   //now need to replace any %20's
   extractStr = SearchAndReplace(extractStr,"%20"," "); 
   if (extractStr!=""){ 
      //var the_form = window.document.forms[0];
      //the_form.keywords.value=extractStr;
      //set for the back button	to store the search
      self.location.replace("srch_ie.htm?"+extractStr); 
      search(extractStr);
      }
   }
}

function SearchAndReplace(Content, SearchFor, ReplaceWith) {
   var tmpContent = Content;
   var tmpBefore = new String();   
   var tmpAfter = new String();
   var tmpOutput = new String();
   var intBefore = 0;
   var intAfter = 0;
   if (SearchFor.length == 0)
      return;
   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {  
      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;
      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;
      // Get the rest of the content after the match until
      // the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);
   }

   return tmpOutput + tmpContent;
}


//For headers and footers that are themselves part of 
//a sub-frameset (ie Mangomart pages) use below to reload 
//the correct parent frameset and its correct parents
//called directly from Body onload event
//ie for product list headers/footers but not product pages

function FrameSetCheck(MainFrameParent){
//called by on load event of mangomart product/category list
//header or footer page & check framing is correct with ParentFrameset
var result=true;
//get name of page for web address
var thispage = self.location.pathname.substring((top.location.pathname.lastIndexOf("/"))+1);
var webname = top.location.pathname.substring((top.location.pathname.lastIndexOf("/"))+1);
webname = webname.toLowerCase();
var locfname=webname;
//alert("webname="+webname + " thispage="+thispage);
//get name of page for a local file IE5 uses normal local paths unlike NS6
if (!NS6){locfname = top.location.pathname.substring((top.location.pathname.lastIndexOf("\\"))+1);}
locfname=locfname.toLowerCase();
if ((webname!=IndexPage) && (locfname!=IndexPage)) {
   window.status="please wait reloading with correct framing";
   top.location.href=IndexPage+"?"+MainFrameParent;   	      	
   result=false;
   }
return result;
}

//-->
