/* prints a page */
function doPrint() {
	window.print();
}
/* History -1 */
function back() {
	javascript:history.go(-1);
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	for(var i=0; i<document.images.length ; i++)
	{
		var img = document.images[i]
	  	var imgName = img.src.toUpperCase()
	  	if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	  	{
		     var imgID = ( img.id) ? "id='" + img.id + "' " : ""
		     var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		     var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		     var imgStyle = "display:inline-block;" + img.style.cssText
		     if (img.align == "left") imgStyle = "float:left;" + imgStyle
		     if (img.align == "right") imgStyle = "float:right;" + imgStyle
		     if (img.parentElement.href ) imgStyle = "cursor:hand;" + imgStyle
		     var strNewHTML = "<span " + imgID + imgClass + imgTitle
		     + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		     + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
		     img.outerHTML = strNewHTML
		     i = i-1
  		}
  	}
}

if(window.attachEvent){
    window.attachEvent("onload", correctPNG);
}


/////////////////////////////////////////
//------START----------------------------
//Generates a pop up
//***************************************
//Created 12/5/05
//By Ragarwal
//trigger  -  textbox  -  genPopup('CMS Template URL','cabincatwindow','resizable=yes','width','height')
//***************************************
//TODO make the noeneter JS fuction firefox compatable
//***************************************

popWindow = new Object();

popWindow.closed = true;

function genPopup(url,target,extraProp,pWidth,pHeight){
	if (!popWindow.closed) {popWindow.close();}
	popWindow = window.open(url,target,'toolbar=no,width='+pWidth+',height='+pHeight+',left=30,top=30,'+extraProp+',status=yes');
  	popWindow.focus();
}

function openPopup(url) {
  genPopup(url, '', 'resizable=yes', 700, 400);
}


//------FINISH----------------------------
//Generates a pop up
/////////////////////////////////////////


////////////////////////////////////////
// pageLoaded allows us to check to see if DOM
// is finished loading
//
var pageLoaded = false;

function isPageLoaded() {
	return pageLoaded;
}

function setPageLoaded() {
	pageLoaded = true;
}


//////////////////////////////////////////////
//------START----------------------------
//general on load scripts
//***************************************

//the onloads array holds the functions to be called when the page loads. Each pagelet is responsible for
//loading this array with the functions it needs to run when the page body loads

var onloads = new Array();

function bodyOnLoad() {
  for ( var i = 0 ; i < onloads.length ; i++ ){
    onloads[i]();
  }

  displayTitlesOnPage();
  updateContainerDimensions();
  setPageLoaded();
}

function onEndLoad()
{
	setMaxLengthForTextFields();
}

function setMaxLengthForTextFields()
{
	var x = document.getElementsByTagName("input");
	var length = x.length;
	for(var i = 0; i<length; i++)
	{
		if(x[i].type == "text" || x[i].type == "password")
		{
			if(x[i].maxLength == -1)
			{
				x[i].maxLength = 200;
			}
		}
	}
}

function updateContainerDimensions() {
  var leftContent = document.getElementById('contentcenter');
  var rightContent = document.getElementById('contentright');


//alert("computed height: " + computedStyle(rightContent).height + " set height: " + rightContent.style.height);

  if (leftContent != null && rightContent != null) {
    var leftContentHeight = parseInt(computedStyle(leftContent).height.replace(/px/,""));
//alert("margin-top: " + computedStyle(rightContent).marginTop + " height: " + computedStyle(rightContent).height);
    var rightContentHeight = parseInt(computedStyle(rightContent).height.replace(/px/,"")) + 25;

    if (leftContentHeight < rightContentHeight) {
      leftContent.style.height = (document.getElementById('frame').offsetHeight - document.getElementById('contentheader').offsetHeight) + 'px';
    }
  }
}


//------FINISH----------------------------
///general on load scripts
/////////////////////////////////////////

//////////////////////////////////////////////
/// form submition
//***************************************
//Created 01/12/05
//By W Antjoule
//////////////////////////////////////////////
//formId = The name of the form to be submitted
//target = the value of the page dispatch to be set to
//formAction = the value the form action will be set to
//
//

function formSubmit(formId,target,formAction)
{
//alert(document.forms[formId].action);
//alert(document.forms[formId].dispatch.value);
//Check if target is passed
	if (target!=null) {
	   document.forms[formId].dispatch.value=target;
	}
//Check if formAction is passed
	if(formAction!=null){
		var x=document.getElementsByName(formId);
		document.forms[formId].action=formAction;
	}
//submit the form
//alert(document.forms[formId].action);
//alert(document.forms[formId].dispatch.value);
	document.forms[formId].submit();
}

/////////////////////////////////////////////////

/* sets paging hidden fileds and submits */
function cruiseSearchPaging(formId,  startingRowNumber)
{
   	//sets startingRowNumber for paging ;
	document.forms[formId].startingRowNumber.value=startingRowNumber;
	formSubmit(formId,"cruiseSearch");
}

function pricingQualify(context, sailingId, itineraryCode, priceProgramCode) {
	//Hack for now. I will remove this shortly - Dan
	var prefix = '';
    if (context == 'agent/booking'){
    	prefix = 'index-2.html';
    } else {
    	prefix = 'index-2.html';
    }

    window.location = prefix + context + '/pricingQualify.html?packageId=' + escape(sailingId) + '&itineraryCode='	+ escape(itineraryCode) + '&priceProgramCode=' + escape(priceProgramCode);
}

/////////////////////////////////////////
//------START----------------------------
//TOTAL GUEST NUMBER VALIDATION
//***************************************
//Used for validating the number of guest that are selected on the pricing qualifier.
//***************************************

var SavedValue = 0;

function guestAmountCalcSave(oSelect)
{
	SavedValue = parseInt(oSelect.options[oSelect.selectedIndex].value);
}

function guestAmountCalcUp(oSelect,e1,e2)
{
    var oSelect1 = oSelect.form.guestQuantityAdult;
    var oSelect2 = oSelect.form.guestQuantityChildren;

    var nValue1 = parseInt(oSelect1.options[oSelect1.selectedIndex].value);
    var nValue2 = parseInt(oSelect2.options[oSelect2.selectedIndex].value);
    window.status = nValue1 + "|" + nValue2 + "|" + (nValue1 + nValue2);

    if ((nValue1 + nValue2) > 8)
    {
        alert(e1 + ( nValue1 + nValue2 ) + e2);
        SetSelect(oSelect, SavedValue);
    }
}

function SetSelect(oSelect, SavedValue)
{
    for (i = 0 ; i < oSelect.options.length ; i++)
    {
        if (oSelect.options[i].value == SavedValue)
        {
            oSelect.selectedIndex = i;
        }
    }
}

//--------END----------------------------
//TOTAL GUEST NUMBER VALIDATION
/////////////////////////////////////////


/////////////////////////////////////////
//------START----------------------------
//highlight and unhighlight the user promocode
//***************************************
//Created 12/15/05
//By W Antjoule
//trigger  -  checkbox -
//***************************************

var tempValue="";
function highlightText(value)
{
	if (value !=null && trim(value)!="")
	{
		value=value.toUpperCase();
		tempValue=value;
		if (document.getElementsByTagName)
		{
// Get table cells in document
			var cells = document.getElementsByTagName('tr');
			var numCells = cells.length;

// Loop through elements returned
			for (var i = 0; i < numCells; ++i)
			{
// If cell should be changed (matching class)...
				var clsName = cells[i].className;
				var cls = String.toUpperCase(clsName);
				var clsIndex =(cls.indexOf(tempValue));
				if (clsIndex==0)
				{
// ...alter the colour value
					cells[i].style.backgroundColor = '#FF66FF';
				}
			}
		}
	}

}

function unhighlightText(){
if (document.getElementsByTagName)
{
	// Get table cells in document
//alert("tempValue"+tempValue);
	if (tempValue !=null && trim(tempValue)!="")
	{
		var cells = document.getElementsByTagName('tr');
		var numCells = cells.length;
// Loop through elements returned
			for (var i = 0; i < numCells; ++i)
			{
				var clsName = cells[i].className;
				var cls = String.toUpperCase(clsName);
				var clsIndex =(cls.indexOf(tempValue));
				if (clsIndex==0)

				{
					cells[i].style.backgroundColor = '';
				}
			}
		}
	}
}

//--------END----------------------------
//highlight and unhighlight the user promocode
/////////////////////////////////////////



/////////////////////////////////////////
//------START----------------------------
//BOOKING CATERGORY PROMO COBINATION VALIDATION
//***************************************
//Created 12/15/05
//By W Antjoule
//trigger  -  Checkbox  -  onClick="checkAll(this,'**cabinCategory**')"
//***************************************
//TO DO
//if a category is selected and then unselected then the catergory changing error message appears.
//***************************************

function bookingPromoComboCatVal( cbs,cb,cabinCat,pc,isGroup )
{
//CV-()-
	var sm = cabinCat +','+ pc;
	var total = 0;
	var maxi = document.bookingForm.combinablePromoCodes.length;
	var usm = 0;
	if (document.bookingForm.upgradeSelected !=null){
		usm = document.bookingForm.upgradeSelected.length;
	}
	var usmName =document.bookingForm.upgradeSelected;
	var maxPromo =1;

	if(cbs==null){
		return false;
	}
		if (cbs.checked) {
			if(document.bookingForm.pricedCabinCategoryCode.value==cabinCat){
				for (var idx = 0; idx < maxi; idx++){
					if (eval("document.bookingForm.combinablePromoCodes[" + idx + "].checked") == true) {
						total += 1;
					}
				}
				if(total>maxPromo){
					document.bookingForm.berthedCabinCategoryCode.value='';
				}
			} else {
				total = 0;
				maxi = document.bookingForm.combinablePromoCodes.length;
				if(document.bookingForm.pricedCabinCategoryCode.value.length>0){
					document.bookingForm.berthedCabinCategoryCode.value='';
				}
			}

			bookingPromoComboCatValUpgrade(sm,usm,usmName,maxi,cb,cbs);
			document.bookingForm.pricedCabinCategoryCode.value=cabinCat;e=cabinCat;

			document.bookingForm.groupCodeSameAsPromoCode.value=isGroup
		}
		else{
			for (var idx = 0; idx < maxi; idx++){
			cb[idx].checked = false ;
			}

			for(var idx = 0; idx < maxi; idx++) {
				var btnObj = eval('document.bookingForm.btn'+'['+idx+']');
				if(btnObj != null && btnObj != 'undefined') {
					btnObj.disabled = true;
				}
			}

			if(document.getElementById(sm)!=null) {
				document.getElementById(sm).disabled = true;
			}
			document.bookingForm.pricedCabinCategoryCode.value='';
			document.bookingForm.berthedCabinCategoryCode.value='';
			document.bookingForm.groupCodeSameAsPromoCode.value='';
			for (var idx = 0; idx < usm; idx++){
				usmName[idx].disabled = true ;
				if(usmName[idx].options) {
					usmName[idx].selectedIndex = 0;
				}
			}
		}
}

function bookingPromoComboCatValUpgrade(sm,usm,usmName,maxi,cb,cbs)
{
	var btnId = 'btn_'+sm.substring(0,sm.indexOf(','));
	for (var idx = 0; idx < maxi; idx++){
		cb[idx].checked = false ;
	}
	cbs.checked = true;

	for (var idx = 0; idx < usm; idx++) {
		usmName[idx].disabled = true ;
		if(usmName[idx].options) {
			usmName[idx].selectedIndex = 0;
		}
	}

	for(var idx = 0; idx < maxi; idx++) {
		var btnObj = eval('document.bookingForm.btn'+'['+idx+']');
		if(btnObj != null && btnObj != 'undefined') {
			btnObj.disabled = true;
		}
	}
	document.getElementById(btnId).disabled = false;

	if(document.getElementById(sm)!=null) {
		document.getElementById(sm).disabled = false;
		document.bookingForm.berthedCabinCategoryCode.value='';
	}
}

//--------END----------------------------
//BOOKING CATERGORY PROMO COBINATION VALIDATION
/////////////////////////////////////////

/////////////////////////////////////////
//------START----------------------------
//Submit the current form when user hits enter key
//***************************************
//Created 12/20/05
//By EThomas
//trigger  -  Text  -  onKeyPress="return submitenter(this,event)"
//***************************************
//TO DO

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

//--------END----------------------------
//BOOKING CATERGORY PROMO COBINATION VALIDATION
/////////////////////////////////////////



/////////////////////////////////////////
//------START----------------------------
//disallow a form to be submitted by hitting the enter key when in a textfield
//***************************************
//Created 12/20/05
//By W Antjoule
//trigger  -  textbox  -  onkeypress="return noenter()"
//***************************************
//TODO make the noeneter JS fuction firefox compatable
//***************************************

function noenter( event )
{
var intKeyCode = 0;
var blnAllow = true;
   if( document.all )
   {
       intKeyCode = event.keyCode;
    }
    else
    {
       intKeyCode = event.which;
    }

if( intKeyCode == 13 )
{
    blnAllow = false;
}
return blnAllow;
}

//--------END----------------------------
//disallow a form to be submitted by hitting the enter key when in a textfield
/////////////////////////////////////////

/*
 * Added these functions here because agent pages are using them too.
 *
 * TODO move these functions to appropriate file.
 */
function changeSrc(imageObject, imgName) {
  imageObject.src = imageObject.src.substring(0, imageObject.src.lastIndexOf("index-2.html") + 1) + imgName;
}

/*
 * Renamed changeSrc to swapImage
 */
function swapImage(imageObject, imgName) {
  imageObject.src = imageObject.src.substring(0, imageObject.src.lastIndexOf("index-2.html") + 1) + imgName;
}

/*
 * TODO GENERALIZE FORM SUBMIT...BASED ON ELEMENT ID
 */
function doSubmit()
{
	window.document.aform.submit();
}

function swapDiv(divName) {
	if (document.getElementById(divName).style.display == "none") {
		document.getElementById(divName).style.display = "block";
	} else {
		document.getElementById(divName).style.display = "none";
	}
}

//--------END----------------------------
/////////////////////////////////////////

 function clearAllRadio(aform)
 {
     for(var i=0;i<=window.document.aform.elements.length;i++ )
     {
        var aRadioObj = window.document.aform.elements[i];

        if (aRadioObj.type == 'radio' &&   aRadioObj.checked)
        {
            aRadioObj.checked=false;
        }
     }
 }

 function setDateToCheckBox(box)
 {

  if (box.value != 0)
  {


 		var lead_pound = box.value.indexOf("#");
 		var checkBoxId = box.value.substring(0,lead_pound);
 		//alert("CheckBox Id: "+checkBoxId);

 		var checkBox = document.getElementById(checkBoxId);
 		checkBox.value = box.value;
 		//alert(checkBox.value);
 	}
 }

/////////////////////////////////////////////////////////////////
// General purpose functions

/*
 * Updates value of hidden element named 'dispatch'.
 * Form that contains that element is identified by its
 * position on page. It is assumed to be first on page.
 *
 *   - target value to be assign to dispatch
 */
function set(target) {
  document.forms[0].dispatch.value=target;
}

/*
 * Removes preceding and trailing whites spaces from string.
 *
 *   - str  string to be operated on
 */
function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}

/*
 */
/////////////////////////////////////////
//------START----------------------------
// getWebAppContext()
//
// Generic function to return the web context from parsing the URL.  This
// function will no longer work if we change the context to /
//***************************************
//Created 2/14/2006
//By Matt Wolinski
//***************************************
//TODO
//***************************************
function getWebAppContext() {
    // parse the context from the URL.
    var loc = location.pathname;
    loc = loc.substring(1);
    var context = loc.substring(0,loc.indexOf("index-2.html"));
    return context;
}


// TODO substitute current implementation of getWebAppContext with following
/*
 * Identifies web context based on location of first script file imported
 * on page. It is assumed that script file is located in folder whose name
 * starts with 'script' and is located right under web context.
 */
/*
function getWebAppContext() {
  var regex = new RegExp('.*' + location.host + '|/script.*', 'g');
  return document.getElementsByTagName('script')[0].src.replace(regex, '');
}
*/

/*
 * Returns CSSStyleDeclaration object for an element.
 *
 *   - elmnt  object whose styles to return
 */
function computedStyle(elmnt) {
  var computedStyle = null;

  if (document.defaultView && document.defaultView.getComputedStyle) {
    computedStyle = document.defaultView.getComputedStyle(elmnt, "");
  } else if (elmnt.currentStyle) {
    computedStyle = elmnt.currentStyle;
  } else {
    computedStyle = element.style;
  }

  return computedStyle;
}

/*
 * E-mail validation function. Taken from
 * http://www.quirksmode.org/js/mailcheck.html
 *
 * Note. This function will not detect all of the e-mail addresses
 *       1) address that have user name in quotes with strange characters
 *          ex: "J. P. 's-Gravezande, a.k.a. The Hacker!"@server.com
 *       2) address with IP address instead of domain name
 *          ex: me@[187.223.45.119]
 *          some of the mail servers won't even recognize this address
 *       Historically a domain name may not begin with a number, but in
 *       practice this rule is disregarded. So address like this is accepted
 *       ex: someone@123.com
 */
function validateEmail(email) {
  var filter  = /^[\w\.\-]+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  return filter.test(email);
}

/*
 * Retrieves element using its id attribute.
 *
 *   - elmnt either reference to element or its id
 */
function getElement(elmnt) {
  return (elmnt != null && (typeof elmnt) == 'string') ? document.getElementById(elmnt): elmnt;
}

var isBrowserIE = false;
var isIEVersion7 = false;

if (document.all) {
  isBrowserIE = true;
  isIEVersion7 = (window.navigator.userAgent.match('.*MSIE 7.*') == null) ? false: true;
}

/*
 * Calculates font size value.
 *
 *   - elmnt  element whose font to calculate
 */
function parseFontSize(elmnt) {
  var baseFontSizeValue = (computedStyle(elmnt).fontSize.match('em')) ? baseFontSize(): 1;
  return parseFloat(computedStyle(elmnt).fontSize.replace(/px|em/, '')) * baseFontSizeValue;
}

/*
 * Returns font size of BODY element. It is assumed that font value is set in pixels.
 */
function baseFontSize() {
  return parseInt(computedStyle(document.getElementsByTagName('body')[0]).fontSize.replace(/px/, ''));
}

/*
 * Returns random number that is greater then low and
 * lower then high
 */
function createRandomValue(low, high) {
  return Math.floor(Math.random() * (1 + high - low) + low);
}

/////////////////////////////////////////////////////////////////
// In page pop-up functions

/*
 * Hides currently displayed content element, if any, and displays
 * requested content element. Elements are identified by some string
 * that is followed by number. Index numbers should start from 1 and
 * indeces should be sequential.
 *
 * If there is only one element then contentIdPrefix becomes element
 * identifier. In this case index parameter can be null OR have
 * two values 'show' or 'hide'. This allows user to explicitely
 * specify operation to be performed.
 *
 *   - contentIdPrefix  id of elements that belong to same group should start
 *                      with this string
 *   - index  after prefix comes number that identifies element in group
 *            This parameter has dual usage
 */
function displayContent(contentIdPrefix, index) {
  var counter = 1;
  var currentElmnt = getElement(contentIdPrefix);

  if (index != null && index != 'show' && index != 'hide') {
    while ((currentElmnt = document.getElementById(contentIdPrefix + counter)) != null) {
      currentElmnt.className = (counter != index) ? currentElmnt.className + ' no_display': currentElmnt.className.replace(/no_display/g, '');
      counter++;
    }
  } else if (currentElmnt.className.match('no_display') != null && (index == null || index == 'show')
             || index == 'show') {
    currentElmnt.className = currentElmnt.className.replace(/no[_]display/g, '');
  } else {
    currentElmnt.className += ' no_display';
  }
}

/*
 * Displays element on page. Element is positioned in center of the page.
 *
 * Note. Hidden element's CSS position and z-index will be set to 'absolute' and '3'
 *
 *   - hiddenElmnt  elemnt that is being manipulated
 *   - isModal  switch indicating if page functionality will be disabled when
 *              hiddenElement is displayed. Accepted value 'modal'
 *   - top  distance from top of the page
 *   - left  distance from left side of the page
 */
function displayElement(hiddenElmnt, isModal, top, left) {
  hiddenElmnt = getElement(hiddenElmnt);

  // setting visibility to "hidden" here and changing it at the end to "visible"
  // displays element to user after it was positioned. Otherwise users will see
  // element move into final position from its base position
  hiddenElmnt.style.visibility = 'hidden';
  hiddenElmnt.style.position = 'absolute';
  hiddenElmnt.style.zIndex = '3';
  displayContent(hiddenElmnt, 'show');

  positionElement(hiddenElmnt);

  if (top != null) {
    hiddenElmnt.style.top = top + 'px';
  }

  if (left != null) {
    hiddenElmnt.style.left = left + 'px';
  }

  if (isModal == 'modal') {
    disableFunctionality();
  }

  hiddenElmnt.style.visibility = 'visible';
}

/*
 * Hides element on page.
 *
 *  - elmntId identifier of element to be hidden
 *  - isModal  switch indicating if page functionality should be enabled.
 *             Accepted value is 'modal'
 */
function hideElement(elmntId, isModal) {
  var elmnt = getElement(elmntId);
  displayContent(elmnt, 'hide');

  if (isModal == 'modal') {
    enablePageFunctionality(document.body);
  }
}

/*
 * Positions element either in center of the page.
 *
 *   - elmnt  element on page to be positioned
 */
function positionElement(elmnt) {
  var top = elmnt.offsetHeight / 2;
  var left = getElement('frame').offsetWidth / 2 - elmnt.offsetWidth / 2;

  if (isBrowserIE) {
    top = (document.documentElement.clientHeight / 2 + document.documentElement.scrollTop) - top;
  } else {
    top = (window.innerHeight / 2 + window.scrollY) - top;
  }

  elmnt.style.top = calculateOffsetDistance(document.body, elmnt, 'top', top) + 'px';
  elmnt.style.left = calculateOffsetDistance(document.body, elmnt, 'left', left) + 'px';
}

/*
 * Calculates number of pixels element should be moved into position.
 *
 *   - refElmnt  element on page relative to which displayed element is beeing positioned
 *   - posElmnt  element for which position coordinates are beeing calculated
 *   - axis  indicator whether distance is from top or left side of the element
 *   - displacement  distance element should be moved in refElmnt
 */
function calculateOffsetDistance(refElmnt, posElmnt, axis, displacement) {
  // number of pixels from top or left of the page where element should be positioned
  var totalVisibleDistance = offsetDistance(refElmnt, axis, false) + displacement;
  return totalVisibleDistance - offsetDistance(posElmnt, axis, true);
}

/*
 * Calculates distance relative to body element or first element (between
 * body and element beeing position) that is relatively positioned.
 */
function offsetDistance(obj, axis, fromRelativeElmnt) {
  var offsetDistance = 0;

  while (obj.offsetParent != null) {
    if (offsetDistance > 0 || !fromRelativeElmnt || computedStyle(obj).position.match('.*relative.*')) {
      if (axis == 'left') {
        offsetDistance += obj.offsetLeft;
      } else {
        offsetDistance += obj.offsetTop;
      }
    }

    obj = obj.offsetParent;
  }

  return offsetDistance;
}

/*
 * Removes user access to the page or its parts.
 *
 *  - refElmntId  element to cover. If not specified then
 *                whole page
 *  - opacity  transparency level. By default set to 50.
 *             0 is opaque and 100 fully transparent
 */
function disableFunctionality(refElmntId, opacity) {
  var refElmnt = (refElmntId == null) ? document.body: getElement(refElmntId);
  var fullPageCover = (refElmntId == null) ? true: false;
  var blockingElmnt = getElement(refElmnt.getAttribute('blockingElementId'));

  if (blockingElmnt == null) {
    blockingElmnt = document.createElement('div');
    blockingElmnt.id = findUnusedId('blockingElement');
    blockingElmnt.className = 'disablingBackground';
    blockingElmnt.style.opacity= '.' + opacity;
    refElmnt.insertBefore(blockingElmnt, refElmnt.firstChild);
    refElmnt.setAttribute('blockingElementId', blockingElmnt.id);
  } else {
    displayContent(blockingElmnt, 'show');
  }

  // IE < 7 needs special treatment
  if (isBrowserIE && !isIEVersion7) {
    blockingElmnt.style.position = 'absolute';
    blockingElmnt.style.height = document.documentElement.scrollHeight + 'px';
    var selectTags = refElmnt.getElementsByTagName('select');

    // disabling all dropdowns on page because in IE they will
    // shine through DIV used for blocking current page
    for (var i = 0; i < selectTags.length; i++) {
      if (selectTags[i].disabled == false) {
        selectTags[i].disabled = true;
        selectTags[i].setAttribute('disabledWithPageFunctionality', 'true');
      }
    }
  }

  if (!fullPageCover) {
    blockingElmnt.style.position = 'absolute';
    blockingElmnt.style.top = calculateOffsetDistance(refElmnt, blockingElmnt, 'top', 0) + 'px';
    blockingElmnt.style.left = calculateOffsetDistance(refElmnt, blockingElmnt, 'left', 0) + 'px';
    blockingElmnt.style.width = refElmnt.offsetWidth + 'px';
    blockingElmnt.style.height = refElmnt.offsetHeight + 'px';
  }
}

/*
 * Gives user access to page.
 */
function enablePageFunctionality(refElmnt) {
  displayContent(refElmnt.getAttribute('blockingElementId'), 'hide');

  if (isBrowserIE && !isIEVersion7) {
    var selectTags = refElmnt.getElementsByTagName('select');

    for (var i = 0; i < selectTags.length; i++) {
      if (selectTags[i].getAttribute('disabledWithPageFunctionality') == 'true') {
        selectTags[i].disabled = false;
        selectTags[i].setAttribute('disabledWithPageFunctionality', null);
      }
    }
  }
}

/*
 * Find unique element id on page. Id is based on a random
 * digit between 100 and 250 appended to a string provided.
 *
 *   - idPostfix  string used as part of the generated id
 */
function findUnusedId(idPostfix) {
  var id = 0;

  do {
    id = createRandomValue(100, 250);
  } while (getElement(id + idPostfix) != null);

  return id + idPostfix;
}

/////////////////////////////////////////////////////////////////
// Tab functions

/*
 * Updates tabs according to user selection.
 *
 * Note. it is assumed CSS class for selected tab starts with 'a_tab'
 * and ends with '_ovr'.
 */
function swtichtabs(elmnt) {
  var anchors = elmnt.parentNode.getElementsByTagName('a');

  for(i = 0; i < anchors.length; ++i) {
    anchors[i].className = anchors[i].className.replace(/_ovr/, ''); // set all tabs to non-active state
    anchors[i].onmouseup = function() { // set only the tab that was clicked on to the active state
      var pattern = /(a_tab\w*)/;
      this.className = this.className.replace(pattern, '$1_ovr');
    }
  }
}

/////////////////////////////////////////////////////////////////
// Date selection functions

/*
 * Updates day drop down with correct number of days for selected
 * month. If user selected day that does not appear in selected month
 * then selection will be defaulted to first dropdown option.
 *
 *   - elmnt  reference to either month or year dropdown
 */
function updateDateSelectionDaysList(elmnt) {
  // indicates whether next or previous sibling in DOM tree should be
  // searched for day dropdown
  var forward = (elmnt.name.match('month') != null) ? true: false;
  var month = (forward) ? elmnt.selectedIndex: 0;
  var year = (!forward) ? elmnt.value: 0;
  var dayDropDown = null;

  while (month == 0 || year == 0) {
    elmnt = (forward) ? elmnt.nextSibling: elmnt.previousSibling;

    if (elmnt.name != null) {
      dayDropDown = (elmnt.name.match('day') != null) ? elmnt: dayDropDown;
      month = parseInt((elmnt.name.match('month') != null) ? elmnt.value: month);
      year = parseInt((elmnt.name.match('year') != null) ? elmnt.value: year);
    }
  }

  var daysPerMonth = getDaysPerMonth(month, year);
  var i = dayDropDown.options.length - 1;

  while (i != daysPerMonth) {
    if (i < daysPerMonth) {
      i++;
      dayDropDown.options[i] = new Option(i, i);
    } else {
      dayDropDown.options[i] = null;
      i--;
    }
  }
}

/*
 * Calculates number of days in selected month.
 *
 *   - month  day of the month
 *   - year  digit corresponding to year
 */
function getDaysPerMonth(monthValue, yearValue) {
  var daysPerMonth = 31;

  if (monthValue == 4 || monthValue == 6 || monthValue == 9 || monthValue == 11) {
    daysPerMonth = 30;
  } else if (monthValue == 2) {
    daysPerMonth = (yearValue % 4 == 0 && yearValue % 100 != 0 || yearValue % 400 == 0) ? 29: 28;
  }

  return daysPerMonth;
}

/////////////////////////////////////////
//------START----------------------------
// Email Validation()
//
// Generic function to validate a email address clientside
//***************************************
//Created 2/14/2006
//By William Antjoule
//***************************************
//TODO
//***************************************


var testresults;
function checkemail(EVFormName,EVFieldName){
	var str=document.forms[EVFormName].elements[EVFieldName].value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
		else{
		alert("Please input a valid email address!")
		testresults=false
		document.forms[EVFormName].elements[EVFieldName].focus();
	}
	return (testresults)
}


function checkbae(EVFormName,EVFieldName){
	if (document.layers||document.getElementById||document.all)
		return checkemail(EVFormName,EVFieldName)
	else
		return true
}

// Function to subit a form
function formSubmitByID(formObj, target) {
	if(formObj != null) {
		formObj.dispatch.value=target;
		formObj.submit();
	}
}

function inArray(arr, testObject) {
	for (i = 0; i < arr.length; i++) {
		if (arr[i] == testObject) {
			return true;
		}
	}
	return false;
}


/////////////////////////////////////////
//------START----------------------------
// Booking Payment Page
//
// Functions to add DHTML functionality to payment page
//***************************************
//Created 8/17/2006
//By DJ Raven[Eban Thomas]
//***************************************
//TODO
//***************************************

function setAddressState(isBillingEqualMailing)
{
	var addressDiv = document.getElementById("address_div");

	if (isBillingEqualMailing != 'false')
	{
		addressDiv.style.display = 'none';
	}
	else
	{
		addressDiv.style.display = '';
	}
}

/////////////////////////////////////////
//***************************************
//Add on 8/26/2006 by Matt Wolinski
//***************************************
// This method will ignore the enter key when the user is
// within the selected html form element.  You can use it to stop a
// user from accidentally submitting a form before completing it.
//
// Usage:  add onkeypress below to the html form element
// onkeypress="return handleEnter(this, event)"
/////////////////////////////////////////
function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		return false;
	}
	return true;
}
/////////////////////////////////////////

function openRelativeLink(link) {
	var newLink = '/' + getWebAppContext() + link;
	location.href = newLink;
}
