if (typeof (com_hp_gc) == "undefined")
com_hp_gc = {};
hpgcDebug = function(text)
{
//DEBUG log(text);
return;
};
//DEBUG function log(message) {
//DEBUG var win, logLine;
//DEBUG if (!log.window_ || log.window_.closed) {
//DEBUG win = window.open("", null, "width=400,height=200," +
//DEBUG "scrollbars=yes,resizable=yes,status=no," +
//DEBUG "location=no,menubar=no,toolbar=no");
//DEBUG if (!win) return;
//DEBUG try { win.document.write("
Debug Log" +
//DEBUG "");
//DEBUG win.document.close();
//DEBUG log.window_ = win; } catch (exc) {log.window_ = null;};
//DEBUG }
//DEBUG if (log.window_ && typeof(log.window_.document.createElement) !== "undefined") {
//DEBUG logLine = log.window_.document.createElement("div");
//DEBUG logLine.appendChild(log.window_.document.createTextNode(message));
//DEBUG log.window_.document.body.appendChild(logLine);
//DEBUG }
//DEBUG }
var hpgcStdTimeout = 25000;
// Does JSONP call with provided options:
// url: URL to JSONP method, ending in ? which is replaced by generated callback function
// onSuccess: callback function on success
// onTimeout: callback function on timeout
// timeout: time in ms to wait for script to execute
/*
_b.Ajax.prototype.makeRequest = function (url, meth, onComp, onErr)
JSONP(url, onErr, onComp, 5000);
*/
var uniq = (new Date).getTime(); // For generating unique IDs for jsonp calls
var jsonp = new Array; // Array to hold active jsonp calls
var JSONP = function(url, onTimeout, onSuccess, timeout) {
var id = 'jsonp' + uniq++; // Generate unique id for this call
jsonp[id] = { hasRun: false }; // Keep track of script run status
// Define callback function for JSONP call
window[id] = function(tmp) {
if (jsonp[id]) {
jsonp[id].data = tmp;
jsonp[id].hasRun = true;
}
// cleanup
window[id] = undefined;
try { delete window[id]; } catch (e) { }
}
// Stick generated callback function on end of provided method URL
url = url.replace(/=(\?|%3F)/g, "=" + id);
// Attach script URL to head
var head = document.getElementsByTagName("head")[0];
if (head === null) {
hpgcDebug("no head");
return;
}
var script = document.createElement("script");
script.src = url;
head.appendChild(script);
// Register callbacks and timeout interval value
//var onTimeout = options.onTimeout;
//var onSuccess = options.onSuccess;
//var timeout = options.timeout;
// Poll for script completion on timeout interval
var i = 0;
jsonp[id].poll = setInterval(function() {
// "success"
if (jsonp[id].hasRun == true) {
clearInterval(jsonp[id].poll);
var data = jsonp[id].data;
// cleanup
try {
head.removeChild(script);
}
catch (e) { hpgcDebug('unable to remove child ' + e); }
jsonp[id] = undefined;
try { delete jsonp[id]; } catch (e) { }
if (onSuccess)
//onSuccess(jsonp[id].data);
onSuccess(data);
hpgcDebug("loaded");
}
else {
i += 13;
// "timeout"
if (i > timeout) {
clearInterval(jsonp[id].poll);
if (onTimeout)
onTimeout(i);
// cleanup
hpgcDebug("not loaded");
try {
head.removeChild(script);
}
catch (e) { hpgcDebug('unable to remove child ' + e); }
jsonp[id] = undefined;
try { delete jsonp[id]; } catch (e) { }
}
}
}, 13)
};
/**
* author: Timothy Groves - http://www.brandspankingnew.net
* version: 1.2 - 2006-11-17
* 1.3 - 2006-12-04
* 2.0 - 2007-02-07
* 2.1.1 - 2007-04-13
* 2.1.2 - 2007-07-07
* 2.1.3 - 2007-07-19
* Changes to accomodate HPGC needs
*NEW
*/
if (typeof(bsn) == "undefined")
_b = bsn = {};
// AJAX PROTOTYPE _____________________________________________
if (typeof(_b.Ajax) == "undefined")
_b.Ajax = {};
_b.Ajax = function ()
{
this.req = {};
this.isIE = false;
};
_b.Ajax.prototype.makeRequest = function(url, meth, onComp, onErr, callBack) {
if (callBack == undefined)
{ url = url + "&jsonp=?"; }
else
{ url = url + "&" + callBack + "=?"; }
JSONP(url, onErr, onComp, hpgcStdTimeout);
};
// DOM PROTOTYPE _____________________________________________
if (typeof(_b.DOM) == "undefined")
_b.DOM = {};
/* create element */
_b.DOM.cE = function ( type, attr, cont, html )
{
var ne = document.createElement( type );
if (!ne)
return 0;
for (var a in attr)
ne[a] = attr[a];
if (cont != null)
{
var t = typeof(cont);
if (t == "string" && !html)
ne.appendChild( document.createTextNode(cont) );
else if (t == "string" && html)
ne.innerHTML = cont;
else if (t == "object")
ne.appendChild( cont );
}
return ne;
};
/* get element */
_b.DOM.gE = function ( e )
{
var t=typeof(e);
if (t == "undefined")
return 0;
else if (t == "string")
{
var re = document.getElementById( e );
if (!re)
return 0;
else if (typeof(re.appendChild) != "undefined" )
return re;
else
return 0;
}
else if (typeof(e.appendChild) != "undefined")
return e;
else
return 0;
};
/* remove element */
_b.DOM.remE = function ( ele )
{
var e = this.gE(ele);
if (!e)
return 0;
else if (e.parentNode.removeChild(e))
return true;
else
return 0;
};
/* get position */
_b.DOM.getPos = function ( e )
{
var e = this.gE(e);
var obj = e;
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
var obj = e;
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return {x:curleft, y:curtop};
};
com_hp_gc.cookies = {
get: function(cookieName) {
var cookieNameStart,valueStart,valueEnd,value;
cookieNameStart = document.cookie.indexOf(cookieName+'=');
if (cookieNameStart < 0) {return null;}
valueStart = document.cookie.indexOf(cookieName+'=') + cookieName.length + 1;
valueEnd = document.cookie.indexOf(";",valueStart);
if (valueEnd == -1){valueEnd = document.cookie.length;}
value = document.cookie.substring(valueStart,valueEnd );
value = unescape(value);
if (value == "") {return null;}
return value;
},
set: function(cookieName,value,hoursToLive,path,domain,secure) {
var expireString,timerObj,expireAt,pathString,domainString,secureString,setCookieString;
if (!hoursToLive || typeof hoursToLive != 'number' || parseInt(hoursToLive)=='NaN'){
expireString = "";
}
else {
timerObj = new Date();
timerObj.setTime(timerObj.getTime()+(parseInt(hoursToLive)*60*60*1000));
expireAt = timerObj.toGMTString();
expireString = "; expires="+expireAt;
}
pathString = "; path=";
(!path || path=="") ? pathString += "/" : pathString += path;
domainString = "; domain=";
(!domain || domain=="") ? domainString += window.location.hostname : domainString += domain;
(secure === true) ? secureString = "; secure" : secureString = "";
value = escape(value);
setCookieString = cookieName+"="+value+expireString+pathString+domainString;
document.cookie = setCookieString;
},
del: function(cookieName,path,domain){
(!path || !path.length) ? path="" : path=path;
(!domain || !domain.length) ? domain="" : domain=domain;
com_hp_gc.cookies.set(cookieName,"",-8760,path,domain);
},
test: function(){
com_hp_gc.cookies.set('cT','acc');
var runTest = com_hp_gc.cookies.get('cT');
if (runTest == 'acc'){
com_hp_gc.cookies.del('cT');
testStatus = true;
}else{testStatus = false;}
return testStatus;
}
};
com_hp_gc.getQueryVariable = function(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i', '>').replace('\'', ''').replace('"', '"');
};
com_hp_gc.addListener = function(elm, evType, fn, useCapture) {
var ret = null;
if (elm.addEventListener)
{ ret = elm.addEventListener(evType, fn, useCapture); }
else {
if (elm.attachEvent)
{ ret = elm.attachEvent('on' + evType, fn); }
else
{ elm['on' + evType] = fn; }
}
return ret;
};
if (typeof(com_hp_gc.Poll) == "undefined")
com_hp_gc.Poll = {};
com_hp_gc.Poll = function (contextKey, elID, submitName, pollID, showBar)
{
this.cK = contextKey;
this.eI = _b.DOM.gE(elID);
this.pC = 'hpgc_poll_div';
this.sN = submitName;
this.pI = pollID;
this.pE = null;//poll element
this.rV = null;//return value
this.pH = null;//poll header
this.aC = 0;//sum of submitted answers
this.mS = 0;//maximum selection
this.rB = new Array();//radio buttons
if (showBar == null)
this.sB = true;
else
this.sB = !showBar;
this.ajax = new _b.Ajax();
if (!this.cK || !this.ajax || !this.eI || !this.sN)
return 0;
};
com_hp_gc.Poll.prototype.getPollQuestion = function()
{
var cK2 = encodeURIComponent("\"" + this.cK + "\"");
var pI2 = '';
if (this.pI)
pI2 = encodeURIComponent("\"" + this.pI + "\"");
var url = "http://h41273.www4.hp.com/hpgc/poll/Poll.asmx/GetPollQuestion?contextKey=" + cK2 + "&pollID=" + pI2;
var pointer = this;
var onSuccessFunc = function (req) { pointer.createPollArea(req) };
var onErrorFunc = function (status) { hpgcDebug("AJAX error: "+status); };
this.ajax.makeRequest( url, 'GET', onSuccessFunc, onErrorFunc);
};
com_hp_gc.Poll.prototype.pollSubmit = function ( formEl )
{
//for (var i=0; i
This is your question
Tkjk |
|
38% |
|
This is your answer text
*/
com_hp_gc.Poll.prototype.createAnswerArea = function ( req )
{
var jsondata = req;//el(req.responseText);
var el = _b.DOM.cE('div', {className:'hpgc_poll_header'}, this.pH, true);
var poll_div = _b.DOM.cE('div', {className:this.pC}, el);
el = _b.DOM.cE('p', {className:'hpgc_poll_question'}, this.rV.question, true);
poll_div.appendChild(el);
var table = document.createElement('tbody');
var sum = this.aC + 1;
for (var i=0;i this.mS)
this.mS = jsondata.results[i].selection_count;
}
var submitter = _b.DOM.cE('button', { className:'hpgc_poll_submit', className:'hpgc_poll_submit' }, this.sN, true);
var pointer = this;
submitter.onclick = function () { pointer.pollSubmit(form); return false; };
form.appendChild(submitter);
var newEl = _b.DOM.cE("div", {className:this.pC}, header);
newEl.appendChild(form);
this.pI = jsondata.poll_id;
this.eI.parentNode.insertBefore(newEl, this.eI);
this.pE = newEl;
};
com_hp_gc.Poll.prototype.clearCheck = function()
{
for (var i = 0; i < this.rB.length; i++)
this.rB[i].checked = false;
};
com_hp_gc.Poll.prototype.registerAnswer = function( contextKey, pollID, answerID, submitterID)
{
if (this.iID != '')
{
var cK2 = encodeURIComponent("\"" + this.cK + "\"");
var pI2 = encodeURIComponent("\"" + pollID + "\"");
var aI2 = encodeURIComponent("\"" + answerID + "\"");
var sI2 = "";
if (submitterID)
sI2 = encodeURIComponent("\"" + submitterID + "\"");
var url = "http://h41273.www4.hp.com/hpgc/poll/Poll.asmx/RegisterAnswer?contextKey=" + cK2 + "&pollID=" + iID2 + "&answerID=" + iI2 + "&submitterID=" + sI2;
var onSuccessFunc = function (req) { hpgcDebug("AJAX success: " + req + "\n" + "input") };
var onErrorFunc = function (status) { hpgcDebug("AJAX error: "+status); };
this.ajax.makeRequest( url, 'GET', onSuccessFunc, onErrorFunc);
}
};