var gMapWidth = 300;
var gMapHeight = 200;
var gMapURL = "";

function clearText(ele, txt) {
    if (ele.value == txt) {
        ele.value = "";
    }
}
function resumeText(ele, txt) {
    if (ele.value == "") {
        ele.value = txt;
    }
}
function clearTextArea(ele, txt) {
    if (ele.value == txt) {
        ele.childNodes[0].nodeValue = "";
    }
}
function resumeTextArea(ele, txt) {
    if (ele.value == "") {
        ele.childNodes[0].nodeValue = txt;
    }
}

function showTab(ele, total) {
    for (var i = 1; i <= total; i++) {
        document.getElementById("tab" + i + "_body").style.display = "none";
    }
    document.getElementById(ele.id + "_body").style.display = "block";
    if (ele.id == "tab1") {
        document.getElementById("tab_nav").style.backgroundPosition = '0px 0px';
    }
    if (ele.id == "tab2") {
        document.getElementById("tab_nav").style.backgroundPosition = '0px -37px';
    }
    if (ele.id == "tab3") {
        document.getElementById("tab_nav").style.backgroundPosition = '0px -74px';
    }
    ele.blur();
}
function showTab2(ele, total) {
    for (var i = 1; i <= total; i++) {
        document.getElementById("tab" + i + "_body").style.display = "none";
    }

    if (ele.id == "tab2") { LoadGoogleMap(); }
    document.getElementById(ele.id + "_body").style.display = "block";
    
    if (ele.id == "tab1") {
        document.getElementById("tab_nav").style.backgroundPosition = '0px -75px';
    }
    if (ele.id == "tab2") {
        document.getElementById("tab_nav").style.backgroundPosition = '0px -37px';
    }
    if (ele.id == "tab3") {
        document.getElementById("tab_nav").style.backgroundPosition = '-1px 1px';
    }
    ele.blur();
}

function showTab3(ele) {
    if (ele == "distance") {
        document.getElementById("tab_nav").style.backgroundPosition = '0 0';
    }
    if (ele == "price") {
        document.getElementById("tab_nav").style.backgroundPosition = '0 -38px';
    }
    if (ele == "recent") {
        document.getElementById("tab_nav").style.backgroundPosition = '0 -76px';
    }
}

function login_with_fb() {
    window.location.href = "/Account/Logon";
}

function facebook_prompt_permission(permission) {
    FB.ensureInit(function() {
        FB.Connect.showPermissionDialog(permission);
    });
}

$(document).ready(function() {
    $('.ExclusiveFreeRental').click(function() {

        checkedState = $(this).attr('checked');

        $('.ExclusiveFreeRental:checked').each(function() {
            $(this).attr('checked', false);
        });

        $(this).attr('checked', checkedState);
    });
    $('.ExclusiveCollectDeliver').click(function() {

        checkedState = $(this).attr('checked');

        $('.ExclusiveCollectDeliver:checked').each(function() {
            $(this).attr('checked', false);
        });

        $(this).attr('checked', checkedState);
    });
    $('.ExclusiveImageDefault').click(function() {

        checkedState = $(this).attr('checked');

        $('.ExclusiveImageDefault:checked').each(function() {
            $(this).attr('checked', false);
        });

        $(this).attr('checked', checkedState);
    });
});

function ResetImageDefaultExclusiveCheck() {
    $('.ExclusiveImageDefault').click(function() {

        checkedState = $(this).attr('checked');

        $('.ExclusiveImageDefault:checked').each(function() {
            $(this).attr('checked', false);
        });

        $(this).attr('checked', checkedState);
    });
}

function CheckItemsForDeletion(el) {
    $('.accountItemDelete').each(function() {
        $(this).attr('checked', $(el).attr('checked') );
    });
}

function CheckMessagesForDeletion(el) {
    $('.messageItemDelete').each(function() {
        $(this).attr('checked', $(el).attr('checked'));
    });
}

function DeleteProducts(all) {
    if (all == "0") {
        if (confirm('Are you sure you want to delete all the products selected?')) {
            $('#all').val('0');
            MarkForDeletion();
            return true;
        } else {
            return false;
        }
    } else {
        if (confirm('Are you sure you want to delete all the products listed?')) {
            $('#all').val('1');
            $('#chkDeleteAll').click();
            MarkForDeletion();
            return true;
        } else {
            return false;
        }
    }
}

function DeleteMessages(all) {
    if (all == "0") {
        if (confirm('Are you sure you want to delete all the message selected?')) {
            $('#allMessages').val('0');
            MarkMessagesForDeletion();
            return true;
        } else {
            return false;
        }
    } else {
        if (confirm('Are you sure you want to delete all the messages listed?')) {
            $('#allMessages').val('1');
            $('#chkDeleteAllMessages').click();
            MarkMessagesForDeletion();
            return true;
        } else {
            return false;
        }
    }
}

function MarkForDeletion() {
    $('delid').val();
    $('.accountItemDelete').each(function() {
        if ($(this).attr('checked') == true) {
            $('#delid').val($('#delid').val() + '-' + $(this).attr('value'));
        }
    });
}

function MarkMessagesForDeletion() {
    $('delMessagesid').val();
    $('.messageItemDelete').each(function() {
        if ($(this).attr('checked') == true) {
            $('#delMessagesid').val($('#delMessagesid').val() + '-' + $(this).attr('value'));
        }
    });
}
function SelectedEndDate(el, description, date) {
    $('#end_booking_selected').html('Booking request to ' + description);
    $('#bookingRequestEndDate').val(date);
    $('#bookingPostEndDate').val(date);
    SelectedEndDateToggle(el);

    if ($('#bookingRequestStartDate').val() != "") {
        $('#bookingCostSubmit').click();
        //$('#bookingCostForm').onsubmit();
    }
}
function SelectedStartDate(el, description, date) {
    $('#start_booking_selected').html('Booking request from ' + description);
    $('#bookingRequestStartDate').val(date);
    $('#bookingPostStartDate').val(date);
    SelectedStartDateToggle(el);

    if ($('#bookingRequestEndDate').val() != "") {
        $('#bookingCostSubmit').click();
        //$('#bookingCostForm').onsubmit();
    }
}

function SelectedAvailabilityEndDate(el, description, date) {

    $('#availabilityEndDate').val(date);

    SelectedEndDateToggle(el);

    if ($('#availabilityStartDate').val() != "") {
        $('#availabilitySubmit').click();
        //$('#bookingCostForm').onsubmit();
    }
}
function SelectedAvailabilityStartDate(el, description, date) {
    $('#availabilityStartDate').val(date);

    SelectedStartDateToggle(el);

    if ($('#availabilityEndDate').val() != "") {
        $('#availabilitySubmit').click();
        //$('#bookingCostForm').onsubmit();
    }
}

function ChangeSortOrder(order) {
    $('#sortOrder').val(order);
    $('#update').click();
}

function SelectedStartDateToggle(el) {
    $('.bookingStartDay').removeClass('selected');
    $(el).addClass('selected');
}
function SelectedEndDateToggle(el) {
    $('.bookingEndDay').removeClass('selected');
    $(el).addClass('selected');
}
function CheckLength(el, max, target, e) {
    if( $(el).val().length <= max){
        return true;
    } else
    {
        return false;
    }
}