﻿/*************************************************************
 * Window Onload Manager (WOM) v1.0
 * Author: Justin Barlow - www.netlobo.com
 *
 * Description:
 * The WOM library of functions allows you to easily call
 * multiple javascript functions when your page loads.
 *
 * Usage:
 * Add functions to WOM using the womAdd() function. Pass the
 * name of your functions (with or without parameters) into
 * womAdd(). Then call womOn() like this:
 *     womAdd('hideDiv()');
 *     womAdd('changeBg("menuopts","#CCCCCC")');
 *     
 * WOM will run when your page loads and run all of the
 * functions you have added using womAdd()
 *************************************************************/

/*************************************************************
 * The womGo() function loops through the woms array and
 * runs each function in the array.
 *************************************************************/
window.onload = function() {
	for(var i = 0;i < woms.length;i++)
		eval(woms[i]);
}

/*************************************************************
 * The womAdd() function will add another function to the woms
 * array to be run when the page loads.
 *************************************************************/
function womAdd(func){
	woms[woms.length] = func;
}

/*************************************************************
 * The woms array holds all of the functions you wish to run
 * when the page loads.
 *************************************************************/
var woms = new Array();

var popupWidth;
var popupHeight;

function setPopupDimensions(popupurl) {
	popupWidth = null;
	popupHeight = null;
	if (popupurl.lastIndexOf("ab-1v") != -1) {popupWidth = 700; popupHeight = 900;}
	if (popupurl.lastIndexOf("ab-49r") != -1) {popupWidth = 630; popupHeight = 645;}
	if (popupurl.lastIndexOf("ab-57v") != -1) {popupWidth = 630; popupHeight = 730;}
	if (popupurl.lastIndexOf("ab-68v69r") != -1) {popupWidth = 630; popupHeight = 800;}
	if (popupurl.lastIndexOf("ab-77r") != -1) {popupWidth = 550; popupHeight = 680;}
	if (popupurl.lastIndexOf("ab-183v") != -1) {popupWidth = 590; popupHeight = 530;}
	if (popupurl.lastIndexOf("ab-89v") != -1) {popupWidth = 480; popupHeight = 580;}
	if (popupurl.lastIndexOf("ab-29v") != -1) {popupWidth = 700; popupHeight = 750;}
	if (popupurl.lastIndexOf("ab-224v") != -1) {popupWidth = 630; popupHeight = 520;}
	if (popupurl.lastIndexOf("ab-headandtail") != -1) {popupWidth = 440; popupHeight = 520;}
	if (popupurl.lastIndexOf("ab-blindtooling") != -1) {popupWidth = 620; popupHeight = 520;}
	if (popupurl.lastIndexOf("ab-clasp") != -1) {popupWidth = 560; popupHeight = 540;}

	if (popupurl.lastIndexOf("ds-scrolls1") != -1) {popupWidth = 460; popupHeight = 550;}
	if (popupurl.lastIndexOf("ds-trever") != -1) {popupWidth = 650; popupHeight = 690;}
	if (popupurl.lastIndexOf("ds-detail2") != -1) {popupWidth = 530; popupHeight = 400;}
	if (popupurl.lastIndexOf("ds-detail3") != -1) {popupWidth = 530; popupHeight = 400;}
	if (popupurl.lastIndexOf("ds-fragment1") != -1) {popupWidth = 515; popupHeight = 500;}

	if (popupurl.lastIndexOf("cccharged") != -1) {popupWidth = 500; popupHeight = 250;}

	if (popupurl.lastIndexOf("fe-logo") != -1) {popupWidth = 580; popupHeight = 430;}
}

// This variable will hold the window object.
// We only allow one pop-up at a time.
var popup = null;
var nokill = false;

/*/ FUNCTIONS THAT WILL WRAP THE POP-UP PROCESS /*/
/*/
/ / PURPOSE:
/ /		To create and center a pop-up window.
/ /
/ / COMMENTS:
/ /		It will replace old pop-up if called
/ / 	without calling DestroyWnd() first..
/*/
function openPopUp(fileUrl, width, height, normal) {

	nokill = false; //reset

	// close any other popups, thanks
	if (popup != null) { // || (popup.closed)) {
		DestroyWnd();
	}

	var attribs = '';
	var size = "no";

	// if no dimensions provided, apply default/percentage dimensions [and set the window to be resizable]
	if (height == null) {height = 0.6; size="yes";}
	if (width == null) {width = 0.6; size="yes";}

	// do percentage values
	if (height <= 1) height = (screen.height * height);
	if (width <= 1) width = (screen.width * width);

	// force minimum dimensions if desired
	// if (height < 375) height = 375;
	// if (width < 600) width = 600;

	// if the screen is smaller than the proposed window, make the window resizable and adjust the proposed window's dimensions accordingly...
	if(screen.width < width) {width = (screen.width * 0.9); size = "yes";}
	if(screen.height < height) {height = (screen.height * 0.75); size = "yes";}

	// if the screen is very small, ensure that the window resizable
	// if(screen.width <= 800 || screen.height <= 600) size = "yes";

	// center the window // THIS DOESN'T WORK RIGHT YET
	// find position
	WndTop  = Math.max(Math.round((screen.height - height) / 2),0);
	WndLeft = Math.max(Math.round((screen.width  - width)  / 2),0);

	// if normal variable is set, enable sizing override. STRONGLY RECOMMENDED - imagine if size was off on a normal window! Dumb.
	if (normal) {size = "yes";}
	// alert("size is " + size);
	
	//size and scrollbar override - strongly recommended for this kind of site for all popups.
	size = "yes"

	// collect the attributes
	attribs = "width=" + width + ",height=" + height + ",top=" + WndTop + ",left=" + WndLeft;

	if (normal) {attribs += ",resizable=" + size + ",scrollbars=" + size + ",status=yes,toolbar=yes,directories=yes,menubar=yes,location=yes"; nokill = true;} else {attribs += ",resizable=" + size + ",scrollbars=" + size + ",dependent=yes,status=no,toolbar=no,directories=no,menubar=no,location=no";}

	// UNUSED ATTRIBS: dependent, // not true, am trying it out again.

	popup = window.open(fileUrl,'',attribs); // optional window name prevents multiple windows and cause auto-recycles even when opening window is browsed elsewhere. Useful, but not here: popups are quickly killed off unless explicitly needed to stay open (nokill) - don't want to then recycle them. Recycling also stops sizing.
	// window.open(fileUrl,'fe',attribs); // window name prevents multiple windows and causes auto-recycles! Nice.
	popup.focus(); // brings popup to front whenever a new one is loaded.
}

/*/
/ / PURPOSE:
/ /		To destroy the pop-up window.
/ /
/*/

function DestroyWnd()
{
	// close the current window
	if(popup != null && nokill == false)
	{
		popup.close();
		popup = null;
	}
}

function nonpopupsOnload() {
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop
	if (!document.getElementsByTagName) {
		return false;
	}

	// create an array of objects of each link in the document
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags)
	for (var i=0; i < popuplinks.length; i++) {
		// if the link has a class of "popupwin"...
		if (popuplinks[i].className.indexOf("popupwin") != -1) {
			// add an onclick event on the fly to pass the href attribute
			// of the link to our second function, openPopUp
			popuplinks[i].onclick = function() {
				setPopupDimensions(this.getAttribute("href"));
				openPopUp(this.getAttribute("href"),popupWidth,popupHeight,false);
				return false;
			}
		}
		if (popuplinks[i].className.indexOf("picture") != -1) {
			popuplinks[i].onclick = function() {
				setPopupDimensions(this.getAttribute("href"));
				openPopUp(this.getAttribute("href"),popupWidth,popupHeight,false);
				return false;
			}
		}
		if (popuplinks[i].className.indexOf("popupwinnormal") != -1) {
			popuplinks[i].onclick = function() {
				setPopupDimensions(this.getAttribute("href"));
				openPopUp(this.getAttribute("href"),popupWidth,popupHeight,true);
				return false;
			}
		}
	}
}
womAdd('nonpopupsOnload()');

var ie567 = false;
var ie56 = false;
var content_min;
var content_max;
var backbutton;
var windowWidth,windowHeight;

var sessioncounter = 0;

function getWindowSize() // http://www.quirksmode.org/viewport/compatibility.html
{
	if (self.innerHeight) // all except Explorer
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
}

function closePopup() {
	if (EnableSizeReport) {
		manualReport = true;
		PopupSizeReport();
	}
	else if (opener) opener.DestroyWnd();
}

function setmessage(boxname,newtext) {
	var mesgtext = new getObj(boxname);
	if (mesgtext.obj.value == '' || mesgtext.obj.value == 'enter search terms' || mesgtext.obj.value == 'entrez mots clés' || mesgtext.obj.value == 'הכנס חיפוש' || mesgtext.obj.value == '検索する語を入力' || mesgtext.obj.value == 'Suchbegriff eingeben' || mesgtext.obj.value == 'ввести термин' || mesgtext.obj.value == 'Please subscribe me to your newsletter.' || mesgtext.obj.value == 'Please update my contact details.' || mesgtext.obj.value == 'I am considering placing an order; please contact me.' || mesgtext.obj.value == 'Please call me back.' || mesgtext.obj.value == 'Please provide details here.')  mesgtext.obj.value = newtext;
}

function changecolor() {
	var box = new getObj('q');
	box.obj.style.color = "#444";
}


