function openWin() { myWindow = window.open("/affordability_calculator/?source=direct ", "affordCalc", "width=760, height=720, menubar=no, statusbar=yes, location=no, scrollbars=yes, toolbar=no, top=0"); myWindow.focus(); } function openWinCallback() { myWindow = window.open("/contact/MortInfoCallback.asp?UTMSource=NewMortApp1 ", "callback", "width=760, height=695, menubar=no, statusbar=yes, location=no, scrollbars=yes, toolbar=no, top=0"); myWindow.focus(); } $(document).ready(function () { if (document.location.toString().indexOf("#buytolet") != -1) { $(window).scrollTop("0"); } $("#saved .del").live("click", function (e) { e.preventDefault(); var that = $(this); var saved = $("#saved"); var href = that.attr("href"); var id = href.split("Remove/")[1]; var url = sitePrepend + "/services/AJAXRemoveMortgage/" + id; $.get(url, function (data) { $.get(sitePrepend + "/Find/Find-A-Mortgage/", function (data) { that.parents(".list").remove(); var savedmortgages = $(data).find(".list"); saved.find("h2 a span").text("(" + savedmortgages.length + ")"); var suffix = (savedmortgages.length == 1) ? "" : "s"; saved.find(".highlight strong strong").text(savedmortgages.length + " saved mortgage" + suffix); }); }); }); if ($("#saved").length != 0) { $("#saved").savemortgages(); } $("#mortgagepage .mPanel .save").live("click", function (e) { e.preventDefault(); var multi = $(this).hasClass("multisave"); if ($(this).hasClass("beensaved")) { return false; } var href = $(this).attr("href"); var saved = $("#saved"); var textupdate = (multi) ? "All saved" : "Saved"; $(this).text(textupdate).addClass("beensaved"); var id = href.split("Save/")[1]; var url = (multi) ? sitePrepend + "/services/AJAXSaveAllMortgages/ALL" : sitePrepend + "/services/AJAXSaveMortgage/" + id; $.get(url, function (data) { $.get(sitePrepend + "/Find/Find-A-Mortgage/", function (data) { var savedmortgages = $(data).find(".list"); saved.find("h2 a span").text("(" + savedmortgages.length + ")"); var suffix = (savedmortgages.length == 1) ? "" : "s"; saved.find(".highlight strong strong").text(savedmortgages.length + " saved mortgage" + suffix); saved.find("h2").addClass("saveon"); var panes = saved.find(".panes .highlight"); var lastpanel = $("#mortgageFinderSavedHeader"); if (multi) { saved.find(".list").remove(); savedmortgages.each(function () { $(this).insertAfter(lastpanel); $(".mPanel .panels .list .expand a.save").text("Saved").addClass("beensaved"); $(this).find(".collapsed").hideshow(); $(this).find(".flex").helppopup(); }); } else { var savedmortgage = savedmortgages.eq("0"); savedmortgage.insertAfter("#mortgageFinderSavedHeader"); savedmortgage.find(".collapsed").hideshow(); savedmortgage.find(".flex").helppopup(); } setTimeout(function () { saved.find("h2").removeClass("saveon"); }, 500); }); }); }); if ($(".jargonbuster").length > 0) { $(".jargonbuster").jargon(); } if ($("#map").length > 0) { $("#map").removeClass("hidden"); $("#mapdetails .regions").addClass("hidden"); $("#branches").hide(); $("#map").insertmap(); } if ($(".budgetplantool").length > 0) { $("#helper").budgetplan(); } if ($(".borrowingtool").length > 0) { $("#helper").borrow(); } if ($("#ask").length > 0) { $("#ask").askaq(); } if ($("#graph").length > 0) { $("#graph").plotGraph(); } $("#seewhathappens").live("click", function (e) { e.preventDefault(); $.overlay(); }); if ($(".collapsed").length != 0) { $(".mPanel .collapsed, #saved .collapsed").hideshow(); } if ($("#routealpha").length) { $.steponealpha(); } if ($("#routebeta").length) { $.steponebeta(); } if ($("#steptwo #morttype").length) { $.steptwo(); } if ($("#stepthree #fees").length) { $.stepthree(); } $("#toolbar a").toolSelect(); if ($("#LoanToValue").length != 0) { $("#LoanToValue").selectToUISlider(); } if ($("#Term").length != 0) { $("#Term").selectToUISlider(); } if ($(".sidetabs").length != 0) { $("dl.sidetabs:not('#spending dl.sidetabs')").tab(); } if ($("#MonthlyPaymentAmount").length != 0) { $("#MonthlyPaymentAmount").addcommas(); } $("#learnabout dl, #branches dl").accordion(); $("#tools a.overlay, .tool, .introtool .content h2 a, .toolpage a.overlay, .last.overlay, .contenttool").overlay(); if ($(".glossary").length != 0) { $(".glossary").helppopup(); } $(".inlinehelp, .flex").helppopup(); $("#inline .radio").css({ position: "absolute", left: "-9999em" }); $("#inline .button").addClass("hidden"); $("#inline label .radio").click(function (e) { if ($(this).attr("value") == "existing") { e.preventDefault(); $(this).siblings("span").find("#helpcopy").removeClass("hidden"); $(this).parents("label").addClass("reset"); } else { $(this).parents("form").submit(); } }); if ($("#allmortgages").length != 0) { $("#allmortgages").tabulate(); } if ($("#firsttimebuyer").length > 0) { $(".step label").hover(function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); }); } }); function renderMap() { if (!$("#map").length) { return false; } var map = new GMap2($("#map").get(0)); var startLocation = new GLatLng(54.559322587438636, -3.7748046875); map.setCenter(startLocation, 5); function addMapEvents(poly, polyhover, desc, areacenter, zoomlevel, name) { GEvent.addListener(poly, "mouseover", function () { $("#maparea").html(desc).show(); map.addOverlay(polyhover); }); GEvent.addListener(poly, "mouseout", function () { $("#maparea").hide(); map.removeOverlay(polyhover); }); GEvent.addListener(polyhover, "click", function () { $("#mapcontrols").show(); getJSONpoints(poly, name); removePolygons(); }); } function removePolygons() { $("#maparea").hide(); for (var i = 0; i < allareas.length; i++) { map.removeOverlay(allareas[i]); map.removeOverlay(allareashover[i]); } } function resetPolygons(allareas) { map.setCenter(startLocation, 5); for (var i = 0; i < allareas.length; i++) { map.addOverlay(allareas[i]); } for (var i = 0; i < zJSON.length; i++) { map.removeOverlay(markers[i]); } $("#list").html(""); $("#mapcontrols,#branches").hide(); $("#mapdetails").show(); } $("#back, .searchagain").live("click", function (e) { e.preventDefault(); resetPolygons(allareas); $("#mapmessage").hide(); $("#branch").hide(); }); $("#zoomin").click(function (e) { e.preventDefault(); map.zoomIn(); $("#mapmessage").hide(); }); $("#zoomout").click(function (e) { e.preventDefault(); map.zoomOut(); $("#mapmessage").hide(); }); $(".showlist").live("click", function (e) { e.preventDefault(); $("#branch").hide(); $("#branches").show(); }); $("#findbranch").live("click", function (e) { e.preventDefault(); var strlookup = $("#searchTerm").val(); if (strlookup == "") { mapError("Please enter either a postcode, city or town", "#searchTerm"); } else { getJSONlookup(strlookup); } }); $("#searchTerm").keydown(function (e) { e = e || window.event; if (e.keyCode == 13) { if ($(this).val() == "") { mapError("Please enter either a postcode, city or town", "#searchTerm"); } else { getJSONlookup($(this).val()); } return false; } }); function getBounds(pointArray) { if (pointArray.length == 1) { var mapCenter = new GLatLng(pointArray[0].Lat, pointArray[0].Lng); map.setCenter(mapCenter, 7); } else { var minLat; var maxLat; var minLng; var maxLng; for (var i = 0; i < pointArray.length; i++) { if (minLat == null || pointArray[i].Lat < minLat) { minLat = pointArray[i].Lat; } if (minLng == null || pointArray[i].Lng < minLng) { minLng = pointArray[i].Lng; } if (maxLat == null || pointArray[i].Lat > maxLat) { maxLat = pointArray[i].Lat; } if (maxLng == null || pointArray[i].Lng > maxLng) { maxLng = pointArray[i].Lng; } } var bounds = new GLatLngBounds; bounds.extend(new GLatLng(minLat, minLng)); bounds.extend(new GLatLng(maxLat, maxLng)); map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); } } var zJSON; function getJSONlookup(str, type) { var strurl = sitePrepend + "/tools/JSONBranchesBySearchTerm/?searchTerm=" + str; $.getJSON(strurl, function (data) { if (data.length == 0) { fieldid = "#searchTerm"; var message; if ($("#searchTerm").val() == "") { message = "Sorry, we couldn't find any results for your search"; } mapError(message, fieldid); return false; } $("#mapcontrols").show(); removePolygons(); zJSON = data; getBounds(zJSON); showMarkers(); removeErrors(); }); var url = sitePrepend + "/tools/AJAXBranchesBySearchTerm/"; var svClient = new GStreetviewClient(); $.post(url, { searchTerm: str }, function (data) { if ($(data).find("dl dd").length == 0) { mapError("Sorry, we couldn't find any results for your search", "#searchTerm"); return false; } $("#mapdetails").hide(); if ($("#branches").length > 0) { $("#branches").show().replaceWith(data); } else { $("#map").after(data); } $("#branches").find("dt").each(function (i) { $(this).removeClass("open").find("a").click(function (e) { e.preventDefault(); GEvent.trigger(markers[i], "click"); }); }); $("#branches").addClass("enhanced").find("dd").each(function (i) { var that = $(this); that.removeClass("open"); var urlImageStr; var gLatLng = new GLatLng(zJSON[i].Lat, zJSON[i].Lng); var branchdetails = $(this).find(".branchdetails").clone(); function callback(latlng) { urlImageStr = (latlng == null) ? "/_mortgage_assets/media/default-medium.png" : "http://cbk0.google.com/cbk?output=thumbnail&w=88&h=60&ll=" + zJSON[i].Lat + "," + zJSON[i].Lng; that.prepend("<img src='" + urlImageStr + "'"); } svClient.getNearestPanoramaLatLng(gLatLng, callback); var link = $("<a class='showmore arrowlink' href='#'>show more details</a>").click(function (e) { e.preventDefault(); $("#branches").hide(); $("#branch").show().find("h2 span").html(zJSON[i].Name).end().find("img").attr("src", urlImageStr.replace("w=88&h=60", "w=268&h=80").replace("medium", "large")).end().find(".branchdetails").html(branchdetails.html()); }); $("<p class='details'></p>").appendTo(that).html(link); }); }); } function mapError(emessage, fid) { var prow = $(fid).parents(".row"); if (prow.find(".field-validation-error").length) { prow.find(".field-validation-error").text(emessage); } else { $(fid).parents(".row").prepend("<p><span class='field-validation-error'>" + emessage + "</span></p>"); } prow.siblings(".row").find(".field-validation-error").parents("p").remove(); } function removeErrors() { $(".field-validation-error").parents(".row").find("input").val("").end().end().parents("p").remove(); } function getJSONpoints(points, name) { var strurl = sitePrepend + "/services/branches/" + points.getBounds().getSouthWest().lat() + "/" + points.getBounds().getSouthWest().lng() + "/" + points.getBounds().getNorthEast().lat() + "/" + points.getBounds().getNorthEast().lng() + "/"; var areaname; switch (name) { case "scotland": areaname = "Scotland"; break; case "nireland": areaname = "Northern Ireland"; break; case "nw": areaname = "North West"; break; case "northeast": areaname = "North East"; break; case "yorks": areaname = "Yorkshire"; break; case "wales": areaname = "Wales"; break; case "wmid": areaname = "West Midlands"; break; case "emid": areaname = "East Midlands"; break; case "eanglia": areaname = "East Anglia"; break; case "swest": areaname = "South West"; break; case "seast": areaname = "South East"; break; case "london": areaname = "London"; break; } var strurl = sitePrepend + "/tools/JSONBranchesByRegion/?region=" + areaname; $.getJSON(strurl, function (data) { zJSON = data; getBounds(zJSON); showMarkers(); removeErrors(); }); var url = sitePrepend + "/tools/AJAXBranchesByRegion/"; var svClient = new GStreetviewClient(); $.post(url, { region: areaname }, function (data) { $("#mapdetails").hide(); if ($("#branches").length > 0) { $("#branches").show().replaceWith(data); } else { $("#map").after(data); } $("#branches").find("dt").each(function (i) { $(this).removeClass("open").find("a").click(function (e) { e.preventDefault(); GEvent.trigger(markers[i], "click"); }); }); $("#branches").addClass("enhanced").find("dd").each(function (i) { var that = $(this); that.removeClass("open"); var urlImageStr; var gLatLng = new GLatLng(zJSON[i].Lat, zJSON[i].Lng); var branchdetails = $(this).find(".branchdetails").clone(); function callback(latlng) { urlImageStr = (latlng == null) ? "/_mortgage_assets/media/default-medium.png" : "http://cbk0.google.com/cbk?output=thumbnail&w=88&h=60&ll=" + zJSON[i].Lat + "," + zJSON[i].Lng; that.prepend("<img src='" + urlImageStr + "'"); } svClient.getNearestPanoramaLatLng(gLatLng, callback); var link = $("<a class='showmore arrowlink' href='#'>show more details</a>").click(function (e) { e.preventDefault(); $("#branches").hide(); $("#branch").show().find("h2 span").html(zJSON[i].Name).end().find("img").attr("src", urlImageStr.replace("w=88&h=60", "w=268&h=80").replace("medium", "large")).end().find(".branchdetails").html(branchdetails.html()); }); $("<p class='details'></p>").appendTo(that).html(link); }); }); } var markers = []; function showMarkers() { var ico = new GIcon(); ico.image = "/_mortgage_assets/js/markers/image.png"; ico.shadow = "/_mortgage_assets/js/markers/shadow.png"; ico.iconSize = new GSize(29, 29); ico.shadowSize = new GSize(44, 29); ico.iconAnchor = new GPoint(15, 29); ico.infoWindowAnchor = new GPoint(15, 0); ico.printImage = "/_mortgage_assets/js/markers/printImage.gif"; ico.mozPrintImage = "/_mortgage_assets/js/markers/mozPrintImage.gif"; ico.printShadow = "/_mortgage_assets/js/markers/printShadow.gif"; ico.transparent = "/_mortgage_assets/js/markers/transparent.png"; ico.imageMap = [17, 0, 19, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, 6, 26, 7, 26, 8, 27, 9, 27, 10, 28, 11, 28, 12, 28, 13, 28, 14, 28, 15, 28, 16, 28, 17, 28, 18, 28, 19, 28, 20, 28, 21, 27, 22, 27, 23, 26, 24, 25, 25, 24, 26, 23, 27, 22, 28, 13, 28, 13, 27, 13, 26, 13, 25, 13, 24, 13, 23, 13, 22, 11, 21, 10, 20, 9, 19, 9, 18, 0, 17, 0, 16, 0, 15, 0, 14, 0, 13, 0, 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 1, 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 1, 7, 0]; for (var i = 0; i < zJSON.length; i++) { var point = new GLatLng(zJSON[i].Lat, zJSON[i].Lng); marker = new GMarker(point, { icon: ico }); map.addOverlay(marker); markers[i] = marker; } var svClient = new GStreetviewClient(); $(markers).each(function (i, marker) { var urlImageStr; var gLatLng = new GLatLng(marker.getLatLng().lat(), marker.getLatLng().lng()); function callback(latlng) { urlImageStr = (latlng == null) ? "/_mortgage_assets/media/default-medium.png" : "http://cbk0.google.com/cbk?output=thumbnail&w=88&h=60&ll=" + latlng.lat() + "," + latlng.lng(); } svClient.getNearestPanoramaLatLng(gLatLng, callback); GEvent.addListener(marker, "click", function () { displayPoint(marker, i); }); }); $("#mapmessage").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE)); function displayPoint(marker, index) { if ($("#branch").is(":visible")) { $("#branches dd:eq(" + index + ") .showmore").trigger("click"); } $("#branches dt:eq(" + index + "),#branches dd:eq(" + index + ")").addClass("open"); $("#branches dt:not(:eq(" + index + ")),#branches dd:not(:eq(" + index + "))").removeClass("open"); $("#mapmessage").hide(); if (map.getCenter().lat() == marker.getLatLng().lat() && map.getCenter().lng() == marker.getLatLng().lng()) { addMiniMapMessage(); } else { var moveEnd = GEvent.addListener(map, "moveend", function () { addMiniMapMessage(); GEvent.removeListener(moveEnd); map.setCenter(marker.getLatLng()); }); map.panTo(marker.getLatLng()); } function addMiniMapMessage() { var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng()); var urlImageStr; var gLatLng = new GLatLng(marker.getLatLng().lat(), marker.getLatLng().lng()); function callback(latlng) { urlImageStr = (latlng == null) ? "/_mortgage_assets/media/default-mini.png" : "http://cbk0.google.com/cbk?output=thumbnail&w=38&h=38&ll=" + latlng.lat() + "," + latlng.lng(); $("#mapmessage").html("<p><strong>" + zJSON[index].Name + "</strong>" + zJSON[index].FirstLineOfAddress.replace(/,/g, "") + "</p><img src='" + urlImageStr + "'/>").show().css({ top: markerOffset.y, left: markerOffset.x }); } svClient.getNearestPanoramaLatLng(gLatLng, callback); } } } var bordercolor = "#fff"; var borderweight = 1; var borderopacity = 1; var bgcolor = "#fff"; var bgopacity = 0.3; var bordercolorhover = "#F00480"; var borderweighthover = 1; var borderopacityhover = 1; var bgcolorhover = "#fff"; var bgopacityhover = 0.3; var scotlandpoints = [new GLatLng(58.64217875870233, -7.66845703125), new GLatLng(58.64217875870233, -0.54931640625), new GLatLng(55.66454366013027, -0.54931640625), new GLatLng(55.66454366013027, -7.66845703125), new GLatLng(58.64217875870233, -7.66845703125)]; var scotland = new GPolygon(scotlandpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var scotlandhover = new GPolygon(scotlandpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(scotland); addMapEvents(scotland, scotlandhover, "scotland", new GLatLng(56.97891594203979, -4.54833984375), 7, "scotland"); var nirelandpoints = [new GLatLng(55.66454366013027, -8.23974609375), new GLatLng(55.66454366013027, -5.25146484375), new GLatLng(54.21512428246311, -5.25146484375), new GLatLng(54.21512428246311, -8.23974609375), new GLatLng(55.66454366013027, -8.23974609375)]; var nireland = new GPolygon(nirelandpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var nirelandhover = new GPolygon(nirelandpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(nireland); addMapEvents(nireland, nirelandhover, "northern&nbsp;ireland", new GLatLng(54.584796743678744, -6.9927978515625), 8, "nireland"); var northeastpoints = [new GLatLng(55.66454366013027, -2.26318359375), new GLatLng(55.66454366013027, 0.59326171875), new GLatLng(54.21512428246311, 0.59326171875), new GLatLng(54.21512428246311, -2.26318359375), new GLatLng(55.66454366013027, -2.26318359375)]; var northeast = new GPolygon(northeastpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var northeasthover = new GPolygon(northeastpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(northeast); addMapEvents(northeast, northeasthover, "north&nbsp;east", new GLatLng(54.85447755156707, -1.64794921875), 8, "northeast"); var nwpoints = [new GLatLng(55.66454366013027, -5.25146484375), new GLatLng(55.66454366013027, -2.26318359375), new GLatLng(54.21512428246311, -2.26318359375), new GLatLng(54.21512428246311, -1.73583984375), new GLatLng(53.24643142993082, -1.73583984375), new GLatLng(53.24643142993082, -5.25146484375), new GLatLng(55.66454366013027, -5.25146484375)]; var nw = new GPolygon(nwpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var nwhover = new GPolygon(nwpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(nw); addMapEvents(nw, nwhover, "north&nbsp;west", new GLatLng(54.15278427641255, -2.79052734375), 8, "nw"); var yorkspoints = [new GLatLng(54.21512428246311, -1.73583984375), new GLatLng(54.21512428246311, 1.12455078125), new GLatLng(53.24643142993082, 1.12455078125), new GLatLng(53.24643142993082, -1.73583984375), new GLatLng(54.21512428246311, -1.73583984375)]; var yorks = new GPolygon(yorkspoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var yorkshover = new GPolygon(yorkspoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(yorks); addMapEvents(yorks, yorkshover, "yorkshire", new GLatLng(53.72921671251272, -1.351318359375), 8, "yorks"); var walespoints = [new GLatLng(53.24643142993082, -5.47119140625), new GLatLng(53.24643142993082, -2.73896484375), new GLatLng(51.5201375693711, -2.73896484375), new GLatLng(51.5201375693711, -5.47119140625), new GLatLng(53.24643142993082, -5.47119140625)]; var wales = new GPolygon(walespoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var waleshover = new GPolygon(walespoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(wales); addMapEvents(wales, waleshover, "wales", new GLatLng(52.35547370875268, -3.8232421875), 7, "wales"); var wmidpoints = [new GLatLng(53.24643142993082, -2.73896484375), new GLatLng(53.24643142993082, -0.93896484375), new GLatLng(51.5201375693711, -0.93896484375), new GLatLng(51.5201375693711, -2.73896484375), new GLatLng(53.24643142993082, -2.73896484375)]; var wmid = new GPolygon(wmidpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var wmidhover = new GPolygon(wmidpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(wmid); addMapEvents(wmid, wmidhover, "west&nbsp;midlands", new GLatLng(52.532931647583325, -1.494140625), 8, "wmid"); var emidpoints = [new GLatLng(53.24643142993082, -0.93896484375), new GLatLng(53.24643142993082, 0.53896484375), new GLatLng(51.9201375693711, 0.53896484375), new GLatLng(51.9201375693711, -0.93896484375), new GLatLng(53.24643142993082, -0.93896484375)]; var emid = new GPolygon(emidpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var emidhover = new GPolygon(emidpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(emid); addMapEvents(emid, emidhover, "east&nbsp;midlands", new GLatLng(52.532931647583325, -0.230712890625), 8, "emid"); var londonpoints = [new GLatLng(51.9201375693711, -0.93896484375), new GLatLng(51.9201375693711, 0.53896484375), new GLatLng(51.1201375693711, 0.53896484375), new GLatLng(51.1201375693711, -0.93896484375), new GLatLng(51.9201375693711, -0.93896484375)]; var london = new GPolygon(londonpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var londonhover = new GPolygon(londonpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(london); addMapEvents(london, londonhover, "london", new GLatLng(51.36492148825955, -0.0494384765625), 8, "london"); var eangliapoints = [new GLatLng(53.24643142993082, 0.53896484375), new GLatLng(53.24643142993082, 2.21923828125), new GLatLng(51.9201375693711, 2.21923828125), new GLatLng(51.9201375693711, 0.53896484375), new GLatLng(53.24643142993082, 0.53896484375)]; var eanglia = new GPolygon(eangliapoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var eangliahover = new GPolygon(eangliapoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(eanglia); addMapEvents(eanglia, eangliahover, "east&nbsp;anglia", new GLatLng(52.44596613327885, 0.867919921875), 8, "eanglia"); var seastpoints = [new GLatLng(51.1201375693711, -0.93896484375), new GLatLng(51.1201375693711, 0.53896484375), new GLatLng(51.9201375693711, 0.53896484375), new GLatLng(51.9201375693711, 2.41923828125), new GLatLng(50.44118096458178, 2.41923828125), new GLatLng(50.44118096458178, -0.93896484375), new GLatLng(51.1201375693711, -0.93896484375)]; var seast = new GPolygon(seastpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var seasthover = new GPolygon(seastpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(seast); addMapEvents(seast, seasthover, "south&nbsp;east", new GLatLng(51.327179239685634, 0.1043701171875), 8, "seast"); var swestpoints = [new GLatLng(51.5201375693711, -6.30615234375), new GLatLng(51.5201375693711, -0.93896484375), new GLatLng(49.89409650023248, -0.93896484375), new GLatLng(49.89409650023248, -6.30615234375), new GLatLng(51.5201375693711, -6.30615234375)]; var swest = new GPolygon(swestpoints, bordercolor, borderweight, borderopacity, bgcolor, bgopacity); var swesthover = new GPolygon(swestpoints, bordercolorhover, borderweighthover, borderopacityhover, bgcolorhover, bgopacityhover); map.addOverlay(swest); addMapEvents(swest, swesthover, "south&nbsp;west", new GLatLng(50.77815527465925, -3.0322265625), 7, "swest"); var allareas = [scotland, nireland, northeast, nw, yorks, wales, wmid, emid, london, eanglia, seast, swest]; var allareashover = [scotlandhover, nirelandhover, northeasthover, nwhover, yorkshover, waleshover, wmidhover, emidhover, londonhover, eangliahover, seasthover, swesthover]; } jQuery.fn.jargon = function () { $(this).addClass("busting"); $(this).find("h2:first").addClass("open"); $(this).find("dl:first").addClass("open"); $(this).find("ul li:first").addClass("here"); $(this).find("ul a").click(function (e) { e.preventDefault(); if ($(this).hasClass("disabled") || $(this).hasClass("here")) { return false; } $(this).parent("li").addClass("here").siblings("li.here").removeClass("here"); var assocId = $("#jargon" + ($(this).attr("href")).split("#")[1].toLowerCase()); assocId.addClass("open").prev("h2").addClass("open").end().siblings("dl.open").removeClass("open").prev("h2").removeClass("open"); }); }; jQuery.fn.tab = function () { return this.each(function () { var manual = $(this).hasClass("manual"); $(this).addClass("tabslide"); $(this).find("dd:not('dd dd'):not(:first)").addClass("hidden"); $(this).find("dd:not('dd dd')").addClass("slidedd").prepend("<span class='arrowhead'></span>"); var hidehtml = $("<span class='hide'>hide<em>&ndash;</em></span>"); var showhtml = $("<span class='show'>show<em>+</em></span>"); $(this).find("dt:not('dd dt'):first").addClass("open first").append(hidehtml.clone()); $(this).find("dt:not('dd dt'):last").addClass("last"); $(this).find("dt:not('dd dt'):not(:first)").append(showhtml.clone()); $(this).find("dt:not('dd dt')").addClass("slidedt").each(function () { $(this).click(function (e) { e.preventDefault(); if ($(this).hasClass("open")) { $(this).removeClass("open").find("span").replaceWith(showhtml.clone()); $(this).next("dd").addClass("hidden"); } else { $(this).find("span").replaceWith(hidehtml.clone()); if (manual) { $(this).addClass("open"); $(this).next("dd").removeClass("hidden"); } else { $(this).addClass("open").siblings("dt.open").removeClass("open").find("span").replaceWith(showhtml.clone()); $(this).next("dd").removeClass("hidden").siblings("dd").addClass("hidden"); } } }); }); }); }; jQuery.fn.accordion = function () { $(this).each(function () { var items = $(this).find("dt"); items.each(function () { var linkparent = $(this); var linksibling = $(this).next("dd"); linkparent.removeClass("open"); linksibling.removeClass("open"); $(this).wrapInner("<a href='#'></a>").click(function (e) { e.preventDefault(); if (linkparent.hasClass("open")) { linkparent.removeClass("open"); linksibling.removeClass("open"); } else { linkparent.addClass("open").siblings("dt.open").removeClass("open"); linksibling.addClass("open").siblings("dd.open").removeClass("open"); } }); }); }); }; $.overlay = function () { var wrap = getWrap(); $("body").append(wrap); $("#wrap").show(); var closebtn = $("<a href='#' class='close'>close</a>").click(function (e) { e.preventDefault(); $("#wrap").trigger("click"); }); var panesclone = $("#saved .panes").clone(); panesclone.css({ position: "relative" }).prepend(closebtn).find("#savednextsteps").remove(); if (!$.browser.msie) { var loadedcontents = overlayContent(($("#mortgagepage").height() - $("#mInfo").height() + 10), 225, "5px 5px 0"); $("#content").append(loadedcontents); $("#loaded").append(panesclone); } else { if ($.browser.version != "6.0") { var loadedcontents = overlayContent(($("#mortgagepage").height() - $("#mInfo").height() + 10), 170, "5px 50px 0 58px"); var shadows = addOverlayShadows(); $("#content").append(loadedcontents); $("#loaded").append(panesclone); $(shadows).each(function () { var that = $(this); $("#loaded").append(that); }); } else { var loadedcontents = overlayContent(($("#mortgagepage").height() - $("#mInfo").height() + 10), 225, "0 0 0"); var shadows = addOverlayShadows(); $("#content").append(loadedcontents); var newmarkup = $("<div style='width:100%;height:100%;background:#fff;position:relative;z-index:9999;padding:0 5px'></div>").html(panesclone); $("#loaded").append(newmarkup); $(shadows).each(function () { var that = $(this); $("#loaded").append(that); }); } } var change = 0.25; var rate = $("#loaded #ratechanger #rate strong"); var variable = $("#loaded #ratechanger #rate #variable"); var trackers = $("#loaded .trackerpanel"); var fixed = $("#loaded .fixedpanel"); fixed.addClass("hidden"); $("#loaded .highlight, #loaded #savednextsteps").addClass("hideme"); panesclone.find("#ratechanger").removeClass("hidden"); panesclone.find(".collapsed").hideshow(); panesclone.find(".flex").helppopup(); if (trackers.length > 0) { panesclone.find("#rateedit").removeClass("hidden"); } else { panesclone.find("#notracker").removeClass("hidden"); } var controlpanel = panesclone.find("#ratechanger"); controlpanel.find("#increaserate").bind("click", function (e) { e.preventDefault(); variable.text("increase"); var currentvalue = Math.round(parseFloat(rate.text()) * 100); var roundedchange = Math.round(change * 100); var outcome = (parseInt(currentvalue) + parseInt(roundedchange)) / 100; rate.text(outcome); setVariable(outcome); changeRate(outcome); }); controlpanel.find("#decreaserate").bind("click", function (e) { e.preventDefault(); variable.text("decrease"); var currentvalue = Math.round(parseFloat(rate.text()) * 100); var roundedchange = Math.round(change * 100); var outcome = (parseInt(currentvalue) - parseInt(roundedchange)) / 100; rate.text(outcome); setVariable(outcome); changeRate(outcome); }); function setVariable(rate) { var txt = (rate < 0) ? "decrease" : "increase"; variable.text(txt); } trackers.each(function () { $(this).addClass("changingrates"); var monthlypay = $(this).find(".container dl dd.monthly em.MonPay"); var overallrate = $(this).find(".container dl dd em.IntRate"); var initialpayment = parseFloat(monthlypay.text()); var initialrate = parseFloat(overallrate.text()); var propval = $(this).find(".container .extradetails .apply .pvalue").text().replace(/,/g, ""); var depval = $(this).find(".container .extradetails .apply .dvalue").text().replace(/,/g, ""); var years = $(this).find(".container .extradetails .apply .yr").text(); var principal = $(this).find(".container .extradetails .apply .dvalue").text(); principal = clearCommas(principal); var months = parseInt(years) * 12; var fees = $(this).find(".container dd .fees").text(); fees = fees.substring(1, fees.length); $(this).data("monthlypay", monthlypay).data("overallrate", overallrate).data("initialpayment", initialpayment).data("initialrate", initialrate).data("principal", principal).data("fees", fees).data("months", months); }); function changeRate(ratechange) { trackers.each(function () { var or = Math.round($(this).data("initialrate") * 100) + Math.round(ratechange * 100); or = (or / 100 < 0) ? 0 : or / 100; $(this).data("overallrate").text(or); var monpayfield = $(this).data("monthlypay"); var NRStrUrl = sitePrepend + "/services/mortgage-monthly-payment/"; NRStrUrl += or + "/"; NRStrUrl += $(this).data("months") + "/"; NRStrUrl += $(this).data("principal") + "/"; NRStrUrl += "0/"; NRStrUrl += $(this).data("fees") + "/"; $.getJSON(NRStrUrl, function (data) { monpayfield.text(Math.round(data)); }); }); } }; function getWrap() { if ($.browser.msie && $.browser.version.substr(0, 1) < 7) { var wrap = $("<div id='wrap' title='click to close'></div>").css({ width: $("body").width() + "px", height: $(document).height() + "px", background: "#000", position: "absolute", top: "0", left: "0", opacity: "0.4", display: "none", "z-index": "11" }); $("html").css({ height: "100%" }); } else { var wrap = $("<div id='wrap' title='click to close'></div>").css({ width: $(document).width() + "px", height: $(document).height() + "px", background: "#000", position: "fixed", top: "0", left: "0", opacity: "0.4", display: "none", "z-index": "11" }); } return wrap; } function overlayContent(height, leftpos, padding) { var loadedcontents = $("<div id='loaded'></div>").css({ background: "#fff", position: "relative", width: "710px", padding: padding, height: "auto", margin: "-" + height + "px 0 5px -5px", "z-index": "99999", "float": "left", display: "inline", left: leftpos + "px" }); if (!$.browser.msie) { loadedcontents.css({ "-moz-box-shadow": "0 0 50px 5px #000", "-webkit-box-shadow": "0 0 100px #000", "box-shadow": "0 0 50px 5px #000" }); } else { if ($.browser.version != "6.0") { loadedcontents.css({ background: "transparent url(/_mortgage_assets/css/images/overlayshadowbg.png) repeat-y 0 0" }); } } return loadedcontents; } function addOverlayShadows() { if ($.browser.version != "6.0") { var shadow = $("<div></div>").css({ height: "50px", padding: "0", width: "820px", "float": "left", display: "inline", zoom: "1", "z-index": "9998", position: "absolute", left: "0" }); var shadowbottom = shadow.clone(); var shadowtop = shadow.clone(); shadowbottom.css({ background: "transparent url(/_mortgage_assets/css/images/overlayshadowbottom.png) no-repeat 0 0", bottom: "-50px" }); shadowtop.css({ background: "transparent url(/_mortgage_assets/css/images/overlayshadowtop.png) no-repeat 0 0", top: "-50px" }); } else { var shadow = $("<div></div>").css({ background: "#000", height: "50px", display: "block", zoom: "1", "float": "left", "z-index": "9998", position: "absolute", filter: "progid:DXImageTransform.Microsoft.Blur(enabled=true,makeShadow=true,pixelRadius=30,shadowOpacity=0.5)" }); var shadowbottom = shadow.clone(); var shadowtop = shadow.clone(); shadowbottom.css({ padding: "5px 5px 0", width: "670px", bottom: "-50px", right: "0" }); shadowtop.css({ width: "720px", top: "-50px", right: "-25px" }); } return [shadowtop, shadowbottom]; } jQuery.fn.overlay = function () { var wrap = getWrap(); $(this).each(function () { var link = $(this).attr("href"); var pagedata; $(this).click(function (e) { e.preventDefault(); $.get(link, function (data) { pageintro = $(data).find("#intro"); pagedata = $(data).find("#helper"); $("body").append(wrap); if (!$.browser.msie) { var loadedcontents = overlayContent(($("#content").height() + 5), 0, "5px 5px 0"); $("#content").append(loadedcontents); $("#loaded").html(pageintro); $("#loaded").append(pagedata); } else { if ($.browser.version != "6.0") { var loadedcontents = overlayContent(($("#content").height() + 5), -50, "5px 55px 0"); var shadows = addOverlayShadows(); $("#content").append(loadedcontents); $("#loaded").html(pageintro); $("#loaded").append(pagedata); $(shadows).each(function () { var that = $(this); $("#loaded").append(that); }); } else { var loadedcontents = overlayContent(($("#content").height() + 5), 0, "0 0 0"); var shadows = addOverlayShadows(); $("#content").append(loadedcontents); var newmarkup = $("<div style='width:100%;height:100%;background:#fff;position:relative;z-index:9999;padding:0 5px'></div>").html(pageintro).append(pagedata); $("#loaded").append(newmarkup); $(shadows).each(function () { var that = $(this); $("#loaded").append(that); }); } } var closebtn = $("<a href='#' class='close'>close</a>").click(function (e) { e.preventDefault(); $("#wrap").trigger("click"); }); if ($.browser.msie && $.browser.version != "6.0") { closebtn.css({ right: "52px" }); } $("#loaded").append(closebtn); if (link.indexOf("Jargon-Buster") != -1) { $(".jargonbuster").jargon(); } if (link.indexOf("Branch-Finder") != -1) { $("#map").removeClass("hidden"); $("#mapdetails .regions").addClass("hidden"); $("#branches").hide(); $("#map").insertmap(); } if (link.indexOf("Budget-Planner") != -1) { $("#helper").budgetplan(); } if (link.indexOf("How-Much-Can-I-Borrow") != -1) { $("#helper").borrow(); } if (link.indexOf("Ask-A-Question") != -1) { $("#ask").askaq(); } if (link.indexOf("Overpayment-Calculator") != -1) { $("#graph").plotGraph(); } checkResizing(); wrap.fadeIn("1000"); $("html").animate({ scrollTop: 0 }, "1000"); }); }); }); $("#wrap").live("click", function () { var that = $(this); $("#loaded").remove(); that.fadeOut("1000", function () { that.remove(); if ($("#saved .panes").length > 0) { $("#saved .panes").css({ "z-index": "1", background: "transparent" }); } }); }); function getOverlayWidth() { var bw = $("body").width(); var dw = $(document).width(); var ww = $(window).width(); return ((dw > ww) ? (ww < bw) ? bw : ww : dw) + "px"; } function getOverlayHeight() { var bh = $("body").height(); var dh = $(document).height(); var wh = $(window).height(); return (dh > bh) ? dh + "px" : "100%"; } var startWidth = getOverlayWidth(); var startHeight = getOverlayHeight(); function checkResizing() { if ($("#wrap").length != 1) { return false; } var currentWidth = getOverlayWidth(); var currentHeight = getOverlayHeight(); if (startWidth != currentWidth || startHeight != currentHeight) { if ($.browser.msie && $.browser.version.substr(0, 1) < 7) { $("#wrap").css({ width: $("body").width() + "px", height: $("body").height() + "px", position: "absolute", top: "0", left: "0" }); } else { $("#wrap").css({ width: currentWidth, height: currentHeight }); startWidth = currentWidth; startHeight = currentHeight; } } if ($.browser.msie && $.browser.version.substr(0, 1) < 7) { $("#wrap").css({ width: $("body").width() + "px", height: $("body").height() + "px", position: "absolute", top: "0", left: "0" }); } } $(window).resize(checkResizing); if ($.browser.msie && $.browser.version.substr(0, 1) < 7) { $(window).scroll(checkResizing); } }; $.fn.borrow = function () { var URL = sitePrepend + "/Tools/JSONBorrow"; var resultpanel = $("#borrowResult"); $("input.comma").addcommas(); $("#btnBorrow").live("click", function (e) { e.preventDefault(); $.post(URL, $("#borrowCalc").serialize(), function (data) { var jd = data; if (isNaN(parseInt(jd))) { $(".field-validation-error").addClass("invalid"); resultpanel.addClass("hidden"); for (var i = 0; i < jd.length; i++) { var lbl = $("label[for='" + jd[i].Field + "']"); if (lbl.find(".field-validation-error").length) { var lblError = lbl.find(".field-validation-error"); if (lblError.hasClass("invalid") && lblError.text() == jd[i].Message) { lblError.removeClass("invalid"); } else { lblError.text(jd[i].Message).removeClass("invalid"); } } else { lbl.append("<span class='field-validation-error'>" + jd[i].Message + "</span>"); } $(".invalid").remove(); } } else { $(".field-validation-error").remove(); resultpanel.removeClass("hidden").find(".value .amount").html("&pound;" + jd); var p = resultpanel.position(); $("html").animate({ scrollTop: p.top }, "1000"); } }); }); }; $.fn.budgetplan = function () { var validating = false; $("#spending").addClass("hidden"); $("#bpFindButton").addClass("hidden"); $("input#MonthlyIncomeEmploy, input#MonthlyIncomeOther, #spending .text").addcommas(); var nextstepbtn = $('<div class="row nextstep"><span class="button"><input type="submit" value="Next step"/></span></div>'); var dlist = $(this).find("dl.sidetabs"); var dds = dlist.find("dd:not(:last)"); dds.append(nextstepbtn); dlist.tab(); $("#income").append('<div class="row nextstep"><span class="button"><input id="openSpending" type="submit" value="Next step"/></span></div>'); dds.find(".button input").click(function (e) { e.preventDefault(); $(this).parents("dd").next("dt").trigger("click"); }); $("#spending .tabnavigation a").live("click", function (e) { e.preventDefault(); validateAllFields(); }); $(".CalcBudget").click(function (e) { e.preventDefault(); validateAllFields(); var results = $("#income .results"); var p = results.position(); $("html").animate({ scrollTop: p.top }, "1000"); }); $("#openSpending").click(function (e) { e.preventDefault(); validateAllFields(); if ($(".field-validation-error").length == 0 && $("#MonthlyIncomeEmploy").val() != "") { $(this).parents(".nextstep").addClass("hidden"); $("#spending").removeClass("hidden"); $("#bpFindButton").removeClass("hidden"); } }); function validateAllFields() { $(".field-validation-error").addClass("invalid"); validating = true; function checkHeights() { var that = $("#spending"); that.find("dd.tabsection").height("auto"); var wraph = that.find(".tabwrap").height(); var openh = that.find("dd.open").height(); if (wraph > openh) { that.find("dd.open").height(wraph).siblings("dd.tabsection").removeAttr("style"); } } var URL = sitePrepend + "/Tools/JSONPlanner"; $.post(URL, $("#bPlan").serialize(), function (data) { var jd = eval("(" + data + ")"); if (jd.MonthlyIncome != null) { if ($("#monthlyIncTotal").text() != jd.MonthlyIncome || $("#monthlySpendTotal").text() != jd.MonthlySpending || $("#amountRemaining").text() != jd.AmountRemaining) { $("#monthlyIncTotal").text((jd.MonthlyIncome).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); $("#monthlySpendTotal").text((jd.MonthlySpending).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); $("#amountRemaining").text((jd.AmountRemaining).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); $("#income .results").css({ background: "#FFF6D9", borderColor: "#EDD3A3" }).animate({ backgroundColor: "#fff", borderBottomColor: "#fff", borderTopColor: "#fff", borderLeftColor: "#fff", borderRightColor: "#fff" }, 1500); validating = false; } } else { for (var i = 0; i < jd.length; i++) { var lbl = $("label[for='" + jd[i].Field + "']"); if (lbl.find(".field-validation-error").length) { var lblError = lbl.find(".field-validation-error"); if (lblError.hasClass("invalid") && lblError.text() == jd[i].Message) { lblError.removeClass("invalid"); } else { lblError.text(jd[i].Message).removeClass("invalid"); } } else { lbl.append("<span class='field-validation-error'>" + jd[i].Message + "</span>"); } } } $(".invalid").remove(); checkHeights(); }, "JSON"); } $("#bPlan input.text").blur(validateAllFields); }; $.fn.askaq = function () { var btn = $(this).find(".button input"); var frm = $(this).parent("form"); var resset = $("#resultSet"); var frame = resset.find("#framepanel"); btn.live("click", function (e) { e.preventDefault(); var url = frm.attr("action") + "?" + frm.serialize(); window.open(url, "ask", "width=640,height=800"); }); }; $.fn.addcommas = function () { return this.each(function () { var that = $(this); var store; function addCommas() { if (store != hidden.val()) { var val = $(this).val(); var keypos = getSelRange(this); var lenBefore = getKeyPosCommaLen($(this).val().toString(), keypos); var commaless = hidden.val().replace(/,/g, ""); hidden.val(commaless.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")); that.val(commaless); var lenAfter = getKeyPosCommaLen($(this).val(), keypos); var len = lenAfter - lenBefore; keypos = keypos + len; setSelRange(this, keypos, keypos); store = hidden.val(); } else { return false; } } var hidden = $("<input type='text' class='text' maxLength='11'/>"); hidden.keyup(addCommas).insertAfter(that); hidden.val(that.val()); that.hide(); addCommas(); }); }; $.fn.hideshow = function () { $(".extradetails").addClass("hidden"); return this.each(function () { $(this).click(function (e) { e.preventDefault(); $(this).parents(".list").find(".extradetails").toggleClass("hidden"); ($(this).hasClass("expanded")) ? $(this).removeClass("expanded") : $(this).addClass("expanded"); }); }); }; $.fn.savemortgages = function () { var that = $(this); $(this).find("h2.hidden").removeClass("hidden"); $(this).find("p.hidden").removeClass("hidden"); var heading = $(this).find("h2 a"); var panes = $(this).find(".panes"); panes.addClass("hidden"); heading.bind("click", function (e) { e.preventDefault(); if (that.hasClass("showingsaved")) { that.removeClass("showingsaved"); panes.addClass("hidden"); $(".mPanel .highlight").removeClass("hideme"); } else { that.addClass("showingsaved"); panes.removeClass("hidden"); $(".mPanel .highlight").addClass("hideme"); } }); }; $.fn.tabulate = function () { var linkitems = $(this).find(".tabheading li a"); var lc = window.location.toString(); if (lc.indexOf("#") != -1) { var anc = "#" + lc.split("#")[1]; $(this).find(".tabheading li a[href=" + anc + "]").parent("li").addClass("here").siblings("li.here").removeClass("here"); checktabs(anc); } else { $(".mortgagerange:not('#ftbmortrge')").addClass("hidden"); linkitems.eq(0).parent("li").addClass("here"); } linkitems.each(function (e) { $(this).click(function (e) { e.preventDefault(); var pli = $(this).parent("li"); if (pli.hasClass("here")) { return false; } else { pli.addClass("here").siblings("li.here").removeClass("here"); checktabs($(this).attr("href")); } }); }); function showAB_Elements(show) { var myStyle; if (show == true) { myStyle = "block"; } else { myStyle = "none"; } var myElement = document.getElementById("calcRhnNotBTL"); if (myElement != null) { myElement.style.display = myStyle; } var allLinks = document.links; for (var i = 0; i < allLinks.length; i++) { if (allLinks[i].className.indexOf("mortABCalcLink") != -1) { allLinks[i].style.display = myStyle; } } } function checktabs(item) { var footerText = document.getElementById("footerMassage"); footerText.textContent = "HOME"; switch (item) { case "#flist": $("#ftbmortrge").removeClass("hidden").siblings(".mortgagerange").addClass("hidden"); showAB_Elements(true); break; case "#rlist": $("#rmortrge").removeClass("hidden").siblings(".mortgagerange").addClass("hidden"); showAB_Elements(true); break; case "#mlist": $("#mhmortrge").removeClass("hidden").siblings(".mortgagerange").addClass("hidden"); showAB_Elements(true); break; case "#buytolet": $("#btlmortrge").removeClass("hidden").siblings(".mortgagerange").addClass("hidden"); var footerText = document.getElementById("footerMassage"); footerText.textContent = "PROPERTY"; showAB_Elements(false); break; default: return false; } } }; $.fn.toolSelect = function () { var timer; var hideitem = false; var tools = $(this).parents("#toolbar").siblings("#tools"); $(this).click(function (e) { hideitem = false; clearTimeout(timer); var tId = $(this).parents("li").attr("id"); e.preventDefault(); var cName = (tId == "moretools") ? "mt" : "ttu"; if (tools.hasClass("hidden")) { tools.removeClass("hidden"); $(this).parents("li").addClass("here").siblings("li.here").removeClass("here"); tools.removeAttr("class").addClass("panel " + cName); } else { if (tools.find("ul").hasClass(cName)) { tools.addClass("hidden"); $(this).parents("li").removeClass("here"); } else { tools.removeAttr("class").addClass("panel " + cName); $(this).parents("li").addClass("here").siblings("li.here").removeClass("here"); } } }).mouseover(function () { hideitem = false; clearTimeout(timer); }).mouseout(function () { hideitem = true; timeon(); }); tools.mouseover(function () { hideitem = false; clearTimeout(timer); }).mouseout(function () { hideitem = true; timeon(); }); function timeon() { if (hideitem) { timer = setTimeout(function () { if (hideitem) { tools.addClass("hidden"); $("#toolbar li").removeClass("here"); } }, 1000); } } }; jQuery.fn.helppopup = function () { $(this).each(function () { var flex = $(this).hasClass("flex"); var glossary = $(this).hasClass("glossary"); var link = $(this).data("hide", true); var tooltip = (glossary) ? $(this).attr("title") : $(this).next(".helptxt").html(); $(this).attr("title", ""); var content = $("<div class='jargoninfo'></div>").css({ "z-index": "999" }).data("hide", true); $(this).hover(function (e) { $(this).data("hide", false).addClass("clickable"); }, function () { var _that = $(this); _that.data("hide", true); hidepanel(link, content); $(this).removeClass("clickable"); }).click(function (e) { e.preventDefault(); var cMarkup = (glossary) ? ("<strong>" + $(this).html() + "</strong><span class='tippy'>" + tooltip + "</span>") : ("<span class='tippy'>" + tooltip + "</span>"); $(this).data("hide", false).after(content.html(cMarkup)); var pos = $(this).offset(); var relativepos = $(this).position(); var y = parseInt(pos.top); var x = $(window).height(); var z = $(window).scrollTop(); var top = 0; if ((y - z) > (x / 2)) { var addition = (flex || glossary) ? 5 : 25; var addition = (flex) ? 0 : (glossary) ? 5 : 25; top = parseInt(relativepos.top) - content.height() - $(this).height() - addition; } else { var addition = (flex || glossary) ? -5 : 20; top = parseInt(relativepos.top) + $(this).height() - addition; } $(this).removeClass("clickable").addClass("infodisplay"); content.css({ left: relativepos.left + "px", top: top + "px" }).data("hide", true).hover(function () { $(this).data("hide", false); }, function () { hidepanel(link, content); $(this).data("hide", true); }); }); }); }; function hidepanel(link, content) { setTimeout(function () { if (link.data("hide") == true && content.data("hide") == true) { content.remove(); } }, 500); } jQuery.fn.selectToUISlider = function (settings) { var selects = jQuery(this); selects.addClass("hidden"); var options = jQuery.extend({ labels: 3, tooltip: true, tooltipSrc: "text", labelSrc: "text", sliderOptions: null }, settings); var handleIds = (function () { var tempArr = []; selects.each(function () { tempArr.push("handle_" + jQuery(this).attr("id")); }); return tempArr; })(); var selectOptions = (function () { var opts = []; selects.eq(0).find("option").each(function () { opts.push({ value: jQuery(this).attr("value"), text: jQuery(this).text() }); }); return opts; })(); var groups = (function () { if (selects.eq(0).find("optgroup").size() > 0) { var groupedData = []; selects.eq(0).find("optgroup").each(function (i) { groupedData[i] = {}; groupedData[i].label = jQuery(this).attr("label"); groupedData[i].options = []; jQuery(this).find("option").each(function () { groupedData[i].options.push({ text: jQuery(this).text(), value: jQuery(this).attr("value") }); }); }); return groupedData; } else { return null; } })(); function ttText(optIndex) { return (options.tooltipSrc == "text") ? selectOptions[optIndex].text : selectOptions[optIndex].value; } var pbar = jQuery('<div id="progressbar">&nbsp;</div>'); var sliderOptions = { step: 1, min: 0, orientation: "horizontal", max: selectOptions.length - 1, range: selects.length > 1, slide: function (e, ui) { var thisHandle = jQuery(ui.handle); var textval = ttText(ui.value); thisHandle.attr("aria-valuetext", textval).attr("aria-valuenow", ui.value).find(".ui-slider-tooltip .ttContent").text(textval); var currSelect = jQuery("#" + thisHandle.attr("id").split("handle_")[1]); currSelect.find("option").eq(ui.value).attr("selected", "selected"); pbar.width(pbarwidth()); }, stop: function (e, ui) { pbar.width(pbarwidth()); selects.trigger("change"); }, change: function () { pbar.width(pbarwidth()); showLabel(); fireLtvChange = true; }, values: (function () { var values = []; selects.each(function () { values.push(jQuery(this).get(0).selectedIndex); }); return values; })() }; options.sliderOptions = (settings) ? jQuery.extend(sliderOptions, settings.sliderOptions) : sliderOptions; selects.bind("change keyup click", function () { var thisIndex = jQuery(this).get(0).selectedIndex; var thisHandle = jQuery("#handle_" + jQuery(this).attr("id")); var handleIndex = thisHandle.data("handleNum"); thisHandle.parents(".ui-slider:eq(0)").slider("values", handleIndex, thisIndex); }); var sliderComponent = jQuery("<div></div>"); selects.each(function (i) { var hidett = ""; var thisLabel = jQuery("label[for=" + jQuery(this).attr("id") + "]"); var labelText = (thisLabel.size() > 0) ? "Slider control for " + thisLabel.text() + "" : ""; var thisLabelId = thisLabel.attr("id") || thisLabel.attr("id", "label_" + handleIds[i]).attr("id"); if (options.tooltip == false) { hidett = ' style="display: none;"'; } jQuery('<a href="#" tabindex="0" id="' + handleIds[i] + '" class="ui-slider-handle" role="slider" aria-labelledby="' + thisLabelId + '" aria-valuemin="' + options.sliderOptions.min + '" aria-valuemax="' + options.sliderOptions.max + '" aria-valuenow="' + options.sliderOptions.values[i] + '" aria-valuetext="' + ttText(options.sliderOptions.values[i]) + '" ><span class="screenReaderContext">' + labelText + '</span><span class="ui-slider-tooltip ui-widget-content ui-corner-all"' + hidett + '><span class="ttContent"></span><span class="ui-tooltip-pointer-down ui-widget-content"><span class="ui-tooltip-pointer-down-inner"></span></span></span></a>').data("handleNum", i).appendTo(sliderComponent); pbar.appendTo(sliderComponent); }); if (groups) { var inc = 0; var scale = sliderComponent.append('<dl class="ui-slider-scale ui-helper-reset" role="presentation"></dl>').find(".ui-slider-scale:eq(0)"); jQuery(groups).each(function (h) { scale.append('<dt style="width: ' + (100 / groups.length).toFixed(2) + "%; left:" + (h / (groups.length - 1) * 100).toFixed(2) + '%"><span>' + this.label + "</span></dt>"); var groupOpts = this.options; jQuery(this.options).each(function (i) { var style = (inc == selectOptions.length - 1 || inc == 0) ? 'style="display: none;"' : ""; var labelText = (options.labelSrc == "text") ? groupOpts[i].text : groupOpts[i].value; scale.append('<dd style="left:' + leftVal(inc) + '"><span class="ui-slider-label">' + labelText + '</span><span class="ui-slider-tic ui-widget-content"' + style + "></span></dd>"); inc++; }); }); } else { var scale = sliderComponent.append('<ol class="ui-slider-scale ui-helper-reset" role="presentation"></ol>').find(".ui-slider-scale:eq(0)"); jQuery(selectOptions).each(function (i) { var style = (i == selectOptions.length - 1 || i == 0) ? 'style="display: none;"' : ""; var labelText = (options.labelSrc == "text") ? this.text : this.value; scale.append('<li style="left:' + leftVal(i) + '"><span class="ui-slider-label">' + labelText + '</span><span class="ui-slider-tic ui-widget-content"' + style + "></span></li>"); }); } function leftVal(i) { return (i / (selectOptions.length - 1) * 100).toFixed(2) + "%"; } if (options.labels > 1) { sliderComponent.find(".ui-slider-scale li:last span.ui-slider-label, .ui-slider-scale dd:last span.ui-slider-label").addClass("ui-slider-label-show"); } var increm = Math.max(1, Math.round(selectOptions.length / options.labels)); for (var j = 0; j < selectOptions.length; j += increm) { if ((selectOptions.length - j) > increm) { sliderComponent.find(".ui-slider-scale li:eq(" + j + ") span.ui-slider-label, .ui-slider-scale dd:eq(" + j + ") span.ui-slider-label").addClass("ui-slider-label-show"); } } sliderComponent.insertAfter(jQuery(this).eq(this.length - 1)).slider(options.sliderOptions).attr("role", "application").find(".ui-slider-label").each(function () { jQuery(this).css("marginLeft", -jQuery(this).width() / 2); }); sliderComponent.find(".ui-tooltip-pointer-down-inner").each(function () { var bWidth = jQuery(".ui-tooltip-pointer-down-inner").css("borderTopWidth"); var bColor = jQuery(this).parents(".ui-slider-tooltip").css("backgroundColor"); jQuery(this).css("border-top", bWidth + " solid " + bColor); }); pbar.css({ width: pbarwidth() }); function showLabel() { sliderComponent.find(".ttContent").each(function () { $(this).text(selects.find("option:selected").text()); }); } showLabel(); function pbarwidth() { return selects.find("option:selected").prevAll("option").length / (selects.find("option").length - 1) * 100 + "%"; } selects.parents(".slider").find(".ui-slider").wrap("<div id='sliderwrap'></div>"); sliderComponent.find(".ui-slider-label").removeAttr("style"); return this; }; function setSelRange(inputEl, selStart, selEnd) { if (inputEl.setSelectionRange) { inputEl.focus(); inputEl.setSelectionRange(selStart, selEnd); } else { if (inputEl.createTextRange) { var range = inputEl.createTextRange(); range.collapse(true); range.moveEnd("character", selEnd); range.moveStart("character", selStart); range.select(); } } } function getSelRange(el) { var sel, rng, r2, i = -1; if (typeof el.selectionStart == "number") { i = el.selectionStart; } else { if (document.selection && el.createTextRange) { sel = document.selection; if (sel) { r2 = sel.createRange(); rng = el.createTextRange(); i = rng.text.length; } } else { el.onkeyup = null; el.onclick = null; } } return i; } var fireLtvChange = false; $.steponealpha = function (args) { var ltvpanel = $("#ltvhelp"); var propVal = $("#PropertyValue"); var deposit = $("#Deposit"); var ltv = $("#LoanToValue"); var loanreq = $("#loanrequired span"); var loanreqPartnPart = $("#loanAmount"); var defaultLtv = ltv.val(); $("#nonJSSubmit").addClass("hidden"); if (propVal.val() && deposit.val()) { $.getMortgageList("About-Your-Property"); } var propValClone = $("<input type='text' class='text' maxLength='11'/>"); var depositClone = $("<input type='text' class='text' maxLength='11'/>"); $("#ltvdisplay, #ltvchange fieldset.row,#loanrequired,#changetoggle").removeClass("hidden"); $("#ltvchange").addClass("hidden"); $("#changetoggle").click(function (e) { $(this).toggleClass("expanded"); $("#ltvchange").toggleClass("hidden"); if ($("#ltvchange").hasClass("hidden")) { propValClone.removeClass("disabled"); depositClone.removeClass("disabled"); } else { if (depositClone.hasClass("disabled")) { propValClone.removeClass("disabled"); $("#holdproperty").attr("checked", "checked").parent("label").addClass("held"); } else { $("#stepone #PropertyValue").addClass("disabled"); propValClone.addClass("disabled"); depositClone.removeClass("disabled"); $("#holddeposit").attr("checked", "checked").parent("label").addClass("held"); } } }); var ltvdisplay = $("#ltvdisplay span"); ltvdisplay.text(calcActualLTV(propVal.val(), deposit.val()) + "%"); loanreq.html("&pound;" + calcLoanAmount(propVal.val(), deposit.val())); loanreqPartnPart.val(clearCommas(calcLoanAmount(propVal.val(), deposit.val()))); propVal.addClass("hidden"); deposit.addClass("hidden"); propValClone.val(getCommas(propVal.val())); depositClone.val(getCommas(deposit.val())); propValClone.insertAfter(propVal); depositClone.insertAfter(deposit); $("#holddeposit").click(function (e) { $(this).parent("label").addClass("held"); $("#holdproperty").parent("label").removeClass("held"); propValClone.addClass("disabled"); depositClone.removeClass("disabled"); }); $("#holdproperty").click(function (e) { $(this).parent("label").addClass("held"); $("#holddeposit").parent("label").removeClass("held"); depositClone.addClass("disabled"); propValClone.removeClass("disabled"); }); function calcDepVal(arg, prop) { return Math.round(prop * ((100 - arg) * 0.01)); } function calcPropVal(arg, dep) { return Math.round(dep / (100 - arg) * 100); } var ptime; propValClone.keyup(function (e) { var pval = $(this).val(); propVal.val(clearCommas(pval)); getCommasExtra(this, pval); $(this).addClass("fixedvalue"); if (isNaN(propVal.val())) { throwError(propVal); return false; } else { if ($("label[for='" + propVal.attr("id") + "']").length > 0) { $("label[for='" + propVal.attr("id") + "']").find(".field-validation-error").remove(); } } clearTimeout(ptime); clearTimeout(dtime); clearTimeout(ltime); if (deposit.val() == "" || propVal.val() == "") { return false; } ptime = setTimeout(function () { actltv = calcActualLTV(propVal.val(), deposit.val()); loanamount = calcLoanAmount(propVal.val(), deposit.val()); if (parseInt(deposit.val()) == 0) { throwError(deposit, "Please enter a deposit value"); return false; } else { if (parseInt(propVal.val()) <= parseInt(deposit.val())) { throwError(deposit, "Deposit must be less than property value"); return false; } else { if ($("label[for='" + deposit.attr("id") + "']").length > 0) { $("label[for='" + deposit.attr("id") + "']").find(".field-validation-error").remove(); } else { if ($("label[for='" + propVal.attr("id") + "']").length > 0) { $("label[for='" + propVal.attr("id") + "']").find(".field-validation-error").remove(); } } } } ltvpanel.removeClass("hidden"); fireLtvChange = false; ltv.val(actltv).trigger("change"); var dValue = calcDepVal(ltv.val(), propVal.val()); var dValueMin = calcDepVal("90", propVal.val()); var dValueMax = calcDepVal("70", propVal.val()); ltvdisplay.text(actltv + "%"); if (actltv <= 75) { $("#radIntOnly").removeClass("hidden"); } if (actltv <= 85) { $("#radPartPart").removeClass("hidden"); } if (actltv > 75) { $("#radIntOnly").addClass("hidden"); } if (actltv > 85) { $("#radPartPart").addClass("hidden"); } var betterLTV = $("#betterLTV"); if ((actltv > 70) || (clearCommas(loanamount) <= 1000000)) { $("#betterLTV").removeClass("hidden"); } if ((actltv <= 70) || (clearCommas(loanamount) > 1000000)) { $("#betterLTV").addClass("hidden"); } var incDep = $("#incDep"); var decVal = $("#decVal"); var bestLTV = $("#bestLTV"); if (actltv > 85) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (85 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 85)) * deposit.val())))); bestLTV.html(85); } else { if (actltv > 80) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (80 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 80)) * deposit.val())))); bestLTV.html(80); } else { if (actltv > 75) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (75 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 75)) * deposit.val())))); bestLTV.html(75); } else { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (70 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 70)) * deposit.val())))); bestLTV.html(70); } } } loanreq.html("&pound;" + loanamount); loanreqPartnPart.val(clearCommas(loanamount)); $.getMortgageList("About-Your-Property"); }, 400); }); function setDepFields(dval) { deposit.val(dval); depositClone.val(getCommas(dval)); } var dtime; depositClone.keyup(function (e) { var dval = $(this).val(); deposit.val(clearCommas(dval)); getCommasExtra(this, dval); $(this).addClass("fixedvalue"); if (isNaN(deposit.val())) { throwError(deposit); return false; } else { if ($("label[for='" + deposit.attr("id") + "']").length > 0) { $("label[for='" + deposit.attr("id") + "']").find(".field-validation-error").remove(); } } clearTimeout(ptime); clearTimeout(dtime); clearTimeout(ltime); if (deposit.val() == "" || propVal.val() == "") { return false; } dtime = setTimeout(function () { if (parseInt(deposit.val()) == 0) { throwError(deposit, "Please enter a deposit value"); return false; } else { if (parseInt(propVal.val()) <= parseInt(deposit.val())) { throwError(deposit, "Deposit must be less than property value"); return false; } else { if ($("label[for='" + deposit.attr("id") + "']").length > 0) { $("label[for='" + deposit.attr("id") + "']").find(".field-validation-error").remove(); } } } actltv = calcActualLTV(propVal.val(), deposit.val()); ltvpanel.removeClass("hidden"); fireLtvChange = false; ltv.val(actltv).trigger("change"); var pValue = calcPropVal(ltv.val(), deposit.val()); var pValueMax = calcPropVal("90", deposit.val()); var pValueMin = calcPropVal("70", deposit.val()); ltvdisplay.text(actltv + "%"); if (actltv <= 75) { $("#radIntOnly").removeClass("hidden"); } if (actltv <= 85) { $("#radPartPart").removeClass("hidden"); } if (actltv > 75) { $("#radIntOnly").addClass("hidden"); } if (actltv > 85) { $("#radPartPart").addClass("hidden"); } var betterLTV = $("#betterLTV"); var lnamount = clearCommas(calcLoanAmount(propVal.val(), deposit.val())); if ((actltv > 70) || (lnamount <= 1000000)) { $("#betterLTV").removeClass("hidden"); } if ((actltv <= 70) || (lnamount > 1000000)) { $("#betterLTV").addClass("hidden"); } var incDep = $("#incDep"); var decVal = $("#decVal"); var bestLTV = $("#bestLTV"); if (actltv > 85) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (85 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 85)) * deposit.val())))); bestLTV.html(85); } else { if (actltv > 80) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (80 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 80)) * deposit.val())))); bestLTV.html(80); } else { if (actltv > 75) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (75 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 75)) * deposit.val())))); bestLTV.html(75); } else { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (70 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 70)) * deposit.val())))); bestLTV.html(70); } } } loanreq.html("&pound;" + calcLoanAmount(propVal.val(), deposit.val())); loanreqPartnPart.val(clearCommas(calcLoanAmount(propVal.val(), deposit.val()))); $.getMortgageList("About-Your-Property"); }, 400); }); function setPropFields(pval) { propVal.val(pval); propValClone.val(getCommas(pval)); } var ltime; ltv.change(function () { clearTimeout(ptime); clearTimeout(dtime); clearTimeout(ltime); var ltv = $(this).val(); if (defaultLtv == ltv || fireLtvChange == false) { clearTimeout(ltime); return false; } else { if (propValClone.hasClass("disabled")) { var pval = calcPropVal(ltv, deposit.val()); setPropFields(pval); } else { if (depositClone.hasClass("disabled")) { var dval = calcDepVal(ltv, propVal.val()); setDepFields(dval); } else { var help = $("#ltvvaluehelp"); help.find(".ltv").text(ltv); var mp = calcPropVal(ltv, deposit.val()); var md = calcDepVal(ltv, propVal.val()); help.find(".maxpro").text(getCommas(mp)); help.find(".mindep").text(getCommas(md)); help.find("#maxproperty").click(function (e) { e.preventDefault(); propValClone.val(mp).trigger("keyup"); }); help.find("#mindeposit").click(function (e) { e.preventDefault(); depositClone.val(md).trigger("keyup"); }); } } defaultLtv = ltv; } ltime = setTimeout(function () { ltvdisplay.text(ltv + "%"); if (ltv <= 75) { $("#radIntOnly").removeClass("hidden"); } if (ltv <= 85) { $("#radPartPart").removeClass("hidden"); } if (ltv > 75) { $("#radIntOnly").addClass("hidden"); } if (ltv > 85) { $("#radPartPart").addClass("hidden"); } var betterLTV = $("#betterLTV"); var lnamount = clearCommas(calcLoanAmount(propVal.val(), deposit.val())); if ((ltv > 70) || (lnamount <= 1000000)) { $("#betterLTV").removeClass("hidden"); } if ((ltv <= 70) || (lnamount > 1000000)) { $("#betterLTV").addClass("hidden"); } var incDep = $("#incDep"); var decVal = $("#decVal"); var bestLTV = $("#bestLTV"); if (ltv > 85) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (85 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 85)) * deposit.val())))); bestLTV.html(85); } else { if (ltv > 80) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (80 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 80)) * deposit.val())))); bestLTV.html(80); } else { if (ltv > 75) { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (75 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 75)) * deposit.val())))); bestLTV.html(75); } else { incDep.html(getCommas(Math.round(propVal.val() - deposit.val() - (propVal.val() * (70 / 100))))); decVal.html(getCommas(Math.round(propVal.val() - ((100 / (100 - 70)) * deposit.val())))); bestLTV.html(70); } } } loanreq.html("&pound;" + calcLoanAmount(propVal.val(), deposit.val())); loanreqPartnPart.val(clearCommas(calcLoanAmount(propVal.val(), deposit.val()))); $.getMortgageList("About-Your-Property"); }, 100); }); if (propVal.val() == "" && deposit.val() == "") { ltvpanel.addClass("hidden"); } else { if (deposit.val() == "") { propValClone.trigger("keyup"); } else { if (propVal.val() == "") { depositClone.trigger("keyup"); } else { ltv.trigger("change"); } } } }; $.steponebeta = function (args) { var ltvpanel = $("#ltvhelp"); $("#borrowing").addClass("hidden"); $("#nonJSSubmit").addClass("hidden"); var propVal = $("#PropertyValue"); var outstand = $("#OutstandingMortgageBalance"); var furtherborrow = $("#FurtherBorrowing"); var ltv = $("#LoanToValue"); var loanreq = $("#loanrequired span"); var loanreqPartnPart = $("#loanAmount"); var defaultLtv = ltv.val(); $("#ltvdisplay,#loanrequired,#changetoggle").removeClass("hidden"); loanreq.html("&pound;" + calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val()))); loanreqPartnPart.val(clearCommas(calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val())))); $("#ltvchange").addClass("hidden"); var propValClone = $("<input type='text' class='text' maxLength='11'/>"); var outstandValClone = $("<input type='text' class='text' maxLength='11'/>"); var fbValClone = $("<input type='text' class='text' maxLength='11'/>"); propVal.addClass("hidden"); outstand.addClass("hidden"); furtherborrow.addClass("hidden"); propValClone.val(getCommas(propVal.val())); outstandValClone.val(getCommas(outstand.val())); fbValClone.val(getCommas(furtherborrow.val())); propValClone.insertAfter(propVal); outstandValClone.insertAfter(outstand); fbValClone.insertAfter(furtherborrow); var errMess = "Outstanding mortgage balance must not be larger than property value"; propValClone.keyup(function (e) { var pval = $(this).val(); propVal.val(clearCommas(pval)); getCommasExtra(this, pval); if (isNaN(propVal.val())) { clearTimeout(ntime); throwError(propVal); return false; } else { if (parseInt(propVal.val()) <= parseInt(outstand.val())) { clearTimeout(ntime); throwError(outstand, errMess); return false; } } if ($("label[for='" + propVal.attr("id") + "']").length > 0) { $("label[for='" + propVal.attr("id") + "']").find(".field-validation-error").remove(); } if ($("label[for='" + outstand.attr("id") + "']").length > 0) { $("label[for='" + outstand.attr("id") + "']").find(".field-validation-error").remove(); } loadLTV(); loanreq.html("&pound;" + calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val()))); loanreqPartnPart.val(clearCommas(calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val())))); }); outstandValClone.keyup(function (e) { var oval = $(this).val(); outstand.val(clearCommas(oval)); getCommasExtra(this, oval); if (isNaN(outstand.val())) { clearTimeout(ntime); throwError(outstand); return false; } else { if (parseInt(propVal.val()) <= parseInt(outstand.val())) { clearTimeout(ntime); throwError(outstand, errMess); return false; } else { if ($("label[for='" + outstand.attr("id") + "']").length > 0) { $("label[for='" + outstand.attr("id") + "']").find(".field-validation-error").remove(); } else { if ($("label[for='" + propVal.attr("id") + "']").length > 0) { $("label[for='" + propVal.attr("id") + "']").find(".field-validation-error").remove(); } } } } loadLTV(); loanreq.html("&pound;" + calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val()))); loanreqPartnPart.val(clearCommas(calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val())))); }); fbValClone.keyup(function (e) { var fval = $(this).val(); furtherborrow.val(clearCommas(fval)); getCommasExtra(this, fval); if (isNaN(furtherborrow.val())) { clearTimeout(ntime); throwError(furtherborrow); return false; } else { if ($("label[for='" + furtherborrow.attr("id") + "']").length > 0) { $("label[for='" + furtherborrow.attr("id") + "']").find(".field-validation-error").remove(); } } loadLTV(); loanreq.html("&pound;" + calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val()))); loanreqPartnPart.val(clearCommas(calcRemortLoanAmount(parseInt(outstand.val()), parseInt(furtherborrow.val())))); }); var ntime; function loadLTV() { var pv = propVal.val(); var ov = outstand.val(); var fv = furtherborrow.val(); if (pv != "" && ov != "") { clearTimeout(ntime); if ($("#borrowing").hasClass("hidden")) { $("#borrowing").removeClass("hidden"); ltvpanel.removeClass("hidden"); } var propvalamount = parseInt(pv); var depositamount = (fv == "") ? propvalamount - ov : propvalamount - (parseInt(ov) + parseInt(fv)); var lval = calcLTV(propvalamount, depositamount); ltv.val(lval).trigger("change"); var remortLTV = calcActualLTV(propvalamount, depositamount); if (remortLTV <= 75) { $("#radIntOnly").removeClass("hidden"); } if (remortLTV <= 85) { $("#radPartPart").removeClass("hidden"); } if (remortLTV > 75) { $("#radIntOnly").addClass("hidden"); } if (remortLTV > 85) { $("#radPartPart").addClass("hidden"); } ntime = setTimeout(function () { $("#ltvdisplay span").text(calcActualLTV(propvalamount, depositamount) + "%"); $.getMortgageList("About-Your-Property"); }, 500); } } if (propVal.val() == "" || outstand.val() == "") { ltvpanel.addClass("hidden"); } else { propValClone.trigger("keyup"); } }; function calcLTV(property, deposit) { var ltvvalue = Math.ceil((1 - (deposit / property)) * 100); if (ltvvalue < 70) { ltvvalue = 70; } return ltvvalue; } function calcActualLTV(property, deposit) { property = (property == "") ? 0 : property; deposit = (deposit == "") ? 0 : deposit; var ltvvalue = (property == 0 && deposit == 0) ? 0 : Math.ceil((1 - (deposit / property)) * 100); if (ltvvalue < 0) { ltvvalue = 0; } return ltvvalue; } function calcLoanAmount(property, deposit) { property = (property == "" || isNaN(property) == true) ? 0 : property; deposit = (deposit == "" || isNaN(deposit) == true) ? 0 : deposit; var loanamount = property - deposit; if (loanamount < 0) { loanamount = 0; } return getCommas(loanamount); } function calcRemortLoanAmount(outstanding, furtherborrowing) { outstanding = (outstanding == "" || isNaN(outstanding)) ? 0 : outstanding; furtherborrowing = (furtherborrowing == "" || isNaN(furtherborrowing)) ? 0 : furtherborrowing; return getCommas(outstanding + furtherborrowing); } function getKeyPosCommaLen(str, keypos) { var s = str.toString(); s = s.slice(0, keypos); s = (s.match(/,/g)) ? s.match(/,/g).length : 0; return s; } function getCommas(val) { var val = val; val = val.toString().replace(/,/g, "").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); return val; } function getCommasExtra(elem, val) { var val = val; var keypos = getSelRange(elem); var lenBefore = getKeyPosCommaLen($(elem).val().toString(), keypos); val = val.toString().replace(/,/g, "").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); var lenAfter = getKeyPosCommaLen(val, keypos); var len = lenAfter - lenBefore; keypos = keypos + len; $(elem).val(val); setSelRange(elem, keypos, keypos); } function clearCommas(val) { var val = val; val = val.toString().replace(/,/g, ""); return val; } function throwError(elem, message) { var item = elem.siblings("label[for='" + elem.attr("id") + "']"); var errMessage = (message == undefined) ? "Please enter a valid amount" : message; if (item.find(".field-validation-error").length > 0) { item.find(".field-validation-error").text(errMessage); } else { item.append('<span class="field-validation-error">' + errMessage + "</span>"); } } $.steptwo = function (args) { var intonly = $("#InterestOnlyAmount"); var pnp = $("#RepaymentMethodPartAndPart"); if (pnp.is(":not(:checked)")) { $("#partnpart").addClass("hidden"); } $("#RepaymentMethodPartAndPart").click(function () { if ($(this).is(":checked")) { $("#partnpart").removeClass("hidden"); if (intonly.val() != "" && intonly.val() != 0) { $.getMortgageList("Your-Monthly-Payments"); } } }); $("#RepaymentMethodRepayment, #RepaymentMethodInterestOnly").click(function () { $(this).each(function () { $("#partnpart").addClass("hidden"); $.getMortgageList("Your-Monthly-Payments"); }); }); $("#steptwo #Term").change(function () { if (pnp.is(":not(:checked)")) { $.getMortgageList("Your-Monthly-Payments"); } else { if (intonly.val() != "" && intonly.val() != 0) { $.getMortgageList("Your-Monthly-Payments"); } } }); var pv = $("#stepone #PropertyValue"); var dv = $("#stepone #Deposit"); var hiddenLoan = calcLoanAmount(pv.val(), dv.val()); var clone = $("<input type='text' class='text' maxLength='11'/>"); intonly.addClass("hidden"); clone.val(getCommas(intonly.val())); clone.insertAfter(intonly); var inttime; clone.keyup(function () { clearTimeout(inttime); intonly.val(clearCommas($(this).val())); getCommasExtra(this, intonly.val()); var label = $("label[for=" + intonly.attr("id") + "]"); var hiddenLoan = clearCommas(calcLoanAmount(pv.val(), dv.val())); if (parseInt(intonly.val()) > hiddenLoan) { var error = $('<span class="field-validation-error">you must supply an interest only amount smaller or equal to loan amount minus one pound</span>'); if (label.find(".field-validation-error").length > 0) { label.find(".field-validation-error").replaceWith(error); } else { label.find(".helptxt").before(error); } return false; } else { if (parseInt(intonly.val()) <= 0) { var error = $('<span class="field-validation-error">you must supply an interest only amount of at least one pound</span>'); if (label.find(".field-validation-error").length > 0) { label.find(".field-validation-error").replaceWith(error); } else { label.find(".helptxt").before(error); } } else { if ($(this).val() == "") { throwError(intonly, "You must supply an interest only amount"); } else { if (isNaN(parseInt($(this).val())) == true) { throwError(intonly, "You must supply an numeric interest only amount"); } else { label.find(".field-validation-error").remove(); inttime = setTimeout(function () { $.getMortgageList("Your-Monthly-Payments"); }, 500); } } } } }); }; $.stepthree = function (args) { var withFee = $("#ProductsWithFee"); var withoutFee = $("#ProductsWithNoFee"); var label = withFee.parents("#fees").find("p.label"); withFee.click(function (e) { if (!($(this).is(":checked")) && !(withoutFee.is(":checked"))) { setError(); return false; } else { label.find(".field-validation-error").remove(); $.getMortgageList("Fees-And-Flexibility"); } }); withoutFee.click(function (e) { if (!($(this).is(":checked")) && !(withFee.is(":checked"))) { setError(); return false; } else { label.find(".field-validation-error").remove(); $.getMortgageList("Fees-And-Flexibility"); } }); function setError() { var error = $('<span class="field-validation-error">You must have at least one option checked.</span>'); if (label.find(".field-validation-error").length > 0) { label.find(".field-validation-error").replaceWith(error); } else { label.append(error); } } }; $.fn.plotGraph = function (args) { $("#oLoanAmount").addcommas(); $("#TermOverpayment").selectToUISlider(); $("#OverpaymentPerMonth").selectToUISlider(); var colorarray = ["rgb(240, 4, 127)", "rgb(12, 23, 244)"]; var URL = sitePrepend + "/Tools/JSONOverPay"; $("#overpaycalc .button input").click(function (e) { e.preventDefault(); $.post(URL, $("#overpaycalc").serialize(), function (data) { var jd = data; if (jd[0]) { if ($("label[for='" + jd[0].Field + "']").find(".field-validation-error").length > 0) { $("label[for='" + jd[0].Field + "']").find(".field-validation-error").text(jd[0].Message); } else { $("label[for='" + jd[0].Field + "']").append('<span class="field-validation-error">' + jd[0].Message + "</span>"); } } else { $(".field-validation-error").remove(); var gdata = []; var arr1 = []; var arr2 = []; $(jd.AnnualPayments).each(function (i) { arr1.push([(i).toString(), jd.AnnualPayments[i]]); }); fini = false; $(jd.AnnualPaymentsOverpayments).each(function (i) { if (fini == false) { arr2.push([(i).toString(), jd.AnnualPaymentsOverpayments[i]]); if (jd.AnnualPaymentsOverpayments[i] == "0") { fini = true; } } }); plotGraph(arr1, arr2, gdata); $("#TermWithoutHolder").text(jd.TermWithout + " years"); $("#TotalInterestWithoutHolder").html("&pound;" + getCommas(Math.round(jd.TotalInterestWithout))); $("#MonthlyWithoutHolder").html("&pound;" + getCommas(Math.round(jd.MonthlyWithout))); $("#TermWithHolder").text(jd.TermWith); $("#TotalInterestWithHolder").html("&pound;" + getCommas(Math.round(jd.TotalInterestWith))); $("#MonthlyWithHolder").html("&pound;" + getCommas(Math.round(jd.MonthlyWith))); $("#SavingTermHolder").text(jd.SavingTerm); $("#SavingAmountHolder").html("&pound;" + getCommas(Math.round(jd.SavingAmount))); $("#oSummary").removeClass("hidden"); } }); }); if ($("#graphdata").length == 234234234234234) { var gdata = []; var arr1 = []; var arr2 = []; fini = false; $("#graphdata").find("tbody tr").each(function (i) { arr1.push([(i).toString(), $(this).find("td:eq(1)").text()]); if (fini == false) { arr2.push([(i).toString(), $(this).find("td:eq(2)").text()]); if ($(this).find("td:eq(2)").text() == "0") { fini = true; } } }); $("#graphdata").addClass("hidden"); plotGraph(arr1, arr2, gdata); } function plotGraph(array1, array2, gdata) { gdata.push({ data: array1, label: "without overpayments", points: { show: true }, lines: { show: true, fill: false, lineWidth: 1 }, color: colorarray[0] }); gdata.push({ data: array2, label: "with overpayments", points: { show: true }, lines: { show: true, fill: false, lineWidth: 1 }, color: colorarray[1] }); $.plot($("#graph"), gdata, { legend: { position: "ne", margin: 15, labelBoxBorderColor: "rgb(59,59, 59)", backgroundColor: "rgb(255, 255, 255)" }, grid: { show: true, backgroundColor: "rgb(236,244, 249)", color: "rgb(59,59, 59)", borderWidth: 1, borderColor: "rgb(129, 156, 180)"} }); $("#graph").append("<p id='yaxis'>Loan amount</p>").append("<p id='xaxis'>Term</p>"); } }; $.getMortgageList = function (path) { if ($("#mortgageform #Deposit").val() == 0 || $("#mortgageform #PropertyValue").val() == 0) { return false; } var loading = $('<span class="loader"><img src="/_mortgage_assets/css/images/ajax-loader.gif"/></span>'); $("#mortgagepage #options .step.open").append(loading); var d = new Date(); var URL = sitePrepend + "/Find/AJAX/" + path + "?_=" + d.getTime(); $.ajax({ type: "POST", url: URL, data: $("#mortgageform").serialize(), success: function (data) { if ($(".mPanel").length == 0) { $("#mortgagepage").append('<div class="mPanel"></div>'); } $(".mPanel").replaceWith(data); var newno = $(data).find("dl").length; $("#mInfo .container .inner p strong").text(newno + " mortgages"); $(".mPanel .collapsed").hideshow(); $(".flex").helppopup(); showHelp(); setTimeout(function () { loading.remove(); }, 1000); }, dataType: "html" }); }; function showHelp() { if ($("#stepone #PropertyValue").length == 0) { return false; } var pv = $("#stepone #PropertyValue"); var dv = $("#stepone #Deposit"); var loanamount = calcLoanAmount(pv.val(), dv.val()); var helpltv = calcActualLTV(pv.val(), dv.val()); if (helpltv > 80 && pv.val() > 500000) { $("#ltvmaxmorethan").removeClass("hidden").siblings(".highlight").addClass("hidden"); } else { if (helpltv > 90) { $("#ltvmorethan").removeClass("hidden").siblings(".highlight").addClass("hidden"); } else { if (helpltv < 71) { var lessthan = $("#ltvlessthan"); lessthan.removeClass("hidden").siblings(".highlight").addClass("hidden"); lessthan.find("#ltvlessthanltv").html(helpltv); lessthan.find("#ltvlessthanloan").html(loanamount); } else { if (helpltv > 70) { var inbetween = $("#ltvinbetween"); inbetween.removeClass("hidden").siblings(".highlight").addClass("hidden"); if (helpltv >= 80 && helpltv < 90) { helpltv = "an " + helpltv + "%"; } else { helpltv = "a " + helpltv + "%"; } inbetween.find("#ltvinbetweenloan").html(loanamount); inbetween.find("#ltvinbetweenltv").html($("#ltvdisplay span").text()); } else { $("#ltvmorethan,#ltvlessthan,#ltvinbetween").addClass("hidden"); } } } } } (function (jQuery) { jQuery.each(["backgroundColor", "borderBottomColor", "borderLeftColor", "borderRightColor", "borderTopColor", "color", "outlineColor"], function (i, attr) { jQuery.fx.step[attr] = function (fx) { if (fx.state == 0) { fx.start = getColor(fx.elem, attr); fx.end = getRGB(fx.end); } fx.elem.style[attr] = "rgb(" + [Math.max(Math.min(parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0), Math.max(Math.min(parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0), Math.max(Math.min(parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)].join(",") + ")"; }; }); function getRGB(color) { var result; if (color && color.constructor == Array && color.length == 3) { return color; } if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) { return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])]; } if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)) { return [parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55]; } if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)) { return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)]; } if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)) { return [parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16)]; } return colors[jQuery.trim(color).toLowerCase()]; } function getColor(elem, attr) { var color; do { color = jQuery.curCSS(elem, attr); if (color != "" && color != "transparent" || jQuery.nodeName(elem, "body")) { break; } attr = "backgroundColor"; } while (elem = elem.parentNode); return getRGB(color); } var colors = { aqua: [0, 255, 255], azure: [240, 255, 255], beige: [245, 245, 220], black: [0, 0, 0], blue: [0, 0, 255], brown: [165, 42, 42], cyan: [0, 255, 255], darkblue: [0, 0, 139], darkcyan: [0, 139, 139], darkgrey: [169, 169, 169], darkgreen: [0, 100, 0], darkkhaki: [189, 183, 107], darkmagenta: [139, 0, 139], darkolivegreen: [85, 107, 47], darkorange: [255, 140, 0], darkorchid: [153, 50, 204], darkred: [139, 0, 0], darksalmon: [233, 150, 122], darkviolet: [148, 0, 211], fuchsia: [255, 0, 255], gold: [255, 215, 0], green: [0, 128, 0], indigo: [75, 0, 130], khaki: [240, 230, 140], lightblue: [173, 216, 230], lightcyan: [224, 255, 255], lightgreen: [144, 238, 144], lightgrey: [211, 211, 211], lightpink: [255, 182, 193], lightyellow: [255, 255, 224], lime: [0, 255, 0], magenta: [255, 0, 255], maroon: [128, 0, 0], navy: [0, 0, 128], olive: [128, 128, 0], orange: [255, 165, 0], pink: [255, 192, 203], purple: [128, 0, 128], violet: [128, 0, 128], red: [255, 0, 0], silver: [192, 192, 192], white: [255, 255, 255], yellow: [255, 255, 0] }; })(jQuery); (function () { jQuery.color = {}; jQuery.color.make = function (E, D, B, C) { var F = {}; F.r = E || 0; F.g = D || 0; F.b = B || 0; F.a = C != null ? C : 1; F.add = function (I, H) { for (var G = 0; G < I.length; ++G) { F[I.charAt(G)] += H; } return F.normalize(); }; F.scale = function (I, H) { for (var G = 0; G < I.length; ++G) { F[I.charAt(G)] *= H; } return F.normalize(); }; F.toString = function () { if (F.a >= 1) { return "rgb(" + [F.r, F.g, F.b].join(",") + ")"; } else { return "rgba(" + [F.r, F.g, F.b, F.a].join(",") + ")"; } }; F.normalize = function () { function G(I, J, H) { return J < I ? I : (J > H ? H : J); } F.r = G(0, parseInt(F.r), 255); F.g = G(0, parseInt(F.g), 255); F.b = G(0, parseInt(F.b), 255); F.a = G(0, F.a, 1); return F; }; F.clone = function () { return jQuery.color.make(F.r, F.b, F.g, F.a); }; return F.normalize(); }; jQuery.color.extract = function (C, B) { var D; do { D = C.css(B).toLowerCase(); if (D != "" && D != "transparent") { break; } C = C.parent(); } while (!jQuery.nodeName(C.get(0), "body")); if (D == "rgba(0, 0, 0, 0)") { D = "transparent"; } return jQuery.color.parse(D); }; jQuery.color.parse = function (E) { var D, B = jQuery.color.make; if (D = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(E)) { return B(parseInt(D[1], 10), parseInt(D[2], 10), parseInt(D[3], 10)); } if (D = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(E)) { return B(parseInt(D[1], 10), parseInt(D[2], 10), parseInt(D[3], 10), parseFloat(D[4])); } if (D = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(E)) { return B(parseFloat(D[1]) * 2.55, parseFloat(D[2]) * 2.55, parseFloat(D[3]) * 2.55); } if (D = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(E)) { return B(parseFloat(D[1]) * 2.55, parseFloat(D[2]) * 2.55, parseFloat(D[3]) * 2.55, parseFloat(D[4])); } if (D = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(E)) { return B(parseInt(D[1], 16), parseInt(D[2], 16), parseInt(D[3], 16)); } if (D = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(E)) { return B(parseInt(D[1] + D[1], 16), parseInt(D[2] + D[2], 16), parseInt(D[3] + D[3], 16)); } var C = jQuery.trim(E).toLowerCase(); if (C == "transparent") { return B(255, 255, 255, 0); } else { D = A[C]; return B(D[0], D[1], D[2]); } }; var A = { aqua: [0, 255, 255], azure: [240, 255, 255], beige: [245, 245, 220], black: [0, 0, 0], blue: [0, 0, 255], brown: [165, 42, 42], cyan: [0, 255, 255], darkblue: [0, 0, 139], darkcyan: [0, 139, 139], darkgrey: [169, 169, 169], darkgreen: [0, 100, 0], darkkhaki: [189, 183, 107], darkmagenta: [139, 0, 139], darkolivegreen: [85, 107, 47], darkorange: [255, 140, 0], darkorchid: [153, 50, 204], darkred: [139, 0, 0], darksalmon: [233, 150, 122], darkviolet: [148, 0, 211], fuchsia: [255, 0, 255], gold: [255, 215, 0], green: [0, 128, 0], indigo: [75, 0, 130], khaki: [240, 230, 140], lightblue: [173, 216, 230], lightcyan: [224, 255, 255], lightgreen: [144, 238, 144], lightgrey: [211, 211, 211], lightpink: [255, 182, 193], lightyellow: [255, 255, 224], lime: [0, 255, 0], magenta: [255, 0, 255], maroon: [128, 0, 0], navy: [0, 0, 128], olive: [128, 128, 0], orange: [255, 165, 0], pink: [255, 192, 203], purple: [128, 0, 128], violet: [128, 0, 128], red: [255, 0, 0], silver: [192, 192, 192], white: [255, 255, 255], yellow: [255, 255, 0] }; })(); (function ($) { function Plot(placeholder, data_, options_, plugins) { var series = [], options = { colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"], legend: { show: true, noColumns: 1, labelFormatter: null, labelBoxBorderColor: "#ccc", container: null, position: "ne", margin: 5, backgroundColor: null, backgroundOpacity: 0.85 }, xaxis: { mode: null, transform: null, inverseTransform: null, min: null, max: null, autoscaleMargin: null, ticks: null, tickFormatter: null, labelWidth: null, labelHeight: null, tickDecimals: null, tickSize: null, minTickSize: null, monthNames: null, timeformat: null, twelveHourClock: false }, yaxis: { autoscaleMargin: 0.02 }, x2axis: { autoscaleMargin: null }, y2axis: { autoscaleMargin: 0.02 }, series: { points: { show: false, radius: 3, lineWidth: 2, fill: true, fillColor: "#ffffff" }, lines: { lineWidth: 2, fill: false, fillColor: null, steps: false }, bars: { show: false, lineWidth: 2, barWidth: 1, fill: true, fillColor: null, align: "left", horizontal: false }, shadowSize: 3 }, grid: { show: true, aboveData: false, color: "#545454", backgroundColor: null, tickColor: "rgba(0,0,0,0.15)", labelMargin: 5, borderWidth: 2, borderColor: null, markings: null, markingsColor: "#f4f4f4", markingsLineWidth: 2, clickable: false, hoverable: false, autoHighlight: true, mouseActiveRadius: 10 }, hooks: {} }, canvas = null, overlay = null, eventHolder = null, ctx = null, octx = null, axes = { xaxis: {}, yaxis: {}, x2axis: {}, y2axis: {} }, plotOffset = { left: 0, right: 0, top: 0, bottom: 0 }, canvasWidth = 0, canvasHeight = 0, plotWidth = 0, plotHeight = 0, hooks = { processOptions: [], processRawData: [], processDatapoints: [], draw: [], bindEvents: [], drawOverlay: [] }, plot = this; plot.setData = setData; plot.setupGrid = setupGrid; plot.draw = draw; plot.getPlaceholder = function () { return placeholder; }; plot.getCanvas = function () { return canvas; }; plot.getPlotOffset = function () { return plotOffset; }; plot.width = function () { return plotWidth; }; plot.height = function () { return plotHeight; }; plot.offset = function () { var o = eventHolder.offset(); o.left += plotOffset.left; o.top += plotOffset.top; return o; }; plot.getData = function () { return series; }; plot.getAxes = function () { return axes; }; plot.getOptions = function () { return options; }; plot.highlight = highlight; plot.unhighlight = unhighlight; plot.triggerRedrawOverlay = triggerRedrawOverlay; plot.pointOffset = function (point) { return { left: parseInt(axisSpecToRealAxis(point, "xaxis").p2c(+point.x) + plotOffset.left), top: parseInt(axisSpecToRealAxis(point, "yaxis").p2c(+point.y) + plotOffset.top) }; }; plot.hooks = hooks; initPlugins(plot); parseOptions(options_); constructCanvas(); setData(data_); setupGrid(); draw(); bindEvents(); function executeHooks(hook, args) { args = [plot].concat(args); for (var i = 0; i < hook.length; ++i) { hook[i].apply(this, args); } } function initPlugins() { for (var i = 0; i < plugins.length; ++i) { var p = plugins[i]; p.init(plot); if (p.options) { $.extend(true, options, p.options); } } } function parseOptions(opts) { $.extend(true, options, opts); if (options.grid.borderColor == null) { options.grid.borderColor = options.grid.color; } if (options.xaxis.noTicks && options.xaxis.ticks == null) { options.xaxis.ticks = options.xaxis.noTicks; } if (options.yaxis.noTicks && options.yaxis.ticks == null) { options.yaxis.ticks = options.yaxis.noTicks; } if (options.grid.coloredAreas) { options.grid.markings = options.grid.coloredAreas; } if (options.grid.coloredAreasColor) { options.grid.markingsColor = options.grid.coloredAreasColor; } if (options.lines) { $.extend(true, options.series.lines, options.lines); } if (options.points) { $.extend(true, options.series.points, options.points); } if (options.bars) { $.extend(true, options.series.bars, options.bars); } if (options.shadowSize) { options.series.shadowSize = options.shadowSize; } for (var n in hooks) { if (options.hooks[n] && options.hooks[n].length) { hooks[n] = hooks[n].concat(options.hooks[n]); } } executeHooks(hooks.processOptions, [options]); } function setData(d) { series = parseData(d); fillInSeriesOptions(); processData(); } function parseData(d) { var res = []; for (var i = 0; i < d.length; ++i) { var s = $.extend(true, {}, options.series); if (d[i].data) { s.data = d[i].data; delete d[i].data; $.extend(true, s, d[i]); d[i].data = s.data; } else { s.data = d[i]; } res.push(s); } return res; } function axisSpecToRealAxis(obj, attr) { var a = obj[attr]; if (!a || a == 1) { return axes[attr]; } if (typeof a == "number") { return axes[attr.charAt(0) + a + attr.slice(1)]; } return a; } function fillInSeriesOptions() { var i; var neededColors = series.length, usedColors = [], assignedColors = []; for (i = 0; i < series.length; ++i) { var sc = series[i].color; if (sc != null) { --neededColors; if (typeof sc == "number") { assignedColors.push(sc); } else { usedColors.push($.color.parse(series[i].color)); } } } for (i = 0; i < assignedColors.length; ++i) { neededColors = Math.max(neededColors, assignedColors[i] + 1); } var colors = [], variation = 0; i = 0; while (colors.length < neededColors) { var c; if (options.colors.length == i) { c = $.color.make(100, 100, 100); } else { c = $.color.parse(options.colors[i]); } var sign = variation % 2 == 1 ? -1 : 1; c.scale("rgb", 1 + sign * Math.ceil(variation / 2) * 0.2); colors.push(c); ++i; if (i >= options.colors.length) { i = 0; ++variation; } } var colori = 0, s; for (i = 0; i < series.length; ++i) { s = series[i]; if (s.color == null) { s.color = colors[colori].toString(); ++colori; } else { if (typeof s.color == "number") { s.color = colors[s.color].toString(); } } if (s.lines.show == null) { var v, show = true; for (v in s) { if (s[v].show) { show = false; break; } } if (show) { s.lines.show = true; } } s.xaxis = axisSpecToRealAxis(s, "xaxis"); s.yaxis = axisSpecToRealAxis(s, "yaxis"); } } function processData() { var topSentry = Number.POSITIVE_INFINITY, bottomSentry = Number.NEGATIVE_INFINITY, i, j, k, m, length, s, points, ps, x, y, axis, val, f, p; for (axis in axes) { axes[axis].datamin = topSentry; axes[axis].datamax = bottomSentry; axes[axis].used = false; } function updateAxis(axis, min, max) { if (min < axis.datamin) { axis.datamin = min; } if (max > axis.datamax) { axis.datamax = max; } } for (i = 0; i < series.length; ++i) { s = series[i]; s.datapoints = { points: [] }; executeHooks(hooks.processRawData, [s, s.data, s.datapoints]); } for (i = 0; i < series.length; ++i) { s = series[i]; var data = s.data, format = s.datapoints.format; if (!format) { format = []; format.push({ x: true, number: true, required: true }); format.push({ y: true, number: true, required: true }); if (s.bars.show) { format.push({ y: true, number: true, required: false, defaultValue: 0 }); } s.datapoints.format = format; } if (s.datapoints.pointsize != null) { continue; } if (s.datapoints.pointsize == null) { s.datapoints.pointsize = format.length; } ps = s.datapoints.pointsize; points = s.datapoints.points; insertSteps = s.lines.show && s.lines.steps; s.xaxis.used = s.yaxis.used = true; for (j = k = 0; j < data.length; ++j, k += ps) { p = data[j]; var nullify = p == null; if (!nullify) { for (m = 0; m < ps; ++m) { val = p[m]; f = format[m]; if (f) { if (f.number && val != null) { val = +val; if (isNaN(val)) { val = null; } } if (val == null) { if (f.required) { nullify = true; } if (f.defaultValue != null) { val = f.defaultValue; } } } points[k + m] = val; } } if (nullify) { for (m = 0; m < ps; ++m) { val = points[k + m]; if (val != null) { f = format[m]; if (f.x) { updateAxis(s.xaxis, val, val); } if (f.y) { updateAxis(s.yaxis, val, val); } } points[k + m] = null; } } else { if (insertSteps && k > 0 && points[k - ps] != null && points[k - ps] != points[k] && points[k - ps + 1] != points[k + 1]) { for (m = 0; m < ps; ++m) { points[k + ps + m] = points[k + m]; } points[k + 1] = points[k - ps + 1]; k += ps; } } } } for (i = 0; i < series.length; ++i) { s = series[i]; executeHooks(hooks.processDatapoints, [s, s.datapoints]); } for (i = 0; i < series.length; ++i) { s = series[i]; points = s.datapoints.points, ps = s.datapoints.pointsize; var xmin = topSentry, ymin = topSentry, xmax = bottomSentry, ymax = bottomSentry; for (j = 0; j < points.length; j += ps) { if (points[j] == null) { continue; } for (m = 0; m < ps; ++m) { val = points[j + m]; f = format[m]; if (!f) { continue; } if (f.x) { if (val < xmin) { xmin = val; } if (val > xmax) { xmax = val; } } if (f.y) { if (val < ymin) { ymin = val; } if (val > ymax) { ymax = val; } } } } if (s.bars.show) { var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth / 2; if (s.bars.horizontal) { ymin += delta; ymax += delta + s.bars.barWidth; } else { xmin += delta; xmax += delta + s.bars.barWidth; } } updateAxis(s.xaxis, xmin, xmax); updateAxis(s.yaxis, ymin, ymax); } for (axis in axes) { if (axes[axis].datamin == topSentry) { axes[axis].datamin = null; } if (axes[axis].datamax == bottomSentry) { axes[axis].datamax = null; } } } function constructCanvas() { function makeCanvas(width, height) { var c = document.createElement("canvas"); c.width = width; c.height = height; if ($.browser.msie) { if (parseInt($.browser.version, 10) != 9) { c = window.G_vmlCanvasManager.initElement(c); } } return c; } canvasWidth = placeholder.width(); canvasHeight = placeholder.height(); placeholder.html(""); if (placeholder.css("position") == "static") { placeholder.css("position", "relative"); } if (canvasWidth <= 0 || canvasHeight <= 0) { throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight; } if ($.browser.msie) { if (parseInt($.browser.version, 10) != 9) { window.G_vmlCanvasManager.init_(document); } } canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(placeholder).get(0); ctx = canvas.getContext("2d"); overlay = $(makeCanvas(canvasWidth, canvasHeight)).css({ position: "absolute", left: 0, top: 0 }).appendTo(placeholder).get(0); octx = overlay.getContext("2d"); octx.stroke(); } function bindEvents() { eventHolder = $([overlay, canvas]); if (options.grid.hoverable) { eventHolder.mousemove(onMouseMove); } if (options.grid.clickable) { eventHolder.click(onClick); } executeHooks(hooks.bindEvents, [eventHolder]); } function setupGrid() { function setTransformationHelpers(axis, o) { function identity(x) { return x; } var s, m, t = o.transform || identity, it = o.inverseTransform; if (axis == axes.xaxis || axis == axes.x2axis) { s = axis.scale = plotWidth / (t(axis.max) - t(axis.min)); m = t(axis.min); if (t == identity) { axis.p2c = function (p) { return (p - m) * s; }; } else { axis.p2c = function (p) { return (t(p) - m) * s; }; } if (!it) { axis.c2p = function (c) { return m + c / s; }; } else { axis.c2p = function (c) { return it(m + c / s); }; } } else { s = axis.scale = plotHeight / (t(axis.max) - t(axis.min)); m = t(axis.max); if (t == identity) { axis.p2c = function (p) { return (m - p) * s; }; } else { axis.p2c = function (p) { return (m - t(p)) * s; }; } if (!it) { axis.c2p = function (c) { return m - c / s; }; } else { axis.c2p = function (c) { return it(m - c / s); }; } } } function measureLabels(axis, axisOptions) { var i, labels = [], l; axis.labelWidth = axisOptions.labelWidth; axis.labelHeight = axisOptions.labelHeight; if (axis == axes.xaxis || axis == axes.x2axis) { if (axis.labelWidth == null) { axis.labelWidth = canvasWidth / (axis.ticks.length > 0 ? axis.ticks.length : 1); } if (axis.labelHeight == null) { labels = []; for (i = 0; i < axis.ticks.length; ++i) { l = axis.ticks[i].label; if (l) { labels.push('<div class="tickLabel" style="float:left;width:' + axis.labelWidth + 'px">' + l + "</div>"); } } if (labels.length > 0) { var dummyDiv = $('<div style="position:absolute;top:-10000px;width:10000px;font-size:smaller">' + labels.join("") + '<div style="clear:left"></div></div>').appendTo(placeholder); axis.labelHeight = dummyDiv.height(); dummyDiv.remove(); } } } else { if (axis.labelWidth == null || axis.labelHeight == null) { for (i = 0; i < axis.ticks.length; ++i) { l = axis.ticks[i].label; if (l) { labels.push('<div class="tickLabel">' + l + "</div>"); } } if (labels.length > 0) { var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller">' + labels.join("") + "</div>").appendTo(placeholder); if (axis.labelWidth == null) { axis.labelWidth = dummyDiv.width(); } if (axis.labelHeight == null) { axis.labelHeight = dummyDiv.find("div").height(); } dummyDiv.remove(); } } } if (axis.labelWidth == null) { axis.labelWidth = 0; } if (axis.labelHeight == null) { axis.labelHeight = 0; } } function setGridSpacing() { var maxOutset = options.grid.borderWidth; for (i = 0; i < series.length; ++i) { maxOutset = Math.max(maxOutset, 2 * (series[i].points.radius + series[i].points.lineWidth / 2)); } plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = maxOutset; var margin = options.grid.labelMargin + options.grid.borderWidth; if (axes.xaxis.labelHeight > 0) { plotOffset.bottom = Math.max(maxOutset, axes.xaxis.labelHeight + margin); } if (axes.yaxis.labelWidth > 0) { plotOffset.left = Math.max(maxOutset, axes.yaxis.labelWidth + margin); } if (axes.x2axis.labelHeight > 0) { plotOffset.top = Math.max(maxOutset, axes.x2axis.labelHeight + margin); } if (axes.y2axis.labelWidth > 0) { plotOffset.right = Math.max(maxOutset, axes.y2axis.labelWidth + margin); } plotWidth = canvasWidth - plotOffset.left - plotOffset.right; plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top; } var axis; for (axis in axes) { setRange(axes[axis], options[axis]); } if (options.grid.show) { for (axis in axes) { prepareTickGeneration(axes[axis], options[axis]); setTicks(axes[axis], options[axis]); measureLabels(axes[axis], options[axis]); } setGridSpacing(); } else { plotOffset.left = plotOffset.right = plotOffset.top = plotOffset.bottom = 0; plotWidth = canvasWidth; plotHeight = canvasHeight; } for (axis in axes) { setTransformationHelpers(axes[axis], options[axis]); } if (options.grid.show) { insertLabels(); } insertLegend(); } function setRange(axis, axisOptions) { var min = +(axisOptions.min != null ? axisOptions.min : axis.datamin), max = +(axisOptions.max != null ? axisOptions.max : axis.datamax), delta = max - min; if (delta == 0) { var widen = max == 0 ? 1 : 0.01; if (axisOptions.min == null) { min -= widen; } if (axisOptions.max == null || axisOptions.min != null) { max += widen; } } else { var margin = axisOptions.autoscaleMargin; if (margin != null) { if (axisOptions.min == null) { min -= delta * margin; if (min < 0 && axis.datamin != null && axis.datamin >= 0) { min = 0; } } if (axisOptions.max == null) { max += delta * margin; if (max > 0 && axis.datamax != null && axis.datamax <= 0) { max = 0; } } } } axis.min = min; axis.max = max; } function prepareTickGeneration(axis, axisOptions) { var noTicks; if (typeof axisOptions.ticks == "number" && axisOptions.ticks > 0) { noTicks = axisOptions.ticks; } else { if (axis == axes.xaxis || axis == axes.x2axis) { noTicks = 0.3 * Math.sqrt(canvasWidth); } else { noTicks = 0.3 * Math.sqrt(canvasHeight); } } var delta = (axis.max - axis.min) / noTicks, size, generator, unit, formatter, i, magn, norm; if (axisOptions.mode == "time") { var timeUnitSize = { second: 1000, minute: 60 * 1000, hour: 60 * 60 * 1000, day: 24 * 60 * 60 * 1000, month: 30 * 24 * 60 * 60 * 1000, year: 365.2425 * 24 * 60 * 60 * 1000 }; var spec = [[1, "second"], [2, "second"], [5, "second"], [10, "second"], [30, "second"], [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], [30, "minute"], [1, "hour"], [2, "hour"], [4, "hour"], [8, "hour"], [12, "hour"], [1, "day"], [2, "day"], [3, "day"], [0.25, "month"], [0.5, "month"], [1, "month"], [2, "month"], [3, "month"], [6, "month"], [1, "year"]]; var minSize = 0; if (axisOptions.minTickSize != null) { if (typeof axisOptions.tickSize == "number") { minSize = axisOptions.tickSize; } else { minSize = axisOptions.minTickSize[0] * timeUnitSize[axisOptions.minTickSize[1]]; } } for (i = 0; i < spec.length - 1; ++i) { if (delta < (spec[i][0] * timeUnitSize[spec[i][1]] + spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2 && spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) { break; } } size = spec[i][0]; unit = spec[i][1]; if (unit == "year") { magn = Math.pow(10, Math.floor(Math.log(delta / timeUnitSize.year) / Math.LN10)); norm = (delta / timeUnitSize.year) / magn; if (norm < 1.5) { size = 1; } else { if (norm < 3) { size = 2; } else { if (norm < 7.5) { size = 5; } else { size = 10; } } } size *= magn; } if (axisOptions.tickSize) { size = axisOptions.tickSize[0]; unit = axisOptions.tickSize[1]; } generator = function (axis) { var ticks = [], tickSize = axis.tickSize[0], unit = axis.tickSize[1], d = new Date(axis.min); var step = tickSize * timeUnitSize[unit]; if (unit == "second") { d.setUTCSeconds(floorInBase(d.getUTCSeconds(), tickSize)); } if (unit == "minute") { d.setUTCMinutes(floorInBase(d.getUTCMinutes(), tickSize)); } if (unit == "hour") { d.setUTCHours(floorInBase(d.getUTCHours(), tickSize)); } if (unit == "month") { d.setUTCMonth(floorInBase(d.getUTCMonth(), tickSize)); } if (unit == "year") { d.setUTCFullYear(floorInBase(d.getUTCFullYear(), tickSize)); } d.setUTCMilliseconds(0); if (step >= timeUnitSize.minute) { d.setUTCSeconds(0); } if (step >= timeUnitSize.hour) { d.setUTCMinutes(0); } if (step >= timeUnitSize.day) { d.setUTCHours(0); } if (step >= timeUnitSize.day * 4) { d.setUTCDate(1); } if (step >= timeUnitSize.year) { d.setUTCMonth(0); } var carry = 0, v = Number.NaN, prev; do { prev = v; v = d.getTime(); ticks.push({ v: v, label: axis.tickFormatter(v, axis) }); if (unit == "month") { if (tickSize < 1) { d.setUTCDate(1); var start = d.getTime(); d.setUTCMonth(d.getUTCMonth() + 1); var end = d.getTime(); d.setTime(v + carry * timeUnitSize.hour + (end - start) * tickSize); carry = d.getUTCHours(); d.setUTCHours(0); } else { d.setUTCMonth(d.getUTCMonth() + tickSize); } } else { if (unit == "year") { d.setUTCFullYear(d.getUTCFullYear() + tickSize); } else { d.setTime(v + step); } } } while (v < axis.max && v != prev); return ticks; }; formatter = function (v, axis) { var d = new Date(v); if (axisOptions.timeformat != null) { return $.plot.formatDate(d, axisOptions.timeformat, axisOptions.monthNames); } var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]]; var span = axis.max - axis.min; var suffix = (axisOptions.twelveHourClock) ? " %p" : ""; if (t < timeUnitSize.minute) { fmt = "%h:%M:%S" + suffix; } else { if (t < timeUnitSize.day) { if (span < 2 * timeUnitSize.day) { fmt = "%h:%M" + suffix; } else { fmt = "%b %d %h:%M" + suffix; } } else { if (t < timeUnitSize.month) { fmt = "%b %d"; } else { if (t < timeUnitSize.year) { if (span < timeUnitSize.year) { fmt = "%b"; } else { fmt = "%b %y"; } } else { fmt = "%y"; } } } } return $.plot.formatDate(d, fmt, axisOptions.monthNames); }; } else { var maxDec = axisOptions.tickDecimals; var dec = -Math.floor(Math.log(delta) / Math.LN10); if (maxDec != null && dec > maxDec) { dec = maxDec; } magn = Math.pow(10, -dec); norm = delta / magn; if (norm < 1.5) { size = 1; } else { if (norm < 3) { size = 2; if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) { size = 2.5; ++dec; } } else { if (norm < 7.5) { size = 5; } else { size = 10; } } } size *= magn; if (axisOptions.minTickSize != null && size < axisOptions.minTickSize) { size = axisOptions.minTickSize; } if (axisOptions.tickSize != null) { size = axisOptions.tickSize; } axis.tickDecimals = Math.max(0, (maxDec != null) ? maxDec : dec); generator = function (axis) { var ticks = []; var start = floorInBase(axis.min, axis.tickSize), i = 0, v = Number.NaN, prev; do { prev = v; v = start + i * axis.tickSize; ticks.push({ v: v, label: axis.tickFormatter(v, axis) }); ++i; } while (v < axis.max && v != prev); return ticks; }; formatter = function (v, axis) { return v.toFixed(axis.tickDecimals); }; } axis.tickSize = unit ? [size, unit] : size; axis.tickGenerator = generator; if ($.isFunction(axisOptions.tickFormatter)) { axis.tickFormatter = function (v, axis) { return "" + axisOptions.tickFormatter(v, axis); }; } else { axis.tickFormatter = formatter; } } function setTicks(axis, axisOptions) { axis.ticks = []; if (!axis.used) { return; } if (axisOptions.ticks == null) { axis.ticks = axis.tickGenerator(axis); } else { if (typeof axisOptions.ticks == "number") { if (axisOptions.ticks > 0) { axis.ticks = axis.tickGenerator(axis); } } else { if (axisOptions.ticks) { var ticks = axisOptions.ticks; if ($.isFunction(ticks)) { ticks = ticks({ min: axis.min, max: axis.max }); } var i, v; for (i = 0; i < ticks.length; ++i) { var label = null; var t = ticks[i]; if (typeof t == "object") { v = t[0]; if (t.length > 1) { label = t[1]; } } else { v = t; } if (label == null) { label = axis.tickFormatter(v, axis); } axis.ticks[i] = { v: v, label: label }; } } } } if (axisOptions.autoscaleMargin != null && axis.ticks.length > 0) { if (axisOptions.min == null) { axis.min = Math.min(axis.min, axis.ticks[0].v); } if (axisOptions.max == null && axis.ticks.length > 1) { axis.max = Math.max(axis.max, axis.ticks[axis.ticks.length - 1].v); } } } function draw() { ctx.clearRect(0, 0, canvasWidth, canvasHeight); var grid = options.grid; if (grid.show && !grid.aboveData) { drawGrid(); } for (var i = 0; i < series.length; ++i) { drawSeries(series[i]); } executeHooks(hooks.draw, [ctx]); if (grid.show && grid.aboveData) { drawGrid(); } } function extractRange(ranges, coord) { var firstAxis = coord + "axis", secondaryAxis = coord + "2axis", axis, from, to, reverse; if (ranges[firstAxis]) { axis = axes[firstAxis]; from = ranges[firstAxis].from; to = ranges[firstAxis].to; } else { if (ranges[secondaryAxis]) { axis = axes[secondaryAxis]; from = ranges[secondaryAxis].from; to = ranges[secondaryAxis].to; } else { axis = axes[firstAxis]; from = ranges[coord + "1"]; to = ranges[coord + "2"]; } } if (from != null && to != null && from > to) { return { from: to, to: from, axis: axis }; } return { from: from, to: to, axis: axis }; } function drawGrid() { var i; ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); if (options.grid.backgroundColor) { ctx.fillStyle = getColorOrGradient(options.grid.backgroundColor, plotHeight, 0, "rgba(255, 255, 255, 0)"); ctx.fillRect(0, 0, plotWidth, plotHeight); } var markings = options.grid.markings; if (markings) { if ($.isFunction(markings)) { markings = markings({ xmin: axes.xaxis.min, xmax: axes.xaxis.max, ymin: axes.yaxis.min, ymax: axes.yaxis.max, xaxis: axes.xaxis, yaxis: axes.yaxis, x2axis: axes.x2axis, y2axis: axes.y2axis }); } for (i = 0; i < markings.length; ++i) { var m = markings[i], xrange = extractRange(m, "x"), yrange = extractRange(m, "y"); if (xrange.from == null) { xrange.from = xrange.axis.min; } if (xrange.to == null) { xrange.to = xrange.axis.max; } if (yrange.from == null) { yrange.from = yrange.axis.min; } if (yrange.to == null) { yrange.to = yrange.axis.max; } if (xrange.to < xrange.axis.min || xrange.from > xrange.axis.max || yrange.to < yrange.axis.min || yrange.from > yrange.axis.max) { continue; } xrange.from = Math.max(xrange.from, xrange.axis.min); xrange.to = Math.min(xrange.to, xrange.axis.max); yrange.from = Math.max(yrange.from, yrange.axis.min); yrange.to = Math.min(yrange.to, yrange.axis.max); if (xrange.from == xrange.to && yrange.from == yrange.to) { continue; } xrange.from = xrange.axis.p2c(xrange.from); xrange.to = xrange.axis.p2c(xrange.to); yrange.from = yrange.axis.p2c(yrange.from); yrange.to = yrange.axis.p2c(yrange.to); if (xrange.from == xrange.to || yrange.from == yrange.to) { ctx.beginPath(); ctx.strokeStyle = m.color || options.grid.markingsColor; ctx.lineWidth = m.lineWidth || options.grid.markingsLineWidth; ctx.moveTo(xrange.from, yrange.from); ctx.lineTo(xrange.to, yrange.to); ctx.stroke(); } else { ctx.fillStyle = m.color || options.grid.markingsColor; ctx.fillRect(xrange.from, yrange.to, xrange.to - xrange.from, yrange.from - yrange.to); } } } ctx.lineWidth = 1; ctx.strokeStyle = options.grid.tickColor; ctx.beginPath(); var v, axis = axes.xaxis; for (i = 0; i < axis.ticks.length; ++i) { v = axis.ticks[i].v; if (v <= axis.min || v >= axes.xaxis.max) { continue; } ctx.moveTo(Math.floor(axis.p2c(v)) + ctx.lineWidth / 2, 0); ctx.lineTo(Math.floor(axis.p2c(v)) + ctx.lineWidth / 2, plotHeight); } axis = axes.yaxis; for (i = 0; i < axis.ticks.length; ++i) { v = axis.ticks[i].v; if (v <= axis.min || v >= axis.max) { continue; } ctx.moveTo(0, Math.floor(axis.p2c(v)) + ctx.lineWidth / 2); ctx.lineTo(plotWidth, Math.floor(axis.p2c(v)) + ctx.lineWidth / 2); } axis = axes.x2axis; for (i = 0; i < axis.ticks.length; ++i) { v = axis.ticks[i].v; if (v <= axis.min || v >= axis.max) { continue; } ctx.moveTo(Math.floor(axis.p2c(v)) + ctx.lineWidth / 2, -5); ctx.lineTo(Math.floor(axis.p2c(v)) + ctx.lineWidth / 2, 5); } axis = axes.y2axis; for (i = 0; i < axis.ticks.length; ++i) { v = axis.ticks[i].v; if (v <= axis.min || v >= axis.max) { continue; } ctx.moveTo(plotWidth - 5, Math.floor(axis.p2c(v)) + ctx.lineWidth / 2); ctx.lineTo(plotWidth + 5, Math.floor(axis.p2c(v)) + ctx.lineWidth / 2); } ctx.stroke(); if (options.grid.borderWidth) { var bw = options.grid.borderWidth; ctx.lineWidth = bw; ctx.strokeStyle = options.grid.borderColor; ctx.strokeRect(-bw / 2, -bw / 2, plotWidth + bw, plotHeight + bw); } ctx.restore(); } function insertLabels() { placeholder.find(".tickLabels").remove(); var html = ['<div class="tickLabels" style="font-size:smaller;color:' + options.grid.color + '">']; function addLabels(axis, labelGenerator) { for (var i = 0; i < axis.ticks.length; ++i) { var tick = axis.ticks[i]; if (!tick.label || tick.v < axis.min || tick.v > axis.max) { continue; } html.push(labelGenerator(tick, axis)); } } var margin = options.grid.labelMargin + options.grid.borderWidth; addLabels(axes.xaxis, function (tick, axis) { return '<div style="position:absolute;top:' + (plotOffset.top + plotHeight + margin) + "px;left:" + Math.round(plotOffset.left + axis.p2c(tick.v) - axis.labelWidth / 2) + "px;width:" + axis.labelWidth + 'px;text-align:center" class="tickLabel">' + tick.label + "</div>"; }); addLabels(axes.yaxis, function (tick, axis) { return '<div style="position:absolute;top:' + Math.round(plotOffset.top + axis.p2c(tick.v) - axis.labelHeight / 2) + "px;right:" + (plotOffset.right + plotWidth + margin) + "px;width:" + axis.labelWidth + 'px;text-align:right" class="tickLabel">' + tick.label + "</div>"; }); addLabels(axes.x2axis, function (tick, axis) { return '<div style="position:absolute;bottom:' + (plotOffset.bottom + plotHeight + margin) + "px;left:" + Math.round(plotOffset.left + axis.p2c(tick.v) - axis.labelWidth / 2) + "px;width:" + axis.labelWidth + 'px;text-align:center" class="tickLabel">' + tick.label + "</div>"; }); addLabels(axes.y2axis, function (tick, axis) { return '<div style="position:absolute;top:' + Math.round(plotOffset.top + axis.p2c(tick.v) - axis.labelHeight / 2) + "px;left:" + (plotOffset.left + plotWidth + margin) + "px;width:" + axis.labelWidth + 'px;text-align:left" class="tickLabel">' + tick.label + "</div>"; }); html.push("</div>"); placeholder.append(html.join("")); } function drawSeries(series) { if (series.lines.show) { drawSeriesLines(series); } if (series.bars.show) { drawSeriesBars(series); } if (series.points.show) { drawSeriesPoints(series); } } function drawSeriesLines(series) { function plotLine(datapoints, xoffset, yoffset, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize, prevx = null, prevy = null; ctx.beginPath(); for (var i = ps; i < points.length; i += ps) { var x1 = points[i - ps], y1 = points[i - ps + 1], x2 = points[i], y2 = points[i + 1]; if (x1 == null || x2 == null) { continue; } if (y1 <= y2 && y1 < axisy.min) { if (y2 < axisy.min) { continue; } x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.min; } else { if (y2 <= y1 && y2 < axisy.min) { if (y1 < axisy.min) { continue; } x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.min; } } if (y1 >= y2 && y1 > axisy.max) { if (y2 > axisy.max) { continue; } x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.max; } else { if (y2 >= y1 && y2 > axisy.max) { if (y1 > axisy.max) { continue; } x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.max; } } if (x1 <= x2 && x1 < axisx.min) { if (x2 < axisx.min) { continue; } y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.min; } else { if (x2 <= x1 && x2 < axisx.min) { if (x1 < axisx.min) { continue; } y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.min; } } if (x1 >= x2 && x1 > axisx.max) { if (x2 > axisx.max) { continue; } y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.max; } else { if (x2 >= x1 && x2 > axisx.max) { if (x1 > axisx.max) { continue; } y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.max; } } if (x1 != prevx || y1 != prevy) { ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset); } prevx = x2; prevy = y2; ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y2) + yoffset); } ctx.stroke(); } function plotLineArea(datapoints, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize, bottom = Math.min(Math.max(0, axisy.min), axisy.max), top, lastX = 0, areaOpen = false; for (var i = ps; i < points.length; i += ps) { var x1 = points[i - ps], y1 = points[i - ps + 1], x2 = points[i], y2 = points[i + 1]; if (areaOpen && x1 != null && x2 == null) { ctx.lineTo(axisx.p2c(lastX), axisy.p2c(bottom)); ctx.fill(); areaOpen = false; continue; } if (x1 == null || x2 == null) { continue; } if (x1 <= x2 && x1 < axisx.min) { if (x2 < axisx.min) { continue; } y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.min; } else { if (x2 <= x1 && x2 < axisx.min) { if (x1 < axisx.min) { continue; } y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.min; } } if (x1 >= x2 && x1 > axisx.max) { if (x2 > axisx.max) { continue; } y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.max; } else { if (x2 >= x1 && x2 > axisx.max) { if (x1 > axisx.max) { continue; } y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.max; } } if (!areaOpen) { ctx.beginPath(); ctx.moveTo(axisx.p2c(x1), axisy.p2c(bottom)); areaOpen = true; } if (y1 >= axisy.max && y2 >= axisy.max) { ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.max)); lastX = x2; continue; } else { if (y1 <= axisy.min && y2 <= axisy.min) { ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.min)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min)); lastX = x2; continue; } } var x1old = x1, x2old = x2; if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) { x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.min; } else { if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) { x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.min; } } if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) { x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.max; } else { if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) { x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.max; } } if (x1 != x1old) { if (y1 <= axisy.min) { top = axisy.min; } else { top = axisy.max; } ctx.lineTo(axisx.p2c(x1old), axisy.p2c(top)); ctx.lineTo(axisx.p2c(x1), axisy.p2c(top)); } ctx.lineTo(axisx.p2c(x1), axisy.p2c(y1)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(y2)); if (x2 != x2old) { if (y2 <= axisy.min) { top = axisy.min; } else { top = axisy.max; } ctx.lineTo(axisx.p2c(x2), axisy.p2c(top)); ctx.lineTo(axisx.p2c(x2old), axisy.p2c(top)); } lastX = Math.max(x2, x2old); } if (areaOpen) { ctx.lineTo(axisx.p2c(lastX), axisy.p2c(bottom)); ctx.fill(); } } ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); ctx.lineJoin = "round"; var lw = series.lines.lineWidth, sw = series.shadowSize; if (lw > 0 && sw > 0) { ctx.lineWidth = sw; ctx.strokeStyle = "rgba(0,0,0,0.1)"; var angle = Math.PI / 18; plotLine(series.datapoints, Math.sin(angle) * (lw / 2 + sw / 2), Math.cos(angle) * (lw / 2 + sw / 2), series.xaxis, series.yaxis); ctx.lineWidth = sw / 2; plotLine(series.datapoints, Math.sin(angle) * (lw / 2 + sw / 4), Math.cos(angle) * (lw / 2 + sw / 4), series.xaxis, series.yaxis); } ctx.lineWidth = lw; ctx.strokeStyle = series.color; var fillStyle = getFillStyle(series.lines, series.color, 0, plotHeight); if (fillStyle) { ctx.fillStyle = fillStyle; plotLineArea(series.datapoints, series.xaxis, series.yaxis); } if (lw > 0) { plotLine(series.datapoints, 0, 0, series.xaxis, series.yaxis); } ctx.restore(); } function drawSeriesPoints(series) { function plotPoints(datapoints, radius, fillStyle, offset, circumference, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize; for (var i = 0; i < points.length; i += ps) { var x = points[i], y = points[i + 1]; if (x == null || x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) { continue; } ctx.beginPath(); ctx.arc(axisx.p2c(x), axisy.p2c(y) + offset, radius, 0, circumference, false); if (fillStyle) { ctx.fillStyle = fillStyle; ctx.fill(); } ctx.stroke(); } } ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); var lw = series.lines.lineWidth, sw = series.shadowSize, radius = series.points.radius; if (lw > 0 && sw > 0) { var w = sw / 2; ctx.lineWidth = w; ctx.strokeStyle = "rgba(0,0,0,0.1)"; plotPoints(series.datapoints, radius, null, w + w / 2, Math.PI, series.xaxis, series.yaxis); ctx.strokeStyle = "rgba(0,0,0,0.2)"; plotPoints(series.datapoints, radius, null, w / 2, Math.PI, series.xaxis, series.yaxis); } ctx.lineWidth = lw; ctx.strokeStyle = series.color; plotPoints(series.datapoints, radius, getFillStyle(series.points, series.color), 0, 2 * Math.PI, series.xaxis, series.yaxis); ctx.restore(); } function drawBar(x, y, b, barLeft, barRight, offset, fillStyleCallback, axisx, axisy, c, horizontal) { var left, right, bottom, top, drawLeft, drawRight, drawTop, drawBottom, tmp; if (horizontal) { drawBottom = drawRight = drawTop = true; drawLeft = false; left = b; right = x; top = y + barLeft; bottom = y + barRight; if (right < left) { tmp = right; right = left; left = tmp; drawLeft = true; drawRight = false; } } else { drawLeft = drawRight = drawTop = true; drawBottom = false; left = x + barLeft; right = x + barRight; bottom = b; top = y; if (top < bottom) { tmp = top; top = bottom; bottom = tmp; drawBottom = true; drawTop = false; } } if (right < axisx.min || left > axisx.max || top < axisy.min || bottom > axisy.max) { return; } if (left < axisx.min) { left = axisx.min; drawLeft = false; } if (right > axisx.max) { right = axisx.max; drawRight = false; } if (bottom < axisy.min) { bottom = axisy.min; drawBottom = false; } if (top > axisy.max) { top = axisy.max; drawTop = false; } left = axisx.p2c(left); bottom = axisy.p2c(bottom); right = axisx.p2c(right); top = axisy.p2c(top); if (fillStyleCallback) { c.beginPath(); c.moveTo(left, bottom); c.lineTo(left, top); c.lineTo(right, top); c.lineTo(right, bottom); c.fillStyle = fillStyleCallback(bottom, top); c.fill(); } if (drawLeft || drawRight || drawTop || drawBottom) { c.beginPath(); c.moveTo(left, bottom + offset); if (drawLeft) { c.lineTo(left, top + offset); } else { c.moveTo(left, top + offset); } if (drawTop) { c.lineTo(right, top + offset); } else { c.moveTo(right, top + offset); } if (drawRight) { c.lineTo(right, bottom + offset); } else { c.moveTo(right, bottom + offset); } if (drawBottom) { c.lineTo(left, bottom + offset); } else { c.moveTo(left, bottom + offset); } c.stroke(); } } function drawSeriesBars(series) { function plotBars(datapoints, barLeft, barRight, offset, fillStyleCallback, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize; for (var i = 0; i < points.length; i += ps) { if (points[i] == null) { continue; } drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal); } } ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); ctx.lineWidth = series.bars.lineWidth; ctx.strokeStyle = series.color; var barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth / 2; var fillStyleCallback = series.bars.fill ? function (bottom, top) { return getFillStyle(series.bars, series.color, bottom, top); } : null; plotBars(series.datapoints, barLeft, barLeft + series.bars.barWidth, 0, fillStyleCallback, series.xaxis, series.yaxis); ctx.restore(); } function getFillStyle(filloptions, seriesColor, bottom, top) { var fill = filloptions.fill; if (!fill) { return null; } if (filloptions.fillColor) { return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor); } var c = $.color.parse(seriesColor); c.a = typeof fill == "number" ? fill : 0.4; c.normalize(); return c.toString(); } function insertLegend() { placeholder.find(".legend").remove(); if (!options.legend.show) { return; } var fragments = [], rowStarted = false, lf = options.legend.labelFormatter, s, label; for (i = 0; i < series.length; ++i) { s = series[i]; label = s.label; if (!label) { continue; } if (i % options.legend.noColumns == 0) { if (rowStarted) { fragments.push("</tr>"); } fragments.push("<tr>"); rowStarted = true; } if (lf) { label = lf(label, s); } fragments.push('<td class="legendColorBox"><div style="border:1px solid ' + options.legend.labelBoxBorderColor + ';padding:1px"><div style="width:4px;height:0;border:5px solid ' + s.color + ';overflow:hidden"></div></div></td><td class="legendLabel">' + label + "</td>"); } if (rowStarted) { fragments.push("</tr>"); } if (fragments.length == 0) { return; } var table = '<table style="font-size:smaller;color:' + options.grid.color + '">' + fragments.join("") + "</table>"; if (options.legend.container != null) { $(options.legend.container).html(table); } else { var pos = "", p = options.legend.position, m = options.legend.margin; if (m[0] == null) { m = [m, m]; } if (p.charAt(0) == "n") { pos += "top:" + (m[1] + plotOffset.top) + "px;"; } else { if (p.charAt(0) == "s") { pos += "bottom:" + (m[1] + plotOffset.bottom) + "px;"; } } if (p.charAt(1) == "e") { pos += "right:" + (m[0] + plotOffset.right) + "px;"; } else { if (p.charAt(1) == "w") { pos += "left:" + (m[0] + plotOffset.left) + "px;"; } } var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos + ";") + "</div>").appendTo(placeholder); if (options.legend.backgroundOpacity != 0) { var c = options.legend.backgroundColor; if (c == null) { c = options.grid.backgroundColor; if (c && typeof c == "string") { c = $.color.parse(c); } else { c = $.color.extract(legend, "background-color"); } c.a = 1; c = c.toString(); } var div = legend.children(); $('<div style="position:absolute;width:' + div.width() + "px;height:" + div.height() + "px;" + pos + "background-color:" + c + ';"> </div>').prependTo(legend).css("opacity", options.legend.backgroundOpacity); } } } var highlights = [], redrawTimeout = null; function findNearbyItem(mouseX, mouseY, seriesFilter) { var maxDistance = options.grid.mouseActiveRadius, smallestDistance = maxDistance * maxDistance + 1, item = null, foundPoint = false, i, j; for (i = 0; i < series.length; ++i) { if (!seriesFilter(series[i])) { continue; } var s = series[i], axisx = s.xaxis, axisy = s.yaxis, points = s.datapoints.points, ps = s.datapoints.pointsize, mx = axisx.c2p(mouseX), my = axisy.c2p(mouseY), maxx = maxDistance / axisx.scale, maxy = maxDistance / axisy.scale; if (s.lines.show || s.points.show) { for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1]; if (x == null) { continue; } if (x - mx > maxx || x - mx < -maxx || y - my > maxy || y - my < -maxy) { continue; } var dx = Math.abs(axisx.p2c(x) - mouseX), dy = Math.abs(axisy.p2c(y) - mouseY), dist = dx * dx + dy * dy; if (dist <= smallestDistance) { smallestDistance = dist; item = [i, j / ps]; } } } if (s.bars.show && !item) { var barLeft = s.bars.align == "left" ? 0 : -s.bars.barWidth / 2, barRight = barLeft + s.bars.barWidth; for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1], b = points[j + 2]; if (x == null) { continue; } if (series[i].bars.horizontal ? (mx <= Math.max(b, x) && mx >= Math.min(b, x) && my >= y + barLeft && my <= y + barRight) : (mx >= x + barLeft && mx <= x + barRight && my >= Math.min(b, y) && my <= Math.max(b, y))) { item = [i, j / ps]; } } } } if (item) { i = item[0]; j = item[1]; ps = series[i].datapoints.pointsize; return { datapoint: series[i].datapoints.points.slice(j * ps, (j + 1) * ps), dataIndex: j, series: series[i], seriesIndex: i }; } return null; } function onMouseMove(e) { if (options.grid.hoverable) { triggerClickHoverEvent("plothover", e, function (s) { return s.hoverable != false; }); } } function onClick(e) { triggerClickHoverEvent("plotclick", e, function (s) { return s.clickable != false; }); } function triggerClickHoverEvent(eventname, event, seriesFilter) { var offset = eventHolder.offset(), pos = { pageX: event.pageX, pageY: event.pageY }, canvasX = event.pageX - offset.left - plotOffset.left, canvasY = event.pageY - offset.top - plotOffset.top; if (axes.xaxis.used) { pos.x = axes.xaxis.c2p(canvasX); } if (axes.yaxis.used) { pos.y = axes.yaxis.c2p(canvasY); } if (axes.x2axis.used) { pos.x2 = axes.x2axis.c2p(canvasX); } if (axes.y2axis.used) { pos.y2 = axes.y2axis.c2p(canvasY); } var item = findNearbyItem(canvasX, canvasY, seriesFilter); if (item) { item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left + plotOffset.left); item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top + plotOffset.top); } if (options.grid.autoHighlight) { for (var i = 0; i < highlights.length; ++i) { var h = highlights[i]; if (h.auto == eventname && !(item && h.series == item.series && h.point == item.datapoint)) { unhighlight(h.series, h.point); } } if (item) { highlight(item.series, item.datapoint, eventname); } } placeholder.trigger(eventname, [pos, item]); } function triggerRedrawOverlay() { if (!redrawTimeout) { redrawTimeout = setTimeout(drawOverlay, 30); } } function drawOverlay() { redrawTimeout = null; octx.save(); octx.clearRect(0, 0, canvasWidth, canvasHeight); octx.translate(plotOffset.left, plotOffset.top); var i, hi; for (i = 0; i < highlights.length; ++i) { hi = highlights[i]; if (hi.series.bars.show) { drawBarHighlight(hi.series, hi.point); } else { drawPointHighlight(hi.series, hi.point); } } octx.restore(); executeHooks(hooks.drawOverlay, [octx]); } function highlight(s, point, auto) { if (typeof s == "number") { s = series[s]; } if (typeof point == "number") { point = s.data[point]; } var i = indexOfHighlight(s, point); if (i == -1) { highlights.push({ series: s, point: point, auto: auto }); triggerRedrawOverlay(); } else { if (!auto) { highlights[i].auto = false; } } } function unhighlight(s, point) { if (s == null && point == null) { highlights = []; triggerRedrawOverlay(); } if (typeof s == "number") { s = series[s]; } if (typeof point == "number") { point = s.data[point]; } var i = indexOfHighlight(s, point); if (i != -1) { highlights.splice(i, 1); triggerRedrawOverlay(); } } function indexOfHighlight(s, p) { for (var i = 0; i < highlights.length; ++i) { var h = highlights[i]; if (h.series == s && h.point[0] == p[0] && h.point[1] == p[1]) { return i; } } return -1; } function drawPointHighlight(series, point) { var x = point[0], y = point[1], axisx = series.xaxis, axisy = series.yaxis; if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) { return; } var pointRadius = series.points.radius + series.points.lineWidth / 2; octx.lineWidth = pointRadius; octx.strokeStyle = $.color.parse(series.color).scale("a", 0.5).toString(); var radius = 1.5 * pointRadius; octx.beginPath(); octx.arc(axisx.p2c(x), axisy.p2c(y), radius, 0, 2 * Math.PI, false); octx.stroke(); } function drawBarHighlight(series, point) { octx.lineWidth = series.bars.lineWidth; octx.strokeStyle = $.color.parse(series.color).scale("a", 0.5).toString(); var fillStyle = $.color.parse(series.color).scale("a", 0.5).toString(); var barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth / 2; drawBar(point[0], point[1], point[2] || 0, barLeft, barLeft + series.bars.barWidth, 0, function () { return fillStyle; }, series.xaxis, series.yaxis, octx, series.bars.horizontal); } function getColorOrGradient(spec, bottom, top, defaultColor) { if (typeof spec == "string") { return spec; } else { var gradient = ctx.createLinearGradient(0, top, 0, bottom); for (var i = 0, l = spec.colors.length; i < l; ++i) { var c = spec.colors[i]; if (typeof c != "string") { c = $.color.parse(defaultColor).scale("rgb", c.brightness); c.a *= c.opacity; c = c.toString(); } gradient.addColorStop(i / (l - 1), c); } return gradient; } } } $.plot = function (placeholder, data, options) { var plot = new Plot($(placeholder), data, options, $.plot.plugins); return plot; }; $.plot.plugins = []; $.plot.formatDate = function (d, fmt, monthNames) { var leftPad = function (n) { n = "" + n; return n.length == 1 ? "0" + n : n; }; var r = []; var escape = false; var hours = d.getUTCHours(); var isAM = hours < 12; if (monthNames == null) { monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; } if (fmt.search(/%p|%P/) != -1) { if (hours > 12) { hours = hours - 12; } else { if (hours == 0) { hours = 12; } } } for (var i = 0; i < fmt.length; ++i) { var c = fmt.charAt(i); if (escape) { switch (c) { case "h": c = "" + hours; break; case "H": c = leftPad(hours); break; case "M": c = leftPad(d.getUTCMinutes()); break; case "S": c = leftPad(d.getUTCSeconds()); break; case "d": c = "" + d.getUTCDate(); break; case "m": c = "" + (d.getUTCMonth() + 1); break; case "y": c = "" + d.getUTCFullYear(); break; case "b": c = "" + monthNames[d.getUTCMonth()]; break; case "p": c = (isAM) ? ("am") : ("pm"); break; case "P": c = (isAM) ? ("AM") : ("PM"); break; } r.push(c); escape = false; } else { if (c == "%") { escape = true; } else { r.push(c); } } } return r.join(""); }; function floorInBase(n, base) { return base * Math.floor(n / base); } })(jQuery); jQuery.ui || (function (c) { var i = c.fn.remove, d = c.browser.mozilla && (parseFloat(c.browser.version) < 1.9); c.ui = { version: "1.7.1", plugin: { add: function (k, l, n) { var m = c.ui[k].prototype; for (var j in n) { m.plugins[j] = m.plugins[j] || []; m.plugins[j].push([l, n[j]]); } }, call: function (j, l, k) { var n = j.plugins[l]; if (!n || !j.element[0].parentNode) { return; } for (var m = 0; m < n.length; m++) { if (j.options[n[m][0]]) { n[m][1].apply(j.element, k); } } } }, contains: function (k, j) { return document.compareDocumentPosition ? k.compareDocumentPosition(j) & 16 : k !== j && k.contains(j); }, hasScroll: function (m, k) { if (c(m).css("overflow") == "hidden") { return false; } var j = (k && k == "left") ? "scrollLeft" : "scrollTop", l = false; if (m[j] > 0) { return true; } m[j] = 1; l = (m[j] > 0); m[j] = 0; return l; }, isOverAxis: function (k, j, l) { return (k > j) && (k < (j + l)); }, isOver: function (o, k, n, m, j, l) { return c.ui.isOverAxis(o, n, j) && c.ui.isOverAxis(k, m, l); }, keyCode: { BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, CONTROL: 17, DELETE: 46, DOWN: 40, END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37, NUMPAD_ADD: 107, NUMPAD_DECIMAL: 110, NUMPAD_DIVIDE: 111, NUMPAD_ENTER: 108, NUMPAD_MULTIPLY: 106, NUMPAD_SUBTRACT: 109, PAGE_DOWN: 34, PAGE_UP: 33, PERIOD: 190, RIGHT: 39, SHIFT: 16, SPACE: 32, TAB: 9, UP: 38} }; if (d) { var f = c.attr, e = c.fn.removeAttr, h = "http://www.w3.org/2005/07/aaa", a = /^aria-/, b = /^wairole:/; c.attr = function (k, j, l) { var m = l !== undefined; return (j == "role" ? (m ? f.call(this, k, j, "wairole:" + l) : (f.apply(this, arguments) || "").replace(b, "")) : (a.test(j) ? (m ? k.setAttributeNS(h, j.replace(a, "aaa:"), l) : f.call(this, k, j.replace(a, "aaa:"))) : f.apply(this, arguments))); }; c.fn.removeAttr = function (j) { return (a.test(j) ? this.each(function () { this.removeAttributeNS(h, j.replace(a, "")); }) : e.call(this, j)); }; } c.fn.extend({ remove: function () { c("*", this).add(this).each(function () { c(this).triggerHandler("remove"); }); return i.apply(this, arguments); }, enableSelection: function () { return this.attr("unselectable", "off").css("MozUserSelect", "").unbind("selectstart.ui"); }, disableSelection: function () { return this.attr("unselectable", "on").css("MozUserSelect", "none").bind("selectstart.ui", function () { return false; }); }, scrollParent: function () { var j; if ((c.browser.msie && (/(static|relative)/).test(this.css("position"))) || (/absolute/).test(this.css("position"))) { j = this.parents().filter(function () { return (/(relative|absolute|fixed)/).test(c.curCSS(this, "position", 1)) && (/(auto|scroll)/).test(c.curCSS(this, "overflow", 1) + c.curCSS(this, "overflow-y", 1) + c.curCSS(this, "overflow-x", 1)); }).eq(0); } else { j = this.parents().filter(function () { return (/(auto|scroll)/).test(c.curCSS(this, "overflow", 1) + c.curCSS(this, "overflow-y", 1) + c.curCSS(this, "overflow-x", 1)); }).eq(0); } return (/fixed/).test(this.css("position")) || !j.length ? c(document) : j; } }); c.extend(c.expr[":"], { data: function (l, k, j) { return !!c.data(l, j[3]); }, focusable: function (k) { var l = k.nodeName.toLowerCase(), j = c.attr(k, "tabindex"); return (/input|select|textarea|button|object/.test(l) ? !k.disabled : "a" == l || "area" == l ? k.href || !isNaN(j) : !isNaN(j)) && !c(k)["area" == l ? "parents" : "closest"](":hidden").length; }, tabbable: function (k) { var j = c.attr(k, "tabindex"); return (isNaN(j) || j >= 0) && c(k).is(":focusable"); } }); function g(m, n, o, l) { function k(q) { var p = c[m][n][q] || []; return (typeof p == "string" ? p.split(/,?\s+/) : p); } var j = k("getter"); if (l.length == 1 && typeof l[0] == "string") { j = j.concat(k("getterSetter")); } return (c.inArray(o, j) != -1); } c.widget = function (k, j) { var l = k.split(".")[0]; k = k.split(".")[1]; c.fn[k] = function (p) { var n = (typeof p == "string"), o = Array.prototype.slice.call(arguments, 1); if (n && p.substring(0, 1) == "_") { return this; } if (n && g(l, k, p, o)) { var m = c.data(this[0], k); return (m ? m[p].apply(m, o) : undefined); } return this.each(function () { var q = c.data(this, k); (!q && !n && c.data(this, k, new c[l][k](this, p))._init()); (q && n && c.isFunction(q[p]) && q[p].apply(q, o)); }); }; c[l] = c[l] || {}; c[l][k] = function (o, n) { var m = this; this.namespace = l; this.widgetName = k; this.widgetEventPrefix = c[l][k].eventPrefix || k; this.widgetBaseClass = l + "-" + k; this.options = c.extend({}, c.widget.defaults, c[l][k].defaults, c.metadata && c.metadata.get(o)[k], n); this.element = c(o).bind("setData." + k, function (q, p, r) { if (q.target == o) { return m._setData(p, r); } }).bind("getData." + k, function (q, p) { if (q.target == o) { return m._getData(p); } }).bind("remove", function () { return m.destroy(); }); }; c[l][k].prototype = c.extend({}, c.widget.prototype, j); c[l][k].getterSetter = "option"; }; c.widget.prototype = { _init: function () { }, destroy: function () { this.element.removeData(this.widgetName).removeClass(this.widgetBaseClass + "-disabled " + this.namespace + "-state-disabled").removeAttr("aria-disabled"); }, option: function (l, m) { var k = l, j = this; if (typeof l == "string") { if (m === undefined) { return this._getData(l); } k = {}; k[l] = m; } c.each(k, function (n, o) { j._setData(n, o); }); }, _getData: function (j) { return this.options[j]; }, _setData: function (j, k) { this.options[j] = k; if (j == "disabled") { this.element[k ? "addClass" : "removeClass"](this.widgetBaseClass + "-disabled " + this.namespace + "-state-disabled").attr("aria-disabled", k); } }, enable: function () { this._setData("disabled", false); }, disable: function () { this._setData("disabled", true); }, _trigger: function (l, m, n) { var p = this.options[l], j = (l == this.widgetEventPrefix ? l : this.widgetEventPrefix + l); m = c.Event(m); m.type = j; if (m.originalEvent) { for (var k = c.event.props.length, o; k; ) { o = c.event.props[--k]; m[o] = m.originalEvent[o]; } } this.element.trigger(m, n); return !(c.isFunction(p) && p.call(this.element[0], m, n) === false || m.isDefaultPrevented()); } }; c.widget.defaults = { disabled: false }; c.ui.mouse = { _mouseInit: function () { var j = this; this.element.bind("mousedown." + this.widgetName, function (k) { return j._mouseDown(k); }).bind("click." + this.widgetName, function (k) { if (j._preventClickEvent) { j._preventClickEvent = false; k.stopImmediatePropagation(); return false; } }); if (c.browser.msie) { this._mouseUnselectable = this.element.attr("unselectable"); this.element.attr("unselectable", "on"); } this.started = false; }, _mouseDestroy: function () { this.element.unbind("." + this.widgetName); (c.browser.msie && this.element.attr("unselectable", this._mouseUnselectable)); }, _mouseDown: function (l) { l.originalEvent = l.originalEvent || {}; if (l.originalEvent.mouseHandled) { return; } (this._mouseStarted && this._mouseUp(l)); this._mouseDownEvent = l; var k = this, m = (l.which == 1), j = (typeof this.options.cancel == "string" ? c(l.target).parents().add(l.target).filter(this.options.cancel).length : false); if (!m || j || !this._mouseCapture(l)) { return true; } this.mouseDelayMet = !this.options.delay; if (!this.mouseDelayMet) { this._mouseDelayTimer = setTimeout(function () { k.mouseDelayMet = true; }, this.options.delay); } if (this._mouseDistanceMet(l) && this._mouseDelayMet(l)) { this._mouseStarted = (this._mouseStart(l) !== false); if (!this._mouseStarted) { l.preventDefault(); return true; } } this._mouseMoveDelegate = function (n) { return k._mouseMove(n); }; this._mouseUpDelegate = function (n) { return k._mouseUp(n); }; c(document).bind("mousemove." + this.widgetName, this._mouseMoveDelegate).bind("mouseup." + this.widgetName, this._mouseUpDelegate); (c.browser.safari || l.preventDefault()); l.originalEvent.mouseHandled = true; return true; }, _mouseMove: function (j) { if (c.browser.msie && !j.button) { return this._mouseUp(j); } if (this._mouseStarted) { this._mouseDrag(j); return j.preventDefault(); } if (this._mouseDistanceMet(j) && this._mouseDelayMet(j)) { this._mouseStarted = (this._mouseStart(this._mouseDownEvent, j) !== false); (this._mouseStarted ? this._mouseDrag(j) : this._mouseUp(j)); } return !this._mouseStarted; }, _mouseUp: function (j) { c(document).unbind("mousemove." + this.widgetName, this._mouseMoveDelegate).unbind("mouseup." + this.widgetName, this._mouseUpDelegate); if (this._mouseStarted) { this._mouseStarted = false; this._preventClickEvent = (j.target == this._mouseDownEvent.target); this._mouseStop(j); } return false; }, _mouseDistanceMet: function (j) { return (Math.max(Math.abs(this._mouseDownEvent.pageX - j.pageX), Math.abs(this._mouseDownEvent.pageY - j.pageY)) >= this.options.distance); }, _mouseDelayMet: function (j) { return this.mouseDelayMet; }, _mouseStart: function (j) { }, _mouseDrag: function (j) { }, _mouseStop: function (j) { }, _mouseCapture: function (j) { return true; } }; c.ui.mouse.defaults = { cancel: null, distance: 1, delay: 0 }; })(jQuery); (function (a) { a.widget("ui.slider", a.extend({}, a.ui.mouse, { _init: function () { var b = this, c = this.options; this._keySliding = false; this._handleIndex = null; this._detectOrientation(); this._mouseInit(); this.element.addClass("ui-slider ui-slider-" + this.orientation + " ui-widget ui-widget-content ui-corner-all"); this.range = a([]); if (c.range) { if (c.range === true) { this.range = a("<div></div>"); if (!c.values) { c.values = [this._valueMin(), this._valueMin()]; } if (c.values.length && c.values.length != 2) { c.values = [c.values[0], c.values[0]]; } } else { this.range = a("<div></div>"); } this.range.appendTo(this.element).addClass("ui-slider-range"); if (c.range == "min" || c.range == "max") { this.range.addClass("ui-slider-range-" + c.range); } this.range.addClass("ui-widget-header"); } if (a(".ui-slider-handle", this.element).length == 0) { a('<a href="#"></a>').appendTo(this.element).addClass("ui-slider-handle"); } if (c.values && c.values.length) { while (a(".ui-slider-handle", this.element).length < c.values.length) { a('<a href="#"></a>').appendTo(this.element).addClass("ui-slider-handle"); } } this.handles = a(".ui-slider-handle", this.element).addClass("ui-state-default ui-corner-all"); this.handle = this.handles.eq(0); this.handles.add(this.range).filter("a").click(function (d) { d.preventDefault(); }).hover(function () { a(this).addClass("ui-state-hover"); }, function () { a(this).removeClass("ui-state-hover"); }).focus(function () { a(".ui-slider .ui-state-focus").removeClass("ui-state-focus"); a(this).addClass("ui-state-focus"); }).blur(function () { a(this).removeClass("ui-state-focus"); }); this.handles.each(function (d) { a(this).data("index.ui-slider-handle", d); }); this.handles.keydown(function (i) { var f = true; var e = a(this).data("index.ui-slider-handle"); if (b.options.disabled) { return; } switch (i.keyCode) { case a.ui.keyCode.HOME: case a.ui.keyCode.END: case a.ui.keyCode.UP: case a.ui.keyCode.RIGHT: case a.ui.keyCode.DOWN: case a.ui.keyCode.LEFT: f = false; if (!b._keySliding) { b._keySliding = true; a(this).addClass("ui-state-active"); b._start(i, e); } break; } var g, d, h = b._step(); if (b.options.values && b.options.values.length) { g = d = b.values(e); } else { g = d = b.value(); } switch (i.keyCode) { case a.ui.keyCode.HOME: d = b._valueMin(); break; case a.ui.keyCode.END: d = b._valueMax(); break; case a.ui.keyCode.UP: case a.ui.keyCode.RIGHT: if (g == b._valueMax()) { return; } d = g + h; break; case a.ui.keyCode.DOWN: case a.ui.keyCode.LEFT: if (g == b._valueMin()) { return; } d = g - h; break; } b._slide(i, e, d); return f; }).keyup(function (e) { var d = a(this).data("index.ui-slider-handle"); if (b._keySliding) { b._stop(e, d); b._change(e, d); b._keySliding = false; a(this).removeClass("ui-state-active"); } }); this._refreshValue(); }, destroy: function () { this.handles.remove(); this.range.remove(); this.element.removeClass("ui-slider ui-slider-horizontal ui-slider-vertical ui-slider-disabled ui-widget ui-widget-content ui-corner-all").removeData("slider").unbind(".slider"); this._mouseDestroy(); }, _mouseCapture: function (d) { var e = this.options; if (e.disabled) { return false; } this.elementSize = { width: this.element.outerWidth(), height: this.element.outerHeight() }; this.elementOffset = this.element.offset(); var h = { x: d.pageX, y: d.pageY }; var j = this._normValueFromMouse(h); var c = this._valueMax() - this._valueMin() + 1, f; var k = this, i; this.handles.each(function (l) { var m = Math.abs(j - k.values(l)); if (c > m) { c = m; f = a(this); i = l; } }); if (e.range == true && this.values(1) == e.min) { f = a(this.handles[++i]); } this._start(d, i); k._handleIndex = i; f.addClass("ui-state-active").focus(); var g = f.offset(); var b = !a(d.target).parents().andSelf().is(".ui-slider-handle"); this._clickOffset = b ? { left: 0, top: 0} : { left: d.pageX - g.left - (f.width() / 2), top: d.pageY - g.top - (f.height() / 2) - (parseInt(f.css("borderTopWidth"), 10) || 0) - (parseInt(f.css("borderBottomWidth"), 10) || 0) + (parseInt(f.css("marginTop"), 10) || 0) }; j = this._normValueFromMouse(h); this._slide(d, i, j); return true; }, _mouseStart: function (b) { return true; }, _mouseDrag: function (d) { var b = { x: d.pageX, y: d.pageY }; var c = this._normValueFromMouse(b); this._slide(d, this._handleIndex, c); return false; }, _mouseStop: function (b) { this.handles.removeClass("ui-state-active"); this._stop(b, this._handleIndex); this._change(b, this._handleIndex); this._handleIndex = null; this._clickOffset = null; return false; }, _detectOrientation: function () { this.orientation = this.options.orientation == "vertical" ? "vertical" : "horizontal"; }, _normValueFromMouse: function (d) { var c, h; if ("horizontal" == this.orientation) { c = this.elementSize.width; h = d.x - this.elementOffset.left - (this._clickOffset ? this._clickOffset.left : 0); } else { c = this.elementSize.height; h = d.y - this.elementOffset.top - (this._clickOffset ? this._clickOffset.top : 0); } var f = (h / c); if (f > 1) { f = 1; } if (f < 0) { f = 0; } if ("vertical" == this.orientation) { f = 1 - f; } var e = this._valueMax() - this._valueMin(), i = f * e, b = i % this.options.step, g = this._valueMin() + i - b; if (b > (this.options.step / 2)) { g += this.options.step; } return parseFloat(g.toFixed(5)); }, _start: function (d, c) { var b = { handle: this.handles[c], value: this.value() }; if (this.options.values && this.options.values.length) { b.value = this.values(c); b.values = this.values(); } this._trigger("start", d, b); }, _slide: function (f, e, d) { var g = this.handles[e]; if (this.options.values && this.options.values.length) { var b = this.values(e ? 0 : 1); if ((e == 0 && d >= b) || (e == 1 && d <= b)) { d = b; } if (d != this.values(e)) { var c = this.values(); c[e] = d; var h = this._trigger("slide", f, { handle: this.handles[e], value: d, values: c }); var b = this.values(e ? 0 : 1); if (h !== false) { this.values(e, d, (f.type == "mousedown" && this.options.animate), true); } } } else { if (d != this.value()) { var h = this._trigger("slide", f, { handle: this.handles[e], value: d }); if (h !== false) { this._setData("value", d, (f.type == "mousedown" && this.options.animate)); } } } }, _stop: function (d, c) { var b = { handle: this.handles[c], value: this.value() }; if (this.options.values && this.options.values.length) { b.value = this.values(c); b.values = this.values(); } this._trigger("stop", d, b); }, _change: function (d, c) { var b = { handle: this.handles[c], value: this.value() }; if (this.options.values && this.options.values.length) { b.value = this.values(c); b.values = this.values(); } this._trigger("change", d, b); }, value: function (b) { if (arguments.length) { this._setData("value", b); this._change(null, 0); } return this._value(); }, values: function (b, e, c, d) { if (arguments.length > 1) { this.options.values[b] = e; this._refreshValue(c); if (!d) { this._change(null, b); } } if (arguments.length) { if (this.options.values && this.options.values.length) { return this._values(b); } else { return this.value(); } } else { return this._values(); } }, _setData: function (b, d, c) { a.widget.prototype._setData.apply(this, arguments); switch (b) { case "orientation": this._detectOrientation(); this.element.removeClass("ui-slider-horizontal ui-slider-vertical").addClass("ui-slider-" + this.orientation); this._refreshValue(c); break; case "value": this._refreshValue(c); break; } }, _step: function () { var b = this.options.step; return b; }, _value: function () { var b = this.options.value; if (b < this._valueMin()) { b = this._valueMin(); } if (b > this._valueMax()) { b = this._valueMax(); } return b; }, _values: function (b) { if (arguments.length) { var c = this.options.values[b]; if (c < this._valueMin()) { c = this._valueMin(); } if (c > this._valueMax()) { c = this._valueMax(); } return c; } else { return this.options.values; } }, _valueMin: function () { var b = this.options.min; return b; }, _valueMax: function () { var b = this.options.max; return b; }, _refreshValue: function (c) { var f = this.options.range, d = this.options, l = this; if (this.options.values && this.options.values.length) { var i, h; this.handles.each(function (p, n) { var o = (l.values(p) - l._valueMin()) / (l._valueMax() - l._valueMin()) * 100; var m = {}; m[l.orientation == "horizontal" ? "left" : "bottom"] = o + "%"; a(this).stop(1, 1)[c ? "animate" : "css"](m, d.animate); if (l.options.range === true) { if (l.orientation == "horizontal") { (p == 0) && l.range.stop(1, 1)[c ? "animate" : "css"]({ left: o + "%" }, d.animate); (p == 1) && l.range[c ? "animate" : "css"]({ width: (o - lastValPercent) + "%" }, { queue: false, duration: d.animate }); } else { (p == 0) && l.range.stop(1, 1)[c ? "animate" : "css"]({ bottom: (o) + "%" }, d.animate); (p == 1) && l.range[c ? "animate" : "css"]({ height: (o - lastValPercent) + "%" }, { queue: false, duration: d.animate }); } } lastValPercent = o; }); } else { var j = this.value(), g = this._valueMin(), k = this._valueMax(), e = k != g ? (j - g) / (k - g) * 100 : 0; var b = {}; b[l.orientation == "horizontal" ? "left" : "bottom"] = e + "%"; this.handle.stop(1, 1)[c ? "animate" : "css"](b, d.animate); (f == "min") && (this.orientation == "horizontal") && this.range.stop(1, 1)[c ? "animate" : "css"]({ width: e + "%" }, d.animate); (f == "max") && (this.orientation == "horizontal") && this.range[c ? "animate" : "css"]({ width: (100 - e) + "%" }, { queue: false, duration: d.animate }); (f == "min") && (this.orientation == "vertical") && this.range.stop(1, 1)[c ? "animate" : "css"]({ height: e + "%" }, d.animate); (f == "max") && (this.orientation == "vertical") && this.range[c ? "animate" : "css"]({ height: (100 - e) + "%" }, { queue: false, duration: d.animate }); } } })); a.extend(a.ui.slider, { getter: "value values", version: "1.7.1", eventPrefix: "slide", defaults: { animate: false, delay: 0, distance: 0, max: 100, min: 0, orientation: "horizontal", range: false, step: 1, value: 0, values: null} }); })(jQuery);
