//make sure the dependant files are loaded
//var script_host_url = "http://templates.activestate.com";
//document.write("<script type=\"text/javascript\" src=\"" + script_host_url + "/js/jquery-1.2.1.pack.js\"></script>");
//document.write("<script type=\"text/javascript\" src=\"" + script_host_url + "/js/thickbox-compressed.js\"></script>");
//document.write("<style type=\"text/css\" media=\"all\">@import \"" + script_host_url + "/css/thickbox.css\";</style>");
//write the JS to the page to initialize the checker
//document.write("<script type=\"text/javascript\">var t=setTimeout(\"survey_pop.init()\",2000);</script>\r\n");

var survey_pop = {
  cookie_expire : 3650,
  window_height : 200,
  window_width : 300,
  cookie_name : "taken_survey",
  pop_message : "<h2>We value your opinion!</h2><p>Please take a couple of minutes to answer a few questions about yourself and your development needs.</p><p>We'll use this information to help us provide you an even more valuable experience in the future.</p><p>Click Start to begin the 2-minute survey!</p><p><input type=button value='Start' onclick='location.href=\"http://surveys.activestate.com/38\"; return false;'></p>",
  init : function(){
    //check if the cookie is NOT set to generate the pop-up
    if(!survey_pop.checkCookie(survey_pop.cookie_name)){
      survey_pop.generate();
    }
  },
  generate : function()
  {
    //Add the hidden div to the page with the pop-up messaging
    $("body").append("<div id=\"survey_pop_content\" style=\"display:none;\">" + survey_pop.pop_message + "</div>");
    //trigger the thickbox code
    tb_show(" ", "#TB_inline?height=" + survey_pop.window_height + "&width=" + survey_pop.window_width + "&inlineId=survey_pop_content", null);
    //set the cookie to ensure the box doesn't appear again.
    survey_pop.setCookie(survey_pop.cookie_name,location.href ,survey_pop.cookie_expire);
  },
  postSurvey : function(id_name)
  {
	var dest = survey_pop.getCookie(survey_pop.cookie_name);
	if(location.href != dest){
	    $("#" + id_name).attr("href", dest);
	    setTimeout("location.href='" + dest + "'", 8000);
	}
  },
  setCookie : function(c_name,value,expiredays)
  {
    //function to set a cookie
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";domain=.activestate.com;path=/;expires="+exdate.toGMTString());
  },
  getCookie : function(c_name)
  {
    //function to get a cookie
    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 "";
  },
  checkCookie : function(cookie_name)
  {
    //function to check if the cookie exists
    cookie_val=survey_pop.getCookie(cookie_name);
    if (cookie_val!=null && cookie_val!="")
    {
      return true;
    }
    else 
    {
      return false;
    }
  }
};
