
$(document).ready(function () {
    setSiteMap();

    // Setup Search function
    setSearch();
    // Setup Flash text
    setSIFR();
    //Setup high contrast switching
    if ($('ul.high-contrast li a').length) {
        setContrast();
    }

    setFAQ();
    //set Carousel Hover
    setCarouselHover();
    setLogin();
    //set Email to a friend popup
    setEmailButton();
    setKeyboardNav();
    setInputClear();
    setIE6Background();
    dropDownFix();

    //Start changes - Team2 
    controlsOnLoad();
    // Start for Registration page
    companyType();
    dxfield();
    //End for Registration page
    // Generic save as draft
    savedraft()
    //start for expand collapse button
    toggleRows();
    //end for expand collapse button

    //End changes - Team2 

    // If image feature exists call function to initiate
    if ($('div.image-feature.gallery').length) {
        $('div.image-feature.gallery').wtdgallery();
    }
    $('select, div.form-container input, div.form-container textarea, #email-content-container input, #email-content-container textarea').wtdforms();

    setCheckBox();
    loadFancyBox();

    // If ibanner feature exists call function to initiate
    if ($('div.banner-feature').length) {
        $('div.banner-feature').wtdbanner();
    }

    // If top tips exists call function to initiate
    if ($('div.toptips').length) {
        $('div.toptips').wtdtoptips();
    }

    // If carousel exists call function to initiate
    if ($('div.carousel-container').length) {
        $('div.carousel-container').wtdcarousel();
    }

    // If flickr exists call function to initiate
    if ($('div.flickr-feed').length) {
        $('div.flickr-feed').wtdflickr();
    }

    // Form Validation Initialised
    if ($('.validate-form').length) {
        setDatePicker();

        $('.validate-form').validate({
            rules: {
                newPassword: "required",
                confNewPassword: {
                    equalTo: "#newPassword"
                }
            },
            errorElement: "em",
            errorPlacement: function (error, element) {
                if (element.hasClass('select-replacement')) {
                    error.appendTo(element);
                }
                else {
                    error.appendTo(element.parent());
                }
            },
            success: function (label) {
                label.addClass("success");
                if (label.parent().hasClass('select-replacement')) {
                    label.parent().css({
                        width: "373px"
                    });
                }

                $('div.input-replacement input').each(function () {
                    if ($(this).parent().find('em').hasClass('success')) {
                        $(this).parent().removeClass('error');
                    }
                });

            },
            messages: {

                password: { required: "Please enter your password" },
                newPassword: { required: "Please enter a new password" },
                confNewPassword: { required: "Please confirm your new password" },
                dxNumber: { required: "Please enter your DX number" },
                dxExchange: { required: "Please enter your DX exchange" },
                Forename: { required: "Please enter your first name" },
                Surname: { required: "Please enter your last name" },
                Email: { required: "Please enter your email address" },
                Forename_Adduser: { required: "Please enter the first name" },
                Surname_Adduser: { required: "Please enter the last name" },
                Email_Adduser: { required: "Please enter the email address" },
                Phonenumber: { required: "Please enter a valid contact number - numbers and spaces only" },
                Phonenumber_Adduser: { required: "Please enter a valid phone number" },
                jobTitle: { required: "Please enter your job title" },
                username: { required: "Please enter a user name" },
                username_Adduser: { required: "Please enter a user name" },

                ReferenceNumber: { required: "Please enter your reference" },
                EmailId: { required: "Please enter your email address" },
                AddressLine1: { required: "Please enter your delivery address" },
                TownCity: { required: "Please enter your town or city" },
                

                subaddressOut_addr1: { required: "Please enter first line of address" },
                subaddressOut_town: { required: "Please enter town" },
                subaddressOut_county: { required: "Please enter county" },
                phonenumber: { required: "Please enter a valid contact number - numbers and spaces only" },
                surname: { required: "Please enter your last name" },
                enquirer_company_name: { required: "Please enter your company name" },
                housenumber: { required: "Please enter building name / number" },
                address1: { required: "Please enter first line of address" },
                town: { required: "Please enter town" },
                county: { required: "Please enter county" },
                telephone: { required: "Please enter a valid contact number - numbers and spaces only" },
                trade_process: { required: "Please describe trade process(es) producing effluent" },
                site_name: { required: "Please enter site name" },
                site_housenumber: { required: "Please enter building name / number" },
                site_address1: { required: "Please enter first line of address" },
                site_town: { required: "Please enter town" },
                site_county: { required: "Please enter county" },
                site_contact_name: { required: "Please enter site contact person name" },
                contact_telephone: { required: "Please enter a valid contact number - numbers and spaces only" },
                message: { required: "Please type your message / enquiry" },
                termscond: { required: "Please conform you have read, understood and accept the terms and conditions of use" },
                initials: { required: "Please enter your first name" },
                enquirytype: { required: "Please tell us the nature of your enquiry" },
                road: { required: "Please confirm your road name" },
                message: { required: "Please enter your message" },
                Forename1: { required: "Please enter your first name" },
                jobtitle: { required: "Please enter your job title" },
                mediaorganisation: { required: "Please enter your media organisation" },
                email: { required: "Please enter your email address" },
                email2: { required: "Please confirm your email address" },
                confirmemail: { required: "Please confirm your email address" },
                Email2: { required: "Please confirm your email address" },
                preferred_address: { required: "Please select preferred address for correspondence" },
                phonenum: { required: "Please enter a valid contact number - numbers and spaces only" },
                address_line1: { required: "Please enter first line of address" },
                town1: { required: "Please enter town" },
                county1: { required: "Please enter county" },
                project_name: { required: "Please enter site / project name" },
                site_cn_name: { required: "Please enter contact name" },
                site_pno: { required: "Please enter site phone number" },
                address1_agent: { required: "Please enter first line of address" },
                town_agent: { required: "Please enter town" },
                county_agent: { required: "Please enter county" },
                local_auth: { required: "Please enter local authority" },
                third_firstname: { required: "Please enter your first name" },
                third_lastname: { required: "Please enter your last name" },
                third_contact: { required: "Please enter a valid contact number - numbers and spaces only" },
                house_num_cust: { required: "Please enter house number / name" },
                addressOut_addr1: { required: "Please enter first line of address" },
                addressOut_town: { required: "Please enter town" },
                addressOut_county: { required: "Please enter county" },
                leak_repair: { required: "Please enter who repaired leak" },
                accountholdername: { required: "Please enter account holder name" },
                accountnumber: { required: "Please enter account number" },
                Companytype: { required: "Please select your company type" },
                companyName: { required: "Please enter your company name" },
                Address1: { required: "Please enter your address" },
                Town: { required: "Please enter your town or city" },
                termsConditions: { required: "Please confirm that you agree to the terms and conditions" },
                paymentType: { required: "Please select your payment type" },
                Postcode: { required: "Please enter your postcode" }
            }
        });

        clearLabels();
        accountNumberPopup();
        setaddNames();
        backtoTop();
    }

    propertyInsight();
    //closepopUpforPlanUpload();
});

function propertyInsight() {

    setInfoIcons();
    var name;
    var CaseQuoteId = 12345;
    var liulBasket = '';
    var liulProduct = '';
    var chkLandReg;
    var count = parseInt('0');

    //Reset button IE fix
    $('input.reset-form-button').hover(function () {
        $(this).css({
            backgroundPosition: "0 -40px"
        });
    }, function () {
        $(this).css({
            backgroundPosition: "0 0"
        });
    });

    //Start - Wipro - for updation of basket according to case plan options

    $('div.article-case').each(function (index) {
        if ($('input[type=radio]:eq(' + index + ')').attr('checked') == true) {
            $(this).addClass('active');
            name = $(this).find("a").name;
        }
        $(this).click(function () {
            $('p.errorMessage').css('display', 'inline').html("&nbsp;");
            $('div.article-case').removeClass('active');
            //$(this).addClass('active');
            $('input[type=radio]').attr('checked', false);
            //alert(index);
            if (index == 2) {
                $('input[type=radio]:eq(' + index + ')').attr('checked', false);
                $(this).removeClass('active');
                $('p.errorMessageUpload').css('display', 'inline').html("&nbsp;");
                $('p.errorMessage').css('display', 'inline').html("&nbsp;");
            }
            else {
                $('input[type=radio]:eq(' + index + ')').attr('checked', true);
                $(this).addClass('active');
                $('p.errorMessageUpload').css('display', 'inline').html("&nbsp;");
                $('p.errorMessage').css('display', 'inline').html("&nbsp;");
            }
            if (index == 1) {
                var val = $("#ulProduct li:eq(0)").text();
                var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length);
                //var exVatTotal = parseFloat(exVat) + parseFloat('0.05');
                $.ajax({
                    type: "POST",
                    url: "/NewCase/LandRegistry",
                    dataType: "json",
                    data: { CaseQuoteId: CaseQuoteId },
                    success: function (data) {
                        //   document.body.style.cursor = 'default';
                        if (data.valid) {
                            $("#ulBasket li").each(function (index) {
                                if ($.trim($(this).text()) == 'Title Plan View')
                                    chkLandReg = $(this).text();
                            });

                            $("#ulProduct li").each(function (index) {
                                count = count + 1;
                            });
                            if (!($.trim(chkLandReg) == 'Title Plan View')) {
                                $.each(data.ProductList, function (index, value) {
                                    if (index == 0) {
                                        liulBasket = liulBasket.trim();
                                        liulBasket = '<li>';
                                        liulBasket = liulBasket.trim();
                                        liulBasket = liulBasket + value;
                                        liulBasket = liulBasket.trim();
                                        liulBasket = liulBasket + '</li>';
                                        liulBasket = liulBasket.trim();
                                        $("#ulBasket").append(liulBasket);
                                    }
                                    else if (index == 1) {
                                        if (count > 0) {
                                            var val = $("#ulProduct li:eq(0)").text();
                                            var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                            var exVatTotal = parseFloat(exVat) + parseFloat(value);
                                            exVatTotal = exVatTotal.toFixed(2);

                                            var exVatTotalStr = "Ex VAT<span>&pound;" + exVatTotal + "</span>";
                                            $("#ulProduct li:eq(0)").html(exVatTotalStr);
                                            //$("#ulProduct li:eq(0)").html(function (i, html) {
                                            //                                                return html.replace(exVat, exVatTotal);
                                            //                                            });
                                        }
                                        else {
                                            liulProduct = liulProduct.trim();
                                            liulProduct = '<li>Ex VAT<span>&pound;';
                                            liulProduct = liulProduct.trim();
                                            liulProduct = liulProduct + value;
                                            liulProduct = liulProduct.trim();
                                            liulProduct = liulProduct + '</span></li>';
                                            liulProduct = liulProduct.trim();
                                            $("#ulProduct").append(liulProduct);
                                        }

                                    }

                                    else if (index == 2) {
                                        if (count > 0) {
                                            var val = $("#ulProduct li:eq(1)").text();
                                            var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                            var exVatTotal = parseFloat(exVat) + parseFloat(value);
                                            exVatTotal = exVatTotal.toFixed(2);
                                            var exVatTotalStr = "VAT<span>&pound;" + exVatTotal + "</span>";
                                            $("#ulProduct li:eq(1)").html(exVatTotalStr);

                                            //                                            $("#ulProduct li:eq(1)").html(function (i, html) {
                                            //                                                return html.replace(exVat, exVatTotal);
                                            //                                            });
                                        }
                                        else {
                                            liulProduct = liulProduct.trim();
                                            liulProduct = '<li>VAT<span>&pound;';
                                            liulProduct = liulProduct.trim();
                                            liulProduct = liulProduct + value;
                                            liulProduct = liulProduct.trim();
                                            liulProduct = liulProduct + '</span></li>';
                                            liulProduct = liulProduct.trim();
                                            $("#ulProduct").append(liulProduct);
                                        }
                                    }

                                    else {
                                        if (count > 0) {
                                            var val = $("#ulProduct li:eq(2)").text();
                                            var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                            var exVatTotal = parseFloat(exVat) + parseFloat(value);
                                            exVatTotal = exVatTotal.toFixed(2);
                                            var exVatTotalStr = "Total<span>&pound;" + exVatTotal + "</span>";
                                            $("#ulProduct li:eq(2)").html(exVatTotalStr);

                                            //                                            $("#ulProduct li:eq(2)").html(function (i, html) {
                                            //                                                return html.replace(exVat, exVatTotal);
                                            //                                            });
                                        }
                                        else {
                                            liulProduct = liulProduct.trim();
                                            liulProduct = '<li>Total<span>&pound;';
                                            liulProduct = liulProduct.trim();
                                            liulProduct = liulProduct + value;
                                            liulProduct = liulProduct.trim();
                                            liulProduct = liulProduct + '</span></li>';
                                            liulProduct = liulProduct.trim();
                                            $("#ulProduct").append(liulProduct);
                                        }

                                    }
                                }

                         );
                            }

                        }
                        else {
                            $('p.errorMessage').css('display', 'block').html(data.errorMessage);
                        }
                    }
                });

            }

            if (index == 2) {
                var chkLandReg = '';

                $("#ulBasket li").each(function (index) {
                    if ($.trim($(this).text()) == 'Title Plan View') {
                        chkLandReg = chkLandReg.trim();
                        chkLandReg = $(this).text();
                        chkLandReg = chkLandReg.trim();
                    }
                });
                if (($.trim(chkLandReg) == 'Title Plan View')) {

                    $.ajax({
                        type: "POST",
                        url: "/NewCase/LandRegistry",
                        dataType: "json",
                        data: { CaseQuoteId: CaseQuoteId },
                        success: function (data) {
                            //   document.body.style.cursor = 'default';
                            if (data.valid) {

                                $.each(data.ProductList, function (index, value) {
                                    if (index == 0) {
                                        $("#ulBasket li").each(function (index, item) {
                                            if ($.trim($(this).text()) == 'Title Plan View')
                                                $(item).remove();
                                        });

                                    }
                                    else if (index == 1) {
                                        var val = $("#ulProduct li:eq(0)").text();
                                        var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                        var exVatTotal = parseFloat(exVat).toFixed(2) - parseFloat(value).toFixed(2);
                                        exVatTotal = exVatTotal.toFixed(2);
                                        var exVatTotalStr = "Ex VAT<span>&pound;" + exVatTotal + "</span>";
                                        $("#ulProduct li:eq(0)").html(exVatTotalStr);

                                        //                                        $("#ulProduct li:eq(0)").html(function (i, html) {
                                        //                                            return html.replace(exVat, exVatTotal);
                                        //                                        });
                                    }

                                    else if (index == 2) {
                                        var val = $("#ulProduct li:eq(1)").text();
                                        var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                        var exVatTotal = parseFloat(exVat).toFixed(2) - parseFloat(value).toFixed(2);
                                        exVatTotal = exVatTotal.toFixed(2);
                                        var exVatTotalStr = "VAT<span>&pound;" + exVatTotal + "</span>";
                                        $("#ulProduct li:eq(1)").html(exVatTotalStr);
                                        //                                        $("#ulProduct li:eq(1)").html(function (i, html) {
                                        //                                            return html.replace(exVat, exVatTotal);
                                        //                                        });
                                    }
                                    else {
                                        var val = $("#ulProduct li:eq(2)").text();
                                        var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                        var exVatTotal = parseFloat(exVat).toFixed(2) - parseFloat(value).toFixed(2);
                                        exVatTotal = exVatTotal.toFixed(2);
                                        var exVatTotalStr = "Total<span>&pound;" + exVatTotal + "</span>";
                                        $("#ulProduct li:eq(2)").html(exVatTotalStr);
                                        //                                        $("#ulProduct li:eq(2)").html(function (i, html) {
                                        //                                            return html.replace(exVat, exVatTotal);
                                        //                                        });
                                    }
                                }

                         );

                            }
                            else {
                                $('p.errorMessage').css('display', 'block').html(data.errorMessage);
                            }
                        }
                    });
                }
                popUpforPlanUpload();
                //showFileUpload();
            }

            if (index == 0) {
                var chkLandReg = '';

                $("#ulBasket li").each(function (index) {
                    if ($.trim($(this).text()) == 'Title Plan View') {
                        chkLandReg = chkLandReg.trim();
                        chkLandReg = $(this).text();
                        chkLandReg = chkLandReg.trim();
                    }
                });

                if (($.trim(chkLandReg) == 'Title Plan View')) {

                    $.ajax({
                        type: "POST",
                        url: "/NewCase/LandRegistry",
                        dataType: "json",
                        data: { CaseQuoteId: CaseQuoteId },
                        success: function (data) {
                            //   document.body.style.cursor = 'default';
                            if (data.valid) {

                                $.each(data.ProductList, function (index, value) {
                                    if (index == 0) {
                                        $("#ulBasket li").each(function (index, item) {
                                            if ($.trim($(this).text()) == 'Title Plan View')
                                                $(item).remove();
                                        });

                                    }
                                    else if (index == 1) {
                                        var val = $("#ulProduct li:eq(0)").text();
                                        var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                        var exVatTotal = parseFloat(exVat).toFixed(2) - parseFloat(value).toFixed(2);
                                        exVatTotal = exVatTotal.toFixed(2);
                                        var exVatTotalStr = "Ex VAT<span>&pound;" + exVatTotal + "</span>";
                                        $("#ulProduct li:eq(0)").html(exVatTotalStr);

                                        //                                        $("#ulProduct li:eq(0)").html(function (i, html) {
                                        //                                            return html.replace(exVat, exVatTotal);
                                        //                                        });
                                    }

                                    else if (index == 2) {
                                        var val = $("#ulProduct li:eq(1)").text();
                                        var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                        var exVatTotal = parseFloat(exVat).toFixed(2) - parseFloat(value).toFixed(2);
                                        exVatTotal = exVatTotal.toFixed(2);
                                        var exVatTotalStr = "VAT<span>&pound;" + exVatTotal + "</span>";
                                        $("#ulProduct li:eq(1)").html(exVatTotalStr);
                                        //                                        $("#ulProduct li:eq(1)").html(function (i, html) {
                                        //                                            return html.replace(exVat, exVatTotal);
                                        //                                        });
                                    }
                                    else {
                                        var val = $("#ulProduct li:eq(2)").text();
                                        var exVat = val.substring(val.indexOf("\u00A3") + 1, val.length)
                                        var exVatTotal = parseFloat(exVat).toFixed(2) - parseFloat(value).toFixed(2);
                                        exVatTotal = exVatTotal.toFixed(2);
                                        var exVatTotalStr = "Total<span>&pound;" + exVatTotal + "</span>";
                                        $("#ulProduct li:eq(2)").html(exVatTotalStr);
                                        //                                        $("#ulProduct li:eq(2)").html(function (i, html) {
                                        //                                            return html.replace(exVat, exVatTotal);
                                        //                                        });
                                    }
                                }

                         );


                            }
                            else {
                                $('p.errorMessage').css('display', 'block').html(data.errorMessage);
                            }
                        }
                    });
                }

            }

        });
    });
    //End - Wipro - for updation of basket according to case plan options

    //Set textarea click state
    var starterText = "";
    $('textarea').click(function () {
        if ($(this).val() == "Please type your message" || $(this).val() == "Please type your message / enquiry here" || $(this).val() == "Please type your message / response here" || $(this).val() == "Please give details") {
            starterText = $(this).val();
            $(this).val("");
        }
    });

    $('textarea').focusout(function () {
        if ($(this).val() == "") {
            $(this).val(starterText);
        }
    });

    //Set profile bar name to align correctly
    if ($('span.name').height() > 30) {
        $('span.name').css({
            margin: "-7px 0 0 0"
        });
    }
    else {
        if ($('span.name').width() > 109) {
            $('span.name').css({
                'font-size': '1em',
                margin: "1px 0 0 0"
            });
            if ($('span.name').width() > 109) {
                $('span.name').css({
                    'font-size': '0.75em',
                    margin: "4px 0 0 0"
                });
                if ($('span.name').width() > 109) {
                    $('span.name').css({
                        'font-size': '0.583em',
                        margin: "7px 0 0 0"
                    });
                }
            }
        }
    }

    //Set text cutter on case dashboard table
    if ($('th.key-column-small').length) {
        $('table.product-dashboard tr td').each(function (index, element) {
            var lengthOfText = $(this).text().length;
            if (lengthOfText > 35) {
                var origText = $(element).text();
                var cutText = $(element).text().substring(0, 35) + '...';

                $(element).text(cutText);
                $(element).prepend('<div class="table-anchor"><div class="dashboard-popup hidden"><span>' + origText + '</span></div></div>');
            }
        });
        $('div.dashboard table tr td.ref').each(function (index, element) {
            var lengthOfText = $(this).text().length;
            if (lengthOfText > 8) {
                var origText = $(element).text();
                var cutText = $(element).text().substring(0, 8) + '...'
                $(element).text(cutText);
                $(element).prepend('<div class="table-anchor"><div class="dashboard-popup-small hidden"><span>' + origText + '</span></div></div>');
            }
        });
    }
    $('div.dashboard table tr td').hover(function () {
        $(this).find('div.dashboard-popup').toggleClass('hidden');
    });
    $('div.dashboard table tr td.ref').hover(function () {
        $(this).find('div.dashboard-popup-small').toggleClass('hidden');
    });
    $('table.grid tr td:first-child').css({
        borderLeft: "none"
    });

    //Set nested hide/show rows
    if ($('#hiddenField').val() != "0")//Wipro code added for expand collapse
        $('tr.child, tr.second-child').hide();
    $('tr.open-close td.closed').click(function () {
        if ($(this).parent().hasClass('active')) {
            $(this).parent().removeClass('active');
            $(this).parent().nextUntil('tr:not(tr.child)').toggle();
            $(this).parent().find('td.closed').removeClass('open');
        }
        else {
            $('tr.child').hide();
            $(this).parent().removeClass('active').find('td.closed').removeClass('open');
            $(this).parent().addClass('active');
            $(this).parent().nextUntil('tr:not(tr.child)').toggle();
            $(this).parent().find('td.closed').addClass('open');
        }
        return false;
    });
    $('tr.open-close td a').click(function () {
        if ($(this).hasClass('active')) {
            $('tr.open-close td a').removeClass('active');
            $(this).parent().parent().nextUntil('tr:not(tr.child)').toggle();
            $('tr.second-child').hide();
        }
        else {
            $('tr.child').hide();
            $('tr.open-close td a,tr.child td a').removeClass('active');
            $(this).parent().parent().nextUntil('tr:not(tr.child)').toggle();
            $('tr.second-child').hide();
            $(this).addClass('active');
        }
        return false;
    });
    $('tr.child td a').click(function () {
        if ($(this).parent().parent().hasClass('second-child')) {
            return false;
        }
        if ($(this).hasClass('active')) {
            $('tr.child td a').removeClass('active');
            $(this).parent().parent().nextUntil('tr:not(tr.second-child)').toggle();
        }
        else {
            $('tr.second-child').hide();
            $('tr.child td a').removeClass('active');
            $(this).parent().parent().nextUntil('tr:not(tr.second-child)').toggle();
            $(this).addClass('active');
        }
        return false;
    });

    //Set carousel hover for article case touts
    $('div.article-case').hover(function () {
        $(this).find('div').show();
        $(this).find('h3 a').css({
            color: "#FFFFFF"
        });
    }, function () {
        $(this).find('div').hide();
        $(this).find('h3 a').css({
            color: "#5d5d5d"
        });
    });

    //Set open close list on case form for extra information page
    //$('div.open-close-list div.field').hide();
    //Start - Wipro - for case extra information page
    if ($('input[id=hiddenField]').val() != "1")
        $('div.open-close-list div.field').hide();
    //End - Wipro - for case extra information page

    //$('div.open-close-list:first-child div.field').show();
    //$('div.open-close-list:first-child h3 a').addClass('active');

    $('div.open-close-list h3 a').click(function () {
        $('div.open-close-list div.field ').css('position', 'static');
        $('div.open-close-list div.field ').hide();
        $('div.open-close-list div.field ').css('position', 'relative');
        if ($(this).hasClass('active')) {
            $('div.open-close-list h3 a').removeClass('active');
        }
        else {
            $('div.open-close-list h3 a').removeClass('active');
            $(this).addClass('active');
            $(this).parent().parent().find('div.field').show();
        }
        return false;
    });

    $('input.reset-button').live('click', function () {
        $('div.select-replacement.large').css({
            width: "345px"
        });
    });
    $('input.submit-button').live('click', function () {
        $('div.select-replacement.large').css({
            width: "373px"
        });
    });

}


function setSearch(){
	//Direct address search to Live Maps page
	$('input#submit-address').click(function(){
		var searchVal = $('input#address-search').val();
		window.open('http://192.168.0.82/index.htm?k=' + searchVal);
	});
}

function setCarouselHover(){
	$('div.carousel-hover').hide();
	$('div.carousel ul li.carousel-item').live('mouseenter',function(){
		$(this).find('div.carousel-hover').show();
	}).live('mouseleave',function(){
		$(this).find('div.carousel-hover').hide();
	});

	$('div.carousel ul li.carousel-item h3 a').live('focus',function(){
		$(this).parent().parent().find('div.carousel-hover').show();
	}).live('focusout',function(){
		$(this).parent().parent().find('div.carousel-hover').hide();
	});
}


function loadFancyBox(){
	if($('a.lightbox, div.lightbox a').length){
		if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
			return false;
		}
		else{
			$('a.lightbox, div.lightbox a').fancybox({
				padding : 7,
				titlePosition : 'over',
				'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-overlay">' + title + '</span>';
				}
			});
		}
	}
}

function setSiteMap(){
	
	// Hide Sitemap
	$('div.sitemap').css('display', 'none');
	
	$('div.sitemap-link ul li a').live('click', function(event) {
		if($('div.sitemap').is(':visible')){
			if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
				$('div.sitemap').css('display', 'none');
				$(this).removeClass('active');
			}
			else{
				$('div.sitemap').slideUp(1000, 'easeOutExpo');
				$(this).removeClass('active');
			}
				event.preventDefault();
		} 
		else {
			if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
				$('div.sitemap').css('display', 'block');
				$(this).removeClass('active');
			}
			else{
				$('div.sitemap').slideDown(1000, 'easeOutExpo');
				$(this).addClass('active');
			}
				event.preventDefault();
		}
	});

}

function setLogin(){
	$('a.logout').live('click', function(){
		$('div.profile-bar ul li:first-child').remove();
		$('div.profile-bar ul li:first-child').html('<a href="#" title="Logout" class="login">Login</a>');
		$('div.profile-bar ul li:last-child').html('<a href="#" title="Register">Register</a>');
    });

    $('a.cancel').live('click', function () {
        $('div.content-box, div.content-overlay').remove();
        $('div.content-mask').remove();
        return false;
    });

	$('a.login').live('click', function(){
		$('div.content-overlay').remove();
		$('div.content-mask').remove();

		// Find the height and width of the document for the overlay							   
		$documentHeight = $(document).height();
		$documentWidth = $(document).width();
			
		// Set the overlay		
		$('body').prepend('<div class="content-overlay"><div class="content-box"></div></div>');
		$('body').prepend('<div class="content-mask"></div>');
		$('div.content-mask').css('height',$documentHeight).fadeTo(400, 0.6);

		$contentOffset = ($documentWidth / 2) - ($('div.content-box').width() / 2)
		$('div.content-box').css('left',$contentOffset);
		$('div.content-box').load('/Login' + ' #login-content-container', function() {
			// If content loaded then display overlay and content
			$('div.content-box').append('<ul class=\'close\'><li><a href=\'#\'>Close</a></li></ul>');
			$('div.content-box').fadeIn(600, 'easeOutExpo');

			sIFR.replace(albertExtraBold, {
			  selector: 'h1',
			  css: '.sIFR-root {  color:#9ebe2f; font-size:25px;}',
			  wmode: 'transparent',
			  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
			});
			
			$('ul.close li a, div.cancel-button a').click(function(){
				$('div.content-box, div.content-overlay').fadeOut(400, 'easeOutExpo', function(){
					$('div.content-box, div.content-overlay').remove();
				});
				$('div.content-mask').remove();
			});
			$('#login-content-container input').wtdforms();
			$('#login-content-container input').eq(0).focus();
		});
		return false;
	});

    $('a.resetPassword').live('click', function () {
        $('div.content-overlay').remove();
        $('div.content-mask').remove();

        // Find the height and width of the document for the overlay							   
        $documentHeight = $(document).height();
        $documentWidth = $(document).width();

        // Set the overlay
        $('body').prepend('<div class="content-overlay"><div class="content-box"></div></div>');
        $('body').prepend('<div class="content-mask"></div>');
        $('div.content-mask').css('height', $documentHeight).fadeTo(400, 0.6);
        $contentOffset = ($documentWidth / 2) - ($('div.content-box').width() / 2)
        $('div.content-box').css('left', $contentOffset);

        $('div.content-box').load('/Login/ResetPassword' + ' #login-content-container', function () {
            // If content loaded then display overlay and content
            $('div.content-box').append('<ul class=\'close\'><li><a href=\'#\'>Close</a></li></ul>');
            $('div.content-box').fadeIn(600, 'easeOutExpo');

            sIFR.replace(albertExtraBold, {
                selector: 'h1',
                css: '.sIFR-root {  color:#9ebe2f; font-size:25px;}',
                wmode: 'transparent',
                ratios: [7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
            });
            
            $('ul.close li a, div.cancel-button a').click(function () {
                $('div.content-box, div.content-overlay').fadeOut(400, 'easeOutExpo', function () {
                    $('div.content-box, div.content-overlay').remove();
                });
                $('div.content-mask').remove();
            });
            
            $('#login-content-container input').wtdforms();
            $('#login-content-container input').eq(0).focus();
        });
        return false;
    });

	$('div#login-content-container input.required').live('click',function(){
		$(this).parent().removeClass('error');
	});
}

function loginValidation(){
	var nameCheck = document.forms["login"]["username"].value;
	var passCheck = document.forms["login"]["password"].value;

	if(nameCheck == null || nameCheck == ""){
		$('input#username').parent().addClass('error');
		if(passCheck == null || passCheck == ""){
			$('input#password').parent().addClass('error');
			return false;
		}
		return false;
	}
	if(passCheck == null || passCheck == ""){
		$('input#password').parent().addClass('error');
		return false;
	}
	$('div.content-box, div.content-overlay').fadeOut(400, 'easeOutExpo', function(){
		$('div.content-box, div.content-overlay').remove();
		$('div.content-mask').remove();
	});

	$('div.profile-bar ul li:last-child').html('<a href="#" title="Logout" class="logout">Logout</a>');
	$('div.profile-bar ul li:first-child').html('<a href="#" title="My account">My account</a>');
	$('div.profile-bar ul').prepend('<li><span>Welcome: </span><span class="name">' + nameCheck + '</span></li>');
	if($('span.name').height() > 30){
		$('span.name').css({
			margin:"-7px 0 0 0"
		});
	}
	else{
		if($('span.name').width() > 109){
			$('span.name').css({
				'font-size':'1em',
				margin:"1px 0 0 0"
			});
			if($('span.name').width() > 109){
				$('span.name').css({
					'font-size':'0.75em',
					margin:"4px 0 0 0"
				});
				if($('span.name').width() > 109){
					$('span.name').css({
						'font-size':'0.583em',
						margin:"7px 0 0 0"
					});
				}
			}
		}
	}
	/*$('body').prepend('<div class="content-sent-box"></div>');
	$contentOffset = ($documentWidth / 2) - ($('div.content-sent-box').width() / 2)
	$('div.content-sent-box').css('left',$contentOffset);
	$('div.content-sent-box').load('emailtoafriend.html' + ' #email-thankyou-container', function() {
		// If content loaded then display overlay and content
		$('div.content-sent-box').append('<ul class=\'close\'><li><a href=\'#\'>Close</a></li></ul>');
		$('div.content-sent-box').fadeIn(600, 'easeOutExpo');

		sIFR.replace(albertExtraBold, {
		  selector: 'h1',
		  css: '.sIFR-root {  color:#3894af; font-size:25px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});

		sIFR.replace(albert, {
		  selector: 'div#email-thankyou-container p',
		  css: '.sIFR-root {  color:#000000; font-size:15px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
		
		$('ul.close li a, div.cancel-button').click(function(){
			$('div.content-sent-box').fadeOut(400, 'easeOutExpo', function(){
				$('div.content-sent-box').remove();
			});
		});
	});*/

	return false;
}

function setEmailButton(){
	$('a.button_email').live('click', function(){
		$('div.content-box').remove();

		// Find the height and width of the document for the overlay							   
		$documentHeight = $(document).height();
		$documentWidth = $(document).width();
			
		// Set the overlay
		$('body').prepend('<div class="content-box"></div>');
		$contentOffset = ($documentWidth / 2) - ($('div.content-box').width() / 2)
		$('div.content-box').css('left',$contentOffset);
		$('div.content-box').load('emailtoafriend.html' + ' #email-content-container', function() {
			// If content loaded then display overlay and content
			$('div.content-box').append('<ul class=\'close\'><li><a href=\'#\'>Close</a></li></ul>');
			$('div.content-box').fadeIn(600, 'easeOutExpo');

			sIFR.replace(albertExtraBold, {
			  selector: 'h1',
			  css: '.sIFR-root {  color:#3894af; font-size:25px;}',
			  wmode: 'transparent',
			  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
			});

			sIFR.replace(albertExtraBold, {
			  selector: 'label',
			  css: '.sIFR-root {  color:#000000; font-size:15px;}',
			  wmode: 'transparent',
			  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
			});
			
			$('ul.close li a, div.cancel-button').click(function(){
				$('div.content-box').fadeOut(400, 'easeOutExpo', function(){
					$('div.content-box').remove();
				});
			});
			$('#email-content-container input, #email-content-container textarea').wtdforms();
			$('#email-content-container input').eq(0).focus();
		});
	});
	
	$('div#email-content-container input.required').live('click',function(){
		$(this).parent().removeClass('error');
	});
}

function emailValidation(){
	var nameCheck = document.forms["emailToAFriend"]["emailName"].value;
	var emailCheck = document.forms["emailToAFriend"]["emailAddress"].value;
	var atCheck = emailCheck.indexOf("@");
	var dotCheck = emailCheck.lastIndexOf(".");

	if(nameCheck == null || nameCheck == ""){
		$('input#emailName').parent().addClass('error');
		if(atCheck < 1 || dotCheck < atCheck + 2 || dotCheck + 2 >= emailCheck.length || emailCheck == null || emailCheck == ""){
			$('input#emailAddress').parent().addClass('error');
			return false;
		}
		return false;
	}
	if(atCheck < 1 || dotCheck < atCheck + 2 || dotCheck + 2 >= emailCheck.length || emailCheck == null || emailCheck == ""){
		$('input#emailAddress').parent().addClass('error');
		return false;
	}
	$('div.content-box').fadeOut(400, 'easeOutExpo', function(){
		$('div.content-box').remove();
	});
	$('body').prepend('<div class="content-sent-box"></div>');
	$contentOffset = ($documentWidth / 2) - ($('div.content-sent-box').width() / 2)
	$('div.content-sent-box').css('left',$contentOffset);
	$('div.content-sent-box').load('emailtoafriend.html' + ' #email-thankyou-container', function() {
		// If content loaded then display overlay and content
		$('div.content-sent-box').append('<ul class=\'close\'><li><a href=\'#\'>Close</a></li></ul>');
		$('div.content-sent-box').fadeIn(600, 'easeOutExpo');

		sIFR.replace(albertExtraBold, {
		  selector: 'h1',
		  css: '.sIFR-root {  color:#3894af; font-size:25px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});

		sIFR.replace(albert, {
		  selector: 'div#email-thankyou-container p',
		  css: '.sIFR-root {  color:#000000; font-size:15px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
		
		$('ul.close li a, div.cancel-button').click(function(){
			$('div.content-sent-box').fadeOut(400, 'easeOutExpo', function(){
				$('div.content-sent-box').remove();
			});
		});
	});

	return false;
}

function setSIFR(){

	// Setting H1 and color dependent on site area
	sIFR.replace(albert, {
	  selector: 'div.content.home-page h1',
	  css: '.sIFR-root {  color:#9ebe2f; font-size:42px; leading:-7;}',
	  wmode: 'transparent',
	  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
	});
	if($('div.error').length){
		sIFR.replace(albertExtraBold, {
		  selector: 'h1',
		  css: '.sIFR-root {  color:#a33f97; font-size:110px; }',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});

		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#666766; font-size:30px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});

		sIFR.replace(albertExtraBold, {
		  selector: 'h3',
		  css: '.sIFR-root {  color:#555555; font-size:20px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
	}
	if($('div.disaster').length){
		sIFR.replace(albertExtraBold, {
		  selector: 'div.header-inner ul li',
		  css: ['a {  color:#FFFFFF; font-size:40px; text-decoration:none; text-align:right;}',
			  'a:hover {  color:#FFFFFF; text-decoration:underline;}'],
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});

		sIFR.replace(albertExtraBold, {
		  selector: 'h1',
		  css: '.sIFR-root {  color:#01cae8; font-size:30px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});

		sIFR.replace(albertExtraBold, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#01cae8; font-size:20px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
	}
	if($('div.content').hasClass('landing-page') == false){
		sIFR.replace(albertExtraBold, {
		  selector: 'h1',
		  css: '.sIFR-root {  color:#666666; font-size:24px;}',
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
	}
	sIFR.replace(albert, {
	  selector: 'p.strapline',
	  css: '.sIFR-root {  color:#FFFFFF; font-size:16px; line-height:42px;}',
	  wmode: 'transparent',
	  ratios: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
	});
	
	if($('div.sidebar h2').hasClass('create-case') == false && $('div.sidebar h2').hasClass('add-product') == false){
		sIFR.replace(albertExtraBold, {
		  selector: 'div.sidebar h2',
		  css: '.sIFR-root {  color:#9ebe2f; font-size:24px;}',
		  wmode: 'transparent',
		  ratios: [7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
	}

	sIFR.replace(albertExtraBold, {
	  selector: 'div.search-container h3',
	  css: '.sIFR-root {  color:#FFFFFF; font-size:16px;}',
	  wmode: 'transparent'
	});

	sIFR.replace(albertThin, {
	  selector: 'div.content.wide div.section h3',
	  css: ['.sIFR-root {  color:#FFFFFF; font-size:27px;}',
	  '.sIFR-root a { color: #ffffff; text-decoration:none; cursor:pointer;}',
	  '.sIFR-root a:hover { color: #ff0000; text-decoration:none; }'],
	  wmode: 'transparent'
	});
	sIFR.replace(albertThin, {
	  selector: 'ul.landing-highlights li span.heading',
	  css: '.sIFR-root {  color:#FFFFFF; font-size:24px; cursor:pointer;}',
	  wmode: 'transparent'
	  //onRelease: function(fi) { sIFRLink(fi.getAncestor()) } 
	});/**/
	sIFR.replace(albertExtraBold, {
	  selector: 'div.article.amp5 div.map-header h3',
	  css: '.sIFR-root {  color:#97af51; font-size:25px;}',
	  wmode: 'transparent',
	  ratios: [7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
	});
	sIFR.replace(albertExtraBold, {
	  selector: 'div.map-header h3',
	  css: '.sIFR-root {  color:#005599; font-size:25px;}',
	  wmode: 'transparent',
	  ratios: [7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
	});
	sIFR.replace(albert, {
	  selector: 'div.key-projects h3',
	  css: '.sIFR-root {  color:#555555; font-size:20px;}',
	  wmode: 'transparent'
	});


	// Landing Page Tout Headings
	// Applies default landing page headings
	if($('body').hasClass('contact-us') == false){
		sIFR.replace(albertExtraBold, {
		  selector: 'div.landing-page div.article h3',
		  css: ['.sIFR-root {  color:#FFFFFF; font-size:24px; cursor:pointer;}',
		  '.sIFR-root a { color: #FFFFFF; text-decoration:none; cursor:pointer;}',
		  '.sIFR-root a:hover { color:#FFFFFF; text-decoration:underline;}'],
		  wmode: 'transparent',
		  ratios: [7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
	}
	// Applies section specific landing page headings on contact page
	else{
		$('div.landing-page div.article span').each(function(index, element){
			// Check which article heading color is required
			if($(element).hasClass('your-account') == true){
				var textColor = '#9ab931';
				var className = 'your-account';
			}
			else if($(element).hasClass('got-problem') == true){
				var textColor = '#7e4a80';
				var className = 'got-problem';
			}
			else if($(element).hasClass('moving-home') == true){
				var textColor = '#cd7423';
				var className = 'moving-home';
			}
			else if($(element).hasClass('water-meters') == true){
				var textColor = '#b61277';
				var className = 'water-meters';
			}
			else if($(element).hasClass('your-water') == true){
				var textColor = '#0f9ab7';
				var className = 'your-water';
			}
			// Apply color to those with the required class
			sIFR.replace(albertExtraBold, {
			  selector: 'div.landing-page div.article span.' + className,
			  css: ['.sIFR-root {  color:' + textColor + '; font-size:24px; cursor:pointer;}',
					'a:hover .sIFR-root a{ color: #FFFFFF; text-decoration:none; cursor:pointer;}'],
			  wmode: 'transparent',
			  onRelease: function(fi) { sIFRLink(fi.getAncestor()) }, 
			  ratios: [7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
			});
		});
	}
	sIFR.replace(albertBold, {
	  selector: 'div.header div.image h4',
	  css: '.sIFR-root {  color:#FFFFFF; font-size:20px; font-weight:bold;}',
	  wmode: 'transparent',
	  forceSingleLine:true,
	  ratios:[8, 1.31, 12, 1.27, 15, 1.21, 16, 1.22, 22, 1.2, 23, 1.17, 25, 1.19, 33, 1.17, 42, 1.16, 47, 1.15, 48, 1.16, 66, 1.15, 70, 1.14, 72, 1.15, 78, 1.14, 79, 1.15, 1.14]
	});

	sIFR.replace(albertBold, {
	  selector: 'div.header div.article h3',
	  css: ['.sIFR-root {  color:#193c72; font-size:20px; font-weight:bold;}',
	  '.sIFR-root.image h3 { color: #ffffff;}'],
	  wmode: 'transparent',
	  forceSingleLine:true,
	  ratios:[8, 1.31, 12, 1.27, 15, 1.21, 16, 1.22, 22, 1.2, 23, 1.17, 25, 1.19, 33, 1.17, 42, 1.16, 47, 1.15, 48, 1.16, 66, 1.15, 70, 1.14, 72, 1.15, 78, 1.14, 79, 1.15, 1.14]
	});
	
	// Setting H2 and color dependent on site section
	if($('div.content').hasClass('landing-page') == false && $('body').hasClass('your-account') == true){
		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#829043; font-size:21px;}',
		  wmode: 'transparent',
		  debug: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
		});
	}
	else if($('div.content').hasClass('landing-page') == false && $('body').hasClass('got-problem') == true){
		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#924e95; font-size:21px;}',
		  wmode: 'transparent',
		  debug: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
		});
	}
	else if($('div.content').hasClass('landing-page') == false && $('body').hasClass('moving-home') == true){
		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#ba5d17; font-size:21px;}',
		  wmode: 'transparent',
		  debug: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
		});
	}
	else if($('div.content').hasClass('landing-page') == false && $('body').hasClass('water-meters') == true){
		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#b41176; font-size:21px;}',
		  wmode: 'transparent',
		  debug: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
		});
	}
	else if($('div.content').hasClass('landing-page') == false && $('body').hasClass('your-water') == true){
		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#137d9c; font-size:21px;}',
		  wmode: 'transparent',
		  debug: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
		});
	}
	else if($('div.content').hasClass('landing-page') == true){
		sIFR.replace(albertExtraBold, {
		  selector: 'h2',
          css: ['.sIFR-root {  color:#FFFFFF; font-size:24px;}',
          'em { font-style: normal; color: #FFFFFF; font-size:15px;}'],
		  wmode: 'transparent',
		  ratios:[7, 1.32, 8, 1.31, 12, 1.27, 19, 1.23, 29, 1.19, 36, 1.18, 49, 1.17, 50, 1.16, 51, 1.17, 74, 1.16, 75, 1.15, 80, 1.16, 1.15]
		});
	}
	else if($('div.content').hasClass('home-page') == false && $('h2').hasClass('create-case') == false && $('h2').hasClass('add-product') == false){
		sIFR.replace(albert, {
		  selector: 'h2',
		  css: '.sIFR-root {  color:#9ebe2f; font-size:21px; leading:0;}',
		  wmode: 'transparent',
		  debug: [8, 1.31, 12, 1.27, 16, 1.21, 17, 1.2, 23, 1.19, 24, 1.16, 25, 1.18, 27, 1.17, 32, 1.16, 33, 1.17, 41, 1.16, 58, 1.15, 64, 1.14, 65, 1.15, 95, 1.14, 96, 1.13, 100, 1.14, 101, 1.13, 102, 1.14, 104, 1.13, 109, 1.14, 113, 1.13, 114, 1.14, 1.13]
		});
	}
}



/*function setLightboxHover(){
	$('body').append('<div id=\'magnify-cursor\'></div>')
	$('div.image-feature.lightbox a').each(function(index, element){
		$(element).mouseout(function(){
			$('#magnify-cursor').hide();
			return false;
		});
		$(element).mouseenter(function(){
			$('#magnify-cursor').show();
			return false;
		});
		$(element).mousemove(function(e){
			$('#magnify-cursor').css({
				'left': e.clientX,
				'top': e.clientY
			});
		});
		  
	});
}*/

function setFAQ(){
	$('ul.open-close-list li.faq-content').hide();
	//$('ul.open-close-list li:first-child ul li:first-child').show();
	//$('ul.open-close-list li:first-child').addClass('active');

	$('ul.open-close-list li a').click(function(event){
		if($(this).parent().find('li.faq-content').is(':visible')){
			$(this).parent().find('li.faq-content').hide();
			$(this).parent().parent().find('li').removeClass('active');
			$(this).parent().removeClass('active');
			event.preventDefault();
		} 
		else {
			$(this).parent().parent().find('li.faq-content').hide();
			$(this).parent().find('li.faq-content').show();
			$(this).parent().parent().find('li').removeClass('active');
			$(this).parent().addClass('active');
			event.preventDefault();
		}
	});
	
	$('ul.open-close-list li ul li a').unbind('click');
}

function setKeyboardNav(){
	$('ul.secondary-nav li a').focus(function() {
		$('ul.secondary-nav li').removeClass('hover');
		$(this).parent().addClass('hover');
	});	
	
	$('ul.secondary-nav li a').click(function() {
		$(this).parent().removeClass('hover');
	});

	$('ul.secondary-nav li ul li a').unbind('focus');
		
	$('div.header div.search input, div.logo a').focus(function() {
		$('ul.secondary-nav li').removeClass('hover');
	});

}

function setIE6Background(){
	if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
		var homepageWidth = $(window).width();
		var contentWidth = $('div.content-inner').width();
		var backgroundImage = $('div.home-page').css('background-image') + ' #228CB4 repeat-x';
		var landingImage = $('div.landing-page').css('background-image');
		var head = $("div.header-inner");
		var offset = head.offset();

		if($('div.content').hasClass('landing-page') == true){
			offset.left = offset.left - 27;
			$('div.content').css('padding-left',offset.left);
			/*$leftOffset = (($(window).width() - contentWidth) / 4) + 5;
			$('div.content-background').css('margin-left', $leftOffset + 'px');
			//$('div.content-background').css('width',$(window).width())
			*/$('body').css({
				'background':landingImage,
				'background-position':'0 0',
				'margin':'0 auto'
			});
		}
		else if($('div.content').hasClass('home-page') == true){
			offset.left = offset.left - 35;
			$('div.content').css('padding-left',offset.left);
			$('body').css({
				'background':backgroundImage,
				'background-position':'0 136px',
				'margin':'0 auto'
			});
		}
		else{
			offset.left = offset.left - 3;
			$('div.content').css('padding-left',offset.left);
			//$leftOffset = (($(window).width() - contentWidth) / 4 - 50) ;
			//$('div.content-background').css('margin-left', $leftOffset + 'px');
			
			//var leftMargin = $('div.header-inner');
			//var offset = leftMargin.offset();
			//$('div.content-background').css('margin-left', offset.left + 'px');
			
			/*$leftOffset = (($(window).width() - contentWidth) / 4) -1;
			$('div.content-background').css('margin-left', $leftOffset + 'px');
			$('body').css({
				'background':backgroundImage,
				'background-position':'0 136px'
			});*/
		}

		//$leftOffset = (($(window).width() - contentWidth) / 4) - 1;
		//$('div.content-background').css('margin-left', $leftOffset + 'px');
		//$('div.content.home-page').css('width', $(window).width() + 'px');
	}
}

//$(window).resize(function() {
//  setIE6Background();
//});


$(window).resize(function(){
	window_resize();
});

var resizeTimeoutId;

function window_resize() {
    window.clearTimeout(resizeTimeoutId);
	resizeTimeoutId = window.setTimeout('setIE6Background();', 100);
}

function setInputClear() {
    $defaultVal = '';
    $('input[type="text"]').each(function (index) {
        $defaultVal = $(this).val();
        /*Team2 changes start*/
        if ($(this).attr("id") == 'SearchText')
            $(this).attr("rev", $defaultVal);
        /* Team2 changes end*/
    });

    $('input[type="text"]').focus(function () {
        $defaultVal = $(this).attr("rev");
        if ($(this).val() == $defaultVal) {
            $(this).val('');
        }
    });

    $('input[type="text"]').blur(function () {
        if ($(this).val() == '') {
            $(this).val($defaultVal);
        }
    });

    $('input.non-form[type="text"]').each(function (index) {
        $defaultVal = $(this).val();
        $(this).attr("rev", $defaultVal);
    });

    $('input.non-form[type="text"]').focus(function () {
        $defaultVal = $(this).attr("rev");
        if ($(this).val() == $defaultVal) {
            $(this).val('');
        }
    });

    $('input.non-form[type="text"]').blur(function () {
        if ($(this).val() == '') {
            $(this).val($defaultVal);
        }
    });
   }


function dropDownFix(){	
	
	if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
		$('ul.secondary-nav li a:first-child').hover(function() {
			$(this).parent().addClass('hover');
		}, function () {
			$(this).parent().removeClass('hover');
		});
		
		$('ul.secondary-nav').hover(function() {
			$(this).append('<iframe></iframe>');
			$(this).find('iframe').css('filter', 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)');
			$(this).find('iframe').css('opacity', '0');
		}, function () {
			$(this).find('iframe').remove();
		});
	
		$('ul.secondary-nav li ul li a').unbind('hover');
	}
}


function setCheckBox(){
	
	$('input[type="checkbox"]').each(function(index, element){
		$(element).ezMark();
		if($(element).parent().parent().parent().parent().parent().hasClass('plumber-search')){
			$(element).parent().css('margin-top','6px');
		}
	});
	

	$('input#search-whole-site').click(function(){
		$wholeChecked = $(this).attr('checked');		

		$('div.search-filter input[type="checkbox"]').each(function(index, element){
			if ($wholeChecked == true)
			{
				$(element).attr('checked', 'true');
				$(element).parent().addClass('ez-checked')
			}else{
				$(element).attr('checked', '');
				$(element).parent().removeClass('ez-checked')
			}
		});
	});


	$('div.search-filter input[type="checkbox"]').click(function(){

		$thisChecked = $(this).attr('checked');

		if ($thisChecked == false)
		{
			$('input#search-whole-site').attr('checked', '')
			$('input#search-whole-site').parent().removeClass('ez-checked')
		}
	});

}

function setRadioButton(){
	
	$('input[type="radio"]').each(function(index, element){
		//if($(element).parent().parent().parent().parent().hasClass('plumber-search') == false){
			$(element).ezMark();
		//}
		//else{
		//	$(element).ezMark({checkboxCls:'ez-checkbox-plumber', checkedCls: 'ez-checked-plumber'});
		//}
	});
}

// IE6 PNG Fix

function fixPNG(myImage){
 
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
		var imgTitle = (myImage.title) ? 
               "title=\"" + myImage.title  + "\" " : "title=\"" + myImage.alt + "\" "
		var imgStyle = "display:block; margin-top:0px;" + myImage.style.cssText
		var myParent = myImage.parentNode
 
		if (myParent.nodeName == "A"){
			var aHref=myParent.href;
			var aTarget=""
			var aStyle="style=\" display:block; width:" + myImage.width + "px; height:" + myImage.height + "px;\" "
			if (myParent.target !=="") {
				aTarget = "target=\""+ myParent.target + "\"";
			}
			var strNewHTML = "<span " + imgID + imgClass
			+ imgTitle + " style=\"" + "width:" + myImage.width 
			+ "px; height:" + myImage.height 
			+ "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='image');\">"
			+ "<a " + aStyle +  "href=\""+aHref + "\" target=\""+ aTarget + "\" ><!-- --></a> </span>"
			myParent.outerHTML = strNewHTML
		}
		else{
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width 
			+ "px; height:" + myImage.height 
			+ "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='image');\"></span>"
			myImage.outerHTML = strNewHTML
		}
    }
}

// Form Validation

function clearLabels(){
	jQuery('input.reset-button,input.reset-form-button').click(function(){
		jQuery('em.error').remove();
		jQuery('.error').removeClass('error');
		jQuery('.date-error').removeClass('date-error');
		jQuery('div.tooltip-container').remove();
	});
}

function accountNumberPopup(){
	
	// Hide your account number help image
	jQuery('ul.account-number li ul').css('left', '-999em');
	jQuery('div.field').css('position', 'relative');
	jQuery('div.radio').css('position', 'relative');
	jQuery('div.radio-validation-group div.radio').css('position', 'static');
	jQuery('div.check').css('position', 'relative');
	jQuery('div.date-field').css('position', 'relative');
	jQuery('form').find('iframe').remove();
	
	jQuery('ul.account-number li').unbind('mouseover');
	jQuery('ul.account-number li').unbind('mouseout');

	jQuery('ul.account-number li').mouseover(function() {
		jQuery(this).parent().css('z-index', '101');
		jQuery(this).find('ul').prepend('<iframe></iframe>');
		jQuery(this).find('iframe').css('filter', 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)');
		jQuery(this).find('iframe').css('opacity', '0');
		jQuery('div.field').css('position', 'static');
		jQuery('div.radio label').css('position', 'static');
		jQuery('div.radio').css('position', 'static');
		jQuery('div.check').css('position', 'static');
		jQuery('div.date-field').css('position', 'static');
		jQuery(this).find('ul').css('left', '-30px');
		jQuery('div.tooltip-container').remove();
		return false;
	}).mouseout(function(){
		jQuery(this).parent().css('z-index', '100');
		jQuery(this).find('ul').css('left', '-999em');
		jQuery(this).find('iframe').remove();
		jQuery('div.field').css('position', 'relative');
		jQuery('div.radio').css('position', 'relative');
		jQuery('div.radio-validation-group div.radio').css('position', 'static');
		jQuery('div.date-field').css('position', 'relative');
		return false;
	});

	jQuery('ul.account-number li a').click(function(){
		return false;
	});
}

function setaddNames(){
	// Hide all items in hidden group
	jQuery('ul.show-hidden-group li.remove-contact').css('display', 'none');	
	jQuery('div.hidden-group').css('display', 'none');	
	
	var count = 0;
	
	jQuery('ul.show-hidden-group li.add-contact a').click(function(){
		count = count + 1;
		var hiddenGroup = jQuery(this).parent().parent().parent().find('div.hidden-group');	
		jQuery('ul.show-hidden-group').css('padding-bottom', '15px');
		hiddenGroup.each(function(index, element){
			
			jQuery('ul.show-hidden-group li.remove-contact').css('display', 'block');
			
			// Check the display state of each item
			var displayState = jQuery(element).css('display');

			// The last item reached that is display:none; is made visible and then return false so loop can start again
			if(displayState == 'none'){
				jQuery(element).css('display', 'block');
				jQuery(element).find('input.hidden-required').addClass('required');
				return false;
			}
		});
		return false;												   
	});
	jQuery('ul.show-hidden-group li.remove-contact a').click(function(){
		count = count - 1;
		var hiddenGroup = jQuery(this).parent().parent().parent().find('div.hidden-group');	
		hiddenGroup.each(function(index, element){
			
			// Check the display state of each item
			var displayState = jQuery(element).css('display');

			if(count == 0){
				jQuery('ul.show-hidden-group li.remove-contact').css('display', 'none');
					jQuery('ul.show-hidden-group').css('padding-bottom', '0');
			}

			// The last item reached that is display:block; is hidden and then return false so loop can start again
			if(displayState == 'block'){
				jQuery(element).css('display', 'none');
				jQuery(element).find('input.hidden-required').removeClass('required');
				return false;
			}

		});
		return false;												   
	});
}

function setDatePicker(){
	count = 0;

	jQuery('.date-pick').each(function(index, element){
		jQuery(element).attr('id', 'date-pick' + index);
	
		$startDay = jQuery('.date-pick').parent().parent().parent().find('select.d').find('option:eq(1)').val();
		$startMonth = jQuery('.date-pick').parent().parent().parent().find('select.m').find('option:eq(1)').val();
		$startYear = jQuery('.date-pick').parent().parent().parent().find('select.y').find('option:eq(1)').val();

		$endDay = jQuery('.date-pick').parent().parent().parent().find('select.d').find('option:last-child').val();
		$endMonth = jQuery('.date-pick').parent().parent().parent().find('select.m').find('option:last-child').val();
		$endYear = jQuery('.date-pick').parent().parent().parent().find('select.y').find('option:last-child').val();
		
		// initialise the "Select date" link
		jQuery('.date-pick')
			.datePicker(
				// associate the link with a date picker
				{
					createButton:false,
					startDate:$startDay + '/' + $startMonth + '/' + $startYear,
					endDate:$endDay + '/' + $endMonth + '/' + $endYear
				}
			).bind(
				// when the link is clicked display the date picker
				'click',
				function()
				{
					$datepickID = jQuery(this).attr('id').substring(9);
					updateSelects(jQuery(this).dpGetSelected()[0], $datepickID);
					jQuery(this).dpDisplay();
					return false;
				}
			).bind(
				// when a date is selected update the SELECTs
				'dateSelected',
				function(e, selectedDate, $td, state)
				{
					$datepickID = jQuery(this).attr('id').substring(9);
					count = 1;
					updateSelects(selectedDate, $datepickID);
				}
			).bind(
				'dpClosed',
				function(e, selected)
				{
					updateSelects(selected[0], $datepickID);
				}
			);
	});
	
	jQuery('.d').each(function(index, element){
		jQuery(element).addClass('d' + index);
		jQuery(element).css('width', '65px');
	});
	jQuery('.m').each(function(index, element){
		jQuery(element).addClass('m' + index);	
		jQuery(element).css('width', '65px');
	});
	jQuery('.y').each(function(index, element){
		jQuery(element).addClass('y' + index);	
		jQuery(element).css('width', '77px');
	});
	
	var updateSelects = function (selectedDate, $myID)
	{
		var selectedDate = new Date(selectedDate);

		if(count < 1){
			jQuery('.d' + $myID + ' option[value=default-value]').attr('selected', 'selected');
			jQuery('.m' + $myID + ' option[value=default-value]').attr('selected', 'selected');
			jQuery('.y' + $myID + ' option[value=default-value]').attr('selected', 'selected');
		}
		else{
			jQuery('.d' + $myID + ' option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
			jQuery('.m' + $myID + ' option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
			jQuery('.y' + $myID + ' option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
			if(jQuery('#date-pick' + $myID).parent().parent().parent().find('em.error').length < 1){
				jQuery('#date-pick' + $myID).parent().parent().parent().append('<em class=\'error success\'></em>');
				jQuery('#date-pick' + $myID).parent().parent().parent().find('em.error').css('display', 'block');
			}
			else{
				jQuery('#date-pick' + $myID).parent().parent().parent().find('em.error').unbind('mouseover');
				jQuery('#date-pick' + $myID).parent().parent().parent().find('em.error').unbind('mouseout');
				jQuery('#date-pick' + $myID).parent().parent().parent().find('em.error').addClass('success');
				jQuery('#date-pick' + $myID).parent().parent().parent().find('select').removeClass('date-error');
				jQuery('#date-pick' + $myID).parent().parent().parent().find('div.select-replacement').removeClass('error');
			}
		}
		
		// Update Values in Select Box Replacements
		$selectedDay = jQuery('.d' + $myID).find(':selected').html();
		jQuery('.d' + $myID).parent().find('div').html($selectedDay);
		$selectedMonth = jQuery('.m' + $myID).find(':selected').html();
		jQuery('.m' + $myID).parent().find('div').html($selectedMonth);
		$selectedYear = jQuery('.y' + $myID).find(':selected').html();
		jQuery('.y' + $myID).parent().find('div').html($selectedYear);
		
	}
	// listen for when the selects are changed and update the picker
	 jQuery('.date-pick').each(function(index, element){
		jQuery('.d' + index + ', .m' + index + ', .y' + index + '').bind(
			'change',
			function()
			{
				var dayVal = jQuery('.d' + index).val();
				var monthVal = jQuery('.m' + index).val(); 
				var yearVal = jQuery('.y' + index).val();
				
				if(dayVal == 'default-value' || monthVal == 'default-value' || yearVal == 'default-value'){
					jQuery('#date-pick' + index).parent().parent().parent().find('em.error').removeClass('success');
					if(jQuery('#date-pick' + index).parent().parent().parent().find('em.error').length){
						jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('date-error');
						jQuery('#date-pick' + index).parent().parent().parent().find('div.select-replacement').addClass('error');
					}
					jQuery('#date-pick' + index).parent().parent().parent().find('em.error').text('Please enter a valid date');
					setPopup(jQuery('#date-pick' + index).parent().parent());
					count = 0;
					return false;
				}
				else{
					count = 1;
					if(checkDaysInMonth(dayVal, monthVal-1, yearVal) ==  true){
						var d = new Date(
									jQuery('.y' + index).val(),
									jQuery('.m' + index).val()-1,
									jQuery('.d' + index).val()
								);
								count = 1;
						jQuery(element).dpSetSelected(d.asString());
						jQuery('#date-pick' + index).parent().parent().parent().find('div.select-replacement').removeClass('error');
					}
					else{
						if(jQuery('#date-pick' + index).parent().parent().parent().find('em.error').length){
							jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('date-error');
							jQuery('#date-pick' + index).parent().parent().parent().find('em.error').removeClass('success');
							jQuery('#date-pick' + index).parent().parent().parent().find('em.error').text('Please enter a valid date');
							setPopup(jQuery('#date-pick' + index).parent().parent());
						}
						else{
							jQuery('#date-pick' + index).parent().parent().parent().append('<em class=\'error\'></em>');
							jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('date-error');
							jQuery('#date-pick' + index).parent().parent().parent().find('em.error').text('Please enter a valid date');
							jQuery('#date-pick' + index).parent().parent().parent().find('em.error').show();
							setPopup(jQuery('#date-pick' + index).parent().parent());
						}
					}
				}
			}
		);
	});
	// default the position of the selects to today
	jQuery('.date-pick').each(function(index, element){
		var today = new Date();
		updateSelects(today.getTime(), index);
	});
	
	jQuery('input.submit-button').click(function(){
		jQuery('.date-pick').each(function(index, element){
			var dayVal = jQuery('.d' + index).val();
			var monthVal = jQuery('.m' + index).val(); 
			var yearVal = jQuery('.y' + index).val();

			var requiredDate = jQuery(element).parent().parent().parent().hasClass('required');
			if(requiredDate == true){
				// Check if there are any DD, MM, or YYYY default values left and display or keep error icon
				if(dayVal == 'default-value' || monthVal == 'default-value' || yearVal == 'default-value'){
					if(jQuery('#date-pick' + index).parent().parent().parent().find('em.error').length < 1){
						jQuery('#date-pick' + index).parent().parent().parent().append('<em class=\'error\'>Please enter a valid date</em>');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('date-error');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').removeClass('valid');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('error');
						setPopup(jQuery('#date-pick' + index).parent().parent());
						jQuery('#date-pick' + index).parent().parent().parent().find('div.select-replacement').addClass('error');
					}
					else{
						jQuery('#date-pick' + index).parent().parent().parent().find('em.error').removeClass('success');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').removeClass('valid');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('error');
						setPopup(jQuery('#date-pick' + index).parent().parent());
					}
					jQuery('#date-pick' + index).parent().parent().parent().find('em.error').css('display', 'block');
				}
				else{
					// Check if it is a valid date and if so display tick icon
					if(checkDaysInMonth(dayVal, monthVal-1, yearVal) ==  true){
						jQuery('#date-pick' + index).parent().parent().parent().find('em.error').addClass('success');
						jQuery('#date-pick' + index).parent().parent().parent().find('em.error').text('');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').removeClass('date-error');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').removeClass('error');
						jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('valid');
						jQuery('#date-pick' + index).parent().parent().parent().find('em.error').css('display', 'block');
						jQuery('#date-pick' + index).parent().parent().parent().find('div.select-replacement').removeClass('error');
					}
					// Check if not a valid date and if so
					else{
						if(jQuery('#date-pick' + index).parent().parent().parent().find('em.error').length < 1){
							jQuery('#date-pick' + index).parent().parent().parent().append('<em class=\'error\'>Please enter a valid date</em>');
							jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('date-error');
							jQuery('#date-pick' + index).parent().parent().parent().find('select').removeClass('valid');
							jQuery('#date-pick' + index).parent().parent().parent().find('select').addClass('error');
							setPopup(jQuery('#date-pick' + index).parent().parent());
						}
						else{
							jQuery('#date-pick' + index).parent().parent().parent().find('em.error').removeClass('success');
							setPopup(jQuery('#date-pick' + index).parent().parent());
						}
						jQuery('#date-pick' + index).parent().parent().parent().find('em.error').css('display', 'block');
					}
				}
			}
		})
	});
}

function checkDaysInMonth($currentDay, $currentMonth, $currentYear) {
	$numDays = [31,(checkLeapYear($currentYear) ? 29:28),31,30,31,30,31,31,30,31,30,31][$currentMonth];

	if($currentDay > $numDays){
		return false;	
	}
	return true;
}

function checkLeapYear($currentYear) {
		var y = $currentYear;
		return (y%4==0 && y%100!=0) || y%400==0;
}

function setInfoIcons(){
	jQuery('em.info').mouseover(function(){
		jQuery('div.tooltip-container').remove();

		var tipText = jQuery(this).attr('title');
		
		
		/*
		ANDYS NEW*/
		if ($(this).parent().parent().parent().parent().parent().hasClass('product-dashboard')
        || ($(this).parent().parent().parent().parent().parent().parent().parent().parent().parent().hasClass('product-dashboard')) )
        {
			var sidetipText = jQuery(this).html();
			jQuery('.form-container').prepend('<div class=\'tooltip-side-container\'><div class=\'tooltip-side-top\'></div><div class=\'tooltip-side-content\'><p>' + sidetipText + '</p></div></div>');

			jQuery('.tooltip-side-container').css('top', $(this).offset().top-10)
			jQuery('.tooltip-side-container').css('left', $(this).offset().left+15)
		//	jQuery(this).parent().append('<div class=\'tooltip-side-container\'><div class=\'tooltip-side-top\'></div><div class=\'tooltip-side-content\'><p>' + sidetipText + '</p></div></div>');
		}
		else if(tipText == ''){
			return false;	
		}
		else{
			// Build HTML for tooltip
             jQuery(this).parent().append('<div class=\'tooltip-container\'><div class=\'tooltip-top\'></div><div class=\'tooltip-content\'><p>' + tipText + '</p></div></div>');
			
			//Find height of tooltip for top position above form element	
			$tooltipPos = jQuery('div.tooltip-container').height() - 2;
			
			// AR 06/10/2010 - set the right position for info elements differently if there is an active error
			var tooltipRight = '-15px';
			if(jQuery(this).parent().find('em.error').length){
				tooltipRight = '-43px';
			}
			//AS 08/08/2011 - Set the right position for the property search popups
			if($(this).parent().parent().hasClass('table-head')){
				tooltipRight = '-160px';
			}
			if($(this).parent().hasClass('legend-replace')){
				tooltipRight = '-197px';
			}
			if($(this).parent().hasClass('submitBtns')){
				tooltipRight = '410px';	
				$tooltipPos = jQuery('div.tooltip-container').height() - 26;
			}
			if($(this).parent().children('div').hasClass('medium')){
				tooltipRight = '105px';
			}
			if($(this).parent().parent().parent().hasClass('table-head')){
				tooltipRight = '-160px';
			}
			jQuery('div.tooltip-container').css('right', tooltipRight);
			jQuery('div.tooltip-container').css('top', '-' + $tooltipPos + 'px');
			
		}
		if($(this).hasClass('payment')){
			Paymenthtml = '<ul><li><img src="/common/images/icon-diners.gif" alt="Diners"/><span>Diners</span></li>' + 
			'<li><img src="/common/images/icon-master.gif" alt="MasterCard"/><span>Master</span></li>' + 
			'<li><img src="/common/images/icon-visa.gif" alt="Visa"/><span>Visa</span></li>' + 
			'<li><img src="/common/images/icon-amex.gif" alt="American Express"/><span>Amex</span></li>' + 
			'<li><img src="/common/images/icon-maestro.gif" alt="Maestro"/><span>Maestro</span></li>' + 
			'<li><img src="/common/images/icon-jcb.gif" alt="JCB"/><span>JCB</span></li>' + 
			'<li><img src="/common/images/icon-laser.gif" alt="Laser"/><span>Laser</span></li>' + 
			'<li><img src="/common/images/icon-solo.gif" alt="Solo"/><span>Solo</span></li>' + 
			'<li><img src="/common/images/icon-worldpay.gif" alt="WorldPay"/></li></ul>';
			$(this).parent().find('div.tooltip-container').addClass('payment').find('div.tooltip-content').append(Paymenthtml);
			if($('h3.account').length){
				$tooltipPaymentPos = jQuery('div.tooltip-container').height() - 25;
				jQuery('div.tooltip-container').css('right', '406px');
				jQuery('div.tooltip-container').css('top', '-' + $tooltipPaymentPos + 'px');
			}
			else{
				$tooltipPaymentPos = jQuery('div.tooltip-container').height() - 4;
				jQuery('div.tooltip-container').css('right', '-18px');
				jQuery('div.tooltip-container').css('top', '-' + $tooltipPaymentPos + 'px');
			}
		}
  }).mouseout(function(){
	jQuery('div.tooltip-container, div.tooltip-side-container').remove();
  });
	
}

function setPopup(element){
    $('div.check em.error').mouseover(function () {
        jQuery('div.tooltip-container').remove();
        var tipText = $(this).text();
        if (tipText == '') {
            return false;
        }
        else {
            $(this).parent().append('<div class=\'tooltip-container\'><div class=\'tooltip-top\'></div><div class=\'tooltip-content\'><p>' + tipText + '</p></div></div>');
            //Find height of tooltip for top position above form element	
            $tooltipPos = jQuery('div.tooltip-container').height();
            $tooltipPosR = $(this).position().left + 56;
            if ($(this).parent().hasClass('terms')) {
                $tooltipPosR = -85;
            }
            jQuery('div.tooltip-container').css('right', $tooltipPosR + 'px');
            jQuery('div.tooltip-container').css('top', '-' + $tooltipPos + 'px');

            jQuery('div.tooltip-container').css('z-index', '100000');

            if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
                jQuery(element).parent().prepend('<iframe></iframe>');
                jQuery(element).parent().find('iframe').css('filter', 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)');
                jQuery(element).parent().find('iframe').css('opacity', '0');
                jQuery(element).parent().find('iframe').css('width', '230px');
                jQuery(element).parent().find('iframe').css('height', '100px');
                jQuery(element).parent().find('iframe').css('left', ($tooltipPosR + 10) + 'px');
                jQuery(element).parent().find('iframe').css('top', '-' + ($tooltipPos + 50) + 'px');
                jQuery(element).parent().find('iframe').css('z-index', '1000');
            }
        }
    }).mouseout(function () {
        jQuery('div.tooltip-container').remove();
        if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
            jQuery('iframe').remove();
        }
    });
	if(jQuery(element).parent().find('em.error').length){
		jQuery(element).parent().find('em.error').mouseover(function(){
			// Remove any existing tooltips
	
			jQuery('div.tooltip-container').remove();
			//jQuery('iframe').remove();
			
			// Find text from label for tooltip
			if(jQuery(element).parent().find('em.error').length){
				//jQuery(element).parent().find('label.info').hide();
				var tipText = jQuery(element).parent().find('em.error').text();
				if(tipText == ''){
					return false;	
				}

				else{
					// Build HTML for tooltip
					if(jQuery(element).parent().hasClass('select-replacement')){
						jQuery(element).parent().parent().find('div.select-replacement').append('<div class=\'tooltip-container\'><div class=\'tooltip-top\'></div><div class=\'tooltip-content\'><p>' + tipText + '</p></div></div>');
					}
					else{
						jQuery(element).parent().append('<div class=\'tooltip-container\'><div class=\'tooltip-top\'></div><div class=\'tooltip-content\'><p>' + tipText + '</p></div></div>');
					}
					//Find height of tooltip for top position above form element	
					$tooltipPos = jQuery('div.tooltip-container').height();
					$tooltipPosR = jQuery(element).parent().find('em.error').position().left - 53;
					
					$parentClass = jQuery(element).parent().attr('class');
					if($parentClass == 'radio' || $parentClass == 'check'){
						$tooltipPos = $tooltipPos - 6;
						$tooltipPosR = $tooltipPosR - 10;
					}
					$isRadioGroup = jQuery(element).parent().parent().hasClass('radio-validation-group');
					if($isRadioGroup == true){
						jQuery('div.tooltip-container').css('left', $tooltipPosR  + 'px');
						jQuery('div.tooltip-container').css('bottom', '40px');
					}
					else{
						jQuery('div.tooltip-container').css('left', $tooltipPosR  + 'px');
						jQuery('div.tooltip-container').css('top', '-' + $tooltipPos + 'px');
					}
					
					jQuery('div.tooltip-container').css('z-index', '100000');

					if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
						jQuery(element).parent().prepend('<iframe></iframe>');
						jQuery(element).parent().find('iframe').css('filter', 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)');
						jQuery(element).parent().find('iframe').css('opacity', '0');
						jQuery(element).parent().find('iframe').css('width', '230px');					
						jQuery(element).parent().find('iframe').css('height', '100px');	
						jQuery(element).parent().find('iframe').css('left', ($tooltipPosR+10)  + 'px');
						jQuery(element).parent().find('iframe').css('top', '-' + ($tooltipPos+50) + 'px');
						jQuery(element).parent().find('iframe').css('z-index', '1000');
					}


				}
			}
		  }).mouseout(function(){
			jQuery('div.tooltip-container').remove();
			if(jQuery.browser.msie && jQuery.browser.version == '6.0'){
				jQuery('iframe').remove();
			}
		  });

	}
}

function setContrast(){
	var hiContrastLinks = $('ul.high-contrast li a');
	hiContrastLinks.unbind("click");
	for(i=0; i<hiContrastLinks.length; i++){
		hiContrastLinks.click(function(){
			hiContrastLinks.text('View site in normal contrast');
			enableHighContrast();
			return false;
		});	
	}
}

function enableHighContrast(){
	var HTMLhead = document.getElementsByTagName("head")[0];         
	var headerCSS = document.createElement('link');
	headerCSS.type = 'text/css';
	headerCSS.rel = 'stylesheet';
	headerCSS.className = 'hc-stylesheet';
	headerCSS.href = 'common/css/contrast.css';
	headerCSS.media = 'screen';
	HTMLhead.appendChild(headerCSS);

	sIFR.rollback();
	setCookie('TWHC', 'hc-stylesheet', 30);
	setContrastClose();	
	
}

function setContrastClose(){
	var hiContrastClose = $('ul.high-contrast li a');
	
	$('ul.high-contrast li a').unbind("click");
	$('ul.high-contrast li a').click(function(){
		hiContrastClose.text('View site in high contrast');
		$('.hc-stylesheet').remove();
		
		deleteCookie('TWHC');
		setContrast();
		setSIFR();
		return false;
	});
	
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function deleteCookie( cookie_name ){
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function backtoTop(){
	$('ul li.back-to-top a').click(function(){
			// Calculate the top offset of the element
			var targetOffset = $('#container').offset();
			var targetTop = targetOffset.top;
			
			//Slide to the element by setting the body scroll top to anchor top
			$('html, body').animate({
				scrollTop:targetTop
			}, 'slow', 'easeOutExpo');
		return false;
	});	
}

/*  sIFR Unofficial Rollback addon for sIFR 3
    Modified by Paul Hassinger - hassinger.paul@ipaul.com - http://www.ipaul.com
    (modified from sIFR 2.0.1 Official Add-ons 1.2)

    Copyright 2005 Mark Wubben

    This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

if(typeof sIFR == "object"){
    sIFR.rollback = function(){
        function rollback(sSelector){
            if(sSelector == null){
                sSelector = "";
            } else {
                sSelector += ">";
            };

            sIFR.removeFlashClass();

            if(doRollback(sSelector+"embed") == false){
                doRollback(sSelector+"object");
            };
        };

        function doRollback(sSelector){
            var node, nodeParent, nodeAlternate, nodeAlternateChild, nodeAlternateNextChild, indexNodeToRemove;
            var listNodes = parseSelector(sSelector);
            var i = listNodes.length - 1;
            var bHasRun = false;

            while(i >= 0){
                node = listNodes[i];
                listNodes.length--;
                nodeParent = node.parentNode;

                if(node.className == 'sIFR-flash'){
                    /*  Flash blockers may add other nodes as siblings to the Flash element. 
                        Thus, we remove all children of nodeParent, and look for nodeAlternate at the same time */
                    indexNodeToRemove = 0;

                    while(indexNodeToRemove < nodeParent.childNodes.length){
                        node = nodeParent.childNodes[indexNodeToRemove];
                        if(node.className == "sIFR-alternate"){
                            nodeAlternate = node;
                            indexNodeToRemove++;
                            continue;
                        };
                        nodeParent.removeChild(node);
                    };

                    if(nodeAlternate != null){
                        nodeAlternateChild = nodeAlternate.firstChild;
                        while(nodeAlternateChild != null){
                            nodeAlternateNextChild = nodeAlternateChild.nextSibling;
                            nodeParent.appendChild(nodeAlternate.removeChild(nodeAlternateChild));
                            nodeAlternateChild = nodeAlternateNextChild;
                        };
                        nodeParent.removeChild(nodeAlternate);
                    };

                    nodeParent.className = nodeParent.className.replace(/\bsIFR\-replaced\b/, "");
                    bHasRun = true;
                };

                i--;
            };

            return bHasRun;
        };

        return rollback;
    }();
};

function buildFlashMap (divId, swfLoc, swfName, swfWidth, swfHeight, swfVar){
	var flashVersion = 8;

	var so = new SWFObject(swfLoc, swfName, swfWidth, swfHeight, flashVersion, "#000000");
	so.addParam("wmode", "transparent");
	so.addParam("scale", "noscale");
	so.addParam("allowFullScreen", "true");

	if (swfVar){
		so.addVariable("xmlPath", swfVar);
	}
	so.write(divId);
}

//Start changes - Team2 
function loginValidation() {
    var nameCheck = document.forms["login"]["username"].value;
    var passCheck = document.forms["login"]["password"].value;

    if (nameCheck == null || nameCheck == "") {
        $('input#username').parent().addClass('error');
        if (passCheck == null || passCheck == "") {
            $('input#password').parent().addClass('error');
            return false;
        }
        return false;
    }
    if (passCheck == null || passCheck == "") {
        $('input#password').parent().addClass('error');
        return false;
    }

    $('p.errorMessage').css('display', 'none').empty();
    $('p.errorMessage').css('display', 'inline').html("&nbsp;");
    document.body.style.cursor = 'wait';
    $.ajax({
        url: '/Login/ValidateLogin',
        type: 'POST',
        dataType: 'json',
        data: { username: nameCheck, password: passCheck },
        success: function (data) {
            document.body.style.cursor = 'default';
            if (data.valid) {
                $('div.content-box, div.content-overlay, div.content-mask').fadeOut(400, 'easeOutExpo', function () {
                    $('div.content-box, div.content-overlay, div.content-mask').remove();
                });
                window.location = "/Case/Dashboard";
            }
            else {
                $('p.errorMessage').css('display', 'block').html(data.errorMessage);
            }
        }
    });

    return false;
}

function controlsOnLoad() {
    if (jQuery('#DeliveryMethod').parent().find('select option:selected').text() == 'Royal Mail') {
        jQuery('div .email1').css('display', 'none');
        jQuery('div .dxNumber').css('display', 'none');
        jQuery('div .dxExchange').css('display', 'none');
        jQuery('div .address1').css('display', 'block');
        jQuery('div .address2').css('display', 'block');
        jQuery('div .address3').css('display', 'block');
        jQuery('div .town').css('display', 'block');
        jQuery('div .postcode').css('display', 'block');
        $("#EmailId").removeClass('required');
        $("#AddressLine1").addClass('required');
        $("#TownCity").addClass('required');
        $("#PostCode").addClass('ukpostcode');
        $("#dxNumber").removeClass('required');
        $("#dxExchange").removeClass('required');
    }

    else if (jQuery('#DeliveryMethod').parent().find('select option:selected').text() == 'Email') {
        jQuery('div .address1').css('display', 'none');
        jQuery('div .address2').css('display', 'none');
        jQuery('div .address3').css('display', 'none');
        jQuery('div .town').css('display', 'none');
        jQuery('div .postcode').css('display', 'none');
        jQuery('div .dxNumber').css('display', 'none');
        jQuery('div .dxExchange').css('display', 'none');
        jQuery('div .email1').css('display', 'block');
        $("#AddressLine1").removeClass('required');
        $("#TownCity").removeClass('required');
        $("#PostCode").removeClass('ukpostcode');
        $("#PostCode").addClass('optukpostcode');
        $("#EmailId").addClass('required');
        $("#dxNumber").removeClass('required');
        $("#dxExchange").removeClass('required');
    }
    else if (jQuery('#DeliveryMethod').parent().find('select option:selected').text() == 'DX') {
        jQuery('div .address1').css('display', 'none');
        jQuery('div .address2').css('display', 'none');
        jQuery('div .address3').css('display', 'none');
        jQuery('div .town').css('display', 'none');
        jQuery('div .postcode').css('display', 'none');
        jQuery('div .email1').css('display', 'none');
        jQuery('div .dxNumber').css('display', 'block');
        jQuery('div .dxExchange').css('display', 'block');
        $("#AddressLine1").removeClass('required');
        $("#TownCity").removeClass('required');
        $("#PostCode").removeClass('ukpostcode');
        $("#PostCode").addClass('optukpostcode');
        $("#EmailId").removeClass('required');
        $("#dxNumber").addClass('required');
        $("#dxExchange").addClass('required');
    }
    else if (jQuery('#DeliveryMethod').parent().find('select option:selected').text() == 'Online' || jQuery('#DeliveryMethod').parent().find('select option:selected').text() == 'Select') {
        jQuery('div .address1').css('display', 'none');
        jQuery('div .address2').css('display', 'none');
        jQuery('div .address3').css('display', 'none');
        jQuery('div .town').css('display', 'none');
        jQuery('div .postcode').css('display', 'none');
        jQuery('div .email1').css('display', 'none');
        jQuery('div .dxNumber').css('display', 'none');
        jQuery('div .dxExchange').css('display', 'none');
        $("#AddressLine1").removeClass('required');
        $("#TownCity").removeClass('required');
        $("#PostCode").removeClass('ukpostcode');
        $("#PostCode").addClass('optukpostcode');
        $("#EmailId").removeClass('required');
        $("#dxNumber").removeClass('required');
        $("#dxExchange").removeClass('required');
    }
}

function companyType() {
    jQuery('#Companytype').change(function () {
        if (jQuery('#Companytype').val() == '5') {
            firstname = jQuery.trim(jQuery('#Forename').val());
            lastname = jQuery.trim(jQuery('#Surname').val());
            var fullname = firstname + ' ' + lastname;
            var payment = "Credit or debit card";
            jQuery('#companyName').val(fullname);
            jQuery('#companyName').attr('readonly', true);
            jQuery('#companyName').attr('onKeyPress', "javascript:return preventBackspace(event);");
            jQuery('#companyName').attr('onkeydown', "javascript:return preventBackspace(event);");
            $('#companyName').parent().find('em.error').remove();
            $('#companyName').parent().removeClass('error');
            jQuery('#paymentType').siblings().text(payment);
            jQuery("#paymentType option[value=2]").attr("selected", true);
            jQuery('#paymentType').attr("disabled", true);
            $('#paymentType').parent().parent().find('em.error').remove();
            $('#paymentType').parent().removeClass('error');
            jQuery('#paymentType').removeClass('required');
            jQuery('#companyName').removeClass('required');
        }
        else {
            jQuery('#paymentType').attr("disabled", false);
            jQuery('#companyName').attr('readonly', false);
            jQuery('#companyName').attr('onKeyPress', "");
            var payment = $('#paymentType [value="default-value"]').text();
            $('#paymentType').siblings().text(payment);
            $('#paymentType').val(payment); 
            jQuery('#paymentType').addClass('required');
            jQuery('#companyName').addClass('required');
        }

    });
    jQuery('#Surname').change(function () {       
        if (jQuery('form[id=registration]').attr("name") == "registration") {
            if (jQuery('#Companytype').val() == '5') {
                firstname = jQuery.trim(jQuery('#Forename').val());
                lastname = jQuery.trim(jQuery('#Surname').val());
                var fullname = firstname + ' ' + lastname;
                var payment = "Credit or debit card";
                jQuery('#companyName').val(fullname);
                jQuery('#companyName').attr('readonly', true);
                jQuery('#companyName').attr('onKeyPress', "javascript:return preventBackspace(event);");
                jQuery('#companyName').attr('onkeydown', "javascript:return preventBackspace(event);");
                $('#companyName').parent().find('em.error').remove();
                $('#companyName').parent().removeClass('error');
                jQuery('#paymentType').siblings().text(payment);
                jQuery("#paymentType option[value=2]").attr("selected", true);
                jQuery('#paymentType').attr("disabled", true);
                $('#paymentType').parent().parent().find('em.error').remove();
                $('#paymentType').parent().removeClass('error');
                jQuery('#paymentType').removeClass('required');
                jQuery('#companyName').removeClass('required');
            }
            else {
                jQuery('#paymentType').attr("disabled", false);
                jQuery('#companyName').attr('readonly', false);
                var payment = $('#paymentType [value="default-value"]').text();
                $('#paymentType').siblings().text(payment);
                $('#paymentType').val(payment);
                //jQuery('#paymentType [value=0]').attr("selected", true);
                jQuery('#paymentType').addClass('required');
                jQuery('#companyName').addClass('required');
            }
        }
    });
    jQuery('#Forename').change(function () {        
        if (jQuery('form[id=registration]').attr("name") == "registration") {
            if (jQuery('#Companytype').val() == '5') {
                firstname = jQuery.trim(jQuery('#Forename').val());
                lastname = jQuery.trim(jQuery('#Surname').val());
                var fullname = firstname + ' ' + lastname;
                var payment = "Credit or debit card";
                jQuery('#companyName').val(fullname);
                jQuery('#companyName').attr('readonly', true);
                jQuery('#companyName').attr('onKeyPress', "javascript:return preventBackspace(event);");
                jQuery('#companyName').attr('onkeydown', "javascript:return preventBackspace(event);");
                jQuery('#paymentType').siblings().text(payment);
                jQuery("#paymentType option[value=2]").attr("selected", true);
                jQuery('#paymentType').attr("disabled", true);
                jQuery('#paymentType').removeClass('required');
                jQuery('#companyName').removeClass('required');
            }
            else {
                jQuery('#paymentType').attr("disabled", false);
                jQuery('#companyName').attr('readonly', false);
                //jQuery('#paymentType [value=0]').attr("selected", true);
                var payment = $('#paymentType [value="default-value"]').text();
                $('#paymentType').siblings().text(payment);
                $('#paymentType').val(payment);
                jQuery('#paymentType').addClass('required');
                jQuery('#companyName').addClass('required');
            }
        }
    });
}


$("#DeliveryMethod").keypress(function () {
    arrangecontrols();
});


function dxfield() {

    jQuery('#dxNumber').keyup(function () {
        if ($('#dxNumber').val() != "") {
            $('#dxExchange').addClass('required');
            $('#dxExchangelabel').addClass('label-required');
        }
        else {
            $('#dxExchange').removeClass('required');
			$('#dxExchangelabel').removeClass('label-required');
        }
    });


    jQuery('#dxExchange').keyup(function () {
        if ($('#dxExchange').val() != "") {
            $('#dxNumber').addClass('required');
            $('#dxNumberlabel').addClass('label-required');
        }
        else {
            $('#dxNumber').removeClass('required');
			$('#dxNumberlabel').removeClass('label-required');
        }
    });
} 

function savedraft(){
    jQuery('#saveasdraft').click(function () {

        if ($('#saveasdraft').click)
        {
	            $('#ReferenceNumber').removeClass('letterswithbasicpunc required');
			
				$('#AddressLine1').removeClass('required');
				$('#TownCity').removeClass('required');
				$('#PostCode').removeClass('small ukpostcode');
				$('#EmailId').removeClass('required');

				$("#dxNumber").removeClass('required');
				$("#dxExchange").removeClass('required');
        }
       
	});
	}
function toggleRows() {
    $('tr.open-close').each(function (i) {
        if ($('#hiddenField').val() == "0") {
            $('tr.child').hide();
            $('tr.open-close').removeClass('active').find('td.closed').removeClass('open');
            $('tr.open-close').addClass('active');
            $('tr.open-close').nextUntil('tr:not(tr.child)').toggle();
            $('tr.open-close').find('td.closed').addClass('open');
        }

    });
    return false;
}

//function myAccount() {
//    var selectValue = $('#myAccount').val();    
//    window.location = "/MyAccount/" + selectValue    ;
//}
//End changes - Team2

function popUpforPlanUpload() {
    var w=600;
    var h=600;
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    window.open('/NewCase/CasePlanAttachment', '_blank', 'toolbar=0,location=0,menubar=0,height=200,width=400,resizable=no,top='+top+', left='+left);
}

//function closepopUpforPlanUpload() {
//    alert('Inside closepopUpforPlanUpload');
//    alert($('#_showModalPopup').val());
//   // self.close();
//    if ($('#_showModalPopup').val()) {
//        alert('equal');
//        window.close();
//        if (window.opener && !window.opener.closed) {
//            alert('Hello');
//            window.opener.location.reload();
//        } 
//        
//        //opener.location.reload();
//        ///self.close();
//    }

//}

function preventBackspace(e) {

    if (e.which || e.keyCode) {
        if ((e.which == 13) || (e.keyCode == 13)) {
            e.returnValue = false;
            e.cancel = true;
        }
    }
   
    return false;
}


function sIFRLink(sifr) {
    $href = $(sifr).parent().parent().find('a').attr('href');
    window.location.href($href);
}

