let clientKey = "CA1001BF-AF4C-9E5C-9661-4DB273495918"; let verifyHostURL = "//verify.flickfusion.net/"; let vehicleVinData = {}; var getRefDomain = window.location.hostname; loadFFScript( "https://storage.googleapis.com/gcbimages/s/popup.js", function () { } ); async function checkifVideoIsAvailable(vin,client_Key) { if(client_Key) clientKey = client_Key; var checkVIN = verifyHostURL + "ff_verify_vin.php?vin=" + vin + "&client_id=" + clientKey; let result = await fetchJsonp(checkVIN, { timeout: 25000, jsonpCallback: "jsoncallback", jsonpCallbackFunction: null, }) .then((response) => { return response.json(); }) .then((videoData) => { return videoData; }); if (result.code === 200) { let vinNumber = result.data.vin; vehicleVinData[vin] = result.data; return true; } else { return false; } } function openWidget(vin) { var videoData = vehicleVinData[vin]; if (videoData.popup) { var iframeURL = videoData.popup.url; var popupWidth = 960; new ConModal({ width: popupWidth, videoPage: videoData.popup.type, modalTitle: 'Video', iframeUrl: iframeURL + '&referer=' + getRefDomain, fullscreen: videoData.popup.tab === 1 ? true : false }); } if (videoData.nv) { var vh_af_queryString = '&vin=' + videoData.veh_vin + '&year=' + videoData.veh_year + '&make=' + encodeURIComponent(videoData.veh_make) + '&model=' + encodeURIComponent(videoData.veh_model) + '&trim=' + encodeURIComponent(videoData.veh_trim) + '&body_type=' + encodeURIComponent(videoData.veh_body); new ConModal({ width: videoData.nv ? (videoData.nv.button === 'AF' ? '90%' : 960) : 960, videoPage: videoData.nv.type, modalTitle: 'Video', iframeUrl: videoData.nv.url + vh_af_queryString + '&referer=' + getRefDomain }); } } function fetchJsonp(_url) { var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var url = _url; var timeout = options.timeout || defaultOptions.timeout; var jsonpCallback = options.jsonpCallback || defaultOptions.jsonpCallback; var timeoutId = undefined; return new Promise(function (resolve, reject) { var callbackFunction = options.jsonpCallbackFunction || generateCallbackFunction(); var scriptId = jsonpCallback + "_" + callbackFunction; window[callbackFunction] = function (response) { resolve({ ok: true, // keep consistent with fetch API json: function json() { return Promise.resolve(response); }, }); if (timeoutId) clearTimeout(timeoutId); removeScript(scriptId); clearFunction(callbackFunction); }; // Check if the user set their own params, and if not add a ? to start a list of params url += url.indexOf("?") === -1 ? "?" : "&"; var jsonpScript = document.createElement("script"); jsonpScript.setAttribute( "src", "" + url + jsonpCallback + "=" + callbackFunction ); if (options.charset) { jsonpScript.setAttribute("charset", options.charset); } jsonpScript.id = scriptId; document.getElementsByTagName("head")[0].appendChild(jsonpScript); timeoutId = setTimeout(function () { reject(new Error("JSONP request to " + _url + " timed out")); clearFunction(callbackFunction); removeScript(scriptId); window[callbackFunction] = function () { clearFunction(callbackFunction); }; }, timeout); // Caught if got 404/500 jsonpScript.onerror = function () { reject(new Error("JSONP request to " + _url + " failed")); clearFunction(callbackFunction); removeScript(scriptId); if (timeoutId) clearTimeout(timeoutId); }; }); } function generateCallbackFunction() { return ( "jsonp_" + new Date().getTime() + "_" + Math.ceil(Math.random() * 100000) ); } function clearFunction(functionName) { try { delete window[functionName]; } catch (e) { window[functionName] = undefined; } } function removeScript(scriptId) { var script = document.getElementById(scriptId); if (script) { document.getElementsByTagName("head")[0].removeChild(script); } } function loadFFScript(url, callback) { var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.type = "text/javascript"; script.src = url; var done = false; script.onload = script.onreadystatechange = function () { if ( !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") ) { done = true; if (callback) callback(); script.onload = script.onreadystatechange = null; head.removeChild(script); } }; head.appendChild(script); }