////check availability
//function checkAvailability() {
//    var checkIn = $(".datepickerhome-checkin").datepicker('getDate');
//    var checkOut = $(".datepickerhome-checkout").datepicker('getDate');

//    var diff = checkOut - checkIn;
//    diff = diff / 86400000;
//    diff = Math.floor(diff);

//    var checkInDay = checkIn.getDate();
//    var checkInMonth = checkIn.getMonth() + 1;
//    var checkInYear = checkIn.getFullYear();
//    var formattedDate = checkInDay + '/' + checkInMonth + '/' + checkInYear;

//    var url = "http://www.resonline.com.au/Portal/V2/default.aspx?NumNights=" + diff + "&DisplayFrom=" + formattedDate + "&r=3&olt=3&CommodityTypeID=&view=1&DivisionID=487&refcode=";

//    window.open(url, 'resWindow', '');
//}

//custom static method
//can be used as string.Format(string,arg[]) command in C#
String.format = function() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

//custom enum-type
function EvenType() {
    this.AddType = "add";
    this.DelType = "del";
}

function SetMenu(obj, fixVal) {
    var iniWidth = 0;
    obj.find("ul").find("li").each(function() {
        iniWidth += $(this).width() + 40;
    });
    obj.find("ul").css("width", iniWidth);
    
    var baseLength = $("#nav > ul:first-child").offset().left;
    var currentLength = obj.offset().left;
    var relativeLength = currentLength - baseLength;
    var fullLength = $("#nav").width();
    var overLength = relativeLength + obj.find("ul").width() - fullLength;
    var fixLength = relativeLength - overLength;
    obj.addClass("initial");


    obj.find("ul").css("left", overLength < 0 ? relativeLength : fixLength);
    if (fixLength != fixVal) { SetMenu(obj, fixLength); }
}

$(document).ready(function() {
    //add initial style to the menu items.
    $(".menu > li").each(function() {
        $(this).hover(
            function() {
                SetMenu($(this),null);
            },
            function() {
                $(this).removeClass("initial");
                $(this).find("ul").css("left", 0);
            });
    });

    //events page button(+/-) action.
    $(".eventAction").click(function() {
        var etEvent = new EvenType();

        var ID = $(this).attr("groupName");
        var imgAppPath = $(this).attr("src").replace(/icon\_.*\.png$/g, "");
        var blnUnselected = $(this).attr("src").match(/unselected/g);
        var imgClass = $(this).attr("id");
        var imgReverseClass = imgClass != etEvent.AddType ? etEvent.AddType : etEvent.DelType;

        if (!blnUnselected) {
            imgClass == etEvent.AddType ? $("#r_" + ID).slideDown("normal", false) : $("#r_" + ID).slideUp("normal", false);
        }

        $(this).attr("src", String.format(imgAppPath + "icon_{1}{0}.png", "_unselected", imgClass));
        $("img[id=" + imgReverseClass + "][groupName=" + ID + "]")
                .attr("src", String.format(imgAppPath + "icon_{1}{0}.png", "", imgReverseClass));
    });
    
    $('.bannerImages').cycle({
        timeout: 4000 
    });
    
    $("#rhsHomeSpecialOffers").cycle({
        timeout: 8000 
    });
    
    $("#rhsHomePackages").cycle({
        timeout: 8000 
    });
    
    //

	var height = $(".sidefooterimages").height() + 60;
	$("#content").css({ 'margin-bottom' : height });
	
	$("a.sidebar_colorbox").colorbox();
	$(".colorboximage").colorbox({maxWidth:'80%', maxHeight:'80%'});

	$("iframe").attr("frameborder","no");
	
	var dateIn = querySt("datein");
	var dateOut = querySt("dateout");
	
	if (dateIn != "" && dateOut != "")
	{
	    $("iframe").attr("frameborder","no");
	    $("iframe").attr("src", "http://www.seekom.com/accommodation/Property.php?op=1935&pid=2950&datein=" + dateIn + "&dateout=" + dateOut);
	}
    
});

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function registerNewsletter(name, email)
{
    var errorMsg = "";
    
    if (name == "")
    {
        errorMsg += "- Please enter your name\n";
    }
    
    if (email == "")
    {
        errorMsg += "- Please your email address\n";
    }
    
    if (errorMsg != "")
    {
        alert(errorMsg);
    }
    else
    {
    
        //CustomFields
	    var extraParams = "";

	    jQuery.ajax({ 
		    url: "http://www.hotelonlinemarketing.com.au/WebService/WebService.asmx/RegisterNewsletterExtra",
		    data: { email:email, password: "", mailinglistId: "29", extraInfo: extraParams },			
		    dataType: "jsonp"
	    });
    	
	    alert('Thanks for signing up to our newsletter');
	    
	}

}

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
    ft = gy[i].split("=");
    if (ft[0] == ji) {
    return ft[1];
    }
    }
}


function checkAvailability()
{
    var dateText =  $(".ddlMonths").val() + "-" + $(".ddlDays").val();
//    var dateInArray = dateText.split("-");
//    var checkIn =  new Date(dateInArray[0],(parseInt(dateInArray[1])-1),dateInArray[2]);
//    var checkOut = new Date();
//    checkOut.setDate(checkIn.getDate() + 3);
//    
//    var checkOutDay = checkIn.getDate();
//    var checkOutMonth = checkIn.getMonth()+1;
//    var checkOutYear = checkIn.getFullYear();
//    var formattedCheckOutDate = checkOutDay + '-' + checkOutMonth + '-' + checkOutYear;

    
    document.location = "/Accommodation/Reservations.aspx?datein=" + dateText + "&dateout=" + dateText;
    //window.open("https://www.thebookingbutton.com.au/public/reservation/PropertyOverview.do?channelCode=COOGEESHADIRECT&dateFrom=" + $(".ddlMonths").val() + "-" + $(".ddlDays").val());
     
     
}