//Saiba Tools. 20/06/1999 12:54
//  Amended    24/06/1999 17:55

//ReadSaibaCookie()
//WriteSaibaCookie()
//inactive()
//active()
//Splice()
//Breakdown()
//LoadImages()
//ImgSwap() 
//ImgSwapRestore()
 
  
  function ReadSaibaCookie(name) {
    var CookieName,CookieString, CookieVal, length, start, end;
    CookieName=name+"=";
    CookieVal="";
    CookieString=document.cookie;
    length=CookieString.length;
    if (length>0) {
      start=CookieString.indexOf(CookieName,0);
      if (start !=-1) {
        start+=CookieName.length;
        end=CookieString.indexOf(";",start);
        if (end==-1){end=length;}
        CookieVal=unescape(CookieString.substring(start,end));
      }
    }
    return(CookieVal);
  }

 
  
  function WriteSaibaCookie(name,data,expires,domain,path,secure) {
    var CookieVal,CookieError;
    CookieVal=CookieError=""; 
    if (name) {
      CookieVal=CookieVal+escape(name)+"=";
      if (data) {
        CookieVal=CookieVal+escape(data);
        if (expires) { 
          CookieVal=CookieVal+"; expires="+expires.toGMTString();
        }
        if (domain) {
          CookieVal=CookieVal+"; domain="+domain;
        }
        if (path) {
          CookieVal=CookieVal+"; path="+path;
        }
        if (secure) {
          CookieVal=CookieVal+"; secure";
        }
      }
      else {CookieError=CookieError+"Data failure";} //data required
    }
    else {CookieError=CookieError+"Name failure";} //name required
    if (!CookieError) {
      document.cookie=CookieVal; //set cookie 
      if (data != ReadSaibaCookie(name)) {
        CookieError="Write failure";           //check cookie set Ok
      } 
    }
    return CookieError;
  }

  

  function inactive(imgName) {
    if (document.images){
      document[imgName].src = eval(imgName + '.src')
    } 
  }

  function active(imgName) {
    if (document.images){ 
      document[imgName].src = eval(imgName + 'a.src')
    }
  }

  function splice() {
    var delimiter,numArgs, spliced, i;
    spliced="";
    delimiter="|";
    numArgs=splice.arguments.length;
    if (numArgs>1) {
      for (i=0; i<numArgs; i++) {
         spliced=spliced+splice.arguments[i]+delimiter;
      } 
    }
    return spliced.substring(0,spliced.length-1);  
  } 

  function breakdown(data) {
    var delimeter, start,end,count;
    broken=new Object();
    delimiter="|";
    start=end=0;
    count=1;
    end=data.indexOf(delimiter,end);
    while ((end) && (end>-1)) {
      broken[count]=data.substring(start,end);
      count++;
      start=end+1
      end=data.indexOf(delimiter,start);
    }
    broken[count]=data.substring(start,data.length);
    broken[0]=count+1;
    return broken;    
  }


  function LoadImages() {
    if (document.images) {
      if (document.loadArray==null) document.loadArray = new Array();
      var i = document.loadArray.length;
      for (j=0; j<LoadImages.arguments.length; j++) 
           if (LoadImages.arguments[j].charAt(0)!="#"){
             document.loadArray[i] = new Image;
             document.loadArray[i++].src = LoadImages.arguments[j];
           } 
    }
  }

  
  function ImgSwapRestore() { 
    if (document.ImgSwapData != null)
       document.ImgSwapData[0].src = document.ImgSwapData[1];
  }

  

  function ImgSwap() { 
    var i,j=0,objStr,obj,
        swapArray=new Array,
        oldArray=document.ImgSwapData;
 
      objStr = ImgSwap.arguments[0];
      obj = eval(objStr);
    
      if (obj != null) {
        swapArray[j++] = obj;
        swapArray[j++] = obj.src;
        obj.src = ImgSwap.arguments[1]; 
        //What does this mean-- swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      } 
  
    document.ImgSwapData = swapArray; //used for restore
  }

