if(!window.Msn){window.Msn={};}
Msn.Survey=new function(){var me=this;var tid=null;var d=document;var w=window;var scrollHt;function getValue(offset)
{var endstr=document.cookie.indexOf(";",offset);if(endstr==-1)
endstr=document.cookie.length;return unescape(document.cookie.substring(offset,endstr));}
function SetCookie(name,value,expires)
{document.cookie=name+"="+escape(value)+";expires="+expires.toGMTString();}
function GetCkVal(name)
{var arg=name+"=";var arg_len=arg.length;var cookie_length=document.cookie.length;if(cookie_length<1){cookie_length=0;}
var i=0;while(i<cookie_length)
{var j=i+arg_len;if(document.cookie.substring(i,j)==arg)
return getValue(j);i=document.cookie.indexOf(" ",i)+1;if(i==0)break;}
return null;}
function ssc(s,c)
{sc("IsShown",s);sc("IsCompleted",c);}
function gc(n)
{var m=null;if(w.RegExp)
{var re=new RegExp(";\\s*"+n+"=([^;]*)","i");m=re.exec(';'+d.cookie);}
return(m?unescape(m[1]):null);}
function sc(n,v){var x=new Date();x.setTime(x.getTime()+(cookieExpiration*86400000));d.cookie=n+"="+v+"; expires="+x.toGMTString()+";path=/";}
function gce(n)
{var m=null;if(w.RegExp)
{var re=new RegExp("&\\s*"+n+"=(\d+)","i");m=re.exec("&"+gc("SurveyService"));}
return(m?parseInt(m[1]):30);}
function ElementbyID(i)
{return d.getElementById(i);}
function sa()
{var b=ElementbyID(surveyID);scrollHt=d.body.scrollHeight;if(b)
{if(w.attachEvent)
{w.attachEvent("onscroll",py);w.attachEvent("onresize",py);w.attachEvent("onunload",cu);}
else if(w.addEventListener)
{w.addEventListener("scroll",py,false);w.addEventListener("resize",py,false);}
b.style.width=surveyWidth+"px";b.style.height=surveyHeight+"px";b.style.position="absolute";b.style.zIndex="9999";b.style.left=(d.body.clientWidth-10)+"px";pa(b);b.style.display="block";Msn.Survey.Slide();ssc("Y","N");}}
function py()
{var b=ElementbyID(surveyID);if(b)
{pa(b);}}
function pa(b)
{var winht;var scrtop;if(navigator.userAgent.match("Safari")!=null)
{winht=self.innerHeight;scrtop=self.pageYOffset;}
else
{winht=document.documentElement.clientHeight;scrtop=document.documentElement.scrollTop;}
if(winht==0)
{winht=d.body.clientHeight;scrtop=d.body.scrollTop;}
var surveyTop;if(navigator.appName=="Opera"){surveyTop=616+scrtop-surveyHeight;}
else{surveyTop=winht+scrtop-surveyHeight;}
var maxScrollHt=scrollHt-surveyHeight;if(surveyTop>=maxScrollHt)
b.style.top=(maxScrollHt)+"px";else
b.style.top=(surveyTop)+"px";}
function cu()
{var b=ElementbyID(surveyID);if(b)
{b.style.display="none";}
if(w.detachEvent)
{w.detachEvent("onscroll",py);w.detachEvent("onresize",py);w.detachEvent("onunload",cu);}
else if(w.removeEventListener){w.removeEventListener("scroll",py,false);w.removeEventListener("resize",py,false);}}
function ac()
{var b=ElementbyID(surveyID);if(b)
{var x=parseInt(b.style.left)+slideIncrement;if(x>=d.body.clientWidth)
{cu();}
else
{b.style.left=x+"px";w.setTimeout(ac,slideInterval);}}}
this.DaysToGMTString=function(days)
{var expiration_date=new Date();var next_survey_date=expiration_date.getTime()+(days*24*60*60*1000);expiration_date.setTime(next_survey_date);var ex_date=expiration_date;return ex_date.toGMTString();}
this.CreateSurvey=function(urlSurvey,delaySlide,delayVisible)
{var already_seen=GetCkVal("DSurv");if(already_seen!="true")
{var isLuckyWinner=(Math.random()*random_factor<1);if(isLuckyWinner)
{this.Display(urlSurvey,delaySlide,delayVisible);document.cookie="DSurv=true; Path=/; Expires="+this.DaysToGMTString(days_between_surveys);}
else
{document.cookie="DSurv=false; Path=/; Expires="+this.DaysToGMTString(days_between_reqs);}}}
this.Display=function(urlSurvey,delaySlide,delayVisible)
{delayVisible=(delayVisible?delayVisible:delayVisible);cookieExpiration=gce("CookieExpiry");var delaySlide=(delaySlide?delaySlide:8);w.setTimeout(sa,delaySlide*1000);};this.Show=function()
{me.Hide();if(urlSurvey)
{w.open(urlSurvey);}
return false;};this.Hide=function()
{w.clearTimeout(tid);var b=ElementbyID(surveyID);if(b)
{cu();}
ssc("Y","Y");return false;};this.Slide=function()
{var b=ElementbyID(surveyID);if(b)
{var x=parseInt(b.style.left)-slideIncrement;if(x<d.body.clientWidth-surveyWidth)
{b.style.left=(d.body.clientWidth-surveyWidth-5)+"px";tid=w.setTimeout(ac,delayVisible*1000);}
else
{b.style.left=x+"px";w.setTimeout(me.Slide,slideInterval);}}};return this};
