function LoadJQuery() {

    $(document).ready(function() {

        $("#homefooter .accordionlink").click(
          function() {
              $(this).parent().nextAll().toggle('100');
          }
        );
        $("#homeintrocontent .accordionlink").click(
          function() {
              $(this).parent().nextAll().toggle('100');
          }
        );

        $("ul.CMSListMenuUL ul.CMSListMenuUL").slideUp('100');
        $("ul.CMSListMenuUL li").hover(
            function() {
                $(this).children("ul.CMSListMenuUL").slideDown('fast');
            },
            function() {
                $(this).children("ul.CMSListMenuUL").slideUp('fast');
            }
          );

        /**************** BEGIN HOME PAGE TABS ********************/
        $("#lnkfeaturedparks").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabFeaturedParks").show();
              $("#tabFeaturedParks div").show();
          }
        );

        $("#lnkfeaturedcaravans").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabFeaturedCaravans").show();
              $("#tabFeaturedCaravans div").show();
          }
        );

        $("#lnkparksoffers").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabParkOffers").show();
              $("#tabParkOffers div").show();
          }
        );

        $("#lnkcaravansoffers").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabCaravanOffers").show();
              $("#tabCaravanOffers div").show();
          }
        );

        $("#lnkmoveyourcaravan").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabMoveYourCaravan").show();
              $("#tabMoveYourCaravan div").show();
          }
        );

        $("#lnkmanufacturers").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabManufacturers").show();
              $("#tabManufacturers div").show();
          }
        );
        /**************** END HOME PAGE TABS ********************/

        /**************** BEGIN PARK DETAILS PAGE TABS ********************/
        $("#tabMap").hide();
        $("#lnkoverview").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabOverview").show();
              $("#tabOverview div").show();
          }
        );
        $("#lnkmap").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabMap").show();
              $("#tabMap div").show();
              $("#tabMap").css("visibility", "visible");
          }
        );
        $("#lnkcaravansforsale").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabCaravansForSale").show();
              $("#tabCaravansForSale div").show();
              $(".caravanpopup").hide();
          }
        );
        $("#lnkspecialoffers").click(
          function() {
              $("#tabsnav li").removeClass("selected");
              $(this).parent().addClass("selected");
              $("#tabdetails div").hide();
              $("#tabdetails div.clearboth").show();
              $("#tabSpecialOffers").show();
              $("#tabSpecialOffers div").show();
          }
        );
        /**************** END PARK DETAILS PAGE TABS ********************/

        $("#counties_map > area").hover(
          function(e) {
              var elementid = "map_" + this.title.toLowerCase().replace(/ /g, '');
              if (document.getElementById(elementid) != null) {
                  document.getElementById(elementid).style.display = 'block';
                  document.getElementById(elementid).style.top = (e.pageY - 122) + "px";
                  document.getElementById(elementid).style.left = (e.pageX - 85) + "px";
              }
          },
          function() {
              var elementid = "map_" + this.title.toLowerCase().replace(/ /g, '');
              if (document.getElementById(elementid) != null) {
                  document.getElementById(elementid).style.display = 'none';
              }
          }
        );

        $("#thumbnails > img").hover(
          function(e) {
              var imgurl = this.src.replace("119x119", "640x385");
              imgurl = imgurl.replace("sml", "");
              $("#parkdetailsleft .mainimage").attr("src", imgurl.replace("119X119", "640x385"));
              $("#thumbnails > img").css("border-color", "#fff");
              $(this).css("border-color", "#777");
          },
          function() {
          }
        );

        $(".colorbox").colorbox({ width: '775px', height: '700px', iframe: true });
        $(".caravanpopup img").hover(
          function(e) {
              var imgurl = this.src.replace("119x119", "640x385");
              imgurl = imgurl.replace("sml", "");
              $(".caravanpopup .caravanpopupenlarged").attr("src", imgurl.replace("119X119", "640x385"));
              $(".caravanpopup img").css("border-color", "#fff");
              $(this).css("border-color", "#777");
          },
          function() {
          }
        );


        $("#sortedtable").tablesorter({ sortList: [[3, 1], [2, 0]], widgets: ['zebra'] });
        $("#sortedadvertresultstable").tablesorter({ sortList: [[5, 1], [4, 0]], widgets: ['zebra'] });
        $("#uservanstable").tablesorter({ sortList: [[0, 0]], widgets: ['zebra'] });

        //$("#popup_form tr td span").parent().find("input").css("background-color", "#f9b5cb");
        $("#popup_form tr td span").parent().find("input").css("border", "1px solid #ec0303");
        $("#popup_form tr td span").css("display", "none");
        $("#popup_form tr td span.likeotherbrochures").parent().find("input").css("border", "none");
        $("#popup_form tr td span.likeotherbrochures").css("display", "inline");

        $("#ctl00_cntMain_bizSalesForm_ctl00_ParkID").prepend($("<option selected='true'></option>").attr("value", "0").text("Please select your caravan park..."));


        $("#ctl00_cntMain_bizSalesForm_ctl00_btnOK").click(
          function() {
              return submitSalesForm();
          }
        );
        $("roundrect").css("display", "none");
    });
}

LoadJQuery();


function goToPanel2() { 
    var sel_index = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_Location1').selectedIndex;
    var sel_val = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_Location1').options[sel_index].text;
    if (sel_val != '1st Choice') {
        document.getElementById('error_location').style.display = 'none';
        goToPanel(2);
    } else {
        document.getElementById('error_location').style.display = 'block';
        document.getElementById('error_location').innerHTML = 'Please select an option.';
    }
}

function goToPanel(inPanel) {
    document.getElementById('step1').style.display = 'none';
    document.getElementById('step2').style.display = 'none';
    document.getElementById('step3').style.display = 'none';
    document.getElementById('step' + inPanel).style.display = 'block';
}

$(document).ready(function() {
    var field = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_btnOK');
    if (field) {
        field.onclick = function() {
            var fname = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_FirstName').value;
            var sname = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_LastName').value;
            var postcode = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_Postcode').value;
            var address = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_Address').value;
            var town = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_Town').value;
            var tel = document.getElementById('ctl00_cntMain_bizEnquiryForm_ctl00_Telephone').value;
            var haserrors = false;

            if (fname == '') {
                haserrors = true;
                document.getElementById('error_fname').innerHTML = '<span class="EditingFormErrorLabel">&nbsp;</span>';
                document.getElementById('error_fname').style.display = 'block';
            }
            else {
                document.getElementById('error_fname').innerHTML = '';
                document.getElementById('error_fname').style.display = 'none';
            }

            if (sname == '') {
                haserrors = true;
                document.getElementById('error_sname').innerHTML = '<span class="EditingFormErrorLabel">&nbsp;</span>';
                document.getElementById('error_sname').style.display = 'block';
            }
            else {
                document.getElementById('error_sname').innerHTML = '';
                document.getElementById('error_sname').style.display = 'none';
            }

            if (postcode == '') {
                haserrors = true;
                document.getElementById('error_postcode').innerHTML = '<span class="EditingFormErrorLabel">&nbsp;</span>';
                document.getElementById('error_postcode').style.display = 'block';
            }
            else {
                document.getElementById('error_postcode').innerHTML = '';
                document.getElementById('error_postcode').style.display = 'none';
            }

            if (address == '') {
                haserrors = true;
                document.getElementById('error_address').innerHTML = '<span class="EditingFormErrorLabel">&nbsp;</span>';
                document.getElementById('error_address').style.display = 'block';
            }
            else {
                document.getElementById('error_address').innerHTML = '';
                document.getElementById('error_address').style.display = 'none';
            }

            if (town == '') {
                haserrors = true;
                document.getElementById('error_town').innerHTML = '<span class="EditingFormErrorLabel">&nbsp;</span>';
                document.getElementById('error_town').style.display = 'block';
            }
            else {
                document.getElementById('error_town').innerHTML = '';
                document.getElementById('error_town').style.display = 'none';
            }

            if (tel == '') {
                haserrors = true;
                document.getElementById('error_tel').innerHTML = '<span class="EditingFormErrorLabel">&nbsp;</span>';
                document.getElementById('error_tel').style.display = 'block';
            } else {
                document.getElementById('error_tel').innerHTML = '';
                document.getElementById('error_tel').style.display = 'none';
            }

            return (!haserrors);
        };
    }
});


function PopupThanks() {
    $(document).ready(function() {
    $.colorbox({ width: "450px", inline: true, href: "#msgThanks" });
    setTimeout('$.colorbox.close()', 2500);
    });
}

function PopupWizardThanks() {
    $(document).ready(function() {
    $.colorbox({ width: "450px", inline: true, href: "#msgWizardThanks" });
    setTimeout('$.colorbox.close()', 3500);
    });
}

function goToSalesPanel2() {
        var fname = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_FirstName').value;
        var sname = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_LastName').value;
        var postcode = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Postcode').value;
        var address = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Address').value;
        var tel = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Telephone').value;
        var email = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Email').value;
        var password = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Password').value;
        var haserrors = false;
        
        if (fname == '') {
            haserrors = true;
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_FirstName').style.border = '1px solid red';
        }
         else {
             document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_FirstName').style.border = '1px solid #777';
        }
        
        if (sname == '') {
            haserrors = true;
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_LastName').style.border = '1px solid red';
        }
         else {
             document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_LastName').style.border = '1px solid #777';
        }
        
        if (postcode == '') {
            haserrors = true;
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Postcode').style.border = '1px solid red';
        }
         else {
             document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Postcode').style.border = '1px solid #777';
        }

        if (postcode != '') {
            if (address == '') {
                haserrors = true;
                document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Postcode').style.border = '1px solid red';
                document.getElementById('error_address').style.display = 'block';
            }
            else {
                document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Postcode').style.border = '1px solid #777';
                document.getElementById('error_address').style.display = 'none';
            }
        }
        
        if (tel == '') {
            haserrors = true;
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Telephone').style.border = '1px solid red';
        } else {
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Telephone').style.border = '1px solid #777';
        }
        
        if (email == '') {
            haserrors = true;
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Email').style.border = '1px solid red';
        } else {
            if (!validateEmailAddress(email)) {
                haserrors = true;
                document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Email').style.border = '1px solid red';
            } else {
                document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Email').style.border = '1px solid #777';
            }
        }
        
        if (password == '') {
            haserrors = true;
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Password').style.border = '1px solid red';
        } else {
            document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Password').style.border = '1px solid #777';
        }

        if (!haserrors) {
            document.getElementById('step1').style.display = 'none';
            document.getElementById('step2').style.display = 'block';
        }
    }

function goToSalesPanel3() {
    var parkid = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_ParkID').value;
    var parkname = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_ParkName').value;
    var parkpostcode = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_ParkPostcode').value;
    var haserrors = false;
    if (parkid == '0') {
        if ((parkname == '') || (parkpostcode == '')) {
            haserrors = true;
            document.getElementById('parkselecterror').innerHTML = 'Please select your park from the list above. If you are unable to find your park, please click the &quot;Can\'t find your park?&quot; link to submit your park to www.myholidaycaravan.com';
        } else {
            document.getElementById('parkselecterror').innerHTML = '';
        }
    } else {
        document.getElementById('parkselecterror').innerHTML = '';
    }

    if (!haserrors) {
        document.getElementById('step2').style.display = 'none';
        document.getElementById('step3').style.display = 'block';
    }
}

function submitSalesForm() {
    var description = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_CaravanDescription').value;
    var salesprice = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_SalePrice').value;
    var make = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Make').value;
    var model = document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Model').value;
    var haserrors = false;

    if (description == '') {
        haserrors = true;
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_CaravanDescription').style.border = '1px solid red';
    } else {
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_CaravanDescription').style.border = '1px solid #777'; 
    }

    if (salesprice == '') {
        haserrors = true;
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_SalePrice').style.border = '1px solid red';
    } else {
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_SalePrice').style.border = '1px solid #777';
    }

    if (make == '') {
        haserrors = true;
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Make').style.border = '1px solid red';
    } else {
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Make').style.border = '1px solid #777';
    }

    if (model== '') {
        haserrors = true;
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Model').style.border = '1px solid red';
    } else {
        document.getElementById('ctl00_cntMain_bizSalesForm_ctl00_Model').style.border = '1px solid #777';
    }

    return (!haserrors);
}

function validateEmailAddress(address) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(address);
}

function ShowNewPark() {
    document.getElementById('salesparkname').style.display = 'table-row';
    document.getElementById('salesparkpostcode').style.display = 'table-row';
}
