﻿/// <reference path="jquery-1.2.6.js" />

//Give all elements the click function
//This is used by some of the modal dialogs 
var browser = navigator.appName;
if (browser == "Netscape") {
    HTMLElement.prototype.click = function() {
        var evt =
    this.ownerDocument.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true,
    this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0,
    null); this.dispatchEvent(evt);
    }
}    




// JScript File
function WindowSizeData()//object
{
    this.imageWidth = 100;
    this.imageHeight = 100;
    this.waWidth = 100;//workarea width
    this.waHeight = 100;//workarea height
    this.windowWidth = 100;
    this.windowHeight = 100;
    this.AutoCalculateAndResize = true;
}

var NS,MS,AP;//shared page variables to indicate browser type
var popupHeight = '100';
var popupWidth = '100';
popupInitialSize = new WindowSizeData();
function PopupPic(sPicURL) { 
//popupInitialSize will be either initialized or set by the template
window.open( "ImagePopup.aspx?"+sPicURL, "",  
"resizable=1,height=" + popupInitialSize.waHeight + ",width=" + popupInitialSize.waWidth); 
} 

function BrowserDetect()
{
   NS = (navigator.appName=="Netscape")?true:false; 
   MS = (navigator.appName=="Microsoft Internet Explorer")?true:false;
   AP = false;
   if(navigator.vendor != null)
   {
        if(navigator.vendor.indexOf("Apple") > -1)
        {
            AP = true;
            NS = false;
        }
   }
}

//Used with window.open()
//based on fixed sizes from WindowSizeData object
function CalculateWorkAreaSize(wsd)//WindowSizeData object
{
//Workarea is smaller than window size
      BrowserDetect();
      winiWidth = (NS)?window.innerWidth:document.body.clientWidth; 
      winiHeight = (NS)?window.innerHeight:document.body.clientHeight; 

      iWidth = wsd.imageWidth;
      iHeight = wsd.imageHeight;
      
      //So far workArea is independent of browser but the following is setup just incase it is needed in the future
//      
//      if(MS)//Adjustment for IE
//      {
//        iWidth = iWidth;
//        iHeight = iHeight;
//      }
//      if(NS)//Adjustment for Netscape
//      {
//        iWidth = iWidth;
//        iHeight = iHeight;
//      }
//      if(AP)//Adjustment for Safari
//      {
//        iWidth = iWidth;
//        iHeight = iHeight;
//      }
      
    //Update the object for pass by reference
    wsd.waWidth = iWidth;
    wsd.waHeight = iHeight;
}

//Used with window.resizeTo()
//Requires ImagePopup.aspx single image page
function CalculateWindowSize(wsd)//WindowSizeData object
{
      BrowserDetect();
      winiWidth = (NS)?window.innerWidth:document.body.clientWidth; 
      winiHeight = (NS)?window.innerHeight:document.body.clientHeight; 

      iWidth = document.images[0].width;
      iHeight = document.images[0].height;
      
      if(MS)//Adjustment for IE
      {
        iWidth = iWidth + 10;
        iHeight = iHeight + 24 + 22 + 26;//height + title bar + url bar + lower status bar...locally the last two parts are now seen so in development it should appear too tall.
      }
      if(NS)//Adjustment for Netscape
      {
        iWidth = iWidth + 8;
        iHeight = iHeight + 49;
      }
      if(AP)//Adjustment for Safari
      {
        iWidth = iWidth + 4;
        iHeight = iHeight + 25;
      }
      
    //Update the object for pass by reference
    wsd.windowWidth = iWidth;
    wsd.windowHeight = iHeight;
}

function FitPic() 
{ 
  var wsd = window.opener.popupInitialSize;

  if(wsd.AutoCalculateAndResize)
  {
    CalculateWindowSize(wsd)
    window.resizeTo(wsd.windowWidth,wsd.windowHeight); 
  }
  self.focus(); 
}; 

//Menu Images Methods - Generated from FrontPage

//A simpler version of swapImg
function Cy_swapImg(id,imagefile,basePath)
{
    FP_swapImg(1,1,/*id*/id,/*url*/basePath + imagefile);
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

// Replaces all instances of the given substring.
String.prototype.replaceAll = function( 
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
){
    var strText = this;
    var intIndexOfMatch = strText.indexOf( strTarget );
     
    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1){
    // Relace out the current instance.
    strText = strText.replace( strTarget, strSubString )
     

    // Get the index of any next matching substring.
    intIndexOfMatch = strText.indexOf( strTarget );
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return( strText );
}
