var d = document;

function externalLinks(){
	for (var i=0; (a=document.getElementsByTagName('a')[i]);i++) {
		if (a.getAttribute("rel") == "external")
			a.target = "_blank";
	}
}
function setOpacity(e,op) {
	if(typeof e == "string")
		var x = $(e);
	else if(typeof e == "object")
		var x = e;
	if (!x) return;
	op = (op == 100)?99.999:op;
	// ie/Win
	x.style.filter = "alpha(opacity:"+op+")";
	// Safari<1.2, Konqueror
	x.style.KHTMLopacity = op/100;
	// Older mozilla and Firefox
	x.style.Mozopacity = op/100;
	// Safari 1.2, newer Firefox and mozilla, CSS3
	x.style.opacity = op/100;
}

function clearSearchBox(){
	var s = $('searchBox');
	if (typeof s == 'object')
		s.onfocus = function(){this.value='';}
}

function changeFontSize(){
	var i = $('incF');
	var d = $('decF');
	var s=readCookie('bc');

	if (!s)
		createCookie('bc', 2);
	else
		setBodyClass(s);

	if(!i || !d) return;

	i.onclick = function() {
		var s = readCookie('bc');
		if(s==1 || s==2){
			var x=s-(-1);
			setBodyClass(x);
			createCookie('bc',x);
		}
		return false;
	};

	d.onclick = function (){
		var s = readCookie('bc');
		if(s==2 || s==3){
			var x=s-1;
			setBodyClass(x);
			createCookie('bc',x);
		}
		return false;
	}

}
function setBodyClass(lvl){
	var a=new Array(0,'small','','big');
	document.getElementsByTagName('body')[0].className=a[lvl];
}

function highlightMenu(url) {
	var path = url.split('/');
	if (path && path[1]) {
		var el = $(path[1]+'Menu');
		if (el) {
			el.addClassName('current');
		}
	}
}

function webcamUpdate(){
	var img = $('camimg');
	if (!img) return;

	var cam = {
		src	: img.getAttribute('src')
	};

	cam.update=function(){
		$('camimg').src = cam.src + '?' + (new Date()*1);
	}
	new PeriodicalExecuter(cam.update, 10);
}



function ShowCurrentImage(imageName)
	{

		var thumb = document.getElementById("mainThumbArea");
		var divloading = document.getElementById("divloading");
		var divchild = document.getElementById("childslid");

			thumb.src = imageName;


			thumb.onreadystatechange = function() {

			if(thumb.readyState!="complete")
			{
				divloading.style.visibility = 'visible';
				divloading.className = "cropImageArea";
				divchild.style.visibility = 'hidden';
			}
	else if(thumb.readyState=="complete")
			{
				divloading.style.visibility = 'hidden';
				divchild.style.visibility = 'visible';
				divchild.style.position = 'relative';
				divchild.className = "cropImageArea";
			}

	};


	}


function slideshow() {

	if(!$('slideshow'))return;
	if (document.getElementsByTagName) {
	var popupLinks = document.getElementsByTagName("a");
	var slideshowImages = new Array();

	for (i = 0; i < popupLinks.length; i++) {
		if (popupLinks[i].className == "thumbnail_slideshow hidden") {
			slideshowImages.push(popupLinks[i].href);
		}
	}
	}

	var be = $('sse');
	var bn = $('ssn');
	var bp = $('ssp');
	var cs = $('ssc').firstChild;
	var thumb = document.getElementById("mainThumbArea");
	var divloading = document.getElementById("divloading");
	var divchild = document.getElementById("childslid");
	//var divchild2 = document.getElementById("divChild2");
	var temp ;
	var theSrc;

	bn.onclick = function(e){


		temp = thumb.src.split('=');
		temp = temp[1];

		temp++;
		if(temp >= slideshowImages.length){
			temp = 0;
		}


		document.getElementById("hdnId").value= parseInt(temp) + 1;

		thumb.src = slideshowImages[temp]+"?n="+temp;

			cs.nodeValue=++temp;
			stoplink(e);




if(navigator.appName =='Microsoft Internet Explorer')
	{


	thumb.onreadystatechange = function() {

	if(thumb.readyState!="complete")
			{
				divloading.style.visibility = 'visible';
				divloading.className = "cropImageArea";
				//divchild.className = "";
				divchild.style.visibility = 'hidden';
				//divchild.style.position = 'absolute';

				//Loading Please Wait............
				//divloading.innerHTML = "Loading image please wait....";
			}
	else if(thumb.readyState=="complete")
			{
				divloading.style.visibility = 'hidden';
				//divloading.className = "";
				divchild.style.visibility = 'visible';
				divchild.style.position = 'relative';
				divchild.className = "cropImageArea";

			}

		};
	}





	}


	bp.onclick = function(e){
		temp = thumb.src.split('=');
		temp = temp[1];
		temp--;
		if(temp < 0){
			temp = slideshowImages.length;
			temp--;
		}
		thumb.src = slideshowImages[temp]+"?n="+temp;

		document.getElementById("hdnId").value= parseInt(temp) + 1;

		cs.nodeValue=++temp;
		stoplink(e);
	}

	be.onclick = theSlideShow;
	//  be.onclick = theSlideShow2;

	return;

	if(!$('slideshow'))return;
	var s = {
		con	:	$('slideshow'),
		cur	:	0,
		cs	:	$('ssc').firstChild,	//counter
		ts	:	$('sst').firstChild,	//title
		bn	:	$('ssn'),	//next
		bp	:	$('ssp'),	//previous
		be	:	$('sse')	//enlarge
	};
	s.sl=s.con.getElementsByTagName('img');
	if(s.sl.length==0)return;

	s.move=function(n){

		for(var i=0;i<s.sl.length;i++)
			Element.addClassName(s.sl[i],'h');

		//var fpath=APP_URI+'images/locations/fullsize/';
		var fpath='/images/locations/hires/';
		var x=s.sl[s.cur].getAttribute('src').split('/');
		var fname=x[x.length-1];
		s.fi = new Image();
		s.fi.src = fpath+fname;

		mySetAttribute(s.be,'href', fpath+fname);
		Element.removeClassName(s.sl[s.cur],'h');
		s.cs.nodeValue=s.cur+1;
		s.ts.nodeValue=s.sl[s.cur].alt;
	}

	s.bn.onclick=function(e){
		s.cur=((s.cur+1)>=s.sl.length?0:(s.cur+1));
		s.move();
		stoplink(e);
	};

	s.bp.onclick=function(e){
		s.cur=((s.cur-1)<0?s.sl.length-1:(s.cur-1));
		s.move();
		stoplink(e);
	};

	s.be.onclick = function(e) {
		showIndicator();
		stoplink(e);

		var im = new Image();
		im.id="bigImage";
		im.src=this.getAttribute('href');
		im.alt=s.sl[s.cur].getAttribute('alt');
		im.title="Click to close [x]";

		if ($('popunder'))
			Element.remove($('popunder'));
		var pu = document.createElement('div');
		mySetAttribute(pu,'id','popunder');

		var a=document.createElement('a');
		mySetAttribute(a,'href','#');

		a.onclick = function(e){
			Element.remove(pu);stoplink(e);
		}

		var cl=document.createElement('a');
		mySetAttribute(cl,'href',"#");
		mySetAttribute(cl,'id',"img_close");
		cl.appendChild(document.createTextNode('Close this image [x]'));
		cl.onclick=function(e){
			Element.remove(this.parentNode);
			stoplink(e)
		};

		var bn=document.createElement('a');
		mySetAttribute(bn,'href',"#");
		mySetAttribute(bn,'id',"next_button");
		bn.appendChild(document.createTextNode('Next >>'));
		bn.onclick=function(e){
			s.cur=((s.cur+1)>=s.sl.length?0:(s.cur+1));
			setNewBigImage(s,im,pu,off);
			stoplink(e);
		};

		var bp=document.createElement('a');
		mySetAttribute(bp,'href',"#");
		mySetAttribute(bp,'id',"prev_button");
		bp.appendChild(document.createTextNode('<< Prev'));
		bp.onclick=function(e){
			s.cur=((s.cur-1)<0?s.sl.length-1:(s.cur-1));
			setNewBigImage(s,im,pu,off);
			stoplink(e);
		};


		var off=0;
		// only do this for ie
		if(typeof(document.media)=='string'){
			// scrolling offset calculation via www.quirksmode.org
			if (self.pageYOffset){off = self.pageYOffset;}
			else if (document.documentElement && document.documentElement.scrollTop) {off = document.documentElement.scrollTop; }
			else if (document.body) {off = document.body.scrollTop; }
		}


		var x=s.fi.width;
		var y=s.fi.height;
		mySetAttribute(im,'width',x);
		mySetAttribute(im,'height',y);
		pu.style.width=x+"px";

		//There used to be a cl.height here but ie has problems with
		//it so we just sort of guess the height - 25
		pu.style.height=y+25+"px";
		pu.style.marginLeft=-(x/2)+"px";
		pu.style.marginTop=-(y/2)+off+"px";
		a.appendChild(im);
		pu.appendChild(bp);
		pu.appendChild(bn);
		pu.appendChild(cl);
		pu.appendChild(a);
		document.getElementsByTagName('body')[0].appendChild(pu);


		removeIndicator();
		document.getElementById("popunder").style.display = "block";

		//a.focus();
		stoplink(e);

		s.move(s.cur+1);
	}


	//preload image
	s.move(0);
}

function setNewBigImage(s,im,pu,off){
	s.move();
	var x=s.fi.width;
	var y=s.fi.height;
	mySetAttribute(im,'width',x);
	mySetAttribute(im,'height',y);
	mySetAttribute(im,'src',s.be.getAttribute('href'));
	pu.style.width=x+"px";

	//There used to be a cl.height here but ie has problems with
	//it so we just sort of guess the height
	pu.style.height=y+25+"px";
	pu.style.marginLeft=-(x/2)+"px";
	pu.style.marginTop=-(y/2)+off+"px";
}

function details(){
	var con=$('infos');
	if(!con)return;
	var o={},s={};
	var g=function(n){
		var c=n.parentNode.nextSibling;
		return c.nodeName!="DD" ? c.nextSibling : c;
	};
	for(var i=0;(a=con.getElementsByTagName('a')[i]);i++){
		if(a.parentNode.nodeName!='DT')continue;
		var dd=g(a);
		var idd=dd.getAttribute('id');
		var ob="o."+idd;
		var os="s."+idd;
		eval(ob+'=new fx.Height(dd,{duration: 400});'+ob+'.hide();'+os+'=false;');
		a.onclick=function(e){
			var id=g(this).id;
			for(var i in o){
				if(typeof eval('o.'+i)!='function'&&i!=id){
					eval("if(s."+i+"){s."+i+"=false;o."+i+".toggle();}");
				}
			}
			eval('o.'+id+'.toggle();s.'+id+'=!s.'+id+';');
			stoplink(e);
		};
	}
}

function comparison(){
	var r=null;//requester
	var con=null;

	var trigg=document.getElementsByClassName('comp2');
	for(var i=0;(comp=trigg[i]);i++){

		var a=comp.getElementsByTagName('a')[0];
		if (!a) continue;
		a.onclick=function(e){

			if ($('comparison_content'))
				Element.remove($('comparison_content'));

			con=document.createElement('div');
			mySetAttribute(con,'id','comparison_content');

			var cl=document.createElement('a');
			mySetAttribute(cl,'href',"#");
			mySetAttribute(cl,'id',"compare_close");
			cl.appendChild(document.createTextNode('Close this comparison [x]'));
			cl.onclick=function(e){
				Element.remove(this.parentNode);
				stoplink(e)
			};

			// only do this for ie
			if(typeof(document.media)=='string'){
				var off=0;
				// scrolling offset calculation via www.quirksmode.org
				if (self.pageYOffset){off = self.pageYOffset;}
				else if (document.documentElement && document.documentElement.scrollTop) {off = document.documentElement.scrollTop; }
				else if (document.body) {off = document.body.scrollTop; }
				con.style.top=200+off;
			}

			con.appendChild(cl);

			fetch(this.id);

			document.getElementsByTagName('body')[0].appendChild(con);
			stoplink(e);
		};
	}

	var fetch=function(id){

		var T=id.substring(8,11).split('v');
		var url = APP_URI + 'compare.php';
		var pars = 't1='+escape(T[0])+'&t2='+escape(T[1]);
		var target = 'comwrap';
		var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars,onComplete:voodoo});
	}

	var voodoo=function(obj){
		var w=document.createElement('div');
		w.setAttribute('id','comwrap');
		con.appendChild(w);
		w.innerHTML=obj.responseText;
	}
}

function updateCost(){
	//console.log(">>>> updateCost");
	var numPeople = $F("passengers");
	var theWeightCharge = $F('weight_charge');
	var origCost = $F('original_cost');
	var totalCost = $('totalCostArea');
	var numComfort = $F("numComfort");
	var newTotal = 0;

	if( $F("passengers") > 1 ) {
		var display = "";
	}else {
		var display = "none";
	}

	for(var i=1;i<$("passengersList").rows.length;i++){
		$("passengersList").rows[i].cells[3].firstChild.nodeValue = "$" + $("price").value;
		$("passengersList").rows[i].cells[4].firstChild.style.display = display;
	}

	var totalComfort = Math.round(theWeightCharge*numComfort*100)/100;

	//Whether or not we show a comfort charge
	$('comfortSeat').firstChild.nodeValue = "$" + totalComfort;
	//$('tsComfortSeat').firstChild.nodeValue = "$" + totalComfort;
	if(numComfort > 0){
		$("comfortRow").style.display = "";
		//$("tsComfortRow").style.display = "";
	} else {
		$("comfortRow").style.display = "none";
		//$("tsComfortRow").style.display = "none";
	}

	//setTripSummary();
}

function datePicker(){
	if(!$('daSel'))return;

	Canlendar.setup({
		inputField: "date",
		dateFormat: "%m/%d/%Y",
		trigger: "daSel",
		align: "Br",
		weekNumbers: false
	});
}



function bookDatePicker(){
	if(!$('cal-button-1') || !$('cal-field-1'))return;

	var cal1, cal2, currDate;
	var minDate = new Date();
	minDate.setDate( minDate.getDate() );

	function dateInfo( date, wantsClassName ) {
		var d = new Date();
		var dd = Calendar.dateToInt(date);
		var dd1 = Calendar.dateToInt(d);


		if (dd == dd1) {
			return {
				klass: "calendarHighlight2",
				tooltip: "If requesting a tour within 24 hours please call us for immediate confirmation at:" +
							"Maui 808-871-8844 (or 800-745-2583) | Kauai 808-245-5800 (or 800-745-2583)" +
							"Oahu 808-831-8800 (or 800-745-2583) | Big Island 808-961-5600 (or 800-786-2583)"
			};
		}

		var d1 = new Date();
		d1.setDate(d.getDate() + 1);
		var d2 = new Date();
		d2.setDate(d.getDate() + 5);
		var dd2 = Calendar.dateToInt(d2);

		if (dd >= dd1 && dd <= dd2) {
			return {
				klass: "calendarHighlight",
				tooltip: "no discount day"
			};
		}
	}


	cal1 = Calendar.setup({
			inputField: "cal-field-1",
			dateFormat:"%m/%d/%Y",
			trigger: "cal-button-1",
			align: "Tr",
			selectionType: Calendar.SEL_SINGLE,
			weekNumbers: false,
			min: Calendar.dateToInt( minDate ),
			onSelect: function( args ) {
				/*
				if ($("cal-field-2").value) {
					var c1 = new Date(Date.parse($("cal-field-1").value, "m/d/Y"));
					var c2 = new Date(Date.parse($("cal-field-2").value, "m/d/Y"));
					if (c2 < c1) {
						$("cal-field-2").value = "";
					}
				}
				*/


				var now = Calendar.dateToInt( new Date() );
				var myDate = Calendar.dateToInt( new Date(Date.parse( $("cal-field-1").value, "m/d/Y") ) );

				if (now == myDate) {
					$("cal-field-1").value = "";
				} else {
					//cal2.refresh();
					setHeliPrice();
					this.hide();
				}
			},
			dateInfo: dateInfo
	});
	/*
	cal2 = Calendar.setup({
			inputField: "cal-field-2",
			dateFormat: "%m/%d/%Y",
			trigger: "cal-button-2",
			align: "T/r",
			selectionType: Calendar.SEL_SINGLE,
			weekNumbers: false,
			min: Calendar.dateToInt( minDate ),
			disabled: function(date) {
				if( $('cal-field-1').value ) {
					if( date < new Date( Date.parse($('cal-field-1').value, "m/d/Y") ) ) {
						return true;
					}
				}
			},
			onSelect: function( args ) {
				var now = Calendar.dateToInt( new Date() );
				var myDate = Calendar.dateToInt( new Date(Date.parse( $("cal-field-2").value, "m/d/Y") ) );

				if (now == myDate) {
					$("cal-field-2").value = "";
				} else {
					this.hide();
				}
			},
			dateInfo: dateInfo
	});
	*/
	//$('cal-field-1').addListener( "onClick", ie6Hack );
	//cal2.addEventListener( "onClick", ie6Hack );

}


function vacationDatePicker(){
	if(!$('vdp1') || !$('vdp2')) return;

	var cal1, cal2;

	cal1 = Calendar.setup({
		inputField: "vacdate1",
		dateFormat: "%m/%d/%Y",
		trigger: "vdp1",
		align: "Tr",
		selectionType: Calendar.SEL_SINGLE,
		weekNumbers : false,
		onSelect: function( args ) {
			this.hide();
		}
	});

	cal2 = Calendar.setup({
		inputField: "vacdate2",
		dateFormat: "%m/%d/%Y",
		trigger: "vdp2",
		align: "Tr",
		selectionType: Calendar.SEL_SINGLE,
		weekNumbers : false,
		onSelect: function( args ) {
			this.hide();
		}
	});
}

function homeLinks(){
	var c=document.getElementsByClassName('av')[0];
	if(!c)return;
	for(var i=0;(l=c.getElementsByTagName('li')[i]);i++){
		if (l.getElementsByTagName('a')[0])
		{
			l.style.cursor="pointer";
			l.onmouseover=function(){
				window.status=this.getElementsByTagName('a')[0].href;
			}
			l.onmouseout=function(){
				window.status='';
			}
			l.onclick=function(){
				window.location=this.getElementsByTagName('a')[0].href;
			}
		}
	}
}

/*
<tr>
	<td class="fname"><input type="hidden" value="1" name="person[0][type]"/><input type="text" id="personName_0" value="" name="person[0][firstName]"/></td>
	<td class="fname"><input type="hidden" value="1" name="person[0][type]"/><input type="text" id="personName_0" value="" name="person[0][lastName]"/></td>
	<td class="fweight"><input type="text" onchange="updateCost();" maxlength="4" id="personWeight_0" value="" name="person[0][weight]"/></td>
	<td class="fweight"><input type="text" maxlength="4" id="personHeight_0" value="" name="person[0][height]"/></td>
	<td class="fprice">$ 140.25</td>
	<td class="delete"><a class="del_link" href="#">delete</a><a href="#"><img alt="Delete" src="images/delete.png"/></a></td>
</tr>
*/

function setHeliPrice() {
	//console.log(">>>setHeliPrice");
	var helicopters = $("tourBook1")["helicopter"];
	var heliId;

	if( helicopters.length > 0 ) {
		for( var i = 0; i < helicopters.length; i++ ) {
			if( helicopters[i].checked == true ) {
				heliId = helicopters[i].value;
				break;
			}
		}

		if( heliId == null ) {
			heliId = helicopters[0].value;
			helicopters[0].checked = true;
		}
	}else {
		heliId = helicopters.value;
		helicopters.checked = true;
	}

	var p = $F("passengers");
	var hp = 0;

	if( p > 0 ) {
		for( var i = 1; i < $("passengersList").rows.length; i++ ) {
			// 251 - weight limit
			if( $("passengersList").rows[i].childNodes.length > 0) {
				for (var ii = 0; ii < $("passengersList").rows[i].cells.length; ii++) {
					if ($("passengersList").rows[i].cells[ii].className == "fweight") {
						if ($("passengersList").rows[i].cells[ii].getElementsByTagName("input")[0].value > 250) {
							hp++;
						}
					}
				}
			}
		}
	}
	$("numComfort").value = hp;
	//console.log([">>>", hp]);

	var params ="id=" + heliId + "&" +
				"tid=" + $("tour_id").value + "&" +
				"p=" + p + "&" +
				"hp=" + hp + "&" +
				"d1=" + $('cal-field-1').value + "&";// +
				//"d2=" + $('cal-field-2').value;

	//console.log( ">>>>>> prepared params: " + params );
	var q = new Ajax.Request( "book_heli.php",{
				method:"get",
				parameters: params,
				onFailure:function(res) {
					//console.log( "Epic Fail!" );
				},
				onSuccess:function(res) {
					var r = eval( "(" + res.responseText + ")" );


					var helicopters = "";
					for( var i = 0; i < r.priceList.length; i++ ) {
						var price = formatPrice(parseFloat( r.priceList[i].reduced ) + parseFloat( r.priceList[i].fee ));
						var checked = "";
						if (r.currHeliId == r.priceList[i].id) {
							checked = "checked='checked'";
						}
						helicopters += "<span class='formHeli'>" +
											"<input id='heliType' type='radio' name='helicopter' value='" + r.priceList[i].id + "' onClick='setHeliPrice();' " + checked + "/>" +
											"<span id='hc" + r.priceList[i].id + "' class='small'><strong>" + r.priceList[i].name + " - <b class='price'>$" + price + "</b></strong></span>" +
										"</span>";
					}

					$("helicopters").innerHTML = helicopters;

					$("weight_charge").value = r.weightCharge;
					$("original_cost").value = r.originalPrice;
					$("price").value = r.price;
					if( r.hour == 1 ) {
						$("price").value = $("price").value + "/h";
					}

					for( var i = 1; i < $("passengersList").rows.length; i++ ) {
						$("price" + $("passengersList").rows[i].id ).firstChild.nodeValue = "$"+ $("price").value;
					}

					var text = r.fee;
					if( r.hour == 1 ) {
						text += "/h";
					}
					if( $("taxes_and_fees").hasChildNodes() ) {
						$("taxes_and_fees").firstChild.nodeValue = text;
					}else {
						$("taxes_and_fees").appendChild( d.createTextNode( text ) );
					}

					text = r.regularPrice;
					if( r.hour == 1 ) {
						text += "/h";
					}
					if( $("regular_price").hasChildNodes() ) {
						$("regular_price").firstChild.nodeValue = text;
					}else {
						$("regular_price").appendChild( d.createTextNode( text ) );
					}

					text = r.total_cost;
					if( r.hour == 1 ) {
						text += "/h";
					}
					if( $("totalCostArea").hasChildNodes() ) {
						$("totalCostArea").firstChild.nodeValue = text;
					}else {
						$("totalCostArea").appendChild( d.createTextNode( text ) );
					}

					if( r.savings >= 0 ) {
						text = r.savings;
						if( r.hour == 1 ) {
							text += "/h";
						}
						if( $("onlineSavings").hasChildNodes() ) {
							$("onlineSavings").firstChild.nodeValue = text;
						}else {
							$("onlineSavings").appendChild( d.createTextNode( text ) );
						}
					}



					$("heliportAddr").href = "/" + r.island + "/tours/" + r.tourData["tour_nice_url"] + "/";
					$("heliportAddr2").href = $("heliportAddr").href;
					$("heliportName").firstChild.nodeValue = r.tourData['heliport_name'];
					$("heliportName2").firstChild.nodeValue = r.tourData['heliport_name'];
					$("tourDuration").firstChild.nodeValue = r.tourData['tour_duration'];
					if (r.tourMap.length) {
						$("tourMap").src = "/images/tours/maps/fullsize/" + r.tourMap;
					}
					//$("tsTourName").firstChild.nodeValue = r.tourData['tour_name'];

					$("minimum_party").value = r.tourData['tour_minimum_party'];

					updateCost();
				} });
}


function saveFormData() {
	if( !$("tourBook2") ) {
		return false;
	}

	var data = Array();
	var inputs = $("tourBook2").getElementsByTagName("input");

	if( inputs.length > 0 ) {
		for( var i = 0; i < inputs.length; i++ ) {
			data[i] = inputs[i].name + "=" + escape( inputs[i].value ) + "";
		}
	}

	var q = new Ajax.Request( "book_ss.php", { method: "post",
																		postBody: data.join('&'),
																		onComplete: function( res ) {

																		} } );
}

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec;
	y.splice(z, 0, pnt);
	while (z > 3) {
		z-=3;
		y.splice(z,0,thou);
	}
	var r = curr1+n1+y.join('')+n2+curr2;
	return r;
}

function formatPrice(num) {return formatNumber(num, 2, ',', '.', '', '', '', '');}

function passengersListFill() {
	//console.log(">> passengersListFill");
	if (!$F("passengers")) return;
	var pTotal = $F("passengers");
	var pExist = 0;
	if( $("passengersList").rows.length > 0 ) {
		pExist = $("passengersList").rows.length - 1;
	}
	var dp = pTotal;
	if( pExist != 0 ) {
		dp = pTotal - pExist;
	}

	if( dp > 0 ) {
		for( var i = pExist; i < pTotal; i++ ) {
			var num = i;

			var tr = $("passengersList").insertRow( -1 );
			tr.id = "pl" + num;
			var td = tr.insertCell(-1);
			//td.className = "fname";
			var input = d.createElement( "input" );
			input.type = "text";
			input.id = "personName_" + num;
			input.value="";
			input.name = "person[" + num + "][firstName]";
			input.style.width="100px";
			/*
			input.onkeyup = function() {
				updatePassengersList();
			}
			*/
			td.appendChild( input );

			input = d.createElement( "input" );
			input.type = "hidden";
			input.value="1";
			input.name = "person[" + num + "][type]";
			td.appendChild( input );

			td = tr.insertCell(-1);

			input = d.createElement( "input" );
			input.type = "text";
			input.value="";
			input.id = "personLastName_" + num;
			input.name = "person[" + num + "][lastName]";
			input.style.width="100px";
			/*
			input.onkeyup = function() {
				updatePassengersList();
			}
			*/
			td.appendChild( input );

			td = tr.insertCell(-1);
			td.className = "fweight";
			input = d.createElement( "input" );
			input.type = "text";
			input.value="170";
			input.id = "personWeight_" + num;
			input.name = "person[" + num + "][weight]";
			input.style.width="35px";
			/*
			input.onchange = function() {
				setHeliPrice();
			};
			input.onclick = function(input) {
				clearOnce(this);
			};
			*/
			input.maxlength = 4;
			td.appendChild( input );
			td.appendChild( d.createTextNode( "lbs." ) );

			td = tr.insertCell(-1);
			td.className = "tprice";
			var div = d.createElement("div");
			div.id = "price" + tr.id;
			div.innerHTML = '$' + $("price").value;
			td.appendChild( div );

			td = tr.insertCell(-1);
			td.className = "delete";
			div = d.createElement("div");
			div.id = "delPassenger"+num;
			div.innerHTML = '<a href="#pl" onclick="delPassenger(this);"><img alt="Delete" src="/images/delete.png"/></a>';
			td.appendChild( div );
		}
	}else
	if( dp < 0 ) {
		for( var i = dp; i < 0; i++ ) {
			$("passengersList").deleteRow($("passengersList").rows.length + i);
		}
	}

	updatePassengersList();
	setHeliPrice();
}

function delPassenger(a) {
	if( $("passengersList").rows.length == 2 ) {
		return;
	}

	var row = a.parentNode.parentNode.parentNode;

	for( var i = 1; i < $("passengersList").rows.length; i++ ) {
		if( row.id == $("passengersList").rows[i].id ) {
			$("passengersList").deleteRow( i );
			for( var ii = 0; ii < $("passengers").options.length; ii++ ) {
				if( $("passengers").options[ii].value == ($("passengersList").rows.length-1) ) {
					$("passengers").options[ii].selected = true;
				}else {
					$("passengers").options[ii].selected = false;
				}
			}
			break;
		}
	}

	for( var i = 1; i < $("passengersList").rows.length; i++ ) {
		var id = i - 1;
		var inputs = $("passengersList").rows[i].getElementsByTagName("input");
		inputs[0].name = "person["+id+"][firstName]";
		inputs[1].name ="person["+id+"][type]";
		inputs[2].name = "person["+id+"][lastName]";
		inputs[3].name =  "person["+id+"][weight]";
	}

	updatePassengersList();
	setHeliPrice();
}


function setTripSummary() {
	/*
	//console.log(">>>>> setTripSummary");
	$("tsDate").firstChild.nodeValue = $("cal-field-1").value;

	if ($("departure_time0").checked ) {
		$("tsDeparture").firstChild.nodeValue = $("client_departure_time").options[$("client_departure_time").selectedIndex].text;
	}

	if ($("departure_time1").checked ) {
		$("tsDeparture").firstChild.nodeValue = "Morning (8:00 AM to 12:00 PM)";
	}

	if ($("departure_time2").checked ) {
		$("tsDeparture").firstChild.nodeValue = "Afternoon (12:00 PM to 5:00 PM)";
	}

	$("tsComfortSeat").firstChild.nodeValue = $("comfortSeat").firstChild.nodeValue;
	$("tsComfortRow").style.display = $("comfortRow").style.display;
	$("tsPrice").firstChild.nodeValue = $F("price");
	$("tsTaxesAndFees").firstChild.nodeValue = $("taxes_and_fees").firstChild.nodeValue;
	$("tsTotalCost").firstChild.nodeValue = $("totalCostArea").firstChild.nodeValue;
	$("tsSavings").firstChild.nodeValue = $("onlineSavings").firstChild.nodeValue;
	$("tsRegularPrice").firstChild.nodeValue = $("regular_price").firstChild.nodeValue;

	//$("tsTotalPrice") = $("bookedPrice").value + $("totalCostArea").firstChild.nodeValue;
	*/
}

function updatePassengersList() {
	//(">>> updatePassengersList");
	var passengers = [];

	for (var i = 0; i < $( 'passengersList' ).rows.length; i++ ) {
		if ($('passengersList').rows[i].id) {
			passengers.push($('passengersList').rows[i].cells[0].getElementsByTagName("input")[0].value + " " + $('passengersList').rows[i].cells[1].getElementsByTagName("input")[0].value);
		}
	}
/*
	if (navigator.userAgent.toLowerCase().indexOf("safari") != -1) {
		$("tsPassengers").textContent = passengers.join(", ");
	} else {
		$("tsPassengers").firstChild.nodeValue = passengers.join(", ");
	}
*/
}


function showBillingAddress() {
	if( $F('sameAddress') == 1 ) {
		$("cc_address").style.display = "block";
	}else {
		$("cc_address").style.display = "none";
	}
}

function stepOneOnSubmit() {
	function _vMinimumParty() {
		var ps = $('passengers');
		var ch = $('children');
		var mp = $('minimum_party');
		if (!mp || !ps || !ch)
			return true;
		var psgsNum = ps[ps.selectedIndex].value;
		if (ch[ch.selectedIndex]) {
			var chldnNum = ch[ch.selectedIndex].value;
		} else {
			var chldnNum = 0
		}

		var min_party = mp.value;
		if (psgsNum + chldnNum < min_party) {
			regError('This tour requires a minimum of ' + min_party + ' passengers: ( please call 1-800-745-BLUE ).' );
			return false;
		}
		return true;
	}
	//validate date
	function _vDate(d){
		var t=d.parentNode.parentNode;
		if ($F(d)=="") {
			regError( 'Please provide a date.' );
			return false;
		}

		if (!validateDate($F(d))) {
			regError( 'Invalid date format.' );
			return false;
		}

		return true;
	}

	//validate helipocopter
	function _vHelicopters(a) {
		var f=false;
		for(var i=0;i<a.length;i++){
			if (a[i].checked==true) {f=true;}
		}
		if (!f){
			regError( "Choose helicopter." );
		}
		return f;
	}

	//validate departure time
	function _vTime() {
		var f = $F("departure_time1");
		if ( !$("departure_time1") && !$("departure_time2")){
			regError( "Choose departure time." );
			return false;
		}
		return true;
	}

	function _vPassengers() {
		var t=$('passengersList');
		if(!t)return;
		for(var i=0;(inp=t.getElementsByTagName('input')[i]);i++){
			if (inp.value=="") {
				regError( 'Please provide passenger information for each participating person.' );
				return false;
			}

//			if (inp.value.indexOf("ie:") >= 0 ) {
//				regError( 'Please provide real weight and height information for each participating person.' );
//				return false;
//			}

		}
		return true;
	}


	var h=new Array(), t=new Array,d;
	for(var i=0;(inp=$('tourBook1').getElementsByTagName('input')[i]);i++) {
		if(inp.name=="helicopter" && inp.type!='hidden')
			h[h.length]=inp;
		if(inp.name=="time")
			t[t.length]=inp;
		if(inp.name=="date")
			d=inp;
	}

	//clear all errors before rechecking the form
	clearErrors();


	var flag = true;
	if(h.length > 1 && !_vHelicopters(h)) flag=false;
	if(!_vDate(d)) flag=false;
	if(!_vTime()) flag=false;
	if (!_vMinimumParty()) flag=false;
	if (!_vPassengers()) flag=false;

	if (!flag) {
		$("errorBlock" ).style.display = "";
		window.location = "#error";
	}

	return flag;
}
/*
function validateStep1() {
	var f=$('tourBook1');
	if(!f)return;
	f.onsubmit=function() {
		return stepOneOnSubmit();
	}


}
*/

function regError(msg) {
	var con=document.createElement('p');
	con.appendChild(document.createTextNode( msg ));

	$("errorBlock").appendChild( con );
}

function clearErrors() {
	var err = $("errorBlock");
	err.style.display = "none";
	while (err.hasChildNodes()) {
		err.removeChild( err.firstChild );
	}
}


//function regError2(e, msg) {
//	var txt = document.createTextNode(msg + "&nbsp;" );
//	var con=document.createElement('tr');
//	var td=document.createElement('td');
//	var s=document.createElement('strong');
//	mySetAttribute(td, 'colspan', 3);
//	s.appendChild(txt);
//	td.appendChild(s);
//	con.appendChild(td);
//	Element.addClassName(con, "err");
//	e.parentNode.parentNode.insertBefore(con, e.parentNode);
//}

function validateDate(d){
	/*
	SUPERB !!! pls don't remove this line !!! I didn't see this kind of validation anywhere!
	var reg = /(01|02|03|04|05|06|07|08|09|10|11|12)\/(01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)\/(2005|2006|2007|2008|2009|2010)/;
	return reg.test(d);
	*/
	return str.match(new RegExp("^[0-9]{2}/[0-9]{2}/[0-9]{4}$"));
}

//step 2 validation
function validateStep2(){
	var f = $('tourBook2');
	if(!f)return;
	f.onsubmit=function(){
		var flag=true;

		clearErrors();

		if(!_vClientName()) flag=false;
		if(!_vClientAddress()) flag=false;
		if(!_vClientCity()) flag=false;
		if(!_vClientCountry()) flag=false;
		if(!_vClientPhone()) flag=false;
		if(!_vClientEmail()) flag=false;
		if(!_vTravelAccommodation()) flag=false;
		if(!_vTravelCell()) flag=false;
		if(!_vCCname()) flag=false;
		if(!_vCCnumber()) flag=false;
		if(!_vCCcvv()) flag=false;
		if($F('sameAddress')) {
			if(!_vClientName_bill()) flag=false;
			if(!_vClientAddress_bill()) flag=false;
			if(!_vClientCity_bill()) flag=false;
			if(!_vClientCountry_bill()) flag=false;
			if(!_vClientPhone_bill()) flag=false;
		}
		if(!_vTravelDates()) flag=false;    //see case 8373
		if(!_vTerms()) flag=false;
		if (!flag) {
			$("errorBlock" ).style.display = "";
			window.location = "#error";
		}
		return flag;
	}

	function _vClientName(){
		if($F('firstName')=="" || $F('lastName')=="") {
			regError('Please provide your name.');
			return false;
		}
		return true;
	}

	function _vClientPhone(){
		if($F('phone')=="") {
			regError('Please provide your phone number.');
			return false;
		}
		return true;
	}

	function _vTravelAccommodation(){
		if($F('accommodation')=="") {
			regError('Please provide your place of accommodation during your vacation.');
			return false;
		}
		return true;
	}

	function _vTravelCell(){
		if($F('cellphone')=="") {
			regError('Please provide your cellphone, so that we can contact you.');
			return false;
		}
		return true;
	}

	function _vClientEmail(){
		var e1=$F('email'),e2=$F('emailConfirm');
		if(e1==""){
			regError('Please provide your email address.');
			return false;
		}
		else if(!validateEmail(e1)) {
			regError('Invalid email format.');
			return false;
		}
		else if(e1!=e2) {
			regError('Emails don\'t match.');
			return false;
		}
		return true;
	}

	function _vClientAddress(){
		if($F('address_one')=="") {
			regError('Please provide your billing address.');
			return false;
		}
		return true;
	}

	function _vClientCity(){
		if($F('city')==""||($F('zip')==""&&$F('state')=="")) {
			regError('Please provide your billing city, state / Zip code.');
			return false;
		}
		return true;
	}

	function _vClientCountry() {
		if($F('country')=="") {
			regError('Please provide your country.');
			return false;
		}
		return true;
	}



	function _vCCname(){
		if($F('ccName')==""){
			regError('Please provide the name from credit card.');
			return false;
		}
		return true;
	}

	function _vCCnumber() {
		var c=$F('ccNumber').replace( / /, "" );
		if(c=="") {
			regError('Please provide your credit card number.');
			return false;
		}
		else if(!Mod10(c)) {
			regError('Invalid credit card number.');
			return false;
		}
		return true;
	}

	function _vCCcvv() {
		if($F('ccCvv')==""){
			regError('Please provide the card security code.');
			return false;
		}
		return true;
	}

	function _vClientPhone_bill(){
		if($F('phone_bill')=="") {
			regError('Please provide your phone number.');
			return false;
		}
		return true;
	}

	function _vClientAddress_bill(){
		if($F('address_one_bill')=="") {
			regError('Please provide your billing address.');
			return false;
		}
		return true;
	}

	function _vClientCity_bill(){
		if($F('city_bill')==""||($F('zip_bill')==""&&$F('state_bill')=="")) {
			regError('Please provide your billing city, state / Zip code.');
			return false;
		}
		return true;
	}

	function _vClientCountry_bill() {
		if($F('country_bill')=="") {
			regError('Please provide your country.');
			return false;
		}
		return true;
	}

	function _vTerms(){
		if(!$F('agree')){
			regError('You must accept the terms & conditions.');
			return false;
		}
		return true;
	}

	function _vClientName_bill(){
		if($F('firstName_bill')=="" || $F('lastName_bill')=="") {
			regError('Please provide your first and last name.');
			return false;
		}
		return true;
	}

	function _vTravelDates(){
		if($F('vacdate1')=="" || $F('vacdate2')=="") {
			regError('Please provide your vacation start and end dates.');
			return false;
		}
		return true;
	}

	/*
	function _vTravelDates(){
		var v1=$('vacdate1'),v2=$('vacdate2');
		var v1v=$F('vacdate1'),v2v=$F('vacdate2');

		if(v1v=="" || v2v==""){
			regError('Please provide your vacation start and end dates.');
			return false;
		} else if(!validateDate(v1v) || !validateDate(v2v)) {
				regError('Invalid date format');
				return false;
		} else {
			var d1 = new Date();
			var d2 = new Date()
			d1.setYear(parseInt(v1v.substring(6,10)));
			d1.setMonth(parseInt(v1v.substring(0,2)-1));
			d1.setDate(parseInt(v1v.substring(3,5)));

			d2.setYear(parseInt(v2v.substring(6,10)));
			d2.setMonth(parseInt(v2v.substring(0,2)-1));
			d2.setDate(parseInt(v2v.substring(3,5)));

			var checkDate1=d1.getTime();
			var checkDate2=d2.getTime();
			if (checkDate1 >= checkDate2) {
				regError('Vacation end date cannot be earlier to start date.');
				return false;
			}
		}
		return true;
	}
	*/
}





function validateContactForm() {
	var flag = true;
	clearErrors();

	if(!_vClientName()) flag=false;
	if(!_vClientEmail()) flag=false;
	if(!_vClientMessage()) flag=false;
	if(!_vClientCode()) flag=false;

	function _vClientName(){
		if($F('contactName')=="") {
			regError('Please provide your name.');
			return false;
		}
		return true;
	}

	function _vClientEmail(){
		var e1=$F('contactEmail');
		if(e1==""){
			regError('Please provide your email address.');
			return false;
		}
		else if(!validateEmail(e1)) {
			regError('Invalid email format.');
			return false;
		}

		return true;
	}

	function _vClientMessage(){
		if($F('contactMessage')=="") {
			regError('Please provide your message.');
			return false;
		}
		return true;
	}

	function _vClientCode(){
		if($F('captcha')=="") {
			regError('Please enter security code from image.');
			return false;
		}
		return true;
	}


	if (!flag) {
		$("errorBlock" ).style.display = "";
		window.location = "#error";
	}
	return flag;
}


/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function Mod10(ccNumb) {  // v2.0
	var valid = "0123456789"  // Valid digits in a credit card number
	var len = ccNumb.length;  // The length of the submitted cc number
	var iCCN = parseInt(ccNumb);  // integer of ccNumb
	var sCCN = ccNumb.toString();  // string of ccNumb
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
	var iTotal = 0;  // integer total set at zero
	var bNum = true;  // by default assume it is a number
	var bResult = false;  // by default assume it is NOT a valid cc
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit

	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
		temp = "" + sCCN.substring(j, j+1);
		if (valid.indexOf(temp) == "-1"){bNum = false;}
	}

	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
		/*alert("Not a Number");*/bResult = false;
	}

	// Determine if it is the proper length
	if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
		bResult = false;
	} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
		if(len >= 15){  // 15 or 16 for Amex or V/MC
			for(var i=len;i>0;i--){  // LOOP throught the digits of the card
				calc = parseInt(iCCN) % 10;  // right most digit
				calc = parseInt(calc);  // assure it is an integer
				iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
				i--;  // decrement the count - move to the next digit in the card
				iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
				calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
				calc = calc *2;                                 // multiply the digit by two
				// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
				// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
				switch(calc){
					case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
					case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
					case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
					case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
					case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
					default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
				}
				iCCN = iCCN / 10;  // subtracts right most digit from ccNum
				iTotal += calc;  // running total of the card number as we loop
			}  // END OF LOOP
			if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
				bResult = true;  // This IS (or could be) a valid credit card number.
			} else {
				bResult = false;  // This could NOT be a valid credit card number
			}
		}
	}
	return bResult; // Return the results
}

function showIndicator()
{
	//removeIndicator();
	var holder = document.createElement('div');
	var indicator = document.createElement('img');
	indicator.src = APP_URI+"images/indicator.gif";
	indicator.id = 'indicator';
	indicator.alt = 'Please wait';
	var x= 16;
	var y=16;
	indicator.height = 16;
	indicator.width = 16;

	var off=0;
	// only do this for ie
	if(typeof(document.media)=='string'){
		// scrolling offset calculation via www.quirksmode.org
		if (self.pageYOffset){off = self.pageYOffset;}
		else if (document.documentElement && document.documentElement.scrollTop) {off = document.documentElement.scrollTop; }
		else if (document.body) {off = document.body.scrollTop; }
	}


	holder.appendChild(indicator);
	document.getElementsByTagName('body')[0].appendChild(holder);
}

function removeIndicator()
{
	if ($('indicator'))
		Element.remove($('indicator'));
}
function popImage(filename, filetitle,width,height)
{
	var s = {
		fi		: new Image(),
		fname	: filename,
		title	: filetitle,
		width	: width,
		height	: height
	};

	s.fi.src = s.fname;

	showIndicator();
	s.fi.onload = loadThePopup(s);
//	s.fi.onload = function() {

}

function loadThePopup(s){

		removeIndicator();
		if ($('popunder'))
			Element.remove($('popunder'));
		var pu = document.createElement('div');
		mySetAttribute(pu,"id","poppedUp");

		mySetAttribute(pu,'id','popunder');

		var a=document.createElement('a');
		mySetAttribute(a,'href','#');

		a.onclick = function(e){
			Element.remove(pu);stoplink(e);
		}

		var cl=document.createElement('a');
		mySetAttribute(cl,'href',"#");
		mySetAttribute(cl,'id',"compare_close");
		cl.appendChild(document.createTextNode('Close this image [x]'));
		cl.onclick=function(e){
			Element.remove(this.parentNode);
			stoplink(e)
		};

		var im=document.createElement('img');
		mySetAttribute(im,'src',s.fname);
		mySetAttribute(im,'alt',s.title);
		mySetAttribute(im,'title','Click to close [x]');

		var off=0;
		// only do this for ie
		if(typeof(document.media)=='string'){
			// scrolling offset calculation via www.quirksmode.org
			if (self.pageYOffset){off = self.pageYOffset;}
			else if (document.documentElement && document.documentElement.scrollTop) {off = document.documentElement.scrollTop; }
			else if (document.body) {off = document.body.scrollTop; }
		}


		var x=s.width;
		var y=s.height;

		mySetAttribute(im,'width',x);
		mySetAttribute(im,'height',y);
		pu.style.width=x+"px";
		pu.style.height=y+cl.height+"px";
		pu.style.marginLeft=-(x/2)+"px";
		pu.style.marginTop=-(y/2)+off+"px";
		a.appendChild(im);
		pu.appendChild(cl);
		pu.appendChild(a);
		document.getElementsByTagName('body')[0].appendChild(pu);
		a.focus();
	//}
}

function preloadImages(){
	if(document.images){
		var imgObject = new Array();
		var imgArray = new Array();
		var imgs=document.getElementsByClassName('bigImage');
		for(var i=0;i<imgs.length;i++){
			imgArray[i] = imgs[i].getAttribute('href');
		}
		for(var i=0;i<imgs.length;i++){
			imgObject[i] = new Image();
			imgObject[i].src = imgArray[i];
		}
	}
}

//SLIDESHOW - NEWEST
function closeThumbnail()
{
	var theBody = document.getElementsByTagName("body")[0];
	var theCanvasShadow = document.getElementById("canvasShadow");

	//theBody.style.backgroundColor = "#fff";
	theCanvasShadow.className = "hidden";

	return false;
}


function closeWindow()
{
	window.close();
	return false;
}

function theSlideShow(){

	var theBody = document.getElementsByTagName("body")[0];
	var theCanvasShadow = document.getElementById("canvasShadow");
	var theCloseLink = document.createElement("a");
	var theContentHeight = 561;
	var theDD = document.createElement("dd");
	var theDDInner = document.createElement("div");
	var theDL = document.createElement("dl");
	var theDT = document.createElement("dt");
	var theIDNum = 0;
	var theImage = document.createElement("img");
	var theNextImage = document.createElement("img");
	var theLinksContainer = document.createElement("div");
	var theNextLink = document.createElement("a");
	var thePreviousLink = document.createElement("a");
	var theDesc = document.createElement("div");
	var theSpan = document.createElement("span");

	//alert(this.id);
	theIDNum = parseInt(this.id.replace(/.*thumbnailLink(.*[0-9]).*/, "$1"));

	if(isNaN(theIDNum)){
		theIDNum = 1;
	}

	var theTotal = 0;
	for(var i = 1; i<50; i++){
		if (document.getElementById("thumbnailLink" + i)){

		} else {
			theTotal = i;
			break;
		}
	}
	theTotal--;

	theDesc.innerHTML = theIDNum + ' of '+theTotal+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+document.getElementById('thumbnailLink'+theIDNum).innerHTML;
	theDesc.className = "theDescription";



	theCanvasShadow.innerHTML = "";

	//theBody.style.backgroundColor = "#000000";
	theCanvasShadow.className = "on";

	theImage.id = "exampleImage";
	theImage.src = this.href.replace(/\?.*/, "");
	theImage.alt = this.title.replace(/.*/, theDesc.innerHTML);

	theDL.style.width = "900px";
	theDL.style.marginTop = parseInt((theContentHeight - 100 - 10 - 27 - 10) / 2) + "px";

	theSpan.innerHTML = theImage.alt;

	theLinksContainer.id = "linksContainer";

	thePreviousLink.className = "previousLink";

	if (document.getElementById("thumbnailLink" + (theIDNum - 1)))
	{
		var thePreviousThumbnail = document.getElementById("thumbnailLink" + (theIDNum - 1));

		thePreviousLink.id = thePreviousThumbnail.id + "Previous";
		thePreviousLink.href = thePreviousThumbnail.href;
		thePreviousLink.onclick = theSlideShow;
		thePreviousLink.title = thePreviousThumbnail.title;
		thePreviousLink.innerHTML = "&laquo; previous photo";
	}
	else
	{
		thePreviousLink.name = "none";
		thePreviousLink.className += " off";
	}

	theCloseLink.id = "closeLink";
	theCloseLink.className = "closeLink";
	theCloseLink.href = "#";
	theCloseLink.onclick = closeThumbnail;
	theCloseLink.title = "Close this image";
	theCloseLink.innerHTML = "close window [x]";

	theNextLink.className = "nextLink";

	if (document.getElementById("thumbnailLink" + (theIDNum + 1)))
	{
		var theNextThumbnail = document.getElementById("thumbnailLink" + (theIDNum + 1));

		theNextLink.id = theNextThumbnail.id + "Next";
		theNextLink.href = theNextThumbnail.href;
		theNextLink.onclick = theSlideShow;
		theNextLink.title = theNextThumbnail.title;
		theNextLink.innerHTML ="next photo &raquo;";

		theNextImage.id = "nextImage";
		theNextImage.src =	theNextThumbnail.href.replace(/\?.*/, "");
		theNextImage.style.visibility = "hidden";

	}
	else
	{
		theNextLink.name = "none";
		theNextLink.className += " off";

		theNextImage.src =	"";
	}

	theLinksContainer.appendChild(thePreviousLink);
	theLinksContainer.appendChild(theNextLink);
	theLinksContainer.appendChild(theCloseLink)	;
	theLinksContainer.appendChild(theDesc);
	theCanvasShadow.appendChild(theLinksContainer);
	theDT.appendChild(theImage);
	theDT.appendChild(theNextImage);
	theDDInner.appendChild(theSpan);
	theDD.appendChild(theDDInner);
	theDL.appendChild(theDT);
	theDL.appendChild(theDD);
	theCanvasShadow.appendChild(theDL);

	scroll(0,0);
	return false;
}


function theSlideShow2(file_name){

	//alert(file_name);
	var theBody = document.getElementsByTagName("body")[0];
	//var theCanvasShadow = document.getElementById("canvasShadow2");
	var theCloseLink = document.createElement("a");
	var theContentHeight = 0;
	var theDD = document.createElement("dd");
	var theDDInner = document.createElement("div");
	var theDL = document.createElement("dl");
	var theDT = document.createElement("dt");
	var theIDNum = 0;
	var theImage = document.createElement("img");

	//var theImage = document.getElementById("exampleImage");

	//var theNextImage = document.createElement("img");
	//var theLinksContainer = document.createElement("div");
	var theNextLink = document.createElement("a");
	var thePreviousLink = document.createElement("a");


	var thePreviousContainer = document.getElementById("divPrevious");
	var theNextContainer = document.getElementById("divNext");
	var theCloseContainer = document.getElementById("divClose");
	var theMainImageContainer = document.getElementById("ShowImage");
	var theMsg = document.getElementById("DivShowMsg");
	var theOpenerId = window.opener.document.getElementById("hdnId");




//divCnt

	thePreviousContainer.innerHTML="";
	theNextContainer.innerHTML="";



	//var theDesc = document.createElement("div");

	var theCounter = document.getElementById("divCnt");
	var theDesc = document.getElementById("divPlace");


	theCounter.innerHTML="";
	theDesc.innerHTML="";
	theCloseContainer.innerHTML="";
	theMainImageContainer.innerHTML = "";



	var theSpan = document.createElement("span");
	var theBlank = document.createElement("div");



			if(!this.id || this.id==null)
			{
			if(theOpenerId.value=="")
				{
				theIDNum = 1;
				}
			else
				{
				theIDNum = parseInt(theOpenerId.value);
				}
			}
			else
			{
			theIDNum = parseInt(this.id.replace(/.*thumbLink(.*[0-9]).*/, "$1"));
			}

			if(isNaN(theIDNum)){
				theIDNum = 1;
			}


	var theTotal = 0;
	for(var i = 1; i<50; i++){
		if (window.opener.document.getElementById("thumbLink" + i)){

		} else {
			theTotal = i;
			break;
		}
	}
	theTotal--;


	theCounter.innerHTML = theIDNum + ' of '+theTotal+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';



	theDesc.innerHTML = window.opener.document.getElementById('thumbLink'+theIDNum).innerHTML;



	document.title = window.opener.document.getElementById('thumbLink'+theIDNum).innerHTML;



	document.title +="| Blue Hawaiian Helicopters "


	theDesc.className = "SlideHeading";



	//theCanvasShadow.innerHTML = "";



	//theBody.style.backgroundColor = "#000000";

	//theCanvasShadow.className = "on";



	//theImage.id = "exampleImage";

<!--<table height="343" width="516"><tr><td valign="middle" align="center"><b>Loading photo please wait......</b></td></tr></table>-->

if(!this.href || this.href=="undefined")
{


		if(theOpenerId.value=="")
				{

				theImage.src = file_name.replace(/\?.*/, "");
				}
			else
				{

				theImage.src = window.opener.document.getElementById("thumbLink" + (theIDNum)).href;
				}




	theImage.onreadystatechange = function() {

		//alert(theImage.readyState);

	if(theImage.readyState!="complete")
			{
				//theMsg.style.position = 'relative';
				theMsg.style.visibility = 'visible';
				//divloading.className = "cropImageArea";

				theMainImageContainer.style.visibility = 'hidden';
			}
	else if(theImage.readyState=="complete")
			{
				//theMsg.style.position = 'absolute';
				theMsg.style.visibility = 'hidden';

				theMainImageContainer.style.visibility = 'visible';
				theMainImageContainer.style.position = 'relative';
				//divchild.className = "cropImageArea";

			}
		};


	theImage.alt = window.opener.document.getElementById('thumbLink'+theIDNum).innerHTML;
	//theImage.width="960";
}
else
	{

theImage.src = this.href.replace(/\?.*/, "");

	theImage.onreadystatechange = function() {

		//alert(theImage.readyState);

	if(theImage.readyState!="complete")
			{
				theMsg.style.visibility = 'visible';
				//theMsg.style.position = 'relative';
				//divloading.className = "cropImageArea";

				theMainImageContainer.style.visibility = 'hidden';
			}
	else if(theImage.readyState=="complete")
			{

				//theMsg.style.position = 'absolute';
				theMsg.style.visibility = 'hidden';
				theMainImageContainer.style.visibility = 'visible';
				theMainImageContainer.style.position = 'relative';
				//divchild.className = "cropImageArea";

			}
		};

	theImage.alt = window.opener.document.getElementById('thumbLink'+theIDNum).innerHTML;
	//theImage.width="960";
	}


if(theImage.width>1000)
	{
	theImage.width="1000";
	};




// Assigning Code Starts

	theImage.style.align="center";
	theDL.style.width = "1025px";
	theDL.style.height = "700px";
	//theLinksContainer.style.width = "1025px";

	theBlank.style.width="100";

	theDL.style.marginTop = parseInt((theContentHeight - 100 - 10 - 27 - 10) / 2) + "px";

	theSpan.innerHTML = theImage.alt;

//	theLinksContainer.id = "linksContainer";

//	thePreviousLink.className = "previousLink";



	if (window.opener.document.getElementById("thumbLink" + (theIDNum - 1)))
	{


		var thePreviousThumbnail = window.opener.document.getElementById("thumbLink" + (theIDNum - 1));

		thePreviousLink.id = thePreviousThumbnail.id + "Previous";
		thePreviousLink.href = thePreviousThumbnail.href;
		thePreviousLink.onclick = theSlideShow2;
		thePreviousLink.title = thePreviousThumbnail.title;
		thePreviousLink.innerHTML = '<img src="/images/popupImages/slideBarPreviousBt.gif" width="79" height="33" border="0" Id="ImgPre">';    //&laquo; previous photo
	}
	else
	{

	///	thePreviousLink.name = "none";
	///	thePreviousLink.className += " off";
	}



	theCloseLink.id = "closeLink";
	theCloseLink.className = "closeLink";
	theCloseLink.href = "#";
	theCloseLink.onclick = closeWindow;
	theCloseLink.title = "Close this image";
	theCloseLink.innerHTML = '<img src="/images/popupImages/SlideCloseBT.gif" width="65" height="22" border="0">'; /// close window [x]
	//theCloseLink.align="left";

	///theNextLink.className = "nextLink";



	if (window.opener.document.getElementById("thumbLink" + (theIDNum + 1)))
	{


		var theNextThumbnail = window.opener.document.getElementById("thumbLink" + (theIDNum + 1));

		theNextLink.id = theNextThumbnail.id + "Next";
		theNextLink.href = theNextThumbnail.href;
		theNextLink.onclick = theSlideShow2;
		theNextLink.title = theNextThumbnail.title;
		theNextLink.innerHTML ='<img src="/images/popupImages/slideBarNextBt.gif" width="79" height="33" border="0" Id="ImgNex">';  //next photo &raquo;

		//theNextImage.id = "nextImage";
		//theNextImage.src =	theNextThumbnail.href.replace(/\?.*/, "");
		//theNextImage.style.visibility = "hidden";

	}
	else
	{

	///	theNextLink.name = "none";
	///	theNextLink.className += " off";
	}


	///theLinksContainer.appendChild(thePreviousLink);
	///theLinksContainer.appendChild(theNextLink);
	///theLinksContainer.appendChild(theCloseLink)	;
	///theLinksContainer.appendChild(theBlank);
	///theLinksContainer.appendChild(theDesc);
///	theCanvasShadow.appendChild(theLinksContainer);
	thePreviousContainer.appendChild(thePreviousLink);
	theNextContainer.appendChild(theNextLink);
	theCloseContainer.appendChild(theCloseLink);

	theMainImageContainer.appendChild(theImage);

	//theDT.appendChild(theImage);
	///theDT.appendChild(theNextImage);
	theDDInner.appendChild(theSpan);
	theDD.appendChild(theDDInner);
	theDL.appendChild(theDT);
	theDL.appendChild(theDD);
	//theCanvasShadow.appendChild(theDL);

	scroll(0,0);
	return false;
}


// Detecting Flash player Functions

function JSGetSwfVer(i){

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		} else {
			flashVer = -1;
		}
	}

	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;

	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;

	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;

	else {

		flashVer = -1;
	}
	return flashVer;
}



/*function VBGetSwfVer(i)
{
var swControl, swVersion;
swVersion = 0;


swControl = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i.toString());

if((IsObject(swControl))){
	swVersion = swControl.GetVariable("$version");
}
return swVersion;
}*/


function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	reqVer = parseFloat(reqMajorVer + "." + reqRevision);

	for (i=25;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);
		}

		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];

			versionString     = versionMajor + "." + versionRevision;
			versionNum        = parseFloat(versionString);

			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
	return (reqVer ? false : 0.0);
}

function lib_bwcheck(){ //Browsercheck (needed)
		this.ver=navigator.appVersion
		this.agent=navigator.userAgent
		this.dom=document.getElementById?1:0
		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
		this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
		this.ie4=(document.all && !this.dom)?1:0;
		this.ie=this.ie4||this.ie5||this.ie6
		this.mac=this.agent.indexOf("Mac")>-1
		this.opera5=this.agent.indexOf("Opera 5")>-1
		this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
		this.ns4=(document.layers && !this.dom)?1:0;
		this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
		//return this
		if(this.ie6 || this.ie5 || this.ie4)
			{
			return "ie";
			}
		else if(this.ns4 || this.ns6 || this.opera5)
			{
			return "other";
			}

}


function alertcheck(url)
{

	//alert(url);
	//var chkBrowser = lib_bwcheck();

//alert(url);
// Globals
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;



//var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;



var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if(hasRightVersion) {
	var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	+ 'width="720" height="640"'
	+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" id="blue">'
	+ '<param name="movie" value="'+url+'" /><param name="quality" value="high" /><param name="bgcolor" value="#14285f" />'
	+ '<embed src="'+url+'" quality="high" bgcolor="#14285f" '
	+ 'width="720" height="640" name="detectiontest" align="middle"'
	+ 'play="true"'
	+ 'loop="false"'
	+ 'quality="high"'
	+ 'allowScriptAccess="sameDomain"'
	+ 'type="application/x-shockwave-flash"'
	+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
	+ '<\/embed>'
	+ '<\/object>';
	document.write(oeTags);
	//alert(oeTags);
} else {
	var alternateContent = '<p align="center"><font color="red">An old version of the Flash plugin was detected. <strong><a href="http://www.macromedia.com/go/getflash/" >Please upgrade your Flash plugin.</a></strong></font></p>';
	document.write(alternateContent);
}
}



function clearOnce(input) {
if (input.cleared)
	return;

input.value = '';
input.cleared = true;
}


/* ------------------------------------------------------------------------- */


function galerySelect( item ) {
	if (!$("gallery")) {
		return;
	}

	var items = $("galmenu").getElementsByTagName( "a" );
	for (var i = 0; i < items.length; i++) {
		items[i].className = "";
	}

	item.className = "current";

	items = $("gallery").getElementsByTagName( "div" );
	for (var i = 0; i < items.length; i++) {
		if( items[i].id != "galmenu") {
			items[i].style.display = "none";
		}
	}

	$( "items_" + item.firstChild.className ).style.display = "";

}


function testimonialPage(page) {
	if( !$("testimonials")) {
		return;
	}

	var q = new Ajax.Request( "/testimonials_nav.php",{
				method:"get",
				parameters: 'p=' + page,
				onComplete: function(res) {
					var r = eval( "(" + res.responseText + ")" );
					if (r.data.length > 0) {
						var content = "";
						for (var i = 0; i < r.data.length; i++) {
							content += '<p class="quote">' + r.data[i].content +
										'<strong>' + r.data[i].author + '</strong><a href="/about/testimonials/" title="Show more testimonials">more <b>&raquo;</b></a></p>' +
										'<p class="grline">&nbsp;</p>';
						}
						$("testimonials").innerHTML = content;

						if ($("tprev")) {
							$("tprev").onclick = function() {
								testimonialPage(r.prev);
							}
						}

						if ($("tnext")) {
							$("tnext").onclick = function() {
								testimonialPage(r.next);
							}
						}

						if ($("tpages")) {
							var dots = "";
							for (var i = 0; i < r.pagesnum; i++) {
								if (r.currpage == i) {
									dots += "	<b class='current'>&nbsp;</b>"
								} else {
									dots += "	<b>&nbsp;</b>"
								}
							}

							$("tpages").innerHTML = dots;
						}
					}

				} });


}

function switchEl(el) {
	var elems = $('showhideul').select('ul');
	if (elems && elems.length) {
		for (var i=0; i<elems.length; i++) {
			elems[i].hide();
		}
	}
	elems = $$('li.s_title');
	if (elems && elems.length) {
		for (var i=0; i<elems.length; i++) {
			elems[i].removeClassName('current');
		}
	}
	var elem = $(el);
	var elem2 = $(el+'li');
	if (elem) {
		if (elem.style.display=='none') {
			elem.show();
			if (elem2) elem2.addClassName('current');
		} else {
			elem.hide();
			if (elem2) elem2.removeClassName('current');
		}
	}
}

function switchHelis(el) {
	var elems = $('helislist').select('ul');
	if (elems && elems.length) {
		for (var i=0; i<elems.length; i++) {
			elems[i].hide();
		}
	}
	var elem = $(el);
	if (elem) {
		if (elem.style.display=='none') {
			elem.show();
		} else {
			elem.hide();
		}
	}
}

function switchDiv(el) {
	var elem = $(el);
	if (elem) {
		if (elem.style.display=='none') {
			elem.show();
		} else {
			elem.hide();
		}
	}
}

function imgPreloader(arr){
var img=new Image();
for(var i=0;i<arr.length;++i)
	img.src=arr[i];
}


function locationsPage(island_id, page) {
	//console.log(["locationsPage>>", island_id, page]);
	if( !$("locations")) {
		return;
	}
	var types = [];
	for(i=0;i<document.phototour.checkgroup.length;i++){
		if (document.phototour.checkgroup[i].checked) {
			types.push(document.phototour.checkgroup[i].value);
		}
	};

	if (!types.length) {
		$('locations').hide();
		$('leftright').hide();
		$('page_container').style.visibility = 'hidden';
		$('flash_phototours').style.visibility = 'hidden';
		$('curr_title').innerHTML = "";
		$('curr_desc').innerHTML = "";
	}

	var q = new Ajax.Request( "/locations_nav.php",{
			method:"post",
			parameters: {
				i: island_id,
				p: page,
				t: types.toJSON()
			},
			onComplete: function(res) {
				$("locations").innerHTML = "";
				$("leftright").hide();
				var r = eval( "(" + res.responseText + ")" );
				if( r.success ) {
					if (r.data) {
						if(r.data.length > 0) {
							var content = "";
							for (var i = 0; i < r.data.length; i++) {
								content += '<li><a href="javascript:void(0)" onclick="updateSlideShow(\'' + r.data[i].id + '\',true)">' + r.data[i].name + '</a></li>';
							}
							$("locations").innerHTML = content;
							$('locations').show();
							if ($("lprev")) {
								$("lprev").onclick = function() {
									locationsPage(island_id, r.prev);
								}
							}

							if ($("lnext")) {
								$("lnext").onclick = function() {
									locationsPage(island_id, r.next);
								}
							}
							$("leftright").show();

							if ($("lpages")) {
								var dots = "";
								var iMin = 0;
								var iMax = r.pagesnum;

								if (r.pagesnum > 15) {
									iMin = r.currpage - 4;
									iMax = r.currpage + 4;
								}
								for (var i = iMin; i < iMax; i++) {
									if (r.currpage == i) {
										dots += "	<b class='current'>&nbsp;</b>"
									} else {
										dots += "	<b>&nbsp;</b>"
									}
								}

								$("lpages").innerHTML = dots;
							}

							var types = [];
							for(i=0;i<document.phototour.checkgroup.length;i++){
								if (document.phototour.checkgroup[i].checked) {
									types.push(document.phototour.checkgroup[i].value);
								}
							};
							//console.log( ["types: ", types] );
							if( types.length > 0 ) {
								$('page_container').style.visibility = 'visible';
								$('flash_phototours').style.visibility = 'visible';
							}
						}
					}
				}
			}
		}
	);
}

function areasPage(island_id, page) {
	if( !$("locations")) {
		return;
	}

	var q = new Ajax.Request( "/areas_nav.php",{
				method:"get",
				parameters: 'i=' + island_id + '&p=' + page,
				onComplete: function(res) {
					var r = eval( "(" + res.responseText + ")" );
					if (r.data.length > 0) {
						var content = "";
						for (var i = 0; i < r.data.length; i++) {
							content += '<li><a href="javascript:void(0)" onclick="playStream2(' + r.data[i].video_id + ')">' + r.data[i].video_name + '</a></li>';
						}
						$("locations").innerHTML = content;

						if ($("lprev")) {
							$("lprev").onclick = function() {
								areasPage(island_id, r.prev);
							}
						}

						if ($("lnext")) {
							$("lnext").onclick = function() {
								areasPage(island_id, r.next);
							}
						}

						if ($("lpages")) {
							var dots = "";
							var iMin = 0;
							var iMax = r.pagesnum;

							if (r.pagesnum > 20) {
								iMin = r.currpage - 4;
								iMax = r.currpage + 4;
							}
							for (var i = iMin; i < iMax; i++) {
								if (r.currpage == i) {
									dots += "	<b class='current'>&nbsp;</b>"
								} else {
									dots += "	<b>&nbsp;</b>"
								}
							}

							$("lpages").innerHTML = dots;
						}

					}

				} });


}

function addAdditionalTour() {
	if (!stepOneOnSubmit()) {
		return;
	}


	var input = d.createElement( "input" );
	input.type = "hidden";
	input.name = "addAdditional";
	input.value = "1";
	$("tourBook1").appendChild( input );

	$("tourBook1").submit();

}

function loginFormVisible( isVisible ) {
	if (isVisible) {
		$("loginForm").style.display = "";
	} else {
		$("loginForm").style.display = "none";
	}
}

var dialogs_theme = 'alphacube';
var popupWin;
var confirmed = false;

function closeLoginForm() {
	$("loginForm").hide();
	if (popupWin)
		popupWin.close();
}

function showLoginForm() {
	popupWin = new Window({title:'Login Form', className:dialogs_theme, showEffect: Element.show, hideEffect: Element.hide, resizable:false, closable:true, minimizable: false, maximizable:false, draggable: true, destroyOnClose: true, onClose: closeLoginForm});
	popupWin.setContent("loginForm", true, true);
	popupWin.setZIndex(10000);
	popupWin.showCenter(true);
}

function closeConfirmForm() {
	$("confirmForm").hide();
	if (!confirmed)
		$("departure_time1").checked = true;
	if (popupWin)
		popupWin.close();
}

function yesConfirmForm() {
	if (!$("checkedConfirm").checked)
		return false;
	$("confirmForm").hide();
	confirmed = true;
	if (popupWin)
		popupWin.close();
	$("departure_time0").checked = true;
	//setTripSummary();
	return false;
}

function showConfirmForm() {
	if (confirmed) {
		$("departure_time0").checked = true;
		//setTripSummary();
		return;
	}
	$("opacity").addClassName("opacity");
	$("checkedConfirm").checked = false;
	popupWin = new Window({title:'Confirmation', width: 400, height: 200, className:dialogs_theme, showEffect: Element.show, hideEffect: Element.hide, resizable:false, closable:true, minimizable: false, maximizable:false, draggable: true, destroyOnClose: true, onClose: closeConfirmForm});
	popupWin.setContent("confirmForm", true, true);
	popupWin.setZIndex(10000);
	popupWin.showCenter(true);
}

function switchConfirmButton(state) {
	if ($("checkedConfirm").checked) {
		$("opacity").removeClassName("opacity");
	} else {
		$("opacity").addClassName("opacity");
	}
}


function showWhatIsThis() {
	popupWin = new Window({title:'What is this?', className:dialogs_theme, showEffect: Element.show, hideEffect: Element.hide, resizable:false, closable:true, minimizable: false, maximizable:false, draggable: true, destroyOnClose: true, onClose: closeConfirmForm});
	popupWin.setContent("whatIsThis", true, true);
	popupWin.setZIndex(10000);
	popupWin.showCenter(true);
}


function setIsland() {
	if (!$F("island_id")) {
		return;
	}


	var q = new Ajax.Request( "/book_island.php",{
				method:"get",
				parameters: 'id=' + $F("island_id"),
				onComplete: function(res) {
					var r = res.responseText.evalJSON();
					if (r.success) {
						//var toursSelect = document.createElement( "select" );
						while ($("tour_id").length > 0 ) {
							$("tour_id").remove($("tour_id").length-1);
						}

						for( var i = 0; i < r.tours.length; i++ ) {
							var tour = document.createElement( "option" );
							tour.value = r.tours[i]['tour_id'];
							tour.text = r.tours[i]['tour_name'];
							//$("tour_id").add( tour );
							try {
								$("tour_id").add( tour, null );
							}catch( ex ) {
								$("tour_id").add( tour );
							}
						}

						var helicopters = "";
						for( var i = 0; i < r.priceList.length; i++ ) {
							var price = formatPrice(parseFloat( r.priceList[i].reduced ) + parseFloat( r.priceList[i].fee ));
							var checked = "";
							if (r.currHeliId == r.priceList[i].id) {
								checked = "checked='checked'";
							}
							helicopters += "<span class='formHeli'>" +
												"<input id='heliType' type='radio' name='helicopter' value='" + r.priceList[i].id + "' onClick='setHeliPrice();' " + checked + "/>" +
												"<span id='hc" + r.priceList[i].id + "' class='small'><strong>" + r.priceList[i].name + " - <b class='price'>$" + price + "</b></strong></span>" +
											"</span>";
						}

						$("helicopters").innerHTML = helicopters;

						passengersListFill();

						var phones = $('island_phones').getElementsByTagName('li');
						for( var i = 0; i < phones.length; i++ ) {
							phones[i].style.display = "none";
						}

						$('if_' + r.island ).style.display = "";
					}

				} });

}


// common.js
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all :
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function stoplink(e)
{
	if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.stopPropagation && e.preventDefault) {
      e.stopPropagation();
      e.preventDefault();
    }
}

//look for it at list apart
function mySetAttribute(el,att,val)
{
	if (el.getAttributeNode(att)) {
	  for (var i = 0; i < el.attributes.length; i++) {
	    var attrName = el.attributes[i].name.toUpperCase();
	    if (attrName == att.toUpperCase()) {
			el.attributes[i].value = val;
	    }
	  }
	// otherwise create a new attribute
	} else {
	  el.setAttribute(att, val);
	}
}

function validateEmail(e) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])/;
	return reg.test(e);
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}


// init.js
function init() {
	activateMenu('mainMenu');

	bookDatePicker();
	vacationDatePicker();

	if( $("tourBook1") ) {
		passengersListFill();
	}

	if( $("tourBook2") ) {
		showBillingAddress();
	}

	//validateStep1();
	validateStep2();
}

function init_old(){
	if(arguments.callee.done)return;
	arguments.callee.done=true;

	externalLinks();
	setOpacity('sublogo',50);
	clearSearchBox();
	changeFontSize();
	/*@cc_on @*/
	/*@if (@_win32)
  		navigation();
	/*@end @*/
	webcamUpdate();
	slideshow();
	details();
	comparison();
	datePicker();
	vacationDatePicker();
	bookDatePicker();
	homeLinks();

	if( $("tourBook1") ) {
		passengersListFill();
		//setHeliPrice();
		//updateCost();
	}

	if( $("tourBook2") ) {
		showBillingAddress();
	}

	validateStep1();
	validateStep2();
	validateStep3()
	preloadImages();
	var sPath = window.location.pathname;
	var sPage = sPath.indexOf('phototour');
	if(sPage > 0){
		document.getElementsByTagName('body')[0].className='phototour';
	}
};
/*
// mainmenu.js
activateMenu = function(mainMenu) {
	if (document.all && document.getElementById(mainMenu).currentStyle) {
        var navroot = document.getElementById(mainMenu);
        var lis=navroot.getElementsByTagName("LI");
        for (i=0; i<lis.length; i++) {

			var uls = lis[i].getElementsByTagName('UL');

            if( uls.length > 0 ){
                // assign the function to the LI
             	lis[i].onmouseover=function() {
                   // display the inner menu
                   this.getElementsByTagName('UL')[0].style.display="block";
                }
                lis[i].onmouseout=function() {
                   this.getElementsByTagName('UL')[0].style.display="none";
                }
            }
        }
    }
}
*/