/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/
/*
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}
*/




function postcode_lookupShow(displayMode)
{
	var el = document.getElementById('addressDetails');
	if(el) el.style.display = displayMode || 'block';
}

function hideAddressDetails()
{
	var el = document.getElementById('addressDetails');
	if(el) el.style.display = 'none';
}

function toggleAddressDetails()
{
	var el = document.getElementById('addressDetails');
	if(el) {
		if(el.style.display == 'none')
			el.style.display = '';
		else
			el.style.display = 'none';
	}
}

function postcode_lookup2Show(displayMode)
{
	var el = document.getElementById('addressDetails2');
	if(el) el.style.display = displayMode || 'block';
}

function hideAddressDetails2()
{
	var el = document.getElementById('addressDetails2');
	if(el) el.style.display = 'none';
}

function toggleAddressDetails2(elstr)
{
	var el = document.getElementById('addressDetails2');
	if(el) {
		if(el.style.display == 'none')
			el.style.display = '';
		else
			el.style.display = 'none';
	}
}

function initLSQ() 
{
    /** Address lookup by house number and postcode */	
    proxies.LookupByPostcode = {
    url: "/webservices/LookupByPostcode.asmx",
    ns: "http://tempuri.org/"
    } // proxies.LookupByPostcode
    /* inputMessageName='SearchSoapIn', outputMessageName='SearchSoapOut'  */
    /** Returns an array of addresses from a postcode */
    proxies.LookupByPostcode.Search = function () { return(proxies.callSoap(arguments)); }
    proxies.LookupByPostcode.Search.fname = "Search";
    proxies.LookupByPostcode.Search.service = proxies.LookupByPostcode;
    proxies.LookupByPostcode.Search.action = "\"http://tempuri.org/Search\"";
    proxies.LookupByPostcode.Search.params = ["sPostcode"];
    proxies.LookupByPostcode.Search.rtype = ["SearchResult:ds","sMessage"];
    
    /* Address Class */
    var alternate = false;

    function showFields(){
	    var fields = $$('.hide');
	    fields.each(function(field) {
		    field.removeClass("hide");
	    });
	    //showFormLink.style.display = "none";
    }

    // Show form fields button
    var showFormLink = $('postcode_lookupEnterManual');
    if(showFormLink){
	    showFormLink.addEvent('click', function(event) {
		    event = new Event(event).stop();
		    showFields();
	    });    	
    }
    
        // Show form fields button
    var showFormLink = $('postcode_lookup2EnterManual');
    if(showFormLink){
	    showFormLink.addEvent('click', function(event) {
		    event = new Event(event).stop();
		    showFields();
	    });    	
    }

    var Address = new Class({
	    initialize: function(line1,line2,line3,town,county,postcode){
		    this.line1    = line1;
		    this.line2    = line2;
		    this.line3    = line3;
		    this.town     = town;
		    this.county   = county;
		    this.postcode = postcode;
    		
		    var listingTitle = this.line1;
    		
		    if(listingTitle.length > 50){
			    listingTitle = listingTitle.substring(0,50)+"&hellip;";
		    }
    		
		    var listingClass = "";
		    if (alternate == true) {
			    listingClass = "alt";
			    alternate = false;
		    } else {
			    alternate = true;
		    }
    		
		    var listing = new Element('a', {
			    'class': listingClass,
			    'href': '#',
			    'events': {
				    'click': function(e){
					    e = new Event(e).stop();
    					
					    var links = $$('#listingHolder a');
    					
					    links.each(function(link) {
							    link.removeClass("highlighted");
					    });
					    this.addClass("highlighted");									
    					
					    $('address1').value = listing.$tmp.addressData.line1;
					    $('address2').value = listing.$tmp.addressData.line2;  
					    // $('address3').value = listing.$tmp.addressData.line3;  
					    $('town').value     = listing.$tmp.addressData.town;  
					    $('county').value   = listing.$tmp.addressData.county;  
					    $('postcode').value = listing.$tmp.addressData.postcode;
					    $('listingHolder').remove();
    					
						postcode_lookupShow();
				    }
			    }
		    }).setHTML(listingTitle);    		
		    listing.$tmp.addressData = this;   		
		    listing.injectInside($('listingHolder'));

	    }    	
    });

    // IMPORTANT this bit decides if to show the manual form or not
    // If the postcode within the manual form is empty then hide it
    // so postcode search can be used
	var postcodeReset = $('postcode');
	var postcodeReset2 = $('propertyPostcode');
	
	if (postcodeReset != null) {
		if(postcodeReset.value != ""){
			postcode_lookupShow();
		}	
	}
	if (postcodeReset2 != null) {
		if(postcodeReset2.value != ""){
			postcode_lookup2Show();
		}	
	}

	var getAddressButton = $('postcode_lookupID');	
	var postcodeInput = $('postcode_lookup');	
	
	if(getAddressButton != null){	

	getAddressButton.addEvent('click', function(event) {
		event = new Event(event);	
		if($('postcodeError')){ $('postcodeError').remove(); }
			getAddressButton.innerHTML = "<span>Loading</span>";
			addressSubmitted(true);
		});
	}
	
	var getAddressButton2 = $('postcode_lookup2id');	
	var postcodeInput2 = $('postcode_lookup2');

		if(getAddressButton2 != null){	

	getAddressButton2.addEvent('click', function(event) {
		event = new Event(event);
		if($('postcodeError')){ $('postcodeError').remove(); }
			getAddressButton2.innerHTML = "<span>Loading</span>";
			addressSubmitted2(true);
		});
	}
	   		
	function addressSubmitted(success) {
		if(success == true){

			hideAddressDetails();

		    // Call the webservice
		    //alert("calling web service");		    
		    proxies.LookupByPostcode.Search.func = getLookupByPostcodeOnLoad;
            proxies.LookupByPostcode.Search.onException = getLookupByPostcodeOnError;
            //alert(houseNumInput.value);
            //alert(postcodeInput.value);
            var sMessage = "";
            proxies.LookupByPostcode.Search(postcodeInput.value, sMessage);
       }
	}
	
	// returns dataset
	function getLookupByPostcodeOnLoad(returnCode, sMessage) {
		getAddressButton.innerHTML = "<span>Search</span>";
		if($('errorMsg')){$('errorMsg').remove();}
	
		if (returnCode == null){
			
			var searchButtonholder = $('getAddressSubmit');
			var errorMsg = new Element('p',{'id':'errorMsg'}).setText('We were unable to locate your address, please enter it below.').injectInside(searchButtonholder);
            searchButtonholder.focus();
			//showFields();
			
		} else {
			postcodeInput.className = "text";
		    parseXML(returnCode);			
		}	
	    return;   

	}
	
	function getLookupByPostcodeOnError(error)
	{
        return;
	}
	function parseXML(xml){

        // Show the form
		showFields();		
		
		if ($('listingHolder')) {
            // Empty the listing holder 
			$('listingHolder').empty();
		} else {
            // Set up listing holder
			var listingHolder = new Element('div', {
				'id': 'listingHolder'
			}).injectInside($('addressListing'));
		}
	
		var addresses = xml.firstChild.childNodes;
		var listings = [];
		$A(addresses).each(function(address) {
			var line1    = address.childNodes[1].firstChild;
			var line2    = address.childNodes[2].firstChild;
			var line3    = address.childNodes[3].firstChild;
			var town     = address.childNodes[4].firstChild;
			var county   = address.childNodes[5].firstChild;
			var postcode = address.childNodes[6].firstChild;
			
			if(line1    != null){ line1    = line1.data;   } else { line1    = ""; }
			if(line2    != null){ line2    = line2.data;   } else { line2    = ""; }
			if(line3    != null){ line3    = line3.data;   } else { line3    = ""; }
			if(town     != null){ town     = town.data;    } else { town     = ""; }
			if(county   != null){ county   = county.data;  } else { county   = ""; }
			if(postcode != null){ postcode = postcode.data;} else { postcode = ""; }
			
            // Add an address
			var newListing = new Address(line1,line2,line3,town,county,postcode);
			listings.push(newListing);			
		});
		$('listingHolder').focus();
	}	

//DUPLICATED CODE TO HANDLE SECONDARY POSTCODE LOOKUP
//SECONDARY ADDRESS CLASS
    var Address2 = new Class({
	    initialize: function(line1,line2,line3,town,county,postcode){
		    this.line1    = line1;
		    this.line2    = line2;
		    this.line3    = line3;
		    this.town     = town;
		    this.county   = county;
		    this.postcode = postcode;
    		
		    var listingTitle = this.line1;
    		
		    if(listingTitle.length > 50){
			    listingTitle = listingTitle.substring(0,50)+"&hellip;";
		    }
    		
		    var listingClass = "";
		    if (alternate == true) {
			    listingClass = "alt";
			    alternate = false;
		    } else {
			    alternate = true;
		    }
    		
		    var listing = new Element('a', {
			    'class': listingClass,
			    'href': '#',
			    'events': {
				    'click': function(e){
					    e = new Event(e).stop();
    					
					    var links = $$('#listingHolder a');
    					
					    links.each(function(link) {
							    link.removeClass("highlighted");
					    });
					    this.addClass("highlighted");									
    					
					    $('propertyAddress1').value = listing.$tmp.addressData.line1;
					    $('propertyAddress2').value = listing.$tmp.addressData.line2;  
					    // $('propertyAddress3').value = listing.$tmp.addressData.line3;  
					    $('propertyTown').value     = listing.$tmp.addressData.town;  
					    $('propertyCounty').value   = listing.$tmp.addressData.county;  
					    $('propertyPostcode').value = listing.$tmp.addressData.postcode;
					    $('listingHolder').remove();
    					
						postcode_lookup2Show();
				    }
			    }
		    }).setHTML(listingTitle);    		
		    listing.$tmp.addressData = this;   		
		    listing.injectInside($('listingHolder'));

	    }    	
    });



function addressSubmitted2(success) {
		if(success == true){

			hideAddressDetails2();

		    // Call the webservice
		    //alert("calling web service");		    
		    proxies.LookupByPostcode.Search.func = getLookupByPostcodeOnLoad2;
            proxies.LookupByPostcode.Search.onException = getLookupByPostcodeOnError2;
            //alert(houseNumInput.value);
            //alert(postcodeInput.value);
            var sMessage = "";
            proxies.LookupByPostcode.Search(postcodeInput2.value, sMessage);
       }
	}

// returns dataset
	function getLookupByPostcodeOnLoad2(returnCode, sMessage) {
		getAddressButton2.innerHTML = "<span>Search</span>";
		if($('errorMsg')){$('errorMsg').remove();}
	
		if (returnCode == null){
			
			var searchButtonholder = $('getAddressSubmit');
			var errorMsg = new Element('p',{'id':'errorMsg'}).setText('We were unable to locate your address, please enter it below.').injectInside(searchButtonholder);

			//showFields();
			
		} else {
			postcodeInput2.className = "text";
		    parseXML2(returnCode);			
		}	
	    return;   

	}

function getLookupByPostcodeOnError2(error)
	{
        return;
	}
	function parseXML2(xml){

        // Show the form
		showFields();		
		
		if ($('listingHolder')) {
            // Empty the listing holder 
			$('listingHolder').empty();
		} else {
            // Set up listing holder
			var listingHolder = new Element('div', {
				'id': 'listingHolder'
			}).injectInside($('addressListing'));
		}
	
		var addresses = xml.firstChild.childNodes;
		var listings = [];
		$A(addresses).each(function(address2) {
			var line1    = address2.childNodes[1].firstChild;
			var line2    = address2.childNodes[2].firstChild;
			var line3    = address2.childNodes[3].firstChild;
			var town     = address2.childNodes[4].firstChild;
			var county   = address2.childNodes[5].firstChild;
			var postcode = address2.childNodes[6].firstChild;
			
			if(line1    != null){ line1    = line1.data;   } else { line1    = ""; }
			if(line2    != null){ line2    = line2.data;   } else { line2    = ""; }
			if(line3    != null){ line3    = line3.data;   } else { line3    = ""; }
			if(town     != null){ town     = town.data;    } else { town     = ""; }
			if(county   != null){ county   = county.data;  } else { county   = ""; }
			if(postcode != null){ postcode = postcode.data;} else { postcode = ""; }
			
            // Add an address
			var newListing = new Address2(line1,line2,line3,town,county,postcode);
			listings.push(newListing);			
		});
	}	








}

function initLSQQuotation()
{
    /* Quotation web service  */
    proxies.Quotation = {
    url: "/webservices/quotation.asmx",
    ns: "http://tempuri.org/"
    } // proxies.Quotation
    /* inputMessageName='GetQuotesSoapIn', outputMessageName='GetQuotesSoapOut'  */
    proxies.Quotation.GetQuotes = function () { return(proxies.callSoap(arguments)); }
    proxies.Quotation.GetQuotes.fname = "GetQuotes";
    proxies.Quotation.GetQuotes.service = proxies.Quotation;
    proxies.Quotation.GetQuotes.action = "\"http://tempuri.org/GetQuotes\"";
    proxies.Quotation.GetQuotes.params = ["quoteType","authKey","leadId:int"];
    proxies.Quotation.GetQuotes.rtype = ["GetQuotesResult:ds"];
    
	var Document = new Class(
	{
	    initialize: function(name, description, url){
	       this.name = name;
	       this.description = description;
	       this.url = url;
	    }
	    , setDescription : function(description) {
	        this.description = description;
	    }
	    , toLink : function(){
	        var link = "";
	        if (this.url.length > 0)
	        {
	            link = '<a href="' + this.url + '" target="_blank">' + this.description + '</a>';
	        }
	        return link;
	    }
	});	
	var Quote = new Class(
	{
		initialize: function(quoteId, responseRef, errorCode, providerId, providerIdent, providerName
		                    , providerLogo, productId, productName, weblineInfo, notesHtml, documents
		                    , isApplicationAvailable, logonTokenAccepted, success, exceptionMessage
		                    , benefit, premium, rates, netPremium, cictpdDef, loanRate, isTaxEfficient){
			this.quoteId = quoteId;
            this.responseRef = responseRef;
            this.errorCode = errorCode;
            this.providerId = providerId;
            this.providerIdent = providerIdent;
            this.providerName = providerName;
            this.providerLogo = providerLogo;
            this.productId = productId;
            this.productName = productName;
            this.weblineInfo = weblineInfo;
            this.notesHtml = notesHtml;
            this.documents = this.setDocuments(documents);
            this.isApplicationAvailable = isApplicationAvailable;
            this.logonTokenAccepted = logonTokenAccepted;
            this.success = success;
            this.exceptionMessage = exceptionMessage;
            this.benefit = benefit;
            this.premium = premium;
            this.rates = rates;
            this.netPremium = netPremium;
            this.cictpdDef = cictpdDef;
            this.loanRate = loanRate;
            this.isTaxEfficient = isTaxEfficient;
		}
		, getAllDocumentsAsHtml : function() {
		    var links = "";
		    $A(this.documents).each(function(d) {
		        links += document.toLink() + "<br/>";
		    })
		    return links;
		}
		, getQuoteLogoAsHtml : function() {
		    var fullImagePath = "";
		    var imagePath = "/_include/images/quote_logos";
		    if (this.providerLogo.length > 0)
		    {
		        var logo = this.providerLogo;
		        var pos = logo.lastIndexOf("/");
		        var logoPath = logo.substring(pos, logo.length);
		        fullImagePath = '<img src="' + imagePath + logoPath + '" alt="' + this.providerName + ' logo"/>';
		    }
		    return fullImagePath;
		}
		, getProviderAsHtml : function() {
		    var provider = "";
		    provider += this.providerName;
		    //provider += ((this.providerIdent != '' && this.providerIdent != this.providerName) ? ' (' + this.providerIdent + ')' : '');
			return '<div class="provider">' + ((provider.length > 0) ? provider : '&nbsp;') + '</div>';
		}
		, getProductAsHtml : function() {			
			return '<div class="product">' + ((this.productName.length > 0) ? this.productName : '&nbsp;') + '</div>';
		}
		, getKeyFactsDocumentAsHtml : function() {
		    var link = "";
		    if (this.documents.length > 0) {
		        this.documents[0].description = "View policy details";
		        link = this.documents[0].toLink();
		    }
		    return link;
		}
		, getPremiumAsHtml : function() {
		    var prem = "";
			if (this.premium.length > 0)
			{
			    prem = '<div class="price">&pound;' + this.convertToMoney(this.premium) + '</div>';
			    prem += '<div class="conditions">Per month';
			    if (this.rates.length > 0) prem += ' (' + this.rates + ')';
			    prem += '</div>';
			}
			return prem;
		}
		, getButtonAsHtml : function() {
		    //if (this.quoteId.length > 0) return '<a href="#" onclick="alert(' + this.quoteId + ')">Proceed</a>';
		    if (this.quoteId.length > 0) return '<input type="submit" class="submit" name="proceedbutton" value="Proceed" onclick="button=\'proceed\'" />';
		}
		, setDocuments : function(documentsAsString){
		    var documentsAsStringArray = null;
		    var documentsAsClassArray = new Array();
		    if (documentsAsString.indexOf(';') > -1)
		    {
		        documentsAsStringArray = documentsAsString.split(";");
		        if (documentsAsStringArray.length > 0)
		        {
		            // Loop through the documents
		            $A(documentsAsStringArray).each(function(documentFromStringArray) {
		                if (documentFromStringArray.indexOf(',') > -1)
		                {
		                    var documentAsStringArray = documentFromStringArray.split(",");
		                    var documentAsClass;
		                    var index = 0;
		                    var name = "";
		                    var description = "";
		                    var url = "";
		                    // loop through the document properties
		                    $A(documentAsStringArray).each(function(property) {
		                        switch(index)
		                        {
		                            case 0 :
		                                name = property;
		                                break;
		                            case 1 :
		                                description = property;
		                                break;
		                            case 2 :
		                                url = property;
		                                break;
		                            default :
		                                break;
		                        }		                        		                             
		                        index++;
		                    })	                    
	                        // Instantiate the document class then add it to the document class array
	                        if (url.trim() != "" && description.trim() != "")
	                        {
	                            //var documentAsClass = new this.Document(name.clean(), description.clean(), url.clean());
	                            var documentAsClass = new Document(name, description, url);
	                            documentsAsClassArray.push(documentAsClass);
	                        }
		                }
		            })
		        }
		    }
		    return documentsAsClassArray;		    
		}
		, addImageCell : function(){
		    // Cell features
			var features = {
				'class' : 'image'
			};	
			var html = this.getQuoteLogoAsHtml();
			return new Element("td", features).setHTML(html);
		}
		, addProviderCell : function(){
		    // Cell features
			var features = {
				'class' : 'provider'
			};
			var html = this.getProviderAsHtml();
			html += this.getProductAsHtml();
			html += this.getKeyFactsDocumentAsHtml();
			return new Element("td", features).setHTML(html);
		}
		, addPremiumCell : function(){
		    // Cell features
			var features = {
				'class' : 'premium'
			};	
			var html = this.getPremiumAsHtml();
			return new Element("td", features).setHTML(html);
		}
		, addButtonCell : function(){
		    // Cell features
			var features = {
				'class' : 'button'
			};	
			var html = this.getButtonAsHtml();
			return new Element("td", features).setHTML(html);
		}
		, convertToMoney: function(num){
		    var newNum = num.toFloat().round(2);
		    // Check to see two decimal places exist
		    var newNumAsString = newNum.toString()
		    var len = newNumAsString.length;
		    var pos = newNumAsString.lastIndexOf(".");
		    if(pos != -1)
				if ((len - pos) == 2)
					return (newNumAsString + "0");
		    return newNumAsString;
		}
		, toRow: function() {
		    var tr, td;
			tr = new Element("tr");
		    // Add Image Cell
			td = this.addImageCell();
			td.injectInside(tr);
			// Add Provider Cell
			td = this.addProviderCell();
			td.injectInside(tr);
			// Add Premium Cell
			td = this.addPremiumCell();
			td.injectInside(tr);
			// Add Button Cell
			td = this.addButtonCell();
			td.injectInside(tr);
			return tr;
		}
	});
	var Quotations = new Class(
	{
		initialize: function(holder, type, authKey, leadId){
			this.holder    = holder;
			this.quoteType = type;
			this.authKey   = authKey;
			this.leadId    = leadId;
		}
		, getQuotes : function(){
			if (this.authKey == "" || this.leadId == "")
			{
				this.handleException();
			}
			else
			{
				this.showMessage("Getting Quotes:");
				this.showAnimation();
				
				proxies.Quotation.GetQuotes.func = this.handleOnLoad;
				proxies.Quotation.GetQuotes.onException = this.handleException;
				proxies.Quotation.GetQuotes(this.quoteType, this.authKey, this.leadId);
			}
		}
		, showMessage: function(message){
			$(this.holder).setHTML("<span>" + message + "</span><br /><img src=\"/_include/images/getQuoteLoader.gif\" alt=\"Getting Quotes\"/>");
		}
		, showAnimation: function(){
			
		}
		, hideAnimation: function(){
			
		}
		, handleOnLoad: function(data){		    
		    var dataToString = function(data){						
			    var serializer = new XMLSerializer();
			    var xml = serializer.serializeToString(data);
			    $(g_holder).setHTML(xml);
		    }
		    var findXmlNode = function(xmlList, name) {
				var xmlElement, xmlListLength = xmlList.length;
				for(var i = 0; i < xmlListLength; i++) {
					xmlElement = xmlList[i];
					if(xmlElement.localName == name)
						return xmlElement;
				}
				return null;
			}
		    var getNodeValue = function(parentNode, prefix, nodeName){
		        var node;
		        var nodeValue = "";
		        try
		        {
		            if (window.ie)
		            {
		                node = parentNode.selectSingleNode(prefix + ':' + nodeName).firstChild; //IE
		            }
		            else
		            {
						var tempNode = findXmlNode(parentNode.childNodes, nodeName);
						if(tempNode != null)
							node = tempNode.firstChild;
		                //node = parentNode.getElementsByTagName(nodeName)[0].firstChild; //Firefox
		            }
		            if (node != null)
		            {
		                nodeValue = node.nodeValue;
		            }
		        }
		        catch (e)
		        {
		            nodeValue = "Error: " + e.Message;
		        }
		        return nodeValue;
		    }		    
			if (data != null)
			{							
				// Print xml out as a string (debug)
				//$(g_holder).setHTML(data.text);
				//alert(data.xml);
				//return;
				
				// Create a listings array from the xml
				var quoteNodes = data.firstChild.childNodes;
				var quotes = [];
				var counter = 1;
				$A(quoteNodes).each(function(quoteNode) {
				    var prefix = "q" + counter.toString();
				    this.quoteId = getNodeValue(quoteNode, prefix, "QuoteID");
                    this.responseRef = getNodeValue(quoteNode, prefix, "ResponseRef");
                    this.errorCode = getNodeValue(quoteNode, prefix, "ErrorCode");
                    this.providerId = getNodeValue(quoteNode, prefix, "ProviderID");
                    this.providerIdent = getNodeValue(quoteNode, prefix, "ProviderIdent");
                    this.providerName = getNodeValue(quoteNode, prefix, "ProviderName");
                    this.productId = getNodeValue(quoteNode, prefix, "ProductID");
                    this.providerLogo = getNodeValue(quoteNode, prefix, "ProviderLogo");
                    this.productName = getNodeValue(quoteNode, prefix, "ProductName");
                    this.weblineInfo = getNodeValue(quoteNode, prefix, "WeblineInfo");
                    this.notesHtml = getNodeValue(quoteNode, prefix, "NotesHTML");
                    this.documents = getNodeValue(quoteNode, prefix, "Documents");
                    this.isApplicationAvailable = getNodeValue(quoteNode, prefix, "IsApplicationAvailable");
                    this.logonTokenAccepted = getNodeValue(quoteNode, prefix, "LogonTokenAccepted");
                    this.success = getNodeValue(quoteNode, prefix, "Success");
                    this.exceptionMessage = getNodeValue(quoteNode, prefix, "ExceptionMessage");
                    this.benefit = getNodeValue(quoteNode, prefix, "Benefit");
                    this.premium = getNodeValue(quoteNode, prefix, "Premium");
                    this.rates = getNodeValue(quoteNode, prefix, "Rates");
                    this.netPremium = getNodeValue(quoteNode, prefix, "NetPremium");
                    this.cictpdDef = getNodeValue(quoteNode, prefix, "CICTPDDef");
                    this.loanRate = getNodeValue(quoteNode, prefix, "LoanRate");
                    this.isTaxEfficient = getNodeValue(quoteNode, prefix, "IsTaxEfficient");                    
					
					//Add an quote
					var quote = new Quote(quoteId, responseRef, errorCode, providerId, providerIdent, providerName
		                                , providerLogo, productId, productName, weblineInfo, notesHtml, documents
		                                , isApplicationAvailable, logonTokenAccepted, success, exceptionMessage
		                                , benefit, premium, rates, netPremium, cictpdDef, loanRate, isTaxEfficient);
					quotes.push(quote);
					
					//Increment
					counter++;
				});
					
				// Display a table of quotes
				var table = new Element('table', {
					    'class' : 'quotes_table'	
					    , 'border' : '0'			
					    , 'cellspacing' : '0'
					    , 'cellpadding' : '0'		
				    });
				for (var i = 0; i < quotes.length; i++)
				{
			        // Add row to table
					var tr = quotes[i].toRow();
			        tr.injectInside(table);
				}
				// Add table to placeholder
				if (window.ie)
				{
				    $(g_holder).setHTML(table.outerHTML);
				}
				else
				{
				    $(g_holder).setHTML("");
				    table.injectInside($(g_holder));				
				}
				// Fix an IE6 mousehover bug
				attachMouseHoverEvents();
			}
			else
			{
				$(g_holder).setHTML("Sorry no quote was available!");
			}
		}
		, handleException: function(exception){
			var msg = "Exception occurred. No more information available.";
			if (exception != null && exception.message != null) msg = exception.message;
			$(g_holder).setHTML("<span>Sorry there was an error! Error: " + msg + "</span>");
		}
	});
    
	var quotations = new Quotations(g_holder, g_quoteType, g_authKey, g_leadId);
	quotations.getQuotes();
}
/* Help Dialogue */    
var helpDialogBox;
var HelpDialog = new Class({
    initialize: function(){
        this.helpIcon = "";
        this.oDialog = $('helpDialog');
        this.oText = $('helpText');
        this.topOffSet = -23;
        if (window.gecko) this.topOffSet = -33;
        this.leftOffSet = 22;
        this.showDelay = 500;
        this.hideDelay = 0;
        this.timeout;
    }
    , setHelpIcon : function(helpIcon) {
        this.helpIcon = helpIcon;
    }
    , show : function() {
        if (this.timeout != null) window.clearTimeout(this.timeout);
        this.timeout = window.setTimeout(this.show_delegate, this.showDelay);
    }
    , hide : function() {
        if (this.timeout != null) window.clearTimeout(this.timeout);
        this.timeout = window.setTimeout(this.hide_delegate, this.hideDelay);        
    }
    , show_delegate : function() {
        helpDialogBox.oText.setText(helpDialogBox.helpIcon.getProperty('helptext'));
        var position = helpDialogBox.helpIcon.getCoordinates();
        helpDialogBox.oDialog.setStyles({
            top: position.top + helpDialogBox.topOffSet
            , left: position.left + helpDialogBox.leftOffSet
        });
        helpDialogBox.doOpacity(0, 1);            
    }
    , hide_delegate : function() {
        if (helpDialogBox.oDialog.getStyle('visibility') == 'visible') helpDialogBox.doOpacity(1, 0);
    }
    , doOpacity : function(s, f) {
        var myFx = new Fx.Style(this.oDialog, 'opacity').start(s, f);        
    }
});
/* Help Dialogue Functions */   
function showHelp(oHelpIcon)
{
    if (helpDialogBox == null) helpDialogBox = new HelpDialog();
    helpDialogBox.setHelpIcon(oHelpIcon);
    helpDialogBox.show();
}
function hideHelp()
{
    helpDialogBox.hide();
}