/*
(c) 2006-2008  Carmil 1, Surveylyzer.com, Carmil.net
surveylyzer3_b908.js
*/

if ( typeof(window.nssy) == 'undefined' ) { window.nssy= new Object (); };


function Surveylyzer3 ()
{
this.idContainer = null;
this.nodeContainer= null;
this.idPoll = 0;
this.publisherUser= "";
this.allowedPublisherUser= new Array();
this.showResults= Surveylyzer3.ResultsShow.SHOW_EXTERNALLY;
this.refCode= "";
this.style= "";
this.isAutoDetectQuaire= true;
this.width= 0;
this.unitWidth= "";
this.height= 0;
this.unitHeight= "";
this.debugParam= "";

this.hostname= "www.surveylyzer.com";
 

this.port= 80;

this.scripts = "/cgi-bin";
 

this.ReportParams= function ()
{
this.isShowQuestionsWithoutResults= true;
this.maxReportLevel= Surveylyzer3.ReportLevel.ADVANCED ;
this.isShowReportForAll= true;
this.isAutoExpand= false;
this.supportedReportTypes= new Array( Surveylyzer3.ReportType.SIMPLE, Surveylyzer3.ReportType.CROSSES );

this.setShowQuestionsWithoutResults = function (flag)
{
this.isShowQuestionsWithoutResults = flag;
};

this.getShowQuestionsWithoutResults = function ()
{
return this.isShowQuestionsWithoutResults;
};

this.setShowReportForAllQuestions = function (flag)
{
this.isShowReportForAll = flag;
};

this.getShowReportForAllQuestions = function ()
{
return this.isShowReportForAll;
};

this.setAutoExpand = function (flag)
{
this.isAutoExpand = flag;
};

this.getAutoExpand = function ()
{
return this.isAutoExpand;
};

this.setMaxReportLevel = function (level)
{
 
this.maxReportLevel = level;
};

this.getMaxReportLevel = function ()
{
 
return this.maxReportLevel;
};

this.setSupportedReportTypes = function (arrayTypes)
{
 
this.supportedReportTypes= arrayTypes;
};

this.getSupportedReportTypes = function ()
{
 
return this.supportedReportTypes;
};
};
this.rp= new this.ReportParams();

this.getMsgWait = function ()
{
return "Preparing the questionnaire...";
};

this.getQueryStringParam = function (param, defVal)
{
var pattern="^(.+[?])(.*[&])*(" + param + "[=])([A-Za-z0-9\.\,\%\_\@\+-]+)([&#].*)?$";
var regex= new RegExp(pattern);
var val= regex.exec( document.location );
if (val == null)
{
return defVal;
}
return decodeURIComponent( val[4] );
};

this.report = function ()
{
return this.rp;
};

this.setContainer = function (id)
{
this.idContainer = id;
};

this.getContainerNode = function ()
{
return this.nodeContainer;
};

this.getMainContainerId = function ()
{
return this.idContainer;
};

this.setQuestionnaire = function (id)
{
this.idPoll = id;
};

this.getQuestionnaire = function ()
{
var idPoll= this.idPoll;
if (this.isAutoDetectQuaire || (idPoll == 0))
{
idPoll= parseInt(this.getQueryStringParam("sy_id_poll", idPoll));
}
return idPoll ;
};

this.setAutoDetectQuestionnaire = function ( flag )
{
this.isAutoDetectQuaire= flag;
}

this.getUrlPrefix = function ()
{
var schema= (location && location.protocol && ( /^(http|https)[:]/i.test(location.protocol) )) ? location.protocol : "http:";

var prefix= schema + "//" + this.hostname;
if ((!isNaN(this.port)) &&
(((this.port != "80") && (schema == "http:")) || ((this.port != "443") && (schema == "https:"))))
{
prefix= prefix + ":" + this.port;
}
return prefix;
};

this.setReferrerCode = function (refcode)
{
this.refCode= refcode;
};

this.getReferrerCode = function ()
{
return this.refCode;
};

this.setStyle = function (style)
{
this.style = style;
};

this.getStyle = function ()
{
return this.style;
};

this.setWidth = function (size, units)
{
this.width= size;
this.unitWidth= ((units == null) || (units == ""))? "px" : units;
};

this.getWidth = function ()
{
var str= "";
if (this.unitWidth != "")
{
str= new Number(this.width).toString() + this.unitWidth;
}
this.trace("Width:" + str);
return str;
};

this.getWidthVal = function ()
{
return this.width;
}

this.getWidthUnits = function ()
{
return this.unitWidth;
}

this.setHeight = function (size, units)
{
this.height= size;
this.unitHeight= ((units == null) || (units == ""))? "px" : units;
};

this.getHeight = function ()
{
var str= "";
if (this.unitHeight != "")
{
str= new Number(this.height).toString() + this.unitHeight;
}
this.trace("Height:" + str);
return str;
};

this.getHeightVal = function ()
{
return this.height;
}

this.getHeightUnits = function ()
{
return this.unitHeight;
}

this.setHost = function (host)
{
var isOK= /^[a-zA-Z0-9\-]+[.]surveylyzer[.]com$/i.test(host);
if (isOK)
{
this.hostname= host;
if (this.hostname == "local.surveylyzer.com")
{
this.scripts = "/cgi-bin";
}
 
}
else
{
this.trace( "Cannot set host: " + host );
}
};

this.setPort = function (port)
{
this.port= port;
};

this.setPublisherUser = function (user)
{
this.publisherUser = user;
this.allowedPublisherUser.push( user );
};

this.addAllowedPublisherUser = function (user)
{
this.allowedPublisherUser.push( user );
};

this.getAllowedPublisherUsers = function ()
{
return this.allowedPublisherUser;
};

this.setAllowedPublisherUsers = function (users)
{
this.allowedPublisherUser= users;
};

this.setShowResults = function (how)
{
this.showResults = how;
};

this.getShowResults = function ()
{
return this.showResults;
};

this.trace = function (msg)
{
var outmsg= "Surveylyzer3: " + msg + "\n";
if (window.dump) { window.dump(outmsg); }
else if ((window.Debug) && (window.Debug.write)) { window.Debug.write(outmsg); }
};

this.getNodePreferHead = function ()
{
var node= null
var heads = document.getElementsByTagName('head');
if (heads && (heads.length > 0))
{
node= heads[0];
}
else
{
node= document.getElementById(this.idContainer);
}
return node;
};

this.putStylesheet = function (file)
{
var urlcss= this.getUrlPrefix() + file ;
var nodeCSS= document.createElement("LINK");
nodeCSS.setAttribute("href", urlcss );
nodeCSS.setAttribute("type", "text/css");
nodeCSS.setAttribute("rel", "stylesheet");
this.getNodePreferHead().appendChild(nodeCSS);
};

this.go = function ()
{
this.trace("go: " + new Date().toString());

this.debugParam= this.getQueryStringParam("sy_debug", "");

this.nodeContainer= document.getElementById(this.idContainer);
while ( this.nodeContainer.hasChildNodes() )
{
this.nodeContainer.removeChild( this.nodeContainer.lastChild );
}
if (this.nodeContainer.className == "")
{
this.nodeContainer.className= "clsSy";
}

this.putStylesheet( this.scripts + "/ap_style.pl?caller=jssy3&style=SyWwDyn&container=" +
encodeURIComponent(this.idContainer) + "&width=" + encodeURIComponent(this.getWidth()) +
"&height=" + encodeURIComponent(this.getHeight()) + "&styleext=" + encodeURIComponent(this.style) +
"&debug=" + encodeURIComponent(this.debugParam) );

 
 

if ((this.debugParam != null) && (this.debugParam != ""))
{
var nodeDivDebug= document.createElement("DIV");
nodeDivDebug.className= this.debugParam;
this.nodeContainer.appendChild(nodeDivDebug);
this.nodeContainer= nodeDivDebug;
}

if ((this.style != null) && (this.style != ""))
{
 
var nodeDivStyled= document.createElement("DIV");
nodeDivStyled.className= this.style;
this.nodeContainer.appendChild(nodeDivStyled);
this.nodeContainer= nodeDivStyled;
}

nssy.surveylyzer3= this;
var url= this.getUrlPrefix() + this.scripts + "/ap_js_sy3.pl?id_poll=" + encodeURIComponent( this.getQuestionnaire() ) +
"&container=" + encodeURIComponent( this.idContainer ) +
"&host=" + encodeURIComponent( this.hostname ) +
"&port=" + encodeURIComponent( this.port );
 

var nodeDivPleaseWait= document.createElement("DIV");
nodeDivPleaseWait.setAttribute("id", "idSyPleaseWait");
nodeDivPleaseWait.setAttribute("class", "clsPleaseWait");
nodeDivPleaseWait.appendChild( document.createTextNode(this.getMsgWait()) );
this.nodeContainer.appendChild(nodeDivPleaseWait);

var nodeJS= document.createElement("SCRIPT");
nodeJS.setAttribute("src", url );
nodeJS.setAttribute("type", "text/javascript");
nodeJS.setAttribute("defer", "defer" );
this.getNodePreferHead().appendChild(nodeJS);

return 0;
};
}
Surveylyzer3.ResultsShow= { HIDE : 1, INTERNALLY : 2, EXTERNALLY : 3 };
 
Surveylyzer3.ReportLevel= { STANDARD : 1, ADVANCED : 2 };
 
Surveylyzer3.ReportType= { SIMPLE : 1, CROSSES : 2 };

/* End of file */
