/**************************************************************************************
 * FOO.JS: A collection of functions for use in get2dom.com and indeed many other
 *         places. This is a dHTML library. basic functionality for non DOM
 *         compliant browsers, fun with DOM browsers (document.getElementByID),
 *         and a little extra for MS Internet Explorer 5.5 & later.
 * AUTHOR: Dominic Winsor, get2dom.com - Comments and Suggestions welcome!
 * VERSION: 3.4
 * LAST UPDATED: 18 October 2001
 ************************************************************************************ */

/**************************************************************************************
 * FUNCTION LIST:
 * Read each function comment for fuller description
 *
 * doContact();                        // displays my e-mail address in a popup window
 * hideLast();                         // hide last layer shown with showLayer();
 * hideLayer(index);                   // hide a layer
 * showLayer(layerName,StayVisible);   // show a hidden layer
 * doFilter(index, opacity);           // make a layer translucent in IE5.5+
 * doStatus(message);                  // change and restore window status message
 * doWindow(page,x,y,winStatus);       // popup window function
 * popup(filename,x,y,pageTitle);      // another popup window function
 * popupText(textString,x,y,pageTitle; // popup window for text/html information
 * goDropMenu(where,selObj);           // evaluates combo box links
 * doBorder(index);                    // swap the border of a layer
 * doBg(index,colval);                 // swap background of a layer
 * swapClass(index,className);         // swap the class of a layer
 * switchDisplay(index);               // swap the display of a layer
 ************************************************************************************ */



/* ********************************************************
 * USER-AGENT (BROWSER) DETECTION CODE
 * Author: Dominic Winsor, Adapted from code by Netscape.
 * Usage: use in 'if' statements for browser-specific code.
 * Example: if(this.ie4up) alert('hello');
 * ******************************************************** */

  var agt=navigator.userAgent.toLowerCase()

  this.major = parseInt(navigator.appVersion)
  this.minor = parseFloat(navigator.appVersion)


  //Netscape navigator www.netscape.com
  this.nav   = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
             && (agt.indexOf('compatible') == -1)))
  this.nav2 = (this.nav && (this.major == 2))
  this.nav3 = (this.nav && (this.major == 3))
  this.nav4 = (this.nav && (this.major == 4))
  this.nav4up = this.nav && (this.major >= 4)
  this.navonly = (this.nav && (agt.indexOf(";nav") != -1))
  this.nav6 = this.nav && (agt.indexOf('netscape6/6') != -1)
  this.nav7 = this.nav && (agt.indexOf('netscape/7') != -1)

  //Microsoft Internet Explorer (MSIE) www.microsoft.com/ie
  this.ie   = (agt.indexOf("msie") != -1)
  this.ie3  = (this.ie && (this.major == 2))
  this.ie4  = (this.ie && (this.major == 4))
  this.ie4only  = this.ie  && (agt.indexOf('4.01')!=-1)
  this.ie4up  = this.ie  && (this.major >= 4)
  this.ie5  = this.ie  && (agt.indexOf('5.0')!=-1)
  this.ie501 = this.ie && (agt.indexOf('5.01')!=-1)
  this.ie5up  = this.ie  && (this.major >= 5)
  this.ie55 = this.ie  && (agt.indexOf('5.5')!=-1)
  this.ie6  = this.ie  && (agt.indexOf('6.0')!=-1)

  //Mac Extensions
  this.mac = (agt.indexOf('mac')!=-1)
  this.ie50mac =this.ie5 && this.mac
  this.ie513mac = this.ie && (agt.indexOf('5.13')!=-1) && this.mac



  // does not work, must either substring or regexp as version string has both 4.0 and 6.0
  // this.ie6up  = this.ie  && (this.major >= 6)

  //Opera www.operasoftware.com
  this.opera = (agt.indexOf("opera") != -1)

  //Mozilla www.mozilla.org
  this.mozillaCompatible = (agt.indexOf("mozilla") != -1)
  this.mozilla = (this.mozillaCompatible && (agt.indexOf('gecko')!=-1)) && !this.nav7 && !this.nav6





/* ********************************************************
 * CODE TO DISPLAY WEBSITE CONTACT INFO
 * This exists to provide a point and click way of mailing me,
 * but which excludes robots, crawlers and e-mail 'harvesters'
 * to protect me from spam.
 *
 * Dependencies: popupText()
 * Author: Dominic Winsor
 * ******************************************************** */
 function doContact() {
	var mailString = new Array();
	var mailStringOut = new String();
	var htmlOut = new String();
	mailString[0] = 'webmonster';
	mailString[1] = '@get2dom.com';
	mailStringOut = (mailString[0] + mailString[1]);
	htmlOut = '<b><big>Contact me</big></b><br>';
	htmlOut = htmlOut + '<a onclick="self.close();" href="mailto:'+mailStringOut+'">'+mailStringOut+'</a><br>';
	popupText(htmlOut,200,50,'contact me');
 }






/* ********************************************************
 * CODE TO FIX RESIZE ISSUES IN NETSCAPE
 * Author: Macromedia (Dreamweaver)
 * ******************************************************** */
 function MM_reloadPage(init) {  //reloads the window if Nav4 resized
   if (init==true) with (navigator) {
     if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
       document.MM_pgW=innerWidth;
       document.MM_pgH=innerHeight;
       onresize=MM_reloadPage;
      }
   } else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
 }
 MM_reloadPage(true);






/* ******************************************************
 * SHOW AND HIDE DHTML LAYERS
 * Author: Dominic Winsor
 * Dependencies: User-agent detection code (this.browser)
 * Usage: use showLayer(); hideLayer(); hideLast();
 *            or showLayer2(); as appropriate
 * ****************************************************** */

// definitions outside functions
// This bit to do with the way I do cross-browser, (non-DOM browser) layer manipulation.
 if (this.nav && (this.mozilla==false)) {
   layerRef = '.layers';
   styleRef = '';
   vis_on = "show";
   vis_off = "hide";
 }

 if(this.ie){
   layerRef = '.all';
   styleRef = '.style';
   vis_on = "visible";
   vis_off = "hidden";
 }

 var last=0; // used to remember which layer was last made visible
 var menuLastChanged; // used to remember last mouseover for menu fx below




/*  Hide layer previously made visible (useful for menus)
 *  Use hideLast() to hide last layer made visible;
 */
 function hideLast() {
	if(last != 0) hideLayer(last);
 }



/*  Hide a specific layer by its ID
 *  Use hideLayer(this.id), where this.id is the id of the layer to hide.
 */
 function hideLayer(layerName) {
	if (document.getElementById) {
		document.getElementById(layerName).style.visibility = 'hidden';
	} else {
		eval( "document" + layerRef + "." + [layerName] + styleRef + ".visibility = vis_off");
	}
 }



/*  Show a specific layer by its ID
 *  invoke hideLayer(this.id), where this.id is the id of the layer to hide.
 *  If you call this function with the stayVisible parameter set to 1
 *  then the layer will not get hidden again when the hideLast() function is called.
 */

 function showLayer(layerName,StayVisible){
 	if (StayVisible!=1) {
		hideLast();
		last=layerName;

	}


	if (document.getElementById) {
		document.getElementById(layerName).style.visibility = 'visible';
		// Uncomment below to make layers go translucent in IE5.5 and up (very nice!)
		//doFilter(layerName,90);
	} else {
		eval( "document" + layerRef + "." + [layerName] + styleRef + ".visibility = vis_on");
	}



	// A specific bugfix, positioning in navigator 4.x. for www.get2dom.com only.
	if ((this.nav==true)&&(this.mozilla==false)) document.layers[layerName].top = 80;

 }

// -----------------------------------------------------------------------------------------------
  var last2 = 0;
 // ---- ShowLayer2

 /*  Hide layer previously made visible (useful for menus)
 *  Use hideLast() to hide last layer made visible;
 */
 function hideLast2() {
	if(last2 != 0) hideLayer2(last2);
 }



/*  Hide a specific layer by its ID
 *  Use hideLayer(this.id), where this.id is the id of the layer to hide.
 */
 function hideLayer2(layerName) {
	if (document.getElementById) {
		document.getElementById(layerName).style.visibility = 'hidden';
	} else {
		eval( "document" + layerRef + "." + [layerName] + styleRef + ".visibility = vis_off");
	}
 }



/*  Show a specific layer by its ID
 *  invoke hideLayer(this.id), where this.id is the id of the layer to hide.
 *  If you call this function with the stayVisible parameter set to 1
 *  then the layer will not get hidden again when the hideLast() function is called.
 */

 function showLayer2(layerName,StayVisible){
 	if (StayVisible!=1) {
		hideLast2();
		last2=layerName;

	}


	if (document.getElementById) {
		document.getElementById(layerName).style.visibility = 'visible';
		// Uncomment below to make layers go translucent in IE5.5 and up (very nice!)
		//doFilter(layerName,90);
	} else {
		eval( "document" + layerRef + "." + [layerName] + styleRef + ".visibility = vis_on");
	}



	// A specific bugfix, positioning in navigator 4.x. for www.get2dom.com only.
	if ((this.nav==true)&&(this.mozilla==false)) document.layers[layerName].top = 80;

 }






/* *************************************************************
 * VARIABLE LAYER OPACITY IN IE5.5
 *           cool, but only works in Internet Explorer V5.5
 * Author: Dominic Winsor
 * Usage: index is the layer id, opacity is a positive
 *        integer, 0=totally transparent, 100=solid
 * ************************************************************* */

 function doFilter(index, opacity) {
   if(this.ie55) {
     eval([index] +'.style.filter = "alpha(opacity=" + opacity + ")"');
   }
 }



/* *************************************************************
 * SET THE WINDOW STATUS MESSAGE
 * Author: Dominic Winsor
 * Usage: Supply a string as parameter to set message. Use with
 *        no parameters to set default window message.
 * ************************************************************* */

 function doStatus(message) {
   (message)  ?  window.status = message  :  window.status = '';
 }



/* *************************************************************
 * NEW WINDOW OPENER
 * Author: Dominic Winsor
 * Usage: page=document location; x/y=dimensions of window
          winStatus=show status bar if supplied
 * ************************************************************* */

 function doWindow(page,x,y,winStatus) {
   (winStatus) ? winStatus="yes" : winStatus="no"
   if (window.myWindow) myWindow.close();
   winOptions='"toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,';
   eval('myWindow=window.open("'+page+'","",'+winOptions+'status='+winStatus+',width='+x+',height='+y+'");');
 }



/* *************************************************************
 * NEW WINDOW OPENER FOR IMAGES THAT FIT THE WINDOW EXACTLY
 * Author: Dominic Winsor
 * Usage: filename=image location (href); x/y=dimensions;
 *        pageTitle=window title
 * ************************************************************* */

 function popup(filename,x,y,pageTitle) {
   LeftPosition = (screen.width) ? (screen.width-x)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-y)/2 : 0;
   myWindow = window.open("","Picture","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+x+",height="+y+',left='  +LeftPosition +  ',top='  +TopPosition +"");
   myWindow.document.write("<html><head>");
   myWindow.document.write("<title>" + pageTitle + "</title>");
   myWindow.document.write("</head><body marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' onload=\"window.focus();\">");
   myWindow.document.write("<a href=\"javascript:window.close()\"><img border=0 hspace=0 vspace=0 height=" + y + " width=" + x + " src='" + filename + "'></a>");
   myWindow.document.write("</body></html>");
   myWindow.document.close();
}




/* *************************************************************
 * NEW WINDOW OPENER FOR TEXT INFORMATION
 * Author: Dominic Winsor
 * Usage: textString=any string of text; x/y=window dimensions;
 *        pageTitle=window title
 * ************************************************************* */

 function popupText(textString,x,y,pageTitle) {
   LeftPosition = (screen.width) ? (screen.width-x)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-y)/2 : 0;
   myWindow = window.open("","Info","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+x+",height="+y+',left='  +LeftPosition +  ',top='  +TopPosition +"");
   myWindow.document.write("<html><head><style>body {text-align: center; font-family: Trebuchet MS, sans-serif; font-size: 10pt;} </style>");
   myWindow.document.write("<title>" + pageTitle + "</title>");
   myWindow.document.write("</head><body marginheight='0' marginwidth='0' topmargin='0' leftmargin='0' onload=\"window.focus();\">");
   myWindow.document.write(textString);
   myWindow.document.write("<br><a href=\"javascript:window.close()\">close</a>");
   myWindow.document.write("</body></html>");
   myWindow.document.close();
}



/* *************************************************************
 * GO TO NEW DOCUMENT LOCATION WITH DROPMENU (COMBO BOX)
 * Author: Dominic Winsor
 * Usage: where=new location (url), selObj=calling object
 *        that is, 'document', or 'window' etc..
 * ************************************************************* */

 function goDropMenu(where,selObj){
   eval(where+".location='"+selObj.options[selObj.selectedIndex].value+"'");
 }






/*
 * DHTML FUN!
 * These functions are designed for use on the onMouseOver and onMouseOut
 * events. They all work the same way. Call with the layer ID to invoke
 * plus any other params needed. Use the function with no params
 * onMouseOut to restore layer to default appearance
 */


/* *************************************************************
 * ADD A BORDER TO A LAYER
 * Author: Dominic Winsor
 * Usage: index=layer id, if not supplied then it will return to
 *        default border.
 * ************************************************************* */

 function doBorder(index){
   if(document.getElementById) {
     if(index) {
       lastBorder=index;
       document.getElementById(index).style.border = '1px #bbbbbb solid';
     } else {
       document.getElementById(lastBorder).style.border = '1px white solid';
     }
   }
 }



/* *************************************************************
 * ADD A BACKGROUND TO A LAYER
 * Author: Dominic Winsor
 * Usage: index=layer id, if not supplied then it will return to
 *        default border. colval=hexadecimal colour value for bg
 *
 * ************************************************************* */

 function doBg(index,colval){
   if(document.getElementById) {
     if(index) {
       lastBg=index;
       lastColour=document.getElementById(index).style.background;   //not set properly in mozilla
       document.getElementById(index).style.background = colval;
     } else {
       document.getElementById(lastBg).style.background = 'white';   //should set to lastColour
     }
   }
 }



/* *************************************************************
 * CHANGE THE CLASS OF AN ELEMENT
 * Author: Dominic Winsor
 * Usage: index=layer id, if not supplied then it will return to
 *        previous class. class=stylesheet class to apply
 * ************************************************************* */

 function swapClass(index,className) {
   if(this.ie) {
     if(index) {
       lastChange=index;
       lastClass=eval("document.all."+index+".className;");
       eval("document.all."+index+".className = '"+className+"';");
     } else {
       eval("document.all."+lastChange+".className = '"+lastClass+"';");
     }
   }
 }






/* *************************************************************
 * CHANGE THE DISPLAY OF MANY ELEMENTS
 * A small function for switching the display property of page elements
 *
 * Author: Dominic Winsor
 * Usage: index=layer id, use with event handler
 *
 * it has two modes of operation:
 *   1. Comment out the first 2 lines inside the function to make
 *      it toggle the display of an item.
 *
 *   2. Uncomment the first 2 lines inside the function to
 *      make it show one element at a time.
 * ************************************************************* */

 var lastElement = new String();
 function switchDisplay(index) {
   if( (lastElement.length)!=0 ) document.all[lastElement].style.display = 'none';
   lastElement = index;
   (document.all[index].style.display == 'none') ?  document.all[index].style.display = 'inline'  :  document.all[index].style.display = 'none';
 }


 function showColours(viz,id)
{
 	popupWindow(false, '/foc/shopadmin/colours.html?'+id, 170, 250);
}

function popupWindow(modal, href, x, y)
{
  LeftPosition = (screen.width) ? (screen.width-x)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-y)/2 : 0;
  if( modal )
  	showModalDialog(href,"","dialogWidth:"+x+"px; dialogHeight:"+y+"px; dialogLeft:"+LeftPosition+"; dialogTop:"+TopPosition +"");
  else
    window.open(href,"","toolbar=0,location=0,directories=0,status=yes,menubar=0,scrollbars=no,resizable=no,copyhistory=0,width="+x+",height="+y+',left='+LeftPosition+',top='+TopPosition+"");
}
// -------------------------------------------------------------------------------



