//******GLOBAL.JS******

// Browser sniffer
var ns4 = (document.layers); 
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);

// Attaches objects dependent on browser
function object_attach(id)
{
	var obj;
	if(ns4) obj = document.layers[id];
	else if(ie4) obj = document.all[id];
	else if(ie5 || ns6) obj = document.getElementById(id);
	return obj;
}

function HideShowDiv(id)
{
	//added to check whether div is currently hidden or not
	if(id)
	{
		if(id.value == 'true'){id.value = 'false';div_switch('HideSearchDiv', true, true);  }
		else{id.value = 'true';div_switch('HideSearchDiv', false, true);}
	}
}

// Shows/hides div objects
function div_switch(id, bShow, bBlock)
{
	
	temp_Obj = object_attach(id);
	if(ns4)
	{
		if(bShow==true)
		{
			if(bBlock==true) { temp_Obj.display = "block"; }
			else { temp_Obj.visibility = "show"; }
		}
		else
		{
			if(bBlock==true) { temp_Obj.display = "none"; }
			else { temp_Obj.visibility = "hide"; }
		}
	}
	else
	{
		if(bShow==true)
		{
			if(bBlock==true) { temp_Obj.style.display = "block";}
			else { temp_Obj.style.visibility = "visible"; }
		}
		else
		{
			if(bBlock==true) { temp_Obj.style.display = "none";}
			else { temp_Obj.style.visibility = "hidden"; }
		}
	}
}

function row_switch(id, bShow)
{
	
	temp_Obj = object_attach(id);
	if(ns4)
	{
		if(bShow==true)
		{
			temp_Obj.display = "table-row";
		}
		else
		{
			temp_Obj.display = "none";
		}
	}
	else
	{
		if(bShow==true)
		{
			temp_Obj.style.display = "table-row";
		}
		else
		{
			temp_Obj.style.display = "none";
		}
	}
}

function showHideResultItems(id,sHideText,sShowText)
{
	var oObjLayer = document.getElementById("_divHideShow" + id);
	var oObjImg = document.getElementById("_imgHideShow" + id);
	var oObjHref = document.getElementById("_hrefHideShow" + id);
	if(!oObjLayer) return;
	if(oObjLayer.style.display == "none")
	{
		oObjImg.src = "/buildyourown/images/ico_minus.gif";
		oObjHref.innerText = sHideText;
	}
	else
	{
		oObjImg.src = "/buildyourown/images/ico_plus.gif";
		oObjHref.innerText = sShowText;
	}
	oObjLayer.style.display = (oObjLayer.style.display == "none"?"block":"none");
}
function tabMouseOver(id,className)
{
	temp_Obj = object_attach(id);
	temp_Obj.className = className;
}

// Clears a text field only if the value matches what is passed in
function clearField(fId, sMatch, sChange)
{
	if(sChange == null) sChange = '';
	if(fId.value == sMatch)
	{ fId.value = sChange; }
}

// Cross-browser function to change the contents inside a DIV tag
function writeInDiv(text, id)
{
	if (document.getElementById)
	{ x = document.getElementById(id); if (x) { x.innerHTML = ''; x.innerHTML = text; } }
	else if (document.all)
	{ x = document.all[id]; if (x) { x.innerHTML = text; } }
	else if (document.layers)
	{ x = document.layers[id]; if (x) { text2 = '<p>' + text + '</p>'; x.document.open(); x.document.write(text2); x.document.close(); } }
}

// Shows popup calendar
function showCalendar3(calTitle,calTarget,calInit)
{
	if(calInit!=null)
	{ calendarWin=window.open("/includes/calendar.asp?initDate=" + eval("document." + calInit + "_d.value") + "/" + eval("document." + calInit + "_m.value") + "/" + eval("document." + calInit + "_y.value") + "&title=" + escape(calTitle) + "&field=" + escape(calTarget),"calendarWin","width=220,height=200,left=" + ((screen.width-220)/2) + ",top=" + ((screen.height-200)/2) + ",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"); }
	else
	{ calendarWin=window.open("/includes/calendar.asp?initDate=" + eval("document." + calTarget + "_d.value") + "/" + eval("document." + calTarget + "_m.value") + "/" + eval("document." + calTarget + "_y.value") + "&title=" + escape(calTitle) + "&field=" + escape(calTarget),"calendarWin","width=220,height=200,left=" + ((screen.width-220)/2) + ",top=" + ((screen.height-200)/2) + ",status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"); }
	if(!calendarWin.opener) calendarWin.opener=self;
}

// Opens a popup window
function openPopupWin(popUrl, popWid, popHgt, popScroll, popResize)
{
	popupWin=window.open(popUrl,"popupWin","width=" + popWid + ",height=" + popHgt + ",left=" + ((screen.width-popWid)/2) + ",top=" + ((screen.height-popHgt)/2) + ",status=yes,toolbar=no,menubar=no,scrollbars=" + popScroll + ",resizable=" + popResize);
	if(!popupWin.opener) popupWin.opener=self;
}

// Print page function
function printPage()
{
	if(window.print)
	{ window.print(); }
	else
	{ alert("Your browser does not support this feature!\nPlease try pressing CTRL + P to print this page."); }
}

// Bookmark page function
function bookmarkPage(url, title)
{
	if (document.all) { window.external.AddFavorite(url, title); } else if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }
}

// Enquiry form validation
function checkEnquiryForm(fId)
{
	if(fId.enqEmail.value == '' || isValidField(fId.enqEmail.value,2) == false)
	{ alert("Please enter a valid email address before submitting your enquiry!"); fId.enqEmail.focus(); return false; }
	else if(fId.enqTitle.selectedIndex == 0)
	{ alert("Please select a title before submitting your enquiry!"); fId.enqTitle.focus(); return false; }
	else if(fId.enqFirstname.value == '' || fId.enqFirstname.value == '- Firstname -')
	{ alert("Please enter a firstname before submitting your enquiry!"); fId.enqFirstname.focus(); return false; }
	else if(fId.enqSurname.value == '' || fId.enqSurname.value == '- Surname -')
	{ alert("Please enter a surname before submitting your enquiry!"); fId.enqSurname.focus(); return false; }
	else if(fId.enqTelDay.value == '' && fId.enqTelEve.value == '' && fId.enqTelMob.value == '')
	{ alert("Please enter at least one contact telephone number!"); fId.enqTelDay.focus(); return false; }
	else if(fId.enqEnquiry.value == '')
	{ alert("Please enter a valid comment before submitting your enquiry!"); fId.enqEnquiry.focus(); return false; }
	else
	{ return true; }
}


function isValidField(sText, iType){
	if(iType==1)
	{ ValidChars = "0123456789"; }
	else if(iType==2)
	{ ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-@"; }
	else if(iType==3)
	{ ValidChars = "0123456789."; }
	else if(iType==4)
	{ ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "; }
	else if(iType==5)
	{ ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-/ "; }
	var isValid=true;
	var Char;
	for (iii = 0; iii < sText.length && isValid == true; iii++) 
	{ 
		Char = sText.charAt(iii); 
		if (ValidChars.indexOf(Char) == -1) 
		{ isValid = false; }
	}
	return isValid;
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
}
function checkFormPaxTitles(sErrTxt)
{
	oTitleElements = document.getElementsByTagName("select")
	for (i = 0; i < oTitleElements.length; i++)
	{
		if(oTitleElements.item(i).id.indexOf("title") == 0)
		{
			if(oTitleElements.item(i).selectedIndex == 0)
			{ alert(sErrTxt); oTitleElements.item(i).focus(); return false; break; }
		}
	}
	return true;
}
function checkFormFieldSelectedIndex(sFieldName, sErrTxt)
{
	oTitleElements = document.getElementsByTagName("select")
	for (i = 0; i < oTitleElements.length; i++)
	{
		if(oTitleElements.item(i).id.indexOf(sFieldName) == 0)
		{
			if(oTitleElements.item(i).selectedIndex == 0)
			{ alert(sErrTxt); oTitleElements.item(i).focus(); return false; break; }
		}
	}
	return true;
}

function LeftCheck(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}




function checkFormFieldValue(sFieldName, sDefaultVal, sErrTxt, iMinLen){
	if(iMinLen==undefined || iMinLen==null) { iMinLen = 1; }
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++){
		if(oFormElements.item(i).id.indexOf(sFieldName) == 0){
			if(oFormElements.item(i).value == '' || oFormElements.item(i).value == sDefaultVal || oFormElements.item(i).value.length < iMinLen || (sFieldName == 'surname' && oFormElements.item(i).value.indexOf(' ') > -1) || ((sFieldName == 'surname' || sFieldName == 'firstname') && (isValidField(oFormElements.item(i).value,5)==false || LeftCheck(oFormElements.item(i).value,1)=='-' || LeftCheck(oFormElements.item(i).value,1)=='/' || oFormElements.item(i).value.length < 2 || oFormElements.item(i).value==sDefaultVal))){
				alert(sErrTxt);
				oFormElements.item(i).focus();
				return false;
				break;
			}
		}
	}
	oFormElements = document.getElementsByTagName("textarea")
	for (i = 0; i < oFormElements.length; i++){
		if(oFormElements.item(i).id.indexOf(sFieldName) == 0){
			if(oFormElements.item(i).value == '' || oFormElements.item(i).value == sDefaultVal){
				alert(sErrTxt);
				oFormElements.item(i).focus()
				return false;
				break;
			}
		}
	}
	return true;
}


function checkFormFieldAges(sErrTxt)
{
	oFormElements = document.getElementsByTagName("select")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).id.indexOf("dob") == 0 && oFormElements.item(i).id.lastIndexOf("d") == 3)
		{
			temp_Obj1 = object_attach(oFormElements.item(i).id);
			temp_Obj1a = Math.abs(temp_Obj1.idmin);
			temp_Obj1b = Math.abs(temp_Obj1.idmax);
			temp_Obj2 = object_attach('dobm' + temp_Obj1.id.substr(4,temp_Obj1.id.length-4));
			temp_Obj3 = object_attach('doby' + temp_Obj1.id.substr(4,temp_Obj1.id.length-4));
			if(checkAge(temp_Obj1a, temp_Obj1b, temp_Obj1, temp_Obj2, temp_Obj3) == false)
			{ alert(sErrTxt + '\nPassenger ' + temp_Obj1.id.substr(4,temp_Obj1.id.length-4) + ' is out of the acceptable age range (' + temp_Obj1a + '-' + temp_Obj1b + 'yrs).'); temp_Obj1.focus(); return false; break; }
		}
	}
	return true;
}
function checkRadio(sFieldName)
{
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type == "radio" && oFormElements.item(i).name == sFieldName)
		{
			if(oFormElements.item(i).checked)
			{ return oFormElements.item(i).value; break; }
		}
	}
	return '';
}

//preload navigation images
nav1 = new Image()
nav1.src = "images/nav1_1.gif" 
nav2 = new Image()
nav2.src = "images/nav2_1.gif" 
nav3 = new Image()
nav3.src = "images/nav3_1.gif" 
nav4 = new Image()
nav4.src = "images/nav4_1.gif" 
nav5 = new Image()
nav5.src = "images/nav5_1.gif" 
nav6 = new Image()
nav6.src = "images/nav6_1.gif" 
nav7 = new Image()
nav7.src = "images/nav7_1.gif" 
search_button1 = new Image()
search_button1.src = "images/search_button1.gif" 
newsletter_button1 = new Image()
newsletter_button1.src = "images/newsletter_button1.gif" 

//swap background image
function swapImage(id,state){
		document.getElementById(id).style.backgroundImage = 'url(/images/'+id+state+'.gif)';
	}

function addDurationBYO2()
{
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

    oSelect = document.getElementById('startdate_d');
	iDay = oSelect.options[oSelect.selectedIndex].value;
	oSelect = document.getElementById('startdate_m');
	iMonth = oSelect.options[oSelect.selectedIndex].value;
	oSelect = document.getElementById('startdate_y');
	iYear = oSelect.options[oSelect.selectedIndex].value;
	
	cindate = new Date(iYear, parseInt(iMonth - 1), iDay, 0, 0, 0);
	
	oSelect = document.getElementById('duration');
	if (oSelect.options[oSelect.selectedIndex].value == 'other')
	{
		tmpDuration = prompt("Please enter the number of nights","")
		if (tmpDuration == '')
		{
			iDuration = 7
		}
		else
		{
			var opt = new Option(tmpDuration + ' days', tmpDuration);
			insertOptionAt (oSelect, opt, oSelect.options.length);
			iDuration = parseInt(oSelect.options[oSelect.options.length-1].value);
			oSelect.selectIndex = oSelect.options.length;
			oSelect.options[oSelect.options.length-1].selected = 'selected';
		}
	}
	else
	{
		iDuration = parseInt(oSelect.options[oSelect.selectedIndex].value);
	}

	// Amend the end date
	days = 1000 * 60 * 60 * 24 * iDuration;
	newdate = new Date(cindate.valueOf() + days);
	if ((newdate.getHours() != 0) || (newdate.getMinutes() != 0) || (newdate.getSeconds() != 0)) {
		// Workaround to JavaScript bug: sometimes when adding days represented as milliseconds it would onhly add 23 hrs
		// Work out time in milliseconds
		time = newdate.getHours() * 60 * 60 * 1000;
		time += newdate.getMinutes() * 60 * 1000;
		time += newdate.getSeconds() * 1000;
		newdate = new Date(newdate.getTime() + time);
	}
	sArrDate = newdate.getDate() + ' ' + months[newdate.getMonth()] + ' ' + newdate.getFullYear();
	document.getElementById("arrdate").innerHTML = '&nbsp;&nbsp;&nbsp;<b>' + sArrDate + '</b>'
	
	iDay = newdate.getDate();
	iMonth = newdate.getMonth() + 1;
	iYear = newdate.getFullYear();

	oTxt = document.getElementById('enddate_d');	
	if (iDay < 10) { iDay = '0' + iDay; }
	oTxt.value = iDay;
	
	oTxt = document.getElementById('enddate_m');
	if (iMonth < 10) { iMonth = '0' + iMonth; }
	oTxt.value = iMonth;
	
	oTxt = document.getElementById('enddate_y');
	oTxt.value = iYear;	
}

function addDurationBYOstripped(selDuration)
{
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

	
	oSelect = document.getElementById('duration');
	if (oSelect.options[oSelect.selectedIndex].value == 'other')
	{
		tmpDuration = prompt("Please enter the number of nights","")
		if ( (tmpDuration==' ') || (tmpDuration==null) || (tmpDuration == ''))
		{
			iDuration = 7
			oSelect.options[0].selected = 'selected';
		}
		else
		{
			var stemp = tmpDuration
			if (stemp < 10)
			{
				stemp = "0" + stemp
			}
			for (loop=0; loop < oSelect.options.length; loop++)
			{
				if (oSelect.options[loop].value == stemp)
				{
					oSelect.options[loop].selected = 'selected';
					iDuration = stemp
				}
			}

			if (isNumeric(tmpDuration) == true)
			{	
				var opt = new Option(tmpDuration + ' Nights', tmpDuration);
				insertOptionAt (oSelect, opt, oSelect.options.length);
				iDuration = oSelect.options[oSelect.options.length-1].value;
				oSelect.selectIndex = oSelect.options.length;
				oSelect.options[oSelect.options.length-1].selected = 'selected';
			}
			else
			{
				iDuration = 7
				oSelect.options[0].selected = 'selected';
			}
		}
	}
	else if(selDuration) //For results page, if user has selected a duration not in list then need to add it in
	{
		var selCount = 0
		for (loop=0; loop < oSelect.options.length; loop++)
			{
				if (oSelect.options[loop].value == selDuration)
				{
					oSelect.options[loop].selected = 'selected';
					selCount = selCount + 1
				}
			}

			if (isNumeric(selDuration) == true && selCount == 0)
			{	
				var opt = new Option(selDuration + ' Nights', selDuration);
				insertOptionAt (oSelect, opt, oSelect.options.length);
				oSelect.options[oSelect.options.length-1].selected = 'selected';
			} 
	}
	else
	{
		iDuration = oSelect.options[oSelect.selectedIndex].value;
	}

}

function addDurationBYO()
{
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

    oSelect = document.getElementById('startdate_d');
	iDay = oSelect.options[oSelect.selectedIndex].value;
	oSelect = document.getElementById('startdate_m');
	iMonth = oSelect.options[oSelect.selectedIndex].value;
	oSelect = document.getElementById('startdate_y');
	iYear = oSelect.options[oSelect.selectedIndex].value;
	
	cindate = new Date(iYear, iMonth - 1, iDay, 0, 0, 0);
	
	oSelect = document.getElementById('duration');
	if (oSelect.options[oSelect.selectedIndex].value == 'other')
	{
		tmpDuration = prompt("Please enter the number of nights","")
		if ( (tmpDuration==' ') || (tmpDuration==null) || (tmpDuration == ''))
		{
			iDuration = 7
			oSelect.options[0].selected = 'selected';
		}
		else
		{
			var stemp = tmpDuration
			if (stemp < 10)
			{
				stemp = "0" + stemp
			}
			for (loop=0; loop < oSelect.options.length; loop++)
			{
				if (oSelect.options[loop].value == stemp)
				{
					oSelect.options[loop].selected = 'selected';
					iDuration = stemp
				}
			}

			if (isNumeric(tmpDuration) == true)
			{	
				var opt = new Option(tmpDuration + ' days', tmpDuration);
				insertOptionAt (oSelect, opt, oSelect.options.length);
				iDuration = oSelect.options[oSelect.options.length-1].value;
				oSelect.selectIndex = oSelect.options.length;
				oSelect.options[oSelect.options.length-1].selected = 'selected';
			}
			else
			{
				iDuration = 7
				oSelect.options[0].selected = 'selected';
			}
		}
	}
	else
	{
		iDuration = oSelect.options[oSelect.selectedIndex].value;
	}

	// Amend the end date
	days = 1000 * 60 * 60 * 24 * iDuration;
	newdate = new Date(cindate.valueOf() + days);
	if ((newdate.getHours() != 0) || (newdate.getMinutes() != 0) || (newdate.getSeconds() != 0)) {
		// Workaround to JavaScript bug: sometimes when adding days represented as milliseconds it would onhly add 23 hrs
		// Work out time in milliseconds
		time = newdate.getHours() * 60 * 60 * 1000;
		time += newdate.getMinutes() * 60 * 1000;
		time += newdate.getSeconds() * 1000;
		newdate = new Date(newdate.getTime() + time);
	}
	sArrDate = newdate.getDate() + ' ' + months[newdate.getMonth()] + ' ' + newdate.getFullYear();
	document.getElementById("arrdate").innerHTML = '&nbsp;&nbsp;&nbsp;<b>' + sArrDate + '</b>'
	
	iDay = newdate.getDate();
	iMonth = newdate.getMonth() + 1;
	iYear = newdate.getFullYear();

	oTxt = document.getElementById('enddate_d');	
	if (iDay < 10) { iDay = '0' + iDay; }
	oTxt.value = iDay;
	
	oTxt = document.getElementById('enddate_m');
	if (iMonth < 10) { iMonth = '0' + iMonth; }
	oTxt.value = iMonth;
	
	oTxt = document.getElementById('enddate_y');
	oTxt.value = iYear;	
}


function addDurationBYO_ST()
{
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

    oSelect = document.getElementById('startdate_d');
	iDay = oSelect.options[oSelect.selectedIndex].value;
	oSelect = document.getElementById('startdate_m');
	iMonth = oSelect.options[oSelect.selectedIndex].value;
	oSelect = document.getElementById('startdate_y');
	iYear = oSelect.options[oSelect.selectedIndex].value;
	cindate = new Date(iYear, iMonth - 1, iDay, 0, 0, 0);
	
	
	if (document.getElementById('durationType').value == 'Package')
	{oSelect = document.getElementById('durationPackage');}
	else
	{oSelect = document.getElementById('durationNormal');}
	
	
	if (oSelect.options[oSelect.selectedIndex].value == 'other')
	{
		tmpDuration = prompt("Please enter the number of nights","")
		if ( (tmpDuration==' ') || (tmpDuration==null) || (tmpDuration == ''))
		{
			iDuration = 7
			oSelect.options[0].selected = 'selected';
		}
		else
		{
			var stemp = tmpDuration
			if (stemp < 10)
			{
				stemp = "0" + stemp
			}
			for (loop=0; loop < oSelect.options.length; loop++)
			{
				if (oSelect.options[loop].value == stemp)
				{
					oSelect.options[loop].selected = 'selected';
					iDuration = stemp
				}
			}

			if (isNumeric(tmpDuration) == true)
			{	
				var opt = new Option(tmpDuration + ' days', tmpDuration);
				insertOptionAt (oSelect, opt, oSelect.options.length);
				iDuration = oSelect.options[oSelect.options.length-1].value;
				oSelect.selectIndex = oSelect.options.length;
				oSelect.options[oSelect.options.length-1].selected = 'selected';
			}
			else
			{
				iDuration = 7
				oSelect.options[0].selected = 'selected';
			}
		}
	}
	else
	{
		iDuration = oSelect.options[oSelect.selectedIndex].value;
	}

	// Amend the end date
	days = 1000 * 60 * 60 * 24 * iDuration;
	newdate = new Date(cindate.valueOf() + days);
	if ((newdate.getHours() != 0) || (newdate.getMinutes() != 0) || (newdate.getSeconds() != 0)) {
		// Workaround to JavaScript bug: sometimes when adding days represented as milliseconds it would onhly add 23 hrs
		// Work out time in milliseconds
		time = newdate.getHours() * 60 * 60 * 1000;
		time += newdate.getMinutes() * 60 * 1000;
		time += newdate.getSeconds() * 1000;
		newdate = new Date(newdate.getTime() + time);
	}
	sArrDate = newdate.getDate() + ' ' + months[newdate.getMonth()] + ' ' + newdate.getFullYear();
	document.getElementById("arrdate").innerHTML = '&nbsp;&nbsp;&nbsp;<b>' + sArrDate + '</b>'
	
	iDay = newdate.getDate();
	iMonth = newdate.getMonth() + 1;
	iYear = newdate.getFullYear();

	oTxt = document.getElementById('enddate_d');	
	if (iDay < 10) { iDay = '0' + iDay; }
	oTxt.value = iDay;
	
	oTxt = document.getElementById('enddate_m');
	if (iMonth < 10) { iMonth = '0' + iMonth; }
	oTxt.value = iMonth;
	
	oTxt = document.getElementById('enddate_y');
	oTxt.value = iYear;	
}

function isNumeric2(a) {
    return typeof a == 'number' && isFinite(a);
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function insertOptionAt (select, option, index) {
    for (var i = select.options.length; i > index; i--)
      select.options[i] = select.options[i - 1];
    select.options[index] = option;
  }


function getInnerHeight(iframe){
	var d=iframe.contentWindow ?
	iframe.contentWindow.document :
	iframe.contentDocument;
	var h=0;
	if(d){
		if(d.documentElement && d.compatMode && d.compatMode=="CSS1Compat")
		h=d.documentElement.scrollHeight;
		else if(d.body)
		h=d.body.scrollHeight;
		if(h) h+=getInsets(d);
		}
		// Add a bit on to stop it chopping off the bottom
		if(!ie4){
			h += 28;
		}else{
			h += 4;
		}
	return (h||300) - 50; //300 is a default value
	}



	function getInsets(d){
		if(d.body.currentStyle)
		with (d.body.currentStyle)
		return (parseInt(marginTop)||0) +
		(parseInt(marginBottom)||0) +
		(parseInt(paddingTop)||0) +
		(parseInt(paddingBottom)||0);
		if(d.defaultView && d.defaultView.getComputedStyle)
		with (d.defaultView)
		return parseInt(getComputedStyle(d.body,"").
		getPropertyValue("margin-top"))+
		parseInt(getComputedStyle(d.body,"").
		getPropertyValue("margin-bottom"))+
		parseInt(getComputedStyle(d.body,"").
		getPropertyValue("padding-top"))+
		parseInt(getComputedStyle(d.body,"").
		getPropertyValue("padding-bottom"));
		return 0;
	}
	
	var newIframe
	function resizeIframe(iframe) {
		newIframe = parent.document.getElementById(iframe)
		newIframe.style.height=getInnerHeight(newIframe)	
	}
function echeck(str) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
return (true)
}
return (false)
}
/* Start functions relating to MultipleRoomTypes */
function updateRooms(control, maxRooms) {
	if (control) {
		var iRooms = parseInt(control.options[control.selectedIndex].value);
		for (var iRoom=1;iRoom<=maxRooms;iRoom++) {
			var obj = document.getElementById('trRoom'+iRoom)
			if (obj) {
					if (iRoom > iRooms) {
						obj.style.display = 'none';
					} else {
						obj.style.display = 'block';
					}
			}
			
			var obj = document.getElementById('trRoom'+iRoom+'Values')
			if (obj) {
					if (iRoom > iRooms) {
						obj.style.display = 'none';
					} else {
						obj.style.display = 'block';
					}
			}
			var obj = document.getElementById('rowRoom'+iRoom+'Values')
			if (obj) {
					if (iRoom > iRooms) {
						obj.style.display = 'none';
					} else {
						obj.style.display = 'block';
					}
			}
		}		
	}
}

function updatePax(maxPax, maxAdults, maxChild, maxInfant) {
	var oRooms = document.getElementById('rooms');
	var iPax = 0, iAdults = 0, iChildren = 0, iInfants = 0, iTotalAdults = 0, iTotalChildren = 0, iTotalInfants = 0;
	var paxOkay =  false;
	sDisplay = 'block';
	if (oRooms) {
		paxOkay = true;
		var iRooms = parseInt(oRooms.options[oRooms.selectedIndex].value);
		for (var iRoom=1;iRoom<=iRooms;iRoom++) {
			iAdults = 0;
			iChildren = 0;
			iInfants = 0;
			
			var objAdult = document.getElementById('r'+iRoom+'a');
			if (objAdult) { iAdults = parseInt(objAdult.options[objAdult.selectedIndex].value); }

			var objChild = document.getElementById('r'+iRoom+'c');
			if (objChild) { iChildren = parseInt(objChild.options[objChild.selectedIndex].value); }	

			var objInfant = document.getElementById('r'+iRoom+'i');
			if (objInfant) { iInfants = parseInt(objInfant.options[objInfant.selectedIndex].value); }
			
			iPax += iAdults + iChildren + iInfants;

			if (maxPax != -1) {
				if (iPax > maxPax) { alert('The maximum number of people allowed across all rooms is ' + maxPax); paxOkay = false;}
			}

			if (paxOkay && maxAdults != -1) {
				if (iAdults > maxAdults) { alert('The maximum number of adults allowed in room ' + iRoom + ' is ' + maxAdults); paxOkay = false; }
			}

			if (paxOkay && maxChild != -1) {
				if (iChildren > maxChild) { alert('The maximum number of children allowed in room ' + iRoom + ' is ' + maxChild); paxOkay = false; }
			} 

			if (paxOkay && maxInfant != -1) {
				if (iInfants > maxInfant) { alert('The maximum number of infants allowed in room ' + iRoom + ' is ' + maxInfant); paxOkay = false; }
			}
			
			if (iChildren > 0 || iInfants > 0) {
				for (var iChild=1;iChild<=maxChild;iChild++) {
					obj = document.getElementById('r'+iRoom+'c_ages'+iChild);
						if (obj) {
							if (iChild <= iChildren) { 
							obj.style.display = sDisplay; 
							//alert("Show: " + obj.id);
						} else { 
							obj.style.display = 'none'; 
							//alert("Hide: " + obj.id);
						}
					}
				}	

				obj = document.getElementById('sCAges'+iRoom);
				if (obj) {
					if (iChildren < 1) { obj.style.display = 'none'; } else { obj.style.display = sDisplay; }
				}
				
				for (var iInfant=1;iInfant<=maxInfant;iInfant++) {
					obj = document.getElementById('r'+iRoom+'i_ages'+iInfant);
					if (obj) {
						if (iInfant <= iInfants) { obj.style.display = sDisplay; } else { obj.style.display = 'none'; }
					}
				}			
				
				obj = document.getElementById('sIAges'+iRoom);
				if (obj) {
					if (iInfants < 1) { obj.style.display = 'none'; } else { obj.style.display = sDisplay; }
				}
			}
			if (iChildren < 1) {
				// Hide children
				for (var iChild=1;iChild<=maxChild;iChild++) {
					obj = document.getElementById('r'+iRoom+'c_ages'+iChild);
					if (obj) { obj.style.display = 'none'; }
				}	

				obj = document.getElementById('sCAges'+iRoom);
				if (obj) { obj.style.display = 'none'; }		
			}

			if (iInfants < 1) {
				// Hide infants
				for (var iInfant=1;iInfant<=maxInfant;iInfant++) {
					obj = document.getElementById('r'+iRoom+'i_ages'+iInfant);
					if (obj) { obj.style.display = 'none'; }
				}	

				obj = document.getElementById('sIAges'+iRoom);
				if (obj) { obj.style.display = 'none'; }		
			}
			
			iTotalAdults += iAdults
			iTotalChildren += iChildren
			iTotalInfants += iInfants
		}
		var objSeats = document.getElementById('seats_adult')
		//if (objSeats && iAdults <= objSeats.options.length) { objSeats.options[iTotalAdults].selected = true; }
		var objSeats = document.getElementById('seats_child')
		//if (objSeats && iChildren <= objSeats.options.length) { objSeats.options[iTotalChildren].selected = true; }
		var objSeats = document.getElementById('seats_infant')
		//if (objSeats && iInfants <= objSeats.options.length) { objSeats.options[iTotalInfants].selected = true; }
	}
	//getInnerHeight(window.top.document.getElementById('ifSearch'))
	//if(window.top.document.getElementById('ifSearch')){
	//	window.top.document.getElementById('ifSearch').style.height=getInnerHeight(window.top.document.getElementById('ifSearch')) + 'px';
	//}
	return paxOkay;
}

function updateRoomsV2(control, maxRooms, SType) {
	if (control) {
		var iRooms = parseInt(control.options[control.selectedIndex].value);
		for (var iRoom=1;iRoom<=maxRooms;iRoom++) {
			var obj = document.getElementById('trRoom'+iRoom+SType)
			if (obj) {
					if (iRoom > iRooms) {
						obj.style.display = 'none';
					} else {
						obj.style.display = 'block';
					}
			}
			
			var obj = document.getElementById('trRoom'+iRoom+'Values'+SType)
			if (obj) {
					if (iRoom > iRooms) {
						obj.style.display = 'none';
					} else {
						obj.style.display = 'block';
					}
			}
			var obj = document.getElementById('rowRoom'+iRoom+'Values'+SType)
			if (obj) {
					if (iRoom > iRooms) {
						obj.style.display = 'none';
					} else {
						obj.style.display = 'block';
					}
			}
		}		
	}
}

function updatePaxV2(maxPax, maxAdults, maxChild, maxInfant, SType) {
	var oRooms = document.getElementById('rooms'+SType);
	var iPax = 0, iAdults = 0, iChildren = 0, iInfants = 0, iTotalAdults = 0, iTotalChildren = 0, iTotalInfants = 0;
	var paxOkay =  false;
	sDisplay = 'block';
	if (oRooms) {
		paxOkay = true;
		var iRooms = parseInt(oRooms.options[oRooms.selectedIndex].value);
		for (var iRoom=1;iRoom<=iRooms;iRoom++) {
			iAdults = 0;
			iChildren = 0;
			iInfants = 0;
			
			var objAdult = document.getElementById('r'+iRoom+'a'+SType);
			if (objAdult) { iAdults = parseInt(objAdult.options[objAdult.selectedIndex].value); }

			var objChild = document.getElementById('r'+iRoom+'c'+SType);
			if (objChild) { iChildren = parseInt(objChild.options[objChild.selectedIndex].value); }	

			var objInfant = document.getElementById('r'+iRoom+'i'+SType);
			if (objInfant) { iInfants = parseInt(objInfant.options[objInfant.selectedIndex].value); }
			
			iPax += iAdults + iChildren + iInfants;

			if (maxPax != -1) {
				if (iPax > maxPax) { alert('The maximum number of people allowed across all rooms is ' + maxPax); paxOkay = false;}
			}

			if (paxOkay && maxAdults != -1) {
				if (iAdults > maxAdults) { alert('The maximum number of adults allowed in room ' + iRoom + ' is ' + maxAdults); paxOkay = false; }
			}

			if (paxOkay && maxChild != -1) {
				if (iChildren > maxChild) { alert('The maximum number of children allowed in room ' + iRoom + ' is ' + maxChild); paxOkay = false; }
			} 

			if (paxOkay && maxInfant != -1) {
				if (iInfants > maxInfant) { alert('The maximum number of infants allowed in room ' + iRoom + ' is ' + maxInfant); paxOkay = false; }
			}
			
			if (iChildren > 0 || iInfants > 0) {
				for (var iChild=1;iChild<=maxChild;iChild++) {
					obj = document.getElementById('r'+iRoom+'c_ages'+iChild+SType);
						if (obj) {
							if (iChild <= iChildren) { 
							obj.style.display = sDisplay; 
							//alert("Show: " + obj.id);
						} else { 
							obj.style.display = 'none'; 
							//alert("Hide: " + obj.id);
						}
					}
				}	

				obj = document.getElementById('sCAges'+iRoom+SType);
				if (obj) {
					if (iChildren < 1) { obj.style.display = 'none'; } else { obj.style.display = sDisplay; }
				}
				
				for (var iInfant=1;iInfant<=maxInfant;iInfant++) {
					obj = document.getElementById('r'+iRoom+'i_ages'+iInfant+SType);
					if (obj) {
						if (iInfant <= iInfants) { obj.style.display = sDisplay; } else { obj.style.display = 'none'; }
					}
				}			
				
				obj = document.getElementById('sIAges'+iRoom+SType);
				if (obj) {
					if (iInfants < 1) { obj.style.display = 'none'; } else { obj.style.display = sDisplay; }
				}
			}
			if (iChildren < 1) {
				// Hide children
				for (var iChild=1;iChild<=maxChild;iChild++) {
					obj = document.getElementById('r'+iRoom+'c_ages'+iChild+SType);
					if (obj) { obj.style.display = 'none'; }
				}	

				obj = document.getElementById('sCAges'+iRoom+SType);
				if (obj) { obj.style.display = 'none'; }		
			}

			if (iInfants < 1) {
				// Hide infants
				for (var iInfant=1;iInfant<=maxInfant;iInfant++) {
					obj = document.getElementById('r'+iRoom+'i_ages'+iInfant+SType);
					if (obj) { obj.style.display = 'none'; }
				}	

				obj = document.getElementById('sIAges'+iRoom+SType);
				if (obj) { obj.style.display = 'none'; }		
			}
			
			iTotalAdults += iAdults
			iTotalChildren += iChildren
			iTotalInfants += iInfants
		}
		var objSeats = document.getElementById('seats_adult')
		//if (objSeats && iAdults <= objSeats.options.length) { objSeats.options[iTotalAdults].selected = true; }
		var objSeats = document.getElementById('seats_child')
		//if (objSeats && iChildren <= objSeats.options.length) { objSeats.options[iTotalChildren].selected = true; }
		var objSeats = document.getElementById('seats_infant')
		//if (objSeats && iInfants <= objSeats.options.length) { objSeats.options[iTotalInfants].selected = true; }
	}
	//getInnerHeight(window.top.document.getElementById('ifSearch'))
	//if(window.top.document.getElementById('ifSearch')){
	//	window.top.document.getElementById('ifSearch').style.height=getInnerHeight(window.top.document.getElementById('ifSearch')) + 'px';
	//}
	return paxOkay;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function getInnerHeight(iframe){
	var d=iframe.contentWindow ?
	iframe.contentWindow.document :
	iframe.contentDocument;
	var h=0;
	if(d){
		if(d.documentElement && d.compatMode && d.compatMode=="CSS1Compat")
		h=d.documentElement.scrollHeight;
		else if(d.body)
		h=d.body.scrollHeight;
		if(h) h+=getInsets(d);
		}
	return (h||200)+"px"; //300 is a default value
	}



	function getInsets(d){
		if(d.body.currentStyle)
		with (d.body.currentStyle)
		return (parseInt(marginTop)||0) +
		(parseInt(marginBottom)||0) +
		(parseInt(paddingTop)||0) +
		(parseInt(paddingBottom)||0);
		if(d.defaultView && d.defaultView.getComputedStyle)
		with (d.defaultView)
		return parseInt(getComputedStyle(d.body,"").
		getPropertyValue("margin-top"))+
		parseInt(getComputedStyle(d.body,"").
		getPropertyValue("margin-bottom"))+
		parseInt(getComputedStyle(d.body,"").
		getPropertyValue("padding-top"))+
		parseInt(getComputedStyle(d.body,"").
		getPropertyValue("padding-bottom"));
		return 0;
	}
	
	var newIframe
	function resizeIframe(iframe) {
		newIframe = parent.document.getElementById(iframe)
		newIframe.style.height=getInnerHeight(newIframe)	
	}

function LoadGoogleMap(sDiv, iLat, iLng) {
	if(document.getElementById(sDiv)) {
		sDiv = document.getElementById(sDiv)
		sDiv.style.width = '500px';
		sDiv.style.height = '220px';
		if (GBrowserIsCompatible()) {
			var mygmap = new GMap2(sDiv);
			//map.addControl(new YSliderControl());
			mygmap.addControl(new GSmallMapControl());
    		mygmap.addControl(new GMapTypeControl());
			mygmap.setCenter(new GLatLng(iLat, iLng), 13);
			var point = new GLatLng(iLat,iLng);
			mygmap.addOverlay(new GMarker(point));
		}
	}
}
function HideShowSection(ID)
{
	
	if (document.getElementById(ID)) {
		if(document.getElementById(ID).style.display == 'block')
		{document.getElementById(ID).style.display = 'none'}
		else
		{document.getElementById(ID).style.display = 'block'}
	}
}

function AddRemoveAges(SearchType)
{
	if (SearchType != 'Flight' && SearchType != 'PackageHoliday'){
		var MaxAge
		if (SearchType == 'Hotel'){MaxAge=18}else{MaxAge=11}
		
		for(var z = 1; z <= 3; z++) //loop for number of rooms
		{
			for(var y = 0; y <= 2; y++) //loop for number of children
			{
				for(var x = 0; x <= document.getElementById('r'+z+'c_ages'+(parseInt(y)+1)).options.length; x++) //loop to delete all current child age options
				{
					document.getElementById('r'+z+'c_ages'+(parseInt(y)+1)).options[x]=null
				}
				for(var i = 2; i <= MaxAge; i++) //loop to add in new child age options
				{
					document.getElementById('r'+z+'c_ages'+(parseInt(y)+1)).options[i-2] = new Option('Aged '+i+'yrs',i)
				}
			}
		}
	}
}

function selectAirport(){
	sAirport = document.getElementById('multipleAirports').options[document.getElementById('multipleAirports').selectedIndex].value;
	if(sAirport.length < 3){
		alert('Before you can continue you must select an aiport');
	}else{
		document.frmSearching.airportto.value = sAirport;
		div_switch('NonConfirmAirport',true,true);
		div_switch('ConfirmAirport',false,true)
		document.frmSearching.submit();
		document.getElementById('LoadingAnim').src = '/buildyourown/images/pleasewait/searching_anim.gif';
	}
}

function updateSearchDuration(strDate1,strDate2){
	myDateParts = strDate1.split("/");
	datDate1 = new Date(myDateParts[2], myDateParts[1]-1, myDateParts[0]);
	myDateParts2 = strDate2.split("/");
	datDate2 = new Date(myDateParts2[2], myDateParts2[1]-1, myDateParts2[0]);

	datDate1 = new Date(datDate1);
	datDate2 = new Date(datDate2);
	
	// NE JavaScript looks for GMT; if the dates cross over the daylight savings time then one time will always have 1 hour added, and so a comparison may be off slightly
	if (datDate1.getTimezoneOffset() < 0) { datDate1 = datDate1.getTime() + Math.abs(datDate1.getTimezoneOffset()) * 60 * 1000; } else { datDate1 = datDate1.getTime() - Math.abs(datDate1.getTimezoneOffset()) * 60 * 1000; }
	if (datDate2.getTimezoneOffset() < 0) { datDate2 = datDate2.getTime() + Math.abs(datDate2.getTimezoneOffset()) * 60 * 1000; } else { datDate2 = datDate2.getTime() - Math.abs(datDate2.getTimezoneOffset()) * 60 * 1000; }

	document.getElementById('duration').value = (datDate2-datDate1)/(24*60*60*1000)
}


//END GLOBAl.JS


//BUILDYOUROWN.JS
var bDebug;

	/* START MORE INFO AJAX */
		var sCurrentPosition = '';
		function GetMoreHotelInfo(sLink, sPosition, sProvider, sAccommCode, sGABProvID, sMulticomFAB, sSessionID) {
			sCurrentPosition = sPosition
			if(!sSessionID && document.getElementById('SessionID')){
					sSessionID = document.getElementById('SessionID').value
			}

			if(document.getElementById('divHotelInfo'+sPosition).style.display=='none') {
				sURL = '/buildyourown/includes/hotelinfo.asp?provider='+sProvider+'&accommcode='+sAccommCode+'&gabprovid='+sGABProvID+'&multicomfab='+sMulticomFAB+'&session='+sSessionID;
				if(sURL!='') {
					document.getElementById('divHotelInfo'+sPosition).style.display = '';
					document.getElementById('Description'+sCurrentPosition).innerHTML = '<div align="center"><img src="/buildyourown/images/ajax-loader.gif" /><br /><br /><span class="resultPleaseWait">Loading... Please wait.</span></div>'
					if(bDebug) {
						if(confirm('Open '+ sURL)) {
							window.open(sURL);
						}
					}
					setTimeout("loadInfoXMLDoc('"+sURL+"')", 100);
					sLink.innerHTML = 'Click here to hide more hotel information';
				}else{
					alert('No url defined');	
				}
			}else{
				sLink.innerHTML = 'Click here for more hotel information';
				document.getElementById('divHotelInfo'+sPosition).style.display = 'none';
			}
		}
		function loadInfoXMLDoc(url) {
			// branch for native XMLHttpRequest object
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
				req.onreadystatechange = processInfoChange;
				req.open("GET", url, true);
				req.send(null);
			// branch for IE/Windows ActiveX version
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
				if (req) {
					req.onreadystatechange = processInfoChange;
					req.open("GET", url, true);
					req.send();
				}
			}
		}
		function processInfoChange() {
			if (req.readyState == 4) {
				if (req.status == 200){
					xmldoc = req.responseXML.documentElement;
					sDescription = xmldoc.getElementsByTagName('Description').item(0).childNodes.item(0).nodeValue;
					iGoogleLat = parseFloat(xmldoc.getElementsByTagName('GoogleLat').item(0).childNodes.item(0).nodeValue);
					iGoogleLng = parseFloat(xmldoc.getElementsByTagName('GoogleLng').item(0).childNodes.item(0).nodeValue);
					images = xmldoc.getElementsByTagName('Image');
					document.getElementById('IMGThumbs'+sCurrentPosition).innerHTML = ''
					if(images.length>0) {
						for(x=0;x<images.length;x++) {
							sImage = images.item(x).childNodes.item(0).nodeValue;
							if(x==0){
								document.getElementById('IMGPlaceHolder'+sCurrentPosition).innerHTML = '<img src="'+sImage+'" id="placeHolder'+sCurrentPosition+'" onerror="this.src=\'/images/dp/nohotelimage.gif\'" />'	
							}
							if(images.length>1) {
								document.getElementById('IMGThumbs'+sCurrentPosition).innerHTML += '<img src='+sImage+' onclick=SwitchPhoto("placeHolder'+sCurrentPosition+'","'+sImage+'") onerror="this.src=\'/images/dp/nohotelimage.gif\'" />'
								document.getElementById('IMGThumbsText'+sCurrentPosition).style.display = '';
							}else{
								document.getElementById('IMGThumbs'+sCurrentPosition).style.display = 'none';
								document.getElementById('IMGPlaceHolder'+sCurrentPosition).style.borderBottom = '1px';
								
							}
						}
						document.getElementById('MoreInfoIMG'+sCurrentPosition).style.display='';
					}
					if(iGoogleLat!=0 && iGoogleLng!=0) {
						document.getElementById('GoogleMapContainer'+sCurrentPosition).style.display='';
						LoadGoogleMap('GoogleMap'+sCurrentPosition,iGoogleLat,iGoogleLng);
					}
					document.getElementById('Description'+sCurrentPosition).innerHTML = sDescription;
				}else{
					alert('More hotel information is not available');
					document.getElementById('divHotelInfo'+sCurrentPosition).style.display = 'none';
				}
			}
		}
	/* END MORE INFO AJAX */
	

function SwitchPhoto(PlaceHolderName,ThumbImg){
	var ImagePath = ThumbImg;
	if (document.all){
		document.getElementById(PlaceHolderName).style.filter="blendTrans(duration=1)";
		document.getElementById(PlaceHolderName).filters.blendTrans.Apply();
	}
	if(document.getElementById) {
		document.getElementById(PlaceHolderName).src = ImagePath;
	}else{
		document.HotelImage.src = ImagePath;
	}
	if(document.all){
		document.getElementById(PlaceHolderName).filters.blendTrans.Play();
	}
}

//END BUILDYOUROWN.JS


//RESULTS.JS

var outSelected, inSelected

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
	{ window.onload = func; }
	else
	{ window.onload = function() { oldonload(); func(); } }
}

function DummyDefaultSelection(lNumLegsOut, lNumLegsIn, lFlightPos, lOutRoutePos, lInRoutePos, fareid, csifareid, provider)
{	
	var bFound
	var bHasChecked
	var i
	i = 0
	
	if (lNumLegsOut > 1)
	{
		bFound = false;
		bHasChecked = false;
		// Check if any outbound flights have been selected
		oFormElements = document.getElementsByName('tblOutbound');
		do
		{
			if (i < oFormElements.length)
			{
				if (oFormElements.item(i).id == lFlightPos)
				{
					if (oFormElements.item(i).checked == true)
					{
						bFound = true;
						bHasChecked = true;
					}
				}
				i = i + 1
			}
			else
			{
				bFound = true;
			}
		} while (bFound == false)
		
		i = 0
		// If outbound flight has NOT been selected, choose first flight by default
		if (bHasChecked == false)
		{
			bFound = false;
			oFormElements = document.getElementsByName('tblOutbound');
			do
			{
				if (i < oFormElements.length)
				{
					if (oFormElements.item(i).id == lFlightPos)
					{
						oFormElements.item(i).checked = true;
						bFound = true;
					}
					i = i + 1;
				}
				else
				{
					bFound = true;
				}
			} while (bFound == false)
			document.frmResults.route_out.value=lOutRoutePos; 
			document.frmResults.CSI_ROUTEIDOUT.value=lOutRoutePos; 
			document.frmResults.route_out_position.value=lOutRoutePos; 
			outSelected = csifareid;
			
			//onClick('a','tblOutbound',lFlightPos,fareid,csifareid,lOutSegPos,provider);
		}
	}
	
	if (lNumLegsIn > 1)
	{
		i = 0
		bHasChecked = false;
		bFound = false;
		// Check if any inbound flights have been selected
		oFormElements = document.getElementsByName('tblInbound')
		do
		{
//			alert('i: ' + i + ' : oFormElements.length: ' + oFormElements.length);
			if (i < oFormElements.length)
			{
				if (oFormElements.item(i).id == lFlightPos)
				{
//					alert('Here');
					if (oFormElements.item(i).checked == true)
					{
						bFound = true;
						bHasChecked = true;
					}
				}
				i = i + 1
			}
			else
			{
				bFound = true
			}
		} while (bFound == false)
		
//		alert('i: ' + i + ' : oFormElements.length: ' + oFormElements.length);
//		alert('Inbound bFound: ' + bFound);
//		alert('Inbound bHasChecked: ' + bHasChecked);
		
		i = 0
		// If inbound flight has NOT been selected, choose first flight by default
		if (bHasChecked == false)
		{
			bFound = false;
			oFormElements = document.getElementsByName('tblInbound')
			do
			{
				if (i < oFormElements.length)
				{
					if (oFormElements.item(i).id == lFlightPos)
					{
						oFormElements.item(i).checked = true;
						bFound = true;
					}
					i = i + 1
				}
				else
				{
					bFound = true
				}
			} while (bFound == false)
			
//			alert('lInRoutePos: ' + lInRoutePos);
			
			document.frmResults.route_in.value=lInRoutePos;
			document.frmResults.CSI_ROUTEIDIN.value=lInRoutePos; 
			document.frmResults.route_in_position.value=lInRoutePos; 
			inSelected = csifareid;
			//onClick('a','tblInbound',lFlightPos,fareid,csifareid,lInSegPos,provider);
		}
	}
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=csifareid;
	document.frmResults.CSI_FAREID.value=csifareid;
	document.frmResults.fare_id.value=fareid;
	document.frmResults.Provider_Flight.value=provider;
}

function DummyClick(sName, lFlightPos, lSegPos)
{
	var bFound
	bFound = false
	var i
	i = 0
	var iSegCount
	iSegCount = 0
	
	oFormElements = document.getElementsByName(sName)
	do
	{
		if (i < oFormElements.length)
		{
			if (oFormElements.item(i).id == lFlightPos)
			{
				iSegCount = iSegCount + 1
				if (iSegCount == lSegPos)
				{
					oFormElements.item(i).checked = true
					bFound = true
				}
			}
			i = i + 1
		}
		else
		{
			bFound = true
		}
	} while (bFound == false)
}

function selectFlightOut(flight_id, position, fare_id, fId, routePosition, provider)
{
	var bFound
	bFound = false
	var i
	i = 0
	oFormElements = document.getElementsByName("tblOutbound")
	do
	{
		if (i < oFormElements.length)
		{
			if(oFormElements.item(i).id == flight_id)
			{
				oFormElements.item(i).checked = true;
				bFound = true
			}
			i = i + 1
		}
		else
		{
			bFound = true
		}
	} while (bFound == false)
	
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	if(outSelected != fId) {
		document.frmResults.route_out.value=position; 
		document.frmResults.CSI_ROUTEIDOUT.value=position; 
	}
	document.frmResults.route_out_position.value=routePosition;
}
function selectFlightIn(flight_id, position, fare_id, fId, routePosition, provider)
{
	var bFound
	bFound = false
	var i
	i = 0
	oFormElements = document.getElementsByName("tblInbound")
	do
	{
		if (i < oFormElements.length)
		{
			if(oFormElements.item(i).id == flight_id)
			{
				oFormElements.item(i).checked = true;
				bFound = true
			}
			i = i + 1
		}
		else
		{
			bFound = true
		}
	} while (bFound == false)
	
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	if(inSelected != fId) {
		document.frmResults.route_in.value=position; 
		document.frmResults.CSI_ROUTEIDIN.value=position;
	}
	document.frmResults.route_in_position.value=routePosition;
}

function selectHoveredFlight(flight_id, positionout, position, fare_id, fId, routePositionout, routePosition, provider)
{
	var bFound
	bFound = false
	var i
	i = 0
	oFormElements = document.getElementsByName("tblOutbound")
	do
	{
		if (i < oFormElements.length)
		{
			if(oFormElements.item(i).id == flight_id)
			{
				oFormElements.item(i).checked = true;
				bFound = true
			}
			i = i + 1
		}
		else
		{
			bFound = true
		}
	} while (bFound == false)
	bFound = false
	i = 0
	oFormElements = document.getElementsByName("tblInbound")
	do
	{
		if (i < oFormElements.length)
		{
			if(oFormElements.item(i).id == flight_id)
			{
				oFormElements.item(i).checked = true;
				bFound = true
			}
			i = i + 1
		}
		else
		{
			bFound = true
		}
	} while (bFound == false)
	
	oFormElement = document.getElementById('flight'+flight_id)
	oFormElement = document.getElementById('flightbutton'+flight_id)
	
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	
	
	if(inSelected != fId) {
		document.frmResults.route_in.value=position; 
		document.frmResults.CSI_ROUTEIDIN.value=position;
	}
	if(outSelected != fId) {
		document.frmResults.route_out.value=positionout; 
		document.frmResults.CSI_ROUTEIDOUT.value=positionout; 
	}
	document.frmResults.route_out_position.value=routePositionout;
	document.frmResults.route_in_position.value=routePosition;
}
function selectHoveredFlightOneWay(flight_id, positionout, fare_id, fId, routePositionout, provider)
{
	var bFound
	bFound = false
	var i
	i = 0
	oFormElements = document.getElementsByName("tblOutbound")
	
	do
	{
		if (i < oFormElements.length)
		{
			if(oFormElements.item(i).id == flight_id)
			{
				oFormElements.item(i).checked = true;
				bFound = true
			}
			i = i + 1
		}
		else
		{
			bFound = true
		}
	} while (bFound == false)
	
	oFormElement = document.getElementById('flight'+flight_id)
	oFormElement = document.getElementById('flightbutton'+flight_id)
	
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	
	if(outSelected != fId) {
		document.frmResults.route_out.value=positionout; 
		document.frmResults.CSI_ROUTEIDOUT.value=positionout; 
	}
	document.frmResults.route_out_position.value=routePositionout;
}
function switchBYOSearchForms(fId)
{
	if(fId[fId.selectedIndex].value=='Flight_Car')
	{ div_switch('searchOptionsAccomm',false,true); }
	else
	{ div_switch('searchOptionsAccomm',true,true); }
	if(fId[fId.selectedIndex].value=='Hotel')
	{ div_switch('searchOptionsFlights',false,true);div_switch('searchOptionsFlightsExt',false,true); }
	else
	{ div_switch('searchOptionsFlights',true,true);div_switch('searchOptionsFlightsExt',true,true); }
}
function setFilterHotels(sHotelName)
{ document.frmResults.txtIsPostBack.value="true"; if (document.frmResults.FilterHotels) document.frmResults.FilterHotels.value=sHotelName; }
function setLevel(fieldName, fId)
{ document.frmResults.txtLevel.value=fId; }
function setParentID(fId)
{ document.frmResults.ParentID.value=fId; }
function setFareID(fId)
{ document.frmResults.CSI_FAREID.value=fId; }
function setSortFlights(fId,datatype,order,sId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortFlights.value=fId + ";" + datatype + ";" + order+ ";" + sId; }
function setSortHotels(fId,datatype,order,sId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortHotels.value=fId + ";" + datatype + ";" + order + ";" + sId; }
function setSortCars(fId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortCars.value=fId; }
function setSearchType(searchId)
{ document.frmResults.search_type.value=searchId; }
function setAccomm(fieldName, fId, pId, sId, parentId, sessionId, expSupplier, expRoomCode, BoardCode)
{
	//alert("fieldName:" + fieldName + "\nfId:" + fId + "\nsId:" + sId + "\nparentId:" + parentId + "\nsessionId:" + sessionId + "\nexpSupplier:" + expSupplier + "\nexpRoomCode:" + expRoomCode + "\nBoardCode:" + BoardCode)
	if(BoardCode==null) BoardCode='';
	document.frmResults.accomm_id.value=fId;
	document.frmResults.Provider_Accomm.value=pId;
	document.frmResults.hrnQuoteKey.value=sId;
	document.frmResults.expRoomCode.value=expRoomCode;
	document.frmResults.ParentID.value=parentId;
	document.frmResults.exp_supplier.value=expSupplier;
	document.frmResults.BoardCode.value=BoardCode;
}
function setPackageHoliday(sProvider,sId) {
	document.frmResults.Provider_PackageHoliday.value=sProvider;
	document.frmResults.packageholiday_itineraryid.value=sId;
	document.frmResults.Provider_Flight.value=sProvider; // NE 02/09/2008
}
function setProvider(fieldName, fId) {
	//alert("fieldName:" + fieldName + "\nfId:" + fId)
	document.frmResults.Provider_Flight.value=fId;
	document.frmResults.txtIsPostBack.value="true";
}
function updatePricingTotals(iPaxQty)
{
	fId = document.frmResults;
	//Get base price
	dTotalPrice = parseFloat(fId.basePrice.value);
	//Check for options and extras and add to total price
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type=="checkbox" && oFormElements.item(i).name=="CarExtras")
		{	
			if(oFormElements.item(i).checked && oFormElements.item(i).getAttribute("itemValue") != undefined)
			{ dTotalPrice += parseFloat(oFormElements.item(i).getAttribute("itemValue")); }
		}
		if(oFormElements.item(i).type=="radio" && (oFormElements.item(i).name=="delopt" || oFormElements.item(i).name.indexOf("_RoomID") > 0))
		{
			if(oFormElements.item(i).checked && oFormElements.item(i).getAttribute("itemValue") != undefined)
			{ dTotalPrice += parseFloat(oFormElements.item(i).getAttribute("itemValue")); }
		}
	}
	//Update totals on page
	writeInDiv(formatCurrency(dTotalPrice),'total_cost');
	writeInDiv(formatCurrency(dTotalPrice),'total_cost_overall');
	writeInDiv(formatCurrency(dTotalPrice),'total_costTop');
	writeInDiv(formatCurrency(dTotalPrice / iPaxQty),'perpax_cost');
	writeInDiv(formatCurrency(dTotalPrice / iPaxQty),'perpax_costTop');
}
function setPrices(expediaPrice,roomName,paxQty)
{
	document.frmResults.expedia_Price.value=expediaPrice; writeInDiv(roomName,'currentRoomName');
	writeInDiv(formatCurrency(parseFloat(expediaPrice)),'total_cost');
	writeInDiv(formatCurrency(parseFloat(expediaPrice) / paxQty),'perpax_costTop');
	/*
	document.frmResults.expedia_Price.value=expediaPrice; writeInDiv(roomName,'currentRoomName');
	if(document.frmResults.delopt.length == undefined)
	{ writeInDiv(formatCurrency(parseFloat(document.frmResults.delopt.totalValue)+expediaPrice),'total_cost'); writeInDiv(formatCurrency(parseFloat(document.frmResults.delopt.totalValue)+expediaPrice),'total_costTop'); writeInDiv(formatCurrency((parseFloat(document.frmResults.delopt.totalValue)+expediaPrice) / paxQty),'perpax_cost'); writeInDiv(formatCurrency((parseFloat(document.frmResults.delopt.totalValue)+expediaPrice) / paxQty),'perpax_costTop'); }
	else
	{
		for (var i=0; i < document.frmResults.delopt.length; i++)
		{ if(document.frmResults.delopt[i].checked) { writeInDiv(formatCurrency(parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice),'total_cost'); writeInDiv(formatCurrency(parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice),'total_costTop'); writeInDiv(formatCurrency((parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice) / paxQty),'perpax_cost'); writeInDiv(formatCurrency((parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice) / paxQty),'perpax_costTop'); } }
	}*/
}
function setDeliveryPrices(delOptionPrice,paxQty)
{
	if(document.frmResults.medhotels_RoomID == undefined)
	{ var fId = document.frmResults.expedia_RoomID; }
	else
	{ var fId = document.frmResults.medhotels_RoomID; }
	if(fId.length == undefined)
	{ writeInDiv(formatCurrency(parseFloat(fId.totalValue)+delOptionPrice),'total_cost'); writeInDiv(formatCurrency(parseFloat(fId.totalValue)+delOptionPrice),'total_costTop'); writeInDiv(formatCurrency((parseFloat(fId.totalValue)+delOptionPrice) / paxQty),'perpax_cost'); writeInDiv(formatCurrency((parseFloat(fId.totalValue)+delOptionPrice) / paxQty),'perpax_costTop'); }
	else
	{
		for (var i=0; i < fId.length; i++)
		{ if(fId[i].checked) { writeInDiv(formatCurrency(parseFloat(fId[i].totalValue)+delOptionPrice),'total_cost'); writeInDiv(formatCurrency(parseFloat(fId[i].totalValue)+delOptionPrice),'total_costTop'); writeInDiv(formatCurrency((parseFloat(fId[i].totalValue)+delOptionPrice) / paxQty),'perpax_cost'); writeInDiv(formatCurrency((parseFloat(fId[i].totalValue)+delOptionPrice) / paxQty),'perpax_costTop'); } }
	}
}
function setLMPrice(lmPrice)
{
	document.frmResults.flight_cost.value=lmPrice;
	writeInDiv(lmPrice,'total_cost');
	alert (document.frmResults.flight_cost.value)
}

function onClick(td, tablename, position, fare_id, fId, routePosition, provider)
{
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	if (tablename == "tblOutbound")
	{ 
		document.frmResults.route_out.value=position; document.frmResults.CSI_ROUTEIDOUT.value=position; document.frmResults.route_out_position.value=routePosition; 
		outSelected = fId;
	}
	else if (tablename == "tblInbound")
	{ 
		document.frmResults.route_in.value=position; document.frmResults.CSI_ROUTEIDIN.value=position; document.frmResults.route_in_position.value=routePosition; 
		inSelected = fId;
	}
}

function SetDevLayer(ShowDiv)
{ document.frmResults.ShowDiv.value=ShowDiv; }
function ChangePageFlights(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberflights.value=pagenumber; document.frmResults.ShowDiv.value='flights'; submitform('','Please wait while we retrieve another page of flight results.'); }
function ChangePageHotels(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberhotels.value=pagenumber; document.frmResults.ShowDiv.value='accomm'; submitform('','Please wait while we retrieve another page of results.'); }
function ChangePagePackageHolidays(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberpackageholidays.value=pagenumber; document.frmResults.ShowDiv.value='packageholidays'; submitform('','Please wait while we retrieve another page of results.'); }
function submitform(level,msg) {
	document.getElementById('LoadingAnim').src='/buildyourown/images/pleasewait/searching_anim.gif';
	document.frmResults.submit();
	if(level=='booking') 
		{ div_switch('data',false,true); }
	else 
		{ div_switch('flights',false,true); 
		div_switch('cars',false,true);
		div_switch('accomm',false,true); }
	div_switch('divWait',true,true); 
	writeInDiv(msg,'waitMessage'); 
	document.getElementById('LoadingAnim').src='/buildyourown/images/pleasewait/searching_anim.gif';
}

/*function submitform(level,msg)
{
	document.frmResults.submit();
	if(level=='booking') { div_switch('data',false,true); }
	else { div_switch('flights',false,true); }
	div_switch('divWait',true,true); 
	writeInDiv(msg,'waitMessage')
}*/
function PassengerInput(NoOfPax)
{ var x = 1; while (x < NoOfPax) { document.write('Pax Test'); x = x+1; } }
function setCarOption(position) { document.frmResults.car_position.value=position; }
function setCarOptionEx(position,supplier) { document.frmResults.car_position.value=position;document.frmResults.car_provider.value=supplier; }
function fetchMoreHotels(cacheKey, cacheLocation)
{ document.frmResults.fetchMoreHotels.value='true'; document.frmResults.cacheKey.value=cacheKey; document.frmResults.cacheLocation.value=cacheLocation; document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="false"; submitform('','Please wait while we retrieve more hotel results.'); }
function checkSelectedFlights()
{
	if (checkSelectedFlightsEx()) {
		submitform('','Please wait while we update your prices based on your new flight selection.'); }
}

function checkSelectedFlightsEx(flightId) {
	var bSelOutBound = false;
	var bSelInBound = false;
	var iOutBoundFlightID = '';
	var iInBoundFlightID = '';
	
	oOutBoundElements = document.getElementsByName("tblOutbound")
	oInBoundElements = document.getElementsByName("tblInbound")
	if (oInBoundElements.length > 0) {
		for (var i=0; i<oOutBoundElements.length; i++) {
			if (oOutBoundElements[i].checked)	{ bSelOutBound = true; iOutBoundFlightID = oOutBoundElements[i].id;}
			else { bSelOutBound = false; }
			if (bSelOutBound == true) break;
		}
	
		for (var i=0; i<oInBoundElements.length; i++)	{
			if (oInBoundElements[i].checked) { bSelInBound = true; iInBoundFlightID = oInBoundElements[i].id; }
			else { bSelInBound = false; }
			if (bSelInBound == true) break;
		}
		
		if(bSelOutBound==true && bSelInBound==true) 
		{
			if(iOutBoundFlightID==iInBoundFlightID && iOutBoundFlightID==flightId)  
			{ return true; }
			else
			{
				alert('Sorry, you must select an outbound and an inbound flight!'); 
				return false;
			}
		}	
		else 
		{
			alert('Sorry, you must select an outbound and an inbound flight!'); 
			return false;  
		}
	} else {
		// There is no inbound flight - this is a one way flight
		return checkSelectedFlightsExOneWay(flightId);
	}
	//if(flightId != ''){
		//if(outSelected != flightId) { alert('Please select an outbound flight!'); return false; }
		//if(inSelected != flightId) { alert('Please select an inbound flight!'); return false; }
	//}
	
	/*for (var i=0; i<document.frmResults.tblOutbound.length; i++)
	{
		if (document.frmResults.tblOutbound[i].checked)
		{ bSelOutBound = true; iOutBoundFlightID = document.frmResults.tblOutbound[i].id;}
		else
		{ bSelOutBound = false; }
		if (bSelOutBound == true) break;
	}
	for (var i=0; i<document.frmResults.tblInbound.length; i++)
	{
		if (document.frmResults.tblInbound[i].checked)
		{ bSelInBound = true; iInBoundFlightID = document.frmResults.tblInbound[i].id; }
		else
		{ bSelInBound = false; }
		if (bSelInBound == true) break;
	}
	if(bSelOutBound==true && bSelInBound==true)
	{
		if(iOutBoundFlightID==iInBoundFlightID) 
		{ return true; }
		else
		{ alert('When selecting alternative flights, the outbound and inbound routes must be from the same flight!'); return false; }
	}
	else
		{return true; }*/
	return true;
	//{ alert('Sorry, you must select an outbound and an inbound flight!'); return false; }
}

function checkSelectedFlightsExOneWay(flightId) {
	var bSelOutBound = false;
	var iOutBoundFlightID = '';
	oOutBoundElements = document.getElementsByName("tblOutbound")
	for (var i=0; i<oOutBoundElements.length; i++)
	{
		if (oOutBoundElements[i].checked)
		{ bSelOutBound = true; iOutBoundFlightID = oOutBoundElements[i].id;}
		else
		{ bSelOutBound = false; }
		if (bSelOutBound == true) break;
	}
	if(bSelOutBound==true)
	{
		return true; 
	}
	else
	{
		alert('Sorry, you must select an outbound and an inbound flight!');
		return false;
	}
}

function checkPaxForm(sBookLevel, sParentID, startdate, PAX)
{
	if(checkFormFieldSelectedIndex("title", "Please select a title for all passengers!") == false)
	{ return false; }
	else if(checkFormFieldValue("firstname", "- Firstname -", "Please enter a valid first name for all passengers!") == false)
	{ return false; }
	else if(checkFormFieldValue("surname", "- Surname -", "Please enter a valid surname for all passengers!") == false)
	{ return false; }
	else if(checkFormFieldAges("Please check the following date of births!") == false)
	{ return false; }
	else if(checkLeadPassengerOver18(document.getElementById('AgeCheckDepDate').value) == false)
	{ return false; }
	else if(!echeck(document.getElementById('email').value))
	{
		alert("Please enter a valid lead email address!");
		return (false);
	}
	else if(checkPassportInfo(parseInt(PAX), startdate) == false) 
	{ return false; }
	else if(checkAgeDOBMatch(document.getElementById('AgeCheckNoChilds').value, document.getElementById('AgeCheckNoAdults').value, document.getElementById('AgeCheckDepDate').value, document.getElementById('AgeCheckSearchType').value) == false)
	{ return false; }
	else 
	{
		for(var i = 1; i <= parseInt(PAX); i++) 
		{
			if(document.getElementById('infoPassportNum'+i)) 
			{document.getElementById('infoPassportNum'+i).value = document.getElementById('infoPassportNum'+i).value.replace(' ', '');}
		}		
		div_switch('data',false,true); 
		div_switch('divWait',true,true); 
		setLevel('txtLevel',sBookLevel);
		if(sParentID!='') { setParentID(sParentID); }
		submitform('booking','Please wait whilst we process your booking.');
	}
}

function echeck(str) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(str)){
return (true)
}
return (false)
}


function checkPassportInfo(iNumPax, dReturnDate) {
	for(var i = 1; i <= iNumPax; i++) {
		if(document.getElementById('infoPassportNum'+i)) {
			if(!checkAlpha(document.getElementById('infoPassportNum'+i).value.replace(' ', '').substring(0, 3))) {
				alert('Passenger '+i+': The passport country entered is not valid, this should be a three letter code.');
				return false;
			} else if(!checkNumeric(document.getElementById('infoPassportNum'+i).value.replace(' ', '').substring(3))) {
				alert('Passenger '+i+': The passport number entered contains invalid characters.');
				return false;
			}
			var sExpiryDay = document.getElementById('infoPassportExpiryD'+i).options[document.getElementById('infoPassportExpiryD'+i).selectedIndex].value;
			var sExpiryMonth = document.getElementById('infoPassportExpiryM'+i).options[document.getElementById('infoPassportExpiryM'+i).selectedIndex].value;
			var sExpiryYear = document.getElementById('infoPassportExpiryY'+i).options[document.getElementById('infoPassportExpiryY'+i).selectedIndex].value;
			var arReturn = dReturnDate.split('/');
			
			var sExpiry = sExpiryDay + "/" + sExpiryMonth + "/" + sExpiryYear;
			if(!(new Date(sExpiryYear, sExpiryMonth, sExpiryDay)).getTime()) { alert('Passenger '+i+': Invalid passport expiry date.'); return false; }
			else if((new Date(sExpiryYear, sExpiryMonth, sExpiryDay)).getTime() <= (new Date(arReturn[2], arReturn[1], arReturn[0])).getTime()) {
				alert('Passenger '+i+': The expiry date for the passport entered will expire before the return date. A valid passport at time of travel is required in order to book.');
				return false;
			}
		}
	}
}

function checkAlpha(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function checkNumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

function checkBYOForm(fId)
{
	if(fId.airportfrom.selectedIndex == 0)
	{ alert("Please select a departure airport!"); fId.airportfrom.focus(); return false; }
	else if(fId.airportto == undefined && fId.locationto == undefined && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please enter a destination (min. 3 characters)!"); fId.lookup.focus(); return false; }
	else if(fId.airportto != undefined && fId.airportto[fId.airportto.selectedIndex].value == "" && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please confirm your destination or enter a new search (min. 3 characters)!"); fId.airportto.focus(); return false; }
	else if(fId.locationto != undefined && fId.locationto[fId.locationto.selectedIndex].value == "" && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please confirm your destination or enter a new search (min. 3 characters)!"); fId.locationto.focus(); return false; }
	else if(checkValidDate(fId) == false)
	{ alert("Please select an alternative departure date!\nThe date you have selected is unavailable."); fId.startdate_d.focus(); return false; }
	else if(checkTimeTravel(fId) == false)
	{ alert("Please select an alternative return date!\nYour departure date is after your return date."); fId.enddate_d.focus(); return false; }
	else
	{ return true; }
}

function getTotalPrice(type) {
	// For use with MultipleRoom types; calculates the price of selected rooms
	var totalPrice = 0;
	if (document.getElementById('RoomCount')) {
		var iRooms = parseInt(document.getElementById('RoomCount').value);
		switch (type) {
			case 'radio': // Room options are in check boxes
				for (var iRoom=0; iRoom<iRooms; iRoom ++) {
					var iOption=1;
					while (document.getElementById('barceloRoomID'+(iRoom+1)+iOption)) {
						if (document.getElementById('barceloRoomID'+(iRoom+1)+iOption).checked) {
							var sValue = document.getElementById('barceloRoomID'+(iRoom+1)+iOption).value;
							var sValues = sValue.split('|');
							totalPrice += parseFloat(sValues[1]);
						}
						iOption ++;
					}
					//var iOption=1;
					//var iOptionLoop=1;
//					var bFound=false;
//					while ( bFound==false)
//					{
//						if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption))
//						{
//							if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).checked) {
//								
//								var sValue = document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).value;
//								var sValues = sValue.split('|');
//								totalPrice += parseFloat(sValues[1]);
//								bFound = true;
//							}
//						}
//						iOption ++;
//						if ( iOption==10) {bFound=true;}
//					}
					var iOption=1;
					while (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption)) {
						if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).checked) {
							var sValue = document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).value;
							var sValues = sValue.split('|');
							totalPrice += parseFloat(sValues[1]);
						}
						iOption ++;
					}
				}
				break;
		}		
	}
	return totalPrice;
}

function checkHBBoard(type) {
	// For use with MultupleRoom types; checks to see if all the selected rooms have the same board type (this is necessary for HotelBeds)
	var bAllSame = true;
	var sBoard = '';
	
	if (document.getElementById('RoomCount')) {
		var iRooms = parseInt(document.getElementById('RoomCount').value);
		
		switch (type) {
			case 'radio': // Room options are in check boxes
				for (var iRoom=0; iRoom<iRooms; iRoom ++) {
					var iOption=1;
					while (document.getElementById('barceloRoomID'+(iRoom+1)+iOption) && bAllSame) {
						if (document.getElementById('barceloRoomID'+(iRoom+1)+iOption).checked) {
							var sValue = document.getElementById('barceloRoomID'+(iRoom+1)+iOption).value;
							var sValues = sValue.split('|');
							if (iRoom == 0 && iOption == 1) {
								// First board  - set the sBoard variable
								sBoard = sValues[2];
							} else {
								// Compare with fthe first board item
								if (sBoard != sValues[2]) bAllSame = false;							
							}
						}
						iOption ++;
					}
				}
				break;
		}
	}
	return bAllSame;	
}

var bCarhire = false;


function setSearchGrid(sClass, sSearch, sButtonID, sPage){
	var bDebug; bDebug = false;
	var bShow; bShow = false;
	var bDoNothing;
		
	var oClass
	oClass = sClass.split(",");
	
	sDebug = "sClass:" + sClass + "\n";
	sDebug = sDebug + "sSearch:" + sSearch + "\n";
	sDebug = sDebug + "sButtonID:" + sButtonID + "\n";
	
	if(bDebug) alert(sDebug);
	// Loop through all the fields on the page and only show the ones that are relevant to the button they
	// have clicked (ie Flight + Hotel)
	// This uses class names to choose the fields to show / hide
	var alltags=document.all? document.all : document.getElementsByTagName("*"); 
	for (i=0; i<alltags.length; i++){ 
		bShow = false;
		bDoNothing = false;
		if(alltags[i].id.lastIndexOf('rowCarhire')==0){
			bDoNothing = true;
		}else{
			for(x=0; x<oClass.length; x++){	
				if(sClass=='ALL'){
					if (alltags[i].className.lastIndexOf('fieldCar')>=0 && bCarhire == false){
						bShow = false;
					}else if(alltags[i].className.substr(0, 5) == 'field'){
						bShow = true;
					}
					if (alltags[i].className.lastIndexOf('fieldFlight_only')>=0 && sClass == 'Flight'){
						bShow = true;
					}else if(alltags[i].className.lastIndexOf('fieldFlight_only')>=0){
						bShow = false;
					}					
				}else if (alltags[i].className.lastIndexOf(oClass[x])>=0){
					bShow = true;
				}
			}
		}
		if(bDoNothing == false){
			if(bShow == true){
				if(ie4){
					alltags[i].style.display = 'inline';
				}else{
					if(sPage == 'Home'){
						alltags[i].style.display = 'inline';
					}else{
						alltags[i].style.display = 'table-inline';
					}
					
				}
			}else if(alltags[i].className.substr(0, 5) == 'field'){
				alltags[i].style.display = 'none';
			}
		}
	} 
	
	sSearch = sSearch.substr(0,1).toUpperCase() + sSearch.substr(1,sSearch.length);
	
	if(document.getElementById("search_type"))
		document.getElementById("search_type").value = sSearch;
	
	if(document.getElementById('Button1')){
		for (i=1; i<5; i++){
			if('Button'+i == sButtonID){
					document.getElementById('Button'+i).src='/images/search_'+sSearch.toLowerCase()+'1.gif';
					if(bDebug) alert("y:" + i);
			}else if('Button'+i != sButtonID){
					document.getElementById('Button'+i).src=document.getElementById('Button'+i).src.replace('1.gif', '0.gif');
					if(bDebug) alert("n:" + i);
			}
			if(sButtonID != ''){
				if(document.getElementById('Button'+i).src.lastIndexOf('/images/search_'+sSearch.toLowerCase()+'0.gif')>=0){
					document.getElementById('Button'+i).src='/images/search_'+sSearch.toLowerCase()+'1.gif';
				}
			}
		}
	}
	if(document.getElementById("rowCarhireON")) checkCarhire();
	
	if(document.getElementById("trHotelRooms")){
		if(sSearch == 'Package'){
			document.getElementById("trHotelRooms").style.display = 'none';
			//document.getElementById("trRoom1").style.display = 'none';
			//document.getElementById("trPax").style.display = 'block';
			document.getElementById("trRoom1").style.display = 'block';
			document.getElementById("trPax").style.display = 'none';
		}else{
			document.getElementById("trHotelRooms").style.display = 'block';
		}
	}
}

function checkLeadPassengerOver18(DepDate){
		var i, today, d, by, bm, bd, bday, age, dif, DOB
		var ErrTxt = ""
		
				//get depdate in correct format
				d =DepDate.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				today = new Date(by,bm,bd) 
				
				//get childs DOB in correct format
				DOB = document.getElementById('dobd1').value + "/" + document.getElementById('dobm1').value + "/" + document.getElementById('doby1').value
				d =DOB.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				bday = new Date(by,bm,bd) 
				age=0; dif=bday; 
				
				while(dif<today)
				{ 
					dif = new Date(by+age,bm,parseInt(bd)-1); 
					age++; 
				} 
				age +=-2 ; 
				if (parseInt(age) < 18)
				{
				ErrTxt = "Please ensure that the lead passenger is over 18 years of age at time of departure."
				//return false; break;
				}
				
			if (ErrTxt == "")
				{return true;}
			else
				{alert(ErrTxt); return false;}
} 

function updatePrices(flightCost, carCost, flightDep, carDep, numPeople) {
	var iAccomm = 0;
	var iFlight = parseFloat(flightCost);
	var iCar = 	parseFloat(carCost);
	var iAccommDep = 0;
	var iFlightDep = parseFloat(flightDep);
	var iCarDep = parseFloat(carDep);	
	
	// start gta
	selectedRadio = document.getElementsByName('gab_RoomID')
	for(i=0;i<selectedRadio.length;i++) {
		if(selectedRadio[i].checked==true) {
			iAccommDep += parseFloat(selectedRadio[i].getAttribute('accommDepPrice'));
			iAccomm += parseFloat(selectedRadio[i].getAttribute('accommPrice'));
		}
		
	}
	//end gta
	for(x=1;x<4;x++) {
		selectedRadio = document.getElementsByName('gab_RoomID'+x)
		for(i=0;i<selectedRadio.length;i++) {
			if(selectedRadio[i].checked==true) {
				iAccommDep += parseFloat(selectedRadio[i].getAttribute('accommDepPrice'));
				iAccomm += parseFloat(selectedRadio[i].getAttribute('accommPrice'));
				//alert(parseFloat(selectedRadio[i].getAttribute('accommPrice')));
				//alert(parseFloat(selectedRadio[i].getAttribute('accommDepPrice')));
			}
		}
	}
	
	//alert('iAccomm: '+iAccomm)
	//alert('iFlight: '+iFlight)
	iTotalPrice = iAccomm+iFlight+iCar;
	iTotalDepPrice = iAccommDep+iFlightDep+iCarDep;
	iPricePerPerson = iTotalPrice / numPeople;
	iDepPerPerson = iTotalDepPrice / numPeople;
	//total_cost
	//alert(iTotalPrice);
	writeInDiv(formatCurrency(iTotalPrice),'total_cost'); 
	writeInDiv(formatCurrency(iTotalPrice),'total_costTop');
	writeInDiv(formatCurrency(iPricePerPerson),'costPerPax');
	writeInDiv(formatCurrency(iDepPerPerson),'deposit_cost');
	
	//alert(iTotalDepPrice);
	//alert(numPeople);
}

function setRoomPrices() {
	var sShowPrice = '';
	for(i=1;i<4;i++) {
		if(document.getElementById('Room'+i+'OriginalPrice')) {
			originalPrice = parseFloat(document.getElementById('Room'+i+'OriginalPrice').value);
			for(x=0;x<16;x++) {
				if(document.getElementById(i+'_'+x+'_ShowPrice') && document.getElementById(i+'_'+x+'_Price')) {
					RoomPrice = parseFloat(document.getElementById(i+'_'+x+'_Price').value)
					TextHolder = document.getElementById(i+'_'+x+'_ShowPrice')
					if(originalPrice==RoomPrice) {
						sShowPrice = 'incl.';
					}else if(originalPrice>RoomPrice){
						sShowPrice = '-'+formatCurrency(originalPrice-RoomPrice)
					}else if(originalPrice<RoomPrice){
						sShowPrice = formatCurrency(RoomPrice-originalPrice)
					}
					TextHolder.innerHTML = sShowPrice;
				}
			}
		}
	}
}

function changeBoardtype(id) {
	var iFoundSelected = 0;
	if(document.getElementById('available_boardtypes')) {
		sSelect = document.getElementById('available_boardtypes')
		for(x=0;x<sSelect.length;x++) {
			for(i=1;i<4;i++) {
				for(y=0;y<32;y++) {
					if(document.getElementById(sSelect[x].value+'_'+i+'_'+y)) {
						document.getElementById(sSelect[x].value+'_'+i+'_'+y).style.display='none';
					}
				}
			}
		}
	}
	for(i=1;i<4;i++) {
		iFoundSelected = 0;
		for(x=0;x<32;x++) {
			if(document.getElementById(id+'_'+i+'_'+x) && document.getElementById('RB_'+i+'_'+x)) {
				if(document.getElementById(id+'_'+i+'_'+x)) {
					document.getElementById(id+'_'+i+'_'+x).style.display='';
				}
				if(iFoundSelected==0 && document.getElementById('RB_'+i+'_'+x)) {
					iFoundSelected = 1;
					document.getElementById('RB_'+i+'_'+x).checked = true;
					if(bTotalRoomPricesSet==0) {
						document.getElementById('Room'+i+'OriginalPrice').value = document.getElementById('RB_'+i+'_'+x).getAttribute('accommPrice');
					}
				}
			}
		}
	}
	bTotalRoomPricesSet = 1;
}
function setHotelCacheKey(key) {
	el = document.frmResults.hotelCacheKey;
	if (el) { el.value = key; }
}


function setMultipleRoomFields(NumRooms, AccommCode)
{
	var i;
	for(i=1;i<=NumRooms;i++)
		{
			document.getElementById('Room'+i+'Choice').value = checkRadio('sSelectedRoomType'+AccommCode+i);
		}
}
function toggleRoomTypes(accommCode,optionCount,roomnum){
	//for(i=4;i<=optionCount;i++){
		room = document.getElementById('divRoomBlock'+accommCode+roomnum)
		//alert('sRoomBlock'+accommCode+i);
		if (room.style.display != "block"){
			div_switch('divRoomBlock'+accommCode+roomnum,true,true);	
			writeInDiv('Less room options','moreOptionText' + accommCode + roomnum);	
			document.getElementById('moreOptionImage' + accommCode + roomnum).src='http://new.barrhead.csiadmin.co.uk/buildyourown/images/ico_minus.gif';
		}else{
			div_switch('divRoomBlock'+accommCode+roomnum,false,true);
			writeInDiv('More room options','moreOptionText' + accommCode + roomnum);
			document.getElementById('moreOptionImage' + accommCode + roomnum).src='http://new.barrhead.csiadmin.co.uk/buildyourown/images/ico_plus.gif';
		}
		
	//}
}


function toggleBG(accommCode,selectedOption,totalOptions){
	var odd = true
	for(i=1;i<=totalOptions;i++){
		if(document.getElementById('sRoomBlock'+accommCode+i)) {
			room = document.getElementById('sRoomBlock'+accommCode+i);
			if(odd == true){
				room.style.backgroundColor = '#C0DDDB';			
			}else{
				room.style.backgroundColor = '#DCECEB';
			}
			if(odd == true){odd = false}else{odd = true};
		}
	}
	document.getElementById('sRoomBlock'+accommCode+selectedOption).style.backgroundColor = '#E4C5C9';
}

function checkSelectedFlightsMultiRoom()
{
	var bSelOutBound = false;
	var bSelInBound = false;
	var iOutBoundFlightID = '';
	var iInBoundFlightID = '';
	
	submitform();
}

function Check2SelectedFlights(ID)
{
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).id != ID)
		{oFormElements.item(i).checked = false;}
		else
		{oFormElements.item(i).checked = true;}
	}
}

iHotelPos = 0;
//function UpdateMultiRoomPrices(AccommCode, NumRooms)
//{
//	iHotelPos += 1;

	//if (iHotelPos == 1) alert('AccommCode:'+AccommCode+'-NumRooms:'+NumRooms+'-Flight-Cost:'+document.getElementById('MultiRoom_FlightPrice').value);
//	var NewOverallCost = parseFloat(document.getElementById('MultiRoom_FlightPrice').value);
//	for (z = 1; z <= NumRooms; z++)
//	{
//		NewOverallCost += parseFloat(checkRadioMultiRoom('sSelectedRoomType'+AccommCode+z, 'roomValue'))
//	}
//	writeInDiv('&#163;' + NewOverallCost.toFixed(2), 'totalprice'+AccommCode);
//}
function UpdateMultiRoomPrices(AccommCode, NumRooms)
{
	iHotelPos += 1;

	var NewOverallCost = parseFloat(document.getElementById('MultiRoom_FlightPrice').value);
	var NewOverallWasCost = parseFloat(document.getElementById('MultiRoom_FlightPriceNett').value);

	for (z = 1; z <= NumRooms; z++)
	{
		NewOverallCost += parseFloat(checkRadioMultiRoom('sSelectedRoomType'+AccommCode+z, 'roomValue'))
		NewOverallWasCost += parseFloat(checkRadioMultiRoom('sSelectedRoomType'+AccommCode+z, 'roomWasValue'))
	}

	if (parseFloat(NewOverallWasCost) > parseFloat(NewOverallCost)){
		document.getElementById('NowDisplay').style.display = 'inline';
		document.getElementById('WasDisplay').style.display = 'inline';
		writeInDiv('&#163;' + NewOverallWasCost.toFixed(2), 'wasprice'+AccommCode);
	}else{
		document.getElementById('NowDisplay').style.display = 'none';
		document.getElementById('WasDisplay').style.display = 'none';
	}
	writeInDiv('&#163;' + NewOverallCost.toFixed(2), 'totalprice'+AccommCode);
}

function checkRadioMultiRoom(sFieldName, attributeName)
{
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type == "radio" && oFormElements.item(i).name == sFieldName)
		{
			if(oFormElements.item(i).checked)
			{ return oFormElements.item(i).getAttribute(attributeName);}
		}
	}
	return '';
}

function setSortHotelsNEW(type, page)
{
	document.frmResults.txtIsPostBack.value="true";
	if(type==1)
	{
		setSortHotels("translate(CSI_ARE/CHEAPEST_PRICE,',','')",'number','ascending','3');
	}
	if(type==2)
	{
		setSortHotels('AccommInfo/StarRating','number','descending','2');
	}
	if(type==3)
	{
		setSortHotels('AccommInfo/AccommName','text','ascending','1');
	}
	if(type==4)
	{
		setSortHotels('default','','','0');
	}
	if(type==5)
	{
		setSortHotels('AccommInfo/StarRating','number','ascending','5');
	}
	
	ChangePageHotels(page);
}


function checkAgeDOBMatch(NumChildren, NumAdults, DepDate, SearchType){
	var Str = document.getElementById('AgeCheckSearchType').value

	if (Str.indexOf("Hotel") >= 0 && document.getElementById('AgeCheckNoChilds').value != "0")
	{
		var i, today, d, by, bm, bd, bday, age, dif, DOB
		var ErrTxt = "Please ensure child ages and their date of births match! -\n\n"
			for (i = 1; i <= NumChildren; i++)
			{
				//get depdate in correct format
				d =DepDate.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				today = new Date(by,bm,bd) 
				
				//get childs DOB in correct format
				DOB = document.getElementById('dobd' + (i + Number(NumAdults))).value + "/" + document.getElementById('dobm' + (i + Number(NumAdults))).value + "/" + document.getElementById('doby' + (i + Number(NumAdults))).value
				d =DOB.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				bday = new Date(by,bm,bd) 
				age=0; dif=bday; 
				
				while(dif<today)
				{ 
					dif = new Date(by+age,bm,parseInt(bd)-1); 
					age++; 
				} 
				age +=-2 ; 
				if (document.getElementById('AgeCheck' + i).value != age)
				{
				ErrTxt = ErrTxt + "Child " + i + ": " + DOB + " makes the child " + age + ", child must be " + document.getElementById('AgeCheck' + i).value + " at time of departure.\n"
				//return false; break;
				}
			}
			if (ErrTxt == "Please ensure child ages and their date of births match! -\n\n")
				{return true;}
			else
				{alert(ErrTxt); return false;}
	}
} 

//END RESULTS.JS


//PROGRESS_BAR.JS
var cells = 10; var blocks = 3;
var colour = ''; var BGColour2 = '#165693'; var BGColour = '#FFFFFF';


var pos = 1 - blocks;
var i = 0, b = 0;
var iTimeout = 100;
function scrollBar()
{
	pos += 1;
	if (pos > cells) { pos = 1 - blocks; iTimeout = iTimeout - 1; }
	colour = BGColour;
	for (i=0;i<cells;i++) { document.getElementById('cell'+i).style['background'] = colour; }
	colour = BGColour2;
	for (b=0;b<blocks;b++)
	{ if ((pos + b > -1) && (pos + b < cells)) { document.getElementById('cell'+(pos+b)).style['background'] = colour; } }
	if (iTimeout == 0)
	{
		if(location.indexOf('/checkout') >= 0)
		{ self.location.href = 'confirmation.asp?paymentfailed=1'; }
		else
		{ self.location.href = 'default.asp?e=reservation_system_unavailable'; }
	}
}

//END PROGRESS_BAR.JS

//TOOLTIP.JS

//\/////
//\  overLIB 4.22 - You may not remove or change this notice.
//\  Copyright Erik Bosrup 1998-2004. All rights reserved.
//\
//\  Contributors are listed on the homepage.
//\  This file might be old, always check for the latest version at:
//\  http://www.bosrup.com/web/overlib/
//\
//\  Please read the license agreement (available through the link above)
//\  before using overLIB. Direct any licensing questions to erik@bosrup.com.
//\
//\  Do not sell this as your own work or remove this copyright notice. 
//\  For full details on copying or changing this script please read the
//\  license agreement at the link above. Please give credit on sites that
//\  use overLIB and submit changes of the script so other people can use
//\  them as well.
//   $Revision: 1.119 $                $Date: 2005/07/02 23:41:44 $
//\/////
//\mini

////////
// PRE-INIT
// Ignore these lines, configuration is below.
////////
var olLoaded = 0;var pmStart = 10000000; var pmUpper = 10001000; var pmCount = pmStart+1; var pmt=''; var pms = new Array(); var olInfo = new Info('4.22', 0);
var FREPLACE = 0; var FBEFORE = 1; var FAFTER = 2; var FALTERNATE = 3; var FCHAIN=4;
var olHideForm=0;  // parameter for hiding SELECT and ActiveX elements in IE5.5+ 
var olHautoFlag = 0;  // flags for over-riding VAUTO and HAUTO if corresponding
var olVautoFlag = 0;  // positioning commands are used on the command line
var hookPts = new Array(), postParse = new Array(), cmdLine = new Array(), runTime = new Array();
// for plugins
registerCommands('donothing,inarray,caparray,sticky,background,noclose,caption,left,right,center,offsetx,offsety,fgcolor,bgcolor,textcolor,capcolor,closecolor,width,border,cellpad,status,autostatus,autostatuscap,height,closetext,snapx,snapy,fixx,fixy,relx,rely,fgbackground,bgbackground,padx,pady,fullhtml,above,below,capicon,textfont,captionfont,closefont,textsize,captionsize,closesize,timeout,function,delay,hauto,vauto,closeclick,wrap,followmouse,mouseoff,closetitle,cssoff,compatmode,cssclass,fgclass,bgclass,textfontclass,captionfontclass,closefontclass');

////////
// DEFAULT CONFIGURATION
// Settings you want everywhere are set here. All of this can also be
// changed on your html page or through an overLIB call.
////////



if (typeof ol_fgcolor=='undefined') var ol_fgcolor="#ffffff";
if (typeof ol_bgcolor=='undefined') var ol_bgcolor="#63ABFF";
if (typeof ol_textcolor=='undefined') var ol_textcolor="#000000";
if (typeof ol_capcolor=='undefined') var ol_capcolor="#FFFFFF";
if (typeof ol_closecolor=='undefined') var ol_closecolor="#9999FF";
if (typeof ol_textfont=='undefined') var ol_textfont="Verdana,Arial,Helvetica";
if (typeof ol_captionfont=='undefined') var ol_captionfont="Verdana,Arial,Helvetica";
if (typeof ol_closefont=='undefined') var ol_closefont="Verdana,Arial,Helvetica";
if (typeof ol_textsize=='undefined') var ol_textsize="1";
if (typeof ol_captionsize=='undefined') var ol_captionsize="1";
if (typeof ol_closesize=='undefined') var ol_closesize="1";
if (typeof ol_width=='undefined') var ol_width="300";
if (typeof ol_border=='undefined') var ol_border="1";
if (typeof ol_cellpad=='undefined') var ol_cellpad=10;
if (typeof ol_offsetx=='undefined') var ol_offsetx=10;
if (typeof ol_offsety=='undefined') var ol_offsety=10;
if (typeof ol_text=='undefined') var ol_text="Default Text";
if (typeof ol_cap=='undefined') var ol_cap="";
if (typeof ol_sticky=='undefined') var ol_sticky=0;
if (typeof ol_background=='undefined') var ol_background="";
if (typeof ol_close=='undefined') var ol_close="Close";
if (typeof ol_hpos=='undefined') var ol_hpos=RIGHT;
if (typeof ol_status=='undefined') var ol_status="";
if (typeof ol_autostatus=='undefined') var ol_autostatus=0;
if (typeof ol_height=='undefined') var ol_height=-1;
if (typeof ol_snapx=='undefined') var ol_snapx=0;
if (typeof ol_snapy=='undefined') var ol_snapy=0;
if (typeof ol_fixx=='undefined') var ol_fixx=-1;
if (typeof ol_fixy=='undefined') var ol_fixy=-1;
if (typeof ol_relx=='undefined') var ol_relx=null;
if (typeof ol_rely=='undefined') var ol_rely=null;
if (typeof ol_fgbackground=='undefined') var ol_fgbackground="";
if (typeof ol_bgbackground=='undefined') var ol_bgbackground="";
if (typeof ol_padxl=='undefined') var ol_padxl=1;
if (typeof ol_padxr=='undefined') var ol_padxr=1;
if (typeof ol_padyt=='undefined') var ol_padyt=1;
if (typeof ol_padyb=='undefined') var ol_padyb=1;
if (typeof ol_fullhtml=='undefined') var ol_fullhtml=0;
if (typeof ol_vpos=='undefined') var ol_vpos=BELOW;
if (typeof ol_aboveheight=='undefined') var ol_aboveheight=0;
if (typeof ol_capicon=='undefined') var ol_capicon="";
if (typeof ol_frame=='undefined') var ol_frame=self;
if (typeof ol_timeout=='undefined') var ol_timeout=0;
if (typeof ol_function=='undefined') var ol_function=null;
if (typeof ol_delay=='undefined') var ol_delay=0;
if (typeof ol_hauto=='undefined') var ol_hauto=0;
if (typeof ol_vauto=='undefined') var ol_vauto=0;
if (typeof ol_closeclick=='undefined') var ol_closeclick=0;
if (typeof ol_wrap=='undefined') var ol_wrap=0;
if (typeof ol_followmouse=='undefined') var ol_followmouse=1;
if (typeof ol_mouseoff=='undefined') var ol_mouseoff=0;
if (typeof ol_closetitle=='undefined') var ol_closetitle='Close';
if (typeof ol_compatmode=='undefined') var ol_compatmode=0;
if (typeof ol_css=='undefined') var ol_css=CSSOFF;
if (typeof ol_fgclass=='undefined') var ol_fgclass="";
if (typeof ol_bgclass=='undefined') var ol_bgclass="";
if (typeof ol_textfontclass=='undefined') var ol_textfontclass="";
if (typeof ol_captionfontclass=='undefined') var ol_captionfontclass="";
if (typeof ol_closefontclass=='undefined') var ol_closefontclass="";

////////
// ARRAY CONFIGURATION
////////

// You can use these arrays to store popup text here instead of in the html.
if (typeof ol_texts=='undefined') var ol_texts = new Array("Text 0", "Text 1");
if (typeof ol_caps=='undefined') var ol_caps = new Array("Caption 0", "Caption 1");

////////
// END OF CONFIGURATION
// Don't change anything below this line, all configuration is above.
////////





////////
// INIT
////////
// Runtime variables init. Don't change for config!
var o3_text="";
var o3_cap="";
var o3_sticky=0;
var o3_background="";
var o3_close="Close";
var o3_hpos=RIGHT;
var o3_offsetx=2;
var o3_offsety=2;
var o3_fgcolor="";
var o3_bgcolor="";
var o3_textcolor="";
var o3_capcolor="";
var o3_closecolor="";
var o3_width=100;
var o3_border=1;
var o3_cellpad=5;
var o3_status="";
var o3_autostatus=0;
var o3_height=-1;
var o3_snapx=0;
var o3_snapy=0;
var o3_fixx=-1;
var o3_fixy=-1;
var o3_relx=null;
var o3_rely=null;
var o3_fgbackground="";
var o3_bgbackground="";
var o3_padxl=5;
var o3_padxr=5;
var o3_padyt=5;
var o3_padyb=5;
var o3_fullhtml=0;
var o3_vpos=BELOW;
var o3_aboveheight=0;
var o3_capicon="";
var o3_textfont="Verdana,Arial,Helvetica";
var o3_captionfont="Verdana,Arial,Helvetica";
var o3_closefont="Verdana,Arial,Helvetica";
var o3_textsize="1";
var o3_captionsize="1";
var o3_closesize="1";
var o3_frame=self;
var o3_timeout=0;
var o3_timerid=0;
var o3_allowmove=0;
var o3_function=null; 
var o3_delay=0;
var o3_delayid=0;
var o3_hauto=0;
var o3_vauto=0;
var o3_closeclick=0;
var o3_wrap=0;
var o3_followmouse=1;
var o3_mouseoff=0;
var o3_closetitle='';
var o3_compatmode=0;
var o3_css=CSSOFF;
var o3_fgclass="";
var o3_bgclass="";
var o3_textfontclass="";
var o3_captionfontclass="";
var o3_closefontclass="";

// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_showingsticky = 0;
var o3_removecounter = 0;

// Our layer
var over = null;
var fnRef, hoveringSwitch = false;
var olHideDelay;

// Decide browser version
var isMac = (navigator.userAgent.indexOf("Mac") != -1);
var olOp = (navigator.userAgent.toLowerCase().indexOf('opera') > -1 && document.createTextNode);  // Opera 7
var olNs4 = (navigator.appName=='Netscape' && parseInt(navigator.appVersion) == 4);
var olNs6 = (document.getElementById) ? true : false;
var olKq = (olNs6 && /konqueror/i.test(navigator.userAgent));
var olIe4 = (document.all) ? true : false;
var olIe5 = false; 
var olIe55 = false; // Added additional variable to identify IE5.5+
var docRoot = 'document.body';

// Resize fix for NS4.x to keep track of layer
if (olNs4) {
	var oW = window.innerWidth;
	var oH = window.innerHeight;
	window.onresize = function() { if (oW != window.innerWidth || oH != window.innerHeight) location.reload(); }
}

// Microsoft Stupidity Check(tm).
if (olIe4) {
	var agent = navigator.userAgent;
	if (/MSIE/.test(agent)) {
		var versNum = parseFloat(agent.match(/MSIE[ ](\d\.\d+)\.*/i)[1]);
		if (versNum >= 5){
			olIe5=true;
			olIe55=(versNum>=5.5&&!olOp) ? true : false;
			if (olNs6) olNs6=false;
		}
	}
	if (olNs6) olIe4 = false;
}

// Check for compatability mode.
if (document.compatMode && document.compatMode == 'CSS1Compat') {
	docRoot= ((olIe4 && !olOp) ? 'document.documentElement' : docRoot);
}

// Add window onload handlers to indicate when all modules have been loaded
// For Netscape 6+ and Mozilla, uses addEventListener method on the window object
// For IE it uses the attachEvent method of the window object and for Netscape 4.x
// it sets the window.onload handler to the OLonload_handler function for Bubbling
if(window.addEventListener) window.addEventListener("load",OLonLoad_handler,false);
else if (window.attachEvent) window.attachEvent("onload",OLonLoad_handler);

var capExtent;

////////
// PUBLIC FUNCTIONS
////////

// overlib(arg0,...,argN)
// Loads parameters into global runtime variables.
function overlib() {
	if (!olLoaded || isExclusive(overlib.arguments)) return true;
	if (olCheckMouseCapture) olMouseCapture();
	if (over) {
		over = (typeof over.id != 'string') ? o3_frame.document.all['overDiv'] : over;
		cClick();
	}

	// Load defaults to runtime.
	olHideDelay=0;
	o3_text=ol_text;
	o3_cap=ol_cap;
	o3_sticky=ol_sticky;
	o3_background=ol_background;
	o3_close=ol_close;
	o3_hpos=ol_hpos;
	o3_offsetx=ol_offsetx;
	o3_offsety=ol_offsety;
	o3_fgcolor=ol_fgcolor;
	o3_bgcolor=ol_bgcolor;
	o3_textcolor=ol_textcolor;
	o3_capcolor=ol_capcolor;
	o3_closecolor=ol_closecolor;
	o3_width=ol_width;
	o3_border=ol_border;
	o3_cellpad=ol_cellpad;
	o3_status=ol_status;
	o3_autostatus=ol_autostatus;
	o3_height=ol_height;
	o3_snapx=ol_snapx;
	o3_snapy=ol_snapy;
	o3_fixx=ol_fixx;
	o3_fixy=ol_fixy;
	o3_relx=ol_relx;
	o3_rely=ol_rely;
	o3_fgbackground=ol_fgbackground;
	o3_bgbackground=ol_bgbackground;
	o3_padxl=ol_padxl;
	o3_padxr=ol_padxr;
	o3_padyt=ol_padyt;
	o3_padyb=ol_padyb;
	o3_fullhtml=ol_fullhtml;
	o3_vpos=ol_vpos;
	o3_aboveheight=ol_aboveheight;
	o3_capicon=ol_capicon;
	o3_textfont=ol_textfont;
	o3_captionfont=ol_captionfont;
	o3_closefont=ol_closefont;
	o3_textsize=ol_textsize;
	o3_captionsize=ol_captionsize;
	o3_closesize=ol_closesize;
	o3_timeout=ol_timeout;
	o3_function=ol_function;
	o3_delay=ol_delay;
	o3_hauto=ol_hauto;
	o3_vauto=ol_vauto;
	o3_closeclick=ol_closeclick;
	o3_wrap=ol_wrap;	
	o3_followmouse=ol_followmouse;
	o3_mouseoff=ol_mouseoff;
	o3_closetitle=ol_closetitle;
	o3_css=ol_css;
	o3_compatmode=ol_compatmode;
	o3_fgclass=ol_fgclass;
	o3_bgclass=ol_bgclass;
	o3_textfontclass=ol_textfontclass;
	o3_captionfontclass=ol_captionfontclass;
	o3_closefontclass=ol_closefontclass;
	
	setRunTimeVariables();
	
	fnRef = '';
	
	// Special for frame support, over must be reset...
	o3_frame = ol_frame;
	
	if(!(over=createDivContainer())) return false;

	parseTokens('o3_', overlib.arguments);
	if (!postParseChecks('o3_',overlib.arguments)) return false;

	if (o3_delay == 0) {
		return runHook("olMain", FREPLACE);
 	} else {
		o3_delayid = setTimeout("runHook('olMain', FREPLACE)", o3_delay);
		return false;
	}
}

// Clears popups if appropriate
function nd(time) {
	if (olLoaded && !isExclusive()) {
		hideDelay(time);  // delay popup close if time specified

		if (o3_removecounter >= 1) { o3_showingsticky = 0 };
		
		if (o3_showingsticky == 0) {
			o3_allowmove = 0;
			if (over != null && (o3_compatmode ? 1 : o3_timerid == 0)) runHook("hideObject", FREPLACE, over);
		} else {
			o3_removecounter++;
		}
	}
	
	return true;
}

// The Close onMouseOver function for stickies
function cClick() {
	if (olLoaded) {
		runHook("hideObject", FREPLACE, over);
		o3_showingsticky = 0;	
	}	
	return false;
}

// Method for setting page specific defaults.
function overlib_pagedefaults() {
	parseTokens('ol_', overlib_pagedefaults.arguments);
}


////////
// OVERLIB MAIN FUNCTION
////////

// This function decides what it is we want to display and how we want it done.
function olMain() {
	var layerhtml, styleType;
 	runHook("olMain", FBEFORE);
 	
	if (o3_background!="" || o3_fullhtml) {
		// Use background instead of box.
		layerhtml = runHook('ol_content_background', FALTERNATE, o3_css, o3_text, o3_background, o3_fullhtml);
	} else {
		// They want a popup box.
		styleType = (pms[o3_css-1-pmStart] == "cssoff" || pms[o3_css-1-pmStart] == "cssclass");

		// Prepare popup background
		if (o3_fgbackground != "") o3_fgbackground = "background=\""+o3_fgbackground+"\"";
		if (o3_bgbackground != "") o3_bgbackground = (styleType ? "background=\""+o3_bgbackground+"\"" : o3_bgbackground);

		// Prepare popup colors
		if (o3_fgcolor != "") o3_fgcolor = (styleType ? "bgcolor=\""+o3_fgcolor+"\"" : o3_fgcolor);
		if (o3_bgcolor != "") o3_bgcolor = (styleType ? "bgcolor=\""+o3_bgcolor+"\"" : o3_bgcolor);

		// Prepare popup height
		if (o3_height > 0) o3_height = (styleType ? "height=\""+o3_height+"\"" : o3_height);
		else o3_height = "";

		// Decide which kinda box.
		if (o3_cap=="") {
			// Plain
			layerhtml = runHook('ol_content_simple', FALTERNATE, o3_css, o3_text);
		} else {
			// With caption
			if (o3_sticky) {
				// Show close text
				layerhtml = runHook('ol_content_caption', FALTERNATE, o3_css, o3_text, o3_cap, o3_close);
			} else {
				// No close text
				layerhtml = runHook('ol_content_caption', FALTERNATE, o3_css, o3_text, o3_cap, "");
			}
		}
	}	

	// We want it to stick!
	if (o3_sticky) {
		if (o3_timerid > 0) {
			clearTimeout(o3_timerid);
			o3_timerid = 0;
		}
		o3_showingsticky = 1;
		o3_removecounter = 0;
	}

	// Created a separate routine to generate the popup to make it easier
	// to implement a plugin capability
	if (!runHook("olCreatePopup", FREPLACE, layerhtml)) return false;

	// Prepare status bar
	if (o3_autostatus > 0) {
		o3_status = o3_text;
		if (o3_autostatus > 1) o3_status = o3_cap;
		if (o3_wrap) o3_status = o3_status.replace(/&nbsp;/g,' ');
	}

	// When placing the layer the first time, even stickies may be moved.
	o3_allowmove = 0;

	// Initiate a timer for timeout
	if (o3_timeout > 0) {          
		if (o3_timerid > 0) clearTimeout(o3_timerid);
		o3_timerid = setTimeout("cClick()", o3_timeout);
	}

	// Show layer
	runHook("disp", FREPLACE, o3_status);
	runHook("olMain", FAFTER);

	return (olOp && event && event.type == 'mouseover' && !o3_status) ? '' : (o3_status != '');
}

////////
// LAYER GENERATION FUNCTIONS
////////
// These functions just handle popup content with tags that should adhere to the W3C standards specification.

// Makes simple table without caption
function ol_content_simple(text) {
	var cpIsMultiple = /,/.test(o3_cellpad);
	var txt = '<table width="'+o3_width+ '" border="0" cellpadding="'+o3_border+'" cellspacing="0" '+(o3_bgclass ? 'class="'+o3_bgclass+'"' : o3_bgcolor+' '+o3_height)+'><tr><td><table width="100%" border="0" '+((olNs4||!cpIsMultiple) ? 'cellpadding="'+o3_cellpad+'" ' : '')+'cellspacing="0" '+(o3_fgclass ? 'class="'+o3_fgclass+'"' : o3_fgcolor+' '+o3_fgbackground+' '+o3_height)+'><tr><td valign="TOP"'+(o3_textfontclass ? ' class="'+o3_textfontclass+'">' : ((!olNs4&&cpIsMultiple) ? ' style="'+setCellPadStr(o3_cellpad)+'">' : '>'))+(o3_textfontclass ? '' : wrapStr(0,o3_textsize,'text'))+text+(o3_textfontclass ? '' : wrapStr(1,o3_textsize))+'</td></tr></table></td></tr></table>';

	set_background("");
	return txt;
}

// Makes table with caption and optional close link
function ol_content_caption(text,title,close) {
	var nameId, txt, cpIsMultiple = /,/.test(o3_cellpad);
	var closing, closeevent;

	closing = "";
	closeevent = "onmouseover";
	if (o3_closeclick == 1) closeevent = (o3_closetitle ? "title='" + o3_closetitle +"'" : "") + " onclick";
	if (o3_capicon != "") {
	  nameId = ' hspace = \"5\"'+' align = \"middle\" alt = \"\"';
	  if (typeof o3_dragimg != 'undefined' && o3_dragimg) nameId =' hspace=\"5\"'+' name=\"'+o3_dragimg+'\" id=\"'+o3_dragimg+'\" align=\"middle\" alt=\"Drag Enabled\" title=\"Drag Enabled\"';
	  o3_capicon = '<img src=\"'+o3_capicon+'\"'+nameId+' />';
	}

	if (close != "")
		closing = '<td '+(!o3_compatmode && o3_closefontclass ? 'class="'+o3_closefontclass : 'align="RIGHT')+'"><a href="javascript:return '+fnRef+'cClick();"'+((o3_compatmode && o3_closefontclass) ? ' class="' + o3_closefontclass + '" ' : ' ')+closeevent+'="return '+fnRef+'cClick();">'+(o3_closefontclass ? '' : wrapStr(0,o3_closesize,'close'))+close+(o3_closefontclass ? '' : wrapStr(1,o3_closesize,'close'))+'</a></td>';
	txt = '<table width="'+o3_width+ '" border="0" cellpadding="'+o3_border+'" cellspacing="0" '+(o3_bgclass ? 'class="'+o3_bgclass+'"' : o3_bgcolor+' '+o3_bgbackground+' '+o3_height)+'><tr><td><table width="100%" border="0" cellpadding="2" cellspacing="0"><tr><td'+(o3_captionfontclass ? ' class="'+o3_captionfontclass+'">' : '>')+(o3_captionfontclass ? '' : '<b>'+wrapStr(0,o3_captionsize,'caption'))+o3_capicon+title+(o3_captionfontclass ? '' : wrapStr(1,o3_captionsize)+'</b>')+'</td>'+closing+'</tr></table><table width="100%" border="0" '+((olNs4||!cpIsMultiple) ? 'cellpadding="'+o3_cellpad+'" ' : '')+'cellspacing="0" '+(o3_fgclass ? 'class="'+o3_fgclass+'"' : o3_fgcolor+' '+o3_fgbackground+' '+o3_height)+'><tr><td valign="TOP"'+(o3_textfontclass ? ' class="'+o3_textfontclass+'">' :((!olNs4&&cpIsMultiple) ? ' style="'+setCellPadStr(o3_cellpad)+'">' : '>'))+(o3_textfontclass ? '' : wrapStr(0,o3_textsize,'text'))+text+(o3_textfontclass ? '' : wrapStr(1,o3_textsize)) + '</td></tr></table></td></tr></table>';

	set_background("");
	return txt;
}

// Sets the background picture,padding and lots more. :)
function ol_content_background(text,picture,hasfullhtml) {
	var txt;
	if (hasfullhtml) {
		txt=text;
	} else {
		txt='<table width="'+o3_width+'" border="0" cellpadding="0" cellspacing="0" height="'+o3_height+'"><tr><td colspan="3" height="'+o3_padyt+'"></td></tr><tr><td width="'+o3_padxl+'"></td><td valign="TOP" width="'+(o3_width-o3_padxl-o3_padxr)+(o3_textfontclass ? '" class="'+o3_textfontclass : '')+'">'+(o3_textfontclass ? '' : wrapStr(0,o3_textsize,'text'))+text+(o3_textfontclass ? '' : wrapStr(1,o3_textsize))+'</td><td width="'+o3_padxr+'"></td></tr><tr><td colspan="3" height="'+o3_padyb+'"></td></tr></table>';
	}

	set_background(picture);
	return txt;
}

// Loads a picture into the div.
function set_background(pic) {
	if (pic == "") {
		if (olNs4) {
			over.background.src = null; 
		} else if (over.style) {
			over.style.backgroundImage = "none";
		}
	} else {
		if (olNs4) {
			over.background.src = pic;
		} else if (over.style) {
			over.style.width=o3_width + 'px';
			over.style.backgroundImage = "url("+pic+")";
		}
	}
}

////////
// HANDLING FUNCTIONS
////////
var olShowId=-1;

// Displays the popup
function disp(statustext) {
	runHook("disp", FBEFORE, statustext);
	
	if (o3_allowmove == 0) {
		runHook("placeLayer", FREPLACE);
		(olNs6&&olShowId<0) ? olShowId=setTimeout("runHook('showObject', FREPLACE, over)", 1) : runHook("showObject", FREPLACE, over);
		o3_allowmove = (o3_sticky || o3_followmouse==0) ? 0 : 1;
	}
	
	runHook("disp", FAFTER, statustext);

	if (statustext != "") self.status = statustext;
}

// Creates the actual popup structure
function olCreatePopup(lyrContent){
	runHook("olCreatePopup", FBEFORE, lyrContent);
	
	if (o3_wrap) {
		var wd,ww,theObj = (olNs4 ? over : over.style);
		theObj.top = theObj.left = ((olIe4&&!olOp) ? 0 : -10000) + (!olNs4 ? 'px' : 0);
		layerWrite(lyrContent);
		wd = (olNs4 ? over.clip.width : over.offsetWidth);
		if (wd > (ww=windowWidth())) {
			lyrContent=lyrContent.replace(/\&nbsp;/g, ' ');
			o3_width=ww;
			o3_wrap=0;
		} 
	}

	layerWrite(lyrContent);
	
	// Have to set o3_width for placeLayer() routine if o3_wrap is turned on
	if (o3_wrap) o3_width=(olNs4 ? over.clip.width : over.offsetWidth);
	
	runHook("olCreatePopup", FAFTER, lyrContent);

	return true;
}

// Decides where we want the popup.
function placeLayer() {
	var placeX, placeY, widthFix = 0;
	
	// HORIZONTAL PLACEMENT, re-arranged to work in Safari
	if (o3_frame.innerWidth) widthFix=18; 
	iwidth = windowWidth();

	// Horizontal scroll offset
	winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;

	placeX = runHook('horizontalPlacement',FCHAIN,iwidth,winoffset,widthFix);

	// VERTICAL PLACEMENT, re-arranged to work in Safari
	if (o3_frame.innerHeight) {
		iheight=o3_frame.innerHeight;
	} else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientHeight=='number'")&&eval('o3_frame.'+docRoot+'.clientHeight')) { 
		iheight=eval('o3_frame.'+docRoot+'.clientHeight');
	}			

	// Vertical scroll offset
	scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
	placeY = runHook('verticalPlacement',FCHAIN,iheight,scrolloffset);

	// Actually move the object.
	repositionTo(over, placeX, placeY);
}

// Moves the layer
function olMouseMove(e) {
	var e = (e) ? e : event;

	if (e.pageX) {
		o3_x = e.pageX;
		o3_y = e.pageY;
	} else if (e.clientX) {
		o3_x = eval('e.clientX+o3_frame.'+docRoot+'.scrollLeft');
		o3_y = eval('e.clientY+o3_frame.'+docRoot+'.scrollTop');
	}
	
	if (o3_allowmove == 1) runHook("placeLayer", FREPLACE);

	// MouseOut handler
	if (hoveringSwitch && !olNs4 && runHook("cursorOff", FREPLACE)) {
		(olHideDelay ? hideDelay(olHideDelay) : cClick());
		hoveringSwitch = !hoveringSwitch;
	}
}

// Fake function for 3.0 users.
function no_overlib() { return ver3fix; }

// Capture the mouse and chain other scripts.
function olMouseCapture() {
	capExtent = document;
	var fN, str = '', l, k, f, wMv, sS, mseHandler = olMouseMove;
	var re = /function[ ]*(\w*)\(/;
	
	wMv = (!olIe4 && window.onmousemove);
	if (document.onmousemove || wMv) {
		if (wMv) capExtent = window;
		f = capExtent.onmousemove.toString();
		fN = f.match(re);
		if (fN == null) {
			str = f+'(e); ';
		} else if (fN[1] == 'anonymous' || fN[1] == 'olMouseMove' || (wMv && fN[1] == 'onmousemove')) {
			if (!olOp && wMv) {
				l = f.indexOf('{')+1;
				k = f.lastIndexOf('}');
				sS = f.substring(l,k);
				if ((l = sS.indexOf('(')) != -1) {
					sS = sS.substring(0,l).replace(/^\s+/,'').replace(/\s+$/,'');
					if (eval("typeof " + sS + " == 'undefined'")) window.onmousemove = null;
					else str = sS + '(e);';
				}
			}
			if (!str) {
				olCheckMouseCapture = false;
				return;
			}
		} else {
			if (fN[1]) str = fN[1]+'(e); ';
			else {
				l = f.indexOf('{')+1;
				k = f.lastIndexOf('}');
				str = f.substring(l,k) + '\n';
			}
		}
		str += 'olMouseMove(e); ';
		mseHandler = new Function('e', str);
	}

	capExtent.onmousemove = mseHandler;
	if (olNs4) capExtent.captureEvents(Event.MOUSEMOVE);
}

////////
// PARSING FUNCTIONS
////////

// Does the actual command parsing.
function parseTokens(pf, ar) {
	// What the next argument is expected to be.
	var v, i, mode=-1, par = (pf != 'ol_');	
	var fnMark = (par && !ar.length ? 1 : 0);

	for (i = 0; i < ar.length; i++) {
		if (mode < 0) {
			// Arg is maintext,unless its a number between pmStart and pmUpper
			// then its a command.
			if (typeof ar[i] == 'number' && ar[i] > pmStart && ar[i] < pmUpper) {
				fnMark = (par ? 1 : 0);
				i--;   // backup one so that the next block can parse it
			} else {
				switch(pf) {
					case 'ol_':
						ol_text = ar[i].toString();
						break;
					default:
						o3_text=ar[i].toString();  
				}
			}
			mode = 0;
		} else {
			// Note: NS4 doesn't like switch cases with vars.
			if (ar[i] >= pmCount || ar[i]==DONOTHING) { continue; }
			if (ar[i]==INARRAY) { fnMark = 0; eval(pf+'text=ol_texts['+ar[++i]+'].toString()'); continue; }
			if (ar[i]==CAPARRAY) { eval(pf+'cap=ol_caps['+ar[++i]+'].toString()'); continue; }
			if (ar[i]==STICKY) { if (pf!='ol_') eval(pf+'sticky=1'); continue; }
			if (ar[i]==BACKGROUND) { eval(pf+'background="'+ar[++i]+'"'); continue; }
			if (ar[i]==NOCLOSE) { if (pf!='ol_') opt_NOCLOSE(); continue; }
			if (ar[i]==CAPTION) { eval(pf+"cap='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==CENTER || ar[i]==LEFT || ar[i]==RIGHT) { eval(pf+'hpos='+ar[i]); if(pf!='ol_') olHautoFlag=1; continue; }
			if (ar[i]==OFFSETX) { eval(pf+'offsetx='+ar[++i]); continue; }
			if (ar[i]==OFFSETY) { eval(pf+'offsety='+ar[++i]); continue; }
			if (ar[i]==FGCOLOR) { eval(pf+'fgcolor="'+ar[++i]+'"'); continue; }
			if (ar[i]==BGCOLOR) { eval(pf+'bgcolor="'+ar[++i]+'"'); continue; }
			if (ar[i]==TEXTCOLOR) { eval(pf+'textcolor="'+ar[++i]+'"'); continue; }
			if (ar[i]==CAPCOLOR) { eval(pf+'capcolor="'+ar[++i]+'"'); continue; }
			if (ar[i]==CLOSECOLOR) { eval(pf+'closecolor="'+ar[++i]+'"'); continue; }
			if (ar[i]==WIDTH) { eval(pf+'width='+ar[++i]); continue; }
			if (ar[i]==BORDER) { eval(pf+'border='+ar[++i]); continue; }
			if (ar[i]==CELLPAD) { i=opt_MULTIPLEARGS(++i,ar,(pf+'cellpad')); continue; }
			if (ar[i]==STATUS) { eval(pf+"status='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==AUTOSTATUS) { eval(pf +'autostatus=('+pf+'autostatus == 1) ? 0 : 1'); continue; }
			if (ar[i]==AUTOSTATUSCAP) { eval(pf +'autostatus=('+pf+'autostatus == 2) ? 0 : 2'); continue; }
			if (ar[i]==HEIGHT) { eval(pf+'height='+pf+'aboveheight='+ar[++i]); continue; } // Same param again.
			if (ar[i]==CLOSETEXT) { eval(pf+"close='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==SNAPX) { eval(pf+'snapx='+ar[++i]); continue; }
			if (ar[i]==SNAPY) { eval(pf+'snapy='+ar[++i]); continue; }
			if (ar[i]==FIXX) { eval(pf+'fixx='+ar[++i]); continue; }
			if (ar[i]==FIXY) { eval(pf+'fixy='+ar[++i]); continue; }
			if (ar[i]==RELX) { eval(pf+'relx='+ar[++i]); continue; }
			if (ar[i]==RELY) { eval(pf+'rely='+ar[++i]); continue; }
			if (ar[i]==FGBACKGROUND) { eval(pf+'fgbackground="'+ar[++i]+'"'); continue; }
			if (ar[i]==BGBACKGROUND) { eval(pf+'bgbackground="'+ar[++i]+'"'); continue; }
			if (ar[i]==PADX) { eval(pf+'padxl='+ar[++i]); eval(pf+'padxr='+ar[++i]); continue; }
			if (ar[i]==PADY) { eval(pf+'padyt='+ar[++i]); eval(pf+'padyb='+ar[++i]); continue; }
			if (ar[i]==FULLHTML) { if (pf!='ol_') eval(pf+'fullhtml=1'); continue; }
			if (ar[i]==BELOW || ar[i]==ABOVE) { eval(pf+'vpos='+ar[i]); if (pf!='ol_') olVautoFlag=1; continue; }
			if (ar[i]==CAPICON) { eval(pf+'capicon="'+ar[++i]+'"'); continue; }
			if (ar[i]==TEXTFONT) { eval(pf+"textfont='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==CAPTIONFONT) { eval(pf+"captionfont='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==CLOSEFONT) { eval(pf+"closefont='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==TEXTSIZE) { eval(pf+'textsize="'+ar[++i]+'"'); continue; }
			if (ar[i]==CAPTIONSIZE) { eval(pf+'captionsize="'+ar[++i]+'"'); continue; }
			if (ar[i]==CLOSESIZE) { eval(pf+'closesize="'+ar[++i]+'"'); continue; }
			if (ar[i]==TIMEOUT) { eval(pf+'timeout='+ar[++i]); continue; }
			if (ar[i]==FUNCTION) { if (pf=='ol_') { if (typeof ar[i+1]!='number') { v=ar[++i]; ol_function=(typeof v=='function' ? v : null); }} else {fnMark = 0; v = null; if (typeof ar[i+1]!='number') v = ar[++i];  opt_FUNCTION(v); } continue; }
			if (ar[i]==DELAY) { eval(pf+'delay='+ar[++i]); continue; }
			if (ar[i]==HAUTO) { eval(pf+'hauto=('+pf+'hauto == 0) ? 1 : 0'); continue; }
			if (ar[i]==VAUTO) { eval(pf+'vauto=('+pf+'vauto == 0) ? 1 : 0'); continue; }
			if (ar[i]==CLOSECLICK) { eval(pf +'closeclick=('+pf+'closeclick == 0) ? 1 : 0'); continue; }
			if (ar[i]==WRAP) { eval(pf +'wrap=('+pf+'wrap == 0) ? 1 : 0'); continue; }
			if (ar[i]==FOLLOWMOUSE) { eval(pf +'followmouse=('+pf+'followmouse == 1) ? 0 : 1'); continue; }
			if (ar[i]==MOUSEOFF) { eval(pf +'mouseoff=('+pf+'mouseoff==0) ? 1 : 0'); v=ar[i+1]; if (pf != 'ol_' && eval(pf+'mouseoff') && typeof v == 'number' && (v < pmStart || v > pmUpper)) olHideDelay=ar[++i]; continue; }
			if (ar[i]==CLOSETITLE) { eval(pf+"closetitle='"+escSglQuote(ar[++i])+"'"); continue; }
			if (ar[i]==CSSOFF||ar[i]==CSSCLASS) { eval(pf+'css='+ar[i]); continue; }
			if (ar[i]==COMPATMODE) { eval(pf+'compatmode=('+pf+'compatmode==0) ? 1 : 0'); continue; }
			if (ar[i]==FGCLASS) { eval(pf+'fgclass="'+ar[++i]+'"'); continue; }
			if (ar[i]==BGCLASS) { eval(pf+'bgclass="'+ar[++i]+'"'); continue; }
			if (ar[i]==TEXTFONTCLASS) { eval(pf+'textfontclass="'+ar[++i]+'"'); continue; }
			if (ar[i]==CAPTIONFONTCLASS) { eval(pf+'captionfontclass="'+ar[++i]+'"'); continue; }
			if (ar[i]==CLOSEFONTCLASS) { eval(pf+'closefontclass="'+ar[++i]+'"'); continue; }
			i = parseCmdLine(pf, i, ar);
		}
	}

	if (fnMark && o3_function) o3_text = o3_function();
	
	if ((pf == 'o3_') && o3_wrap) {
		o3_width = 0;
		
		var tReg=/<.*\n*>/ig;
		if (!tReg.test(o3_text)) o3_text = o3_text.replace(/[ ]+/g, '&nbsp;');
		if (!tReg.test(o3_cap))o3_cap = o3_cap.replace(/[ ]+/g, '&nbsp;');
	}
	if ((pf == 'o3_') && o3_sticky) {
		if (!o3_close && (o3_frame != ol_frame)) o3_close = ol_close;
		if (o3_mouseoff && (o3_frame == ol_frame)) opt_NOCLOSE(' ');
	}
}


////////
// LAYER FUNCTIONS
////////

// Writes to a layer
function layerWrite(txt) {
	txt += "\n";
	if (olNs4) {
		var lyr = o3_frame.document.layers['overDiv'].document
		lyr.write(txt)
		lyr.close()
	} else if (typeof over.innerHTML != 'undefined') {
		if (olIe5 && isMac) over.innerHTML = '';
		over.innerHTML = txt;
	} else {
		range = o3_frame.document.createRange();
		range.setStartAfter(over);
		domfrag = range.createContextualFragment(txt);
		
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		
		over.appendChild(domfrag);
	}
}

// Make an object visible
function showObject(obj) {
	runHook("showObject", FBEFORE, obj);

	var theObj=(olNs4 ? obj : obj.style);
	theObj.visibility = 'visible';

	runHook("showObject", FAFTER, obj);
}

// Hides an object
function hideObject(obj) {
	runHook("hideObject", FBEFORE, obj);

	var theObj=(olNs4 ? obj : obj.style);
	if (olNs6 && olShowId>0) { clearTimeout(olShowId); olShowId=0; }
	theObj.visibility = 'hidden';
	theObj.top = theObj.left = ((olIe4&&!olOp) ? 0 : -10000) + (!olNs4 ? 'px' : 0);

	if (o3_timerid > 0) clearTimeout(o3_timerid);
	if (o3_delayid > 0) clearTimeout(o3_delayid);

	o3_timerid = 0;
	o3_delayid = 0;
	self.status = "";

	if (obj.onmouseout||obj.onmouseover) {
		if (olNs4) obj.releaseEvents(Event.MOUSEOUT || Event.MOUSEOVER);
		obj.onmouseout = obj.onmouseover = null;
	}

	runHook("hideObject", FAFTER, obj);
}

// Move a layer
function repositionTo(obj, xL, yL) {
	var theObj=(olNs4 ? obj : obj.style);
	theObj.left = xL + (!olNs4 ? 'px' : 0);
	theObj.top = yL + (!olNs4 ? 'px' : 0);
}

// Check position of cursor relative to overDiv DIVision; mouseOut function
function cursorOff() {
	var left = parseInt(over.style.left);
	var top = parseInt(over.style.top);
	var right = left + (over.offsetWidth >= parseInt(o3_width) ? over.offsetWidth : parseInt(o3_width));
	var bottom = top + (over.offsetHeight >= o3_aboveheight ? over.offsetHeight : o3_aboveheight);

	if (o3_x < left || o3_x > right || o3_y < top || o3_y > bottom) return true;

	return false;
}


////////
// COMMAND FUNCTIONS
////////

// Calls callme or the default function.
function opt_FUNCTION(callme) {
	o3_text = (callme ? (typeof callme=='string' ? (/.+\(.*\)/.test(callme) ? eval(callme) : callme) : callme()) : (o3_function ? o3_function() : 'No Function'));

	return 0;
}

// Handle hovering
function opt_NOCLOSE(unused) {
	if (!unused) o3_close = "";

	if (olNs4) {
		over.captureEvents(Event.MOUSEOUT || Event.MOUSEOVER);
		over.onmouseover = function () { if (o3_timerid > 0) { clearTimeout(o3_timerid); o3_timerid = 0; } }
		over.onmouseout = function (e) { if (olHideDelay) hideDelay(olHideDelay); else cClick(e); }
	} else {
		over.onmouseover = function () {hoveringSwitch = true; if (o3_timerid > 0) { clearTimeout(o3_timerid); o3_timerid =0; } }
	}

	return 0;
}

// Function to scan command line arguments for multiples
function opt_MULTIPLEARGS(i, args, parameter) {
  var k=i, re, pV, str='';

  for(k=i; k<args.length; k++) {
		if(typeof args[k] == 'number' && args[k]>pmStart) break;
		str += args[k] + ',';
	}
	if (str) str = str.substring(0,--str.length);

	k--;  // reduce by one so the for loop this is in works correctly
	pV=(olNs4 && /cellpad/i.test(parameter)) ? str.split(',')[0] : str;
	eval(parameter + '="' + pV + '"');

	return k;
}

// Remove &nbsp; in texts when done.
function nbspCleanup() {
	if (o3_wrap) {
		o3_text = o3_text.replace(/\&nbsp;/g, ' ');
		o3_cap = o3_cap.replace(/\&nbsp;/g, ' ');
	}
}

// Escape embedded single quotes in text strings
function escSglQuote(str) {
  return str.toString().replace(/'/g,"\\'");
}

// Onload handler for window onload event
function OLonLoad_handler(e) {
	var re = /\w+\(.*\)[;\s]+/g, olre = /overlib\(|nd\(|cClick\(/, fn, l, i;

	if(!olLoaded) olLoaded=1;

  // Remove it for Gecko based browsers
	if(window.removeEventListener && e.eventPhase == 3) window.removeEventListener("load",OLonLoad_handler,false);
	else if(window.detachEvent) { // and for IE and Opera 4.x but execute calls to overlib, nd, or cClick()
		window.detachEvent("onload",OLonLoad_handler);
		var fN = document.body.getAttribute('onload');
		if (fN) {
			fN=fN.toString().match(re);
			if (fN && fN.length) {
				for (i=0; i<fN.length; i++) {
					if (/anonymous/.test(fN[i])) continue;
					while((l=fN[i].search(/\)[;\s]+/)) != -1) {
						fn=fN[i].substring(0,l+1);
						fN[i] = fN[i].substring(l+2);
						if (olre.test(fn)) eval(fn);
					}
				}
			}
		}
	}
}

// Wraps strings in Layer Generation Functions with the correct tags
//    endWrap true(if end tag) or false if start tag
//    fontSizeStr - font size string such as '1' or '10px'
//    whichString is being wrapped -- 'text', 'caption', or 'close'
function wrapStr(endWrap,fontSizeStr,whichString) {
	var fontStr, fontColor, isClose=((whichString=='close') ? 1 : 0), hasDims=/[%\-a-z]+$/.test(fontSizeStr);
	fontSizeStr = (olNs4) ? (!hasDims ? fontSizeStr : '1') : fontSizeStr;
	if (endWrap) return (hasDims&&!olNs4) ? (isClose ? '</span>' : '</div>') : '</font>';
	else {
		fontStr='o3_'+whichString+'font';
		fontColor='o3_'+((whichString=='caption')? 'cap' : whichString)+'color';
		return (hasDims&&!olNs4) ? (isClose ? '<span style="font-family: '+quoteMultiNameFonts(eval(fontStr))+'; color: '+eval(fontColor)+'; font-size: '+fontSizeStr+';">' : '<div style="font-family: '+quoteMultiNameFonts(eval(fontStr))+'; color: '+eval(fontColor)+'; font-size: '+fontSizeStr+';">') : '<font face="'+eval(fontStr)+'" color="'+eval(fontColor)+'" size="'+(parseInt(fontSizeStr)>7 ? '7' : fontSizeStr)+'">';
	}
}

// Quotes Multi word font names; needed for CSS Standards adherence in font-family
function quoteMultiNameFonts(theFont) {
	var v, pM=theFont.split(',');
	for (var i=0; i<pM.length; i++) {
		v=pM[i];
		v=v.replace(/^\s+/,'').replace(/\s+$/,'');
		/*if(/\s/.test(v) && !/['"]/.test(v)) {
			v="\'"+v+"\'";
			pM[i]=v;
		}*/
	}
	return pM.join();
}

// dummy function which will be overridden 
function isExclusive(args) {
	return false;
}

// Sets cellpadding style string value
function setCellPadStr(parameter) {
	var Str='', j=0, ary = new Array(), top, bottom, left, right;

	Str+='padding: ';
	ary=parameter.replace(/\s+/g,'').split(',');

	switch(ary.length) {
		case 2:
			top=bottom=ary[j];
			left=right=ary[++j];
			break;
		case 3:
			top=ary[j];
			left=right=ary[++j];
			bottom=ary[++j];
			break;
		case 4:
			top=ary[j];
			right=ary[++j];
			bottom=ary[++j];
			left=ary[++j];
			break;
	}


	Str+= ((ary.length==1) ? ary[0] + 'px;' : top + 'px ' + right + 'px ' + bottom + 'px ' + left + 'px;');

	return Str;
}

// function will delay close by time milliseconds
function hideDelay(time) {
	if (time&&!o3_delay) {
		if (o3_timerid > 0) clearTimeout(o3_timerid);

		o3_timerid=setTimeout("cClick()",(o3_timeout=time));
	}
}

// Was originally in the placeLayer() routine; separated out for future ease
function horizontalPlacement(browserWidth, horizontalScrollAmount, widthFix) {
	var placeX, iwidth=browserWidth, winoffset=horizontalScrollAmount;
	var parsedWidth = parseInt(o3_width);

	if (o3_fixx > -1 || o3_relx != null) {
		// Fixed position
		placeX=(o3_relx != null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
	} else {  
		// If HAUTO, decide what to use.
		if (o3_hauto == 1) {
			if ((o3_x - winoffset) > (iwidth / 2) && o3_hpos == RIGHT && ((o3_x - winoffset) - (parsedWidth + o3_offsetx - iwidth > (iwidth - widthFix)))) {
				o3_hpos = LEFT;
			} else if (o3_hpos == LEFT && ((o3_x - o3_offsetx - parsedWidth) < winoffset)) {
				o3_hpos = RIGHT;
			}
		}  		

		// From mouse
		if (o3_hpos == CENTER) { // Center
			placeX = o3_x+o3_offsetx-(parsedWidth/2);

			if (placeX < winoffset) placeX = winoffset;
		}

		if (o3_hpos == RIGHT) { // Right
			placeX = o3_x+o3_offsetx;

			if ((placeX+parsedWidth) > (winoffset+iwidth - widthFix)) {
				placeX = iwidth+winoffset - parsedWidth - widthFix;
				if (placeX < 0) placeX = 0;
			}
		}
		if (o3_hpos == LEFT) { // Left
			placeX = o3_x-o3_offsetx-parsedWidth;
			if (placeX < winoffset) placeX = winoffset;
		}  	

		// Snapping!
		if (o3_snapx > 1) {
			var snapping = placeX % o3_snapx;

			if (o3_hpos == LEFT) {
				placeX = placeX - (o3_snapx+snapping);
			} else {
				// CENTER and RIGHT
				placeX = placeX+(o3_snapx - snapping);
			}

			if (placeX < winoffset) placeX = winoffset;
		}
	}	

	return placeX;
}

// was originally in the placeLayer() routine; separated out for future ease
function verticalPlacement(browserHeight,verticalScrollAmount) {
	var placeY, iheight=browserHeight, scrolloffset=verticalScrollAmount;
	var parsedHeight=(o3_aboveheight ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight));

	if (o3_fixy > -1 || o3_rely != null) {
		// Fixed position
		placeY=(o3_rely != null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
	} else {
		// If VAUTO, decide what to use.
		if (o3_vauto == 1) {
			if ((o3_y - scrolloffset) > (iheight / 2) && o3_vpos == BELOW && (o3_y + parsedHeight + o3_offsety - (scrolloffset + iheight) > 0)) {
				o3_vpos = ABOVE;
			} else if (o3_vpos == ABOVE && (o3_y - (parsedHeight + o3_offsety) - scrolloffset < 0)) {
				o3_vpos = BELOW;
			}
		}

		// From mouse
		if (o3_vpos == ABOVE) {
			if (o3_aboveheight == 0) o3_aboveheight = parsedHeight; 

			placeY = o3_y - (o3_aboveheight+o3_offsety);
			if (placeY < scrolloffset) placeY = scrolloffset;
		} else {
			// BELOW
			placeY = o3_y+o3_offsety;
		} 

		// Snapping!
		if (o3_snapy > 1) {
			var snapping = placeY % o3_snapy;  			

			if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
				placeY = placeY - (o3_snapy+snapping);
			} else {
				placeY = placeY+(o3_snapy - snapping);
			} 			

			if (placeY < scrolloffset) placeY = scrolloffset;
		}
	}

	return placeY;
}

// checks positioning flags
function checkPositionFlags() {
	if (olHautoFlag) olHautoFlag = o3_hauto=0;
	if (olVautoFlag) olVautoFlag = o3_vauto=0;
	return true;
}

// get Browser window width
function windowWidth() {
	var w;
	if (o3_frame.innerWidth) w=o3_frame.innerWidth;
	else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientWidth=='number'")&&eval('o3_frame.'+docRoot+'.clientWidth')) 
		w=eval('o3_frame.'+docRoot+'.clientWidth');
	return w;			
}

// create the div container for popup content if it doesn't exist
function createDivContainer(id,frm,zValue) {
	id = (id || 'overDiv'), frm = (frm || o3_frame), zValue = (zValue || 1000);
	var objRef, divContainer = layerReference(id);

	if (divContainer == null) {
		if (olNs4) {
			divContainer = frm.document.layers[id] = new Layer(window.innerWidth, frm);
			objRef = divContainer;
		} else {
			var body = (olIe4 ? frm.document.all.tags('BODY')[0] : frm.document.getElementsByTagName("BODY")[0]);
			if (olIe4&&!document.getElementById) {
				body.insertAdjacentHTML("beforeEnd",'<div id="'+id+'"></div>');
				divContainer=layerReference(id);
			} else {
				divContainer = frm.document.createElement("DIV");
				divContainer.id = id;
				body.appendChild(divContainer);
			}
			objRef = divContainer.style;
		}

		objRef.position = 'absolute';
		objRef.visibility = 'hidden';
		objRef.zIndex = zValue;
		if (olIe4&&!olOp) objRef.left = objRef.top = '0px';
		else objRef.left = objRef.top =  -10000 + (!olNs4 ? 'px' : 0);
	}

	return divContainer;
}

// get reference to a layer with ID=id
function layerReference(id) {
	return (olNs4 ? o3_frame.document.layers[id] : (document.all ? o3_frame.document.all[id] : o3_frame.document.getElementById(id)));
}
////////
//  UTILITY FUNCTIONS
////////

// Checks if something is a function.
function isFunction(fnRef) {
	var rtn = true;

	if (typeof fnRef == 'object') {
		for (var i = 0; i < fnRef.length; i++) {
			if (typeof fnRef[i]=='function') continue;
			rtn = false;
			break;
		}
	} else if (typeof fnRef != 'function') {
		rtn = false;
	}
	
	return rtn;
}

// Converts an array into an argument string for use in eval.
function argToString(array, strtInd, argName) {
	var jS = strtInd, aS = '', ar = array;
	argName=(argName ? argName : 'ar');
	
	if (ar.length > jS) {
		for (var k = jS; k < ar.length; k++) aS += argName+'['+k+'], ';
		aS = aS.substring(0, aS.length-2);
	}
	
	return aS;
}

// Places a hook in the correct position in a hook point.
function reOrder(hookPt, fnRef, order) {
	var newPt = new Array(), match, i, j;

	if (!order || typeof order == 'undefined' || typeof order == 'number') return hookPt;
	
	if (typeof order=='function') {
		if (typeof fnRef=='object') {
			newPt = newPt.concat(fnRef);
		} else {
			newPt[newPt.length++]=fnRef;
		}
		
		for (i = 0; i < hookPt.length; i++) {
			match = false;
			if (typeof fnRef == 'function' && hookPt[i] == fnRef) {
				continue;
			} else {
				for(j = 0; j < fnRef.length; j++) if (hookPt[i] == fnRef[j]) {
					match = true;
					break;
				}
			}
			if (!match) newPt[newPt.length++] = hookPt[i];
		}

		newPt[newPt.length++] = order;

	} else if (typeof order == 'object') {
		if (typeof fnRef == 'object') {
			newPt = newPt.concat(fnRef);
		} else {
			newPt[newPt.length++] = fnRef;
		}
		
		for (j = 0; j < hookPt.length; j++) {
			match = false;
			if (typeof fnRef == 'function' && hookPt[j] == fnRef) {
				continue;
			} else {
				for (i = 0; i < fnRef.length; i++) if (hookPt[j] == fnRef[i]) {
					match = true;
					break;
				}
			}
			if (!match) newPt[newPt.length++]=hookPt[j];
		}

		for (i = 0; i < newPt.length; i++) hookPt[i] = newPt[i];
		newPt.length = 0;
		
		for (j = 0; j < hookPt.length; j++) {
			match = false;
			for (i = 0; i < order.length; i++) {
				if (hookPt[j] == order[i]) {
					match = true;
					break;
				}
			}
			if (!match) newPt[newPt.length++] = hookPt[j];
		}
		newPt = newPt.concat(order);
	}

	hookPt = newPt;

	return hookPt;
}

////////
//  PLUGIN ACTIVATION FUNCTIONS
////////

// Runs plugin functions to set runtime variables.
function setRunTimeVariables(){
	if (typeof runTime != 'undefined' && runTime.length) {
		for (var k = 0; k < runTime.length; k++) {
			runTime[k]();
		}
	}
}

// Runs plugin functions to parse commands.
function parseCmdLine(pf, i, args) {
	if (typeof cmdLine != 'undefined' && cmdLine.length) { 
		for (var k = 0; k < cmdLine.length; k++) { 
			var j = cmdLine[k](pf, i, args);
			if (j >- 1) {
				i = j;
				break;
			}
		}
	}

	return i;
}

// Runs plugin functions to do things after parse.
function postParseChecks(pf,args){
	if (typeof postParse != 'undefined' && postParse.length) {
		for (var k = 0; k < postParse.length; k++) {
			if (postParse[k](pf,args)) continue;
			return false;  // end now since have an error
		}
	}
	return true;
}


////////
//  PLUGIN REGISTRATION FUNCTIONS
////////

// Registers commands and creates constants.
function registerCommands(cmdStr) {
	if (typeof cmdStr!='string') return;

	var pM = cmdStr.split(',');
	pms = pms.concat(pM);

	for (var i = 0; i< pM.length; i++) {
		eval(pM[i].toUpperCase()+'='+pmCount++);
	}
}

// Registers no-parameter commands
function registerNoParameterCommands(cmdStr) {
	if (!cmdStr && typeof cmdStr != 'string') return;
	pmt=(!pmt) ? cmdStr : pmt + ',' + cmdStr;
}

// Register a function to hook at a certain point.
function registerHook(fnHookTo, fnRef, hookType, optPm) {
	var hookPt, last = typeof optPm;
	
	if (fnHookTo == 'plgIn'||fnHookTo == 'postParse') return;
	if (typeof hookPts[fnHookTo] == 'undefined') hookPts[fnHookTo] = new FunctionReference();

	hookPt = hookPts[fnHookTo];

	if (hookType != null) {
		if (hookType == FREPLACE) {
			hookPt.ovload = fnRef;  // replace normal overlib routine
			if (fnHookTo.indexOf('ol_content_') > -1) hookPt.alt[pms[CSSOFF-1-pmStart]]=fnRef; 

		} else if (hookType == FBEFORE || hookType == FAFTER) {
			var hookPt=(hookType == 1 ? hookPt.before : hookPt.after);

			if (typeof fnRef == 'object') {
				hookPt = hookPt.concat(fnRef);
			} else {
				hookPt[hookPt.length++] = fnRef;
			}

			if (optPm) hookPt = reOrder(hookPt, fnRef, optPm);

		} else if (hookType == FALTERNATE) {
			if (last=='number') hookPt.alt[pms[optPm-1-pmStart]] = fnRef;
		} else if (hookType == FCHAIN) {
			hookPt = hookPt.chain; 
			if (typeof fnRef=='object') hookPt=hookPt.concat(fnRef); // add other functions 
			else hookPt[hookPt.length++]=fnRef;
		}

		return;
	}
}

// Register a function that will set runtime variables.
function registerRunTimeFunction(fn) {
	if (isFunction(fn)) {
		if (typeof fn == 'object') {
			runTime = runTime.concat(fn);
		} else {
			runTime[runTime.length++] = fn;
		}
	}
}

// Register a function that will handle command parsing.
function registerCmdLineFunction(fn){
	if (isFunction(fn)) {
		if (typeof fn == 'object') {
			cmdLine = cmdLine.concat(fn);
		} else {
			cmdLine[cmdLine.length++] = fn;
		}
	}
}

// Register a function that does things after command parsing. 
function registerPostParseFunction(fn){
	if (isFunction(fn)) {
		if (typeof fn == 'object') {
			postParse = postParse.concat(fn);
		} else {
			postParse[postParse.length++] = fn;
		}
	}
}

////////
//  PLUGIN REGISTRATION FUNCTIONS
////////

// Runs any hooks registered.
function runHook(fnHookTo, hookType) {
	var l = hookPts[fnHookTo], k, rtnVal = null, optPm, arS, ar = runHook.arguments;

	if (hookType == FREPLACE) {
		arS = argToString(ar, 2);

		if (typeof l == 'undefined' || !(l = l.ovload)) rtnVal = eval(fnHookTo+'('+arS+')');
		else rtnVal = eval('l('+arS+')');

	} else if (hookType == FBEFORE || hookType == FAFTER) {
		if (typeof l != 'undefined') {
			l=(hookType == 1 ? l.before : l.after);
	
			if (l.length) {
				arS = argToString(ar, 2);
				for (var k = 0; k < l.length; k++) eval('l[k]('+arS+')');
			}
		}
	} else if (hookType == FALTERNATE) {
		optPm = ar[2];
		arS = argToString(ar, 3);

		if (typeof l == 'undefined' || (l = l.alt[pms[optPm-1-pmStart]]) == 'undefined') {
			rtnVal = eval(fnHookTo+'('+arS+')');
		} else {
			rtnVal = eval('l('+arS+')');
		}
	} else if (hookType == FCHAIN) {
		arS=argToString(ar,2);
		l=l.chain;

		for (k=l.length; k > 0; k--) if((rtnVal=eval('l[k-1]('+arS+')'))!=void(0)) break;
	}

	return rtnVal;
}

////////
// OBJECT CONSTRUCTORS
////////

// Object for handling hooks.
function FunctionReference() {
	this.ovload = null;
	this.before = new Array();
	this.after = new Array();
	this.alt = new Array();
	this.chain = new Array();
}

// Object for simple access to the overLIB version used.
// Examples: simpleversion:351 major:3 minor:5 revision:1
function Info(version, prerelease) {
	this.version = version;
	this.prerelease = prerelease;

	this.simpleversion = Math.round(this.version*100);
	this.major = parseInt(this.simpleversion / 100);
	this.minor = parseInt(this.simpleversion / 10) - this.major * 10;
	this.revision = parseInt(this.simpleversion) - this.major * 100 - this.minor * 10;
	this.meets = meets;
}

// checks for Core Version required
function meets(reqdVersion) {
	return (!reqdVersion) ? false : this.simpleversion >= Math.round(100*parseFloat(reqdVersion));
}


////////
// STANDARD REGISTRATIONS
////////
registerHook("ol_content_simple", ol_content_simple, FALTERNATE, CSSOFF);
registerHook("ol_content_caption", ol_content_caption, FALTERNATE, CSSOFF);
registerHook("ol_content_background", ol_content_background, FALTERNATE, CSSOFF);
registerHook("ol_content_simple", ol_content_simple, FALTERNATE, CSSCLASS);
registerHook("ol_content_caption", ol_content_caption, FALTERNATE, CSSCLASS);
registerHook("ol_content_background", ol_content_background, FALTERNATE, CSSCLASS);
registerPostParseFunction(checkPositionFlags);
registerHook("hideObject", nbspCleanup, FAFTER);
registerHook("horizontalPlacement", horizontalPlacement, FCHAIN);
registerHook("verticalPlacement", verticalPlacement, FCHAIN);
if (olNs4||(olIe5&&isMac)||olKq) olLoaded=1;
registerNoParameterCommands('sticky,autostatus,autostatuscap,fullhtml,hauto,vauto,closeclick,wrap,followmouse,mouseoff,compatmode');
///////
// ESTABLISH MOUSECAPTURING
///////

// Capture events, alt. diffuses the overlib function.
var olCheckMouseCapture=true;
if ((olNs4 || olNs6 || olIe4)) {
	olMouseCapture();
} else {
	overlib = no_overlib;
	nd = no_overlib;
	ver3fix = true;
}


//END TOOLTIP.JS


function checkHotelDate(){
	var startDate = new Date();
	var endDate = new Date(document.getElementById('startdate_y').value,parseFloat(document.getElementById('startdate_m').value)-1,document.getElementById('startdate_d').value);
	
	if(startDate < endDate)
	{
		return true;
	}
	else
	{
		alert("Please ensure your checkin date is valid!");
		return false;
	}
}


/*New client-side cookie handler code*/

function setClientData(){
	if(document.getElementById('BYOClientDateTime')) {
		var dteNow = new Date();
		var strDatetime = '';			
		
		var strMonth = (dteNow.getMonth() + 1).toString();
		var strDate = dteNow.getDate().toString()
		var strHours = dteNow.getHours().toString();
		var strMins = dteNow.getMinutes().toString();
		strDatetime = dteNow.getFullYear() + '-' + ((strMonth.length == 1) ? '0':'')  + strMonth + '-' + ((strDate.length == 1) ? '0':'')  + strDate + ' ';
		strDatetime +=	((strHours.length == 1) ? '0':'')  + strHours + ':' + ((strMins.length == 1) ? '0':'') + strMins;
	
		document.getElementById('BYOClientDateTime').value = strDatetime;
	}
}

function setCookie(c_name,value,expiredays){
	if(value != null && value != ''){
		var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" + value +
		((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) +
		((value.indexOf('path=')==-1) ? "; path=/" : "");
	}
}
function getCookie(c_name){
	if(document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1){ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end).replace(new RegExp("^[&]+", "g"), "").replace(new RegExp("[&]+$", "g"), ""));
		} 
	}
	return "";
}
function PersistCookies(name,affiliatedays){
	setCookie(name + 'Affiliate',getCookie(name + 'Affiliate'),affiliatedays);
	setCookie(name,getCookie(name),1);
}

