/*=========================================================================================
	four seasons javascript library


	2005-09-16
	this library contains javascript functions
	in the following groupings:
	
		misc utility functions 
		cookie library 
		font resize library 
		rollover library 
		gallery thumbnail scrolling 
		email this page					// BUGFIX ID 7
		startup and shutdown calls 		// BUGFIX ID 13

==========================================================================================*/

/*=========================================================================================
	email collection (pleac)			
==========================================================================================*/

var emailCollectionDivObject;					// html object reference - value is set later
var emailCollectionDivID = "emailCollection";			// html ID of email form
var emailCollectionViewerID = "emailCollectionViewer"; 		// html ID of viewer div surrounding email form

/*------------------------------------------------------------
*  Function:  emailCollectionForm
*  
*  Description:
*  sets position of email form and calls scrolling function
*  called when user clicks email this page button in page tools module
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function emailCollectionForm(page_name,pleac_left_nav_item_id, property_name, property_id,property_short_url) {
	// only run if email form isn't already showing
	if (getObject(emailCollectionViewerID).style.visibility != "inherit") 
	{
	
	
	
		// Using prototype.js framework to retrieve confirmation page.
		var ajaxUpdater = new Ajax.Updater(
			getObject(emailCollectionViewerID),
			"/apps/email_collection/form.weml",
			{
				method:		'get',
				onComplete:	gotEmailCollectionForm,
				parameters:     "page_name=" + escape(page_name) + "&pleac_left_nav_item_id=" + escape(pleac_left_nav_item_id) + "&property_name=" + escape(property_name)  + "&property_id=" + escape(property_id)  + "&property_short_url=" + escape(property_short_url)
				
			}
		);

		
		hide_select_fields_for_email_collection("hidden");
		
	}
}

/*------------------------------------------------------------
*  Function:  gotEmailCollectionForm
*  
*  Description:
*  Event handler for successful completion of call to
*  AJAX.Updater that loads the email form into the emailThisPage div. 
*  
*
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function gotEmailCollectionForm() 
{
	emailCollectionDivObject = getObject(emailCollectionDivID);

	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var scrolled_pixels_left=document.all? iebody.scrollLeft : pageXOffset
	var scrolled_pixels_top=document.all? iebody.scrollTop : pageYOffset
		
		
	if (window.innerHeight) // all except Explorer
	{
		//x = window.innerWidth;
		y = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		//x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		//x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	x = getObject(emailCollectionViewerID).offsetWidth;
	
	var margin_top = scrolled_pixels_top + Math.floor((y-emailCollectionDivObject.offsetHeight)/2);
	var margin_left = scrolled_pixels_left + Math.floor((x-emailCollectionDivObject.offsetWidth)/2);
	
	emailCollectionDivObject.style.top = margin_top + "px";
	emailCollectionDivObject.style.left = margin_left + "px";
	
	show(emailCollectionViewerID);
	
	//alert("x: " + x + "\ny: " + y + "\nemailCollectionDivObject.offsetWidth: " + emailCollectionDivObject.offsetWidth + "\nemailCollectionDivObject.offsetHeight: " + emailCollectionDivObject.offsetHeight + "\nscrolled_pixels_top: " + scrolled_pixels_top + "\nscrolled_pixels_left: " + scrolled_pixels_left + "\nmargin_top: " + margin_top + "\nmargin_left: " + margin_left + "\n");
	
}


/*------------------------------------------------------------
*  Function:  hideEmailCollection
*  
*  Description:
*  hides email form when user clicks close window or cancel button
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hideEmailCollection() {
	
	hide(emailCollectionViewerID);
	
	// unfreeze email button
	//getObject('ptm_email').className = UNFROZEN_CLASS;
	//rollovers['ptm_email'].frozen = false;
	//imgOff('ptm_email');

	hide_select_fields_for_email_collection("visible");

}

/* begin BUGFIX ID 7 */
var pageURL = "";		// Placeholder for URL of page being e-mailed

/*------------------------------------------------------------
*  Function:  submitEmailCollection
*  
*  Description:
*  Submit handler for E-mail this page form.  Provides
*  temporary simulation of an e-mail confirmation.  To be
*  replaced with proper form validation and submission.
*  
*  Parameters:
*  which	object	the e-mail form being submitted
*  formPage	object	the E-mail this form page
*  
*  Return:
*  none
*------------------------------------------------------------*/
function submitEmailCollection(which, formPage) {
	
	if(!(the_form = $(emailCollectionDivID)))
	{
		alert("Email Collection Submission failed.\nCould not find form object");
		return;
	}
	
	params = Form.serialize(the_form);
	
	// Using prototype.js framework to retrieve confirmation page.
	var ajaxUpdater = new Ajax.Updater(
		formPage,
		"/apps/email_collection/submit.weml",
		{
			method:		'post',
			//onComplete:	displayURL,
			parameters:     params
		}
	);
	
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var scrolled_pixels_left=document.all? iebody.scrollLeft : pageXOffset
	var scrolled_pixels_top=document.all? iebody.scrollTop : pageYOffset
	//alert("scrolled_pixels_top: " + scrolled_pixels_top + "\n");
	
}

function clearEmailCollectionForm(the_form){

	the_form.prefix.value="";
	the_form.first_name.value="";
	the_form.last_name.value="";
	the_form.email_address.value="";

}



/*------------------------------------------------------------
*  Function:  hide_select_fields_for_email_collection
*  
*  Description:
*  
*  
*  
*  Parameters:
*  visible_style = visible or hidden
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide_select_fields_for_email_collection(visible_style)
{

	var emailUA = navigator.userAgent.toLowerCase();
	var emailIsIE = ( (emailUA.indexOf("msie") != -1) && (emailUA.indexOf("opera") == -1) && (emailUA.indexOf("webtv") == -1) );
	if(emailIsIE)
	{
		var emailVer = parseFloat(navigator.appVersion); 

		// correct version number for IE4+ 
		if (emailVer >= 4)
			emailVer = parseFloat( emailUA.substring( emailUA.indexOf('msie ') + 5 ) );

		if (emailVer < 7)
		{
			var select_tag_items = document.getElementsByTagName('select');
			for (var i = 0; i < select_tag_items.length; i++)
				select_tag_items[i].style.visibility = visible_style;
		}
	}

}

/*------------------------------------------------------------
*  Function:  email_collection_prefix_onchange
*  
*  Description:
*  
*  
*  
*  Parameters:
*  
*  
*  Return:
*  none
*------------------------------------------------------------*/

function email_collection_prefix_onchange(elem) {
	index = elem.selectedIndex;
	prefix = elem.options[index].innerHTML;
	if (prefix == 'Other ...')
	document.getElementById("custom_prefix_row").style.display = '';
	else
	document.getElementById("custom_prefix_row").style.display = 'none';
}



/*=========================================================================================
	misc utility functions
==========================================================================================*/



/*------------------------------------------------------------
*  Function:  parseQuery
*  
*  Description:
*  allows us to set javascript variables by passing them in as
*  values in the query string. by default it looks for the
*  query string after the occurrence of '?' in URL of the
*  current document
*  
*  Parameters:
*  loc		string	url to search for query string
*  key		string	string which delimits query string from rest of URL
*  
*  Return:
*  none
*------------------------------------------------------------*/
function parseQuery(loc,key) {
	if (loc == null) loc = document.location.href;
	if (key == null) key = '?';
	if (loc.indexOf(key) > -1) {
		query = loc.substring(loc.indexOf(key)+key.length,loc.length);
		args = query.split('\&');
		for (i=0; i<args.length; i++) {
			chunk = args[i];
			eval(chunk.split('=')[0] + " = '" + chunk.split('=')[1] + "'");
		}
	}
}



/*------------------------------------------------------------
*  Function:  newImage
*  
*  Description:
*  accepts a path to an image file. creates a new image object
*  and stuffs the src. used by the rollover framework
*  
*  Parameters:
*  arg		string	path to image file
*  
*  Return:
*  rslt		image object
*------------------------------------------------------------*/
function newImage(arg) {
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}




/*------------------------------------------------------------
*  Function:  openPopupWindow
*  
*  Description:
*  opens a popup window of a passed width and height
*  and loads the passed URL in it
*  
*  Parameters:
*  url			string		page to load
*  w			integer		width of popup window
*  h			integer		height of popup window
*  features		string		window features - see below for defaults
*  
*  Return:
*  none
*------------------------------------------------------------*/
var popupWindow=null;

function openPopupWindow(url,w,h,features) {
	if (w == null || w=='') w = 400;
	if (h == null || h=='') h = 400;
	if (features == null) features = ",menubar=0,status=0,location=0,directories=0,resizable=1,scrollbars=1";
	
	if (url) {

		if ( (popupWindow!=null) && !popupWindow.closed && popupWindow.location ){
			popupWindow.location.href = url;
			popupWindow.focus();
		} else {
			popupWindow = window.open(url,'popupWindow','width='+w+',height='+h+features);
			popupWindow.focus();
			if (!popupWindow.opener) popupWindow.opener = self;
		}

	}
}




/*------------------------------------------------------------
*  Function:  resizeWindow
*  
*  Description:
*  resizes a window to a given width and height
*  by default, will only resize if the window is smaller than the prescribed width and/or height
*  if forceResize is passed in as true, it will force the window to the desired size
*  
*  Parameters:
*  w				integer	desired width
*  h				integer	desired height
*  forceResize		boolean	if true, forces large window to resize down to desired size
*  
*  Return:
*  none
*------------------------------------------------------------*/
function resizeWindow(w,h,forceResize) {
	if (window.innerWidth && window.innerHeight) {
		var wdiff = window.outerWidth - window.innerWidth;
		var hdiff = window.outerHeight - window.innerHeight;
		
		var windowIsSmaller = false;
		if (window.innerWidth < w) {
			endw = w + wdiff;
			windowIsSmaller = true;
		} else {
			endw = window.outerWidth;
		}
		if (window.innerHeight < h) {
			endh = h + hdiff;
			windowIsSmaller = true;
		} else {
			endh = window.outerHeight;
		}
		if (forceResize) {
			endw = w + wdiff;
			endh = h + hdiff;
		}
		
		if (windowIsSmaller || forceResize) self.resizeTo(endw,endh);
	} else {
		// can't do it the nice way
		// add padding for scrollbar in IE6
		self.resizeTo(w + 30,h);
	}
}



/*------------------------------------------------------------
*  Function:  dw
*  
*  Description:
*  shorthand for document.write
*  
*  Parameters:
*  msg		string	text to be written
*  
*  Return:
*  none
*------------------------------------------------------------*/
function dw(msg) {
	document.write(msg);
}



/*------------------------------------------------------------
*  Function:  randomNum
*  
*  Description:
*  returns a random number in the specified range of numbers, inclusive
*  
*  Parameters:
*  start	integer	first number in desired range
*  end		integer	last number in desired range
*  
*  Return:
*  n		integer
*------------------------------------------------------------*/
function randomNum(start,end) {
	var range = end - start + 1;
	var n = Math.floor(Math.random() * (range)) + start;
	return(n);
}




/*------------------------------------------------------------
*  Function:  getObject
*  
*  Description:
*  accepts an object reference or a string, returns an object reference
*  
*  Parameters:
*  which	string or object	ID of HTML dom entity, or reference to an object
*  
*  Return:
*  obj		object				reference to named or passed DOM object
*------------------------------------------------------------*/
function getObject(which) {
	var obj;
	if (typeof(which) == "object") {
		obj = which;
	} else if (typeof(which) == "string") {
		obj = document.getElementById(which);
	} else {
		obj = null;
	}
	
	return obj;
}



/*------------------------------------------------------------
*  Function:  show
*  
*  Description:
*  shows an object, if not nested in a hidden object
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function show(which) {
	var obj = getObject(which);
	if (obj) obj.style.visibility = "inherit";
}



/*------------------------------------------------------------
*  Function:  hide
*  
*  Description:
*  hides an object from display
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide(which) {
	var obj = getObject(which);
	if (obj) obj.style.visibility = "hidden";
}




/*------------------------------------------------------------
*  Function:  toggleNavMenu
*  
*  Description:
*  this is used for the dhtml menus in the left nav
*  this function accepts a reference to an anchor link
*  it assumes the anchor link to be nested in a paragraph, nested in a menu div
*  it toggles the state of that menu div
*  relies on the css class 'open'
*  
*  Parameters:
*  that	object		reference to object this function
*  
*  Return:
*  false	to prevent clicks from bubbling through
*------------------------------------------------------------*/
function toggleNavMenu(that,key) {
	var theMenu = that.parentNode.parentNode;
	if (theMenu.className.indexOf(' open') > -1) {
		theMenu.className = theMenu.className.substring(0,theMenu.className.indexOf(' open'));
		setMenuClosed(key);
	} else {
		theMenu.className = theMenu.className + ' open';
		setMenuOpen(key);
	}
	
	return false;
}

/*------------------------------------------------------------
*  Function:  isMenuOpen
*  
*  Description:
*  
*  Parameters:
*  key on menu - key consists of PropertyID_LHN Id
*  
*  Return:
*  true or false  - true Cookie denotes menu should remain open
*------------------------------------------------------------*/
function isMenuOpen(key) {
	if(key)
	{
		var qs_open = getCookie(TWIZZLER_COOKIE);
		if(jsQSGet(qs_open,key))
			return true;
	}
	
	return false;
}

/*------------------------------------------------------------
*  Function:  setMenuOpen
*  
*  Description:
*  
*  Parameters:
*  key on menu - key consists of PropertyID_LHN Id
*  
*  Return:
*  true or false  - true Cookie denotes menu should remain open
*------------------------------------------------------------*/
function setMenuOpen(key) {
	if(key)
	{
		var qs_open = getCookie(TWIZZLER_COOKIE);
		qs_open = jsQSSet(qs_open,key,'open');
		setCookie(TWIZZLER_COOKIE, qs_open, "", "/");
	}
}

/*------------------------------------------------------------
*  Function:  setMenuClosed
*  
*  Description:
*  
*  Parameters:
*  key on menu - key consists of PropertyID_LHN Id
*  
*  Return:
*  true or false  - true Cookie denotes menu should remain open
*------------------------------------------------------------*/
function setMenuClosed(key) {
	if(key)
		var qs_open = getCookie(TWIZZLER_COOKIE);
		qs_open = jsQSSet(qs_open,key,'');
		setCookie(TWIZZLER_COOKIE, qs_open, "", "/");
}

/*------------------------------------------------------------
*  Function:  jsQSGet
*  
*  Description:
*  
*  Parameters:
*  key on menu - key consists of PropertyID_LHN Id
*  
*  Return:
*  true or false  - true Cookie denotes menu should remain open
*------------------------------------------------------------*/
function jsQSGet(qs,field) {

	if((!qs) || (!field))
		return '';

	var field_found = qs.indexOf('&' + field + '=');
	if(field_found>-1)
	{
		qs = qs.substring(field_found + field.length + 2);
		var value = qs.split("&");
		
		return qs = unescape(value[0]);
	}

	return '';
}

/*------------------------------------------------------------
*  Function:  jsQSSet
*  
*  Description:
*  
*  Parameters:
*  key on menu - key consists of PropertyID_LHN Id
*  
*  Return:
*  true or false  - true Cookie denotes menu should remain open
*------------------------------------------------------------*/
function jsQSSet(qs,field,value) {
	
	if(!field)
		return qs;

	var new_qs = '';

	var field_found = qs.indexOf('&' + field + '=');
	if(field_found>-1)
	{
		new_qs = qs.substring(0,field_found);
		qs = qs.substring(field_found + field.length + 2);
		var seperator_found = qs.indexOf('&');
		if(seperator_found>-1)
			new_qs = new_qs + qs.substring(seperator_found);
	}
	else
	{
		new_qs = qs;
	}

	if(value)
		new_qs = new_qs + '&' + field + '=' + escape(value);

	return new_qs;
}

/*=========================================================================================
	end misc utility functions
==========================================================================================*/




/*=========================================================================================
	cookie library
==========================================================================================*/


/*------------------------------------------------------------
*  Function:  getExpDate
*  
*  Description:
*  utility function to retrieve an expiration date in proper format
*  pass three integer parameters for the number of days, hours,
*  and minutes from now you want the cookie to expire (or
*  negative values for a past date)
*  all three parameters are required, so use zeros where appropriate
*  
*  Parameters:
*  days	integer
*  hours	integer
*  minutes	integer
*  
*  Return:
*  date	string
*------------------------------------------------------------*/
function getExpDate(days, hours, minutes) {
	var expDate = new Date();
	if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number") {
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}


/*------------------------------------------------------------
*  Function:  getCookieVal
*  
*  Description:
*  utility function called by getCookie()
*  
*  Parameters:
*  offset	string
*  
*  Return:
*  cookie	string
*------------------------------------------------------------*/
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

// 


/*------------------------------------------------------------
*  Function:  getCookie
*  
*  Description:
*  primary function to retrieve cookie by name
*  
*  Parameters:
*  name	string	name of cookie to be retrieved
*  
*  Return:
*  value	string	value of named cookie
*------------------------------------------------------------*/
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return "";
}



/*------------------------------------------------------------
*  Function:  setCookie
*  
*  Description:
*  store cookie value with optional details as needed
*  
*  Parameters:
*  name	string
*  value	string
*  expires	string
*  path	string
*  domain	string
*  secure	boolean
*  
*  Return:
*  none
*------------------------------------------------------------*/
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}




/*------------------------------------------------------------
*  Function:  deleteCookie
*  
*  Description:
*  remove the cookie by setting ancient expiration date
*  
*  Parameters:
*  name	string
*  path	string
*  domain	string
*  
*  Return:
*  none
*------------------------------------------------------------*/
function deleteCookie(name,path,domain) {
	/* BUGFIX ID 25 */
	if (getCookie(name) != "") {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/*=========================================================================================
	end cookie library
==========================================================================================*/



/* begin BUGFIX ID 13 */
/*=========================================================================================
	font resize library
==========================================================================================*/

var styles = new Array();		// Global style array for storing all available stylesheets.

var DEFAULT_STYLE = 2;			// Index of default style.  In this case, "Normal Fonts".

var STYLE_COOKIE = "FSStyle";	// Name of cookie to store ID of active stylesheet.

var TWIZZLER_COOKIE = "FSTwizzler";  // Name of cookie to store open/close status of LHN menus

var INCREASE_BTN = "ptm_fontLarger";		// ID of font increase button
var DECREASE_BTN = "ptm_fontSmaller";		// ID of font decrease button

var INCREASE_BTN_TITLE = "";		// Tooltip for the font increase button
var DECREASE_BTN_TITLE = "";		// Tooltip for the font decrease button

// as necessary, buttons can be 'frozen' to keep them in a certain state
// and to prevent rollovers from affecting them until unfrozen
var FROZEN_CLASS = "buttonImg frozen";		// class for frozen buttons
var UNFROZEN_CLASS = "buttonImg";			// class for unfrozen buttons



/*------------------------------------------------------------
*  Function:  loadStyles
*  
*  Description:
*  Stores available stylesheets (with titles) in an array
*  for tracking.  Styles are ordered in alphabetical order
*  by ID.
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function loadStyles() {
	var linkElements = document.getElementsByTagName("link");
	
	for (var i = 0; i < linkElements.length; i++) {
	
		var linkElement = linkElements[i];
		
		if (linkElement.getAttribute("rel").indexOf("style") != -1
			&& linkElement.getAttribute("title")) {
			styles[styles.length] = linkElement;
		}
	}
	
	styles.sort(compareById);
}



/*------------------------------------------------------------
*  Function:  compareById
*  
*  Description:
*  Comparison function for alphabetic comparison of DOM
*  elements by ID.
*  
*  Parameters:
*  elementA		element		First element to compare
*  elementB		element		Second element to compare
*  
*  Return:
*  integer		-1 (b is greater), 0 (a == b), 1 (a is greater)
*------------------------------------------------------------*/
function compareById(elementA, elementB) {
	if (elementA.id > elementB.id) {
		return 1;
	} else if (elementA.id == elementB.id) {
		return 0;
	} else {
		return -1;
	}
}



/*------------------------------------------------------------
*  Function:  getStyleFromCookie
*  
*  Description:
*  Determines the stylesheet to activate from a cookie.  Assumes
*  styles have been loaded into global style array.  The ID of
*  the stylesheet is used to identify the style.
*  
*  Parameters:
*  none
*  
*  Return:
*  integer		The index of the stylesheet in styles array.
*------------------------------------------------------------*/
function getStyleFromCookie() {
	var style = getCookie(STYLE_COOKIE);
	
	for (var i = 0; i < styles.length; i++) {
		if (styles[i].id == style) {
			return i;
		}
	}

	return DEFAULT_STYLE;
}



/*------------------------------------------------------------
*  Function:  setStyleInCookie
*  
*  Description:
*  Saves the ID of the active stylesheet in a cookie.  Assumes
*  styles have been loaded into global style array.
*  
*  Parameters:
*  styleNum		integer		The index of the style in the global
*							styles array.
*  
*  Return:
*  none
*------------------------------------------------------------*/
function setStyleInCookie(styleNum) {
	var exp = new Date();			// expiration date
	
	/* begin BUGFIX ID 25 */
	/* Set expiration for next year */
	exp.setTime(exp.getTime() + (365 * 24 * 60 * 60 * 1000));
	
	if (styles[styleNum]) {
		setCookie(STYLE_COOKIE, styles[styleNum].id, exp, "/");
	}
	/* end BUGFIX ID 25 */
}



/*------------------------------------------------------------
*  Function:  getActiveStyle
*  
*  Description:
*  Determines the active stylesheet.  Assumes styles have been
*  loaded into global style array.
*  
*  Parameters:
*  none
*  
*  Return:
*  integer		The index of the active stylesheet in styles array.
*------------------------------------------------------------*/
function getActiveStyle() {
	for (var i = 0; i < styles.length; i++) {
		if (!styles[i].disabled) {
			return i;
		}
	}

	return DEFAULT_STYLE;
}



/*------------------------------------------------------------
*  Function:  setActiveStyle
*  
*  Description:
*  Sets the active stylesheet.  Assumes styles have been
*  loaded into global style array.
*  
*  Parameters:
*  styleNum		integer		The index of the style in the global
*							styles array to activate.
*  
*  Return:
*  none
*------------------------------------------------------------*/
function setActiveStyle(styleNum) {
	// MSIE does not handle disabled property correctly.
	// We must manually set this property for all stylesheets.
	// Also, MSIE does not update the styles unless
	// there is a change.  So we must first disable the active
	// stylesheet.
	for (var i = 0; i < styles.length; i++) {
		styles[i].disabled = true;
	}

	// Now we can enable the stylsheet we want.
	styles[styleNum].disabled = false;
}



/*------------------------------------------------------------
*  Function:  getNextStyle
*  
*  Description:
*  Determines the index of the next style in the style array.  Assumes
*  styles have been loaded into global style array.  Last style
*  returns itself.
*  
*  Parameters:
*  none
*  
*  Return:
*  integer		Index of the next style
*------------------------------------------------------------*/
function getNextStyle() {
	var styleNum = getActiveStyle();
	if (styleNum >= (styles.length - 1)) {
		return styleNum;
	} else {
		return ++styleNum;
	}
}



/*------------------------------------------------------------
*  Function:  getPrevStyle
*  
*  Description:
*  Determines the index of the previous style in the style array.  Assumes
*  styles have been loaded into global style array.  First style
*  returns itself.
*  
*  Parameters:
*  none
*  
*  Return:
*  integer		Index of the previous style
*------------------------------------------------------------*/
function getPrevStyle() {
	var styleNum = getActiveStyle();
	return (styleNum > 0) ? --styleNum : 0;
}



/*------------------------------------------------------------
*  Function:  increaseFont
*  
*  Description:
*  Increases the size of the fonts in the main content area of
*  the page by changing stylesheets.  Assumes styles have been
*  loaded into global style array.  Also assumes styles are
*  ordered in style array from smallest font to largest font.
*  Saves the active style in a cookie.
*  
*  Parameters:
*  none
*  
*  Return:
*  false
*------------------------------------------------------------*/
function increaseFont() {
	var styleNum = getNextStyle();
	setActiveStyle(styleNum);
	setFontControls(styleNum);
	setStyleInCookie(styleNum);
	return false;
}



/*------------------------------------------------------------
*  Function:  decreaseFont
*  
*  Description:
*  Decreases the size of the fonts in the main content area of
*  the page by changing stylesheets.  Assumes styles have been
*  loaded into global style array.  Also assumes styles are
*  ordered in style array from smallest font to largest font.
*  Saves the active style in a cookie.
*  
*  Parameters:
*  none
*  
*  Return:
*  false
*------------------------------------------------------------*/
function decreaseFont() {
	var styleNum = getPrevStyle();
	setActiveStyle(styleNum);
	setFontControls(styleNum);
	setStyleInCookie(styleNum);
	return false;
}



/*------------------------------------------------------------
*  Function:  setFontControls
*  
*  Description:
*  Enables and disables font controls on the page.  Assumes
*  styles have been loaded into global style array.  Also
*  assumes styles are ordered in style array from smallest to
*  largest font.  If smallest font is enabled, disables the
*  decrease font control.  If largest font is enabled, disables
*  the increase font control.
*  
*  Parameters:
*  styleNum		integer		The index of the style in the global
*							styles array.
*  
*  Return:
*  none
*------------------------------------------------------------*/
function setFontControls(styleNum) {
	
	var increaseFontBtn = getObject(INCREASE_BTN);
	var decreaseFontBtn = getObject(DECREASE_BTN);
	
	if (increaseFontBtn) {
		if (styleNum >= (styles.length - 1)) {
			disableButton(increaseFontBtn);
		} else {
			enableButton(increaseFontBtn, INCREASE_BTN_TITLE);
		}
	}
	
	if (decreaseFontBtn) {
		if (styleNum <= 0) {
			disableButton(decreaseFontBtn);
		} else {
			enableButton(decreaseFontBtn, DECREASE_BTN_TITLE);
		}
	}
}



/*------------------------------------------------------------
*  Function:  disableButton
*  
*  Description:
*  Disables a button element.  For use with font controls.
*  
*  Parameters:
*  button	object	The button to disable
*  
*  Return:
*  none
*------------------------------------------------------------*/
function disableButton(button) {
	imgSwap(button.id,'disabled');			// Display disabled image
	rollovers[button.id].frozen = true;		// Turn off rollovers
	button.className = FROZEN_CLASS;			// Set disabled class
	button.title = "";						// Remove tooltip
}



/*------------------------------------------------------------
*  Function:  enableButton
*  
*  Description:
*  Enables a button element.  For use with font controls.
*  
*  Parameters:
*  button	object	The button to enable
*  titleStr	string	The tooltip text of the button
*  
*  Return:
*  none
*------------------------------------------------------------*/
function enableButton(button, titleStr) {
	rollovers[button.id].frozen = false;	// Turn on rollovers
	imgOff(button.id);						// Display off image
	button.className = UNFROZEN_CLASS;		// Set enabled class
	button.title = titleStr;				// Set tooltip
}

/*=========================================================================================
	end font resize library
==========================================================================================*/
/* end BUGFIX ID 13 */



/*=========================================================================================
	rollover library
==========================================================================================*/

// array used to store rollover states and image data
var rollovers = new Array();


/*------------------------------------------------------------
*  Function:  imgOn, imgOver, imgOff
*  
*  Description:
*  shorthand functions for calling imgSwap
*  
*  Parameters:
*  which	string 	name of image to swap
*  
*  Return:
*  none
*------------------------------------------------------------*/
function imgOn(which) {
	imgSwap(which,'on');
}

function imgOver(which) {
	imgSwap(which,'over');
}

function imgOff(which) {
	imgSwap(which,'off');
}



/*------------------------------------------------------------
*  Function:  imgSwap
*  
*  Description:
*  stub function for rollovers
*  expects an image name and state
*  checks for existence of named image, and defined state
*  also checks to see if image has been disabled -- this is used to freeze an image in a given state
*  
*  Parameters:
*  which	string 	name of image to swap
*  state	string	name of state to swap to
*  
*  Return:
*  none
*------------------------------------------------------------*/
function imgSwap(which,state) {
	if (which && rollovers[which]) {
		if (document.images[which] && eval('rollovers[which].states.' + state)) {
			if (! rollovers[which].frozen) {
				document.images[which].src = eval('rollovers[which].states.' + state).src;
			}
		}
	}
}


/*------------------------------------------------------------
*  Function:  newRollover
*  
*  Description:
*  this function populates the rollovers array with the image
*  objects used for the various states of a rollover
*  
*  Parameters:
*  name		string	name of image object
*  offsrc		string	path to image file for off (normal) state
*  oversrc		string	path to image file for over state
*  onsrc		string	path to image file for on (selected) state
*  disabledsrc	string	path to image file for disabled state
*  
*  Return:
*  none
*------------------------------------------------------------*/
function newRollover(name,offsrc,oversrc,onsrc,disabledsrc) {
	rollovers[name] = new Object();
	rollovers[name].states = new Object();
	rollovers[name].states.off = (offsrc) ? newImage(offsrc) : null;
	rollovers[name].states.over = (oversrc) ? newImage(oversrc) : null;
	rollovers[name].states.on = (onsrc) ? newImage(onsrc) : null;
	rollovers[name].states.disabled = (disabledsrc) ? newImage(disabledsrc) : null;
	// the following variable is used to prevent an image from being changed on rollover
	// used for disabling images that are in a disabled or selected state and shouldn't change
	rollovers[name].frozen = false;
}


/*=========================================================================================
	end rollover library
==========================================================================================*/



/*=========================================================================================
	gallery thumbnail scrolling
==========================================================================================*/


// gallery variables
var galleryId = "photoThumbsTable";			// id of gallery html object
var viewerId = "photoThumbsViewer";			// id of div enclosing gallery html object
var galleryLeft = 0;						// Gallery offset
var scrollDir = "none";						// Scroll flag.	 Either left, right, or none
var galleryInterval;						// Timeout interval Id
var galleryScrollIncrement = 5;				// gallery scrolling increment

// css IDs of arrow html objects
var photoArrowLeftId = "photoArrowLeft";
var photoArrowRightId = "photoArrowRight";




/*------------------------------------------------------------
*  Function:  scrollForward
*  
*  Description:
*  Starts scroll to the right
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function scrollForward() {
	scrollDir = "right";	// Set flag
	scrollGallery();		// Now scroll
}



/*------------------------------------------------------------
*  Function:  scrollBack
*  
*  Description:
*  Starts scroll to the left
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function scrollBack() {
	scrollDir = "left";		// Set flag
	scrollGallery();		// Now scroll
}



/*------------------------------------------------------------
*  Function:  scrollNone
*  
*  Description:
*  Stops scrolling
*  
*  Parameters:
*  none
*  
*  Return:
*  false
*------------------------------------------------------------*/
function scrollNone() {
	scrollDir = "none"; // Reset flag
	return false;
}



/*------------------------------------------------------------
*  Function:  scrollGallery
*  
*  Description:
*  does the actual work of scrolling
*  calls itself until user mouses up or gallery reaches left or right edge
*  relies on the scrollDir variable set in the above functions
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function scrollGallery() {
	var gallery = getObject(galleryId);
	var galleryWidth = gallery.offsetWidth;
	var viewerWidth = getObject(viewerId).offsetWidth;
	
	switch (scrollDir) {
		// Scroll right
		case "right":

			// Only scroll right if right edge is not aligned with right side
			if (galleryLeft > (viewerWidth - galleryWidth)) {
				galleryLeft -= galleryScrollIncrement;
				
				// check bounds
				if (galleryLeft < (viewerWidth - galleryWidth)) galleryLeft = (viewerWidth - galleryWidth);
				gallery.style.left = galleryLeft + "px";

				// Wait to see if flag is reset. Otherwise, keep scrolling
				galleryInterval = setTimeout("scrollGallery()", 10);
			} else {

				// Gallery is flush right.	Stop scrolling
				clearTimeout(galleryInterval);
			}
			break;

		// Scroll left
		case "left":
			// Only scroll left if left edge is not aligned 0
			if (galleryLeft < 0) {
				galleryLeft += galleryScrollIncrement;
				
				// check bounds
				if (galleryLeft > 0) galleryLeft = 0;
				gallery.style.left = galleryLeft + "px";

				// Wait to see if flag is reset. Otherwise, keep scrolling
				galleryInterval = setTimeout("scrollGallery()", 10);
			} else {

				// Gallery is flush left.  Stop scrolling
				clearTimeout(galleryInterval);
			}
			break;

		// Flag not set.  Stop scrolling
		default:
			clearTimeout(galleryInterval);
	}
	
	checkArrows();
}



/*------------------------------------------------------------
*  Function:  checkArrows
*  
*  Description:
*  checks the state of the gallery scroller and enables or disables the arrows accordingly
*  this function is called by the gallery scroller
*  but it should also be called on startup to set the initial arrow state
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function checkArrows() {
	var gallery = getObject(galleryId);
	var arrowLeft = getObject(photoArrowLeftId);
	var arrowRight = getObject(photoArrowRightId);
	
	if (gallery && arrowLeft && arrowRight) {
		var galleryWidth = gallery.offsetWidth;
		var viewerWidth = getObject(viewerId).offsetWidth;
	
		// if gallery is wider than viewer window, check the arrows
		if (galleryWidth > viewerWidth) {
			//if left edge is hidden, enable left arrow
			arrowLeft.className = (galleryLeft < 0 ) ? "enabled" : "";
			arrowLeft.title = (galleryLeft < 0 ) ? "Scroll left" : "";
			
			// if right edge is hidden, enable right arrow
			arrowRight.className = (galleryLeft > (viewerWidth - galleryWidth)) ? "enabled" : "";
			arrowRight.title = (galleryLeft > (viewerWidth - galleryWidth)) ? "Scroll right" : "";
	
		// gallery isn't wide enough to scroll - disable both arrows
		} else {
			arrowLeft.className = "";
			arrowRight.className = "";
		}
	}
}

/*=========================================================================================
	end gallery thumbnail scrolling
==========================================================================================*/



/*=========================================================================================
	gallery image swapping
==========================================================================================*/


var galleryPhotos = new Array();		// array used to store gallery photo image data and captions

var photoPaneID = "photoPane";			// html ID of div where large image tag will be written
var photoCaptionID = "photoCaption";	// html ID of div where image caption will be written

String.prototype.substitute = function(was, becomes) {
	return this.split(was).join(becomes);
}

/*------------------------------------------------------------
*  Function:  media_widget_show_current_zoomed_out
*  
*  Description:
*  shows fully zoomed out large version of the current thumbnail
*  also generates an accompanying image map for flashpix zooming.
*------------------------------------------------------------*/
function media_widget_show_current_zoomed_out() 
{
	
	
	var thePhotoDiv = getObject(photoPaneID);
	if(!thePhotoDiv){alert("Error: Could not find photo div to zoom out.");return;}

	current_img = galleryPhotos[currentThumbIndex].img;

	if(!current_img.complete)
	{
		setTimeout("media_widget_show_current_zoomed_out()",500);
		return;
	}

	
	path = current_img.src.toString().split('/');
	codes = path[(path.length)-1].toString().split("_")
	flashpix_path = "/image_library/" + codes[0] + "/" + codes[0] + codes[1] + ".fpx";
	
	if(current_img.width > current_img.height)
		this_image_specs = new Array("0,0,150,120:0.0000,0.0000,0.5000,0.5000", "0,120,150,200:0.0000,0.2500,0.5000,0.5000", "0,200,150,320:0.0000,0.5000,0.5000,0.5000", "150,0,250,120:0.2500,0.0000,0.5000,0.5000", "150,120,250,200:0.2500,0.2500,0.5000,0.5000", "150,200,250,320:0.2500,0.5000,0.5000,0.5000", "250,0,400,120:0.5000,0.0000,0.5000,0.5000", "250,120,400,200:0.5000,0.2500,0.5000,0.5000", "250,200,400,320:0.5000,0.5000,0.5000,0.5000");
	else
		this_image_specs = new Array("0,0,120,150:0.000000,0.000000,0.500000,0.500000","0,150,120,250:0.000000,0.250000,0.500000,0.500000","0,250,120,400:0.000000,0.500000,0.500000,0.500000","120,0,200,150:0.250000,0.000000,0.500000,0.500000","120,150,200,250:0.250000,0.250000,0.500000,0.500000","120,250,200,400:0.250000,0.500000,0.500000,0.500000","200,0,320,150:0.500000,0.000000,0.500000,0.500000","200,150,320,250:0.500000,0.250000,0.500000,0.500000","200,250,320,400:0.500000,0.500000,0.500000,0.500000");
	
	
	hover_text = galleryPhotos[currentThumbIndex].hover_text;
	zoomed_out_source = '<img src="' + galleryPhotos[currentThumbIndex].img.src + '" alt="'+hover_text+'" title="'+hover_text+'" border="0" hspace="0" usemap="#map_' + currentThumbIndex +  '"/>'
	zoomed_out_source += '<map name="map_' + currentThumbIndex + '">';
	
	for(i=0; i<this_image_specs.length; i++)
	{
		specs = this_image_specs[i].toString().split(':');
		if(hover_text.indexOf("'")>-1)
			hover_text = hover_text.substitute("'","`");
		zoomed_out_source += "<area shape=\"rect\" coords=\"" +specs[0] + "\"  alt=\"" + hover_text + "\"  title=\"" + hover_text + "\"  href=\"javascript:media_widget_load_href('/apps/flashpix/zoom.weml','picture=" + flashpix_path + "&zoomLevel=1&rgn=" + specs[1] + "&wid=" + current_img.width + "&hei=" + current_img.height + "&hover_text=" + escape(hover_text) + "')\">"
	}
	zoomed_out_source += "</map>"
	
	thePhotoDiv.innerHTML = zoomed_out_source;
}


/*------------------------------------------------------------
*  Function:  media_widget_load_href
*  
*  Description:
*  Does an ajax-style reload of the photoPane div, to hold the zoomed image plus it's image map
*
*  20071130|Jacquie|set method to post and unescape(@pars) for non latin based languages AR, JP, and ZH  tm 12921
*------------------------------------------------------------*/
function media_widget_load_href(new_href, pars)
{
	var ajaxUpdater = new Ajax.Updater
	(
		photoPaneID,
		new_href,
		{
			method:		'post',
			parameters:  	unescape(pars)
		}
	);
}

function failed(request)
{
	alert("failed");
}
/*------------------------------------------------------------
*  Function:  newGalleryPhoto
*  
*  Description:
*  creates an entry in the galleryPhotos array for each gallery photo
*  this function is called in the onload handler of each gallery thumb img tag
*  
*  Parameters:
*  which	integer		numeric index of the photo
*  src		string		path to large version of photo
*  caption	string		photo caption
*  
*  Return:
*  none
*------------------------------------------------------------*/
function newGalleryPhoto(which,src,caption, hover_text) {
	galleryPhotos[which] = new Object();
	galleryPhotos[which].img = newImage(src);
	galleryPhotos[which].caption = caption;
	galleryPhotos[which].hover_text = hover_text;
}



/*------------------------------------------------------------
*  Function:  showGalleryPhoto
*  
*  Description:
*  displays the large version of a gallery image
*  called when user clicks on a thumbnail
*  showGalleryPhoto(0) should also be called on startup to load the initial photo
*  
*  Parameters:
*  which	integer		numeric index of the photo
*  
*  Return:
*  none
*------------------------------------------------------------*/
function showGalleryPhoto(which) {
	if (galleryPhotos[which]) {
		var thePhotoDiv = getObject(photoPaneID);
		var theCaptionDiv = getObject(photoCaptionID);
		var theTag = '<img src="' + galleryPhotos[which].img.src + '" alt="'+galleryPhotos[which].caption+'" title="'+galleryPhotos[which].caption+'" border="0" />';
		if (thePhotoDiv) thePhotoDiv.innerHTML = theTag;
		if (theCaptionDiv) theCaptionDiv.innerHTML = galleryPhotos[which].caption;
		
		// turn off last thumb
		if (galleryPhotos.currentThumb) {
			galleryPhotos.currentThumb.className = "";
			galleryPhotos.currentThumb.parentNode.className = "";
		}
		
		// turn on current thumb
		galleryPhotos.currentThumb = getObject('id_' + which);
		galleryPhotos.currentThumb.className = "currentThumb";
		galleryPhotos.currentThumb.parentNode.className = "currentThumb";
		currentThumbIndex=which;
		media_widget_show_current_zoomed_out();
	}
	return false;
}



/*=========================================================================================
	end gallery image swapping
==========================================================================================*/



/*=========================================================================================
	email this page			// BUGFIX ID 7
==========================================================================================*/

var emailFormTop;									// integer used to track position of email form
var emailFormObject;								// html object reference - value is set later
var emailEventHooks = null;
var emailFormID = "emailThisPage";					// html ID of email form
var emailViewerID = "emailThisPageViewer";				// html ID of viewer div surrounding email form
var emailFormInterval;								// timeout variable
var emailScrollIncrements = new Array(40,10,3,1);	// array of scroll increments to create an 'ease out' effect. last item should always be '1'
var emailScrollIncrement = 0;						// index variable to step through the above array



/*------------------------------------------------------------
*  Function:  emailThisPage
*  
*  Description:
*  sets position of email form and calls scrolling function
*  called when user clicks email this page button in page tools module
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function emailThisPage(page_url, page_name, property_name, event_hooks) {

	emailEventHooks = event_hooks;
	
	// only run if email form isn't already showing
	if (getObject(emailViewerID).style.visibility != "inherit") 
	{
		// Using prototype.js framework to retrieve confirmation page.
		var ajaxUpdater = new Ajax.Updater(
			getObject(emailViewerID),
			"/apps/email_this_page/form.weml",
			{
				method:		'get',
				onComplete:	gotEmailForm,
				parameters:     "page_url=" + escape(page_url) + "&page_name=" + escape(page_name) + "&property_name=" + escape(property_name)
			}
		);

		hide_select_fields_for_email_this_page("hidden");

	}
}


/*------------------------------------------------------------
*  Function:  gotEmailForm
*  
*  Description:
*  Event handler for successful completion of call to
*  AJAX.Updater that loads the email form into the emailThisPage div. 
*  
*
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function gotEmailForm() 
{

	if(emailEventHooks) {
	      if(emailEventHooks.on_open) {
          		emailEventHooks.on_open.call(this);
           	}
        }   	
	
	emailFormObject = getObject(emailFormID);

	//move email form upward out of view
	emailFormTop =  0 - (emailFormObject.offsetHeight + 10);
	emailFormObject.style.top = emailFormTop + "px";

	// line below sets height of viewer div to 10px larger than email form
	// may need to increase this value if error messages are inserted into the form
	// or push it out to a separate function that can be called by the error display function
	getObject(emailViewerID).style.height = (emailFormObject.offsetHeight + 10) + "px";
	show(emailViewerID);

	// set email button to selected state and freeze it to prevent rollovers
	imgOn('ptm_email');
	rollovers['ptm_email'].frozen = true;
	getObject('ptm_email').className = FROZEN_CLASS;

	// stuff document URL into hidden field and into form display for user feedback
//	if(getObject('pageURL'))
//		getObject('pageURL').value = document.location.href;
//	if(getObject('pageURLdisplay'))
//		getObject('pageURLdisplay').innerHTML = document.location.href.substring(0,80);

	scrollEmailForm();

	
}


/*------------------------------------------------------------
*  Function:  scrollEmailForm
*  
*  Description:
*  does the work of scrolling the email form
*  uses an array of scroll increments, defined above, to create an ease-out effect
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function scrollEmailForm() {
	var distance = 0 - emailFormTop;

	
	// if distance is less than 3 x current scroll increment, use next increment
	if (distance < emailScrollIncrements[emailScrollIncrement] * 3) {
		emailScrollIncrement++;
	}
	// make sure we don't exceed the bounds
	if (emailScrollIncrement >= emailScrollIncrements.length) emailScrollIncrement = emailScrollIncrements.length - 1;

	
	// Only scroll down if top edge is hidden
	if (emailFormTop < 0) {
		emailFormTop += emailScrollIncrements[emailScrollIncrement];

		// make sure we don't go past zero
		if (emailFormTop > 0) emailFormTop = 0;
		emailFormObject.style.top = emailFormTop + "px";

		// Wait to see if flag is reset. Otherwise, keep scrolling
		emailFormInterval = setTimeout("scrollEmailForm()", 10);
	} else {

		// stop scrolling
		clearTimeout(emailFormInterval);
		emailScrollIncrement = 0;
	}
}




/*------------------------------------------------------------
*  Function:  hideEmailThisPage
*  
*  Description:
*  hides email form when user clicks close window or cancel button
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hideEmailThisPage() {
	
	if(emailEventHooks) {
		if(emailEventHooks.on_close) {
			emailEventHooks.on_close.call(this);
		}
        }   	
	
	
	hide(emailViewerID);
	
	// unfreeze email button
	getObject('ptm_email').className = UNFROZEN_CLASS;
	rollovers['ptm_email'].frozen = false;
	imgOff('ptm_email');

	hide_select_fields_for_email_this_page("visible");

}

/* begin BUGFIX ID 7 */
var pageURL = "";		// Placeholder for URL of page being e-mailed

/*------------------------------------------------------------
*  Function:  submitEmail
*  
*  Description:
*  Submit handler for E-mail this page form.  Provides
*  temporary simulation of an e-mail confirmation.  To be
*  replaced with proper form validation and submission.
*  
*  Parameters:
*  which	object	the e-mail form being submitted
*  formPage	object	the E-mail this form page
*  
*  Return:
*  none
*------------------------------------------------------------*/
function submitEmail(which, formPage) {
	// Retrieve the URL of the page being emailed.
	//pageURL = document.getElementById("pageURL").value;
	
	if(!(the_form = $(emailFormID)))
	{
		alert("Submission failed.\nCould not find form object");
		return;
	}
	
	params = Form.serialize(the_form);
	
	// Using prototype.js framework to retrieve confirmation page.
	var ajaxUpdater = new Ajax.Updater(
		formPage,
		"/apps/email_this_page/submit.weml",
		{
			method:		'post',
			onComplete:	displayURL,
			parameters:     params
		}
	);
}



/*------------------------------------------------------------
*  Function:  displayURL
*  
*  Description:
*  Event handler for successful completion of call to
*  AJAX.Updater. Updates URL display in E-mail this page form
*  confirmation based on hidden input field.
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function displayURL() {
	// Display the page being emailed.
	//getObject('pageURLdisplay').innerHTML = pageURL;
}	
/* end BUGFIX ID 7 */

/*=========================================================================================
	end email this page library
==========================================================================================*/



/* begin BUGFIX ID 13 */
/*=========================================================================================
	startup and shutdown calls
==========================================================================================*/



/*------------------------------------------------------------
*  Function:  startup
*  
*  Description:
*  Event handler for window.onload.
*  Stores the tooltips for font control buttons in global vars.
*  Retrieves the active stylesheet and enables and disables
*  font control buttons accordingly.
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function startup() {
	var increaseFontBtn = getObject(INCREASE_BTN);
	if (increaseFontBtn) {
		INCREASE_BTN_TITLE = increaseFontBtn.title;
	}
	
	var decreaseFontBtn = getObject(DECREASE_BTN);
	if (decreaseFontBtn) {
		DECREASE_BTN_TITLE = decreaseFontBtn.title;
	}

	setFontControls(getActiveStyle());
	
	/* BUGFIX ID 5 */
	// removed call to load first gallery image using javascript
	// first gallery img tag is now output in html
}



/*------------------------------------------------------------
*  Function:  shutdown
*  
*  Description:
*  Event handler for window.onunload.
*  Saves the active stylesheet into a cookie.
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function shutdown() {
	setStyleInCookie(getActiveStyle());
}

window.onload = startup;
window.onunload = shutdown;


/*=========================================================================================
	end startup and shutdown calls
==========================================================================================*/
/* end BUGFIX ID 13 */



/*=========================================================================================
	inline calls
==========================================================================================*/

// these rollovers are called inline so they are preloaded prior to window.onload

// register rollovers for the page tools module
// newRollover(name,off,over,on,disabled);
newRollover('ptm_fontLarger','/images/common/ptm_fontLarger.gif','/images/common/ptm_fontLarger_over.gif','/images/common/ptm_fontLarger_on.gif','/images/common/ptm_fontLarger_disabled.gif');
newRollover('ptm_fontSmaller','/images/common/ptm_fontSmaller.gif','/images/common/ptm_fontSmaller_over.gif','/images/common/ptm_fontSmaller_on.gif','/images/common/ptm_fontSmaller_disabled.gif');
newRollover('ptm_print','/images/common/ptm_print.gif','/images/common/ptm_print_over.gif','/images/common/ptm_print_on.gif');
newRollover('ptm_email','/images/common/ptm_email.gif','/images/common/ptm_email_over.gif','/images/common/ptm_email_on.gif');

// register rollovers to preload css images
newRollover('boxarrowright','/images/common/img_boxarrowright.gif','/images/common/img_boxarrowright_over.gif');
newRollover('img_arrow_nav','/images/common/img_arrow_nav.gif','/images/common/img_arrow_nav_down.gif');
newRollover('galleryarrowleft','/images/common/img_phototools_arrow_left_disabled.gif','/images/common/img_phototools_arrow_left.gif');
newRollover('galleryarrowright','/images/common/img_phototools_arrow_right_disabled.gif','/images/common/img_phototools_arrow_right.gif');

/*=========================================================================================
	end inline calls
==========================================================================================*/

/*------------------------------------------------------------
*  Function:  hide_date_selector_fields
*  
*  Description:
*  
*  
*  
*  Parameters:
*  visible_style = visible or hidden
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide_date_selector_fields(visible_style)
{
	if (typeof(date_selector)!="undefined")
	{
		if(date_selector==true)
		{
			var select_tag_items = document.getElementsByTagName('select');
			for (var i = 0; i < select_tag_items.length; i++)
				if(select_tag_items[i].name!="Guests")
					select_tag_items[i].style.visibility = visible_style;
		}
	}
}

/*------------------------------------------------------------
*  Function:  hide_select_fields_for_email_this_page
*  
*  Description:
*  
*  
*  
*  Parameters:
*  visible_style = visible or hidden
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide_select_fields_for_email_this_page(visible_style)
{

	var emailUA = navigator.userAgent.toLowerCase();
	var emailIsIE = ( (emailUA.indexOf("msie") != -1) && (emailUA.indexOf("opera") == -1) && (emailUA.indexOf("webtv") == -1) );
	if(emailIsIE)
	{
		var emailVer = parseFloat(navigator.appVersion); 

		// correct version number for IE4+ 
		if (emailVer >= 4)
			emailVer = parseFloat( emailUA.substring( emailUA.indexOf('msie ') + 5 ) );

		if (emailVer < 7)
		{
			var select_tag_items = document.getElementsByTagName('select');
			for (var i = 0; i < select_tag_items.length; i++)
				select_tag_items[i].style.visibility = visible_style;
		}
	}

}

/*------------------------------------------------------------
*  Function:  add_onload
*  
*  Description:
*  Event handler for window.onload.
*  Stores the tooltips for font control buttons in global vars.
*  Retrieves the active stylesheet and enables and disables
*  font control buttons accordingly.
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
//////////////////////////////////// functions for adding body on load ///////////////////////
var add_onload_func_count;
var add_onload;

if(!add_onload_func_count)
	add_onload_func_count=0

/////////////////////////////////////////////////////////////////////////////////////////////////
if(!add_onload)
{
	add_onload = function (func)
	{
		if(add_onload_func_count==0)
		{
			if(window.onload)
			{
				eval("clone" + add_onload_func_count + " = window.onload;")
				add_onload_func_count++
			}
		}

		eval("clone" + add_onload_func_count + " = func;")
		add_onload_func_count++;

		window.onload=run_all_onload;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////

function run_all_onload()
{
	for(add_onload_current_function=0;add_onload_current_function<add_onload_func_count;add_onload_current_function++)
		eval("clone" + add_onload_current_function + "()")
}

function no_op() {
}
