sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
$(document).ready(function(){
	$(function(){$('#more-info-tabs').tabs();});
    $("table tbody tr td:nth-child(even)").addClass("alt");
    $("#sidebar ul li.top-ten ol li:nth-child(odd)").addClass("alt");
  
    //JQueryCycle
    $('#small-slideshow .pictures').cycle({
    fx:     'fade', 
    speed:  'fast', 
    timeout: 0, 
    pager:  '#slide-nav' 
});

    //JQueryCycle
    $('#offers-cycle .ads').cycle({ 
    fx:     'scrollUp', 
    speed:  1000, 
    timeout: 15000
});
    

$('#footer .form-container').hide(); 
$('#search-results #content table.availability').hide();
$('a.toggle-av').click(function() {
$('#search-results #content table.availability').slideToggle(400);
$('a.toggle-av span').css ({'background-position': 'left top'});
	return false;
});

$('#content .full-entry').hide();
$('a.read-more').click(function() {
$('#content .full-entry').slideToggle(400);
 	return false;
});
  
$(function()
{
	//$('.date-picker').datePicker().val(new Date().asString()).trigger('change');
});
});



// when the DOM is ready...
$(document).ready(function () {

var $panels = $('#slider form > div');
var $container = $('#slider form');

// if false, we'll float all the panels left and fix the width 
// of the container
var horizontal = true;

// float the panels left if we're going horizontal
if (horizontal) {
  $panels.css({
    'float' : 'left',
    'position' : 'relative' // IE fix to ensure overflow is hidden
  });
  
  // calculate a new width for the container (so it holds all panels)
  //$container.css('width', $panels[0].offsetWidth * $panels.length);
}

// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $scroll = $('#slider .scroll').css('overflow', 'hidden');



// handle nav selection
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$('#slider #steps').find('a').click(selectNav);

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $('#slider #steps').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $('ul#steps a:first').click();
}

// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset.  Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $scroll, // the element that has the overflow
  
  // can be a selector which will be relative to the target
  items: $panels,
  
  navigation: '.navigation a',
  
  // selectors are NOT relative to document, i.e. make sure they're unique
  prev: 'img.left', 
  next: 'img.right',
  
  // allow the scroll effect to run both directions
  axis: 'xy',
  
  onAfter: trigger, // our final callback
  
  offset: offset,
  
  // duration of the sliding effect
  duration: 500,
  
  // easing - can be used with the easing plugin: 
  // http://gsgd.co.uk/sandbox/jquery/easing/
  easing: 'swing'
};

// apply serialScroll to the slider - we chose this plugin because it 
// supports// the indexed next and previous scroll along with hooking 
// in to our navigation.
//$('#slider').serialScroll(scrollOptions);

// now apply localScroll to hook any other arbitrary links to trigger 
// the effect
//$.localScroll(scrollOptions);

// finally, if the URL has a hash, move the slider in to position, 
// setting the duration to 1 because I don't want it to scroll in the
// very first page load.  We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
//scrollOptions.duration = 1;
//$.localScroll.hash(scrollOptions);

});

/* to open a page in popup*/
function popup(mypage, myname, w, h, scroll) {
	
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable, location=0';
	window.open(mypage, myname, winprops);
}

function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

function isImage(value){
	return (/(.*?)\.(gif|Gif|GIF|jpg|Jpg|JPG|jpeg|png|PNG)/.test(value));
}

function isPDF(value){
	return (/(.*?)\.(pdf|PDF|Pdf)/.test(value));
}

function isSwf(value){
	return (/(.*?)\.(swf|SWF|Swf)/.test(value));
}
function isAmount(value)
{
	return (/^\d+(\.\d{1,2})?$/.test(value));
}

// Removes leading and ending whitespaces
function trimboth( value ) {
	return LTrim(RTrim(value));
}
//return true if value is alphnumeric
function isAlphanumeric(value)	{
	return (/^[A-Za-z0-9 ]+$/.test(value));
}
//return true if value is alphabets
function isAlphabets(value)	{
	return (/^[A-Za-z ]+$/.test(value));
}

//return true if value is phone number
function isPhone(value){
	return (/^[0-9\s+\(\)]+$/.test(value));
}

//return true if value is number
function isNumeric(value){
	return (/^[0-9\.+-]+$/.test(value));
}

// this function validate currency format
function isCurrency (val) {
	str = trimboth(val);
	return (/^\d+(\.\d{1,2})?$/.test(str));
	//return (/^[0-9]+\.?[0-9][0-9]$/.test(str));
    //return /^\$?[1-9][0-9]{0,5}(,[0-9]{3})*(\.[0-9]{2})?$/.test(str);
}


//to validate an email address
function validEmail(obj)
{
	var str=obj.value;
	var a;
	var len=str.length;
	var reg=new RegExp("@");
	var ind=str.search(reg);
	
	var c,d=0;
	var b=0;
	for(a=0;a<=str.length;a++)
	{
		if(str.charAt(a)=="@")
		{
			b++;
		}
	}

	if(b>1)
	{
		alert("You need to provide a valid email address.");
		obj.focus();
		return false;
	}
	else
	{
		for(a=0;a<=str.length;a++)
		{
			if(str.charAt(a)==".")
			{
				d=a;
			}
		}
		if((ind>d)||(ind==-1)||(d==0)||(ind+1==d)||(d+1==len) || (str.indexOf(" ")!=-1) )
		{
			alert ("You need to provide a valid email address.");
			obj.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
}//function end vaild enmail
	
//validate DateRange User for room.php
function validateDateRange(objForm){
	var numChk = objForm.chkBookingDate.length;
	var endDate = "";//objForm.endDate.value;
	var intPreId = 0;
	var intIdsDiff = 0;
	var arrIds = new Array();
	var chkFlag = 0;
	for( intIndex=0; intIndex < numChk; intIndex++ ) {		
		if( objForm.chkBookingDate[intIndex].checked){			
			if(chkFlag == 0){
				if(endDate != ""){
					if(objForm.chkBookingDate[intIndex].value != endDate){
						alert("You must choose continuous dates.");
						objForm.chkBookingDate[intIndex].checked = false;
						totalPrice(objForm);
						return false;
					}
				}
				chkFlag = 1;
			}else{
				intPreId = intIndex-1;				
				if(objForm.chkBookingDate[intPreId].checked == false){
					//objForm.chkBookingDate[intIndex].checked = false;
					alert("You must choose continuous dates.");
					return false;
				}
			}
		}//end if
	}//end for
	totalPrice(objForm);
}//end validateDateRange

function checkRoomPay(objForm){
	//check checkbox has selected
	var numChk = objForm.chkBookingDate.length;
	var mybidprice=objForm.mybidprice.value;
	var full_price = objForm.full_price.value;
	var chkFlag = 0;
	if(mybidprice < full_price * 0.2 )
	{
		alert("A mininum of 20% of the full rate needs to be submited!");
		return false;
	}
	for( intIndex=0; intIndex < numChk; intIndex++ ) 
	{
		if(objForm.chkBookingDate[intIndex].checked)
		{
			chkFlag=1;
			break;
		}
	}
	if(chkFlag == 0){
		alert("Please select booking date!");
		return false;
	}
	//check mybidprice is not null
	
	if(isAmount(trimboth(mybidprice))){
		objForm.submit();
	}else{
		alert("Please input numbers!");
	}
	return false;
}
function totalPrice(objForm){
	var fullPrice=$("#full_price").val();
	var roomId = $("#room_id").val();
	
	var numChk = objForm.chkBookingDate.length;
	var checkIn="";
	var chkFlag = 0;
	var count=0;
	for( intIndex=0; intIndex < numChk; intIndex++ ) {
		if(objForm.chkBookingDate[intIndex].checked){
			if(chkFlag==0){
				checkIn=objForm.chkBookingDate[intIndex].value;
				chkFlag=1;
			}
			count++;
		}
	}
	$.ajax({
		url: 'ajax.php',
	    type: 'post',
	    data:"&fullPrice="+fullPrice+"&count="+count+"&check_date="+checkIn+"&task=total_price"+"&roomId="+roomId,
	    error: function(msg){
	        $("#total").html(msg);
	    },
	    success: function(html){
	    	$("#total").html(html);
	    },
	    beforeSend: function()
	    {
	    	$("#total").html('waiting...');
	    }
	});	
}

/**
** check payment form, used for payment.php
**/
function checkPaymentForm(form, cYear, cMonth){
	//adults
	if(parseInt(trimboth(form.txtAdults.value)) == 0) {
		alert("Please select Adults.");
		form.txtAdults.focus();
		return false;
	}
	if(form.arrival_hour.value == "hour") {
		alert("Please arrival hour.");
		form.arrival_hour.focus();
		return false;
	}
	//arrival date
	if(trimboth(form.arrival_date.value) == "" ) {
		alert("Please enter Arrive Date.");
		form.arrival_date.focus();
		return false;
	}
	//first name
	if(trimboth(form.firstName.value) == "" ) {
		alert("Please enter first name.");
		form.firstName.focus();
		return false;
	}else if(!isAlphabets(form.firstName.value)) {
		alert("This is not valid first name.");
		form.firstName.focus();
		return false;
	}	
	//last name
	if(trimboth(form.lastName.value) == "" ) {
		alert("Please enter last name.");
		form.lastName.focus();
		return false;
	}else if(!isAlphabets(form.lastName.value)) {
		alert("This is not valid last name.");
		form.lastName.focus();
		return false;
	}
	
	if(!validateEmail(form.emailAddress.value))
	{
		alert("This is not valid email address.");
		form.emailAddress.focus();
		return false;
	}
	//password
	if(form.password.value.length < 8) {
		alert("Mininum of 8 characters in length");
		form.password.focus();
		return false;
	}
	if(form.password.value != form.repassword.value) {
		alert("Password and Re-password are different");
		form.repassword.focus();
		return false;
	}
	//address
	if(trimboth(form.address.value) == "" ) {
		alert("Please enter address.");
		form.address.focus();
		return false;
	}
	//suburb city
	if(trimboth(form.suburb.value) == "" ) {
		alert("Please enter city.");
		form.suburb.focus();
		return false;
	}else if(!isAlphabets(form.suburb.value)) {
		alert("This is not valid city.");
		form.suburb.focus();
		return false;
	}
	//state
	if(trimboth(form.state.value) == "" ) {
		alert("Please enter state.");
		form.state.focus();
		return false;
	}else if(!isAlphabets(form.state.value)) {
		alert("This is not valid state.");
		form.state.focus();
		return false;
	}
	//country
	if(trimboth(form.country.value) == 0 ) {
		alert("Please select Country Name.");
		form.country.focus();
		return false;
	}
	//phone
	if(trimboth(form.phoneNumber.value) == "" ) {
		alert("Please enter Phone Number.");
		form.phoneNumber.focus();
		return false;
	}else if(!isPhone(form.phoneNumber.value)) {
		alert("This is not valid Phone Number.");
		form.phoneNumber.focus();
		return false;
	}
	//mobile
	if(trimboth(form.mobileNumber.value) != "" ) {
		if(!isPhone((form.mobileNumber.value))) {
			alert("This is not valid Mobile Number.");
			form.mobileNumber.focus();
			return false;
		}
	}
	
	if(!form.cancel_cond.checked || !form.terms_cond.checked){
		alert("Sorry,but you can't go on unless you agree to the top 2 boxes.");
		return false;
	}
	//card validate
	if(form.cardType.value == ''){
		alert("Please select Card Type.");
		form.cardType.focus();
		return false;
	}
	
	if(form.cardNumber.value == ""){
		alert("Please enter Card Number.");
		form.cardNumber.focus();
		return false;
	}else if(!isNumeric(form.cardNumber.value)){
		alert("This is not valid Card Number.");
		form.cardNumber.focus();
		return false;
	}
	
	if(form.cardNumber.value != ""){
		cardLength = form.cardNumber.value.length;
		if(cardLength <16){
			alert("This is not valid Card Number.");
			form.cardNumber.focus();
			return false;
		}
	}
	if(form.cardHolder.value == ''){
		alert("Please enter Card Holder Name.");
		form.cardHolder.focus();
		return false;
	}else if(!isAlphabets(form.cardHolder.value)){
		alert("This is not a valid Card Holder Name.");
		form.cardHolder.focus();
		return false;
	}
	
	if(form.cvvNumber.value == ''){
		alert("Please enter CVV Number.");
		form.cvvNumber.focus();
		return false;
	}
	
	if(form.expiryMon.value == ''){
		alert("Please select Expiry Month.");
		form.expiryMon.focus();
		return false;
	}
	
	if(form.expiryYear.value == ''){
		alert("Please select Expiry Year.");
		form.expiryYear.focus();
		return false;
	}
	
	if(cYear > form.expiryYear.value){
		alert("Card Expiry Year must be greater than current year.");
		form.expiryYear.focus();
		return false;
	}else if(cYear == form.expiryYear.value){		
		if(cMonth > form.expiryMon.value){
			alert("Card Expiry Month must be greater than current month.");
			form.expiryYear.focus();
			return false;
		}
	}
	
	if(form.confirm_code.value == "")
	{
		alert("Please input confirm code!");
		form.confirm_code.focus();
		return false;
	}
	
	return true;	
}

function validateEmail(elementValue)
{  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue);
}  

//check mail
function checkMail(form_id){
	var form=document.getElementById(form_id);
	if(!form){
		return false;
	}
	var firstName=form.first_name.value;
	if(firstName=="" || firstName=="Your First Name"){
		alert("Please enter first name");
		return false;
	}
	
	var lastName=form.last_name.value;
	if(lastName=="" || lastName=="Your Last Name"){
		alert("Please enter last name");
		return false;
	}
	
	var address=form.address.value;
	if(address=="Your Address"){
		form.address.value ="";
	}
	
	var email=trimboth(form.email.value);
	if(email=="" || email=="Your Email Address"){
		alert("Please enter email");
		return false;
	}
	if(validEmail(form.email)==false){
		return false;
	}
	
	var enquiry =form.enquiry.value;
	if(enquiry=="Your Enquiry" || enquiry==""){
		alert("Please enter enquiry");
		return false;
	}	

	return true;
}
