/***********************************************
* jQuery functions execute
***********************************************/

jQuery(document).ready(function(){                  
              
	/*cmx form */
	if(jQuery.browser.mozilla) {
		$('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
                          	var $labelContent = $(this).html();
                                       var $labelWidth = $(this).css('width');
                                       $(this).empty();
                                       $(this).append('<span style="display: block; width: '+$labelWidth+';">');
                                       $(this).prepend('</span>');
                                       $(this).css('display', '-moz-inline-box');
                                       $(this).find('span').html($labelContent);
                                       $('form.cmxform').show();
                                });
                };             

	$('#tbArrival').datePicker({clickInput:true, dateFormat: 'dd/mm/yyyy'}).val(new Date().asString()).trigger('change');
	
	/*non CSS2.1*/
	$('body').css('overflow-x', 'hidden');
	/*external link*/
	$('a[rel*=external]').click( function(){this.target = "_blank";});
	$("form.popup").attr("target","_blank");
	/*slimbox*/
	$('#lbOverlay, input.checknow, #booking-form img').css('cursor', 'pointer');
	/*image link*/	
	$("#logo").css('cursor', 'pointer').click( function() { window.location = './';});
	/*email protect*/
	/*homepage form apha*/
	$('.booking-form-bg').css('opacity', '0.77');
	$('.booking-form-client-btn').css('opacity', '0.77');
	$("span.safermailing").each(function(){
		exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
		match = exp.exec($(this).text());
		addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
		link = match[2] ? match[2] : addr;
		subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
		$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
		$(this).remove();
	});
	
	/*ie6 dropdown fix*/
	$('ul#nav li').hover(function() {$(this).addClass('over');}, function() {$(this).removeClass('over');});
	$('ul#nav ul').hover(function() {$('.over a').addClass('onsection');}, function() {$('.over a').removeClass('onsection');});
	
	/*set hover class for anything*/
	$('a.send').hover(function() {$(this).addClass('hover');}, function() {$(this).removeClass('hover');});
	$('input.submit').css('cursor', 'pointer');
	$('form.cmxform input.send').css('cursor', 'pointer').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('#sitemap').hide();
	$('#sitemap').css('opacity', '0.75');
	$('a#navsitemap').click(function() {$('#sitemap').slideToggle('slow'); $('a#navsitemap').addClass('navsitemaphover');});
	$('a#cbut').click(function() {$('#sitemap').fadeOut('fast'); $('a#navsitemap').removeClass('navsitemaphover');});
	
	/*homepage ctas*/
	//hide buton when click
	$('a#cta-events').click(function() {$('a#cta-events').css('opacity', '0'); $('a#cta-gettingtorottnest, a#cta-signup, a#cta-specials').css('opacity', '1.0');});
	$('a#cta-gettingtorottnest').click(function() {$('a#cta-gettingtorottnest').css('opacity', '0'); $('a#cta-events, a#cta-signup, a#cta-specials').css('opacity', '1.0');});
	$('a#cta-signup').click(function() {$('a#cta-signup').css('opacity', '0'); $('a#cta-gettingtorottnest, a#cta-events, a#cta-specials').css('opacity', '1.0');});
	/*$('a#cta-specials').click(function() {$('a#cta-specials').css('opacity', '0'); $('a#cta-gettingtorottnest, a#cta-signup, a#cta-events').css('opacity', '1.0');});*/
	
	$('.cta-hidden-contents').hide();
	$('a#cta-events').css('opacity', '0');
	$("#cta-events-content").show();
	$('a.cta-button').click(function() {
		var category = $(this).attr('href');
		$('.cta-hidden-contents').fadeOut('fast');
		$(category).fadeIn('slow');
		return false;
	});
	
	/*aboutus page ctas*/
	$('a#cta-facts').click(function() {$('a#cta-facts').fadeOut('fast');});
	$('a#cta-facts').hide();
	$('a#cta-facts').click(function() {$('#fast-facts').fadeIn('slow'); return false;});
	$('a#cta-facts-close').click(function() {$('#fast-facts').fadeOut('fast'); $('a#cta-facts').fadeIn('fast');});
	
	/*inline enquiry form*/
	$('#inline-form').hide();
	$('a#navemailus').click(function() {$('#inline-form').slideDown('fast'); return false;});
	$('a#btn-close-email').click(function() {$('#inline-form').slideUp('fast'); return false;});
	
	/*dimming images on hover*/
	$('.form-overlay').css('opacity', '0.80');
	$('.dimmer, #partners-logo li').css('opacity', '0.55').css('cursor', 'pointer');
	$('.dimmer').hover(function() {$(this).css('opacity', '1.0');}, function() {$(this).css('opacity', '0.55');});
	$('#partners-logo li').hover(function() {$(this).css('opacity', '1.0');}, function() {$(this).css('opacity', '0.55');});
	
	/*listing room*/
	$('ul#room-listings li').css('cursor', 'pointer').click(function(){window.location = $(this).find('a').attr("href");});
	
	/*accomodation book now button*/
	//$('.booking-form-bg2').hide();
	//$('body#accomodation-page a#booknow').click(function(){$('.booking-form-bg2').fadeIn('fast').delay(2000).fadeOut(2000);});
	
	/*simple hide and show*/
	
	$('ul.bar_menu li> ul').hide();
	$('ul.bar_menu li> h2').css('cursor', 'pointer').click(function() {$(this).next('ul').slideDown('fast').parent().siblings('li').find('ul:visible').slideUp('fast');});
	$('ul.bar_menu li ul').click(function() {$(this).slideUp('fast');});
	$('ul.bar_menu li ul#food').show();
	
	$("#EnquiryForm, #ContactEnquiryForm").submit(function() {
      var s1 = 'reception';
      var s2 = '@';
      var s3 = 'hotelrottnest.com.au';
      $(this).append('<input type="hidden" name="recipient" value="' + s1 + s2 + s3 + '" />');
    });

});

/***********************************************
* Form fields Validation Script
***********************************************/

 function ValidateForm0(f){
	with(f){
		if (isEmpty(fullname.value)) {alert("Please enter your Full Name");fullname.focus();return false;}
		if (isEmpty(emailAddress.value)) {alert("Please enter your Email Address");emailAddressl.focus();return false;}
		if (!isEmail(emailAddress.value) ) {alert("Please enter a valid Email Address.");emailAddress.focus();return false;}
	}
	return true;
 }

function ValidateForm1(f){
	with(f){
		if (isEmpty(fullname.value)) {alert("Please enter your Full Name");fullname.focus();return false;}
		if (isEmpty(email.value)) {alert("Please enter your Email Address");email.focus();return false;}
		if (!isEmail(email.value) ) {alert("Please enter a valid Email Address.");email.focus();return false;}
		if (isEmpty(enquiries.value)) {alert("Please enter your Enquiry");enquiries.focus();return false;}
	}
	return true;
 }
 
 function ValidateForm2(f){
	with(f){
		if (isEmpty(fullname.value)) {alert("Please enter your Full Name");fullname.focus();return false;}
		if (isEmpty(email.value)) {alert("Please enter your Email Address");email.focus();return false;}
		if (!isEmail(email.value) ) {alert("Please enter a valid Email Address.");email.focus();return false;}
		if (isEmpty(phone.value)) {alert("Please enter your Contact No");phone.focus();return false;}
		if (isEmpty(enquiries.value)) {alert("Please enter your Enquiry");enquiries.focus();return false;}
	}
	return true;
 }
 
function ValidateForm3(f){
	with(f){
		if (isEmpty(fullname.value)) {alert("Please enter your Full Name");fullname.focus();return false;}
		if (isEmpty(email.value)) {alert("Please enter your Email Address");email.focus();return false;}
		if (!isEmail(email.value) ) {alert("Please enter a valid Email Address.");email.focus();return false;}
		if (isEmpty(enquiries.value)) {alert("Please enter your Comments");enquiries.focus();return false;}
	}
	return true;
 }
 
 function ValidateForm4(f){
	with(f){
		if (isEmpty(firstname.value)) {alert("Please enter your First Name");firstname.focus();return false;}
		if (isEmpty(lastname.value)) {alert("Please enter your Last Name");lastname.focus();return false;}
		if (isEmpty(phone_no.value)) {alert("Please enter your Contact No");phone_no.focus();return false;}
		if (isEmpty(your_email.value)) {alert("Please enter your Email Address");your_email.focus();return false;}
		if (!isEmail(your_email.value) ) {alert("Please enter a valid Email Address.");your_email.focus();return false;}
		if (isEmpty(your_address.value)) {alert("Please enter your Address");your_address.focus();return false;}
		if (isEmpty(suburb.value)) {alert("Please enter your Suburb");suburb.focus();return false;}
		if (isEmpty(state.value)) {alert("Please enter your State");state.focus();return false;}
		if (isEmpty(postcode.value)) {alert("Please enter your Postcode");postcode.focus();return false;}
	}
	return true;
 }
