﻿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 openPostcode()
{
    var postcode = document.getElementById('branch_postcode').value;
    
    if(postcode != 'your postcode' && postcode != '') {
        var site = new String(location.href);
        /* first is for development and may be changed locally */
        if (site.indexOf("localhost") > 0) {
            win = window.open("http://www.swinton.co.uk/postcode_locator/locate.php?postcode="+postcode,"Swintonlocator","menubar=no,width=349,height=518,toolbar=no");
            win.focus();
            return false;
        }
        /* don't forget CIPWeb01 */
        else if (site.indexOf("cipweb01") > 0) {
            win = window.open("http://www.swinton.co.uk/postcode_locator/locate.php?postcode="+postcode,"Swintonlocator","menubar=no,width=349,height=518,toolbar=no");
            win.focus();
            return false;
        }
        else if(site.indexOf("connectpoint.dev") > 0) {
            win = window.open("http://www.swinton.co.uk/postcode_locator/locate.php?postcode="+postcode,"Swintonlocator","menubar=no,width=349,height=518,toolbar=no");
            win.focus();
            return false;
        }
        else if(site.indexOf("connectpoint.net") > 0) {
            win = window.open("http://www.swinton.co.uk/postcode_locator/locate.php?postcode="+postcode,"Swintonlocator","menubar=no,width=349,height=518,toolbar=no");
            win.focus();
            return false;
        }
        else if(site.indexOf("testswinton.co.uk") > 0) {
            win = window.open("http://www.swinton.co.uk/postcode_locator/locate.php?postcode="+postcode,"Swintonlocator","menubar=no,width=349,height=518,toolbar=no");
            win.focus();
            return false;
        }
        else {
            win = window.open("http://www.swinton.co.uk/postcode_locator/locate.php?postcode="+postcode,"Swintonlocator","menubar=no,width=349,height=518,toolbar=no");
            win.focus();
            return false;
        }
    }
    else
    {
        return false;
    }
}

function openQuote(loadQuoteUrl, quoteType, affCode)
{
    var urlToLoad = loadQuoteUrl;
    
    //TestTrack 1334 start
    urlToLoad += "?cleardetails=false";

    
    if (quoteType.length > 0)
        urlToLoad += '&product=' + quoteType;
    else
        urlToLoad += '&product=combined';
        
        
    if (affCode.length > 0)
        urlToLoad += '&aff=' + affCode;
        
    window.open(urlToLoad, 'Quote', 'top=0,width=788,height=695,scrollbars=no,resizable=no');
}