﻿ var PopupConfig = new Array();

function updateAnchors() {
    var allA = document.getElementsByTagName("A");
    if (allA != null) {        
        for (var i=0; i<allA.length; i++) {
            var A = allA[i];
            if (A != null) {
                var aTarget = A.target;
                if (aTarget != null) {
                    var newFunc = "";
                    var returnFalse = false;
                    // Calls confirm window if car insurance link
                    if (aTarget=='carInsurance') {
                        newFunc += "confirmCarInsuranceLnk(this);";
                        returnFalse = true;
                    }
                    // Adds window.open call to onclick for popup windows defined in the CMS
                    if (IsInPopupConfig(aTarget)) {
                        newFunc += "OpenPopupFromConfig(this);";
                        returnFalse = true;
                    }
                    
                    if (returnFalse) {
                        newFunc += "return false;";
                    }

                    // Set the onclick of the current Anchor
                    if (newFunc != "") {
                    	if (A.onclick == null || A.onclick == "undefined" || A.onclick == "") {
                    		A.onclick = new Function(newFunc);
                    	}
                    	else {
                    		newFunc = A.onclick + ";" + newFunc;
                    		A.onclick = new Function(newFunc);
                    	}
                    }
                }
            }
        }
    }
}

function IsInPopupConfig(targetName) {
    return PopupConfig[targetName] != null;
}

function OpenPopupFromConfig(obj) {
    var cfg = PopupConfig[obj.target];
    var newWindow = window.open(obj.href, 'name', cfg.styles);
    if ((window.focus) && (newWindow != null)) {
		newWindow.focus();
	}
}

function OpenPopupByTarget(href, target) {
    var cfg = PopupConfig[target];
    window.open(href, target, cfg.styles);
}

//++++++++++++++++++++++++++++++++
// car insurance link confirmation
//++++++++++++++++++++++++++++++++

function confirmCarInsuranceLnk(obj) {
    var msg= confirm("You are now leaving Fiat's website and entering a site that is operated by Equity Insurance Brokers Limited. Fiat Motor Insurance is a trading name of Equity Insurance Brokers Limited, which is authorised and regulated by the Financial Services Authority.");
    if (msg== true)
    {
        window.open(obj.href);
    }
}