//global variables var continueButtonePressed=false; var focusField; var initialLoad = true; var focusOnFirstIncomplete = false; function bindInputListeners(){ $("input:text:visible").bind("focus", function(){ focusField = "#" + this.id; }); $("select:visible").bind("focus change", function(){ executeSelectChangeEvent(this.id); }); $("input:radio:visible").bind("focus click", function(){ if(isGstRadio(this) && this.value == "N"){ //gst radio needs to be handled as an special scenario radioName = "sections.map[aboutYourCar].businessUse"; executeRadioFocusEvent(radioName); } else{ radioName = this.name; executeRadioFocusEvent(radioName); } }); $("input:checkbox:visible").bind("focus click", function(){ checkboxName = this.name; executeCheckboxFocusEvent(checkboxName, this.value); }); } function isGstRadio(radio){ if(radio.name == "sections.map[aboutYourCar].registeredForGst"){ return true; } else{ return false; } } //Function will determine the checkbox just focused or checked and assign to the focusField variable function executeCheckboxFocusEvent(name, selectedValue){ checkboxName = name; checkboxName = checkboxName.replace(/\[/g,"\\["); checkboxName = checkboxName.replace(/\]/g,"\\]"); checkboxName = checkboxName.replace(/\./g,"\\."); checkboxGroup = $("input[name=" + checkboxName + "]"); found = false; for(i=0; (i (sections.length-1)) { s_number = sections.length-1; } return sections[s_number].name; } function getCurrentSectionName() { var currentSectionObject=document.getElementById("currentSection"); if (currentSectionObject) return document.getElementById("currentSection").value; else return null; } function setCurrentSectionName(currentSectionName) { document.getElementById("currentSection").value = currentSectionName; } function showInitialSection() { setCurrentSectionName(initSection); retrieveSection(initSection, "expanded"); } function changeSection(s_next) { continueButtonePressed=true; var s_current = getCurrentSectionName(); fetchResultsAndShowNext(s_current,s_next,changeSectionUrl,false,null); pageHistoryRefresh(historyPointer); } function continueSection() { var s_current = getCurrentSectionName(); continueButtonePressed=true; $('.bt-wrapper').remove(); /* Remove BeatyTip */ fetchResultsAndShowNext(s_current,"",continueSectionUrl,true,null); pageHistoryRefresh(historyPointer); return true; } function fetchResultsAndShowNext(s_current,s_next,url,s_validating,s_callBack) { fetchResultsAndShowNextInner(s_current,s_next,url,s_validating,s_callBack, "form1"); } function fetchResultsAndShowNextInner(s_current,s_next,url,s_validating,s_callBack, formName) { var callBackData = { s_current: s_current, s_validating: s_validating, s_callBack: s_callBack }; if (formName == "form1") { $("#form1 #fetchSection").val(s_current); $("#form1 #nextSection").val(s_next); } else { $("#"+formName+"fetchSection").val(s_current); $("#"+formName+"nextSection").val(s_next); } var options = { cache: false, data: $("#"+formName).serialize(), dataType: "text", success: checkValidationResultsAndShowNext, type: "POST", url: url, callBackData: callBackData }; $.ajax(options); } function checkValidationResultsAndShowNext(o) { var rawText = o; var redirecting = redirectIfRequired(rawText); var s_current = this.callBackData.s_current; var s_validating = this.callBackData.s_validating; var s_callBack = this.callBackData.s_callBack; var endLabel = "[fetchSection]"; var start = 0; var end = rawText.indexOf(endLabel); var dataPart = rawText.substring(start,end); var oResult = eval("(" + dataPart + ")"); var s_next = oResult.nextSection; var HTMLPart = rawText.substring(end+endLabel.length); if (redirecting) { HTMLPart = ""; } var fetchPart = ""; var nextPart = ""; var currentSection; var nextSection; if (oResult.passed == "true") { start = 0; endLabel = "[nextSection]"; end = HTMLPart.indexOf(endLabel); fetchPart = HTMLPart.substring(start,end); nextPart = HTMLPart.substring(end+endLabel.length); //currentSection = findSectionIndex(s_current); replaceSection(s_current,"collapsed",fetchPart); nextSection = findSection(s_next); replaceSection(s_next,"expanded",nextPart); setCurrentSectionName(s_next); saveHistory(s_next); bindInputListeners(); focusField = $("#" + s_next + "-expanded :input:enabled:visible:first"); loadSectionScript(s_next, s_current); //transitionAnimation(s_current, s_next); if (s_validating) { switchToOtherHeading(s_current); if (s_callBack != null) { s_callBack(o,true); } } } else { fetchPart = HTMLPart; setCurrentSectionName(s_current); saveHistory(s_current); currentSection = findSection(s_current); replaceSection(s_current,"expanded",fetchPart); bindInputListeners(); loadSectionScript(s_current); } setupHelp(); } function redirectIfRequired(rawText) { if (rawText != null && rawText != "" && rawText.indexOf("redirectPageURL") != -1) { var oResult = eval("(" + rawText + ")"); var url = oResult.redirectPageURL; var ss = $("#ss").val(); if (ss != null && ss != "") { url = url + "?ss=" + ss; } location.replace(url); return true; } else { return false; } } function midQuoteSave(s_current) { continueButtonePressed=true; $('.bt-wrapper').remove(); /* Remove BeatyTip */ fetchMidQuoteSaveResults(s_current,"",midQuoteSaveUrl,"form1"); /* pageHistoryRefresh(historyPointer); alert("mid quote save - " + s_current); */ return true; } function fetchMidQuoteSaveResults(s_current,s_next,url,formName) { var callBackData = { s_current: s_current }; if (formName == "form1") { $("#form1 #fetchSection").val(s_current); $("#form1 #nextSection").val(s_next); } else { $("#"+formName+"fetchSection").val(s_current); $("#"+formName+"nextSection").val(s_next); } var options = { cache: false, data: $("#"+formName).serialize(), dataType: "text", success: checkMidQuoteSaveResults, type: "POST", url: url, callBackData: callBackData }; $.ajax(options); } function checkMidQuoteSaveResults(o) { var rawText = o; ///alert(rawText); var redirecting = redirectIfRequired(rawText); var s_current = this.callBackData.s_current; var endLabel = "[fetchSection]"; var start = 0; var end = rawText.indexOf(endLabel); // no need to re-display section, as midquote summary page is displayed. if(end == -1) return; var dataPart = rawText.substring(start,end); var oResult = eval("(" + dataPart + ")"); var HTMLPart = rawText.substring(end+endLabel.length); if (redirecting) { HTMLPart = ""; } var fetchPart = ""; var currentSection; if (oResult.passed == "false") { fetchPart = HTMLPart; setCurrentSectionName(s_current); saveHistory(s_current); currentSection = findSection(s_current); replaceSection(s_current,"expanded",fetchPart); bindInputListeners(); loadSectionScript(s_current); } setupHelp(); } /** * Handles the section transition animation. */ function transitionAnimation(currentSection, nextSection) { // Show the change button on the next section. Hide the change button on the current section. showChangeButton(currentSection); hideChangeButton(nextSection); // Unslidable cause slideDown to look TERRIBLE. $('.unslidable').hide(); // Grab the DOM elements for the Section' H2 element. var lastSectionH2 = $('#' + currentSection + '-collapsed').prev('.stepHeading'); var nextSectionH2 = $('#' + nextSection + '-collapsed').prev('.stepHeading'); // Transitioning forwards of backwards? if(nextSectionH2.position().top > lastSectionH2.position().top){ $('#' + currentSection + '-collapsed').show(); $('#' + nextSection + '-collapsed').hide(); $('#' + currentSection + '-expanded').slideUp(1000, 'easeOutCubic'); $('#' + nextSection + '-expanded').slideDown(1000, function() { // Show previously hidden unslidables. $('.unslidable').show(); setTimeout(function () { setFocus();}, 1200); }, 'easeOutCubic'); $.scrollTo(lastSectionH2,'easeOutCubic'); } else { $('#' + currentSection + '-collapsed').show(); $('#' + nextSection + '-collapsed').hide(); $('#' + currentSection + '-expanded').hide(); $('#' + nextSection + '-expanded').show(1, function(){ setFocus(); }); // Show previously hidden unslidables. $('.unslidable').show(); } } function retrieveSection(s_name,s_state) { fetchSection(s_name,s_state,fetchSectionUrl,""); } function fetchSection(s_name,s_state,url,additionalParms) { fetchSectionWithLoadingIcon(s_name,s_state,url,additionalParms,false); } function fetchSectionWithLoadingIcon(s_name,s_state,url,additionalParms,global) { fetchSectionWithCallback(s_name,s_state,url,additionalParms,global,null); } function fetchSectionWithCallback(s_name,s_state,url,additionalParms,global,callBack) { var callBackData = { s_name: s_name, s_state: s_state, customCallBack: callBack }; $("#form1 #fetchSection").val(s_name); $("#form1 #sectionState").val(s_state); var parms = $("#form1").serialize(); var options = { cache: false, data: parms, dataType: "text", global: global, success: showRetrievedSection, type: "POST", url: url, callBackData: callBackData }; $.ajax(options); } function showRetrievedSection(o) { var rawText = o; if (redirectIfRequired(rawText)) { rawText = ""; } var s_name = this.callBackData.s_name; var s_state = this.callBackData.s_state; var section = findSection(s_name); replaceSection(s_name,s_state, rawText); bindInputListeners(); if(initialLoad){ initialLoad = false; if(focusOnFirstIncomplete){ focusOnFirstIncomplete = false; focusField = findFirstIncompleteField(s_name); //if nothing incomplete, set focus to first field if(focusField == null){ focusField = $("#" + s_name + "-expanded :input:enabled:visible:first"); } } else{ focusField = $("#" + s_name + "-expanded :input:enabled:visible:first"); } } if (s_state == "expanded") { loadSectionScript(s_name); expandSection(s_name); } if (this.callBackData.customCallBack != null) { this.callBackData.customCallBack(o); } setupHelp(); } function findFirstIncompleteField(s_name){ elementsInSection = $("#" + s_name + "-expanded :input:enabled:visible"); firstIncompleteFound = false; firstIncompleteField = null; for(i=0; (!firstIncompleteFound && i
') .prepend('
') .append('
'); //This prevents native controls (selects etc) poking through the help bubble in IE6. helpDiv.bgiframe(); //Set the height of the div.m container if(requiredHeight > 0 && requiredHeight < 300) { helpDiv.find("div.m").height(requiredHeight + 'px'); } // Help Text = Cached helpText[helpId] = true; } /** * Inverts the supplied help container if the help containers parent (the anchor) is more * than 50% down the current window. (Things nearer the bottom pop "up", things nearer the * top pop "down"). */ function help_invertIfRequired(helpContainer) { //Up or down based on screen position? var el = helpContainer.parent(); if(el.position() != ''){ var yPc = (el.offset().top - $(window).scrollTop()) / $(window).height(); if(yPc > .5) { // Invert! 20 = padding on div.m, 17 = offset of (b/arrow). var top = (helpContainer.find('div.m').height() + 20 + 17); helpContainer.css('top', '-' + top + 'px'); helpContainer.find("b").css('top', top + 'px'); } else { var top = (17); helpContainer.css('top', '-' + top + 'px'); helpContainer.find("b").css('top', top + 'px'); } } } function showOnlySection(s_name) { var old = document.getElementById("currentSection").value; document.getElementById("currentSection").value = s_name; retrieveSection(s_name, "expanded"); if (s_name != old) { retrieveSection(old, "collapsed"); } } function replaceSection(s_name,s_state,replaceText) { var sectionElement = $('#' + s_name + '-' + s_state); sectionElement.html(replaceText); } function showSection (s_name,s_state) { $('#' + s_name + '-' + s_state).show(); } function hideSection (s_name,s_state) { $('#' + s_name + '-' + s_state).hide(); } function expandSection (s_name) { hideSection(s_name, "collapsed"); showSection(s_name, "expanded"); } function collapseSection (s_name) { hideSection(s_name, "expanded"); showSection(s_name, "collapsed"); } function switchToOtherHeading(s_name) { $('#' + s_name + "-other-heading").show(); $('#' + s_name + "-heading").hide(); } function showChangeButton (s_name) { $('#' + s_name + "-heading-change").show(); $('#' + s_name + "-heading-change").removeClass('hide'); } function hideChangeButton (s_name) { $('#' + s_name + "-heading-change").hide(); $('#' + s_name + "-heading-change").addClass('hide'); } /** * EMAIL: Wires up the email popup div (#emailModelPopup). The content will be fetched via ajax * from the supplied URL. */ function initialiseEmailPopup(url) { clearEmailAddress = false; $("#emailModalPopup").jqm({modal: true, overlay:70, ajax: url, toTop:true, trigger: ".emailModalTrigger", onLoad: function() { var rawText = $("#emailModalPopup").html(); if (redirectIfRequired(rawText)) { $("#emailModalPopup").html(""); } $(this).wrapInner('
') .prepend('
') .append('
'); if (clearEmailAddress) { $("#quoteEmailData-emailRecipient").val(""); } clearEmailAddress = false; } }); return null; }; /** * EMAIL: Submits the email dialog. Given the form to submit and the URL to submit on. */ function submitEmailPopup(form, url) { var resultDiv = $('#emailModalPopup'); var options = { cache: false, type: "POST", success: function(data){ if (redirectIfRequired(data)) { resultDiv.html(""); } else { resultDiv.html(data); } resultDiv.wrapInner('
') .prepend('
') .append('
'); }, url: url, global:false, dataType: "text", data: $(form).serialize() } $.ajax(options); }; /** * EMAIL: Closes the email popup. */ function closeEmailPopup() { $("#emailModalPopup").jqmHide(); } /** */ function initialiseEmbargoPopUp(url) { $("#embargoModalPopup").jqm({modal: true, overlay:70, ajax: url, trigger: ".embargoModalTrigger", onLoad: function() { var rawText = $("#embargoModalPopup").html(); if (redirectIfRequired(rawText)) { $("#embargoModalPopup").html(""); } $(this).wrapInner('
') .prepend('
') .append('
'); } }); return null; }; /** *Clear finance company in about your policy collapsed section */ function clearFinanceCompany() { var identifyYourCarCollapsed= $("#identifyYourCar-collapsed"); if (identifyYourCarCollapsed!=null && identifyYourCarCollapsed.html()!=null) { var htmlCode=identifyYourCarCollapsed.html(); //Important: This calculation is totaly depending on if "Finance company" characters are found in about your policy collapsed section var start=htmlCode.indexOf("Finance company"); var firstPart=htmlCode.substring(0,start); var lastPart=htmlCode.substring(start); var lastPart=lastPart.substring(lastPart.indexOf("|")+1); identifyYourCarCollapsed.html(firstPart+lastPart); } } /** Save page view history. This method should be called once a new section is open **/ function saveHistory(sectionName) { historys[historyPointer]=sectionName; historyPointer++; } /** Refresh page history plugin. This method will append # to the URL **/ function pageHistoryRefresh(historyHash) { $.history.load(historyHash); } var isInitPage=true; //Check it if it is the first time the application is presented to the user var historys=new Array(); //Page visit history storage var historyPointer=0; //history pointer /** back-forward button action method. **/ function pageload(hash) { var currentSectionName=getCurrentSectionName(); if (!isHistoryAllowed()) { return; } if (isInitPage) { //init page isInitPage=false; //The initial page URL does not have a history record number //Append history number to the URL pageHistoryRefresh(historyPointer); saveHistory(currentSectionName); return; } if (continueButtonePressed) { //continue or change button is pressed continueButtonePressed=false; return; } else { //Either back or forward button is pressed //Get the history to open var historynumber=hash; if (!historys[historynumber]) { //User is moving out of the history control, stop them return; } //alert("You are about go from\n"+currentSectionName+"\nto\n"+historys[historynumber]); if (currentSectionName!=historys[historynumber]) { fetchResultsAndShowNextInner(currentSectionName,historys[historynumber],backForwardButtonUrl,true,null, "backForwardButtonForm"); saveHistory(currentSectionName); } setCurrentSectionName(historys[historynumber]); } } /** Initialise pageload method, make the method (pageload) be called everytime when URL is changed in the browser **/ $(document).ready(function(){ // Initialize history plugin. // The callback is called at once by present location.hash. $.history.init(pageload); }); var noHistoryPageList=new Array ("printSummary.html"); function isHistoryAllowed() { var url=getURL(); for (var i=0;i-1) return false; } return true; } function getURL() { var url = window.location.href; return url; } function getURLWithSSNoAnchors() { var url = window.location.href; var pos = url.indexOf('#'); if (pos != -1) { url = url.substring(0,pos); } var pos = url.indexOf('?'); if (pos != -1) { url = url.substring(0,pos); } url = url + "&SS="; var ss = $("#ss").val(); if (ss!=null) { url = url + ss; } return url; } function setupHelp(){ $('a.help-def').each(function() { var currentHelpId = this.id; var spikeDistance = 18; var currentHelpUrl = helperUrl + "?helpId=" + this.id + "&ss=" + $("#ss").val() + "&helpClass=" + this.className; var helpTimeout = 1000; var bubbleWidth = 280; /* 'aboutYourCar-expanded' section */ if ($(this).closest('div').is('#aboutYourCar-expanded')){ var parentTag = $(this).parent().get(0).tagName; if (parentTag == 'LABEL') { var parentHelpItemHeight = $(this).parent().height(); var spikeDistance = parentHelpItemHeight/2 + 3; // so that the bubble does not cover the question if (this.id == 'agreedValueHelp' || this.id == 'marketValueHelp'){ var spikeDistance = 20; } } if (currentHelpId == 'agreedValueHelp') { bubbleWidth=450; } } if (($(this).closest('div').is('#aboutYourCar-expanded')) || currentHelpId == 'excessHelp'){ var viewportWidth = window.innerWidth ? window.innerWidth : $(window).width(); var leftDistance = (((viewportWidth - 990)/2) + 10) + "px"; } $(this).bt({ trigger: 'mouseover focus', width: bubbleWidth, padding: 8, strokeWidth: 1, strokeStyle: '#b8b8b8', cornerRadius: 10, positions: ['top','bottom'], spikeLength: spikeDistance, spikeGirth: 8, centerPointX: .5, centerPointY: .5, fill: "rgb(255,255,255)", windowMargin: 20, ajaxError: ' ', ajaxPath: currentHelpUrl, preShow: function() { if (($(this).closest('div').is('#aboutYourCar-expanded')) || currentHelpId == 'excessHelp'){ $('.bt-wrapper').css('left',leftDistance); } if (currentHelpId == 'agreedValueHelp') { $('.btBubble div.wikiHeaderTop,.btBubble .wikiHelpDetail,.btBubble div.wikiHelpFooter').css('width','440px'); } }, postShow: function() { if (currentHelpId == 'agreedValueHelp') { //$('.btBubble div.wikiHeaderTop,.btBubble .wikiHelpDetail,.btBubble div.wikiHelpFooter').css('width','440px'); } if (($(this).closest('div').is('#aboutYourCar-expanded')) || currentHelpId == 'excessHelp'){ $('.bt-wrapper').css('left',leftDistance); } $('#helpContent table tr').each(function() { $('#helpContent table td:first-child').addClass('firstChild'); // style for table in help }); $('#helpContent').hover( function(){ }, function(){ $('#'+currentHelpId).btOff(); } ); }, ajaxOnComplete: function(data) {return redirectIfRequired(data);}, hoverIntentOpts: { interval: 200, timeout: helpTimeout }, closeWhenOthersOpen: true }); }); $('a.btn-help').each(function() { var currentHelpId = this.id; var currentHelpUrl = helperUrl + "?helpId=" + this.id + "&ss=" + $("#ss").val() + "&helpClass=" + this.className; var helpTimeout = 1000; var bubbleWidth = 500; var leftMarginLimit = 200; $(this).bt({ trigger: 'mouseover focus', width: bubbleWidth, padding: 8, strokeWidth: 1, strokeStyle: '#b8b8b8', cornerRadius: 10, positions: ['top','bottom'], spikeLength: 14, spikeGirth: 8, centerPointX: .5, centerPointY: .5, fill: "rgb(255,255,255)", windowMargin: leftMarginLimit, ajaxError: ' ', ajaxPath: currentHelpUrl, postShow: function() { $('#helpContent table').css('width','460px'); $('#helpContent table tr').each(function() { $('#helpContent table td:first-child').addClass('firstChild'); }); $('#helpContent').hover( function(){ }, function(){ $('#'+currentHelpId).btOff(); } ); if (currentHelpId == 'previousInsurerHelp'){ $('.bt-content, .btBubble .helpInfoContent').css('height','50px'); } }, ajaxOnComplete: function(data) {return redirectIfRequired(data);}, hoverIntentOpts: { interval: 200, timeout: helpTimeout }, closeWhenOthersOpen: true }); }); // When focus chages, hide the current tip. $("a, input, select").focus(function() { $('a.help-def, a.btn-help').btOff(); }); }