
function debug(l,a){
    $("#debug").append(l+":"+a+"<br />");
}

function toggleAdvancedSearch(){
    $(".search .advanced").slideToggle("slow");
}

function removeRoom(roomNumber){
    $(".search .searchWidgetHotelRoom").map(function(){
        num = $(this).attr('id').match(/[0-9]$/);
        if(num < roomNumber){return;}
        nnum = num*1+1;
        if(num != 1 && (num == 8 || $("#numberOfAdultsRoom"+nnum).val() == 0)){
            $("#numberOfAdultsRoom"+num).val(0);
            $("#numberOfChildrenRoom"+num).val(0);
            $(".childAgesRoom"+num).map(function(){
                $(this).val(0);
            });
            $(this).slideUp("slow",function(){
                var roomCount = 0;
                $(".search .searchWidgetHotelRoom").map(function(){
                    roomCount += ($(this).css("display") == "block") ? 1 : 0;
                });
                if(roomCount == 1){
                    $(".search .searchWidgetHotelRoom:first .remove").slideUp();
                }
            });
        }else{
            $("#numberOfAdultsRoom"+num).val($("#numberOfAdultsRoom"+nnum).val());
            $("#numberOfChildrenRoom"+num).val($("#numberOfChildrenRoom"+nnum).val());
            $(".childAgesRoom"+num).map(function(){
                p = $(this).attr('id').match(/[0-9]$/);
                $(this).val($("#childAgesRoom"+(num*1+1)+"Child"+p).val());
            });
        }
    });
}

function addRoom(){
    var roomnum = 0;
    $(".search .searchWidgetHotelRoom").map(function(){
        num = $(this).attr('id').match(/[0-9]$/);
        val = $("#numberOfAdultsRoom"+num).val();
        if(num > 1 && val == 0){
            pval = $("#numberOfAdultsRoom"+(num-1)).val();
            if(pval > 0){
                $(this).slideDown("slow");
                roomnum = num;
            }
        }
    });
    if(roomnum == 0){
        window.location.href = 'http://groups.roomstays.com/GroupForm.cfm';
    }
    $("#numberOfAdultsRoom"+roomnum).val(2);
    $(".search .searchWidgetHotelRoom:first .remove").slideDown();
}
function adjustChildren(select){
    var num = $(select).val();
    $(select).parent().siblings(".ages").children(".age").map(function(){
        var id = $(this).children("select").attr("id").match(/([0-9])$/)[1];
        if(id > num){
            $(this).css("display","none");
            $(this).children("select").val(0);
        }else{
            $(this).css("display","inline-block");
        }
    });
}

function toggleTaxesAndFeesPop(){
    $("#taxesandfeespop").toggle();
}

function toggleBubble(obj){
    $(obj).toggleClass("closed").siblings(".collapse").slideToggle("slow");
}

function toggleConfirmCancel(conf,action){
    if(action == "confirm"){
        $("#bookingcancel"+conf).css("display","none");
        $("#bookingconfirm"+conf).css("display","block");
    }else{
        $("#bookingcancel"+conf).css("display","inline");
        $("#bookingconfirm"+conf).css("display","none");
    }
}

function toggleSendConfirmationEmails(){
    var show = $("form.resend").css('display');
    if(show == "none"){
        $("form.resend").css("display","block");
        $("div.resend").css("display","none");
    }else{
        $("form.resend").css("display","none");
        $("div.resend").css("display","block");
    }
}

$(document).ready(function(){

    $('div.resend,form.resend a.cancel').click(function(){
        toggleSendConfirmationEmails();
        return false;
    });

    $('div.country_row h3 a').click(function() {
        $(this).parent().toggleClass('active');
        $(this).parent().next().slideToggle(300);
        return false;
    });

    $('div.country_row h3 a').eq(0).trigger('click');
    $(".bubble h4").bind('click',function(){
        $(this).toggleClass("closed").siblings(".collapse").slideToggle("slow");
    });
    $("#sortorder").bind('change',function(){
        var url = window.location.toString();
        url = url.replace(/sortOrder\=[0-9]/,"sortOrder="+$(this).val());
        url = url.replace(/page[0-9]+/,"page1",url);
        if(url.match(/sortOrder/)){
            window.location = url;
        }else{
            window.location = url+"&sortOrder="+$(this).val();
        }
    });
    $(".numberOfChildren").map(function(){
        adjustChildren(this);
    });
    $("#destination").parents("form").bind("submit",function(){return wlist.submit;});
    $("form.search").append("<div id='destinationList'></div>").append("<div id='hotelNameList'></div>");
    $("#destinationList").offset($("#destination").offset());
    $("#hotelNameList").offset($("#hotelName").offset());
    $("#destination").bind("blur",function(){
        $("#destinationList").slideUp();
        wlist.submit = true;
    });
    $("#hotelName").bind("blur",function(){
        $("#hotelNameList").slideUp();
        hlist.submit = true;
    });
    $("#destination").bind("focus",function(){
        var co = $(this).offset();
        co.top = Math.ceil(co.top+$(this).outerHeight()*1-1);
        co.left = Math.ceil(co.left+$(this).css("border-width")*1);
        $("#destinationList").slideDown();
        $("#destinationList").offset(co).width($(this).outerWidth());
        wlist.submit = false;
    });
    $("#hotelName").bind("focus",function(){
        var co = $(this).offset();
        co.top = Math.ceil(co.top+$(this).outerHeight()*1-1);
        co.left = Math.ceil(co.left+$(this).css("border-width")*1);
        $("#hotelNameList").slideDown();
        $("#hotelNameList").offset(co).width($(this).outerWidth());
        hlist.submit = false;
    });
    var wlist = {
        page: 0,
        submit: true,
        data: {},
        up: function(){
            if(this.page > 0){
                this.page--;
            }
        },
        down: function(){
            if(this.page < this.data.length){
                this.page++;
            }
        },
        set: function(d){
            if(d.typeOf == 'object'){
                this.data = d;
            }else{
                this.data = eval(d);
            }
        },
        get: function(){
            if(!this.data[0]){
                return "<ul><li><a>No Results</a></li></ul>";
            }
            var html = "<ul>";
            for(var i in this.data){
                var selected = "";
                var oddeven = (i%2 == 0) ? 'even' : 'odd';
                if(i == (this.page-1)){
                    selected = "selected";
                }
                html += "<li onmouseover='insertWList(\""+this.data[i].destination+"\",\""+this.data[i].destinationId+"\");' class='wlistli "+selected+' '+oddeven+"'><a href='javascript:void(0);' onclick='insertWList(\""+this.data[i].destination+"\",\""+this.data[i].destinationId+"\");'>"+this.data[i].destination+"</a></li>";
            }
            html+="</ul>";
            return html;
        },
        setpage: function(i){
            $("#destination").val(this.data[i].destination);
            $("#destinationId").val(this.data[i].destinationId);
        },
        action: function(){
            if(this.page == 0){ // submit
                this.submit = true;
                $("#destination").parents("form").submit();
            }else{ // insert
                $("#destination").val(this.data[(this.page-1)].destination);
                $("#destinationId").val(this.data[(this.page-1)].destinationId);
                this.page = 0;
            }
        }
    }

    var hlist = {
        page: 0,
        submit: true,
        data: {},
        up: function(){
            if(this.page > 0){
                this.page--;
            }
        },
        down: function(){
            if(this.page < this.data.length){
                this.page++;
            }
        },
        set: function(d){
            if(d.typeOf == 'object'){
                this.data = d;
            }else{
                this.data = eval(d);
            }
        },
        get: function(){
            if(!this.data[0]){
                return "<ul><li><a>No Results</a></li></ul>";
            }
            var html = "<ul>";
            for(var i in this.data){
                var selected = "";
                var oddeven = (i%2 == 0) ? 'even' : 'odd';
                if(i == (this.page-1)){
                    selected = "selected";
                }
                html += "<li onmouseover='insertHList(\""+this.data[i].chain+"\");' class='hlistli "+selected+' '+oddeven+"'><a href='javascript:void(0);' onclick='insertHList(\""+this.data[i].chain+"\");'>"+this.data[i].chain+"</a></li>";
            }
            html+="</ul>";
            return html;
        },
        setpage: function(i){
            $("#hotelName").val(this.data[i].chain);
        },
        action: function(){
            $("#hotelName").val(this.data[(this.page-1)].chain);
            this.page = 0;
        }
    }
    $("#destination").bind("keyup",function(e){
        switch(e.keyCode){
            case 27: // esc
                $("#destinationList").slideUp();
                wlist.submit = true;
                return;
                break;
            case 38: // up
                wlist.up();
                break;
            case 40: // down
                wlist.down();
                break;
            case 13: // enter
                $("#destinationList").slideUp();
                wlist.submit = true;
                wlist.action();
                break;
            default:
                wlist.page = 0;
                if(this.value != ""){
                    $.get('/search/destinations/'+this.value,function(data){
                        wlist.set(data);
                        $("#destinationList").html(wlist.get());
                    });
                }else{
                    wlist.set({});
                    $("#destinationList").html(wlist.get());
                }
        }
        $("#destinationList").html(wlist.get());
    });
    $("#hotelName").bind("keyup",function(e){
        return;
        switch(e.keyCode){
            case 27: // esc
                $("#hotelNameList").slideUp();
                hlist.submit = true;
                return;
                break;
            case 38: // up
                hlist.up();
                break;
            case 40: // down
                hlist.down();
                break;
            case 13: // enter
                $("#hotelNameList").slideUp();
                hlist.submit = true;
                hlist.action();
                break;
            default:
                hlist.page = 0;
                if(this.value != ""){
                    $.get('/search/hotelnames/'+this.value,function(data){
                        hlist.set(data);
                        $("#hotelNameList").html(hlist.get());
                    });
                }else{
                    hlist.set({});
                    $("#hotelNameList").html(hlist.get());
                }
        }
        $("#hotelNameList").html(hlist.get());
    });

});

function getLocationInfo(state,country){
    var cname = "";
    switch(country){
        case "US":cname="US";break;
        case "CA":cname="Canada";break;
        case "ZZ":cname="International";break;
    }
    $("#"+cname+" li").map(function(){
        var a = jQuery("a",this);
        if(a.html() == state){
            $(this).addClass("active");
        }else{
            $(this).removeClass("active");
        }
    });
    $.get('/locations/?state='+state+'&country='+country+'&ajax=1',function(data){
        $("#location"+country).html(data);
        $("#location"+country).css("background-color","#185D9B").animate({backgroundColor:"#f2f2f2"},1000);
        $("#location"+country+" > h4").css("color","#fff").animate({color:"#185D9B"},2000);
    });
    $.get('/locations/?state='+state+'&country='+country+'&all=1&ajax=1',function(data){
        $("#location"+country+"All").html(data);
        $("#location"+country+"All").css("background-color","#185D9B").animate({backgroundColor:"#f2f2f2"},1000);
        $("#location"+country+"All > h4").css("color","#fff").animate({color:"#185D9B"},2000);
    });
}

function addEmail(){
    $("#additionalEmails").append($("#additionalEmailsExample").html());
}

function insertWList(dest,id){
    $("#destination").val(dest);
    $("#destinationId").val(id);
}
function insertHList(dest){
    $("#hotelName").val(dest);
}

function toggleChildren(obj,select){
    $(obj).toggleClass("closed");
    $(obj).siblings(select).slideToggle();
}

$(document).ready(function(){
    $('#CVCImage').parent().css('position','relative');
    $('form[name=deals] input[name=name]')
        .bind("focus",function(){toggleNewsletterText(this,"enter your full name here...");})
        .bind("blur",function(){toggleNewsletterText(this,"enter your full name here...");});
    $('form[name=deals] input[name=email]')
        .bind("focus",function(){toggleNewsletterText(this,"enter your email here...");})
        .bind("blur",function(){toggleNewsletterText(this,"enter your email here...");});
    $('input').attr("autocomplete","off");
    $('#arrivalDate').datepicker({minDate:"+1d",numberOfMonths:2,buttonImage:"/images/calendar.png",showOn:'both',buttonImageOnly:true});
    $('#departureDate').datepicker({minDate:"+2d",numberOfMonths:2,buttonImage:"/images/calendar.png",showOn:'both',buttonImageOnly:true});
    $('#arrivalDate').bind('change',function(){
        var dep = $('#departureDate').val();
        if(dep == "" || 1==1){
            var arr = new Date($(this).val());
            var depp = new Date((arr.getMonth()+1)+"/"+(arr.getDate()+2)+"/"+arr.getFullYear());
            $('#departureDate').val(depp.getMonth()+1+"/"+depp.getDate()+"/"+depp.getFullYear());
        }
    });
    $('#advancedLink').bind('click',function(){
        $(this).siblings('.advanced').slideToggle();
    });
        $("#overviewHeader").css("cursor","pointer").append("<sub></sub>");
        $("#ratesHeader").css("cursor","pointer").append("<sub></sub>");
        $("#reviewsHeader").css("cursor","pointer").append("<sub></sub>");
    if(window.location.href.match(/hotel\/[0-9]+\//) && 1==2){
        var hotelId = window.location.href.match(/hotel\/([0-9]+)\//)[1];
        var queryString = window.location.search.substring(1);

        $("h2.head.slide a").attr("href","javascript:void(0);");
        $("#overviewHeader").bind("click",function(){
            if($("#overviewContent").html().length == 0){
                $("#ratesContent").slideUp("fast");
                $("#reviewsContent").slideUp("fast");
                $("#overviewContent").html("Loading...");
                $.get('/hotel/'+hotelId+'/overview/?'+queryString+'&ajax=1',function(data){
                    $("#overviewContent").html(data).slideDown("slow",function(){$(this).removeClass("closed");});
                });
            }else{
                $("#ratesContent").slideUp("slow",function(){$("#ratesHeader").addClass("closed");});
                $("#reviewsContent").slideUp("slow",function(){$("#reviewsHeader").addClass("closed");});
                $("#overviewContent").slideDown("slow",function(){$(this).removeClass("closed");});
            }
        });

        $("#ratesHeader").bind("click",function(){
            if($("#ratesContent").html().length == 0){
                $("#overviewContent").slideUp("fast");
                $("#reviewsContent").slideUp("fast");
                $("#ratesContent").html("Loading...");
                $.get('/hotel/'+hotelId+'/rates/?'+queryString+'&ajax=1',function(data){
                    $("#ratesContent").html(data).slideDown("slow",function(){$(this).removeClass("closed");});
                });
            }else{
                $("#reviewsContent").slideUp("slow",function(){$("#reviewsHeader").addClass("closed");});
                $("#overviewContent").slideUp("slow",function(){$("#overviewHeader").addClass("closed");});
                $("#ratesContent").slideDown("slow",function(){$(this).removeClass("closed");});
            }
        });

        $("#reviewsHeader").bind("click",function(){
            if($("#reviewsContent").html().length == 0){
                $("#overviewContent").slideUp("fast");
                $("#ratesContent").slideUp("fast");
                $("#reviewsContent").html("Loading...");
                $.get('/hotel/'+hotelId+'/rates/?'+queryString+'&ajax=1',function(data){
                    $("#reviewsContent").html(data).slideDown("slow",function(){$(this).removeClass("closed");});
                });
            }else{
                $("#overviewContent").slideUp("slow",function(){$("#overviewHeader").addClass("closed");});
                $("#ratesContent").slideUp("slow",function(){$("#ratesHeader").addClass("closed");});
                $("#reviewsContent").slideDown("slow",function(){$(this).removeClass("closed");});
            }
        });
    }
});
function toggleWriteReview(){
    toggleOverlayContent("","writereview");
}
function toggleOverlayContent(html,cls){
    if($("#overlaycontent").css("display") == "block"){
        $("#overlaycontent").slideUp();
        $("#whiteout").slideUp();
    }else{
        $("#overlaycontent")
            .css("top",$(window).scrollTop()+50+"px")
            .css("width","900px")
            .css("left",($(window).width()-900)/2)
            .slideDown();
        $("#whiteout")
            .css("height",$(document).height())
            .css("width",$(document).width())
            .slideDown();
    }
}
function toggleNewsletterText(item,txt){
    if($(item).val() == txt){
        $(item).val("");
    }else if($(item).val() == ""){
        $(item).val(txt);
    }
}
function toggleCVC(){
    var d = document.getElementById('CVCImage');
    d.style.display = (d.style.display=='block') ? 'none' : 'block';
}
function showCVC(){
    document.getElementById('CVCImage').style.display='block';
}
function hideCVC(){
    document.getElementById('CVCImage').style.display='none';
}
function adjustBillingState(country){
    var us = document.getElementById('billingStateProvinceUS');
    var ca = document.getElementById('billingStateProvinceCA');
    var au = document.getElementById('billingStateProvinceAU');
    var container = us.parentNode.parentNode;
    us.value = "";
    ca.value = "";
    au.value = "";
    us.style.display = "none";
    ca.style.display = "none";
    au.style.display = "none";
    switch(country){
        case "AU":au.style.display = "block";break;
        case "CA":ca.style.display = "block";break;
        case "US":us.style.display = "block";break;
        default:container.style.display = "none";
    }
    if(country == 'AU' || country == 'US' || country == 'CA'){
       container.style.display = "block";
    }
    if(country == 'IE' || country == 'HK'){
        $("#billingPostalCode").parent().removeClass('error');
        $("ul.error_container.inline.postalcode").remove();
    }
    $("ul.error_container.inline.stateprovince").remove();
}
function resetReviewRating(){
    var rating = $("form[name='reviewform'] input[name='reviewRating']").val();
    if($("#reviewRating1").is("*")){
        if($("#reviewRating1").attr("checked")){
            rating = 1;
        }else if($("#reviewRating2").attr("checked")){
            rating = 2;
        }else if($("#reviewRating3").attr("checked")){
            rating = 3;
        }else if($("#reviewRating4").attr("checked")){
            rating = 4;
        }else if($("#reviewRating5").attr("checked")){
            rating = 5;
        }else{
            rating = -1;
        }
    }
    hoverReviewRating(parseInt(rating));
}
function hoverReviewRating(rating){
    $("form[name='reviewform'] .rating img").map(function(count){
        if(count < rating){
            $(this).attr('src','/common/images/star.jpg');
        }else{
            $(this).attr('src','/common/images/star2.jpg');
        }
    });
    var ratingtxt = '';
    switch(rating){
        case -1:
        default:
            ratingtxt = 'Select Rating';
            break;
        case 1:
            ratingtxt = 'Poor';
            break;
        case 2:
            ratingtxt = 'Below Average';
            break;
        case 3:
            ratingtxt = 'Average';
            break;
        case 4:
            ratingtxt = 'Very Good';
            break;
        case 5:
            ratingtxt = 'Excellent';
            break;
    }
    $("form[name='reviewform'] span.yourrating").html(ratingtxt);
}
function selectReviewRating(rating){
    hoverReviewRating(rating);
    if($("#reviewRating"+rating).is("*")){
        $("#reviewRating"+rating).attr("checked",true);
    }else{
        $("form[name='reviewform'] input[name='reviewRating']").val(rating);
    }
}
function gotoCal(){
    if($("#arrivalDate").val() != "" && $("#departureDate").val() != ""){
        document.forms['search'].submit();
    }else{
        $(window).scrollTo(".search",1000);
        $("#arrivalDate").focus();
    }
}

$(function() {
            $(".li_expand a.expand").toggler();
            
            $(".li_expand").expandAll({
              trigger: "a.expand", 
              ref: "a.expand", 
              showMethod: "slideDown", 
              hideMethod: "slideUp"
});


 $(".expended_div").bind('click',function(){
                    if($(this).hasClass('open')){
            
                        $(this).next().slideDown('slow');
                        $(this).removeClass('open');
                        $(this).addClass('close');
                        
                        }
                        else{
                            $(this).next().slideUp('slow');
                        $(this).removeClass('close');
                        $(this).addClass('open');
                            
                            }
                    return false;
                                        
});

});

var checkoutsubmitted = false;
$(document).ready(function(){
    $("#taxesandfeeslink,#taxesandfeespop a.close").bind('click',function(){
        toggleTaxesAndFeesPop();
        return false;
    });
    $("form.booking").bind('submit',function(){
        var result = !checkoutsubmitted;
        checkoutsubmitted = true;
        return result;
    });
    $("a.travelGuideSubmit").bind('click',function(){
        travelGuideSubmit();
    });
    $("select.travelGuideOption").bind('change',function(){
        travelGuideSubmit(this);
    });
    $("a.reviewFilterSubmit").live('click',function(){
        reviewFilterSubmit();
    });
    $("select.reviewFilterOption").live('change',function(){
        reviewFilterSubmit(this);
    });
    $("a.popularFilterSubmit").bind('click',function(){
        popularFilterSubmit();
    });
    $("select.popularFilterOption").bind('change',function(){
        popularFilterSubmit(this);
    });

    $(".tgacontriblink").bind('click',function(){
        var txt1 = "Make your own contribution";
        var txt2 = "Hide the contribution form";
        var form = $("section#customer_support_container .content.article .usercontribs .submitform");
        if($(this).text() == txt1){
            $(".tgacontriblink").text(txt2);
            form.css('display','block');
            $(document).scrollTop($("#guestcontribheader").offset().top);
        }else{
            $(".tgacontriblink").text(txt1);
            form.css('display','none');
        }
        return false;
    });
    $("#share_experience #countries").bind('change',function(){
        $.getJSON('/experience/region/country/'+$(this).val(), function(data){
            var sple = "#share_experience #stateProvinces-label,#share_experience #stateProvinces-element";
            var csle = "#share_experience #cities-label,#share_experience #cities-element";
            if(data.stateProvinces.length == 1 && data.stateProvinces[0] == ''){
                $(sple).css("display","none");
            }else{
                $(sple).css("display","");
                var sp = "#share_experience #stateProvinces";
                $(sp+" option").remove();
                $.each(data.stateProvinces, function(key,val){
                    $(sp).append("<option value='"+val+"'>"+val+"</option>");
                });
            }
            if(data.cities.length == 1 && data.cities[0] == ''){
                $(csle).css("display","none");
            }else{
                $(csle).css("display","");
                var cs = "#share_experience #cities";
                $(cs+" option").remove();
                $.each(data.cities, function(key,val){
                    $(cs).append("<option value='"+val+"'>"+val+"</option>");
                });
            }
        });
    });
    $("#share_experience #stateProvinces").bind('change',function(){
        $.getJSON('/experience/region/stateProvince/'+$(this).val(), function(data){
            $("#share_experience #countries").val(data.country);
            var csle = "#share_experience #cities-label,#share_experience #cities-element";
            if(data.cities.length == 1 && data.cities[0] == ''){
                $(csle).css("display","none");
            }else{
                $(csle).css("display","");
                var cs = "#share_experience #cities";
                $(cs+" option").remove();
                $.each(data.cities, function(key,val){
                    $(cs).append("<option value='"+val+"'>"+val+"</option>");
                });
            }
        });
    });
    $("#share_experience #cities").bind('change',function(){
        $.getJSON('/experience/region/city/'+$(this).val(), function(data){
            $("#share_experience #countries").val(data.country);
            $("#share_experience #stateProvinces").val(data.stateProvince);
        });
    });
});

var recentreview = {
    page : 1,
    url  : '/recentreview/',
    prev : function(obj){
            if(obj.href){
                this.url = obj.href;
                this.override = true;
            }
            if(this.page > 1){
                this.page--;
            }else{
                this.page = 1;
            }
            return this.get();
        },
    next : function(obj){
            if(obj.href){
                this.url = obj.href;
                this.override = true;
            }
            this.page++;
            return this.get();
        },
    turn : function(page, obj){
            if(obj.href){
                this.url = obj.href;
                this.override = true;
            }
            this.page = page;
            return this.get();
        },
    get  : function(){
            if(this.override){
                $.get(this.url + '?ajax=true', function(data){
                    $('#recent_reviews').replaceWith(data);
                });
            }else{
                $.get(this.url + this.page, function(data){
                    $('.hotelreview').not("#write_review").closest('.faq_contact').replaceWith(data);
                });
            }
            return false;
        }
}

function popularFilterSubmit(option){
    var tgp = "popularFilterOption";
    var urlbase = "/popular/";
    if(option){
        var type = $(option).attr("id").replace(tgp,"").toLowerCase();
        var region = $(option).val().replace(/\s/g,"_").toLowerCase();
        if(type == "perpage"){
            url = urlbase + $(option).val().toLowerCase() + "/1";
        }else if(region == "all"){
            if(type == "city" && region == "all"){
                type = "stateprovince";
                var newid = "#"+tgp+"StateProvince";
                if($(newid).length>0){
                    region = $(newid).val().replace(/\s/g,"_").toLowerCase();
                    url = urlbase + type + "/" + region;
                }
            }
            if(type == "stateprovince" && (region == "all" || region == "")){
                type = "country";
                region = $("#"+tgp+"Country").val().replace(/\s/g,"_").toLowerCase();
                url = urlbase + type + "/" + region;
            }
            if(type == "country" && (region == "all" || region == "")){
                url = urlbase;
            }
        }else{
            url = urlbase + type + "/" + region;
        }
        window.location.href = url.toLowerCase();
        return;
    }
    var perpage = 10;
    var perpagedefault = $("#" + tgp + "PerPageDefault").val();
    var city = $("#" + tgp + "City").val().replace(/\s/g,"_").toLowerCase();
    var url = "";
    if(!city || city == "all"){
        var state = $("#" + tgp + "StateProvince").val().toLowerCase();
        if(!state || state == "all"){
            var country = $("#" + tgp + "Country").val().toLowerCase();
            if(!country || country == "All"){
                url = urlbase;
            }else{
                url = urlbase + "country/" + country.replace(/\s/g,"_");
            }
        }else{
            url = urlbase + "stateprovince/" + state.replace(/\s/g,"_");
        }
    }else{
        url = urlbase + "city/" + city.replace(/\s/g,"_");
    }
    window.location.href = url.toLowerCase();
}

function reviewFilterSubmit(option){
    var tgp = "reviewFilterOption";
    var urlbase = "/hotelreview/recentreviews/";
    if(option){
        var type = $(option).attr("id").replace(tgp,"").toLowerCase();
        var region = $(option).val().replace(/\s/g,"_").toLowerCase();
        if(type == "perpage"){
            url = urlbase + $(option).val() + "/1";
        }else if(region == "All"){
            if(type == "city" && region == "All"){
                type = "stateprovince";
                var newid = "#"+tgp+"StateProvince";
                if($(newid).length>0){
                    region = $(newid).val().replace(/\s/g,"_");
                    url = urlbase + type + "/" + region;
                }
            }
            if(type == "stateprovince" && (region == "All" || region == "")){
                type = "country";
                region = $("#"+tgp+"Country").val().replace(/\s/g,"_");
                url = urlbase + type + "/" + region;
            }
            if(type == "country" && (region == "All" || region == "")){
                url = urlbase;
            }
        }else{
            url = urlbase + type + "/" + region;
        }
        window.location.href = url;
        return;
    }
    var perpage = 10;
    var perpagedefault = $("#" + tgp + "PerPageDefault").val();
    var city = $("#" + tgp + "City").val();
    var url = "";
    if(perpagedefault && perpage != perpagedefault){
        url = urlbase + perpage + "/1";
    }else if(!city || city == "All"){
        var state = $("#" + tgp + "StateProvince").val();
        if(!state || state == "All"){
            var country = $("#" + tgp + "Country").val();
            if(!country || country == "All"){
                url = urlbase;
            }else{
                url = urlbase + "country/" + country.replace(/\s/g,"_");
            }
        }else{
            url = urlbase + "stateprovince/" + state.replace(/\s/g,"_");
        }
    }else{
        url = urlbase + "city/" + city.replace(/\s/g,"_");
    }
    window.location.href = url.toLowerCase();
}

function travelGuideSubmit(option){
    var tgp = "travelGuideOption";
    var urlbase = "";
    if(window.location.pathname.match(/experience/)){
        urlbase = "/experience/";
    }else{
        urlbase = "/travelguide/";
    }
    if(option){
        //console.debug('option '+urlbase);
        var type = $(option).attr("id").replace(tgp,"").toLowerCase();
        var region = $(option).val().replace(/\s/g,"_");
        if(type == "perpage"){
            url = urlbase + $(option).val() + "/1";
        }else if(region == "All"){
            if(type == "city" && region == "All"){
                type = "stateprovince";
                var newid = "#"+tgp+"StateProvince";
                if($(newid).length>0){
                    region = $(newid).val().replace(/\s/g,"_");
                    url = urlbase + type + "/" + region;
                }
            }
            if(type == "stateprovince" && (region == "All" || region == "")){
                type = "country";
                region = $("#"+tgp+"Country").val().replace(/\s/g,"_");
                url = urlbase + type + "/" + region;
            }
            if(type == "country" && (region == "All" || region == "")){
                url = urlbase;
            }
        }else{
            url = urlbase + type + "/" + region;
        }
        //console.debug(url);return;
        window.location.href = url;
        return;
    }
    var perpage = $("#" + tgp + "PerPage").val();
    var perpagedefault = $("#" + tgp + "PerPageDefault").val();
    var city = $("#" + tgp + "City").val();
    var url = "";
    if(perpage != perpagedefault){
        url = urlbase + perpage + "/1";
    }else if(!city || city == "All"){
        var state = $("#" + tgp + "StateProvince").val();
        if(!state || state == "All"){
            var country = $("#" + tgp + "Country").val();
            if(!country || country == "All"){
                url = urlbase;
            }else{
                url = urlbase + "country/" + country.replace(/\s/g,"_");
            }
        }else{
            url = urlbase + "stateprovince/" + state.replace(/\s/g,"_");
        }
    }else{
        url = urlbase + "city/" + city.replace(/\s/g,"_");
    }
    window.location.href = url;
}

function advancedFormattingShowHide(){
    var container = document.getElementById("advanced-formatting-show-hide");
    if(container.style.display == 'none'){
        container.style.display = '';
    }else{
        container.style.display = 'none';
    }
    return false;
}

