var VDNA_apiKey = 'imagini'; var VDNA_hash = 'aa4288b2f80d16bfb02e36af35b73858'; var VDNA_enableRemoteCookies = true; /** * VisualDNA API * * @author Imagini */ var VDNA_urls = { live: "http://gateway-lite.visualdna.com/vdna_api.php", staging: "http://gateway-lite.staging.youniverse.com/vdna_api.php", deploytest: "http://gatewaylite.deploytest.dmz.youniverse.com/rest.php", //not functional vm: "http://lightgateway.vm.youniverse.com/vdna_api.php" } var VDNA_url = VDNA_urls.live; var VDNA_enableVDNABank = true; var VDNA_cookieName = "vdnaUserId"; var VDNA_permCookieName = "vdnaUserPermission"; var VDNA_userAskedCookieName = "vdnaUserAskedAboutPermission"; var xmlhttp; var VDNA_userPermission; var VDNA_lastUserResponse; var VDNA_userProfile; var VDNA_userFeedback; var VDNA_userID; var VDNA_safariNewUser = false; var VDNA_safariUpdateCookie = false; var VDNA_setComplete; var VDNA_error = ''; var VDNA_answer = ''; var VDNA_functionNameCalled = new Array(); // used to know what function was called, to know to call it again after the permission is set /** * Fetches UserService id for current user * */ function VDNA_GetUserID() { if (VDNA_LocalCookieExists(VDNA_cookieName)) { VDNA_userID = VDNA_GetInfoFromCookie(VDNA_cookieName); return VDNA_userID; } else { if (VDNA_enableRemoteCookies) { if (VDNA_RequestPeriodOver()) { VDNA_GetUserIDRemote(); } else { return 0; } } else { if (!VDNA_LocalCookieExists(VDNA_permCookieName)) { VDNA_SetUpInfoCookie(VDNA_permCookieName, 'true'); } } } } /** * Determines if a client has access to a user's VDNA data * */ function VDNA_getClientPermission() { if (VDNA_functionNameCalled.length > 0 && !VDNA_LocalCookieExists(VDNA_userAskedCookieName) && VDNA_enableVDNABank == true) return false; if (!VDNA_LocalCookieExists(VDNA_userAskedCookieName) && VDNA_enableVDNABank == true && VDNA_LocalCookieExists(VDNA_cookieName)) { callback = 'VDNA_processGetClientPermission'; var url = VDNA_url + '?method=api.soa.us.getClientPermission¶m1=' + VDNA_config.userID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = url; headID.appendChild(newScript); return false; } return true; } /* * Method that processes the client's permission over user VDNA data * */ function VDNA_processGetClientPermission(jsonObj) { if (jsonObj['@attributes'].stat == 'ok') { if (jsonObj.userPermission['@attributes'].permission == '0') { VDNA_show_modal(); } else { if (jsonObj.userPermission['@attributes'].permission == '1') { VDNA_SetUpInfoCookie(VDNA_userAskedCookieName, 'true'); if (VDNA_functionNameCalled.length > 0) { for (var i=0; i 0) { for (var i=0; i 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { return true; } } return false; } /* * Parse local cookie data * */ function VDNA_GetInfoFromCookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) { c_end=document.cookie.length; } return unescape(document.cookie.substring(c_start, c_end)); } } return false; } /* * Write data to cookie */ function VDNA_SetUpInfoCookie(name, infoStr) { var availability = 1000 * 60 * 60 * 24 * 356 * 10; // ten years if (name == 'vdnaTimestamp') { infoStr = Math.round(new Date().getTime() / 1000); } if (name == VDNA_cookieName || infoStr == '24h') // 24h for asked permission cookie (don't allow) { if (infoStr == 0) return false; availability = 1000 * 60 * 60 * 24; // one day } //cookie val: timestamp; var thisDomain = VDNA_getCookieDomain(); // set time, it's in milliseconds var today = new Date(); today.setTime( today.getTime() ); var expires_date = new Date( today.getTime() + availability ); // one year document.cookie = name + "=" + escape(infoStr) + ";expires=" + expires_date.toGMTString() + ";path=/" + ";domain=" + thisDomain; } /* * Write data to cookie */ function VDNA_DeleteLocalCookie(name) { var thisDomain = VDNA_getCookieDomain(); var deleteTime = 'Thu, 01-Jan-1970 00:00:01 GMT'; document.cookie = name + "=0" + ";expires=" + deleteTime + ";path=/" + ";domain=" + thisDomain; } /* * Verifies that the time period from the former request is over 24h * */ function VDNA_RequestPeriodOver() { var cookieTimestamp = VDNA_GetInfoFromCookie('vdnaTimestamp'); if (!cookieTimestamp) { return true; } var timestamp = Math.round(new Date().getTime() / 1000); if (timestamp - cookieTimestamp > 60*60*24) // period passed is biger than 24h we try again :) { return true; } return false; } /* * Return user id from remote cookie, if available * */ function VDNA_GetUserIDRemote() { if ( (VDNA_userID === false || VDNA_userID == undefined || VDNA_userID == 'false') && VDNA_error == '') { var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = VDNA_url + '?format=json&method=api.vdna.getRemoteCookie&v=1&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_GetUserIDRemoteValue'; headID.appendChild(newScript); setTimeout('VDNA_GetUserIDRemote()',300); } else { if (VDNA_error != '') { alert(VDNA_error); VDNA_error = ''; } else { VDNA_SetUpInfoCookie('vdnaTimestamp', ''); VDNA_SetUpInfoCookie(VDNA_cookieName, VDNA_userID); VDNA_SetUpInfoCookie(VDNA_permCookieName, VDNA_userPermission); } } } /* * Takes the new cookie values from the remote host * */ function VDNA_RefreshCookieValues() { var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = VDNA_url + '?format=json&method=api.vdna.getRemoteCookie&v=1&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_GetUserIDRemoteValue'; headID.appendChild(newScript); } /* * Works togheter with VDNA_GetUserIDRemote() and VDNA_RefreshCookieValues() functions, setting the values from json object * */ function VDNA_GetUserIDRemoteValue(jsonObj) { if (jsonObj['@attributes'].stat == 'fail') { VDNA_error = jsonObj.err['@attributes'].msg; alert(VDNA_error); } else { VDNA_userID = jsonObj.data.vdnaUserId['@value']; VDNA_config.userID = VDNA_userID; VDNA_userPermission = jsonObj.data.vdnaUserPerm['@value']; VDNA_SetUpInfoCookie('vdnaTimestamp', ''); VDNA_SetUpInfoCookie(VDNA_permCookieName, VDNA_userPermission); if (VDNA_userID == 0) VDNA_DeleteLocalCookie(VDNA_cookieName); else VDNA_SetUpInfoCookie(VDNA_cookieName, VDNA_userID); } } /* * Returns last response for a given module * */ function VDNA_GetLastResponse(moduleID, callback) { if (!VDNA_getClientPermission()) { var thisFunction = 'VDNA_GetLastResponse(' + moduleID + ', ' + callback + ')'; VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction; return false; } if (callback == null) callback = 'VDNA_processLastUserResponse'; var url = VDNA_url + '?method=api.soa.us.getLastUserResponse¶m1=' + VDNA_config.userID + '¶m2=' + moduleID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = url; headID.appendChild(newScript); } /* * Returns response data for a given response id * */ function VDNA_GetUserResponse(responseID, callback) { if (!VDNA_getClientPermission()) { var thisFunction = 'VDNA_GetUserResponse(' + responseID + ', ' + callback + ')'; VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction; return false; } if (callback == null) callback = 'VDNA_processResponse'; var url = VDNA_url + '?method=api.soa.us.getUserFullResponse¶m1=' + VDNA_config.userID + '¶m2=' + responseID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = url; headID.appendChild(newScript); } /* * Returns response data for a shared response id * */ function VDNA_GetSharedResponse(responseID, callback) { if (!VDNA_getClientPermission()) { var thisFunction = 'VDNA_GetSharedResponse(' + responseID + ', ' + callback + ')'; VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction; return false; } if (callback == null) callback = 'VDNA_processSharedResponse'; var url = VDNA_url + '?method=api.soa.us.getFullResponse¶m1=' + responseID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = url; headID.appendChild(newScript); } /* * Returns user profile * */ function VDNA_GetUserProfile(callback) { if (!VDNA_getClientPermission()) { var thisFunction = 'VDNA_GetUserProfile(' + callback + ')'; VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction; return false; } if (callback == null) callback = 'VDNA_processUserProfile'; var url = VDNA_url + '?method=api.soa.us.getUserProfile¶m1=' + VDNA_config.userID + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = url; headID.appendChild(newScript); } /* * Returns response feedback data * */ function VDNA_GetUserFeedback(responseID, schema_id, callback) { if (!VDNA_getClientPermission()) { var thisFunction = 'VDNA_GetUserFeedback(' + responseID + ', ' + schema_id + ', ' + callback + ')'; VDNA_functionNameCalled[VDNA_functionNameCalled.length] = thisFunction; return false; } if (callback == null) callback = 'VDNA_processUserFeedback'; var url = VDNA_url + '?method=api.soa.us.getUserFeedback¶m1=' + responseID + '¶m2=' + escape('') + '¶m3=' + schema_id + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=' + callback + '&format=json&v=1'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = url; headID.appendChild(newScript); } /* * Write user id to cookie, function called from Flash * */ function VDNA_FlashGetUserID(user_id) { // set cookie on local domain VDNA_SetUpInfoCookie(VDNA_cookieName, user_id); // adding userid to the config var VDNA_config.userID = user_id VDNA_userID = user_id; //In case of Safari if (/Safari/.test(navigator.userAgent)) VDNA_safariNewUser = true; // set cookie on remote domain (my.visualdna.com) var scriptUrl = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1¶m1=' + user_id + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_SetCompleteRemoteValue'; var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = scriptUrl; headID.appendChild(newScript); } /* * In case of Safari redirect user to my.visualdna.com site for cookie saving * */ function VDNA_Redirect(resultsPage, target) { var thisUrl = window.location.href; urlArray = thisUrl.split("/"); if (urlArray[urlArray.length - 1].indexOf(".") == -1) { resultsPage = thisUrl + resultsPage; } else { urlArray.splice(urlArray.length-1,1); thisUrl = urlArray.join("/"); resultsPage = thisUrl + "/" + resultsPage; } VDNA_userPerm = VDNA_GetInfoFromCookie(VDNA_permCookieName); if ( (VDNA_safariNewUser == true && VDNA_safariUpdateCookie == false) ) { var scriptUrl = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1¶m1=' + VDNA_userID + '¶m2=¶m3=' + escape(resultsPage) + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash; window.location = scriptUrl; return false; } if (VDNA_safariUpdateCookie == true) { if (VDNA_userPerm == 'true') { var scriptUrl = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1¶m1=¶m2=%22' + VDNA_userPerm + '%22¶m3=' + escape(resultsPage) + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash; window.location = scriptUrl; } if (VDNA_userPerm == 'false') { var scriptUrl = VDNA_url + '?format=json&method=api.vdna.deleteRemoteCookie&v=1¶m1=' + escape(resultsPage) + '&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash; window.location = scriptUrl; } return false; } window.location = resultsPage; } /* * Works togheter with VDNA_FlashGetUserID() and VDNA_FlashGetUserPerm() and VDNA_DeleteCookie() functions, getting the values from json object * */ function VDNA_SetCompleteRemoteValue(jsonObj) { if (jsonObj['@attributes'].stat == 'fail' && jsonObj.err['@attributes'].msg != 'No vdnaUserId cookie set') { alert(jsonObj.err['@attributes'].msg); } else { VDNA_setComplete = true; } } /* * function for unsetting "Save my VisualDNA" * */ function VDNA_FlashSetVDNA(bool) { //In case of Safari if (/Safari/.test(navigator.userAgent)) VDNA_safariUpdateCookie = true; if (bool == 'false') { var confText = 'Saving your VisualDNA is recommended, as it allows you to have a more personalised experience on' + ' this site. We respect your privacy, and your VisualDNA is under your total control at all times -' + ' simply go to my.visualdna.com to manage your VisualDNA.' + '\n\n Are you sure you want to change this setting?'; var conf = confirm(confText); if (conf) { VDNA_SetUpInfoCookie(VDNA_permCookieName, 'false'); VDNA_DeleteCookie(); return 'false'; } return 'true'; } else { if (bool == 'true') { VDNA_FlashGetUserPerm('true'); return 'true'; } } } /* * Delete user id cookie and all the association between him and his responses * */ function VDNA_DeleteCookie() { // delete cookie on local domain VDNA_DeleteLocalCookie(VDNA_cookieName); VDNA_DeleteLocalCookie('vdnaTimestamp'); VDNA_DeleteLocalCookie(VDNA_userAskedCookieName); //In case of Safari we solve this by redirect, else we do it this way if (!/Safari/.test(navigator.userAgent)) { // delete cookie on remote domain(my.visualdna.com) an remove associations var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = VDNA_url + '?format=json&method=api.vdna.deleteRemoteCookie&v=1&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_SetCompleteRemoteValue'; headID.appendChild(newScript); } } /* * Get user id from cookie, function called from Flash * */ function VDNA_FlashSendUserID() { VDNA_userID = VDNA_GetInfoFromCookie(VDNA_cookieName); return VDNA_userID; } /* * Write user permission to cookie, function called from Flash or JS * */ function VDNA_FlashGetUserPerm(bool) { // set cookie on local domain VDNA_SetUpInfoCookie(VDNA_permCookieName, bool); // set cookie on remote domain (my.visualdna.com) var headID = document.getElementsByTagName("head")[0]; var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = VDNA_url + '?format=json&method=api.vdna.setRemoteCookie&v=1¶m1=¶m2=%22' + bool + '%22&api_key=' + VDNA_apiKey + '&sig=' + VDNA_hash + '&callback=VDNA_SetCompleteRemoteValue'; headID.appendChild(newScript); } /* * Get user permission from cookie, function called from Flash or JS * */ function VDNA_FlashSendUserPerm() { VDNA_userPerm = VDNA_GetInfoFromCookie(VDNA_permCookieName); return VDNA_userPerm; } /* * Close the permission modal * */ function VDNA_modalClose() { x = document.getElementById('permModal'); x.parentNode.removeChild(x); x = document.getElementById('modalDataContainer'); x.parentNode.removeChild(x); document.body.style.overflow = 'auto'; } /* * Open the permission modal * */ function VDNA_modalClose() { x = document.getElementById('permModal'); x.parentNode.removeChild(x); x = document.getElementById('modalDataContainer'); x.parentNode.removeChild(x); document.body.style.overflow = 'auto'; } /* * Open the permission modal * */ function VDNA_show_modal() { var left = (VDNA_getWindowWidth() - 400)/2 + "px", domain = VDNA_getCookieDomain(), timestamp = Math.round(new Date().getTime() / 1000); VDNA_answer = 'true'; /* outer */ var modalContainerOuter = document.createElement('div'); modalContainerOuter.setAttribute('id', 'modalDataContainer'); modalContainerOuter.style.fontFamily = 'font-family: Arial, "Helvetica Neue", Helvetica, sans-serif'; modalContainerOuter.style.fontSize = '15px'; modalContainerOuter.style.lineHeight = '18px'; modalContainerOuter.style.textAlign = 'left'; modalContainerOuter.style.color = '#999999'; modalContainerOuter.style.backgroundColor = '#eeeeee'; modalContainerOuter.style.position = 'absolute'; modalContainerOuter.style.margin = '0'; modalContainerOuter.style.padding = '0'; modalContainerOuter.style.fontWeight = 'normal'; modalContainerOuter.style.fontStyle = 'normal'; modalContainerOuter.style.textTransform = 'none'; modalContainerOuter.style.left = left; modalContainerOuter.style.top = '90px'; modalContainerOuter.style.zIndex = 1001; modalContainerOuter.style.width = '406px'; /* container */ var modalContainer = document.createElement('div'); modalContainer.style.zIndex = 1001; modalContainer.style.borderColor = '#a9a9a9'; modalContainer.style.borderWidth = '6px'; modalContainer.style.borderStyle = 'solid'; /* inner */ var modalContainerInner = document.createElement('div'); modalContainerInner.style.padding = '25px 18px 13px 18px'; modalContainerInner.style.zIndex = 1001; modalContainerInner.innerHTML = '

' + domain.substr(1, domain.length) + ' wants permission to access your VisualDNA and give you a more personalized experience.

'+ ''+ ''+ ''+ '

See your VisualDNA and set preferences on my.visualdna.com

'+ '
VisualDNA
' /* modal shadow */ var permModal = document.createElement('div'); permModal.id = "permModal"; permModal.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=20)'; permModal.style.backgroundColor = '#333'; permModal.style.position = 'absolute'; permModal.style.top = '0'; permModal.style.left = '0'; permModal.style.height = '100%'; permModal.style.width = '100%'; permModal.style.opacity = '.2'; permModal.style.zIndex = '1000'; document.body.style.overflow = 'hidden'; document.body.appendChild(permModal); modalContainer.appendChild(modalContainerInner); modalContainerOuter.appendChild(modalContainer); document.body.appendChild(modalContainerOuter); permModal.onclick = VDNA_modalClose; } /* * Gets the window width so that the modal window will be always positioned on the center * */ function VDNA_getWindowWidth() { var x = 0; if (self.innerHeight) x = self.innerWidth; else if (document.documentElement && document.documentElement.clientHeight) x = document.documentElement.clientWidth; else if (document.body) x = document.body.clientWidth; return x; }