var showPopupInfoOnLoad = false;
var showPopupTourOnLoad = false;

function checkLHSContact() {
	var validate = new validateForm();
	if( document.getElementById('lhs_contact_name').value == 'Your Name' ) {
		validate.addCustomError( 'Your Name' );
	} else {
		validate.checkText( 'lhs_contact_name', 'Your Name' );
	}
	if( document.getElementById('lhs_contact_number').value == 'Your Phone Number' ) {
		validate.addCustomError( 'Your Phone Number' );
	} else {
		validate.checkText( 'lhs_contact_number', 'Your Phone Number' );
	}
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		return false;
	} 
	return true;
}

function inputBoxFocus( input, defaultText, passwordField ) {
	if( typeof( passwordField ) != 'undefined' ) {
		document.getElementById( passwordField ).style.display = '';
		document.getElementById( passwordField+'_text' ).style.display = 'none';
		document.getElementById( passwordField ).focus();
	} else {
		if( input.value == defaultText ) {
				input.value = '';
		} else {
		}
	}
}

function inputBoxBlur( input, defaultText, passwordField ) {
	if( input.value == '' ) {
		if( typeof( passwordField ) != 'undefined' ) {
			document.getElementById( passwordField ).style.display = 'none';
			document.getElementById( passwordField+'_text' ).style.display = '';
		} else {
			input.value = defaultText;
		}
	}
}

/* info popup match */
function initInfoPopup() {
	// Initialize the temporary Panel to display while waiting for external content to load
	document.getElementById('infoPopup').style.display = '';
	infoBox = 
			new YAHOO.widget.Panel("infoPopup",  
											{ width:"387px", 
											  height:"507px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3}
											} 
										);

	infoBox.render(document.body);
	if( showPopupInfoOnLoad )
		infoBox.show();
}

function hideInfoPopup() {
	// Show the Panel
	if( typeof infoBox != "undefined" )
		infoBox.hide();
}

function showInfoPopup() {
	// Show the Panel
	if( typeof infoBox != "undefined" )
		infoBox.show();
	else
		showPopupInfoOnLoad = true
}

function correctPNG( imageId ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var img = document.getElementById( imageId );
		var imgName = img.src.toUpperCase()
		var imgID = (img.id) ? "id='" + img.id + "' " : "";
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
		if (img.align == "left") imgStyle = "float:left;" + imgStyle
		if (img.align == "right") imgStyle = "float:right;" + imgStyle
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		img.outerHTML = strNewHTML
	}    
}

function showTerms(){
	window.open( '/popup/terms', 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=500, height=500');
}
/* tour popup */
/* info popup match */
function initTourPopup() {
	// Initialize the temporary Panel to display while waiting for external content to load
	document.getElementById('tourPopup').style.display = '';
	tourBox = 
			new YAHOO.widget.Panel("tourPopup",  
											{ width:"387px", 
											  height:"507px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3}
											} 
										);

	tourBox.render(document.body);
	if( showPopupTourOnLoad )
		tourBox.show();
}

function hideTourPopup() {
	// Show the Panel
	if( typeof tourBox != "undefined" )
		tourBox.hide();
}

function showTourPopup( id ) {
	var title = unescape( tourData[id]['title'] );
	if( title != '' ) {
		document.getElementById( 'tour_title' ).innerHTML = title;
	} else {
		document.getElementById( 'tour_title' ).innerHTML = 'No title';
	}
	var content = unescape( tourData[id]['content'] );
	if( content != '' ) {
		document.getElementById( 'tour_content' ).innerHTML = content;
	} else {
		document.getElementById( 'tour_content' ).innerHTML = 'No description';
	}
	// Show the Panel
	if( typeof tourBox != "undefined" )
		tourBox.show();
	else
		showPopupTourOnLoad = true
}
function singleJourney() {
	formattedPrice = currencyFormatted( getPrice.toFixed(2) );
	document.getElementById( 'price_chosen' ).value = formattedPrice;
	document.getElementById( 'price_chosen_view' ).innerHTML = formattedPrice;
}
function returnJourney() {
	var myReturnPrice = getPrice * 2;
	formattedPrice = currencyFormatted( myReturnPrice.toFixed(2) );
	document.getElementById( 'price_chosen' ).value = formattedPrice;
	document.getElementById( 'price_chosen_view' ).innerHTML = formattedPrice;
}
function currencyFormatted( amount ){
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}