///////////////////////////////////////////////////////////////////////////
//  File        :   WebIQOptInScript.js
//
//  Purpose     :   This file contains all of the necessary functionality
//                  to conditionally afford the current HTTP request the
//                  opportunity to opt-in to the WebIQ feedback process.
//
//                  The Opt-In Script can be referenced by using the
//                  following HTML snippet, which can be placed in either the
//                  <head> or <body> elements:
//
//                      <script id="WebIQOptIn.v2" type="text/javascript" language="JavaScript" src="WebIQOptIn.js"></script>
//
//                  Of importance is the value of the <script> element's "id"
//                  attribute - it should never be omitted or changed.
//
//                  If the <script> element is included in the <body>
//                  element, the Opt-In Process can be expedited by
//                  additionally including the following HTML immediately
//                  before the <script> element:
//
//                      <div id="DialogContainer" style="display:none"></div>
//                      <iframe id="DialogContainer.Shadow" style="display:none"></iframe>
//
//                  If one or both of those elements are omitted, the Opt-In
//                  Process will delay until the page completely loads.
//
//                  NOTE:  This entire documentation block can be deleted
//                  prior to deployment in order to reduce the file's size.
//
//  History     :   09.18.2007      USC                     Created
///////////////////////////////////////////////////////////////////////////
var m_disableWebIQ = false;
var m_baseUrl = "http://webiq005.webiqonline.com/WebIQ/DataServer/Pub/";
var m_optInVersion;var m_authParams = new Object();var m_debug = 0;function OptInMain(){if (!m_disableWebIQ){CreateImage("WebIQAuthCookieImage",m_baseUrl + "DataServer.dll?Handler=CreateAuthCookie",OnAuthCookieCreated);}}function OnAuthCookieCreated(){var imgSrc;var params;RemoveImage("WebIQAuthCookieImage");imgSrc = m_baseUrl;AddParameter("Handler", "AuthorizeOptInRequest");AddParameter("pid", "{5e17f9ea-391c-423a-925d-243b2c62f577}");AddParameter("state", "");AddParameter("ourl", window.document.URL);AddParameter("olt", GetOverrideLanguageTags());AddParameter("oiv", 1);AddParameter("seq", new Date().valueOf());params = new Array();for (name in m_authParams){params[params.length] = name + "=" + m_authParams[name];}if (params.length > 0){imgSrc += "DataServer.dll?" + params.join("&");}CreateImage("WebIQAuthorizationImage",imgSrc,OnAuthImageLoaded);}function OnAuthImageLoaded(eventObject){var imgElem;var imageWidth;imgElem = null;imageWidth = 0;if (window.event != null){imgElem = window.event.srcElement;}else if (eventObject != null&&eventObject.currentTarget != null){imgElem = eventObject.currentTarget;}if (imgElem != null&&imgElem.width != null){imageWidth = imgElem.width;}RemoveImage("WebIQAuthorizationImage");switch (imageWidth){case 1:OnAuthorizationGranted();break;case 2:OnProjectUnavailable();break;case 3:OnBrowserPlatformNotSupported();break;case 5:OnRepeatParticipation();break;case 6:OnThirdPartyCookiesNotSupported();break;case 4:default:OnAuthorizationDenied();break;}}function OnAuthorizationGranted(){var link;var userAgent;var isIE;userAgent = navigator.userAgent.toLowerCase();isIE = (userAgent.indexOf("opera") == -1 && userAgent.indexOf("msie") >= 0);link = document.createElement("link");if (isIE){AddEventHandler(link,"load",ShowOptInDialog);}link.rel = "stylesheet";link.type = "text/css";link.href = "http://webiq005.webiqonline.com/WebIQ/DataServer/Pub/DataServer.dll?Handler=GetStyleDocument&SDDID={8DDB9890-25B6-4006-92A3-4EEB4D5DC593}";document.getElementsByTagName("head")[0].appendChild(link);if (!isIE){ShowOptInDialog();}}function ShowOptInDialog(){var optInUI;var optInUIShadow;var addOptInUI2DOM;var addOptInUIShadow2DOM;optInUI = null;optInUIShadow = null;addOptInUI2DOM = false;addOptInUIShadow2DOM = false;if (2 == m_optInVersion){optInUI = document.getElementById("DialogContainer");optInUIShadow = document.getElementById("DialogContainer.Shadow");}if (null == optInUI){optInUI = document.createElement("div");optInUI.id = "DialogContainer";addOptInUI2DOM = true;}if (null == optInUIShadow){optInUIShadow = document.createElement("iframe");optInUIShadow.id = "DialogContainer.Shadow";addOptInUIShadow2DOM = true;}optInUI.Show = function(){var dialog;var dialogShadow;if ((dialog = document.getElementById("DialogContainer")) != null&&(dialogShadow = document.getElementById("DialogContainer.Shadow")) != null){dialog.style.display = "block";dialog.style.visibility = "visible";dialogShadow.style.display = "block";dialogShadow.style.visibility = "visible";}else{m_debug = 1;}};optInUI.Hide = function(){var dialog;var dialogShadow;if ((dialog = document.getElementById("DialogContainer")) != null&&(dialogShadow = document.getElementById("DialogContainer.Shadow")) != null){dialog.style.display = "none";dialog.style.visibility = "hidden";dialogShadow.style.display = "none";dialogShadow.style.visibility = "hidden";}else{m_debug = 2;}};optInUI.style.display = "none";optInUI.style.visibility = "hidden";optInUI.style.position = "absolute";optInUI.style.zIndex = 2147483647;optInUI.style.border = "1px solid #000000";optInUI.style.margin = "0px";optInUI.style.padding = "0px";optInUI.style.width = 620;optInUI.style.height = 480;optInUI.style.left = ((document.body.clientWidth - 620) / 2);optInUI.style.top = document.body.scrollTop + 20;optInUI.innerHTML = unescape("%3Cdiv%20class%3D%22HeaderRegion%22%3E%0A%3Cdiv%20class%3D%22HeaderImage%22%3E%3Cimg%20src%3D%22http%3A//webiq005.webiqonline.com/WebIQ/DataServer/Pub/DataServer.dll%3FHandler%3DGetImage%26amp%3Bidid%3D%7B4F4968DB-0916-4F96-9D79-63557621CD9E%7D%22%20class%3D%22%22%3E%3C/div%3E%0A%3Cdiv%20class%3D%22HeaderText%22%3EOpt-In%3C/div%3E%0A%3Cdiv%20class%3D%22spacer%22%3E%3C/div%3E%0A%3C/div%3E%0A%3Cform%20id%3D%22htmlform%22%3E%0A%3Cdiv%20class%3D%22QuestionGroup%22%20style%3D%22margin-left%3A15px%3Bmargin-right%3A15px%3B%22%3E%0A%3Ctable%20class%3D%22QuestionTable%22%20cellpadding%3D%220%22%20cellspacing%3D%220%22%3E%3Ctr%20class%3D%22QuestionTable%22%3E%3Ctd%20id%3D%22Q10%22%20width%3D%22100%25%22%20class%3D%22%20Opt-InDialogQ001%22%3E%0A%3Cdiv%20class%3D%22QuestionCell%22%3E%0A%3Cdiv%20class%3D%22QuestionHeader%22%3E%0A%3Cdiv%20class%3D%22QuestionTextBlock%22%3E%3Cspan%20class%3D%22QuestionText%22%3E%3Cp%3EAy%FAdenos%20a%20mejorar%20el%20sitio.%3C/p%3E%3Cp%3ESea%20tan%20amable%20de%20responder%20un%20breve%20cuestionario%20%28no%20debe%20tomar%20ni%201%20minuto%29%20sobre%20su%20experiencia%20con%20el%20sitio%20para%20ayudarnos%20a%20que%20su%20pr%F3xima%20visita%20sea%20a%FAn%20mejor.%3C/p%3E%3Cp%3EPara%20participar...%3Cul%3E%3Cli%3ENavegue%20por%20el%20sitio%20como%20lo%20har%EDa%20habitualmente%3C/li%3E%3Cli%3EResponda%20unas%20sencillas%20preguntas%20al%20principio%20y%20antes%20de%20salir%20del%20sitio%3C/li%3E%3Cli%3ESus%20respuestas%20se%20mantienen%20seguras%20y%20en%20estricta%20confidencialidad%3C/li%3E%3Cli%3ENo%20se%20le%20pedir%E1%20que%20compre%20nada%3C/li%3E%3Cli%3EPuede%20salir%20de%20la%20encuesta%20en%20cualquier%20momento%3C/li%3E%3C/ul%3E%3C/p%3E%3C/span%3E%26nbsp%3B%3C/div%3E%0A%3C/div%3E%0A%3Cdiv%20class%3D%22ChoiceGroupCell%22%3E%0A%3C/div%3E%0A%3C/div%3E%0A%3C/td%3E%3C/tr%3E%3C/table%3E%0A%3C/div%3E%0A%3C/form%3E%0A%3Cdiv%20class%3D%22ButtonContainer%22%3E%3Cbutton%20class%3D%22%22%20onclick%3D%22OnOptInAccepted%28%29%3B%22%3EContinuar%3C/button%3E%3Cbutton%20class%3D%22%22%20onclick%3D%22OnOptInDeclined%28%29%3B%22%3ENo%2C%20gracias%3C/button%3E%3C/div%3E%3Cdiv%20class%3D%22HyperlinkContainer%22%3E%3Ca%20id%3D%22PrivacyPolicyLink%22%20href%3D%22http%3A//www.usabilitysciences.com/corp/privacy_policy.html%23webiq%22%20target%3D%22_blank%22%20class%3D%22%22%3EPol%EDtica%20de%20Privacidad%3C/a%3E%3Ca%20id%3D%22SupportLink%22%20href%3D%22http%3A//www.webiqonline.com/support.asp%3Fpid%3Dsearsoptical%22%20target%3D%22_blank%22%20class%3D%22%22%3E%BFTiene%20alg%FAn%20problema%3F%3C/a%3E%3C/div%3E");optInUIShadow.style.display = optInUI.style.display;optInUIShadow.style.visibility = optInUI.style.visibility;optInUIShadow.style.position = optInUI.style.position;optInUIShadow.style.zIndex = optInUI.style.zIndex - 1;optInUIShadow.style.width = optInUI.style.width;optInUIShadow.style.height = optInUI.style.height;optInUIShadow.style.left = optInUI.style.left;optInUIShadow.style.top = optInUI.style.top;if (addOptInUIShadow2DOM){document.body.appendChild(optInUIShadow);}if (addOptInUI2DOM){document.body.appendChild(optInUI);}AddEventHandler(optInUI,"propertychange",OnOptInDisplayed);optInUI.Show();}function OnAuthorizationDenied(){}function OnProjectUnavailable(){}function OnBrowserPlatformNotSupported(){}function OnRepeatParticipation(){}function OnThirdPartyCookiesNotSupported(){}function OnOptInDisplayed(){var dialog;if (event.propertyName.toLowerCase() == "style.display"&&(dialog = document.getElementById("DialogContainer")) != null&&dialog.style.display == "block"){RemoveEventHandler(dialog,"propertychange",OnOptInDisplayed);CreateImage("OptInDisplayImage",m_baseUrl + "DataServer.dll?Handler=RecordOptInEvent&et=2&seq=" + new Date().valueOf(),OnOptInDisplayProcessed);}else{m_debug = 3;}}function OnOptInDisplayProcessed(){RemoveImage("OptInDisplayImage");}function OnOptInAccepted(){var sequenceNumber;sequenceNumber = new Date().valueOf();var dialog;if ((dialog = document.getElementById("DialogContainer")) != null){if (dialog.Hide != null){dialog.Hide();}else{m_debug = 4;}}else{m_debug = 5;}CreateImage("OptInAcceptedImage",m_baseUrl + "DataServer.dll?Handler=RecordOptInEvent&et=3&seq=" + sequenceNumber.toString(),OnAcceptedOptInProcessed);}function OnAcceptedOptInProcessed(){RemoveImage("OptInAcceptedImage");OpenStartWindow(new Date().valueOf());}function OnOptInDeclined(){var dialog;if ((dialog = document.getElementById("DialogContainer")) != null){if (dialog.Hide != null){dialog.Hide();}else{m_debug = 6;}}else{m_debug = 7;}CreateImage("OptInDeclinedImage",m_baseUrl + "DataServer.dll?Handler=RecordOptInEvent&et=4&seq=" + new Date().valueOf(),OnDeclinedOptInProcessed);}function OnDeclinedOptInProcessed(){RemoveImage("OptInDeclinedImage");}function OpenStartWindow(sequenceNumber){var url;url = m_baseUrl + "SelectSegment.srf?seq=" + sequenceNumber.toString() + "&";if (window.screen != null){url += "sw=" + window.screen.width + "&sh=" + window.screen.height;}else{url += "sw=0&sh=0";}url += "&bl=";if (window.navigator != null){if (window.navigator.systemLanguage != null){url += window.navigator.systemLanguage;}else if (window.navigator.language != null){url += window.navigator.language;}else{url += "unknown";}}else{url += "unknown";}window.top.location = url;}function AddEventHandler(elem,eventName,handler){if (elem.attachEvent != null){elem.attachEvent("on" + eventName,handler);}else if (elem.addEventListener != null){elem.addEventListener(eventName,handler,false);}}function RemoveEventHandler(elem,eventName,handler){if (elem.detachEvent != null){elem.detachEvent("on" + eventName,handler);}else if (elem.removeEventListener != null){elem.removeEventListener(eventName,handler,false);}}function CreateImage(imageID,imageSrc,onLoadHandler){var image;image = document.createElement("img");image.id = imageID;if (image.onreadystatechange != null){image.onreadystatechange = function(eventObject){if (this.readyState == "complete"){onLoadHandler(eventObject);}};}else{image.onload = onLoadHandler;image.onerror = onLoadHandler;}document.body.appendChild(image);image.src = imageSrc;}function RemoveImage(imageID){var image;if ((image = document.getElementById(imageID)) != null){document.body.removeChild(image);}else{m_debug = 8;}}function AddParameter(name,value){if (typeof(name) == "string"&&name.length > 0&&value != null&&value.toString != null&&(value = value.toString()).length > 0){name = escape(name);value = escape(value);for (existingName in m_authParams){if (existingName.toLowerCase() == name.toLowerCase()){return;}}m_authParams[name] = value;}}function GetOverrideLanguageTags(){var tag;var url;var oltStart;tag = "";url = document.URL.toUpperCase();if ((oltStart = url.indexOf("OLT=")) != -1){var oltFinish;oltStart += 4;oltFinish = url.indexOf("&", oltStart);try{if (oltFinish == -1){tag = url.substr(oltStart);}else{tag = url.substr(oltStart, oltFinish - oltStart);}}catch (e){tag = "";}}return tag;}if (document.URL.toLowerCase().indexOf("debugwebiq") != -1){debugger;}if (document.getElementById("WebIQOptIn.v2")){m_optInVersion = 2;}else if (document.getElementById("WebIQOptIn.v1")){m_optInVersion = 1;}else{m_optInVersion = 0;}if (!m_disableWebIQ){if (0 == m_optInVersion||(2 == m_optInVersion&&(!document.getElementById("DialogContainer")||!document.getElementById("DialogContainer.Shadow")))){AddEventHandler(window,"load",OptInMain);}else{OptInMain();}}
