try {
   document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function getAff() {

   var loc = new String(window.location);
   var matches = loc.match(/\?aff=([^&]+)/);
   if(matches!=null) {
      return matches[1];
   }
   else {
      var cookies = new String(document.cookie);
      matches = cookies.match(/swinton_referral_tracker\=(.+?)(;|$)/);
      if(matches!=null) {
         return matches[1];
      }
      else {
         return "";
      }
   }
}

function openQuotePanel(ev) {
   YAHOO.util.Event.preventDefault(ev);

   var popup = window.open("https://quote.bullseyeinsurance.co.uk/internet/pm/frontpage.aspx?aff="+getAff(),"bullseyequote","height=648,width=788");

   if(popup != null)
   {
      popup.focus();
   }
}

function retrieveBullseye(ev) {
   YAHOO.util.Event.preventDefault(ev);
   var popup = window.open("https://quote.bullseyeinsurance.co.uk/Internet/pm/quoteretrieval.aspx?aff="+getAff(),"BullseyeQuoteRetrieval","width=788,height=648");
   
   if(popup != null)
   {
      popup.focus();
   }
}

function bullseyeAvailabilityChecker(id) {
   YAHOO.util.Event.onAvailable(id, this.handleOnAvailable, this);
}

bullseyeAvailabilityChecker.prototype.handleOnAvailable = function() {
   if(this.id.match(/retrievelink\d?/)) {
        YAHOO.util.Event.addListener(this, "click", retrieveBullseye);
   }
   else if(this.id.match(/quote/)) {
        YAHOO.util.Event.addListener(this, "click", openQuotePanel);
   }
   
   else if(this.id.match(/quote/)) {
        YAHOO.util.Event.addListener(this, "click", openQuotePanel);
   }
}

var obj = new bullseyeAvailabilityChecker("quotelink");
var obj2 = new bullseyeAvailabilityChecker("quotelink2");
var obj3 = new bullseyeAvailabilityChecker("getaquote");
var obj4 = new bullseyeAvailabilityChecker("retrievelink");
var obj5 = new bullseyeAvailabilityChecker("retrievelink2");








/***** HOME INSURANCE STUFF *****/
/* Create object to hold element information with custom data */
function HomeInsuranceObj(elementId, productType, callback)
{
    this.elementId = elementId;
    this.productType = productType;
    this.callback = callback;
}

/* Set up the callback on it to call the appropriate method */
HomeInsuranceObj.prototype.addClickHandler = function() {
    YAHOO.util.Event.addListener(this.elementId, "click", this.callback, this);
}

/* Will now open the home insurance with the appropriate product parameter */
function openQuotePanelHome(ev, obj) {
    YAHOO.util.Event.preventDefault(ev);
    
    var popup = window.open(urlToLoad + 'proposerdatacapture.aspx?cleardetails=false&product=' + obj.productType + "&aff=" + affCode, 'BullseyePopup', 'top=0, width=788, height=695, scrollbars=no, resizable=no');
    
    if (popup != null)
    {
        popup.focus();
    }
}

/* Function to open the retrieve quote */
function retrieveQuoteHome(ev) {
    YAHOO.util.Event.preventDefault(ev);
    
    var popup = window.open(urlToLoad + 'quoteretrieve.aspx', 'BullseyePopup', 'top=0, width=788, height=695, scrollbars=no, resizable=no');
    
    if (popup != null)
    {
        popup.focus();
    }
}

/* Function to show policy wording */
function showPolicyWording(ev) {
    YAHOO.util.Event.preventDefault(ev);
    
    window.open(urlToLoad + 'SystemText/home_policy_wording.pdf.cdoc?brand=10&product=3', 'PolicyWordingPopup');
}

/***** Add the event handlers *****/
var obj6 = new HomeInsuranceObj("homequotelinkcombined", "combined", openQuotePanelHome);
obj6.addClickHandler();

var obj7 = new HomeInsuranceObj("homequotelinkbuildings", "buildings", openQuotePanelHome);
obj7.addClickHandler();

var obj8 = new HomeInsuranceObj("homequotelinkcontents", "contents", openQuotePanelHome);
obj8.addClickHandler();

var obj9 = new HomeInsuranceObj("retrievelinkhome", "", retrieveQuoteHome);
obj9.addClickHandler();

var aryClassElements = new Array();

/***** Function to add event handlers to policy wording links *****/
function addPolicyWordingHandlers()
{
    getElementsByClassName('relevantPolicyWording', document);
    for ( var i = 0; i < aryClassElements.length; i++ ) 
    {
        var obj = new HomeInsuranceObj(aryClassElements[i].id, "", showPolicyWording);
        obj.addClickHandler();
    }
}


/***** Additional methods *****/
function getElementsByClassName( strClassName, obj ) {
    if ( obj.className == strClassName ) {
        aryClassElements[aryClassElements.length] = obj;
    }
    for ( var i = 0; i < obj.childNodes.length; i++ )
        getElementsByClassName( strClassName, obj.childNodes[i] );
}

/* Travel insurance stuff */

