/*

GZIP CONTENT DELIVERY
Copyright 2010 Fat Publisher

All rights reserved. Republication, redistribution,
replication or use of Fat Publisher content / scripting
is strictly prohibited without the prior written consent of Fat Publisher.

www.fatpublisher.com.au

Content generated : 07:05:46 am 07 September 2010

*/

var onload_events = new Array();

function add_to_onload(event)
{
	onload_events.push(event);
	window.onload = function() { 
		for (var x = 0; x < onload_events.length; x ++) {
			eval(onload_events[x]);
		}
	}
}

function get_position(obj, type)
{
	var retval = 0;

	if (type == "Left" && obj.x) {
		return obj.x;
	}
	else if (obj.y) {
		return obj.y;
	}
	else {
		while (obj.offsetParent) {
			if (obj && obj.style && obj.style.position) obj.style.position = "relative";
			retval += eval("obj.offset" + type);
			obj = obj.offsetParent;
		}
		return retval;
	}
}

function dom_id(id, elmnt)
{
	return (elmnt) ? elmnt.getElementById(id) : document.getElementById(id);
}

function check_contact_form(obj)
{
	var elmnts = obj.form.elements;
	/*if (elmnts["enquiry"].value.length == 0) {
		alert("Please enter your enquiry to continue");
		elmnts["enquiry"].focus();
		return false;
	}
	else */if (elmnts["firstname"].value.length == 0) {
		alert("Please enter your first name to continue");
		elmnts["firstname"].focus();
		return false;
	}
	else if (elmnts["surname"].value.length == 0) {
		alert("Please enter your last name to continue");
		elmnts["surname"].focus();
		return false;
	}
	else if (elmnts["email"].value.length == 0 || elmnts["email"].value.indexOf("@") == -1) {
		alert("Please enter a valid email to continue");
		elmnts["email"].focus();
		return false;
	}
	else if (elmnts["day_time_phone"].value.length == 0 && elmnts["after_hours_phone"].value.length == 0 && elmnts["mobile_phone"].value.length == 0) {
		alert("Please enter a phone, after hours or mobile number to continue");
		return false;
	}
	else if (elmnts["how_did_you_hear_about_us"].value == "#" || (elmnts["how_did_you_hear_about_us"].value == "other" && elmnts["how_did_you_hear_about_us_other"].value.length == 0)) { 
		alert("Please tell us how you heard about us");
		if (elmnts["how_did_you_hear_about_us"].value == "other") {
			elmnts["how_did_you_hear_about_us_other"].focus();
		}
		else {
			elmnts["how_did_you_hear_about_us"].focus();
		}
		return false;
	}
	return true;
}

function show_other_option(obj)
{
	document.getElementById("other_row").style.display = (obj.value == "other") ? "" : "none";
}

function which_key(e)
{
	if (! e) {
		e = window.event;
	}
	return (e.keyCode) ? e.keyCode : (e.which) ? e.which : e.charCode;
}

function add_popups()
{
	var lnks = document.getElementsByTagName("A");
	for (var x = 0; x < lnks.length; x ++) {
		var rel = lnks[x].getAttribute("rel");
		if (rel && rel.search(/^popup/) != -1) {
			lnks[x].onclick = function() {
				var pstr = this.getAttribute("rel").replace(/^popup_?/, "");
				window.open(this.href, "", pstr);
				return false;
			}
		}
	}
}

add_to_onload("add_popups()");










function load_image(img_number) {

        thumb_source = document.getElementById('picture-'+img_number).src;

        new_big = thumb_source.replace(/\/details-thumb\//, '/details-big/');

        document.getElementById('picture').style.width = "323px";
        document.getElementById('picture').style.height = "210px";
        document.getElementById('picture').src = "/images/clear.gif";
        setTimeout("document.getElementById('picture').src = '" + new_big + "';",100);

        if (
                (document.getElementById('picture-holder').style.display=='block')
                ||
                (document.getElementById('picture-holder').style.display=='')
        ) {
                return false;
        }

        document.getElementById('picture-holder').style.display = 'block';
        document.getElementById('google-maps').style.display = 'none';

        return false;

}

function load_map(latitude, longitude) {

	document.getElementById('picture-holder').style.display = 'none';
	document.getElementById('google-maps').style.display = 'block';
	
	var map = new GMap2(document.getElementById("google-maps"));
	map.setCenter(new GLatLng(latitude, longitude), 13);
	map.setMapType(G_SATELLITE_MAP);
	map.addControl(new GSmallMapControl());
	point = new GPoint(longitude, latitude);
	marker = new GMarker(point);
	map.addOverlay(marker);

}


function get_price_form(obj, productName, fromCityCode, service_id) {
	position_y = get_position(obj, "Top");
	position_x = get_position(obj, "Left");
	$('book-now-form-'+service_id).style.display = 'block';
	$('book-now-form-'+service_id).style.left = (position_x+20) + 'px';
	$('book-now-form-'+service_id).style.top = (position_y+10-$('book-now-form-'+service_id).offsetHeight) + 'px';
	$$('#book-now-form-'+service_id + ' input.formProductName').each(function(a) {
		a.value = urldecode(productName);
	});
	$$('#book-now-form-'+service_id + ' input.formFromCityCode').each(function(a) {
		a.value = fromCityCode;
	});
}


function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function urldecode(str) {
	return unescape(str).replace(/\+/g, ' ');
}

function hide_price_form() {
	$$('div.book-now-form').each(function(a) {
		a.style.display = 'none';
	});
}

function check_dates(service_id) {
	valid = validate_date($('fromDate-'+service_id).value, 'Date In');
	if (valid!=0) {
		alert(valid);
		return false;
	}
	if ((service_id==14) || (service_id==32) || (service_id==4)) {
		return true;
	}
	valid = validate_date($('toDate-'+service_id).value, 'Date Out');
	if (valid!=0) {
		alert(valid);
		return false;
	}
	if (date_aus_to_seconds($('toDate-'+service_id).value)<date_aus_to_seconds($('fromDate-'+service_id).value)) {
		alert('Date In is after Date Out');
		return false;
	}
	return true;
}

function validate_date(dateValue, fieldName) {
	dateArray = dateValue.split('-');
	if (dateArray.length != 3) {
		return fieldName + ' is invalid. Use DD-MM-YYYY';
	}
	valid = new Date(dateArray[2], dateArray[1]-1,dateArray[0]);
	if (valid=='Invalid Date') {
		return fieldName + ' is invalid. Use DD-MM-YYYY';
	}
	timeNow = new Date();
	if (valid.getTime()<timeNow.getTime()) {
		return 'The ' + fieldName + ' is in the past.';
	}
	return 0;
}

function date_aus_to_seconds(dateValue) {
	dateArray = dateValue.split('-');
	return new Date(dateArray[2], dateArray[1],dateArray[0]);
}